akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define all(v) v.begin(),v.end()
#define mem(v,x) memset(v,x,sizeof(v))
#define ar array
#define N 100005
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//list of functions: set.insert(val), *(set.find_by_order(order-1)), set.order_of_key(val)

using namespace __gnu_pbds;
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n,x,t;
    cin>>n>>x>>t;
    cout<<((n+x-1)/x)*t<<'\n';
    return 0;
}


Measured memory_bytes: 3608
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
// const long long MOD = (ll)1e9+7;
const long long MOD = (ll)1e6+3;
const long long MAX = (ll)170 * 80;


int main(void) {
   ll A,B,C;
   cin>>A>>B>>C;
   bool flag = ((A==B) && (B==C));
   if (flag) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   return 0;
}

Measured memory_bytes: 256
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> myds;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define F first
#define S second
#define vec(x) vector<x> 
#define pi(x,y) pair<x,y>
#define pqq(x) priority_queue<x> 
#define min_heap(x) priority_queue<x, vector<x>, greater<x> >
#define all(x) x.begin(),x.end()
#define rep(i,x,y) for(int i=x;i<y;i++)
#define repd(i,x,y,k) for(int i=x;i<y;i+=k)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define rev(x) reverse(all(x))
#define full(x,a) memset(x,a,sizeof(x))
#define lcm(x,y) ((x*y)/__gcd(x,y))
#define mod 1000000007
#define bitcount __builtin_popcountll
#define pb push_back
#define indexof order_of_key
#define valueat find_by_order

int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int dxx[8]={0,0,1,-1,-1,-1,1,1};
int dyy[8]={1,-1,0,0,-1,1,1,-1};

bool solve(int n){
	while(n>0){
		int r=n%10;
		if(r==7)
			return 1;
		n/=10;
	}
	return 0;
}

main(){
	fastio;
	int n;
	cin>>n;
	if(solve(n))
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}


Measured memory_bytes: 3652
n,a,b=map(int,input().rstrip().split(' '))

def count(n):
  x = str(n)
  sum=0
  for s in x:
    sum+=int(s)
  return sum
    
ans=0
for i in range(1,n+1):
  if(a <= count(i) and count(i) <=b):ans+=i

print(ans)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int cnt = 0, fcnt = 0;
		for (int i = 0; i < n; i++) {
			if (s[i] == 'a') {
				if (cnt < a + b) {
					sb.append("Yes" + "\n");
					cnt++;
				} else {
					sb.append("No" + "\n");
				}
			} else if (s[i] == 'b') {
				if (cnt < a + b && fcnt < b) {
					sb.append("Yes" + "\n");
					cnt++;
					fcnt++;
				} else {
					sb.append("No" + "\n");
				}
			} else {
				sb.append("No" + "\n");
			}
		}
		System.out.print(sb);
	}
}


Measured memory_bytes: 28472
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v){
    if(v.empty()){
        os<<"{ }";
        return os;
    }
    os<<"{"<<v.front();
    for(auto itr=++v.begin();itr!=v.end();itr++){
        os<<", "<<*itr;
    }
    os<<"}";
    return os;
}

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

class UnionFind{
public:
    int n;
    vector<int> v;

    UnionFind():n{0}{}
    UnionFind(int n_in):n{n_in}{
        v.assign(n,-1);
    }
    
    int find(int x){
        assert(0<=x && x<n);
        if(v[x]<0) return x;
        v[x]=find(v[x]);
        return v[x];
    }
    
    bool same(int a,int b){
        assert(0<=a && a<n);
        assert(0<=b && b<n);
        if(find(a)==find(b)) return true;
        return false;
    }
    
    int merge(int a,int b){
        assert(0<=a && a<n);
        assert(0<=b && b<n);
        int a_p=find(a),b_p=find(b);
        if(a_p==b_p) return a_p;
        if(a_p>b_p) swap(a_p,b_p);
        v[a_p]+=v[b_p]; v[b_p]=a_p;
        return a_p;
    }
    
    int size(int a){
        assert(0<=a && a<n);
        return -v[find(a)];
    }

    int group_cnt(){
        int res=0;
        for(auto p:v)if(p<0) res++;
        return res;
    }

    vector<std::vector<int>> groups(){
        vector<int> leader_buf(n),group_size(n);
        for (int i=0;i<n;i++){
            leader_buf[i]=find(i);
            group_size[leader_buf[i]]++;
        }
        vector<vector<int>> result(n);
        for (int i=0;i<n;i++){
            result[i].reserve(group_size[i]);
        }
        for (int i=0;i<n;i++){
            result[leader_buf[i]].push_back(i);
        }
        //空である配列要素を消去する
        result.erase(
            remove_if(result.begin(),result.end(),
                           [&](const vector<int>& _v) {return _v.empty();}),
            result.end());
        return result;
    }
};

int main(){
    int n,m; cin>>n>>m;
    UnionFind uf{n};
    rep(i,m){
        int a,b; cin>>a>>b;
        a--; b--;
        uf.merge(a,b);
    }
    set<int> s;
    rep(i,n) s.insert(uf.find(i));
    cout<<s.size()-1<<endl;
}

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

#define endl '\n'

using namespace std;

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

  int p, q, r;
  cin >> p >> q >> r;
  cout << min(p + q, min(p + r, r + q)) << endl;

  return 0;
}


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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

struct donguri {
    ll d;
    int g,s,b;
};

int main() {
    ll n,a[3],b[3];
    cin >> n >> a[0] >> a[1] >> a[2] >> b[0] >> b[1] >> b[2];
    int cnt = 0;
    for (int i = 0;i < 3;++i) if (a[i] > b[i]) cnt++;
    ll ans = 0;
    if (cnt == 0) {
        for (int i = 0;i < n/a[0]+1;++i) for (int j = 0;j < (n-i*a[0])/a[1]+1;++j) {
            int k = (n-i*a[0]-j*a[1])/a[2];
            ans = max(ans,n+(b[0]-a[0])*i+(b[1]-a[1])*j+(b[2]-a[2])*k);
        }
    } else if (cnt == 1) {
        for (int i = 1;i < 3;++i) if (a[i] > b[i]) {
            swap(a[i],a[0]);
            swap(b[i],b[0]);
        }
        for (int i = 0;i < n/a[1]+1;++i) {
            int j = (n-a[1]*i)/a[2];
            ll m = n+(b[1]-a[1])*i+(b[2]-a[2])*j;
            ans = max(ans,m%b[0]+a[0]*(m/b[0]));
        }
    } else if (cnt == 2) {
        for (int i = 0;i < 2;++i) if (a[i] <= b[i]) {
            swap(a[i],a[2]);
            swap(b[i],b[2]);
        }
        ll m = n%a[2]+b[2]*(n/a[2]);
        for (int i = 0;i < m/b[0]+1;++i) {
            int j = (m-b[0]*i)/b[1];
            ans = max(ans,m+(a[0]-b[0])*i+(a[1]-b[1])*j);
        }
    } else {
        for (int i = 0;i < n/b[0]+1;++i) for (int j = 0;j < (n-i*b[0])/b[1]+1;++j) {
            int k = (n-i*b[0]-j*b[1])/b[2];
            ans = max(ans,n+(a[0]-b[0])*i+(a[1]-b[1])*j+(a[2]-b[2])*k);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0;
    rep(i,n){
        int a;
        cin >> a;
        while(a%2 == 0){
            a /= 2;
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main()
{
  int a, b;
  cin >> a >> b;
  cout << (b % a == 0 ? a + b : b - a) << "\n";
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pb push_back
#define FF first
#define SS second

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

int A[100005];

int main() {
  int n;
  S(n);
  int cnt = 0;
  rep(i,0,n) {
    int x;
    S(x);
    if(!A[x]) cnt++;
    A[x] = 1;
  }
  if((n - cnt) % 2) cnt--;
  P(cnt);
  return 0;
}

Measured memory_bytes: 640
import queue

n = int(input())
graph = {}
for _ in range(n):
  i = list(map(int,input().split()))
  graph[i[0]] = i[2:]

dist = [-1 for i in range(n)]
todo = queue.Queue()
seen = set()

dist[0] = 0
todo.put(1)

while (not todo.empty()):
  now = todo.get()
  for nx in graph[now]:
    if (dist[nx-1] != -1):
      continue
    dist[nx-1] = dist[now-1] + 1
    todo.put(nx)

for i in range(n):
  print(i+1, dist[i])




Measured memory_bytes: 6876
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int N, M, Q,Ans=0;
vector<int> A(50), B(50), C(50), D(50), V(10);
void dfs(int E, int F){
  if(E==N){
    int Sum=0;
    rep(i, Q)if (V.at(B.at(i))-V.at(A.at(i))==C.at(i)) Sum+=D.at(i);
    Ans=max(Ans, Sum);
    return;
  }
  for(int i=F; i<=M; i++){
    V.at(E)=i;
    dfs(E+1,i);
  }
}
int main(){
  cin >> N >> M >> Q;
  rep(i,Q){
    cin >> A.at(i) >> B.at(i) >> C.at(i) >> D.at(i);
    A.at(i)--;
    B.at(i)--;
  }
  vector<int> V;
  dfs(0,1);
  cout << Ans << endl;
}

Measured memory_bytes: 3596
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 200000
using namespace std;
typedef long long LL;
LL N,K;
int main()
{
	LL ans=0;
	scanf("%lld %lld",&N,&K);
	for(LL b=1;b<=N;b++)
	{
		if(2LL*b%K!=0)
			continue;
		ans+=((N+b)/K-b/K)*((N+b)/K-b/K);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <map>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N;i++) {
		cin >> a[i];
	}
	int max = 1, cnt = 1, b[2],num = 0,sum=1;
	sort(a.begin(), a.end());
	b[0] = 0;
	b[1] = 0;
	
	num = a[0];
	for (int i = 1;i<N;i++) {
		if (a[i] == num) {
			cnt++;
			sum++;
		}
		else if(a[i] == num+1){
			if (max < sum) {
				max = sum;
			}
			sum -= b[1];
			b[1] = b[0];
			b[0] = cnt;
			cnt = 1;
			sum++;
			num++;
		}
		else {
			if (max < sum) {
				max = sum;
			}
			b[1] = 0;
			b[0] = 0;
			sum = 1;
			cnt = 1;
			num = a[i];
		}
	}
	if (max < sum) {
		max = sum;
	}
	cout << max << endl;

	return 0;
}



Measured memory_bytes: 640
'''
????????§????¢?????????????
???????????????????????????????????£????????????
???????????????????????????????????????????????????????????????
?????¢????????????????????????????????????????¢????????????°?????????
???????????????1?????§????????¢??????????????°???????????¨?????????
'''
def partition(A,p,r):
    x = A[r]
    i = p-1
    for j in range(p,r):
        if A[j][1] <= x[1]:
            i = i+1
            (A[i],A[j]) = (A[j],A[i])
    (A[i+1],A[r]) = (A[r],A[i+1])
    return i+1
 
def quicksort(A,p,r):
    if p < r:
        q = partition(A,p,r)
        quicksort(A,p,q-1)
        quicksort(A,q+1,r)

def isStable(A,n):
    for i in range(1,n-1):
        if A[i-1][1] == A[i][1] and A[i-1][2] > A[i][2]:
            return False
    return True

if __name__ == '__main__':
    n = (int)(input())
    A = []
    for i in range(0,n):
        tmp = list(input().split())
        A.append((tmp[0],(int)(tmp[1]),i))
    quicksort(A,0,n-1)

    print("Stable" if isStable(A,n) else "Not stable" )

    for x in A:
        print(x[0],x[1])

Measured memory_bytes: 22516
def f(l,r):
    p=2019
    for i in range(l,r+1):
        for j in range(l,r+1):
            if i==j:
                continue
            p=min((i*j)%2019,p)
    return p
    
l,r=map(int,input().split())
print(0 if r//2019-(l-1)//2019!=0 or (r//673-(l-1)//673!=0 and r//3-(l-1)//3!=0) else f(l,r))

Measured memory_bytes: 9140
// disco2020B.cpp :
#include <iostream>
#include<vector>
#include<algorithm>

using namespace std;
int main()
{
	int N;
	cin >> N;
	vector<long long>A(N);
	long long sum = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> A.at(i);
		sum += A.at(i);
	}

	vector<long long>dp_L(N + 1);
	vector<long long>dp_R(N + 1);
	//long long MIN = 9223372036854775807; // long long型の最大値
	long long MIN = sum;
	dp_L.at(0) = 0;
	dp_R.at(0) = sum;
	for (int i = 0; i < N; i++)
	{
		dp_L.at(i + 1) = dp_L.at(i) + A.at(i);
		dp_R.at(i + 1) = sum - dp_L.at(i + 1);
		MIN = min(MIN, abs(dp_L.at(i + 1) - dp_R.at(i + 1)));
	}
	cout << MIN << endl;
}


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

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

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    int a[3][3], n;
    bool x[3][3] = {false};

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }
    cin >> n;
    int b;
    for (int i = 0; i < n; i++) {
        cin >> b;
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (a[j][k] == b) x[j][k] = true;
            }
        }
    }
    bool ok = false;
    for (int i = 0; i < 3; i++) {
        if (x[i][0] and x[i][1] and x[i][2]) ok = true;
    }

    for (int i = 0; i < 3; i++) {
        if (x[0][i] and x[1][i] and x[2][i]) ok = true;
    }

    if (x[0][0] and x[1][1] and x[2][2]) ok = true;
    if (x[2][0] and x[1][1] and x[0][2]) ok = true;

    
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
import math

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        for line in sys.stdin:
            lines.append(line.strip())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
    

    n = int(lines[0])
    a = [int(e) for e in lines[1].split(' ')]

    return (n, a)


def solve(n, a):

    b = []
    for i in range(1, n):
        b.append(a[i] - a[i-1])
    
    current_money = 1000
    current_stock = 0
    for i in range(0, n):
        if i < n - 1 and b[i] >= 0:
            if current_stock == 0:
                current_stock = current_money // a[i]
                current_money = current_money - current_stock * a[i]
        else:
            if current_stock > 0:
                current_money = current_money + current_stock * a[i]
                current_stock = 0

        if debug:
            log("i=%d, current_money=%d, current_stock=%d" % (i, current_money, current_stock))

    if current_stock > 0:
        current_money = current_money + current_stock * a[n-1]


    return current_money

def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':
  
    main()


Measured memory_bytes: 62384
#include<cstdio>
#include<cstdlib>
using namespace std;
#define MAX_N 500
#define MAX_M 10000

int n, m, f[MAX_N], a[MAX_M], b[MAX_M], i, j, c;

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

int main(){
  while(1){
    scanf("%d", &n);
    scanf("%d", &m);
    for(i = 0; i < n - 1; i++) f[i] = 0;
    if(n == 0 && m == 0) break;
    c = 0;
    for(i = 0; i < m; i++){
      scanf("%d %d", &a[i], &b[i]);
      if(a[i] == 1) f[b[i] - 2] = 2;
      if(b[i] == 1) f[a[i] - 2] = 2;
    }
    for(i = 0; i < m; i++){
      if(a[i] == 1 || b[i] == 1) continue;
      if(f[a[i] - 2] == 2 && f[b[i] - 2] == 2) continue;
      if(f[a[i] - 2] == 2 && f[b[i] - 2] == 0) f[b[i] - 2] = 1;
      if(f[b[i] - 2] == 2 && f[a[i] - 2] == 0) f[a[i] - 2] = 1;
    }
    for(i = 0; i < n - 1; i++){
      if(f[i] > 0) c++;
    }
    printf("%d\n", c);
  }
  return 0;
}

Measured memory_bytes: 1108
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
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(){
    ll n,w;cin >> n >>w;
    vpl it(n);rep(i,n)cin >> it[i].fi >> it[i].se;
    vvl dp(n+1,vl(w+1));
    rep(i,n){
        rep(j,w){
            if(j+it[i].fi<=w)chmax(dp[i+1][j+it[i].fi],dp[i][j]+it[i].se);
            chmax(dp[i+1][j],dp[i][j]);
        }
    }
    ll ans=0;
    rep(i,w+1)chmax(ans,dp[n][i]);
    cout << ans <<endl;
}

Measured memory_bytes: 83000
#include <bits/stdc++.h>
using namespace std;
int64_t dp[100001][3];
int main()
  {int N; cin >> N;
  for (int i = 0; i < N; ++i)
    {int hs[3]; for (auto &h: hs) cin >> h;
    for (int j = 0; j < 3; ++j) for (int k = 0; k < 3; ++k) if (j != k) dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + hs[j]);}
  cout << *max_element(dp[N], dp[N] + 3) << endl;}

Measured memory_bytes: 5864
n = int(input())
l = list(map(int, input().split()))
ans=0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      li = [l[i], l[j], l[k]]
      
      m = max(li)
      if 2*m < sum(li) and len(set(li)) == 3:
        ans += 1
print(ans)

Measured memory_bytes: 9160
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int INF=1e9+5;
bool possible[100001]; vector<ll> a(100001,INF);
int main()
{
    fast
    ll n,W; cin>>n>>W;
    ll w[n],v[n];
    for(ll i=0;i<n;i++) cin>>w[i]>>v[i];
    possible[0]=true; a[0]=0;
    ll V=0;
    for(ll i=0;i<n;i++) V+=v[i];
    for(ll k=0;k<n;k++)
    {
        for(ll x=V;x>=0;x--)
        {
            if(possible[x])
            {
                if(x+v[k]<=V)
                {
                    possible[x+v[k]]=true;
                    a[x+v[k]]=min(a[x+v[k]],a[x]+w[k]);
                }
            }
        }
    }
    ll maxx=0;
    for(ll i=0;i<=V;i++)
    {
        if(a[i]<=W)
        {
            maxx=i;
        }
    }
    cout<<maxx;

    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k, r, s, p;
    string t;
    cin>>n>>k>>r>>s>>p>>t;
    map<char, char> win;
    win['r'] = 'p';
    win['p'] = 's';
    win['s'] = 'r';
    map<char, int> pts;
    pts['r'] = r;
    pts['s'] = s;
    pts['p'] = p;
    int ans = 0;
    vector<bool> win_seq;
    forn(i, k){
        win_seq.push_back(1);
        ans+=pts[win[t[i]]];
    }
    for (int i=k; i<n; i++){
        if(t[i]==t[i-k]){
            if(!win_seq[i-k]){
                win_seq.push_back(1);
                ans+=pts[win[t[i]]];
            }else{
                win_seq.push_back(0);
            }
        }else{
            win_seq.push_back(1);
            ans+=pts[win[t[i]]];
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1000000000000
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;

int main(){
	int n, c, k;
	cin >> n >> c >> k;
	int t[n];
	REP(i, n) cin >> t[i];
	sort(t, t+n);
	int ans = 1;
	int ct = t[0];
	int cp = 1;
	REP(i, n){
		if(ct + k < t[i] || cp > c){
			ans++;
			ct = t[i];
			cp = 1;
		}
		cp++;
	}
	cout << ans << endl;
	return 0;
}


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

class Main {

  static class Solver {
    final FastScanner sc;
    final PrintWriter writer;

    Solver(final FastScanner sc, final PrintWriter writer) {
      this.sc = sc;
      this.writer = writer;
    }

    void run() {
      int r = sc.nextInt();
      writer.println(r * 2 * Math.PI);
    }
  }

  public static void main(final String[] args) {
    final FastScanner sc = new FastScanner();
    try (final PrintWriter w = new PrintWriter(System.out)) {
      new Solver(sc, w).run();
      w.flush();
    }
  }

  // FastScanner
  static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    public FastScanner() {
    }

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

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

    private boolean isPrintableChar(final int c) {
      return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
      while (hasNextByte() && !isPrintableChar(buffer[ptr]))
        ptr++;
      return hasNextByte();
    }

    public String next() {
      if (!hasNext())
        throw new NoSuchElementException();
      final StringBuilder sb = new StringBuilder();
      int b = readByte();
      while (isPrintableChar(b)) {
        sb.appendCodePoint(b);
        b = readByte();
      }
      return sb.toString();
    }

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

    public int nextInt() {
      final long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
        throw new NumberFormatException();
      return (int) nl;
    }

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

    public int[] nextIntArray(final int n) {
      final int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(final int n) {
      final long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }
}

Measured memory_bytes: 33032
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;

using std::vector;

using std::abs;
using std::min;
using std::max;

int main() {
    int n, z, w;
    cin >> n >> z >> w;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    a.push_back(z);
    a.push_back(w);

    vector<vector<vector<int>>> dp(
        2, vector<vector<int>>(n, vector<int>(n + 2, 0)));

    for (int t = 0; t <= 1; t++) {
        for (int j = 0; j < n + 2; j++) {
            dp[t][n - 1][j] = abs(a[n - 1] - a[j]);
        }
    }

    for (int i = n - 2; i >= 0; i--) {
        for (int t = 0; t <= 1; t++) {
            for (int j = 0; j < n + 2; j++) {
                int m;
                if (t == 0) {
                    m = max(dp[t][i+1][j], dp[!t][i+1][i]);
                } else {
                    m = min(dp[t][i+1][j], dp[!t][i+1][i]);
                }
                dp[t][i][j] = m;
            }
        }
    }

    cout << dp[0][0][n+1] << endl;
    return 0;
}


Measured memory_bytes: 47360
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s,t = input().split()
    print(t+s)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 39152
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
const int nax=1007;
using pii=pair<int,int>;

int n, d1, d2;

vector <pii> graf[2][nax][nax];

int odl(pii a, pii b)
{
	a.first-=b.first;
	a.second-=b.second;
	return a.first*a.first+b.second*b.second;
}

int czyok(pii a)
{
	return (min(a.first, a.second)>=0 && max(a.first, a.second)<2*n);
}

int bylo[2][nax][nax];
int roz[2][2];

void dfs(int h, pii v, int kol)
{
	if (bylo[h][v.first][v.second])
	{
		assert(kol==bylo[h][v.first][v.second]);
		return;
	}
	bylo[h][v.first][v.second]=kol;
	for (pii i : graf[h][v.first][v.second])
		dfs(h, i, kol^1);
}

int main()
{
	scanf("%d%d%d", &n, &d1, &d2);
	vector <pii> wek;
	for (int i=0; i<2*n; i++)
		for (int j=0; j<2*n; j++)
			wek.push_back({i, j});
	for (int i=-2*n; i<=2*n; i++)
		for (int j=-2*n; j<=2*n; j++)
			if (i*i+j*j==d1 || i*i+j*j==d2)
				for (int a=0; a<2*n; a++)
					for (int b=0; b<2*n; b++)
						if (czyok({a+i, b+j}))
							graf[i*i+j*j==d2][a][b].push_back({a+i, b+j});
	
	for (int h=0; h<2; h++)
		for (pii i : wek)
			if (!bylo[h][i.first][i.second])
				dfs(h, i, 2);
	for (pii i : wek)
		roz[bylo[0][i.first][i.second]-2][bylo[1][i.first][i.second]-2]++;
	for (int i=0; i<2; i++)
	{
		for (int j=0; j<2; j++)
		{
			if (roz[i][j]>=n*n)
			{
				int jesz=n*n;
				for (pii l : wek)
				{
					if (!jesz)
						break;
					if (bylo[0][l.first][l.second]-2==i && bylo[1][l.first][l.second]-2==j)
					{
						jesz--;
						printf("%d %d\n", l.first, l.second);
					}
				}
				return 0;
			}
		}
	}
	assert(0);
	return 0;
}


Measured memory_bytes: 210540
//Author:- Yatin Patel
//Mail:- yatinpatel.gt@gmail.com

#include <bits/stdc++.h>
#define FILEIN ifstream fin;fin.open("input.txt");
#define FILEOUT ofstream fout;fout.open("output.txt");

using namespace std;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

#define FAST ios::sync_with_stdio(false);ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second

#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define minQueue priority_queue<ll,vector<ll>,greater<ll> >
#define maxQueue priority_queue<ll,vector<ll>,less<ll> > 

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define RFOR(i,a,b) for(ll i=a;i>b;i--)
#define FILL(a,b) memset((a),(b),sizeof((a)))

#define MOD 1000000007
#define INF LONG_MAX
#define MINF LONG_MIN

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

ll power(ll x, unsigned ll y){
    if (y == 0)
        return 1;
    else if (y%2 == 0)
        return power(x, y/2)*power(x, y/2);
    else
        return x*power(x, y/2)*power(x, y/2);
}

//#define fin cin
//#define fout cout

int main(){

    FAST;
    ll n,m;
    cin>>n>>m;
    vector<ll>v(m+1,0);
    for(ll i=0;i<n;i++){
        ll k;
        cin>>k;
        for(ll j=0;j<k;j++){
            ll tmp;
            cin>>tmp;
            v[tmp]++;
        }
    }
    ll ans = 0;
    for(ll i=0;i<=m;i++){
        if(v[i]==n){
            ans++;
        }
    }
    cout<<ans;
    return 0;
}






Measured memory_bytes: 256
a,b = input().split()
if a == 'H' and b == 'H':
    print('H')
elif a == 'H' and b == 'D':
    print('D')
elif a == 'D' and b == 'H':
    print('D')
elif a == 'D' and b == 'D':
    print('H')
    
    

Measured memory_bytes: 2940
N = int(input())
data = [list(map(int, input().split())) for _ in range(N)]

t = 0
x = 0
y = 0

for i in range(N):
    distance = abs(x - data[i][1]) + abs(y - data[i][2])
    time = data[i][0] - t
    if distance > time :
        print('No')
        exit()
    if (distance - time) % 2 == 1:
        print('No')
        exit()

    t = data[i][0]
    x = data[i][1]
    y = data[i][2]

print('Yes')

Measured memory_bytes: 27300
#include<stdio.h>
int main(void)
{
  int judge=0;
  char s[3];
  
  scanf("%s",s);
 
  if(s[0]=='a'){
    if(s[1]=='b'){
      if(s[2]=='c')
        judge=1;
    }else if(s[1]=='c'){
      if(s[2]=='b')
        judge=1;
    }
  }else if(s[0]=='b'){
    if(s[1]=='a'){
      if(s[2]=='c')
        judge=1;
    }else if(s[1]=='c'){
      if(s[2]=='a')
        judge=1;
    }
  }else if(s[0]=='c'){
    if(s[1]=='b'){
      if(s[2]=='a')
        judge=1;
    }else if(s[1]=='a'){
      if(s[2]=='b')
        judge=1;
    }
  }
  if(judge==0)
    puts("No");
  else if(judge==1)
    puts("Yes");
  return 0;
}


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

int c[10][1001];

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  int ans = INF;
  rep (div, 1 << (h-1)) {
    int g = 0;
    vector<int> id(h);
    rep(i,h) {
      id[i] = g;
      if (div >> i & 1) g++;
    }
    g++;
    rep(i,g)rep(j,w) c[i][j] = 0;
    rep(i,h)rep(j,w) c[id[i]][j] += (s[i][j] - '0');
    
    bool ok = true;
    rep(i,g)rep(j,w) if(c[i][j] > k) ok = false;
    if (!ok) continue;
    int num = g-1;
    vector<int> now(g);
    auto add = [&](int j) {
      rep(i,g) now[i] += c[i][j];
      rep(i,g) if (now[i] > k) return false;
      return true;
    };
    rep(j,w) {
      if (!add(j)) {
        num++;
        now = vector<int>(g);
        add(j);
      }
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
n,m=map(int, input().split())
v = [0]*n
v[0]=1
ans = [1]*n
fi = 1
for i in range(m):
    a,b=map(int, input().split())
    ans[a-1]-=1
    ans[b-1]+=1
    if v[a-1]:
        v[b-1]=1
        fi+=1
    if ans[a-1]==0:
        v[a-1]=0
        fi-=1

print(sum(v))


Measured memory_bytes: 4852
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
using namespace std;

long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long res = 0;
	long N; cin >> N;
	long a[100009]; for (int i = 1; i <= N; i++) cin >> a[i];
	long myaug = 1;
	long mycount = 0;
	sort(a + 1, a + N + 1);

	for (long num = a[1]; num <= a[N];) {
		mycount = 0;
		while (a[myaug] == num) { myaug++; mycount++; if(myaug == N + 1) break; }
		//numはmycount個
		res += (mycount >= num) ? mycount - num : mycount;
        
        if (myaug == N + 1) break;
	    num = a[myaug];
	}

	cout << res << endl;
}

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

void init() {
#ifdef MADE_BY_SERT
    freopen("a.in", "r", stdin);
    ///freopen("a.out", "w", stdout);
#endif
}

typedef long long ll;
typedef long double ld;

const double EPS = 1e-9;
const int INF = (int)1e9 + 41;
const int N = (int)1e6 + 34;
int a[N];
void solve() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", a + i);
    }
    int lst = a[0];
    int len = 1;
    int ans = 0;
    for (int i = 1; i < n; i++) {
        if (a[i] == a[i - 1]) len++;
        else {
            ans += len / 2;
            len = 1;
        }
    }
    cout << ans + len / 2 << "\n";
}

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



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

typedef long long ll;

int main(){
	int n;
	cin >> n;
	int res =0;
	for(int i=1;i<=n;++i){
		int p = n-i;
		if(i >= p){
			break;
		}
		res++;
	}
	cout << res <<endl;
	return 0;
}


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

using namespace std;

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

int main() {
  const int N = 500100;
  char s[N];
  scanf("%s", s);
  int n = strlen(s);
  ll sum = 0;

  ll cur = 0;

  FOR(i, n) {
    if (s[i] == '<') {
      cur++;
      sum += cur;
    } else {
      int j = i;
      while (j < n && s[j] == '>') j++;
      ll kol = j - i;
      sum += max(0LL, kol - cur);
      cur = max(cur, kol);
      for (int k = kol-1; k ; k--) sum += k;
      cur = 0;
      i = j-1;
    }
  }

  printf("%lld\n", sum);
  return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (b <= c || d <= a) {
		cout << 0 << endl;
	}
	else
		cout << min(b, d) - max(a, c) << endl;
	return 0;
}



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

int main() {
  int x, y;
  cin >> x >> y;
  bool b = false;
  if(x == 4 || x == 6 || x == 9) {
    if(y = 6 || y == 9 || y == 11) {
      b = true;
    }
  }
  else if(x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10) {
    if(y == 12 || y == 3 || y == 5  || y == 7 || y == 8 || y == 10) {
      b = true;
    }
  }
  if(b) {
    cout << "Yes";
  }
  else {
    cout << "No";
  }
}



Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

h,w,k = li()
MOD = 10**9+7

cnt = [[0 for _ in range(w)] for _ in range(h+1)]
cnt[0][0] = 1

nex_list = []
for i in range(1<<(w-1)):
    if not "11" in bin(i)[2:]:
        nex_list.append(i)
        
for hi in range(1,h+1):
    for bit in nex_list:
        changed = [0]*w

        for i, b in enumerate(bin(bit)[2:].zfill(w-1)):
            
            if b == "1":
                cnt[hi][i] += cnt[hi-1][i+1]
                cnt[hi][i+1] += cnt[hi-1][i]
                changed[i] = 1
                changed[i+1] = 1
        for j,c in enumerate(changed):
            if c == 0:
                cnt[hi][j] += cnt[hi-1][j]
                
    for wj in range(w):
        cnt[hi][wj] %= MOD
        
print(cnt[h][k-1])
        

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<string>
#include<numeric>
using namespace std;
typedef long long ll;
//ll mod = 1e9+7;
ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    if ( k == 0 ) {
        cout << n * n << endl;
        return 0;
    }
    for ( ll i = k + 1; i <= n; ++i ) {
        int mod_group_num = n / i;
        int cntup_num = i - k;
        int rest_num = n - mod_group_num * i;
        int add_cntup_num = max(0LL, rest_num - k + 1);
        ans += cntup_num * mod_group_num + add_cntup_num;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n,q;

int main(){
    scanf("%d%d",&n,&q);
    set<pair<pii,int>> W,R;
    set<pair<int,pii>> C;
    REP(i,n){
        int s,t,x;
        scanf("%d%d%d",&s,&t,&x);
        W.insert(make_pair(pii(s-x,t-x),x));
    }
    REP(i,q){
        int d;
        scanf("%d",&d);
        while(W.size()>0 && W.begin()->first.first <= d){
            // add
            int s = W.begin()->first.first;
            int t = W.begin()->first.second;
            int x = W.begin()->second;
            // printf("in: %d %d %d\n",s,t,x);
            W.erase(W.begin());
            C.insert(make_pair(x,pii(t,s)));
            R.insert(make_pair(pii(t,s),x));
        }
        while(R.size()>0 && R.begin()->first.first <= d){
            // delete
            int s = R.begin()->first.second;
            int t = R.begin()->first.first;
            int x = R.begin()->second;
            // printf("out: %d %d %d\n",s,t,x);
            R.erase(R.begin());
            C.erase(make_pair(x,pii(t,s)));
        }
        if(C.size()==0){
            puts("-1");
        }else{
            printf("%d\n",C.begin()->first);
        }
    }
    return 0;
}


Measured memory_bytes: 26240
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

int main() {
	ll N,K;
	cin>>N>>K;
	vector<int> P(N);
	for (int i = 0; i < N; i++){
		int tmp;cin>>tmp;
		P[i]=tmp-1;
	}
	vector<ll> C(N,0);
	for (int i = 0; i < N; i++){
		cin>>C[i];
	}
	vector<ll> from(N,0);
	for (int i = 0; i < N; i++){
		int start=i;
		int loop_len=1;
		int next=P[start];
		ll loop_sum=C[next];
		while(next!=start){
			next=P[next];
			loop_len++;
			loop_sum+=C[next];
		}
		next=P[start];
		from[start]=C[next];
		ll tmpsum=C[next];
		if(K<loop_len){
			for (int j = 1; j < K; j++){
				next=P[next];
				tmpsum+=C[next];
				from[start]=max(from[start],tmpsum);
			}
		}else if(loop_sum>0){
			for (int j = 1; j < K%loop_len+loop_len; j++){
				next=P[next];
				tmpsum+=C[next];
				from[start]=max(from[start],tmpsum);
			}
			from[start]+=loop_sum*(K/loop_len-1);
		}else{
			for (int j = 1; j < loop_len; j++){
				next=P[next];
				tmpsum+=C[next];
				from[start]=max(from[start],tmpsum);
			}
		}
	}
	sort(from.begin(),from.end());
	cout<<from[N-1]<<endl;
}

Measured memory_bytes: 3796
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <climits>
#include <stack>
#define ll long long int
#define MOD 1000000007
#define eps 0.001 ;

using namespace std ;

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

ll n ;
cin>>n ;
ll arr[n] ;
ll  c  = 0 ;
ll v = 0 ;
for(ll i = 0  ; i< n  ;++i)
  {cin>>arr[i] ;
    if(arr[i] % 4 ==0 )
      c++;

      if(arr[i] % 4 == 2)
        v++ ;

      }


 ll k ;

   if(v > 0 ){

   if((n-v) % 2 == 0)
     k =  (n-v)/2 ;
    else
    k =  (n-v)/2 + 1  ;
}
  else
    {

      k  =  n/2 ;

    }

   // cout<<k<<"\n" ;

  if(c  >= k)
  cout<<"Yes" ;
  else
  cout<<"No" ;


return  0 ;
}


Measured memory_bytes: 1024
N = int(input())
list1=[int(i) for i
       in input().split()]

count = 0
flug = bool(False)
#print(len(list1))
while flug == False:
  for i in range(len(list1)):
    if list1[i] % 2 != 0:
      #print("here")
      flug = bool(True)
      count = count - 1
      break
    list1[i] = int(list1[i]) / 2
  count = count + 1
print(count)
      

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

typedef long long ll;



int main() {
  // Failed to predict input format
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll H, W;
  cin >> H >> W;
  ll Ch, Cw;
  cin >> Ch >> Cw;

  ll Dh, Dw;
  cin >> Dh >> Dw;

  Ch--;
  Dh--;
  Cw--;
  Dw--;

  const auto ix = [W](ll h, ll w) {
    return h * W + w;
  };
  vector<bool> S(H * W);
  for (ll h = 0; h < H; ++h) {
    for (ll w = 0; w < W; ++w) {
      char c;
      cin >> c;
      S[ix(h,w)] = (c == '.');
    }
  }

  ll inf = H*W+1;
  using P = pair<ll,ll>;
  using PD = pair<ll, P>;

  vector<ll> res(H * W, inf);

  set<PD> s;
  s.insert({0, {Ch, Cw}});
  res[ix(Ch, Cw)] = 0;

  while (!s.empty()) {
    auto P = *s.begin();
    s.erase(s.begin());
    auto h = P.second.first;
    auto w = P.second.second;

    const auto walk = [&ix, &res, &s, &S](ll h, ll w, ll hd, ll wd) {
      ll next = ix(h+hd, w+wd);
      ll curr = ix(h,w);
      if (S[next] && res[next] > res[curr]) {
        res[next] = res[curr];
        s.insert({res[curr],{h+hd, w+wd}});
      }
    };
    // walk
    if (h > 0) {
      walk(h, w, -1, 0);
    }
    if (h < H-1) {
      walk(h, w, 1, 0);
    }
    if (w > 0) {
      walk(h, w, 0, -1);
    }
    if (w < W-1) {
      walk(h, w, 0, 1);
    }
    // tele
    for (ll hd = -2; hd <= 2; ++hd) {
      for (ll wd = -2; wd <= 2; ++wd) {
        auto nh = h + hd;
        auto nw = w + wd;
        if (nh >= 0 && nh < H
            && nw >= 0 && nw < W
            && S[ix(nh,nw)]
            && res[ix(nh,nw)] > res[ix(h,w)] + 1) {
          res[ix(nh, nw)] = res[ix(h,w)] + 1;
          s.insert({res[ix(h,w)]+1, {nh, nw}});
        }
      }
    }
  }

  ll rv = res[ix(Dh, Dw)];

  cout << (rv == inf ? -1 : rv)  << endl;

  return 0;
}


Measured memory_bytes: 11836
N = int(input())
a = [int(input()) for i in range(N)]
f = []
x = 1
while x <= N:
    f.append(x)
    x = 3*x + 1
cnt = 0
g = f[::-1]

def insertionSort(a, N, g):
    global cnt
    for i in range(g, N):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j + g] = a[j]
            j -= g
            cnt += 1
        a[j + g] = v
  
m = len(g)    
for j in range(m):
    insertionSort(a, N, g[j])

print(m)
print(" ".join(map(str, g)))
print(cnt)
for i in range(N):
    print(a[i])

Measured memory_bytes: 47648