akhauriyash/Code-Regression huggingface dataset:
function Main(input) {
  input = input.split("\n");
  var a = input[0];
  var b = input[1];
  var c = input[2];

  var aList = [a.split(""), "A"];
  var bList = [b.split(""), "B"];
  var cList = [c.split(""), "C"];

  var turn = aList;

  while (true) {
    if (turn[0].length > 0) {
      var first = turn[0][0];
      turn[0].shift();
      if (first === "a") {
        turn = aList;
      }
      if (first === "b") {
        turn = bList;
      }
      if (first === "c") {
        turn = cList;
      }
    } else if (!(turn[0].length > 0)) {
      console.log(turn[1]);
      break;
    }
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
// ruiseki-wa
#include <algorithm>
#include <iostream>
using namespace std;

int sum[100010];
int main(void)
{
    int n, k;
    while(1) {
        cin >> n >> k;
        if(n==0 && k==0) break;

        int a[n];
        for(int i=0; i<n; i++) cin >> a[i];
        for(int i=0; i<n; i++) sum[i+1] = sum[i] + a[i]; // sum[i] := a[0]??????a[i-1]?????§??????(sum[0]=0)

        int ans = sum[k] - sum[0];
        for(int i=0; i<n-k; i++)
            ans = max(ans, sum[i+1+k] - sum[i+1]);
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1936
#include <iostream>
#include <fstream>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <iterator>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define mp make_pair
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(),x.end()

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const ll INF=1e18+123;
const ld EPS=1e-9;
const int inf=1e9+123;
const int MOD=1e9+7;
const int N=1e5+123;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k%2){
        cout<<b-a;
    }
    else cout<<a-b;
    return 0;
}


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

int main()
{
  ll n;

  cin >> n;
  ll m = 0;
  ll c = 0;
  ll h = 0;
  for (ll i = 0; i < n; ++i) {
    ll t = 0;
    cin >> t;
    if (t <= h) {
      ++c;
    } else {
      m = max(c, m);
      c = 0;
    }
    h = t;
  }
  m = max(c, m);
  cout << m;

  return 0;
}



Measured memory_bytes: 256
import math
A, B, H, M=map(int,input().split())

ang_m = M * 6
ang_h = H * 30 + M * 0.5
ang = max(ang_h, ang_m) - min(ang_h, ang_m)

C = math.sqrt(A**2 + B**2 - 2*A*B * math.cos(math.radians(ang)))
print(C)

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

const int INF = 2e9;

int main(){
    double n;
    cin >> n;
    int t = (n+1)/2;
    double ans = t/n;
    cout << fixed << setprecision(10) << ans << endl;
}

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

int main(void)
{
    int n, a, b, c;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a >> b >> c;
        int min, mid, max;
        min = (a <= b && a <= c)? a : (b <= a && b <= c)? b : c;
        max = (a >= b && a >= c)? a : (b >= a && b >= c)? b : c;
        mid = (a!=min && a!=max)? a : (b!=min &&b!=max)? b : c;
        cout << ((pow(min, 2.0) + pow(mid, 2.0) == pow(max, 2.0))? "YES" : "NO") << endl;
    }
    return 0;
}


Measured memory_bytes: 3072
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    A, B, C = map(int, readline().split())
    K = int(readline())
    print(max(A, B, C) * 2**K + A+B+C-max(A,B,C))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9156
//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 1000 + 5;
const int M = 201;
const int Q = 2e5 + 5;
const int OO = 2e9;
const int mod = 998244353;

string a,b;

void init() {
}

int main() {

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

    cin >> a >> b;

    bool ok = 1;

    for (int i = 0; i < int(a.size()); ++i) {
        if(a[i]!=b[i]) ok = 0;
    }

    cout << (ok ? "Yes" : "No") << '\n';

    return 0;
}

Measured memory_bytes: 3608
/*
* Author. Silviase(@silviasetitech)
* For AtCoder
*/

import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {

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

        String s = sc.next();
        String m = s.substring(5,7);
        int mi = Integer.parseInt(m);
        if (mi <= 4) {
            System.out.println("Heisei");
        }else{
            System.out.println("TBD");
        }


        sc.close();
    }
    
    private static long gcd(Long m, long n) {
        if(m < n) {
            return gcd(n, m);
        }
        if(n == 0){
            return m;
        } 
        return gcd(n, m % n);
    }

    private static long[][] Combination_nCk(long n, long k) {
        n++; k++;
        long[][] ans = new long[(int)n][(int)k];
        for (int i = 0; i < n; i++) {
            ans[i][0] = 1;
        }
        for (int i = 0; i < n-1; i++) {
            for (int j = 0; j < k-1; j++) {
                if (i < j) {
                    ans[i][j] = 0;
                }else{
                    ans[i+1][j+1] = ans[i][j] + ans[i][j+1];
                }
            }
        }
        return ans;
    }
}

Measured memory_bytes: 22100
n = int(input())

ans = 0
numbers = [[0] * 10 for _ in range(10)]
for i in range(1, n+1):
    ss = str(i)
    numbers[int(ss[0])][int(ss[-1])] += 1

for j in range(1, n+1):
    ss = str(j)
    ans += numbers[int(ss[-1])][int(ss[0])]

print(ans)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define int long long int
#define MOD 1000000007
#define mkp make_pair
#define maxn 100005
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define  vi vector<int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define in cin>>
#define out cout<<
using namespace std;
const int infi=1e9+7;
void printVector(vector<int> v){
    for(int i=0;i<(int)v.size();i++)
        cout<<v[i]<<" ";
    out endl;
}

void printArray(int arr[],int n)
{
   for(int i=0;i<n;i++)cout<<arr[i]<<' ';
cout<<endl;
}
 set<pair<int,int>> primeset;
 vi prime_number;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
        for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
           primeset.insert(mkp(p,1));
}
ll modExp(ll base, ll power) {
    if (power == 0) {
        return 1;
    } else {
        ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
        if (power % 2 == 1) cur = cur * base;
        cur = cur % MOD;
        return cur;
    }
}
//for making unordered_map with pair
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
int32_t main()
{
int tt=1;
int t=1;
//in t;
while(t--){
    double l;
    in l;
     cout<<fixed<<setprecision(12)<<((l*l*l)/27);
}
    return 0;
}

/*
google kick start
  cout << "Case #" << tt << ": "<<ans<<endl;
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

void solve(long long W, long long H, long long x, long long y){
	ll res = 0;
	if (W%2 == 0 && H%2 == 0 && x == W/2 && y == H/2) res = 1;
	printf("%.16f %lld\n", W*H/2.0, res);
	// cout << W*H/2.0 << " " << res << endl;
}

int main(){	
	long long y;
	long long x;
	long long H;
	long long W;
	scanf("%lld",&W);
	scanf("%lld",&H);
	scanf("%lld",&x);
	scanf("%lld",&y);
	solve(W, H, x, y);
	return 0;
}



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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  1000005

vi v[2006];
vi ans(2005,0);
ll n;
void dfs(ll x,ll d)
{
	vi vis(n+1,0),dis(n+1,0);
	queue<ll> qu;
	qu.push(x);
	vis[x]=1;
	dis[x]=0;
	while(!qu.empty())
	{
		ll x=qu.front();
		qu.pop();
		for(auto i:v[x])
		{
			if(vis[i]==1)
				continue;
			vis[i]=1;
			dis[i]=dis[x]+1;
			ans[dis[i]]++;
			qu.push(i);
		}
	}
}
int main()
{
    ios;
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
    	ll i,j,k,l,m;
    	ll x,y;
    	cin>>n>>x>>y;
    	for(i=1;i<=n-1;i++)
    	{
    		v[i].pb(i+1);
    		v[i+1].pb(i);
    	}
    	v[x].pb(y);
    	v[y].pb(x);
    	for(i=1;i<=n;i++)
    	{
    		dfs(i,0);
    	}
    	for(i=1;i<=n-1;i++)
    	{
    		cout<<ans[i]/2<<endl;
    	}
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
	// Tenka1 Programmer Contest-C, 1151, 
	ll n; cin >> n;
	rep(i, 3501) {
		if (i == 0) continue;
		rep(j, 3501) {
			if (j == 0) continue;
			int l = 0, r = 3500;
			while (l + 1 < r) {
				int m = (l + r) / 2;
				ll left = ll(m) * (ll(4) * ll(i) * ll(j) - n * ll(i) - n * ll(j));
				ll right = n * ll(i) * ll(j);
				if (left == right) {
					cout << i << " " << j << " " << m << endl;
					return 0;
				}
				else if (left < right) l = m;
				else r = m;
			}
		}
	}
	assert(false);
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m, a, b;
    cin >> n >> m;
    int dp[n][n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) dp[i][j] = 0;
    for (int i = 0; i < m; i++)
    {
        cin >> a >> b;
        dp[a - 1][b - 1]++;
        dp[b - 1][a - 1]++;
    }
    for (int i = 0; i < n; i++) 
    {
        int k = 0;
        for (int j = 0; j < n; j++) k += dp[i][j];
        cout << k << endl;
    }
}

Measured memory_bytes: 3484
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD2 solver = new TaskD2();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskD2 {
		public void solve(int testNumber, Scanner sc, PrintWriter out) {

			int n = sc.nextInt();
			int m = sc.nextInt();
			int[] p = new int[n];
			for (int i = 0; i < n; i++) {
				p[i] = sc.nextInt() - 1;
			}

			UnionFind uf = new UnionFind(n);
			for (int i = 0; i < m; i++) {
				int x = sc.nextInt() - 1;
				int y = sc.nextInt() - 1;
				uf.unite(x, y);
			}

			int count = 0;
			for (int i = 0; i < n; i++) {
				if (uf.same(p[i], i)) count++;
			}

			out.println(count);
		}

	}

	static class UnionFind {
		private int[] parent;
		private int[] rank;

		public UnionFind(int n) {
			parent = new int[n];
			rank = new int[n];
			for (int i = 0; i < n; i++) parent[i] = i;
		}

		public int find(int x) {
			if (parent[x] == x) return x;
			else return parent[x] = find(parent[x]);
		}

		public void unite(int x, int y) {
			x = find(x);
			y = find(y);
			if (x == y) return;
			if (rank[x] < rank[y]) {
				parent[x] = y;
			} else {
				parent[y] = x;
				if (rank[x] == rank[y]) rank[x]++;
			}
		}

		public boolean same(int x, int y) {
			return find(x) == find(y);
		}

	}

	static class Scanner {
		private final InputStream in;
		private final byte[] buffer;
		private int ptr;
		private int buflen;

		public Scanner(InputStream in) {
			this.in = in;
			this.buffer = new byte[1024];
			this.ptr = 0;
			this.buflen = 0;
		}

		private boolean hasNextByte() {
			if (ptr < buflen) return true;
			else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) return false;
			}
			return true;
		}

		private byte readByte() {
			if (hasNextByte()) return buffer[ptr++];
			return -1;
		}

		private boolean isPrintableChar(byte c) {
			return '!' <= c && c <= '~';
		}

		private void skipUnprintable() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
				ptr++;
			}
		}

		public boolean hasNext() {
			skipUnprintable();
			return hasNextByte();
		}

		public int nextInt() {
			if (!hasNext()) throw new NoSuchElementException();
			int n = 0;
			boolean minus = false;
			byte b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) throw new NumberFormatException();
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

	}
}



Measured memory_bytes: 24864
N = int(input())
S  = list(input())
if len(S)%2 == 1:
    print('No')
    exit()
if len(S)%2 == 0:
    for i in range(len(S)//2):
        if S[i] != S[i+len(S)//2]:
            print('No')
            exit()
print('Yes')

Measured memory_bytes: 3060
// ABC096_C
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::prev(iter, n) n 個分デクリメントしたイテレータ
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define pll pair<ll, ll>
#define F first
#define S second
const ll INF = 1LL<<60;  // 10^18

ll x[] = {0, 0, 1, -1};
ll y[] = {1, -1, 0, 0};

int main() {
    // input(sunippets: inpv, inpn, inps)
    ll H, W;
    cin >> H >> W;
    vector<string> vec(H);
    REP(i, H) cin >> vec[i];
    
    // calculation
    bool flag = true;
    ll sum;
    REP(i, H) {
        REP(j, W) {
            if (vec[i][j] == '#') {
                sum = 0;
                REP(l, 4) {
                    ll yy = i+y[l], xx = j+x[l];
                    if ((0 <= yy && yy <= H-1) && (0 <= xx && xx <= W-1)) {
                        if (vec[yy][xx] == '#') sum++;
                    }
                }
                
                if (sum == 0) {
                    flag = false;
                    break;
                }
            }
        }
    }
    
    if (flag) cout << "Yes" << "\n";
    else cout << "No" << "\n";
    
    return 0;
}

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


int main() {
  string S, T;
  cin >> S >> T;
  int count = 0;
  for(int i = 0; i < S.size(); i++) {
    if(S.at(i) != T.at(i)) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

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

int main() {
    cin>>H>>W;
    vec s(2), t(2);
    cin>>s[0]>>s[1]>>t[0]>>t[1];
    rep(i,2){--s[i]; --t[i];}
    vector<string> G(H);
    rep(i,H) cin>>G[i];
    mat dist(H, vec(W, INF));
    dist[s[0]][s[1]] = 0;
    deque<P> que;
    que.emplace_back(0, s[0] * W + s[1]);
    const vector<int> dh = {-1, 0, 1, 0}, dw = {0, -1, 0, 1};
    while(!que.empty()){
        P p = que.front();
        que.pop_front();
        int h = p.se/W, w = p.se%W;
        if(dist[h][w] < p.fi) continue;
        rep(i, 4){
            int nh = h + dh[i], nw = w + dw[i];
            if(nh >= 0 && nh < H && nw >= 0 && nw < W && G[nh][nw] != '#'){
                if(chmin(dist[nh][nw], p.fi)){
                    que.emplace_front(p.fi, nh * W + nw);
                }
            }
        }
        for(int i = -2; i <= 2; ++i){
            for(int j = -2; j <= 2; ++j){
                int nh = h + i, nw = w + j;
                if(nh >= 0 && nh < H && nw >= 0 && nw < W && G[nh][nw] != '#'){
                    if(chmin(dist[nh][nw], p.fi + 1)){
                        que.emplace_back(p.fi + 1, nh * W + nw);
                    }
                }
            }
        }
    }
    cout<<(dist[t[0]][t[1]] == INF ? -1 : dist[t[0]][t[1]])<<endl;
}


Measured memory_bytes: 13444
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <list>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 998244353;
const ll inf = (ll) 1e18;

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

  int n;
  cin >> n;
  vector<int> d(n);
  for (auto &x: d) cin >> x;

  if (d[0] > 0) {
    cout << 0 << endl; // impossible
    return 0;
  }

  sort(d.begin(), d.end());

  if (d[1] == 0) {
    cout << 0 << endl; // impossible
    return 0;
  }

  ll ans = 1;
  ll lastCount = 1;
  ll count = 1;
  int lastDist = d[0];
  for (int i = 1; i < n; i++) {
    if (d[i] == lastDist) {
      ans = (ans * lastCount) % mod;
      count++;
    }
    else if (d[i] == lastDist + 1){
      lastCount = count;
      count = 1;
      lastDist = d[i];
      ans = (ans * lastCount) % mod;
    }
    else {
      cout << 0 << endl; // impossible
      return 0;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
/*
ID: espr1t
TASK: 
KEYWORDS: 
*/

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

using namespace std;
FILE* in = stdin; FILE* out = stdout;

const int MAX = 1024;

int n;
double T, A;
double a[MAX];

int main(void) {
	// in = fopen("B.in", "rt");
	
	fscanf(in, "%d", &n);
	fscanf(in, "%lf %lf", &T, &A);
	for (int i = 0; i < n; i++)
	    fscanf(in, "%lf", &a[i]);
	
	int ans = -1;
	double bestDiff = 1e100;
	for (int i = 0; i < n; i++) {
	    double curDiff = fabs(A - (T - a[i] * 0.006));
	    if (bestDiff > curDiff) {
	        bestDiff = curDiff;
	        ans = i;
        }
    }
    fprintf(out, "%d\n", ans + 1);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    ll n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    reverse(all(s));
    ll cnt = 0;
    ll max_seq = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i]=='1'){
            cnt++;
            max_seq = max(cnt, max_seq);
        }else{
            cnt = 0;
        }
    }
    if(m <= max_seq){
        cout << -1 << endl;
        return 0;
    }
    vector<ll> forward;
    ll pos = 0;
    while(pos<n){
        for(int i = m; i > 0; i--){
            if(pos+i>n){continue;}
            if(s[pos+i] != '1'){
                pos = pos + i;
                forward.push_back(i);
                break;
            }
        }
    }
    reverse(all(forward));
    for(int i = 0; i < forward.size(); i++){
        cout << forward[i] << " ";
    }
    cout << endl;

    return 0;

}


Measured memory_bytes: 1528
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)
#define min(a,b) (a>b?b:a)
#define max(a,b) (a>b?a:b)
#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")
#define pro "はいプロ　世界一○○が上手　○○界のtourist　○○時代の終焉を告げる者　実質○○　○○するために生まれてきた男"
#define Answer_to_the_Ultimate_Question_of_Life_the_Universe_and_Everything 42

signed main(){
	cout<<fixed<<setprecision(7);
	
	int count = 0;
	string str;
	cin>>str;
	
	for(int i = 0; i < str.size(); i++){
		if(str[i] == '1')count++;
	}
	
	cout<<count<<endl;
	
	return 0;
}

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

int main(){
	string n;
	cin >> n;
	bool judge=false;
	if(n.at(0)==n.at(1) && n.at(1)==n.at(2)) judge=true;
	if(n.at(1)==n.at(2) && n.at(2)==n.at(3)) judge=true;
	if(judge) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3628
//long long -> ll
//http://web.mit.edu/~ecprice/acm/acm08/notebook.html#file12
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include<bits/stdc++.h>
typedef long long ll;
#define x first
#define y second
#define all(aaa) (aaa).begin(),(aaa).end()
#define REP(i,sss,eee) for(long long i=sss;i<=eee;++i)
#define pb push_back
#define pii pair<long long,long long>
#define vi vector<long long>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
#define N 1000000007
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}

typedef tree<
long long,
null_type,
less<long long>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

long long ex(long long a, long long b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	long long tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
long long inv(long long k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
/*****************default********************/
long long solve()
{
	long long k,a,b;cin>>k>>a>>b;
	if(k==1){
		cout<<2<<"\n";return 0;
	}
	else
	{
		if(b-a>2)
		{
			long long tot=1,diff;
			if(tot<a)
			{
				diff=(a-tot);
				if(diff>k)
				{
					cout<<(1+k);return 0;
				}
				k-=(a-tot);
				tot+=(a-tot);
			}
			long long q=(k/2);tot+=(k%2);
			tot+=((b-a)*q);
			cout<<tot<<"\n";return 0;
		}
		else
		{
			cout<<(1+k)<<"\n";
		}
	}
}
signed main(){
	speed
	long long tt=1;
	//cin>>tt;
	while(tt--)
	{
		solve();
	}
	return 0;
}

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

int main() {
	string s;
	cin >> s;

	int szs = s.size();

	bool st1 = true, st2 = false, st3 = false, st4 = false;

	bool ok = true;
	for (int i = 0; i < szs; i++) {
		if (st1) {
			if (s.substr(i, 3) == "KIH") {
				i += 2;
				st1 = false;
				st2 = true;
				continue;
			}
			else if (s.substr(i, 4) == "AKIH") {
				i += 3;
				st1 = false;
				st2 = true;
				continue;
			}
			else {
				ok = false;
				break;
			}
		}
		if (st2) {
			if (s.substr(i, 1) == "B") {
				st2 = false;
				st3 = true;
				continue;
			}
			else if (s.substr(i, 2) == "AB") {
				i++;
				st2 = false;
				st3 = true;
				continue;
			}
			else {
				ok = false;
				break;
			}
		}
		if (st3) {
			if (s.substr(i, 1) == "R") {
				st3 = false;
				st4 = true;
				continue;
			}
			else if (s.substr(i, 2) == "AR") {
				i++;
				st3 = false;
				st4 = true;
				continue;
			}
			else {
				ok = false;
				break;
			}
		}
		if (st4) {
			if (s[i] != 'A' || i != szs - 1) ok = false;
		}
	}

	cout << (ok ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 3612
N = int(input())

innerAB_cnt = 0
endA_cnt = 0
startB_cnt = 0
B_A_cnt = 0
for i in range(N):
    S = input()
    innerAB_cnt += S.count('AB')
    is_end_A = S[-1] == 'A'
    is_start_B = S[0] == 'B'
    if is_end_A and is_start_B:
        B_A_cnt += 1
    elif is_end_A:
        endA_cnt += 1
    elif is_start_B:
        startB_cnt += 1
remainder = abs(startB_cnt - endA_cnt)
if B_A_cnt == 0:
    print(min(endA_cnt, startB_cnt) + innerAB_cnt)
elif endA_cnt + startB_cnt > 0:
    print(min(endA_cnt, startB_cnt) + B_A_cnt + innerAB_cnt)
else:
    print(B_A_cnt-1 + innerAB_cnt)




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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  map<int,int>m;
  int a,b,c;cin>>a>>b>>c;
  m[a]++;
  m[b]++;
  m[c]++;

  if(m.size()==2)cout<<"Yes";
  else cout<<"No";

  return 0;
}

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

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] t = new int[n+1];
        int[] t2 = new int[n+1];
        for(int i =1;i<=n;i++){
            t[i]=sc.nextInt();
            t2[i] = t[i];
        }
        int m = sc.nextInt();
        for(int i =0;i<m;i++){
            int p =sc.nextInt();
            int x =sc.nextInt();
            int cnt =0;
            t2[p]=x;
            for(int j =1;j<=n;j++){
                cnt+=t2[j];
            }
            System.out.println(cnt);
            for(int j =1;j<=n;j++){
                t2[j]=t[j];
            }


        }

    }
}






Measured memory_bytes: 23764
import java.util.Scanner

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val a = scn.nextInt()
	val b = scn.nextInt()
	println(if (a<b) IntArray(b){a}.joinToString(separator = "") else IntArray(a){b}.joinToString(separator = ""))
}

Measured memory_bytes: 33996
import java.util.*;

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    String s = String.valueOf(n);
    
    int x = 0;
    for (int i = 0; i < s.length(); i++) {
      x += Integer.parseInt(s.substring(i, i+1));
    }
    
    System.out.println((n % x) == 0 ? "Yes" : "No");
  }
}

Measured memory_bytes: 21716
n = int(input())
words = [input() for x in range(n)]

A = 'Yes'

last_word = words[0][-1:]

# there is duplicated word
if len(words) != len(list(set(words))):
    A = 'No'

for i in range(1, n):
    if last_word == words[i][:1]:
        last_word = words[i][-1:]
        continue

    else:
        A = 'No'
        break

print(A)


Measured memory_bytes: 3060
import java.util.*;

public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int countAC = 0;
        int countWA = 0;
        int countTLE = 0;
        int countRE = 0;

        for (int i=0; i<n; i++) {
            String s = sc.next();
            if(s.equals("AC")) {
                countAC++;
            } else if(s.equals("WA")) {
                countWA++;
            } else if(s.equals("TLE")) {
                countTLE++;
            } else if(s.equals("RE")) {
                countRE++;
            }
        }
        System.out.print("AC x " + countAC);
        System.out.print("\n");
        System.out.print("WA x " + countWA);
        System.out.print("\n");
        System.out.print("TLE x " + countTLE);
        System.out.print("\n");
        System.out.print("RE x " + countRE);
        System.out.print("\n");

    }

}

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

using namespace std;

typedef long long ll;
const ll inf = 1e16;
ll n, vis[200005], ans, cnt1, cnt2, a[100005], b[100005], dif1, dif2, cmp;
struct node
{
	ll v, id;
	friend bool operator < (node a, node b)
	{
		return a.v < b.v;
	}
}e[200005];

int main()
{
	cin >> n;
	for (ll i = 1; i <= n; i++)
	{
		cin >> e[i].v >> e[i + n].v;
		a[i] = e[i].v, b[i] = e[i + n].v;
		e[i].id = i, e[i + n].id = i + n;
	}
	sort(e + 1, e + n * 2 + 1);
	for (ll i = 1; i <= n; i++) vis[e[i].id] = 1, ans += e[i].v;
	for (ll i = 1; i <= n; i++)
	{
		if (vis[i] && vis[i + n])
		{
			cout << ans << endl;
			return 0;
		}
		if (vis[i]) cnt1++, dif1 += b[i] - a[i];
		if (vis[i + n]) cnt2++, dif2 += a[i] - b[i];
	}
	if (cnt1 == 0 || cnt2 == 0)
	{
		cout << ans << endl;
		return 0;
	}
	cmp = inf;
	cmp = min(cmp, ans + dif1);
	cmp = min(cmp, ans + dif2);
	for (int i = 1; i <= n; i++)
	{
		int tar = n + 1;
		if (e[tar].id == e[i].id + n || e[tar].id + n == e[i].id) tar++;
		cmp = min(cmp, ans + e[tar].v - e[i].v);
	}
	cout << cmp << endl;
	return 0;
}


Measured memory_bytes: 6528
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n, m;
		int s, g;
		int barData[][];

		n = sc.nextInt();
		while (n != 0) {
			s = sc.nextInt();
			g = sc.nextInt();
			m = sc.nextInt();
			barData = new int[m][n - 1];
			for (int i = 0; i < m; i++) {
				String st = sc.next();
				for (int j = 0; j < n - 1; j++) {
					barData[i][j] = st.charAt(j) - '0';
				}
			}
			if (check(s, g, n, m, barData)) {
				System.out.println("0");
				n = sc.nextInt();
				continue;
			}
			boolean flag = true;
			for (int i = 0; i < m && flag; i++) {
				for (int j = 0; j < n - 1 && flag; j++) {
					if (barData[i][j] == 1) {
						continue;
					} else {
						boolean left = false;
						boolean right = false;
						if (j == 0 || barData[i][j - 1] == 0) {
							left = true;
						}
						if (j == n - 2 || barData[i][j + 1] == 0) {
							right = true;
						}
						if (left && right) {
							barData[i][j] = 1;
							if (check(s, g, n, m, barData)) {
								System.out.println((i + 1) + " " + (j + 1));
								flag = false;
							}
							barData[i][j] = 0;
						}
					}
				}
			}
			if (flag) {
				System.out.println("1");
			}
			n = sc.nextInt();
		}
	}

	public static boolean check(int s, int g, int n, int m, int barData[][]) {
		int x = s;
		for (int i = 0; i < m; i++) {
			if (x - 1 < n - 1 && barData[i][x - 1] == 1) {
				x++;
			} else if (0 <= x - 2 && barData[i][x - 2] == 1) {
				x--;
			}
		}
		if (x == g) {
			return true;
		} else {
			return false;
		}
	}
}

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

const int MAXN = 2010;
int head[MAXN], nxt[MAXN << 1], to[MAXN << 1], tot;
void addedge(int b, int e) {
	nxt[++tot] = head[b]; to[head[b] = tot] = e;
	nxt[++tot] = head[e]; to[head[e] = tot] = b;
}
int dp[MAXN], d2[MAXN], sz[MAXN], n;
char buf[MAXN];
void dfs(int u, int fa = 0, int dep = 0) {
	int ma = 0, mt = 0;
	sz[u] = buf[u] & 1;
	d2[u] = 0;
	for (int i = head[u]; i; i = nxt[i])
		if (to[i] != fa) {
			dfs(to[i], u, dep + 1);
			sz[u] += sz[to[i]];
			dp[to[i]] += sz[to[i]];
			d2[to[i]] += sz[to[i]];
			d2[u] += d2[to[i]];
			if (dp[to[i]] > ma) ma = dp[to[i]], mt = d2[to[i]];
			if (dp[to[i]] == ma) mt = std::min(mt, d2[to[i]]);
		}
	if (ma <= d2[u] - mt) dp[u] = d2[u] & 1;
	else dp[u] = ma + mt - d2[u];
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> buf + 1;
	for (int i = 1, t1, t2; i < n; ++i) {
		std::cin >> t1 >> t2;
		addedge(t1, t2);
	}
	int ans = 0x3f3f3f3f;
	for (int i = 1; i <= n; ++i)
		dfs(i), dp[i] || (ans = std::min(ans, d2[i]));
	std::cout << (ans == 0x3f3f3f3f ? -2 : ans) / 2 << std::endl;
	return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int d=sc.nextInt();

		int i=0;
		while(true) {
			if(i%2==0) {
				c -= b;
			}else {
				a -= d;
			}
			if(c<=0) {
				System.out.println("Yes");
				break;
			}
			if(a<=0) {
				System.out.println("No");
				break;
			}
			i++;
		}
		sc.close();
	}


}

Measured memory_bytes: 35772
#include <stdio.h>
                                                                                                
  
int main(void){
                                                                                                
   
    int n, i;
   
    int s = 0;
   
      
    scanf("%d", &n );
   
    for( i = 1 ; i <= n ; i = i + 1 ){

         s += i;

         }
   

    printf("%d\n", s );


    return 0;
                                                          
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define Nmax 200010
inline int lowbit(int x)
{
	return x&-x;
}

int ls[2][Nmax];
long long N;
int Q;
long long ans;
void adin(int *A, int x, int y)
{
	for (int i = x; i <= N; i += lowbit(i))
		A[i] = min(A[i], y);
}
int qin(int *A, int x)
{
	int as = N+1;
	for (int i = x; i; i -= lowbit(i))
		as = min(as, A[i]);
	return as;
}
int main()
{
	scanf("%lld %d", &N, &Q);
	ans = (N-2)*(N-2);
	for (int i = 0; i < 2; i++)
	{
		for (int j = 1; j <= N; j++)
			ls[i][j] = N+1;
	}
	adin(ls[0], 1, N);
	adin(ls[1], 1, N);
	int a, b;
	int q;
	int x, y;
	for (int i = 0; i < Q; i++)
	{
		scanf("%d %d", &a, &b);
		q = qin(ls[a-1], N-b+1);
		ans -= q-2;
		if (a == 1)
		{
			x = q;
			y = b;
		}
		else
		{
			x = b;
			y = q;
		}
		adin(ls[0], N-y+1, x);
		adin(ls[1], N-x+1, y);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 5288
#include <bits/stdc++.h>
#define test(a) printf("(%3d)", a)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

const int MAXN = 5e4 + 10;

string a, b;
int i, j, cnt;
int flag1, flag2;
char str[205], tex[205];

int main (void) {
    while (~scanf("%s", str) && str[0] != '.') {
        scanf("%s", tex);
        i = j = cnt = 0;
        for (i = 0, j = 0; str[i] && tex[j]; i++, j++) {
            if (str[i] == '"') {
                flag1 = 1;
                while (str[++i] != '"') a.push_back(str[i]);
            }
            if (tex[j] == '"') {
                flag2 = 1;
                while (tex[++j] != '"') b.push_back(tex[j]);
            }
            if (flag1 && flag2) {
                cnt += (a != b);
            } else if (!flag1 && !flag2) {
                cnt += 2*(str[i] != tex[j]);
            } else {
                cnt += 2;
            }
            flag1 = flag2 = 0;
            a.clear(),b.clear();
            if (cnt >= 2) break;
        }
        if (str[i]) {
            cnt += 2;
        } else if (tex[j]) {
            cnt += 2;
        }
        if (cnt >= 2) printf("DIFFERENT\n");
        else if (cnt == 1) printf("CLOSE\n");
        else printf("IDENTICAL\n");
    }
    return 0;
}


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

#define IOS cin.tie(0);ios_base::sync_with_stdio(false)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vs      vector<string>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)    for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
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(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 200;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//

signed main(){
    LCIN(N,K);
    ll ans=0;
    RepS(i,K,N+1){
        ans+=1+i*(N+1-i);
        ans%=MOD;
    }
    printf("%lld\n",ans);

    return 0;
}


Measured memory_bytes: 3764
from collections import defaultdict

N=int(input())
A=list(map(int, input().split()))

dict=defaultdict(int)

for a in A:
  dict[a]+=1
  
num=[0]*2
for v in dict.values():
  num[v%2]+=1
  
if num[0]%2==0:
  print(sum(num))
else:
  print(sum(num)-1)

Measured memory_bytes: 21976
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
 int n,s,x=0,i;
 cin>>n;
 
 int a[101]={0};
 for (i=1;i<=n;i++)
  {cin>>s;
   a[s]=1;
  }
  
  for(i=1;i<=100;i++)
  x+=a[i];
  
  cout<<x<<endl; 
 return 0;
}

Measured memory_bytes: 256
//問題やり直し
#include <iostream>
#include <string>
using namespace std;

typedef struct{           /* _person がタグ名 */
    int x,y,t;               /* 整数型メンバ age */
} acord_t;

int main(void)
{
  int N;
  cin >> N;
  acord_t point[N];
  for(int i=0; i<N; i++){
    cin >> point[i].t;
    cin >> point[i].x;
    cin >> point[i].y;
  }

  for(int j=0; j<N; j++){
    // cout << "fucnk";
    int x_dis,y_dis,t_dis;
    if(j==0){
      x_dis = point[j].x;
      y_dis = point[j].y;
      t_dis = point[j].t;
    }else{
      x_dis = point[j].x - point[j-1].x;
      y_dis = point[j].y - point[j-1].y;
      t_dis = point[j].t - point[j-1].t;
    }

    int x_front,x_back,y_front,y_back;
    //x_back+y_back=1/2{t_dis-x_dis-y_dis}
    if((t_dis-x_dis-y_dis) %2 != 0){
      cout << "No\n";
      return 0;
    }
    int x_back_min, y_back_min;
    if(x_dis>0) x_back_min = 0;
    else x_back_min = -x_dis;
    if(y_dis>0) y_back_min = 0;
    else y_back_min = -y_dis;
    if(x_back_min+y_back_min > (t_dis-x_dis-y_dis)/2){
      cout << "No\n";
      return 0;
    }
    // if(abs(x_dis)+abs(y_dis) > t_dis){
    //   cout << "No\n";
    //   return 0;
    // }
  }

  cout << "Yes\n";
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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; }

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n+m, INT_MAX), b(n+m, INT_MAX);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];

  vector<ll> sum1(n+1), sum2(m+1);
  rep(i, n) sum1[i+1] = sum1[i] + a[i];
  rep(i, m) sum2[i+1] = sum2[i] + b[i];
  ll maxv = 0;
  for (ll i = 0; i < n+1; ++i) {
    ll count = i;
    ll rem = k - sum1[count];
    if(rem < 0) continue;
    ll ind = upper_bound(ALL(sum2), rem) - sum2.begin();
    ind--;
    chmax(maxv, ind+count);
  }
  // print(sum1);
  // print(sum2);
  cout << maxv << endl;
}


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

int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    bool water[30];
    fill(water, water+30, false);
    water[0] = true;
    for (int i = 0; i < 30; i++) {
        if (water[i]) {
            if (i+A < 30) water[i+A] = true;
            if (i+B < 30) water[i+B] = true;
        }
    }

    bool sugar[3000];
    fill(sugar, sugar+3000, false);
    sugar[0] = true;
    for (int i = 0; i < 3000; i++) {
        if (sugar[i]) {
            if (i+C < 3000) sugar[i+C] = true;
            if (i+D < 3000) sugar[i+D] = true;
        }
    }

    int w=A, s=0;
    double concentration=0.0;
    for (int i = 1; i < 30; i++) {
        for (int j = 0; j < 3000; j++) {
            if (water[i] && sugar[j]) {
                if (i*100+j <= F && i*E >= j && concentration < (double)100*j/(double)(i*100+j)) {
                    w = i;
                    s = j;
                    concentration = (double)100*j/(double)(i*100+j);
                }
            }
        }
    }

    cout << w*100+s << " " << s << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

class UnionFind {
    int cnt;
    vector<int> par, rank, size;
public:
    UnionFind() {}
    UnionFind(int _n) :cnt(_n), par(_n), rank(_n), size(_n, 1) {
        for (int i = 0; i<_n; ++i) par[i] = i;
    }
    int find(int k) {
        return (k == par[k]) ? k : (par[k] = find(par[k]));
    }
    int operator[](int k) {
        return find(k);
    }
    int getSize(int k) {
        return size[find(k)];
    }
    void unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return;
        --cnt;
        if (rank[x] < rank[y]) {
            par[x] = y;
            size[y] += size[x];
        } else {
            par[y] = x;
            size[x] += size[y];
            if (rank[y] == rank[x]) ++rank[x];
        }
    }
    int count() {
        return cnt;
    }
};

int H, W, vis[10001];
string S[101];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    cin >> H >> W;

    map<char, int> B;
    rep(y, H) {
        cin >> S[y];
        each(c, S[y])B[c]++;
    }

    vi X;
    each(p, B)X.push_back(p.second);

    UnionFind uf(H*W);
    rep(y, H)rep(x, W / 2)uf.unite(y*W + x, y*W + W - 1 - x);
    rep(x, W)rep(y, H / 2)uf.unite(y*W + x, (H - 1 - y)*W + x);

    vi cnt(5);
    rep(i, H*W) if(!vis[uf[i]]++){
        cnt[uf.getSize(i)]++;
    }

    for (int i = 4; i >= 1; --i) if(cnt[i]){
        int j = 0;

        for (; j < sz(X) && cnt[i]>0; ++j) {
            if (X[j] >= i) {
                X[j] -= i;
                cnt[i]--;
                --j;
            }
        }
        if (cnt[i] > 0) {
            cout << "No" << endl;
            RT 0;
        }
    }

    cout << "Yes" << endl;
}

/**
HxW

'a'<=a[i][j]<='z'
1<=H,W<=100
**/

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (i == a[a[i - 1] - 1]) {
      count++;
    }
  }

  /* for (int i = 1; i < n + 1; i++) {
    for (int j = i + 1; j < n + 1; j++) {
      if (a[i] == j && a[j] == i) count++;
    }
  } */

  cout << count / 2 << endl;
}

//問題の概要
// ある数列が与えられます、i<jのときa[i] == j && a[j] ==
// iとなるのはいくつありますか?


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

int main()
{
  int n,c;
  long long wait,sum;
  multiset<int> customer;
  multiset<int>::iterator it;
  while(cin>>n,n){
    customer.clear();
    while(n-->0){cin>>c;customer.insert(c);}
    wait=sum=0;
    for(it=customer.begin();it!=customer.end();it++){
      wait+=*it;
      sum+=wait;
    }
    cout<<sum-wait<<endl;
  }
}

Measured memory_bytes: 0