akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <thread>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

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

	vector<int> ms(m);
	for (auto& coin : ms) {
		cin >> coin;
	}
	sort(ms.begin(), ms.end(), greater<int>());

	array<int, 50001> dp = { 0 };
	FOR_LE(i, 1, n) {
		int min_c = INT_MAX;
		FOR_LT(c, 0, m) {
			if (i - ms[c] < 0) continue;
			min_c = min(min_c, dp[i - ms[c]] + 1);
		}
		dp[i] = min_c;
	}

	cout << dp[n] << endl;


	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
//for(int i = 0; i<n; i++)
 
 
int main()
{
    int n;string s,t;
    cin>>n>>s>>t;
    int ans = 0;
    int i;
    for(i = 1; i <= n; i++){
        if(s.substr(n - i,i) == t.substr(0, i)) ans = i;
    }
    cout << n*2 - ans << endl;
    return 0;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int i;
    string s;
    cin>>s;
    set<char> t;
    for (i=0;i<3;i++)
        t.insert(s[i]);
    if (t.size()==3)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
     
    int main()
    {
        int x,v,b,c;
        while(cin>>v>>b>>c>>x){
            x/=50;
            int sum=0;
            for(int i=0;i<=v;i++){
                for(int j=0;j<=b;j++){
                    for(int k=0;k<=c;k++){
                        if(i*10+j*2+k==x) sum++;
                    }
                }
            }
            cout<<sum<<endl;
        }
        return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 10000000000000000; //10^16
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;


int main(void){
    int N;
    cin >> N;
    vector<int> a(101, 0);
    int tmp;
    for(int i = 1 ; i <= N; i++){
        tmp = i;
        for(int j = 2; j * j <= tmp; j++){
            while(tmp % j == 0){
                a.at(j)++;
                tmp = tmp / j;
            }
        }
        if(tmp != 1) a.at(tmp)++;
    }
    
    int ans = 0;
    //74
    for(int i = 2; i <= 100; i++){
        if(a.at(i) >= 74) ans++;
    }
    //4+14
    for(int i = 2; i <= 100; i++){
        for(int j = 2; j <= 100; j++){
            if(i == j) continue;
            if(a.at(i) >= 4 && a.at(j) >= 14) ans++;
        }
    }
    //2+24
    for(int i = 2; i <= 100; i++){
        for(int j = 2; j <= 100; j++){
            if(i == j) continue;
            if(a.at(i) >= 2 && a.at(j) >= 24) ans++;
        }
    }
    int tmpans = 0;
    //2+4+4
    for(int i = 2; i <= 100; i++){
        for(int j = 2; j <= 100; j++){
            if(i == j) continue;
            for(int k = 2; k <= 100; k++){
                if(k == j) continue;
                if(i == k) continue;
                if(a.at(i) >= 2 && a.at(j) >= 4 && a.at(k) >= 4) tmpans++;
            }
        }
    }
    ans += tmpans/2;
    printf("%d\n", ans);
}



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

int main(void){
    string S;
    bool flag = false;
    cin >> S;
    for(int i=0;i<S.length();i++){
        if(i%2 == 0){
            if(S[i] == 'L'){
                flag = true;
            }
        }else{
            if(S[i] == 'R'){
                flag = true;
            }
        }
        if(flag) break;
    }

    if(flag) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
from math import ceil
N = int(input())

x = list(map(int,input().split()))
x_sort = sorted(x)
length = len(x)
median = (x_sort[ceil(length/2-1)]+x_sort[ceil(length/2)])/2

for i in range(length):
    if x[i] <= median:
        print(x_sort[ceil(length/2)])
    else:
        print(x_sort[ceil(length/2-1)])


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

def main():
    A,V = map(int,input().split())
    B,W = map(int,input().split())
    T = int(input())

    if B>A:
        d1 = V*T+A
        d2 = W*T+B
        if (d1 >= d2):
            print('YES')
        else:
            print('NO')
    else:
        d1 = -V*T+A
        d2 = -W*T+B
        if (d2 >= d1):
            print('YES')
        else:
            print('NO')
if __name__ == '__main__':
    main()


Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<n;++i)
const int SIZE = 200005;
int main(){
    long long ans = 0;
    int n, d, a;
    cin >> n >> d >> a;
    vector<int> cs(n+1);
    vector<pair<int, int>> vp;
    for (int i = 0; i < n; i++)
    {
        int x, h;
        cin >> x >> h;
        vp.push_back(make_pair(x, h));
    }
    sort(vp.begin(), vp.end());
    int r = 0;
    pair<int, int> p;
    rep(i,n){
        vp[i].second -= cs[i];
        while(r<n && vp[r].first <= vp[i].first + 2*d)++r;
        if (vp[i].second > 0)
        {
            int num = (vp[i].second + a - 1) / a;
            ans += num;
            cs[i]+=num*a;
            cs[r]-=num*a;
        }
        cs[i+1] += cs[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
    char c[3][4];
    for (int i = 0; i < 3; i++) {
        cin >> c[i];
    }

    for (int i = 0; i < 3; i++) {
        cout << c[i][i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  int i,j,n,h,tmp1[200],len,count;
  char data[200];
  
  
  while(1){
    scanf("%s",data);
    len=strlen(data);
    if(len==1 && data[0]=='-')break;
    //printf("len=%d\n",len);
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
      scanf("%d",&h);
      
      //printf("tmp:");
      for(j=0;j<h;j++){ //?????´???tmp????´?
        tmp1[j]=data[j];
        //printf("%c",tmp1[j]);
      }
      //puts("");
      
      for(j=0;j<len-h;j++){ //????????´??????????????????
        data[j]=data[j+h];
      }
      count=0;
      for(j=len-h;j<len;j++){ //????????´???tmp??\??????
        data[j]=tmp1[count];
        count++;
      }
    }
    for(j=0;j<len;j++){ //??????
      printf("%c",data[j]);
    }
    printf("\n");
  }
}

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

bool ok(const vector<vector<int>> &a) {
        int sum = a[0][0] + a[0][1] + a[0][2];
        for (int i = 0; i < 3; i ++) if (sum != a[i][0] + a[i][1] + a[i][2]) return false;
        for (int i = 0; i < 3; i ++) if (sum != a[0][i] + a[1][i] + a[2][i]) return false;
        if (a[0][0] + a[1][1] + a[2][2] != sum) return false;
        if (a[0][2] + a[1][1] + a[2][0] != sum) return false;
        return true;
}

int main() {
        vector<vector<int>> a(3, vector<int> (3));
        scanf("%d%d%d", &a[0][0], &a[0][1], &a[1][1]);
        for (int x = 0; x <= 1000; x ++) {
                a[0][2] = x;
                int sum = a[0][0] + a[0][1] + a[0][2];
                a[2][1] = sum - a[0][1] - a[1][1];
                a[2][2] = sum - a[0][0] - a[1][1];
                a[2][0] = sum - a[0][2] - a[1][1];
                a[1][0] = sum - a[0][0] - a[2][0];
                a[1][2] = sum - a[0][2] - a[2][2];
                if (ok(a)) {
                        for (int i = 0; i < 3; i ++) for (int j = 0; j < 3; j ++) printf("%d%c", a[i][j], j == 2 ? '\n' : ' ');
                        break;
                }
        }
        return 0;
}



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

struct t
{
	long long a, b, sum;
};

bool cmp(t x,t y)
{
	return x.sum > y.sum;
}

int main()
{
	int n;
	long long ans = 0;
	scanf("%d",&n);
	t dish[n+1];
	for (int i = 0; i < n; i++)
	{
		scanf("%lld",&dish[i].a);
		scanf("%lld",&dish[i].b);
		dish[i].sum = dish[i].a + dish[i].b;
	}
	std::sort(dish,dish+n,cmp);
	if ( n & 1 )
		ans += dish[--n].a;
	for (int i = 0; i < n; i += 2)
	{
		ans += dish[i].a;
		ans -= dish[i+1].b;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <map>
#include<cmath>
#include <queue>
#include <stack>
#include <numeric>
#include <cassert>
#include<map>
#include<bitset>

using lli = long long int;
lli inf = 1000000007;
using namespace std;

void solve() {
	int N, M;
	cin >> N >> M;
	vector<int> H(N);
	for (int i = 0; i < N; i++)cin >> H[i];

	bool ok[100010] = {};
	// false の数を数える
	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;
		A -= 1;
		B -= 1;
		if (H[A] > H[B]) {
			ok[B] = true;
		}
		else if (H[A] < H[B]) {
			ok[A] = true;
		}
		else {
			ok[A] = ok[B] = true;
		}
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (!ok[i])ans++;
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 3788
N, M = gets.split.map(&:to_i)

shops = []
N.times do
  a, b = gets.split.map(&:to_i)
  shops << [a, b]
end

shops.sort_by! {|s| s[0]}

num = 0
money = 0
shops.each do |shop|
  if M <= num + shop[1]
    money += (M - num) * shop[0]
    num += M - num
    break
  else
    num += shop[1]
    money += shop[1] * shop[0]
  end
end

puts money


Measured memory_bytes: 12664
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	
	public static void InsertionSort(final int N, int[] A){
		for(int i = 0; i < N; i++){
			final int v = A[i];
			
			int j = i - 1;
			while(j >= 0 && A[j] > v){
				A[j+1] = A[j];
				j--;
			}
			
			A[j+1] = v;
			
			
			for(int k = 0; k < N; k++){
				if(k != 0){ System.out.print(" "); }
				System.out.print(A[k]);
			}
			System.out.println();
		}
	}
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0; i < N; i++){
			A[i] = sc.nextInt();
		}
		
		InsertionSort(N, A);
		
	}
}

Measured memory_bytes: 26092
#include <bits/stdc++.h>
#include <string.h>
#include <iostream>

int main(void) {
  int x,y;

  scanf("%d %d", &x, &y);

  for(int i = 0; i <= 100; i++){
    for (int j = 0; j <= 100; j++) {
      if ((i + j)==x && (i*2)+(j*4) == y) {
        printf("Yes");
        return 0;
      }
    }
  }

  printf("No");
  return 0;
}

Measured memory_bytes: 3752
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};

struct word {
  vec: Vec<char>,
  string: String,
}

fn main() {
  let n = read::<i32>();
  let mut words = vec![];
  let mut used_words = vec![];

  for _ in 0..n {
    let w = read::<String>();
    let w_vec = w.chars().collect::<Vec<char>>();
    words.push(word {
      vec: w_vec,
      string: w,
    });
  }

  let mut prev_last = words[0].vec[0];
  let mut result = true;

  for i in words {
    if i.vec[0] != prev_last || used_words.contains(&i.string) {
      result = false;
      break;
    }
    prev_last = *i.vec.last().unwrap();
    used_words.push(i.string);

  }

  if result {
    println!("Yes");
  } else {
    println!("No");
  }
}



Measured memory_bytes: 4352
s = input()
k = int(input())

def do(s):
    x = 0
    cur = ""
    count = 1
    #print("s={0}".format(s))
    for i in range(len(s)):
        #print("i={0}, cur = ".format(i, cur))
        if cur == s[i]:
            count += 1
            #print(" same count = {0}".format(count))
        else:
            x += count // 2
            #print(" change add = {0}".format(count // 2))
            count = 1
        cur = s[i]
    x += count // 2
    #print(" change add = {0}".format(count // 2))
    return x

res1 = do(s)
res2 = do(s*2)
res3 = do(s*3)


if k == 1:
    print(res1)
elif k == 2:
    print(res2)
elif k == 3:
    print(res3)
else:
    if (k-1) % 2 == 1:
        res = res1
        res += ( (res3-res2) + (res2-res1) ) * ( (k-1) // 2)
        res += (res2-res1)
    elif (k-1) % 2 == 0:
        res = res1
        res += ( (res3-res2) + (res2-res1) ) * ( (k-1) // 2)
    print(res)


Measured memory_bytes: 38504
import java.io.*; 
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 sc = new FastReader(); 
        PrintWriter out = new PrintWriter(System.out); 

        int n = sc.nextInt();
        int k = sc.nextInt();
        long[] arr = new long[n], dp = new long[n];
        Arrays.fill(dp, -1);

        dp[0] = 0;
        for(int i=0;i<n;i++){
            arr[i] = sc.nextLong();
            int j = i-1;
            while(j>=0 && (i-j<=k)){
	            if(dp[i]==-1)
	            	dp[i] = dp[j]+Math.abs(arr[i]-arr[j]);
	            else
	            	dp[i] = Math.min(dp[j]+Math.abs(arr[i]-arr[j]), dp[i]);
	            j--;
        	}
        }

        out.println(dp[n-1]);
        out.close();
	} 
} 


Measured memory_bytes: 32524
import java.util.*;

public class Main {
	
	private static void checkBalance(int A, int B, int C, int D) {

		int L = A + B;
		int R = C + D;

		if (L > R) {
			System.out.println("Left");
		} else if (L < R) {
			System.out.println("Right");
		} else {
			System.out.println("Balanced");
		}
	}

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		int A = in.nextInt();
		int B = in.nextInt();
		int C = in.nextInt();
		int D = in.nextInt();

		checkBalance(A, B, C, D);
	}


}

Measured memory_bytes: 21972
package main

import "fmt"

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)

	fmt.Println(min(a, b) + min(c, d))
}


Measured memory_bytes: 512
n = gets.to_i
s = gets.split.map(&:to_i)
q = gets.to_i
t = gets.split.map(&:to_i)

count = 0
s.each do |x|
  t1 = t
  t.each do |y|
    if x == y
      count += 1
      t1 -= [y]
    end
  end
  t = t1
end
puts count


Measured memory_bytes: 7128
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int N;
    cin >> N;
    vector<int> L;
    rep(i, N) {
        int Li;
        cin >> Li;
        L.pb(Li);
    }

    int count = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            for (int k = j + 1; k < N; k++) {
                if(L[i] != L[j] && L[i] != L[k] && L[j] != L[k]) {
                    vector<int> tri;
                    tri.pb(L[i]);
                    tri.pb(L[j]);
                    tri.pb(L[k]);
                    sort(all(tri));
                    if(tri[0] + tri[1] > tri[2]) count++;
                }
            }
        }
    }

    cout << count << endl;
}


Measured memory_bytes: 3664
#include<stdio.h>
 
int heap[1000];
 
void output(int k, int n){
    printf("node %d: key = %d, ", k, heap[k]);
    if( k/2 > 0 ){ printf("parent key = %d, ", heap[k/2]); }
    if( k*2 <= n ){ printf("left key = %d, ", heap[k*2]); }
    if( k*2 + 1 <= n ){ printf("right key = %d, ", heap[k*2+1]); }
    printf("\n");
    return;
}
 
int main(){
    int n, i;
    scanf("%d", &n);
    for( i = 1; i <= n; i++ ){ scanf("%d", &heap[i]); }
    for( i = 1; i <= n; i++ ){ output(i, n); }
    return 0;
}


Measured memory_bytes: 2052
import java.io.*;

public class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(br.readLine());
    String[] line = br.readLine().split(" ");
    int[] array = new int[n];
    int i=0;
    int count = 0;
    for(; i<n; i++){
      array[i] = Integer.parseInt(line[i]);
      if( array[i] != i+1 ){
        count++;
        if( 2 < count ){
          System.out.println("NO");
          break;
        }
      }
    }
    if( i == n )
      System.out.println("YES");
  }
}


Measured memory_bytes: 21204
#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
using namespace std;
int main(){

	int x,y;
	cin >> x >> y;
	if(x==1||x==3||x==5||x==7||x==8||x==10||x==12)
		if(y==4||y==6||y==9||y==11||y==2){
			puts("No");
		}else{
			puts("Yes");
		}
	else if(x==4||x==6||x==9||x==11)
		if(y==4||y==6||y==9||y==11){
			puts("Yes");
		}else{
			puts("No");
		}
	else
		if(y==2){
			puts("Yes");
		}else{
			puts("No");
		}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <deque>
#include <map>
#include <iomanip>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <utility>
using namespace std;
int ky[8] = {-1,1,-2,2,-2,2,-1,1}; 
int kx[8] = {-2,-2,-1,-1,1,1,2,2};
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int ddy[8] = {-1,0,1,-1,1,-1,0,1};
int ddx[8] = {-1,-1,-1,0,0,1,1,1};
typedef long long ll;
#define pi pair
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define rep1(i,a,b) for(int i = a; i < b; i++)
#define rep2(i,a,b) for(int i = a; i <= b; i++) 
#define LB lower_bound
#define UP upper_bound
#define INF 999999999999
const double PI = acos(-1.0);
ll N;
map<ll,ll> m;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin >> N;
    ll ans = 0;
    rep1(i,0,N){
        ll x; cin >> x;
        ans += m[i-x];
        m[i+x]++;
    }
    cout << ans;
    return 0;     
}



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

int main(){
    vector<int> moji(3);

    cin >> moji[0] >> moji[1] >> moji[2];

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

    if(moji[0]== 5 && moji[1]==5 && moji[2]==7){
            cout<<"YES"<<endl;
    }else{
            cout<<"NO"<<endl;
    }
    return 0;
}

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

string data[10]={
"* = ****",
"* =* ***",
"* =** **",
"* =*** *",
"* =**** ",
" *= ****",
" *=* ***",
" *=** **",
" *=*** *",
" *=**** "
};

int main(){
	string n;
	for(int f=0;cin>>n;f++){
		if(f)cout<<endl;
		for(;n.size()<5;n="0"+n);
		for(int i=0;i<8;i++){
			for(int j=0;j<5;j++){
				int k=n[j]-'0';
				cout<<data[k][i];
			}
			cout<<endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 1188
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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


long long beki(long long a,int n)
{
  long long s=1LL;
  while(n){
    if(n%2)s=(s*a)%MOD;
    a=(a*a)%MOD;
    n/=2;
  }
  return s;
}

int main(void) {
  int i,j;
  int n;
  cin>>n;
  vi a(n);
  ll sum=1;
  rep(i,n)cin>>a[i];
  rep(i,n)
    if(a[i]%2==0)sum*=2;
  ll ans=beki(3,n)-sum;
  cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>
#include <math.h>           // fabs()

int
main(int argc, char **argv)
{
	double x, y;
	int q;

	while (true)
	{
		scanf("%d", &q);
		if (q == -1)
			break;

		x = q / 2.0;
		while (fabs(x * x * x - q) >= 0.00001 * q)
		{
			y = x - (x * x * x - q) / (3 * x * x);
			x = y;
		}

		printf("%.6f\n", x);
	}

	return 0;
}

Measured memory_bytes: 636
from time import time
import random


def main():
    random.seed(0)

    now = time()

    MAX = 26

    # 入力
    d = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(d)]

    # 初期解を貪欲法で求める
    t = []
    prev = [0] * MAX
    for day, row in enumerate(s, 1):
        mxi = 1
        mx = 0
        for i, (es, ec) in enumerate(zip(row, c), 1):
            point = es + ec * (day - prev[i - 1])
            if point > mx:
                mx = point
                mxi = i

        prev[mxi - 1] = day
        t.append(mxi)

    # 初期解に対する満足度を計算
    last = [0] * MAX
    score = 0
    for day, e in enumerate(t, 1):
        score += s[day-1][e-1]
        last[e-1] = day

        for ec, elast in zip(c, last):
            score -= ec * (day - elast)

    # 変更を検討する日にちの選ばれやすさ
    d_li = []
    for i in range(1, d + 1):
        ln = max(1, (-(i - d // 2) ** 2 + d ** 2 // 4) // 500)
        d_li += [i] * ln

    d_li = list(range(1, d + 1))
    di_max = len(d_li) - 1

    # 各日にちにおいて変更を検討するコンテストの選ばれやすさ
    sc = []
    for row in s:
        app = []
        for i, (es, ec) in enumerate(zip(row, c), 1):
            app += [i] * max(1, (es + ec * d) // 20)

        sc.append(app)

    # 時間の許す限り更新を検討する
    while time() - now <= 1.85:
        prev_score = score

        di = random.randint(0, di_max)
        ed = d_li[di]
        qi = random.randint(0, len(sc[ed-1]) - 1)
        eq = sc[ed-1][qi]

        q_old = t[ed-1]
        d_prev = {q_old: 0, eq: 0}

        c_old = c[q_old-1]
        c_new = c[eq-1]

        for day, e in enumerate(t, 1):
            if e in d_prev.keys():
                d_prev[e] = day

            score += c_old * (day - d_prev[q_old])
            score += c_new * (day - d_prev[eq])

        score -= s[ed-1][q_old-1]
        score += s[ed-1][eq-1]

        t[ed-1] = eq

        d_prev = {q_old: 0, eq: 0}

        for day, e in enumerate(t, 1):
            if e in d_prev.keys():
                d_prev[e] = day

            score -= c_old * (day - d_prev[q_old])
            score -= c_new * (day - d_prev[eq])

        if prev_score > score:
            t[ed-1] = q_old
            score = prev_score

    print(*t, sep="\n")


if __name__ == "__main__":
    main()


Measured memory_bytes: 261868
# coding: utf-8
# Your code here!
N=int(input())
L = [int(i) for i in input().split()]
ANS=1
flag=0
for i in range(N):
    if L[i]==0:
        print(0)
        flag=1
        break
if flag==0:
    for i in range(N):
        ANS=ANS*L[i]
        if ANS>=1000000000000000001:
            print(-1)
            break
        if i==N-1:
            print(ANS)

Measured memory_bytes: 21572
n  = int(input())
zoro_num = 0
ans = "No"
for i in range(n):
    a, b = input().split()
    if(a == b):
        zoro_num += 1
    else:
        zoro_num = 0
    
    if(zoro_num >= 3):
        ans = "Yes"

print(ans)

Measured memory_bytes: 9168
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
#define intt long long

int main(){
	intt N, A, B; std::cin >> N >> A >> B;
	if (A > B)
		std::cout << 0 << std::endl;
	else {
		if (N == 1) {
			if (A == B)
				std::cout << 1 << std::endl;
			else
				std::cout << 0 << std::endl;
		}
		else
			std::cout << (B - A) * (N - 2) + 1 << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>

using namespace std;

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

const ll mod = 1000000007;
ll fact[200200];
ll invfact[200200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a-b);
}


inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll pow(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return pow(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}

ll N;
ll s[101000];

int main(){
    cin >> N;
    make_fact(N);
    s[0] = 0LL;
    s[1] = 1LL;
    for(ll i = 2; i <= N; i++){
        s[i] = add(s[i-1], mod_inv(i));
    }
    ll res = 0LL;
    for(ll i = 1; i <= N; i++){
        int a;  cin >> a;
        res = add(res, mul(a, add(add(s[i], s[N-i+1]), -1)));
    }
    cout << mul(res, fact[N]) << endl;

    return 0;

}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
char s[110];
int ans=1e9,len;
void check(char pos){
    int res=0,tmp=0;
    for(int i=0;i<len;++i){
        if(s[i]==pos){
            res=max(res,tmp);
            tmp=0;
        }
        else tmp++;
    }
    res=max(res,tmp);
    ans=min(res,ans);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>s;
    len=strlen(s);
    for(int i=0;i<26;++i){
        check(i+'a');
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define ll long long
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int>>
const   double eps = 1e-9;
const long double pi = acos(-1.0);
using namespace std;

struct pt{
    double x, y, r;
};

double dist(pt a, pt b){
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
const int N = 1e3 + 4;
const double INF = 1e12;
vector <pair <double, int> > g[N];
pt a[N];

int n;
pt s, t;
void init(){
    cin >> s.x >> s.y;
    cin >> t.x >> t.y;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i].x >> a[i].y >> a[i].r;
    
    for (int i = 0; i < n; i++){
            double d = dist(s, a[i]) - a[i].r;
            if (d < eps) d = 0.0;
            g[n].pb({d, i});
            g[i].pb({d, n});
            d = dist(t, a[i]) - a[i].r;
            if (d < eps) d = 0.0;
            g[n + 1].pb({d, i});
            g[i].pb({d, n + 1});
    }
    g[n].pb({dist(t, s),  n + 1});
    g[n + 1].pb({dist(t, s), n});
    
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            if (i == j) continue;
            double d = dist(a[i], a[j]) - a[i].r - a[j].r;
            if (d < eps) d = 0.0;
            g[i].pb({d, j});
         }
    }
}
double dj(){
    vector <double> d(n + 3, INF);
    d[n + 1] = 0.0;
    vector <bool> used(n + 3, false);
    for (int i = 0; i <= n + 1; i++){
        int v = -1;
        for (int j = 0; j <= n + 1; j++) 
            if (!used[j] && (v == -1 || d[j] < d[v])) v = j;
         
        //cout << v << " " << d[v] << endl;
        if ( abs(d[v] - INF) < eps) break;
        used[v] = true;
        for (int j = 0; j < g[v].size(); j++){
            int to = g[v][j].sc;
            double len = g[v][j].fr;
            if (d[v] + len < d[to] - eps){
                d[to] = d[v] + len;
            }
        }
    }
    return d[n];

}
void solve(){
    init();
    double ans = dj();
    cout << ans << endl;
}       
int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(10);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int step;
    step = 1;
    //cin >> step;
    for (int i = 1; i <= step; i++){
         solve();
    }
}

Measured memory_bytes: 19736
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define MOD 1000000007
typedef long long ll;

int main(){
	ll h, n, sum = 0, i = 0;
	scanf("%lld%lld", &h, &n);
	ll a[n];
	rep(i, n){
		scanf("%lld", &a[i]);
		sum += a[i];
		if(sum >= h){
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}


Measured memory_bytes: 896
def solve():

    N = int(input())

    # 一行で取る
    Plist = [int(input()) for i in range(N)]

    # max indexをとるには
    m = max(Plist)
    Plist.remove(Plist[Plist.index(m)])
    print(m//2+sum(Plist))


if __name__ == "__main__":
    solve()


Measured memory_bytes: 38408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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() {
  ll n,k;
  scanf("%lld%lld", &n,&k);
  ll ans = 0;

  FOR(i,1,n){
    ll a = n/i;
    ll b = n%i;

    if(k!=0){

    ans += max(i-k,(ll)0) * a;
    ans += max(b-k+1,(ll)0);

    }

    else{
      ans = n*n;
    }

    // cout << ans << endl;
  }

  cout << ans << endl;

}



Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  string S;
  cin >> S;

  map<char,int> memo;
  rep(i,S.size()){
    memo[S[i]]++;
  }

  int n = memo['N'];
  int s = memo['S'];
  int e = memo['E'];
  int w = memo['W'];

  bool flg1 = false;
  bool flg2 = false;

  if(n == 0 && s == 0) flg1 = true;
  if(n > 0 && s > 0) flg1 = true;

  if(e == 0 && w == 0) flg2 = true;
  if(e > 0 && w > 0) flg2 = true;

  if(flg1 && flg2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
	unsigned char usW_D_str[1200];
	unsigned short usW_C_i;
	
	for(usW_C_i = 0;usW_C_i < 1200;usW_C_i++){
		usW_D_str[usW_C_i] = '\0';
	}
	
	for(usW_C_i = 0;usW_C_i < 1200;usW_C_i++){
		scanf("%c", &usW_D_str[usW_C_i]);
		if(usW_D_str[usW_C_i] == '\0'){
			break;
		}
	}
	
	for(usW_C_i = 0;usW_C_i < 1200;usW_C_i++){
		if(usW_D_str[usW_C_i] >= 'A' && usW_D_str[usW_C_i] <= 'Z'){
			usW_D_str[usW_C_i] += 32;
		}
		else if(usW_D_str[usW_C_i] >= 'a' && usW_D_str[usW_C_i] <= 'z'){
			usW_D_str[usW_C_i] -= 32;
		}
		else;
	}
	
	for(usW_C_i = 0;usW_D_str[usW_C_i] != '\0';usW_C_i++){
		printf("%c", usW_D_str[usW_C_i]);
	}
	
	return 0;
}


Measured memory_bytes: 2100
#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
//#include <string>
//#include <time.h>
//#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
#define WAIT system ("pause")
#define rt0 return 0
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<(min(a,b))+(min(c,d));
    WAIT;
    rt0;
}

Measured memory_bytes: 504
N, M = map(int, input().split())
a = []
b = []
c = []

import sys
sys.setrecursionlimit(2000)

for i in range(M):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
    ci = list(map(int, input().split()))
    c.append(ci)

c_bin = [0] * M
for j in range(M):
    for k in range(b[j]):
        c_bin[j] |= (1 << (c[j][k] - 1))

ceil = 1 << N
memo = [None] * (ceil * (M + 1))
# print("#", '[' +' '.join(map(lambda x: '0b{:b}'.format(x), c_bin)) + ']', ceil)
def dp(pos, state):
    global M, ceil
    idx = pos * ceil + state
    # print("##", pos, '0b{:b}'.format(state), idx)
    if state == ceil - 1:
        ret = 0
    elif pos == M:
        ret = -1
    elif memo[idx] != None:
        return memo[idx]
    else:
        ret0 = dp(pos + 1, (state | c_bin[pos]))
        ret1 = dp(pos + 1, state)
        if ret0 == ret1 == -1:
            ret = -1
        elif ret1 == -1:
            ret = a[pos] + ret0
        else:
            ret = min(a[pos] + ret0, ret1)
    #
    memo[idx] = ret
    return ret

print(dp(0, 0))


Measured memory_bytes: 154456
use std::io;

fn main()
{
    let mut line = String::new();
    io::stdin().read_line(&mut line).ok();
    let vec: Vec<&str> = line.split_whitespace().collect();
    let n: i32 = vec[0].parse().unwrap_or(0);

    let mut l = String::new();
    io::stdin().read_line(&mut l).ok();
    let v: Vec<&str> = l.split_whitespace().collect();
    let m: i32 = v[0].parse().unwrap_or(0);
    
    println!("{}", n*n - m);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
using namespace std;
set<char>s;
int main()
{
    char c;
    for(int i=1;i<=4;i++)
        scanf("%c",&c),s.insert(c);
    if(s.size()==2){
        printf("Yes\n");
    }
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 256
import sys,collections as cl,bisect as bs,copy
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

c = l()

n = onem()

cc = []

for i in range(4):
    cc.append([c[i],i])

cc[-1][0] /= 2

cc[0][0] *= 4
cc[1][0] *= 2



cc.sort()

su = 0

i = 0
while n:
    kkk = cc[i][1]
    if kkk == 0:
        su += 4 * c[kkk] * n
        n = 0
    elif kkk == 1:
        su += 2 * c[kkk] * n 
        n = 0
    elif kkk == 2:
        su += c[kkk]*n
        n = 0
    else:
        su += c[kkk] * (n//2)
        n %= 2
    i += 1
print(su)









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

using namespace std;

const int N = 200200;

vector<int> g[N];
int d[N];
int rt = 1;
bool f[N];

void dfs(int u,int p) {
   if (d[u] > d[rt]) rt = u;
   for (int v : g[u]) if (v != p) {
      d[v] = d[u] + 1;
      dfs(v, u);
   }
}

int get() {
   dfs(1, -1);
   d[rt] = 0;;
   dfs(rt, -1);
   return d[rt];
}

int main() {
   int n; scanf("%d", &n);
   f[0] = true;
   for (int i = 1; i <= n; ++i) {
      if (i > 0 && !f[i - 1]) f[i] = true;
      if (i > 1 && !f[i - 2]) f[i] = true;
   }
   for (int i = 2; i <= n; ++i) {
      int u, v; scanf("%d %d", &u, &v);
      g[u].push_back(v), g[v].push_back(u);
   }
   puts(f[get()] ? "First" : "Second");
}


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

int main() {
    int n, k ,q;
    cin >> n >> k >> q;
    vector<int> a(q);
    vector<int> point(n);
    for(int i=0; i<n; i++){
        point.at(i) = 0;
    }
    for(int i=0; i<q; i++){
        cin >> a.at(i);
        point.at(a.at(i)-1) += 1;
    }
    for(int i=0; i<n; i++){
        point.at(i) = point.at(i)-q+k;
        if(point.at(i) <= 0){
            cout << "No" << endl;
        }
        else{
            cout << "Yes" << endl;
        }
    }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define pii pair<ll,ll>
#define x1 dlfjl
#define x2 dkfj
#define x3 dflgkg
#define MOD 1000000007
#define y1 dskgj
#define y2 dskfj
#define y3 dfhgdh
#define SQ 320
#define PI 3.14159265359
typedef int ll;
using namespace std;
ll n,i,j,k,x,y,z,m,q,h,r,timer,mx,l,sum, ans;
ll a[100500],  w[100500];
ll dp[100500];
ll used[100500];

set<ll> g[100500];
set<pair<ll,ll> > f;
string s;
void dfs(ll v, ll p = -1) {
    for (auto itr = g[v].begin(); itr != g[v].end(); itr++) {
        ll to = *itr;
        if (to != p)
            dfs(to, v);
    }
    ll max1 = 0, max2 = 0;
    for (auto itr = g[v].begin(); itr != g[v].end(); itr++) {
        ll to = *itr;
        if (to == p)
            continue;
        if (dp[to] > max1) {
            max2 = max1;
            max1 = dp[to];
        } else if (dp[to] > max2) {
            max2 = dp[to];
        }
    }
    ans = max(ans, max1 + max2 + (s[v]=='W'));
    dp[v] = max1 + (s[v] == 'W');
}
int main() {
    //freopen("input.txt","r",stdin);
    cin >> n;
    for (int i = 0; i < n-1; i++) {
        cin >> x >> y;
        x--;y--;
        g[x].insert(y);
        g[y].insert(x);
        w[x]++;
        w[y]++;
    }
    cin >> s;
    for (int i = 0; i < n; i++)
    if (s[i] == 'B') {
        f.insert(mp(w[i], i));
    }
    while (!f.empty()) {
        auto itr = f.begin();
        if ((*itr).X > 1)
            break;
        ll v = (*itr).Y;
        ll to = (*(g[v].begin()));
        g[v].erase(to);
        g[to].erase(v);
        f.erase(mp(w[v], v));
        if (s[to] == 'B')
            f.erase(mp(w[to],to));
        w[v]--;
        w[to]--;
        if (w[v] > 0) {
            f.insert(mp(w[v], v));
        }
        if (w[to] > 0 && s[to] == 'B') {
            f.insert(mp(w[to], to));
        }
        used[v] = 1;
    }
    ll st = -1;
    for (int i = 0; i < n; i++)
        if (!used[i])
            st = i;
    if (st == -1) {
        cout << 0 << endl;
        return 0;
    }
    ans = 0;
    ll tot = 0;
    ll cnt = 0;
    for (int i = 0; i < n; i++) {
        if (!used[i]) {
            cnt++;
            tot += w[i];
            if (w[i] % 2 == 1) {
                if (s[i] == 'W')
                    s[i] = 'B';
                else
                    s[i] = 'W';
            }
            if (s[i] == 'W')
                tot++;
        }
    }
    if (cnt == 1 && s[st] == 'W') {
        cout << 1 << endl;
        return 0;
    }
    //cout << tot << endl;
    dfs(st);
    /*for (int i = 0; i < n; i++) {
        if (!used[i]) {
            if (s[i] == 'W') {
                if (ans > 0) {
                    ans--;
                    tot++;
                } else {
                    tot += 3;
                }
            } else {
                tot += 2;
            }

        }
    }*/
    //cout << ans << endl;
    cout << tot-ans*2 << endl;
    return 0;
}


Measured memory_bytes: 24320
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	ll sum = 0;
	rep(i, 1, N + 1) {
		if (i % 3 != 0 && i % 5 != 0)sum += i;
	}
	cout << sum << "\n";

	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    long long X; cin >> X;

    long long a = X / 500;
    long long b = (X - (500 * a)) / 5;

    cout << (1000 * a) + (5 * b) << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

	ios::sync_with_stdio(false);


	int routes, time_min, cost_min = 1001, cost, time, best_route = 0;

	cin >> routes >> time_min;

	for(int i=0; i<routes; i++){
		cin >> cost >> time;
		if(time_min >= time and cost <= cost_min){
			best_route = cost;
			cost_min = cost;
		}
	}


	//cout << (best_route != 0 ? best_route : "TLE") << endl;
	if(best_route == 0){
		cout << "TLE" << endl;
	}
	else{
		cout << best_route << endl;
	}

	return 0;
}

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

 int main(){

  int r, D;

  vector<int> x(2050);

  cin >> r >> D >> x.at(2000);

  
  for (int i = 0; i < 10; i++) {
   x.at(2000+i+1) =  r * x.at(2000+i) - D;
   }

  for (int i = 0; i < 10; i++) {
   cout << x.at(2000+i+1) << endl;
   }

 return 0;
}


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

using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;

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

  int n, k, q;
  cin >> n >> k >> q;

  int scores[n+1];
  for(int i = 1; i <= n; i++) scores[i] = k-q;

  while(q--) {
    int sc;
    cin >> sc;
    ++scores[sc];
  }

  for(int i = 1; i <= n; i++) {
    cout << ((scores[i] > 0) ? "Yes\n" : "No\n");
  }
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

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

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const int MAX_N = 2e5+10;

int dp1[MAX_N] = {};
int dp2[MAX_N] = {};

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int N,K,C; cin >> N >> K >> C;
    string S; cin >> S;
    
    int cost = 0;    
    REP(i,N){
        if(S[i] == 'o' && cost == 0){
            dp1[i+1] = dp1[i] + 1;
            cost = C;
        }else{
            if(cost > 0) cost--;
            dp1[i+1] = dp1[i];
        }
    }
    cost = 0;
    for(int i = N-1; i >= 0; i--){
        if(S[i] == 'o' && cost == 0){
            dp2[i] = dp2[i+1] + 1;
            cost = C;
        }else{
            if(cost > 0) cost--;
            dp2[i] = dp2[i+1];
        }
    }
    VI ans;
    REP(i,N){
        if(S[i] != 'o') continue;
        dump(i)
        dump(dp1[i])
        dump(dp2[i+C])

        int can = dp1[i] + dp2[i+1];
        if(can < K){
            ans.eb(i+1);
        }
    }
    for(auto i : ans){
        cout << i << endl;
    }

}


Measured memory_bytes: 4236
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn = 5e5 + 10;
const int block = 600;

int main () {
	ios_base::sync_with_stdio (false);
	string s;
	cin >> s;
	int n = s.size();
	int cnt = 0, ans = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'T') {
			if (cnt > 0) {
				cnt --;
				ans --;
			}
			else {
				ans ++;
			}
		}
		else {
			cnt ++;
			ans ++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL A[9]; rep(i, 9) cin >> A[i];
		bool C[9] = {};
		UL N; cin >> N;
		rep(i, N) {
			UL b; cin >> b;
			rep(j, 9) if (b == A[j]) C[j] = true;
		}
		bool ok = false;
		rep(i, 3) {
			if (C[i] && C[i + 3] && C[i + 6]) ok = true;
			if (C[i * 3] && C[i * 3 + 1] && C[i * 3 + 2]) ok = true;
		}
		if (C[0] && C[4] && C[8]) ok = true;
		if (C[2] && C[4] && C[6]) ok = true;
		cout << (ok ? "Yes" : "No") << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 256
def d_remainder_reminder(N, K):
    ans = 0
    for b in range(K + 1, N + 1):
        # N=pb+r(0<=r<b) と表すと、aを"0"からNまで変化させたときに
        # a%bを順に並べた列は、[0,1,2,...,b-1]*p + [0,1,2,...,r] となる
        p = N // b
        r = N % b
        # 条件を満たすaの個数は、p*max(0,b-K) + max(0,r+1-K) 個
        ans += p * max(0, b - K) + max(0, r + 1 - K)
    if K == 0:
        # K=0のとき、1回のループで1だけ解が大きくなる(a=0の分を足してしまうため)
        # その分を差し引く
        ans -= N
    return ans

N,K = [int(i) for i in input().split()]
print(d_remainder_reminder(N, K))

Measured memory_bytes: 3060