akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define R cin>>
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
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;}
template<typename T> void co(T e){cout << e << "\n";}
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}
ll gcd(ll a, ll b) {
    if (a < b)swap(a, b);
    if (b == 0) return a;
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a * b / g;
}
bool prime(ll n) {
    for (ll i = 2; i <= sqrt(n); i++) {
        if (n%i == 0)return false;
    }
    return n != 1;
}

Vec fac, finv;

ll PowMod(ll a, ll n){
    if(n == 1) return a;
    if(n%2 == 0) return PowMod(a*a%MOD, n/2);
    return a*PowMod(a*a%MOD, n/2)%MOD;
}

ll combi(ll n, ll k){
    if(k>n) return 0;
    return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

int main(){
    string s;
    R s;
    int flg=0, cnt=0;
    if(s[0]!='A')flg=1;
    for(char c:s.substr(2, s.size()-3))if(c=='C')cnt+=1;
    if(cnt!=1)flg=1;
    for(char c:s)if(c!='A'&&c!='C'&&isupper(c))flg=1;
    if(flg)co("WA");
    else co("AC");
}

Measured memory_bytes: 256
#include <stdio.h>
  
int main(){
    int countTable[256] = {0};
    char ch;
  
    while((ch = getchar()) != EOF){
                countTable[ch]++;
    }
    for(int i = 97; i <=122;i++)printf("%c : %d\n",i,countTable[i]+countTable[i-32]);
}


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

using namespace std;

#define Vi vector<int>
#define FOR(i,s,e) for (int i=s; i<e; i++)
#define ITER(v) v.begin(), v.end()

constexpr int N_MAX = 100'000;

Vi adj[N_MAX];
int color[N_MAX];

int n;
void build_color() {
    bool isqueued[N_MAX] = {false};
    for (int i = 0, c = 0; i < n; ++i) {
        if (isqueued[i]) { continue; }
        queue<int> q;
        q.push(i);
        isqueued[i] = true;
        while (!q.empty()) {
            const int j = q.front();
            color[j] = c;
            for (const int k : adj[j]) {
                if (isqueued[k]) { continue; }
                q.push(k);
                isqueued[k] = true;
            }
            q.pop();
        }
        ++c;
    }
}

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

    int m;
    cin >> n >> m;

    int a, b;
    FOR(i,0,m) {
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    /*
    cout << "adj read." << endl;
    FOR(i,0,n) {
        for (const int j : adj[i]) {
            cout << " " << j;
        }
        cout << endl;
    }
    */
    build_color();

    int q;
    cin >> q;
    FOR(i,0,q) {
        cin >> a >> b;
        cout << (color[a] == color[b] ? "yes" : "no") << endl;
    }

    return 0;
}

Measured memory_bytes: 9164
A = []

for i in range(3):
    A.append(list(map(int, input().split())))
ans = 0
for i in range(2):
    if(A[0][i] - A[1][i] == A[0][i+1] - A[1][i+1]):
        if(A[1][i] - A[2][i] == A[1][i+1] - A[2][i+1]):
            continue
        else:
            ans=1
    else:
        ans=1

for i in range(2):
    if(A[i][0] - A[i][1] == A[i+1][0] - A[i+1][1]):
        if(A[i][1] - A[i][2] == A[i+1][1] - A[i+1][2]):
            continue
        else:
            ans = 1
    else:
        ans = 1
if(ans==1):
    print("No")
else:
    print("Yes")

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

int main(void) {
    int a;
    long long int sum = 0;
    cin >> a;
    for (int i = 1; i <= a; i++) {
        if (i % 3 == 0|| i % 5 == 0) continue;
        sum += i;
    }
    cout << sum << endl;
    
}

Measured memory_bytes: 3620
#include<iostream>
#include<cstdlib>
#include<utility>
#include<tuple>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<queue>
#include<deque>
#include<bitset>
#include<cmath>
#include<map>
#include<iomanip>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
#define rep(i, a, b) for(int i = a; i < b; i++)

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

	cout << n + 1 - i << endl;
	
	return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		sc.close();
		Arrays.sort(arr);
		
		int alice = 0;
		int bob = 0;
		
		for(int i = 0; i < n; i++) {
			int now = arr[arr.length - 1 - i];
			if(i % 2 == 0) {
				alice += now;
			}else {
				bob += now;
			}
		}
		
		System.out.println(alice-bob);
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
vector<int> v;
int n,ans=0;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		if(v.empty())
		{
			v.push_back(x);
			++ans; 
		} 
		else
		{
			if(x<=v[0])
			{
				v.insert(v.begin(),x);
				++ans;
			}
			else
			{
				int tmp=lower_bound(v.begin(),v.end(),x)-v.begin()-1;
				v.erase(v.begin()+tmp);
				v.insert(v.begin()+tmp,x);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <string>

using namespace std;

int main() {

	int a, b;
	cin >> a >> b;


	if (a >= 13) {
		cout << b << endl;
	}
	else if (a >= 6 && a <= 12) {
		cout << b / 2 << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        A: [i64; N],
    }
    let mut sum = vec![0;N];
    sum[0] = A[0];
    for i in 1..N{
        sum[i] = sum[i-1]+A[i];
    }
    sum.push(0);
    
    let mut ans:i64 = 0;
    let mut map = BTreeMap::new();
    for s in sum{
        *map.entry(s).or_insert(0) += 1;
        ans += map[&s]-1;
    }
    println!("{}",ans);
}

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


int main(void)
{
	double N, M;

	while(scanf("%lf%lf", &N, &M)==2)
	{
		if(N*2>=M) printf("%.0f\n", floor(0.5*M));
		else printf("%.0f\n", N+floor((M-(2*N))*0.25));
	}

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define U [1<<17]={}
#define G(a)((c=A[a]+A[P[a]]+C[a])%k?c:0)
typedef long long L;using namespace std;map<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p;char s U;
L D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)
    d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;}
L M(L i){return i?B[i]+M(i^i&-i):0;}
L S(L x,L i){for(x=G(x)+M(i++)-M(i);i<1e5;i+=i&-i)B[i]+=x;}
L K(L a){p=X[a];n=X[b];return p-n?E[p]<E[n]?swap(p,n),swap(a,b),0:0,M(O[a])-M(O[p])+G(p)+K(P[p]):abs(M(O[a])-M(O[b]));}
main(){for(cin>>n>>k;++p<n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;
       for(D(b=p=0);p<n;p++)if(!p|H[P[p]]-p)for(a=p;!b|a;S(a=H[a],O[a]=b++))X[a]=p;
       for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a?S(a,O[a]-1):0);}

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

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

    int p = count(s.begin(), s.end(), '1');
    int rp = 0, rn = 0;
    for (char c : s) {
        (rp *= 2) %= (p + 1);
        if (p > 1) (rn *= 2) %= (p - 1);
        if (c == '1') {
            (rp += 1) %= (p + 1);
            if (p > 1) (rn += 1) %= (p - 1);
        }
    }

    reverse(s.begin(), s.end());
    vector<int> ans;
    int twop = 1, twon = 1;

    rep(i, n) {
        int r;
        if (s[i] == '0')
            r = (rp + twop) % (p + 1);
        else {
            if (p == 1) {
                ans.push_back(0);
                continue;
            }
            r = (rn - twon + p - 1) % (p - 1);
        }

        int cnt = 1;
        while (r > 0) {
            r %= __builtin_popcount(r);
            cnt++;
        }
        ans.push_back(cnt);

        (twop *= 2) %= (p + 1);
        if (p > 1) (twon *= 2) %= (p - 1);
    }

    reverse(ans.begin(), ans.end());
    for (auto x : ans) cout << x << endl;
    return 0;
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define MAXN 105

using namespace std;
typedef long long ll;

int N, a[MAXN], cnt, ans;

int main ()
{
	cin >> N;
	for ( int i = 0; i < N; i++ )
		cin >> a[i];
	
	for ( int i = 1; i < N; i++ )
	{
		if ( a[i] == a[i - 1] )
			cnt++;
		else
		{
			cnt++;
			ans += floor((double)(cnt) / 2.0);
			cnt = 0;
		}
	}
	cnt++;
	ans += floor((double)cnt / 2.0);
	cout << ans << "\n";
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

ll niz[1000005];
ll res[1000005];

int main(){
    ios_base::sync_with_stdio(false);
	cout.precision(10);
	cout << fixed;

    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> niz[i];
    }
    int i = 1;
    while(1){
        i += 2;
        if(i-n == 1) break;
        if(i > n){
            i -= n;
            res[i] = res[n] + 2*(niz[1]-niz[n]);
        }
        else{
            res[i] = res[i-2] + 2*(niz[i-1]-niz[i-2]);
        }
    }
    int k = (2*niz[1] - res[2])/2;
    for(int i=1; i<=n; i++){
        cout << res[i]+k << " ";
    }
    return 0;
}


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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >>d;
    if (abs(a-c)<=d) cout << "Yes";
    else if(abs(a-b)<=d && abs(b-c)<=d) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long 



int main() {
  ll n,x;
  cin>>n>>x;
  ll a[n];
  for(ll i=0;i<n;i++)
  {
    cin>>a[i];
  }
  ll d=0,i=0,c=1;
  while((d+a[i])<=x && i<n)
  {
        d=a[i]+d;
        //cout<<"d "<<d<<endl;
        i++;
        c++;
  }
  cout<<c<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#define N 55
using namespace std;
int n,m,ans;
int vis[N],low[N],dfn[N];
vector<int>g[55];
void dfs(int u,int p)
{
    static int cont=0;
    low[u]=dfn[u]=++cont;
    int child=0;
    vis[u]=1;
    for(int x:g[u])
    {
        if(vis[x]==0)
        {
            child++;
            dfs(x,u);
            low[u]=min(low[u],low[x]);
            if(low[x]>dfn[u])
            {
  //              printf("(%d %d)",u,x);
                ans++;
            }


        }
        else if(x!=p)
        {
            low[u]=min(low[u],dfn[x]);
        }
    }
//    if(u==1&&child==1)
//        ans++;
}
int main()
{
    int be,en;
    cin>>n>>m;
    //init
    ans=0;
    memset(vis,0,sizeof(vis));
    for(int i=0;i<m;i++)
    {
        cin>>be>>en;
        g[be].push_back(en);
        g[en].push_back(be);
    }
    dfs(1,1);

    for(int i=1;i<=n;i++)
    {
 //       printf("%d (low :%d)(dfn:%d)\n",i,low[i],dfn[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(System.Console.ReadLine());
            string[] s = new string[n];
            int ans = 0, count = 0;
            for(int i = 0; i < n; i++)
            {
                s[i] = System.Console.ReadLine();
            }
            int m = int.Parse(System.Console.ReadLine());
            string[] _s = new string[m];
            for(int i = 0; i < m; i++)
            {
                _s[i] = System.Console.ReadLine();
            }
            for(int i = 0; i < n; i++)
            {
                for(int j = 0; j < n; j++)
                {
                    if (s[i] == s[j]) count++;
                }
                for(int j = 0; j < m; j++)
                {
                    if (s[i] == _s[j]) count--;
                }
                if (count > ans)
                {
                    int tmp = ans;
                    ans = count;
                    count = tmp;
                }
                count = 0;
            }
            System.Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
import heapq
N,M=map(int,input().split())
A=tuple(map(int,input().split()))
l=[(-i,i) for i in A]
heapq.heapify(l)
for _ in range(M):
    m=heapq.heappop(l)
    heapq.heappush(l,(-(m[1]//2),m[1]//2))
a=0
for i in l:
    a+=i[1]
print(a)

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

int main(){
  int n, m;
  std::cin >> n >> m;
  int l[m], r[m];
  for(int i = 0; i < m; i++)
    std::cin >> l[i] >> r[i];
  
  int max_l = l[0];
  int min_r = r[0];

  for(int i = 1; i < m; i++){
    if(max_l < l[i]) max_l = l[i];
    if(r[i] < min_r) min_r = r[i];
  }

  int ret = min_r - max_l +1;
  if(ret < 0) ret = 0;

  std::cout << ret << std::endl;

  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#define N 101

int n;
int G[N][N], H[N], f[N], d[N];
int t = 0;

void DFS(int a)
{
  int i;
  for(i = 1; i <= n; i++){
    if (G[a][i] == 1 && H[i] == 0) {
      t++;
      d[i] = t;
      H[i] = 1;
      DFS(i);
    }
  }
  t++;
  f[a] = t;
}

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

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

  for(i = 1; i <= n; i++) {
    if (H[i] == 0){
      t++;
      d[i] = t;
      H[i] = 1;
      DFS(i);
    }
  }

  for(i = 1; i <= n; i++)
     printf("%d %d %d\n", i, d[i], f[i]);

  return 0;
}

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

int main() {
  int Ntot, Nsort;
  cin >> Ntot >> Nsort;

  vector<int> data(Nsort);
  for(int i=0; i<Nsort; i++){
    cin >> data.at(i);
  }
  sort(data.begin(), data.end(), greater<int>());

  int Nminor= Ntot- data.at(0);
  int ans= max(0, data.at(0)- 1- Nminor);

  cout << ans << endl;
}

Measured memory_bytes: 3620
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    immutable long MOD = 998244353;
    
    auto S = readln.chomp;
    auto A = S.map!(c => (c - 'a').to!int).array;
    auto N = S.length.to!int;

    if (N.iota.map!(i => S[i] == S[0]).all) {
        1.writeln;
        return;
    }

    
    if (N <= 3) {
        S.brute_force.writeln;
        return;
    }

    auto dp = new long[][][][](N+1, 3, 4, 2); // i, mod3, 1つ前の文字, 1度でも連続したか
    dp[0][0][0][0] = 1;

    foreach (i; 0..N) 
        foreach (a; 0..3) 
            foreach (b; 0..3) 
                foreach (c; 0..2) 
                    foreach (d; 0..3) 
                        (dp[i+1][(a+d)%3][d][c||(b==d&&i!=0)] += dp[i][a][b][c]) %= MOD;

    long ans = (N-1).iota.map!(i => A[i] != A[i+1]).all;
    foreach (b; 0..3) (ans += dp[N][A.sum%3][b][1]) %= MOD;
    ans.writeln;
}

int brute_force(string S) {
    int N = S.length.to!int;
    bool[string] mem;
    
    void dfs(string s) {
        if (s in mem) return;
        mem[s] = true;
        
        foreach (i; 0..N-1) {
            if (s[i] == s[i+1]) continue;
            auto t = s.to!(dchar[]);
            if (s[i] + s[i+1] == 'a' + 'b') t[i] = t[i+1] = 'c';
            if (s[i] + s[i+1] == 'b' + 'c') t[i] = t[i+1] = 'a';
            if (s[i] + s[i+1] == 'c' + 'a') t[i] = t[i+1] = 'b';
            dfs(t.to!string);
        }
    }

    dfs(S);
    return mem.keys.length.to!int;
}


Measured memory_bytes: 175544
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, K, x = 1;
    cin >> N >> K;
    for(int i = 0; i < N; i++) {
        if(x > K) {
            x += K;
        } else {
            x *= 2;
        }
    }
    cout << x << endl;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
d = {1 : 0, 2 : 0, 4 : 0}
for i in a:
    if i % 4 == 0:
        d[4] += 1
    elif i % 2 == 0:
        d[2] += 1
    else:
        d[1] += 1
if d[1] <= d[4]:
    print("Yes")
elif d[1] - d[4] == 1 and d[2] == 0:
    print("Yes")
else:
    print("No")

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

using namespace std;

void call(int n) {
	for (int i = 1; i <= n; ++i) {
		if (i % 3 == 0) {
			cout << ' ' << i;
		} else {
			int x = i;
			while (x) {
				if (x % 10 == 3){
					cout << ' ' << i;
					break;
				}
				x /= 10;
			}
		}
	}
	cout << endl;
}

int main() {
	int n;
	cin >> n;
	call(n);
}


Measured memory_bytes: 3064
n, y = map(int, input().split())
cost = 0
remain = 0
for i in range(0,n+1):
        for j in range(0,n+1):
                remain = n - i - j
                cost = 10000*i + 5000*j + 1000*remain
                if cost == y and remain >= 0:
                        print("{} {} {}".format(i, j, remain))
                        exit()
print("-1 -1 -1")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;

const ll INF = 5e15;
const ll MOD = 1e9 + 7;

int main() {
    long double T, X;
    cin >> T >> X;
    printf("%.20Lf\n", T / X);
    return 0;
}


Measured memory_bytes: 256
N,K=map(int, input().split(" "))

out=0
if K==0:
    print(N*N)

else:
    for i in range(N):
        row=N-i
        if row <= K or row ==0:
            break
        out += (N-i-K) * int(N/row)
        if N%row >= K:
            out+=N%row-K+1

    print(out)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define deb(x) cout<<#x<<" is "<<x<<endl;
typedef long long ll;
using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    for(int i=0;i<n;i++)   
        cin>>a[i];
    //dp[i][j] indicates who wins the game when starting with "i" coins and turn of player j is there
    int dp[k+1][2];
    
    for(int i=0;i<=k;i++)
    {
        int li=upper_bound(a.begin(),a.end(),i)-a.begin();
        
        dp[i][0]=1;
        dp[i][1]=0;
        
        for(int p=0;p<li;p++)
        {
            dp[i][0]=min(dp[i][0],dp[i-a[p]][1]);
            dp[i][1]=max(dp[i][1],dp[i-a[p]][0]);
        }

        // cout<<i<<" "<<dp[i][0]<<" "<<dp[i][1]<<endl;
    }

    cout<<(dp[k][1] ? "First" : "Second")<<endl;

}

Measured memory_bytes: 4392
A, B, C, D = gets.split.map(&:to_i)

Div_C = B/C - A/C + (A%C == 0 ? 1 : 0)
Div_D = B/D - A/D + (A%D == 0 ? 1 : 0)

CD = C.lcm(D)

Div_CD = B/CD - A/CD + (A%CD == 0 ? 1 : 0)

STDERR.puts "B/C: #{B/C}, A/C #{(A - 1)/C}"
STDERR.puts "Div_C: #{Div_C}, Div_D: #{Div_D}, Div_CD: #{Div_CD}"

p B - A + 1 - (Div_C + Div_D - Div_CD)


Measured memory_bytes: 1916
n=int(input())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

a=factorization(n)

l=len(a)
ans=l
c=1
for i in range(l):
    a[i][1]-=1

while(c<100):
    c+=1
    for i in range(l):
        if a[i][1]>=c:
            a[i][1]-=c
            ans+=1
if n!=1 and n!=0:
    print(ans)
else:
    print(0)
            

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

int main(){
	int a,b,c,x,y;
	scanf("%d%d%d%d%d",&a,&b,&c,&x,&y);
	double A=(double)a/2,B=(double)b/2,C=c;
	long long cost=0;
	if(C<A+B){
		int dum=min(x,y);
		int banyak=dum*2;
		cost+=banyak*C;
		y-=dum;
		x-=dum;
		if(y<0)y=0;
	}
	if(x){
		if(A<C)
		cost+=x*a;
		else
		cost+=x*2*c;
	}
	if (y){
		if(B<C)
		cost+=y*b;
		else
		cost+=y*2*c;
	}
	printf("%lld\n",cost);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define int long long
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
constexpr int INF = 1000000000000000000LL;
template<typename A, typename B> bool cmin(A &a, const B &b) { return b < a ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }

signed main() {
  int N, W;
  cin >> N >> W;
  vector<int> v(N), w(N);
  rep(i, N) cin >> v[i] >> w[i];
  int mid = N / 2;
  vector<pair<int, int>> left;
  rep(i, 1 << mid) {
    int sv = 0, sw = 0;
    rep(j, mid) if (i >> j & 1) sv += v[j], sw += w[j];
    left.emplace_back(sw, -sv);
  }
  sort(all(left));
  loop(i, 1, left.size()) cmin(left[i].second, left[i - 1].second);
  int maxi = 0;
  rep(i, 1 << (N - mid)) {
    int sv = 0, sw = 0;
    rep(j, N - mid) if (i >> j & 1) sv += v[j + mid], sw += w[j + mid];
    if (sw > W) continue;
    auto p = lower_bound(all(left), make_pair(W - sw, -INF));
    if (p == left.end()) --p;
    if (p->first + sw > W) --p;
    cmax(maxi, -p->second + sv);
  }
  cout << maxi << endl;
}



Measured memory_bytes: 19436
a, b, k = map(int, input().split())
for i in range(k):
    if i % 2 == 0:
        if a % 2 == 1:
            a = (a - 1) // 2
        else:
            a = a // 2
        b = b + a
    else:
        if b % 2 == 1:
            b = (b - 1) // 2
        else:
            b = b // 2
        a = b + a
print(a, b)

Measured memory_bytes: 3060
//created by missever

#include<bits/stdc++.h>
#define MAX 1000000007
using namespace std;
typedef long long LL;

char s[100005];

int main(){
    int n,k;
    scanf("%s",s);
    n = strlen(s);
    if(n & 1)
    {
        if(s[0] == s[n - 1]) k = 2;
        else k = 1;
    }
    else
    {
        if(s[0] == s[n - 1]) k = 1;
        else k = 2;
    }
    if(k == 1) printf("First\n");
    else printf("Second\n");
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
#define S set<int>
#define itn int
bool dbg = false;
itn N, K, h[101010];
void solve() {
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    itn ans = 0;
    cin >> N >> K;
    FOR(i, 0, N) {
        itn a;
        cin >> a;
        if (a >= K) {
            ans++;
        }
    }
    cout << ans << endl;
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define NUM_MAX 2000
#define LEN_MAX 1000
#define NUM2_MAX (NUM_MAX*(NUM_MAX-1)/2)
#define BUF_SIZE (NUM_MAX*5+100)

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}


// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
#ifdef BUF_SIZE
    char line[BUF_SIZE];
    char *tmpbuf = line;
    int i;
    if(!fgets(line, BUF_SIZE, stdin)) return -1;
    for(i = 0; i < size; i++) {
        char *tmp = strtok(tmpbuf, " ");
        arr[i] = strtol(tmp, NULL, 10);
        tmpbuf = NULL;
    }
#else
#error
#endif
    return 0;
}

int asc(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

int lower_bound(int *arr, int size, int key) {
    int low = -1;
    int high = size;
    while(low + 1 < high) {
        int middle = (low+high)/2;
        if(arr[middle] > key) {
            high = middle;
        } else {
            low = middle;
        }
    }
    return high;
}

int main(void) {
    int num = get_int();
    int arr[NUM_MAX];

    fget_array(arr, num);
    qsort(arr, num, sizeof(int), asc);
    int i, j;

    int cnt = 0;
    // In this time, len<=1000 is very small, so it's enough to use map
    static int map[LEN_MAX*2+1];
    for(i = 2; i < num; i++) {
        int pivot = arr[i];
        for(j = 0; j < i-1; j++) {
            map[arr[i-1] + arr[j]]++;
        }
        // a < b+c (s.t. a>b>c)
        for(j = pivot+1; j <= LEN_MAX*2; j++) {
            cnt += map[j];
        }
    }
    printf("%d\n", cnt);
    return 0;
}


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

const int MAX_N = 100;
const int MAX_V = 1000;
const int MAX_W = 1000;
const int MAX_C = 10000;

int N, C;
int V[MAX_N+1], W[MAX_N+1];
int dp[MAX_N+1][MAX_C+1];

int res() {
  for (int i = 0; i <= N; i++) dp[i][0] = 0;
  for (int j = 0; j <= C; j++) dp[0][j] = 0;
  
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= C; j++) {
      if (j < W[i]) {
        dp[i][j] = dp[i-1][j];
      } else {
        dp[i][j] = max(dp[i-1][j], max(dp[i-1][j-W[i]] + V[i], dp[i][j-W[i]] + V[i]));
      }
    }
  }
  
  return dp[N][C];
}

int main(void){
    cin >> N >> C;
    for (int i = 1; i <= N; i++) cin >> V[i] >> W[i];
    V[0] = W[0] = 0;
    
    cout << res() << endl;
    
    return 0;
}

Measured memory_bytes: 5108
Q,H,S,D = map(int,input().split())
N = int(input())
N *= 100
H = min(H,2*Q)
S = min(S,2*H)
D = min(D,2*S)
ans = 0
if N%200 != N:
  ans += (N//200)*D
  N %= 200
if N%100 != N:
  ans += (N//100)*S
  N %= 100
if N%50 != 50:
  ans += (N//50)*H
  N %= 50
if N%25 != N:
  ans += (N//25)*Q
  N %= 25
if N == 0:
  print(ans)

Measured memory_bytes: 3064
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4.2")
#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define PB push_back
#define PI acos(-1)
#define all(x) x.begin(),x.end()
#define vi vector<ll>
#define ii pair<ll,ll>
#define vii vector<ii>
#define vb vector<bool>
#define vvi vector<vector<ll> >
#define vvii vector<vii>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define read(x) long long x;cin>>x;
#define FOR(a,b,c,d) for(int a=b;a<=c;a+=d)
#define MP make_pair
#define F first
#define AS assign
#define S second
#define debug(x) cout<<(#x)<<": "<<(x)<<"\n"
#define SZ(x) x.size()
#define mod 1000000007
#define lg2(x) 63-(__builtin_ctzll(x))
#define RZ resize
#define IN insert
#define X real()
#define Y imag()
#define FBO find_by_order
#define OFK order_of_key
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
typedef unsigned long long ull;
typedef long double d64;
typedef complex<d64>P;
ll modpow(int a,int b,int m){if(!b)return 1%m;ll u=modpow(a,b/2,m);u=(u*u)%m;if(b&1)u=(u*a)%m;return u;}



int main(){
read(n);
string a,b,s;cin>>s;
if(n%2==1)cout<<"No";
else if(n%2==0){
  for(int i=0;i<n/2;i++){
    a+=s[i];
  }
  for(int i=n/2;i<n;i++){
    b+=s[i];
  }
  if(a==b)cout<<"Yes";
  else cout<<"No";
}
return 0;
}




Measured memory_bytes: 3508
import sys
def input():
    return sys.stdin.readline()[:-1]
N,K=map(int,input().split())
p=list(map(int, input().split()))
t=sum(p[:K])
M=(t+K)/2
for i in range(N-K):
    t-=p[i]
    t+=p[i+K]
    M=max(M,(t+K)/2)
print(M)

Measured memory_bytes: 25172
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int maxcount = 0;
		int ans = 1;
		for(int i = 1; i <= N; i++) {
			int a = i;
			int count = 0;
			while(a%2 == 0 && i >= 1) {
				a /= 2;
				count++;
			}
			if(count > maxcount) {
				maxcount = count;
				ans = i;
			}
		}
		System.out.println(ans);

	}

}

Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int A, B, C; cin >> A >> B >> C;
  if (C >= A && C <= B) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
a=int(input())
b=int(a/1.08)
c=int(b*1.08)
if c==a:
    print(b)
else:
    c=int((b+1)*1.08)
    if a==c:
        print(b+1)
    else:
        c=int((b-1)*1.08)
        if a==c:
            print(b-1)
        else:
            print(":(")

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
	int N;
	string S;
	cin >> N >> S;
	int ans = 0;
	fx(N) {
		ans++;
		while (x+1<N&&S[x]==S[x+1]) {
			x++;
		}
	}
	ce(ans)
    return 0;
}



Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include <numeric>
#include<cmath>

using namespace std;

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

int main(){
    long long A,B,C,D;
    cin >> A >> B >> C >> D;
    long long AC = A/C;
    if(C*AC < A)AC++;
    long long BC = B/C;
    long long AD = A/D;
    if(D*AD < A)AD++;
    long long BD = B/D;
    long long lcm_cd = C*D/gcd(C,D);
    long long ACD = A/lcm_cd;
    if(lcm_cd*ACD < A)ACD++;
    long long BCD = B/lcm_cd;

    cout << (B-A+1)-(((BC-AC)+1) + ((BD-AD)+1) - ((BCD-ACD)+1)) << endl;
  


}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>

#define roop(i, n) for(int i=0;i<n;i++)

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ull mod = 1e9+7;
constexpr int N = 13;
ull dp[100010][N];

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	int n, d;
	cin >> n >> d;
	int ans = n / ((2 * d) + 1);
	ans += (n % ((2 * d) + 1)) != 0 ? 1 : 0;
	cout << ans << endl; 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(int argc, char *argv[]) {
	string S;
	vector<int> c(26);

	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		c[S[i] - 'a']++;
	}

	for (int i = 0; i < 26; i++) {
		if (c[i] > 0) continue;
		cout << (char)(i + 'a') << endl;
		return 0;
	}

	cout << "None" << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <algorithm>
#include <limits>
using namespace std;
 
int main(){
    int N;
    cin>>N;
    double x[N];
    string u[N];
    for(int i=0;i<N;i++)cin>>x[i]>>u[i];

    double ans=0;
    for(int i=0;i<N;i++){
        if(u[i]=="JPY")ans+=x[i];
        else ans+=380000*x[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
#include<numeric>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main()
{
  int h, w;
  cin >> h >> w;
  pair<int, int> c;
  pair<int, int> d;
  cin >> c.first >> c.second;
  cin >> d.first >> d.second;
  vector<vector<int>> s(h+1, vector<int>(w+1, 0));
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      char c;
      cin >> c;
      if (c == '#') {
        s[i][j] = INF;
      } else {
        s[i][j] = -1;
      }
    }
  }

  queue<pair<int, int>> q;

  q.push(c);
  s[c.first][c.second] = 0;

  int count = 0;
  while (!q.empty()) {
    queue<pair<int, int>> mas; // 同一カウント値で塗りつぶされたマスを管理
    while (!q.empty()) {
      pair<int, int> p = q.front();
      mas.push(p); // 同一カウント値で塗りつぶされたマスを入れる
      int x = p.first;
      int y = p.second;
      // printf("[q] %d %d\n", x, y);
      q.pop();
      if (x+1 < h+1 && s[x+1][y] == -1) {
        q.push(make_pair(x+1, y));
        s[x+1][y] = s[x][y];
      }
      if (y+1 < w+1 && s[x][y+1] == -1) {
        q.push(make_pair(x, y+1));
        s[x][y+1] = s[x][y];
      }
      if (x-1 > 0 && s[x-1][y] == -1) {
        q.push(make_pair(x-1, y));
        s[x-1][y] = s[x][y];
      }
      if (y-1 > 0 && s[x][y-1] == -1) {
        q.push(make_pair(x, y-1));
        s[x][y-1] = s[x][y];
      }
    }
    ++count;
    while (!mas.empty()) {
      pair<int, int> p = mas.front();
      mas.pop();
      int x = p.first; int y = p.second;
      // printf("[mas] %d %d\n", x, y);
      for (int i = -2; i <= 2; i++) {
        for (int j = -2; j <= 2; j++) {
          if (x+i > h || x+i < 1) continue;
          if (y+j > w || y+j < 1) continue;
          if (s[x+i][y+j] == -1) {
            s[x+i][y+j] = count;
            q.push(make_pair(x+i, y+j));
          }
        }
      }
    }
  }

  if (s[d.first][d.second] == -1 || s[d.first][d.second] == INF) {
    cout << -1 << endl;
  } else {
    cout << s[d.first][d.second] << endl;
  }
}


Measured memory_bytes: 7492
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 10;
 
int data[MAXN], n;
 
int main(){
    scanf("%d", &n);
 
    for(register int i=0; i<n; i++){
        scanf("%d", &data[i]);
    }
 
    sort(data, data+n);
 
    printf("%d", data[n-1] - data[0]);
    return 0;
}

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

int main() {
    string s, p;
    getline(cin, s);
    getline(cin, p);
    s += s;
    bool flg = false;
    REP(i, (s.size()+1)/2) if (memcmp(s.c_str()+i, p.c_str(), p.size()) == 0) flg = true;
    flg ? cout << "Yes" << endl : cout << "No" << endl;
}

Measured memory_bytes: 3232
IDENTIFICATION DIVISION.
        PROGRAM-ID. AtCoder.
      
        ENVIRONMENT DIVISION.
      
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 INP PIC X(100).
        01 A PIC 9(10).
        01 B PIC 9(10).
        01 C PIC ZZ.
	    01 temp1 PIC 9(11).
        01 temp2 PIC 9(11).
        01 N PIC 9(11).
      
        PROCEDURE DIVISION.
      	MAIN.
			ACCEPT INP.
        	PERFORM VARYING temp1 FROM 1 BY 1
            UNTIL INP(temp1:1) = SPACE
        	END-PERFORM.
        	SUBTRACT 1 FROM temp1.
        	MOVE INP(1:temp1) TO A.
        	ADD 2 TO temp1.
        	PERFORM VARYING temp2 FROM temp1 BY 1
            UNTIL INP(temp2:1) = SPACE
        	END-PERFORM.
        	COMPUTE N = temp2 - temp1.
        	MOVE INP(temp1:N) TO B.
      		COMPUTE C = A * B.
			IF A <= 9 AND B <= 9 THEN
				DISPLAY C
			ELSE 
				DISPLAY "-1"
			END-IF.
		STOP RUN.

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

#define ll long long
#define ull unsigned long long

bool isPalindrome(string s) {
    string t(s.rbegin(), s.rend());
    return s == t;
}

int main(void) {
    ll N, K;
    cin >> N >> K;
    ll mar = (N + 1) * (N + 2) / 2;
    ll sum = 0;
    ll m  = 1e9+7;
    for(ll i = K;i <= N + 1;i++) {
        ll mi = i * (i + 1) / 2;
        ll ma = mar - (N - i + 1) * (N - i + 2) / 2;
        sum += ma - mi + 1;
        sum %= m;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3648
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

def inv(a): return pow(a, MOD-2, MOD)

def comb(n,r):
    ans = 1
    for i in range(r):
        ans *= n-i
        ans *= inv(r-i)
        ans %= MOD
    return ans

n,m = imap()
ans = comb(n,2) + comb(m,2)
print(ans)


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */
int main() {


	LL a, b, c; cin >> a >> b >> c;
	LL  ret = min(c, a + b + 1);
	LL ans = ret + b;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long N = scan.nextLong();
		long A = scan.nextLong();
		long B = scan.nextLong();
		
		System.out.println(
			N * A < B ? N * A : B 
		);
		scan.close();
	}

}

Measured memory_bytes: 21716
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vl A(N);
    ll MX=0;
    bool plus=true;
    int index=0;
    rep(i,N){
        cin >> A[i];
        if(chmax(MX,abs(A[i]))){
            index=i;
            if(A[i]>0){
                plus=true;
            }
            else{
                plus=false;
            }
        }
    }//全部maxabsが大きいほうの記号にする。
    cout << 2*N-2 << endl;
    if(plus){
        rep(i,N){
            if(i!=index){
                cout << index+1 << ' ' << i+1 << endl;
            }
        }
        rep(i,N-1){
            cout << i+1 << ' ' << i+2 << endl;
        }
    }
    else{
        rep(i,N){
            if(i!=index){
                cout << index+1 << ' ' << i+1 << endl;
            }
        }
        per(i,N-2){
            cout << i+2 << ' ' << i+1 << endl;
        }
    }
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

Measured memory_bytes: 3644
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int n, tmp;
    vector<int> v1, v2;
    vector<pair<int, int> > s1, s2;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> tmp;
        if((i&1)==0){
            v1.push_back(tmp);
        }
        else{
            v2.push_back(tmp);
        }
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    int lcnt=1, cur=v1[0];
    for(int i=1;i<v1.size();i++){
        if(cur!=v1[i]){
            s1.push_back(make_pair(lcnt, cur));
            lcnt = 1;
            cur = v1[i];
        }
        else{
            lcnt++;
        }
    }
    s1.push_back(make_pair(lcnt, cur));
    s1.push_back(make_pair(0, -1));
    lcnt=1;
    cur=v2[0];
    for(int i=1;i<v2.size();i++){
        if(cur!=v2[i]){
            s2.push_back(make_pair(lcnt, cur));
            lcnt = 1;
            cur = v2[i];
        }
        else{
            lcnt++;
        }
    }
    s2.push_back(make_pair(lcnt, cur));
    s2.push_back(make_pair(0, -1));
    sort(s1.begin(), s1.end(), greater<pair<int, int> >());
    sort(s2.begin(), s2.end(), greater<pair<int, int> >());
    if(s1[0].second!=s2[0].second){
        cout << n - s1[0].first - s2[0].first << endl;
    }
    else{
        cout << n - max(s1[0].first+s2[1].first, s1[1].first+s2[0].first) << endl;
    }
}

Measured memory_bytes: 1784
//青い点を2つ取ってきて、どちらを先に使うか考察する。
//赤い点を使う順番は好きに決めることができる。
#include <iostream>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int a[100], b[100];
int c[100], d[100];
bool usedR[100];
bool usedB[100];

int main() {
	int i, j;
	
	cin >> n;
	rep(i, n) { cin >> a[i] >> b[i]; }
	rep(i, n) { cin >> c[i] >> d[i]; }
	
	int ans = 0;
	rep(i, n) {
		int idR = -1;
		rep(j, n) {
			if (usedR[j]) continue;
			if (idR == -1 || a[idR] < a[j]) idR = j;
		}
		
		int idB = -1;
		rep(j, n) {
			if (usedB[j]) continue;
			if (a[idR] > c[j] || b[idR] > d[j]) continue;
			if (idB == -1 || d[idB] > d[j]) idB = j;
		}
		
		usedR[idR] = true;
		if (idB != -1) {
			usedB[idB] = true;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int64_t n, a, b;
  cin >> n >> a >> b;
  int64_t c = n / (a + b);
  int64_t d = n % (a + b);

  cout << a * c + min(a, d) << endl;
}



Measured memory_bytes: 256
s,asi=gets.split.map(&:to_i)
i=0
if asi <= s*4
  if asi%2==0
    (0..s).each do |n|
      if n*2+(s-n)*4==asi
        puts "Yes"
        i+=1
        break
      end
    end

  end

end

if i==0
  puts "No"
end



Measured memory_bytes: 14340
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

const int mod = 1e9 + 7;

long long int mypow(long long int a, long long int b) {
	if (b == 0) return 1;
	if (b == 1) return a;
	long long int res = mypow(a, b / 2);
	res = res * res % mod;
	if (b % 2 == 1) res = res * a % mod;
	return res;
}

int main() {
	int n, m;
	cin >> n >> m;
	long long int res = 1;
	vector<long long int> fac(1, 1);
	for (int i = 1; i <= 32; i++) {
		fac.push_back(fac.back() * i % mod);
	}

	for (int i = 2; i * i <= m; i++) {
		int c = 0;
		while (m % i == 0) {
			c++;
			m /= i;
		}
		if (c > 0) {
			long long int r = 1;
			for (int a = 0; a < c; a++) {
				r = r * (a + n) % mod;
			}
			r = r * mypow(fac[c], mod - 2) % mod;
			res = res * r % mod;
		}
	}
	if (m > 1) {
		res = res * n % mod;
	}
	cout << res << endl;
}


Measured memory_bytes: 3636
import Control.Monad
import Data.List
import qualified Data.Map as M

gr = map (\x-> (head x, length x)) . group . sort

cmb ln = flip div 2 $ product $ take 2 $ iterate (subtract 1) ln

total :: [(Int, Int)] -> Int
total xs = sum $ map (cmb . snd) xs

solve xs = map (p . e) xs
  where
    g = gr xs
    t = total g
    m = M.fromList g
    e = flip M.lookup m
    p (Just ss) = t - (ss - 1)

main = do
  n <- readLn :: IO Int
  xs <- (map read . words) <$> getLine
  putStrLn $ unlines $ map show (solve xs )


Measured memory_bytes: 84348