akhauriyash/Code-Regression huggingface dataset:
// B - Time Limit Exceeded
#include <bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<(n);++i)

int main(){
	int N,T; cin>>N>>T;
	int mini = INT_MAX;
	rp(i,N){
		int c,t; cin>>c>>t;
		if(t<=T) mini = min(mini,c);
	}
	if(mini==INT_MAX) cout<< "TLE" <<endl;
	else cout<< mini <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(int)(a); i!=(int)(b); i++)
#define RFOR(i, a, b) for(int i=(int)(a); i!=(int)(b); i--)
#define REP(i, n) FOR(i, 0, n)
using namespace std;
using ll = long long;

constexpr int mod = 1e9+7;

int main(){
  int n; cin >> n;
  int a[n], b[n];
  pair<int, int> c[2*n];
  REP(i, n){
    cin >> a[i];
    c[i] = {a[i], 0};
  }
  REP(i, n){
    cin >> b[i];
    c[i+n] = {b[i], 1};
  }

  sort(c, c+2*n);

  ll ans = 1, com = 0, ele = 0;
  REP(i, 2*n){
    if(c[i].second == 0){
      if(ele >= 1){
        (ans *= ele) %= mod;
        ele--;
      }
      else{
        com++;
      }
    }
    else{
      if(com >= 1){
        (ans *= com) %= mod;
        com--;
      }
      else{
        ele++;
      }
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 2560
N = int(input())
"""
どの部分集合の共通する要素も一つだけで、各数字（１～N）は２回ずつしか出現しないことから、部分集合の数をｋとすると、
(1)と(2)の共通が１、(1)と(3)の共通が２、～、(k-1)と(k)の共通がN、のように表現でき、この中で１～Nが２回ずつ出現している。
ある部分集合がほかのk-1この部分集合と共通の値を一個ずつもつので、部分集合の要素数はk-1となる。
１～Nまで２回ずつ出てくる＆ｋ個の部分集合の要素がそれぞれ（ｋ－１）であることから、２N＝k(k-1)となる。
ｋが決まれば、上記の(1)と(2)の共通が１で～みたいな置き方をしていくだけでそれぞれの集合が決まる。
Nは10^5までなので、ｋが１０００程度の範囲までで、２N＝k(k-1)を満たすｋがあるか調べていけばよい。

公式開設動画が非常にわかりやすかった：https://www.youtube.com/watch?v=wwCqOcWkVh4
"""
k = 0
while N != k*(k-1)//2:
    k += 1
    if k == 1000:
        break

if k == 1000:
    print("No")
else:
    ans = [[] for _ in range(k)]
    cnt = 0
    for i in range(k):
        for j in range(i+1,k):
            ans[i].append(cnt+1)
            ans[j].append(cnt+1)
            cnt += 1

    print("Yes")
    print(k)
    for a in ans:
        print(k-1, *a)


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

class Program
{
    struct counter
    {
        public int cnt;
        public char word;
    }

    static void Main(string[] args)
    {
        string input = Console.ReadLine();
        List<counter> charList = new List<counter>();
        for (int i = 0; i < input.Length; i++)
        {
            bool found = false;
            counter temp;
            for (int j = 0; j < charList.Count; j++)
            {
                if (charList[j].word == input[i])
                {
                    found = true;
                    counter c;
                    c.cnt = charList[j].cnt + 1;
                    c.word = charList[j].word;
                    charList.RemoveAt(j);
                    charList.Add(c);
                    break;
                }
            }
            if (!found)
            {
                temp.word = input[i];
                temp.cnt = 1;
                charList.Add(temp);
            }
        }
        bool isBeaut = true;
        for (int i = 0; i < charList.Count; i++)
        {
            if (charList[i].cnt % 2 == 1) isBeaut = false;
        }
        Console.WriteLine((isBeaut)?"Yes":"No");
    }
}

Measured memory_bytes: 2904
s = input()
if s[0] == "A" and s[2:-1].count("C") == 1:
  index_C = s.find("C")
  if s[1:index_C].islower() and s[index_C+1:].islower():
    print("AC")
  else:
    print("WA")
else:
  print("WA")

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Integer sum = 0;
		String output = "No";

		Scanner sc = new Scanner(System.in);

		Integer n = new Integer(sc.next());
		Integer buf = n;
		ArrayList<Integer> data = new ArrayList<Integer>();

		for(int i = 0,len = String.valueOf(buf).length();i<len;i++) {
			data.add(buf%10);
			buf /= 10;
		}

		for(int i = 0; i < data.size();i++) {
			sum += data.get(i);
		}

		if((n%sum) == 0) {
			output = "Yes";
		}
		System.out.println(output);

		sc.close();
	}

}


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

answer = 0
tempvalue = 0

for i in range(n-1):
    if cells[i+1] <= cells[i]:
        tempvalue += 1
    else:
        tempvalue = 0
    if tempvalue > answer:
        answer = tempvalue

print(answer)

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

int main()
{
	std::string str;
	std::cin >> str;

	const char *cstr = str.data();

	int i = str.size() - 1, n;
	
	while (cstr[i--] != 'F');

	for (n = 0; n <= i; ++n)
	{
		std::cout << str.at(n);
	}
	std::cout << std::endl;


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int ll;
static const int MAX_N = 200000;

int N;
pair<int, int> A[MAX_N];
int main(){
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> A[i].first;
		A[i].second = i;
	}
	sort(A, A + N);
	int ans = 0;
	for(int i = 0; i < N; i++){
		int cnt = 1;
		while(i != N - 1 && A[i].second < A[i + 1].second){
			cnt++;
			i++;
		}
		ans = max(ans, cnt);
	}
	cout << N - ans << endl;
	return 0;
}


Measured memory_bytes: 1792
n,d=map(int,input().split())
l=[]
s=0
for _ in range(n):
    l.append(list(map(int,input().split())))
for i in range(n-1):
    for j in range(i+1,n):
        x=0
        for k in range(d):
            x+=(l[i][k]-l[j][k])**2
        x=x**.5
        y=int(x)
        if x==y:
            s+=1
print(s)

Measured memory_bytes: 3064
import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

a, b, c, k = map(int, input().split())

ans = 0
ans += min(k, a)
k -= a
if k <= 0:
    print(ans)
    sys.exit()

k -= b
if k <= 0:
    print(ans)
    sys.exit()

ans -= k
print(ans)


Measured memory_bytes: 65228
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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


int main()
{
  INT(K);
  int x = 7%K;
  REP(i,K+10){
    if(x==0){
      cout << i+1 << endl;
      return 0;
    }
    x=(x*10+7)%K;
  }
  cout << -1 << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    ll n; cin >> n;
    ll a[n + 1]; rep(i, 1, n)cin >> a[i];
    
    ll ans = 0;
    rep(i, 1, n){
    	if(i % 2 == 1 && a[i] % 2 == 1)ans++;
    }
    print(ans)
    
    return 0;
}

Measured memory_bytes: 3648
import math

n, h = map(int, input().split())
ab = [None] * n
for i in range(n):
    ab[i] = tuple(map(int, input().split()))

amax = max([m[0] for m in ab])

ans = 0
for a, b in sorted(ab, key=lambda m: -m[1]):
    if b <= amax:
        break
    h -= b
    ans += 1
    if h <= 0:
        print(ans)
        exit(0)

ans += math.ceil(h / amax)
print(ans)

Measured memory_bytes: 27764
s = list(input())

ans = 'AC'
length = len(s)

if s[0] != 'A':
    ans = 'WA'

s[0] = 'a'
cnum = 0

for i in range(2,length-1):
    if s[i] == 'C':
        cnum = cnum + 1
        s[i] = 'c'
#print(cnum)
if cnum != 1:
    ans = 'WA'
strs = ''.join(s)
#print(strs)

if strs.islower() == False:
    ans = 'WA'

print(ans)

Measured memory_bytes: 3064
n, m = map(int, input().split())
cities = [[i] + list(map(int, input().split())) for i in range(m)]
cities = sorted(cities, key=lambda x: (x[1], x[2]))

num = 1
pref = 0
for city in cities:
    if pref != city[1]:
        pref = city[1]
        num = 1
    city = city.append(num)
    num += 1

cities = sorted(cities, key=lambda x: x[0])

for city in cities:
    print(str(city[1]).zfill(6) + str(city[3]).zfill(6))

Measured memory_bytes: 36720
N = int(input())
A, B = map(int, input().split())
P = list(map(int, input().split()))
first = [p for p in P if p<=A]
second = [p for p in P if p>A and p<=B]
third = [p for p in P if p>B]

ans = min(len(first),len(second),len(third))

print(ans)   

#print(*ans, sep='\n')


Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define ST first
#define ND second
#define ll long long
#define ld long double
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;

const ll  INF = 1e9 + 9;
const ll  MOD = 1e9 + 7;
const long long LINF = (ll)1e18 + 3;
 
// secik.insert({x, t++});
// secik.erase(secik.lower_bound({x,-1}));
// *secik.find_by_order(x)).first << "\n";
// secik.order_of_key(x)
 
//random_device device;
//mt19937 gener(device());
//uniform_int_distribution<ll > gen(0,n-1);
//gen(gener); // generate random number

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

	int n,m,k; cin >> n >> m >> k;
	vector<vector<char> > tab(n,vector<char>(m));
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			cin >> tab[i][j];
			
	int ans = 0;
	for(int i = 0; i < (1 << m); i++){
		for(int j = 0; j < (1 << n); j++){
			int ile = 0;
			for(int a = 0; a < n; a++)
				for(int b = 0; b < m; b++){
					if(j & (1 << a)) continue;
					if(i & (1 << b)) continue;
					if(tab[a][b] == '#') ile++;
				}
			if(ile == k){
				ans++;
			}
		}
	}
	
	cout << ans;	
	
	
	
	
	
	
	
	
	
	
	

}

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

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  
  int a;
  vector<int> b;
  for(int i = 0; i < n; i++){
    cin >> a;
    for(int j = 0; j < a; j++) b.push_back(i + 1);
  }
  
  vector<vector<int>> x(h, vector<int>(w));
  int now = 0;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      x.at(i).at(j) = b.at(now);
      now++;
    }
  }
  
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(i % 2 == 0){
        if(j) cout << " ";
        cout << x.at(i).at(j);
      }
      else{
        if(j) cout << " ";
        cout << x.at(i).at(w - j - 1);
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
ll trans(ll x) {
	if (x == 0)return 0;
	if (x % (ll)2)return (ll)1;
	else return (ll)2*trans(x / (ll)2);
}
ll l; ll xsum = 0;
struct Node {
	Node *lch, *rch;
	ll h;
	Node() : lch(NULL), rch(NULL) {}
	Node(ll height) : lch(NULL), rch(NULL), h(height) {}
};
void add(Node* node, const string &s) {
	for(auto&& c : s) {
		if (c == '0') {
			if (node->lch == NULL) node->lch = new Node(node->h + 1);
			node = node->lch;
		}
		else {
			if (node->rch == NULL) node->rch = new Node(node->h + 1);
			node = node->rch;
		}
	}
}
void dfs(Node* node) {
	if (node->lch == NULL && node->rch == NULL) {
		return;
	}
	else if (node->lch == NULL) {
		dfs(node->rch);
		ll h = l - node->h;
		xsum ^= trans(h);
	}
	else if (node->rch == NULL) {
		dfs(node->lch);
		ll h = l - node->h;
		xsum ^= trans(h);
	}
	else {
		dfs(node->lch);
		dfs(node->rch);
	}
}
int main() {
 	int n;
	cin >> n >> l;
	string in;
	Node* root = new Node(0);
	rep(i, n) {
		cin >> in; add(root, in);
	}
	dfs(root);
	if (xsum)cout << "Alice" << endl;
	else cout << "Bob" << endl;
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
const int MAXN = 100500;

int n, m;
vector <vector <int> > g;
vector <int> p1, p2;
bool used[MAXN];


void dfs(int v, vector <int> &p)
{
	p.push_back(v);
	used[v] = 1;

	for (int to : g[v])
	{
		if (!used[to])
		{
			dfs(to, p);
			return;
		}
	}

}

int main()
{                                                     
	ios_base::sync_with_stdio(0);
	cin >> n >> m;
	g.resize(n);

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

	int v = 0;
	while (g[v].empty())
		++v;

	dfs(v, p1);
	dfs(v, p2);
	reverse(p1.begin(), p1.end());

	cout << (int)p1.size() + (int)p2.size() - 1 << '\n';

	for (int i = 0; i < (int)p1.size() - 1; i++)
		cout << p1[i] + 1 << ' ';
	for (int i = 0; i < (int)p2.size(); i++)
		cout << p2[i] + 1 << ' ';

	cout << '\n';
	
	return 0;
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(int(chrono::steady_clock::now().time_since_epoch().count()));

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

    int N;
    cin >> N;

    string S;
    cin >> S;

    int Q;
    cin >> Q;

    for (int q = 0; q < Q; q++) {
        int K;
        cin >> K;

        ll d = 0, dm = 0, m = 0, dmc = 0;
        for (int i = 0; i < N; i++) {
            if (i >= K) switch (S[i - K]) {
                case 'D': dm -= m; d--; break;
                case 'M': m--; break;
                case 'C': break;
                default: break;
            }
            switch(S[i]) {
                case 'D': d++; break;
                case 'M': dm += d; m++; break;
                case 'C': dmc += dm; break;
                default: break;
            }
        }
        cout << dmc << "\n";
    }

    return 0;
}



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

using namespace std;

int main() {
    string s,t,u;
    int a,b;
 
    cin >> s >> t >> a >> b >> u;

    if (s == u) {
        a--;
    } else {
        b--;
    }

    cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;
  while(cin >> n, n){
    vector<int> p(n), t(n);
    for(int i = 0; i < n; ++i){
      cin >> p[i] >> t[i];
    }
    int INF = 1000000000;
    vector< vector<int> > dp(n, vector<int>(4,INF));
    if(p[0] > t[0]){
      cout << "NG 1" << endl;
      continue;
    }
    dp[0][1] = p[0];
    bool f = true;
    for(int i = 1; i < n; ++i){
      bool g = true;
      for(int j = 1; j < 4; ++j){
	if(dp[i-1][j] == INF) continue;
	int t_diff = t[i] - t[i-1];
	if(j+1 <= 3 && abs(p[i]-p[i-1])*(j+1) <= t_diff){
	  g = false;
	  dp[i][j+1] = min(dp[i][j+1], dp[i-1][j]+abs(p[i]-p[i-1]));
	}
	if(p[i]+p[i-1]*(j+1) <= t_diff){
	  g = false;
	  dp[i][1] = min(dp[i][1], dp[i-1][j]+p[i]+p[i-1]);
	}
      }
      if(g){
	cout << "NG " << i+1 << endl;
	f = false;
	break;
      }
    }
    if(f){
      int ans = INF;
      for(int i = 0; i < 4; ++i){
	ans = min(ans, dp[n-1][i]+p[n-1]);
      }
      cout << "OK " << ans << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  int n,k,i,h[100005],ans=1e9;
  
  cin >> n >> k;
  for (i=0;i<n;i++) cin >> h[i];
  
  sort(h,h+n);
  
  for (i=0;i<n-k+1;i++){
    ans=min(ans,h[i+k-1]-h[i]);
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 640
# fin=open('in','r')
# input=lambda:fin.readline().strip()
n,p=map(int,input().split())
s=list(map(int,input()))
if p==2 or p==5:
  r=0
  for i in range(n):
    if s[i]%p==0:
      r+=i+1
  print(r)
else:
  c=0
  cnt=[0]*p
  cnt[0]+=1
  for k in range(len(s)-1,-1,-1):
      c=(c+s[k]*pow(10,len(s)-1-k,p))%p
      cnt[c]+=1
  print(sum(x*(x-1)//2 for x in cnt))

Measured memory_bytes: 85208
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#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 ALL(c) c.begin(), c.end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) scanf("%d", &a[i]);
    sort(ALL(a));

    bool pos = false;

    if (a[0] == a[n-1]){
        if (a[0] == n-1 || 2*a[0] <= n) pos = true;
    }else if (a[0] == a[n-1] - 1){
        int x = 0;
        REP(i,n) x += (a[i] == a[0]);
        int y = a[n-1] - x;
        if (y > 0 && n - x >= 2 * y) pos = true;
    }

    cout << (pos ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N;
	cin >> N;
	map<int,int> mp;
	rep(i,N){
		int x;
		cin >> x;
		mp[x]++;
	}
	if(N%3){
		if(mp[0] == N) cout << "Yes" << endl;
		else cout << "No" << endl;
	}else{
		int s = 0;
		for(auto p: mp){
			if(p.sc%(N/3)){
				cout << "No" << endl;
				return 0;
			}
			int t = p.sc/(N/3);
			rep(_,t) s ^= p.fs;
		}
		if(s == 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}


Measured memory_bytes: 3840
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

int main(void){
  int N, K;
  string S;
  cin >> N >> K;
  cin >> S;
  for(int index = 0; index < S.size(); ++index){
    if(index == K - 1){
      if(S[index] == 'A') cout << 'a';
      if(S[index] == 'B') cout << 'b';
      if(S[index] == 'C') cout << 'c';
    }else{
      cout << S[index];
    }
  }
  cout << endl;

  return 0;
}


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

int n;
long m, sum, a[20];

//sum/2??\?????§????????????????????????????¨?
void rec(int x, long y){ //x???????????\???????????\????????????,???????????????y
	if(x==n){
		if(m<y) m=y;	
	}
	else{
		if(y+a[x]>sum/2) rec(x+1,y);
		else{
			rec(x+1,y+a[x]);
			rec(x+1,y);		
		}	
	}
	
}

int main(){
	while(1){
		scanf(" %d", &n);
		if(n==0) break;
		
		sum=0;
		for(int i=0; i<n; ++i){
			scanf(" %ld", &a[i]);
			sum+=a[i];
		}
	
		m=0;	
		rec(0, 0);
		
		long mm=sum-m;
		//printf("m=%ld, mm=%ld\n",m ,mm);
		printf("%ld\n", mm-m);
	}
}

Measured memory_bytes: 1188
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

int main() {
    int n, t;
    char c;
    std::cin >> n;
    std::vector<std::pair<bool, int>> v(2 * n + 1);
    std::vector<int> b(n + 1), w(n + 1);
    std::vector<std::vector<int>> tmpb(2 * n + 1, std::vector<int>(n + 1)),
                                tmpw(2 * n + 1, std::vector<int>(n + 1)),
                                costb(n + 1, std::vector<int>(n + 1)),
                                costw(n + 1, std::vector<int>(n + 1)),
                                dp(n + 1, std::vector<int>(n + 1));
    for (auto i = 1; i <= 2 * n; i++) {
        std::cin >> c >> t;
        v[i] = std::make_pair(c == 'B', t);
        if (c == 'B') b[t] = i;
        else w[t] = i;
    }

    for (auto i = 1; i <= n; i++) {
        for (auto k = 1; k <= 2 * n; k++) {
            tmpb[k][i] = tmpb[k - 1][i] + (v[k].first && (v[k].second <= i) ? 1 : 0);
            tmpw[k][i] = tmpw[k - 1][i] + (!v[k].first && (v[k].second <= i) ? 1 : 0);
        }
    }

    for (auto i = 0; i < n; i++) {
        for (auto j = 0; j < n; j++) {
            costb[i][j] = (i - tmpb[b[i + 1]][i]) + (j - tmpw[b[i + 1]][j]);
            costw[i][j] = (i - tmpb[w[j + 1]][i]) + (j - tmpw[w[j + 1]][j]);
        }
    }

    for (auto i = 0; i < n; i++) {
        costb[i][n] = (i - tmpb[b[i + 1]][i]) + (n - tmpw[b[i + 1]][n]);
        costb[n][i] = 1000000000;
        costw[i][n] = 1000000000;
        costw[n][i] = (n - tmpb[w[i + 1]][n]) + (i - tmpw[w[i + 1]][i]);
    }
    costb[n][n] = 1000000000;
    costw[n][n] = 1000000000;

    for (auto i = 1; i <= n; i++) {
        dp[i][0] = dp[i - 1][0] + costb[i - 1][0];
        dp[0][i] = dp[0][i - 1] + costw[0][i - 1];
    }

    for (auto i = 1; i <= n; i++) {
        for (auto j = 1; j <= n; j++) {
            dp[i][j] = std::min(dp[i - 1][j] + costb[i - 1][j],
                                dp[i][j - 1] + costw[i][j - 1]);
        }
    }

    std::cout << dp[n][n] << std::endl;

    return 0;
}

Measured memory_bytes: 110208
#include<bits/stdc++.h>
#define NAME "B"
#define vt vector
#define ll long long
#define fi first
#define se second
#define pb push_back
#define time ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

void init()
{
    freopen(NAME".inp","r",stdin);
    freopen(NAME".out","w",stdout);
}

const int N=1e5+5;
int n,a[N],k;
ll f[N] {0};

void inp()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i],f[i]=INT_MAX;
}

void out()
{
    f[1]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=k;j++)
            f[i+j]=min(f[i]+abs(a[i]-a[i+j]),f[i+j]);
    }
    cout<<f[n];
}

int main()
{
  //  init();
    inp();
    out();
}


Measured memory_bytes: 1408
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func next() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func abs(a int, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	l := nextInt()

	minAbs := math.MaxInt32
	min := math.MaxInt32
	sum := 0

	for i := 1; i <= n; i++ {
		taste := l + i - 1
		abs := abs(taste, 0)
		if abs < minAbs {
			minAbs = abs
			min = taste
		}
		sum += taste
	}

	fmt.Println(sum - min)
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int n,tmp,test;

    cin >> n;

    vector<int> v(n);
    vector<int> v_sort(n), v_tmp(n);
    for(int k=0; k<n; k++) cin >> v[k];

    copy(v.begin(), v.end(), v_sort.begin());

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

    for(int i=0; i<n; i++) {
        for(int j=0; j<n; j++){
            copy(v.begin(), v.end(), v_tmp.begin());
            tmp = v_tmp[i];
            v_tmp[i] = v_tmp[j];
            v_tmp[j] = tmp;

            if(equal(v_tmp.cbegin(), v_tmp.cend(), v_sort.cbegin())){
                printf("%s\n", "YES");
                return 0;
            }
        }
    }

  printf("%s\n", "NO");
  return 0;
}

Measured memory_bytes: 256
from sys import stdin, stdout

N = int(input())
A = [int(x) for x in stdin.readline().split()]
ans = 1
for i in range(N):
  if ans <= 1e18:
    ans *= A[i]
  if A[i] == 0:
    ans *= A[i]

if ans > 1e18:
  print("-1")
else:
  print(ans)

Measured memory_bytes: 21592
import copy

n = int(input())
x = [int(i) for i in input().split()]

x_original_order = copy.deepcopy(x)

x.sort()
large = x[int(n/2)]
small = x[int(n/2)-1]

for i in x_original_order:
	if i <= small:
		print(large)
	else:
		print(small)

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

ll inf=9223372036854775806,ans=0;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	if (a+b>=c){
		cout<<"Yes";
	}
	else {
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static void main(String[] args) {
        FastReader fr = new FastReader();
        int n = fr.nextInt();
        int k = fr.nextInt();
        ArrayList<Integer> arrayList = new ArrayList<>();
        for(int i=0;i<n;i++){
            int val = fr.nextInt();
            arrayList.add(val);
        }
        Collections.sort(arrayList);
        int ans = 0;
        for(int i=0;i<k;i++){
            ans+=(arrayList.get(i));
        }
        System.out.println(ans);
    }
}

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

int main() {
    int n, T, tt, price;
    cin >> n >> T;
    vector<vector<int>> arr;
    for(int i = 0; i < n; i++) {
        cin >> tt >> price;
        arr.push_back({tt, price});
    }
    sort(arr.begin(), arr.end());
    //auto last = arr.back(); arr.pop_back();
    vector<int> dp(T, 0);
    // available at dp[t]
    int ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = T-1; j >= 0; j--) {
            ans = max(ans, dp[j]+arr[i][1]);
            if (j-arr[i][0] >= 0) {
                dp[j] = max(dp[j], dp[j-arr[i][0]]+arr[i][1]);
            }
            // ans = max(ans,dp[j]);
        }
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 512
fn main() {
    let v = read_vec::<usize>();
    if v[0] == v[1] {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
#include <iostream>
using namespace std;
string solve(char c, string vowel)
{
	for(int i = 0; i < vowel.size(); i++)
		if( c == vowel[i] )
			return "vowel";
	return "consonant";
}
int main()
{
	char c;
	cin >> c;
	string vowel = "aeiuo";
	cout << solve(c,vowel);
}


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

int A[51];

void func(int n){
  if(n==50) return;
  A[n]=A[n-1]+A[n-2];
  func(n+1);
}

int main(){
  int n;
  cin >> n;
  A[0]=1; A[1]=1;
  func(2);

  cout << A[n] << endl;
}

Measured memory_bytes: 3112
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int length = scanner.nextInt();
     	int height = scanner.nextInt();
      	int width = scanner.nextInt();
      	int result = (length - height + 1)  * (length - width + 1);
      	System.out.print(result);
    }
}

Measured memory_bytes: 27072
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 nn;
	cin >> nn;
	vector<int64> aa(nn), bb(nn);
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> aa[ii] >> bb[ii];
	}
	for(int64 ii = 2;ii < nn;ii++)
	{
		if(aa[ii] == bb[ii] && aa[ii - 1] == bb[ii - 1] && aa[ii - 2] == bb[ii - 2])
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

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

#define int long long
#define double long double
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int) (x).size())
#define fr first
#define sc second
typedef long long ll;
typedef pair<int,int> pii;



void solve() {
    int n, x;
    cin >> n >> x;
    vector<double> a(n);
    double sum = 0;
    forn (i, n) {
        cin >> a[i];
        sum += a[i];
    }
    double y = sum / (4.0 * x);
    int cnt = 0;
    forn (i, n) {
        if (y <= a[i]) ++cnt;
    }
    if (cnt >= x) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
}


int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef DK
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    while (cin.peek() != EOF) {
        solve();
        cout << endl << endl;
        string s("#");
        do getline(cin, s);
        while (!cin.eof() && !s.empty());
        while (isspace(cin.peek())) cin.get();
    }
#else
    solve();
#endif
    return 0;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w;
	cin >> h >> w;
	vector<string> v(h);
	REP(i, h)cin >> v[i];
	if (v[0][0] == '#') {
		cout << -1 << endl;
		return 0;
	}
	queue<pii> q;
	vvi d(h, vi(w, INF));
	d[0][0] = 0;
	q.push({ 0,0 });
	while (!q.empty()) {
		pii p = q.front(); q.pop();
		int x = p.first, y = p.second;
		REP(i, 4) {
			int nx = dx[i * 2] + x, ny = dy[i * 2] + y;
			if (nx < 0 || ny < 0 || nx >= w || ny >= h || v[ny][nx] == '#')continue;
			if (d[ny][nx] == INF)q.push({ nx,ny });
			d[ny][nx] = min(d[ny][nx], d[y][x] + 1);
			
		}
	}
	if (d[h - 1][w - 1] == INF) {
		cout << -1 << endl;
		return 0;
	}
	int cnt = 0;
	REP(i, h)REP(j, w)if (v[i][j] == '.')cnt++;
	cout << cnt - 1 - d[h - 1][w - 1] << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,s[500005],l[500005],r[500005],ans;vector<int>v[500005];
void add(int x,int v){for(;x<=m;x+=x&-x) s[x]+=v;}
int que(int x){int r=0;for(;x;x-=x&-x) r+=s[x];return r;}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d%d",&l[i],&r[i]),v[r[i]-l[i]+1].push_back(i);
    for(int i=1;i<=m;i++,ans=0)
    {
        for(int j=0;j<v[i].size();j++) add(l[v[i][j]],1),add(r[v[i][j]]+1,-1);
        for(int j=i;j<=m;j+=i) ans+=que(j);
        n-=v[i].size();printf("%d\n",ans+n);
    }
}

Measured memory_bytes: 20480
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

bool dp[101010];
int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    rep(i,n)cin>>a[i];
    rep(i,k+1){
        rep(j,n)if(a[j]<=i)dp[i]|=(dp[i-a[j]]==0);
    }
    cout<<(dp[k]?"First":"Second")<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const ll Mod = 1e9 + 7;
const ll N = 10100;

ll Rec(ll i=0,ll m=0,bool Equal=true);

string k;
ll n;
ll D;
ll s[N];

ll Dp[N][110][2];

int main()
{
    memset(Dp,-1,sizeof(Dp));

    cin>>k>>D;

    n = k.size();

    for(ll i=0;i<n;i++) s[i] = k[i] - '0';

    cout<<(Rec()-1+Mod)%Mod;
}

ll Rec(ll i,ll m,bool Equal)
{
    if(i==n)    return m==0;

    if(Dp[i][m][Equal]+1)   return Dp[i][m][Equal];

    ll Res = 0;

    for(ll j = 0 , L = Equal ? s[i] : 9 ; j<=L ; j++ )  Res += Rec(i+1,(m+j)%D,Equal&&s[i]==j);

    return Dp[i][m][Equal] = Res%Mod;
}

Measured memory_bytes: 18560
s=input()
t=input()
lt=len(t)
ls=len(s)

#例外処理
if lt>ls:
    print("UNRESTORABLE")
else:
    # 後ろから見ていってｔを入れれそうならflagを立てる
    # t入れれたら残りの?を全部aに変えてしまえばいい
    ans=[]
    for i in range(ls-lt+1):
        flag=True
        for j in range(lt):
            if s[i+j]!="?" and s[i+j]!=t[j]:
                flag=False
                break                
        if flag: # countがtの長さになってたらtぶち込めるてこと
            tmp=s[:i]+t+s[i+lt:]
            tmp=tmp.replace("?", "a")
            ans.append(tmp)
            
      
    if ans:
        an=sorted(ans)
        print(an[0])
       
    else:
        print("UNRESTORABLE")
        

Measured memory_bytes: 3064
program main
  implicit none
  integer(8) :: n, m, i, j, tmp
  integer(8), allocatable :: a(:), b(:), parents(:), cnt(:), res(:)
  read (*, *) n, m
  allocate (a(m), b(m), parents(n), cnt(n), res(m))
  do j = 1, m
    read (*, *) a(j), b(j)
  end do

  parents = [(i, i = 1, n)]
  cnt(:) = 1

  tmp = n * (n - 1) / 2
  do j = m, 1, -1
    res(j) = tmp
    if (find(a(j), parents) /= find(b(j), parents)) then
      tmp = tmp - cnt(find(a(j), parents)) * cnt(find(b(j), parents))
      call unite(a(j), b(j), parents, cnt)
    end if
  end do

  do j = 1, m
    print "(i0)", res(j)
  end do

  contains

  subroutine unite(x, y, parents, cnt)
    ! Insert y to x
    integer(8), intent(in) :: x, y
    integer(8), intent(inout) :: parents(:), cnt(:)
    integer(8) :: px, py
    px = find(x, parents)
    py = find(y, parents)
    if (px /= py) then
      parents(py) = px
      cnt(px) = cnt(px) + cnt(py)
    end if
  end subroutine unite

  recursive function find(x, parents) result(r)
    integer(8), intent(in) :: x
    integer(8), intent(inout) :: parents(:)
    integer(8) :: r
    if (parents(x) == x) then
      r = x
    else
      r = find(parents(x), parents)
      parents(x) = r
    end if
  end function find
end program main


Measured memory_bytes: 6012
S = list(input())
count = 0
ans = [0]*(len(S))
for i in range(len(S)):
    if S[i] == "R":
        count += 1
    else:
        if count % 2 == 0:
            ans[i] += count//2
            ans[i-1] += count//2
            count = 0
        else:
            ans[i] += count//2 
            ans[i-1] += count//2 + 1 
            count = 0
	
S.reverse()
ans.reverse()

for i in range(len(S)):
    if S[i] == "L":
        count += 1
    else:
        if count % 2 == 0:
            ans[i] += count//2
            ans[i-1] += count//2
            count = 0
        else:
            ans[i] += count//2 
            ans[i-1] += count//2 + 1 
            count = 0

ans.reverse()

for a in ans:
    print(a, end=" ")

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

int henkan(char* out,const char* in) {
	const char table[5][6]={
		{'a','f','k','p','u','z'},
		{'b','g','l','q','v','.'},
		{'c','h','m','r','w','?'},
		{'d','i','n','s','x','!'},
		{'e','j','o','t','y',' '}
	};
	int i;
	int outpos=0;
	for(i=0;in[i]!=0;i+=2) {
		if(in[i]<'1' || in[i]>'6' || in[i+1]<'1' || in[i+1]>'5')return 0;
		out[outpos++]=table[in[i+1]-'1'][in[i]-'1'];
	}
	out[outpos]=0;
	return 1;
}

int main(void) {
	char buf[300];
	char* kaigyou;
	char out[300];
	while(fgets(buf,sizeof(buf),stdin)) {
		kaigyou=strchr(buf,'\n');
		if(kaigyou)*kaigyou=0;
		if(henkan(out,buf))puts(out); else puts("NA");
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main()
{
	int N,R,K,H;
	scanf("%d %d",&N,&R);
	if(N<10)
	{
		K=100*(10-N);
		H=K+R;
		printf("%d",H);
	}
	else
	{
		printf("%d",R);
	}
}

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

int main(void){
  
  int N;
  double money, temp;
  cin >> N;
  
  money = N / 1.08;
  temp = ceil(money);
  temp = temp * 1.08;
  temp = (int)temp;
  if(temp == N){
    cout << ceil(money) << endl;
  }
  else{
    money = N / 1.08;
    money = (int)money;
    temp = money;
    money *= 1.08;
    money = (int)money;
    if(money == N){
      cout << temp << endl;
    }
    else{
      cout << ":(" << endl;
    }
  }
}

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

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

    ll cnt = 0;
    if(k!=0){
        for(ll b=k+1;b<=n;b++){
            cnt += (n/b)*(b-k) + max(n%b-k+1, 0LL);
        }
    }else{
        cnt = n*n;
    }
    cout << cnt << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int, input().split()))
    cnt=0
    for i in range(1,n-1):
        if l[i-1]<l[i]<l[i+1] or l[i+1]<l[i]<l[i-1]:
            cnt+=1
    print(cnt)
resolve()

Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

string fm_time(int);

int main()
{
    char X;
    cin >> X;
    cout << char(X + 1) << endl;
}



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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	while(1){
        int n, x;
        cin >> n >> x;
        if(n == 0 && x == 0)
            break;
        int ans = 0;
        for(int i = 1; i <= n; i++){
            for(int j = i + 1; j <= n; j++){
                for(int k = j + 1; k <= n; k++){
                    if(i + j + k == x)
                        ans++;
                }
            }
        }
        cout << ans << endl;
    }
	return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include <iomanip>
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;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<62);

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

void no(){
    cout<<-1<<endl;
    exit(0);
}
int main() {
    cin>>N;
    vec a(N + 1, 0);
    rep(i,N + 1) cin>>a[i];
    if(N == 0){
        cout<<(a[0] != 1 ? -1 : 1)<<endl;
        return 0;
    }
    if(a[0] > 0) no();

    vec num(N + 1, 0);
    num[0] = 1;
    const ll m = ll(1e+16);
    ll temp = 1;
    reps(i,1,N+1){
        temp *= 2;
        chmin(temp, m);
        num[i] = temp;
        temp -= a[i];
        if(temp < 0 || (i != N && temp == 0)) no();
    }
    //rep(i,N + 1) cout<<num[i]<<' ';
    //cout<<endl;
    num[N] = a[N];
    temp = num[N];
    Rrep(i,N){
        temp += a[i];
        chmin(num[i], temp);
        temp = num[i];
    }
    //rep(i,N + 1) cout<<num[i]<<' ';
    //cout<<endl;
    ll res = accumulate(ALL(num), 0LL);
    cout<<res<<endl;
}

Measured memory_bytes: 5128
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
	int N, K, X, Y;
	cin >> N >> K >> X >> Y;
	int ans = X * min(N, K) + Y * max(N - K, 0ll);
	cout << ans;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let n = get!(usize);
    let a: Vec<char> = get!(String).chars().collect();
    let b: Vec<char> = get!(String).chars().collect();
    let c: Vec<char> = get!(String).chars().collect();
    let mut ans = 0;
    for i in 0..n {
        if a[i] == b[i] && b[i] == c[i] {
            continue;
        } else if a[i] == b[i] || b[i] == c[i] || c[i] == a[i] {
            ans += 1;
        } else {
            //eprintln!("a: {}, b: {}, c: {}", a[i], b[i], c[i]);
            ans += 2;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n; cin>>n;
  vector<int> d(n); for(int i=0;i<n;i++) cin>>d[i];
  sort(d.begin(),d.end());
  cout<<d[n/2]-d[n/2-1];
}

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

int main(void){
  int N, K;
  cin >> N >> K;
  vector<bool> snuke(N);
  
  int A;
  vector<int> d(K);
  for(int i = 0; i < K; i++){
    cin >> d.at(i);
    for(int j = 0; j < d.at(i); j++){
      cin >> A;
      snuke.at(A-1) = true;
    }
  }
  int ans = 0;
  for(int i = 0; i < N; i++){
	if(snuke.at(i) == false){
      ans++;
    }
  }
  cout << ans << endl;

}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

template <typename T>
T powmod(T n, T k, T mod) {
  if (k == 0) {
    return 1;
  } else if (k % 2 == 0) {
    return powmod(n * n % mod, k / 2, mod);
  } else {
    return n * powmod(n, k-1, mod) % mod;
  }
}

template <typename T>
T inv(T x, T mod) {
  return powmod(x, mod-2, mod);
}

ll fact[(int)1e6+10];

template <typename T>
T comb(int n, int k, T mod) {
  assert(0 <= k and k <= n);
  return fact[n] * inv(fact[k], mod) % mod * inv(fact[n-k], mod) % mod;
}

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int H, W, A, B; cin >> H >> W >> A >> B;
  const ll mod = 1e9+7;

  fact[0] = fact[1] = 1;
  FOR(i, 2, 1e6+1) {
    fact[i] = fact[i-1] * i;
    fact[i] %= mod;
  }

  ll ans = 0;
  FOR(i, B, W) {
    ans += comb(H-A-1+i, i, mod) * comb(A+W-i-2, A-1, mod) % mod;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}


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

Cost = [0]
Start = [0]
Frequency = [0]
Ans = [0] * (N+1)

for __ in range(N-1):
    c, s, f = map(int, input().split())
    Cost.append(c)
    Start.append(s)
    Frequency.append(f)

for i in range(1, N):
    if Ans[i] != 0:
        print(Ans[i])
    else:
        Same = []
        now = 0
        for j in range(i, N):
            if now <= Start[j]:
                if Ans[j] != 0:
                    now = Ans[j]
                    break
                Same.append(j)
                now = Start[j] + Cost[j]
            else:
                tmp = (now-1) // Frequency[j]
                tim = (tmp + 1) * Frequency[j]
                now = tim + Cost[j]
        print(now)
        for k in Same:
            Ans[k] = now
print(0)



Measured memory_bytes: 41580
from collections import Counter
n = int(input())
lst = list(map(int,input().split()))
if lst[0] != 0:
    print(0)
    exit()
mod = 998244353
c = dict(Counter(lst))
c = dict(sorted(c.items(), key=lambda x:x[0]))

for e,(k,v) in enumerate(c.items()):
    if e==0:
        if k!=0 or v!=1:
            ans = 0
            break
        else:
            pre_v = v
            ans = v
    elif e!=k or v==0:
        ans = 0
        break
    else:
        ans = ans*pow(pre_v, v, mod)%mod
        pre_v = v
print(ans%mod)

Measured memory_bytes: 33112
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, k;
  cin>>n>>k;
  int cnt = 0, cnt2 = 0;
  for (int i=1 ; i <= n; i++){
    if (i%k==0) cnt++;
    if (k%2==0 && i%k==(k/2)) cnt2++;
  }
  long long ans = 1LL*cnt*cnt*cnt + 1LL*cnt2*cnt2*cnt2;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256