akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main()
{
    int s;
    cin >> s;
    int a = s/100;
    int b = s%100;
    // cout << a << " " << b << endl;
    if(a == 0 || a > 12) a = -1;
    if(b == 0 || b > 12) b = -1;
    if(a == -1 && b == -1){
        cout << "NA" << endl;
    }else if(a == -1){
        cout << "YYMM" << endl;
    }else if(b == -1){
        cout << "MMYY" << endl;
    }else{
        cout << "AMBIGUOUS" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
def listrep(n,m,s):
    tab = [[0]*(s+1) for j in range(n+1)]
    tab[0][0] = 1
    for i in range(1,n+1):
        for k in range(s+1):
            if i <= k:
                tab[i][k] += tab[i][k-i] + tab[i-1][k-i]
            if k-1 >= m:
                tab[i][k] -= tab[i-1][k-1-m]
            tab[i][k] %= 100000
    return tab[n][s]

while True:
    n,m,s = map(int,input().split())
    if n == 0 : break
    n *= n
    print(listrep(n,m,s))

Measured memory_bytes: 12696
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 2; i++) {
            if (Integer.parseInt(sc.next()) == 2) {
                System.out.println("No");
                System.exit(0);
            }
        }
        System.out.println("Yes");

    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int main(){
	int a,b;
	cin>>a>>b;
	if(a<=8 && b<=8) puts("Yay!");
	else puts(":(");
}


Measured memory_bytes: 256
use std::io::Read;
fn main() {
    let mut buf = String::new();

    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();

    // 読み込んだStringを空白で分解する
    let mut iter = buf.split_whitespace();

    let a: u64 = iter.next().unwrap().parse().unwrap();
    let b: u64 = iter.next().unwrap().parse().unwrap();
    let c: u64 = iter.next().unwrap().parse().unwrap();

    let x: u64 = iter.next().unwrap().parse().unwrap();
    let y: u64 = iter.next().unwrap().parse().unwrap();

    let mut sum = a * x + b * y;

    let mut xa = x;
    let mut ya = y;
    let mut za = 0;

    loop {
        if xa != 0 {
            xa -= 1
        };
        if ya != 0 {
            ya -= 1
        };

        za += 2;

        let next = xa * a + ya * b + za * c;

        if sum <= next {
            break;
        } else {
            sum = next;
        }
    }

    println!("{}", sum);
}


Measured memory_bytes: 4352
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define SREP(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;
int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}

int main() {
	int n;
	int a[100002];
	scanf("%d", &n);
	a[0] = 0;
	REPS(i, n)scanf("%d", &a[i]);
	a[n+1] = 0;
	int d = 0;
	REPS(i, n+1) {
		d += abs(a[i] - a[i - 1]);
	}
	int ans;
	REPS(i,n){
		ans = d;
		ans = ans - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i - 1] - a[i + 1]);
		PRINTD(ans);
	}
}

Measured memory_bytes: 1536
import random


def judge_miller(n, rep):
    if(n == 1):
        return False
    if(n == 2):
        return True
    if(n % 2 == 0):
        return False
    d = n - 1
    while(d & 1 == 0):
        d >>= 1
    for k in range(rep):
        cp_d = d
        a = random.randint(2, n - 1)
        may_prime = False
        x = pow(a, d, n)
        if(x == 1):
            may_prime = True
        while((not may_prime) and x != n - 1 and d != n - 1):
            if(x == n - 1):
                may_prime = True
            d <<= 1
            x = (x * x) % n
        if(x == n - 1):
            may_prime = True
        if(not may_prime):
            return False
        d = cp_d
    return True


n = int(input())
cnt = 0
for i in range(n):
    x = int(input())
    res = judge_miller(x, 15)
    if(res):
        cnt += 1
print(cnt)



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

int main()
{
  int n, s[101], cop[101], rank[10101];

  cin >> n;
  for (int i = 0; i < n * (n - 1) / 2; i++){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (c == d){
      s[a-1]++; s[b-1]++;
    } else {
      (c>d?s[a-1]:s[b-1]) += 3;
    }
  }

  for (int i = 0; i < n; i++) cop[i] = s[i];
  sort(cop, cop + n);
  reverse(cop, cop + n);
  for (int i = n - 1; i >= 0; i--){
    rank[cop[i]] = i + 1;
  }

  for (int i = 0; i < n; i++){
    cout << rank[s[i]] << endl;
  }
}

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

int main(){
  string s;
  vector<string> j = {"KIHBR","AKIHBR","KIHABR","KIHBAR","KIHBRA",
                      "AKIHABR","AKIHBARA","AKIHBRA",
                      "KIHABAR","KIHABRA","KIHBARA",
                      "AKIHABAR","AKIHABRA","AKIHBARA",
                      "KIHABARA","AKIHABARA"};
  cin >> s;
  if( count(j.begin(),j.end(),s) == 0 ){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	int p = scan.nextInt();
      	int q = scan.nextInt();
      	int r = scan.nextInt();
      	int ab = p + q;
      	int bc = q + r;
      	int ca = r + p;
      	if(p + q <= q + r){
        	if(p + q <= r + p) {
            	System.out.print(p + q);
            }
          	else {
            	System.out.print(r + p);
            }
        }
      	else if(q + r < p + q){
        	if(q + r <= r + p){
            	System.out.print(q + r);
            }
          	else {
            	System.out.print(r + p);
            }
        }
    
    }
 
 
}

Measured memory_bytes: 23252
#include <iostream>

using namespace std;

int main(){

	int H = 0;
	int W = 0;

	cin >> H >> W;

	while (H != 0 && W != 0) {

		for (int i = 0; i < H; i++) {

			for (int u = 0; u < W; u++) {

				if ((i + u) % 2 == 0) {

					cout << "#";

				}
				else {

					cout << ".";

				}

			}

			cout << endl;

		}

		cout << endl;

		cin >> H >> W;

	}

	return 0;

}



Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        int n = Integer.parseInt(sc.next());
        int m = Math.max(h, w);
        if (n % m == 0) {
            System.out.println(n / m);
        } else {
            System.out.println((n / m) + 1);
        }
    }
}


Measured memory_bytes: 21844
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String[] A = {"dream", "dreamer", "erase", "eraser"};

        StringBuffer sb;
        S = new StringBuffer(S).reverse().toString();

        for (int i = 0; i < A.length; i++) {
            sb = new StringBuffer(A[i]);
            A[i] = sb.reverse().toString();
        }

        int index = 0;
        while (index < S.length()) {
            boolean f = false;
            for (int i = 0; i < 4; i++) {
                if (S.substring(index, Math.min(index + A[i].length(), S.length())).equals(A[i])) {
                    f = true;
                    index += A[i].length();
                    break;
                }
            }
            if (!f) {
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }
}


Measured memory_bytes: 28056
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    int ans = 0;
    while(1){
        int sum = 0;
        rep(i, n){
            sum += a[i] / n;
        }

        rep(i, n){
            int old = a[i];
            a[i] -= (old / n * n);
            a[i] += sum - (old / n);
        }

        if(sum == 0){
            break;
        }
        ans += sum;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

int digitsSum(int x){
    int ans=0;
    while(1){
        ans+=x%10;
        x/=10;
        if(x<1){
            break;
        }
    }
    return ans;
}

int main(){

    int L,N;
    string S[110]={};
    cin>>N>>L;
    for(int i=0;i<N;i++){
        cin >> S[i];
    }

    sort(S,S+N);

    string ans = "";
    for(int i=0;i<N;i++){
        ans+=S[i];
    }

    cout << ans<<endl;


    return 0;
}


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

int N;
char S[MAX_N + 1];
ll memo1[MAX_N + 1], memo2[MAX_N + 1], memo3[MAX_N + 1];
ll memo4[MAX_N + 1], memo5[MAX_N + 1];

int main(){
	scanf("%d", &N);
	scanf("%s", S);
	
	for(int i = 0; i < N; i++){
		if(S[i] == 'J') memo1[i + 1]++;
		if(S[i] == 'O') memo2[i + 1]++;
		if(S[i] == 'I') memo3[i + 1]++;
	}
	for(int i = 1; i < N + 1; i++){
		memo1[i] += memo1[i - 1];
		memo2[i] += memo2[i - 1];
		memo3[i] += memo3[i - 1];
	}
	ll res = 0LL;
	for(int i = 1; i < N; i++){
		if(S[i] == 'O') res += memo1[i] * (memo3[N] - memo3[i]);
	}
	for(int i = 0; i < N + 1; i++){
		if(S[i] == 'O'){
			memo4[i] += memo1[i];
			memo5[i] += memo3[N] - memo3[i];
		}
	}
	for(int i = 1; i < N + 1; i++) memo4[i] += memo4[i - 1];
	for(int i = N - 1; i >= 0; i--) memo5[i] += memo5[i + 1];
	ll res2 = 0LL;
	for(int i = 0; i < N + 1; i++){
		res2 = max(res2, memo4[i]);
		res2 = max(res2, memo5[i]);
		res2 = max(res2, memo1[i] * (memo3[N] - memo3[i]));
	}
	res += res2;
	printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 6748
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int main(void){
    string l;
    cin >> l;
    
    ll tr[100010], v = 1;
    for (int i = 0; i <= 100000; i++) {
        tr[i] = v;
        v *= 3;
        v %= 1000000007;
    }
    
    ll ans1 = 1, ans2 = 0, ans1_pr;
    for (int i = 0; i < l.size(); i++) {
        if (char(l[i]) == '1') {
            ans1_pr = ans1;
            ans1 *= 2;
            ans2 += ans1_pr * tr[int(l.size()) - 1 - i];
        }
        ans1 %= 1000000007;
        ans1_pr %= 1000000007;
        ans2 %= 1000000007;
    }
    
    //cout << ans1 << " " << ans2 << endl;
    
    cout << (ans1 + ans2) % 1000000007 << endl;
}


Measured memory_bytes: 1280
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

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())

r,d,x = li()

for _ in range(10):
    x = r * x - d
    print(x)

Measured memory_bytes: 3064
//
// Created by 徳備彩人 on 2020/06/01.
//

#include <bits/stdc++.h>
using namespace std;

int main() {
    int N, W;
    cin >> N >> W;
    vector<vector<int>> dp(N+1, vector<int>(W+1, 0));
    vector<int> v;
    vector<int> w;
    for (int i=0;i<N;i++) {
        int a, b;
        cin >> a >> b;
        v.push_back(a);
        w.push_back(b);
    }
    for (int i=0;i<N;i++) {
        for (int j=1;j<=W;j++) {
            if (j >= w[i]) {
                dp[i + 1][j] = max({dp[i][j], dp[i][j-w[i]] + v[i], dp[i+1][j-w[i]] + v[i]});
            } else {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }
    cout << dp[N][W] << endl;
}


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

using namespace std;

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

long lcm(long a, long b) {
  return a * b / gcd(a, b);
}

int main() {
  int A, B;
  cin >> A >> B;

  long result = lcm(A, B);

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
import sys

for s0 in sys.stdin:
  s=s0[:-1]
  a,b=s.split("+")
  b,c=b.split("=")
  f=any([e!=e[0]=="X" for e in [a,b,c]])

  m="NA"
  s=a+"+"+b+"=="+c
  for e in "0123456789"[f:]:
    try:
      if eval(s.replace("X",e)): m=e; break
    except: pass
  print m

Measured memory_bytes: 4256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
using namespace std;
using ll =long long;
const int MOD = 1000000007;

//////検証する数,超えられない数////
long long cine(long long a, long long b) {
	if (a <= b) {
		return a;
	}
	else {
		return b;
	}
};
//vector型の初期化
void vec_initialize(vector<ll>& a, const ll N) {
	ll c;

	for (int i = 0; i < N; i++) {

		cin >> c;
		a.push_back(c);

	}

};

int main() {
	ll N;
	cin >> N;
	vector <ll> a;
	map<ll, ll>A;
	ll big=0;
	vec_initialize(a, N);
	for (int i=0;i<N;i++) {
		A[a[i]]++;
		A[a[i] - 1]++;
		A[a[i] + 1]++;
	}
	for (auto i : A) {

		big = max(i.second, big);

	}

	cout << big;
}

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

int main()
{
	long long N;
	scanf("%lld", &N);
	long long count{};
	for (long long q{1}; q * (q + 2) <= N; q++)
	{
		if (N % q) continue;
		if (N / q - 1 <= q) break;
		count += N / q - 1;
	}
	printf("%lld\n", count);

	return 0;
}

Measured memory_bytes: 256
#include<time.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h> 
int main()
{
	int n,x,a[99999],t=0,i,j,k,h;
	scanf("%d %d",&n,&x);
	while(n!=0 || x!=0)
	{
		h=0;
		t++;
		
		for(i=1;i<=n;i++)
			for(j=i+1;j<=n;j++)
				for(k=j+1;k<=n;k++)
					if(i+j+k==x)
						h++;
		a[t]=h;
		scanf("%d %d",&n,&x);
	}
	for(i=1;i<=t;i++)
		printf("%d\n",a[i]);
	return 0;
}


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

int calcPpland(int x, int y, string str) {
  if (str == "+") return x + y;
  if (str == "-") return x - y;
  if (str == "*") return x * y;
  cout << "error: operator is not correct." << endl;
  return 0;
}

bool isOperator(string str) {
  if (str == "+" || str == "-" || str == "*") {
    return true;
  }
  return false;
}

int main() {
  string str;
  stack<int> st;
  while (cin >> str) {
    if (isOperator(str)) {
      int b = st.top();
      st.pop();
      int a = st.top();
      st.top() = calcPpland(a, b, str);
    } else {
      st.push(atoi(str.c_str()));
    }
    if (getchar() == '\n') {
      cout << st.top() << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3196
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

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

int main(){
  int n, h;
  cin >> n >> h;
  vector<int> a(n), b(n);
  REP(i, n) cin >> a[i] >> b[i];
  
  sort(a.begin(), a.end(), greater<int>());
  sort(b.begin(), b.end(), greater<int>());
  
  long long ans = 0;
  REP(i, n){
    if(a[0] > b[i]) break;
  	if(h <= 0){
      cout << ans << endl;
      return 0;
    }
    
    h -= b[i];
    ans++;
  }
  
  cout << ans + (long long)ceil((double)h / a[0]) << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int N;
  cin >> N;
  if(N <= 999){
    cout << "ABC" << endl;
  }else{
    cout << "ABD"  << endl;
  }

}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
XY = []
for _ in range(N):
    x, y = mapint()
    XY.append((x, y))

from collections import defaultdict, Counter
dic = []
for i in range(N):
    x1, y1 = XY[i]
    for j in range(N):
        if i==j:
            continue
        x2, y2 = XY[j]
        dx, dy = x2-x1, y2-y1
        if dx==0 and dy==0:
            continue
        dic.append((dx, dy))
c = Counter(dic)
if len(c)==0:
    print(N)
else:
    (x, y), cnt = c.most_common()[0]
    print(N-cnt)

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

int main() {
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int mins2 = h2 * 60 + m2;
	int mins1 = h1 * 60 + m1;
	cout << (mins2 - mins1) - k << "\n";
	return 0;
}

Measured memory_bytes: 3632
#include  <iostream>

using namespace std;

int main()
{
	int x, y1, y2, y3, joi;
	int resx, resy;
	
	cin >> x;
	cin >> y1;
	cin >> y2;
	cin >> y3;
	cin >> joi;
	
	resx = x * joi;
	resy = y1 + (joi > y2 ? joi - y2 : 0) * y3;
	
	cout << (resx < resy ? resx : resy) << endl;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 
//なんかむずいんだけどw
// fuck
signed main(){
	int n,k; cin>>n>>k;
	string s;
	cin>>s;
	if(s[k-1]=='A') s[k-1]='a';
	else if(s[k-1]=='B') s[k-1]='b';
	else s[k-1]='c';
	cout<<s;
	
	return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
vector<ll> G[200001];
bool used[200001]={};
void search(ll d[],ll x,ll sum){
  if(used[x])return;
  used[x]=true;
  d[x]+=sum;
  for(int i=0;i<G[x].size();i++){
    search(d,G[x][i],d[x]);
  }
}
int main(){
  ll n,q,a,b,p,x,mrank=0;
  cin >> n >> q;
  ll rank[n],rsum[n];
  ll d[n];
  bool en[n];
  ll vad[n];
  fill(vad,vad+n,0);
  fill(rank,rank+n,-1);
  fill(en,en+n,false);
  fill(rsum,rsum+n,0);
  fill(d,d+n,0);
  rank[0]=0;
  for(ll i=0;i<n-1;i++){
    cin >> a>>b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for(ll i=0;i<q;i++){
    cin >> p >> x;
    p--;
    d[p]+=x;
  }
  search(d,0,0);
  for(ll i=0;i<n;i++){
    cout << d[i]<<" ";
  }
  cout << endl;
}


Measured memory_bytes: 29312
s = input()
result = ''
for i in range(0, len(s)):
  if(s[i] == '0'):
  	result = result + '0'
  elif(s[i] == '1'):
    result = result + '1'
  elif(s[i] == 'B'):
    if(len(result) > 0):
    	result = result[ 0 : len(result)-1 ]
print(result)

Measured memory_bytes: 9032
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
    int n,k;
    cin>>n>>k;
    long long ans=1;
    vector<long long> a(n,0);
    priority_queue<long long> pos,neg;
    for(int i=0;i<n;i++){
        cin>>a[i];long long x=a[i];
        if(x>=0) pos.push(x);
        else neg.push(abs(x));
    }
    if(k==n){
        for(int i=0;i<n;i++){
            ans*=(MOD+a[i])%MOD;
            ans%=MOD;
        }
        cout<<ans<<"\n";
        return;
    }
    if(k%2==1 && pos.empty()){
        sort(rfull(a));
        for(int i=0;i<k;i++){
            ans*=(MOD+a[i])%MOD;
            ans%=MOD;
        }
    }
    else{
        if(k%2==1){
            ans*=pos.top();pos.pop();k--;
            ans%=MOD;
        }
        while(k>0){
            if(pos.size()>=2 && neg.size()>=2){
                long long p1=pos.top(),n1=neg.top();  pos.pop();neg.pop();
                long long p2=pos.top(),n2=neg.top();  pos.pop();neg.pop();
                if(p1*p2>=n1*n2){
                    ans*=((p1*p2)%MOD); ans%=MOD; k-=2;
                    neg.push(n2);
                    neg.push(n1);
                }
                else{
                    ans*=((n1*n2)%MOD);ans%=MOD; k-=2;
                    pos.push(p1);
                    pos.push(p2);
                }
            }
            else{
                if(neg.size()<2){
                    while(k>0){
                        k--;
                        ans*=pos.top();
                        ans%=MOD;
                        pos.pop();
                    }
                }
                else{
                    while(k>0){
                        k--;
                        ans*=neg.top();
                        ans%=MOD;
                        neg.pop();
                    }
                }
            }
        }
    }
    cout<<ans<<"\n";
}

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

    solve();
    return 0;
}

Measured memory_bytes: 6988
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>
#include <string.h>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long

using namespace::std;

int jo(ll int jxo, ll int jyo){
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){
  return (toxbig-0x20);
}
char tolow(char toxlow){
  return (toxlow+0x20);
}
  


int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if((a<=c)&&(c<=a+b)) cout<<"YES";
  else cout<<"NO";


}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>

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



int main() {

    string s;
    cin >> s;
    bool ans=false;
    rep(i,3)
    {
        if(s[i]=='7')
            ans = true;
    }

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

    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
using ll = long long;

ll X, Y, A, B ,C;
ll P[110000];
ll Q[110000];
ll R[110000];


int main(void){

    cin >> X >> Y >> A >> B >> C;
    for (int i = 0; i < A;i++) cin >> P[i];
    for (int i = 0; i < B;i++) cin >> Q[i];
    for (int i = 0; i < C;i++) cin >> R[i];

    sort(P,P+A,greater<int>());
    sort(Q,Q+B,greater<int>());
    sort(R,R+C,greater<int>());

    ll ans = 0;
    ll S[X + Y];

    for (int i = 0; i < X;i++) {
        ans += P[i];
        S[i] = P[i];
    }
    for (int i = 0; i < Y;i++) {
        ans += Q[i];
        S[X + i] = Q[i];
    }
    sort(S,S+X+Y);

    ll limit = X + Y;
    if  (X + Y > C) limit = C;
    for (int i = 0; i < limit;i++){
        if (S[i] < R[i]) ans += R[i] - S[i];
        else break;
    }


    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 7360
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
VI a;
in sol(){
  in sm=0;
  in sf=0;
  forv(i,a){
    sf+=a[i];
    if(i%2==0){
      if(sf<0)
	continue;
      sm+=(sf+1);
      sf=-1;
    }
    else{
      if(sf>0)
	continue;
      sm+=(1-sf);
      sf=1;
    }
  }
  return sm;
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n;
  cin>>n;
  a.resize(n);
  forn(i,n)
    cin>>a[i];
  in r=sol();
  forn(i,n)
    a[i]=-a[i];
  r=min(r,sol());
  cout<<r<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
     
     
//#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define sd(x) scanf("%d",&x)
#define sld(x) scanf("%lld",&x)
#define pld(x) printf("%lld\n",x)
#define pd(x) printf("%d\n",x)

int main(){
    int N,M;
    scanf("%d %d",&N,&M);
    int L[M];
    int R[M];
    for(int i = 0; i < M; i++){
        scanf("%d %d",&L[i],&R[i]);
    }
    sort(L, L+M);
    sort(R, R+M);
    int temp = R[0]-L[M-1]+1;
    if(temp<0)
        temp = 0;
    pd(temp);
    return 0;
}

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

using namespace std;

const int max_n = 101111, inf = 1000111222;

int n, l[max_n], r[max_n];

long long solve() {
    int x = 0;
    long long res = 0;
    multiset<pair<int, int>> byl, byr;
    for (int i = 0; i < n; ++i) {
        byl.insert({l[i], r[i]});
        byr.insert({r[i], l[i]});
    }
    for (int i = 0; i < n; ++i) {
        pair<int, int> p;
        if (i % 2 == 0) {
            p = *byl.rbegin();
        } else {
            p = *byr.begin();
            swap(p.first, p.second);
        }
        //cout << x << " -> " << p.first << " " << p.second << endl;
        int to = x;
        if (x < p.first) {
            to = p.first;
        }
        if (x > p.second) {
            to = p.second;
        }
        res += abs(x - to);
        x = to;
        byl.erase(byl.find(p));
        swap(p.first, p.second);
        byr.erase(byr.find(p));
    }
    res += abs(x);
    return res;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d", &l[i], &r[i]);
    }
    long long ans = solve();
    for (int i = 0; i < n; ++i) {
        swap(l[i], r[i]);
        l[i] *= -1;
        r[i] *= -1;
    }
    ans = max(ans, solve());
    cout << ans;
    return 0;
}


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

#define IL inline 
IL int read() {
	char ch = getchar(); int u = 0, f = 1;
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { u = (u << 1) + (u << 3) + ch - 48; ch = getchar(); }
	return u * f; 
}

set<string>a;
int main() {
	int n = read();
	string s;
	cin >> s;
	a.insert(s);
	char last = s[s.size()-1];
	for (int i = 1; i < n; ++i) {
		cin >> s;
		if(s[0]!=last){cout<<"No";return 0;}
		if(a.count(s)){cout<<"No";return 0;}
		last=s[s.size()-1];
		a.insert(s);
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(c)       int(c.size())
#define FOR(i,a,b)  for (int i=a; i<(b); ++i)
#define DOWN(i,a,b) for (int i=(a)-1; i>=(b); --i)
using namespace std;
using i64 = long long;

const int MAXN=10010;

int n;
int a[MAXN];
int b[MAXN];


int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);

  cin>>n;
  FOR(i,0,n) cin>>a[i];
  FOR(i,0,n) cin>>b[i];

  i64 x=0,y=0;
  FOR(i,0,n) {
    int d=a[i]-b[i];
    if (d<0) { x+=-d/2; } else { y+=d; }
  }

  cout << (x>=y ? "Yes\n" : "No\n");

  return 0;
}


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

int main(){
    long long h;cin >> h;
    //cout << h << endl;
    long long count = 0;
    while(h != 1){
        count++;
        h /= 2;
        //cout << h << endl;
    }
    //cout << count << endl;
    long long ans = 0;
    for (long long i = 0; i <= count; i++)
    {
        ans += pow(2,i);
        //cout << i << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import math
n, p = list(map(int, input().split()))
li = []
box = []
m = 1
k = 1
q = p
 
while True:
    for i in range(2,int(math.sqrt(q)) + 1):
        if p % i == 0:
            p = p // i
            li.append(i)
            k = i
            break
        else:
            continue
    else:
        break
 
for i in range(2,k+1):
    if i in li:
        box.append(i)
 
if n > len(li):
    print(m)
elif n==1:
  print(q)
else:
    for j in box:
        if li.count(j) // n > 0:
            m *= j ** (li.count(j) // n)
    print(m)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    INCANT;
    int n, res = 0;
    string s;
    cin>>n>>s;
    rep(i, 1000) {
        string num;
        num.push_back('0' + i / 100);
        num.push_back('0' + i / 10 % 10);
        num.push_back('0' + i % 10);
        int itr = 0;
        rep(j, n) {
            if(itr < 3 && s[j] == num[itr]) {
                itr++;
            }
        }
        if(itr == 3) res++;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>

#define SENTINEL 1000000001

struct Card {
    char suit;
    int value;
};

void trace(Card a[], int size) {
    for (int i = 0; i < size; ++i) {
        printf("%c %d\n", a[i].suit, a[i].value);
    }
}

void Merge(Card A[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    Card L[n1+1], R[n2+1];
    for (int i = 0; i < n1; ++i) {
        L[i] = A[left + i];
    }
    for (int i = 0; i < n2; ++i) {
        R[i] = A[mid + i];
    }
    L[n1].value = SENTINEL;
    R[n2].value = SENTINEL;
    int m = 0;
    int n = 0;
    for (int i = left; i < right; ++i) {
        if (L[m].value <= R[n].value) {
            A[i] = L[m];
            ++m;
        }
        else {
            A[i] = R[n];
            ++n;
        }
    }
}

void MergeSort(Card A[], int left, int right) {
    if (left >= right - 1) return;
    int mid = (left + right) / 2;
    MergeSort(A, left, mid);
    MergeSort(A, mid, right);
    Merge(A, left, mid, right);
}

int Partition(Card A[], int p, int r) {
    int x = A[r].value;
    int j = p;
    for (int i = p; i < r; ++i) {
        if (A[i].value <= x) {
            std::swap(A[j], A[i]);
            ++j;
        }
    }
    std::swap(A[j], A[r]);
    return j;
}

void QuickSort(Card A[], int p, int r) {
    if (p >= r) return;
    int q = Partition(A, p, r);
    QuickSort(A, p, q-1);
    QuickSort(A, q+1, r);
}

bool IsStable (Card A[], Card B[], int N) {
    for (int i = 0; i < N; ++i) {
        if (A[i].suit != B[i].suit || A[i].value != B[i].value) {
            return false;
        }
    }
    return true;
}

int main() {
    int N;
    Card A[100000], B[100000];

    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        std::cin >> A[i].suit >> A[i].value;
        B[i] = A[i];
    }

    MergeSort(A, 0, N);
    QuickSort(B, 0, N - 1);
    IsStable(A, B, N) ? printf("Stable\n") : printf("Not stable\n");
    trace(B, N);
    return 0;
}

Measured memory_bytes: 5508
N = input()
a = input().split()
f = True
for i in a:
    numi = int(i)
    if numi%2 == 0:
        if(numi%3 != 0) and (numi%5 != 0):
            f = False
            break
        
if f:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>

using namespace std;

int main() {
    int n;
    cin>>n;
    vector<long> a;
    unordered_map<long,long> mp;
    long cnt=0;
    for(int i=0;i<n;i++){
        long ai;
        cin>>ai;
        cnt+=mp[i-ai];
        mp[i+ai]++;
    }
    cout<<cnt<<endl;


    return 0;
}

Measured memory_bytes: 18408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define puts(i) cout<<i<<endl
#define pi 3.14159265358979
using ll = long long;
using P = pair<int,int>;

ll divisor=1e9+7;
int main(){
	int n,m;
	cin>>n>>m;
	pair<ll,ll> drink[n];
	rep(i,n){
		ll a,b;
		cin>>a>>b;
		drink[i]={a,b};
	}
	sort(drink,drink+n);
	int sum=0;
	ll cost=0;
	rep(i,n){
		if(drink[i].second+sum>m){
			cost+=drink[i].first*(m-sum);
			break;
		}else{
			cost+=drink[i].first*drink[i].second;
		}
		sum+=drink[i].second;
	}
  puts(cost);
}

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

int main() {
  int N;
  cin >> N;
 
  vector<int>x(N);
  vector<int>y(N);
  for (int i = 0; i < N; i++){
    cin >> x.at(i) >> y.at(i);
  }
  
  if (N == 1 || N == 2){
    cout << 1 << endl;
    return 0;
  }
      
  vector<int>count(N*(N-1)/2);
  int M = 0;
  for (int i = 0; i < N-1; i++){
    for (int j = i+1; j < N; j++){
      int X = x.at(i) - x.at(j);
      int Y = y.at(i) - y.at(j);
      if (X == 0 && Y == 0){
        M++;
        break;
      }
      for (int k = 0; k < N-1; k++){
        for (int l = k+1; l < N; l++){
          if (x.at(k) - x.at(l) == X && y.at(k) - y.at(l) == Y){
            count.at(M)++;
          }
          else if (x.at(l) - x.at(k) == X && y.at(l) - y.at(k) == Y){
            count.at(M)++;
          }
        }
      }
      M++;
    }
  }
  sort(count.begin(), count.end());
  reverse(count.begin(), count.end());
  
  cout << max(1,N-count.at(0)) << endl;
}
  
    
  
    

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var N = vals[0];
        var M = vals[1];
        var edges = Enumerable.Range(0, N + 1).Select(_ => new List<int>()).ToArray();
        for (int i = 0; i < M; i++)
        {
            vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            edges[vals[0]].Add(vals[1]);
        }

        vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var start = vals[0];
        var goal = vals[1];

        var visited = new bool[N + 1];
        var currents = new HashSet<int> { start };
        visited[start] = true;
        int step = 0;
        while (currents.Count > 0)
        {
            step++;
            var nexts = new HashSet<int>();
            for (int i = 0; i < 3; i++)
            {
                foreach (var p in currents)
                {
                    nexts.UnionWith(edges[p]);
                }
                currents = nexts;
                nexts = new HashSet<int>();
            }
            foreach (var p in currents.ToArray())
            {
                if (p == goal)
                {
                    Console.WriteLine(step);
                    return;
                }

                if (visited[p])
                {
                    currents.Remove(p);
                }
                else
                {
                    visited[p] = true;
                }
            }
        }

        Console.WriteLine(-1);
    }
}

Measured memory_bytes: 35960
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
void swap(long long &a,long long &b)
{
    long long z;
    z=a;
    a=b;
    b=z;
}
int main()
{
    long long a,b,c,d;
    scanf("%lld %lld %lld",&a,&b,&c);
    scanf("%lld",&d);
    if(a<b)
        swap(a,b);
    if(a<c)
        swap(a,c);
    for(int i=1;i<=d;i++)
        a*=2;
    a+=(b+c);
    printf("%lld\n",a);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<int,int>p;
typedef pair<p,p>pa;

bool mem[2001][20001];

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

main()
{
  int n,y;
  cin >> n >> y;
  y/=1000;
  
  queue<pa>que;

  que.push(pa(p(0,0),p(0,0)));//F.F=10, F.S=5, S.F=1, S.S=maisu;
  mem[0][0]=true;
  
  pa ans;
  while(!que.empty()){
    ans=que.front();
    que.pop();
    int sum=(ans.F.F*10)+(ans.F.S*5)+(ans.S.F*1);
    int use=ans.S.S;
    
    if(use==n){
      if(sum==y){
        break;
      }
    }else{
      for(int i=0;i<3;i++){
        int key=(ans.F.F+dx[i])*10+(ans.F.S+dy[i])*5+(ans.S.F+dz[i])*1;
        if(mem[use+1][key]==false){
          mem[use+1][key]=true;
          que.push(pa(p(ans.F.F+dx[i],ans.F.S+dy[i]),p(ans.S.F+dz[i],ans.S.S+1)));
        }
      }
      
    }
  }

  if(y==(ans.F.F*10)+(ans.F.S*5)+(ans.S.F*1))
    printf("%d %d %d\n",ans.F.F,ans.F.S,ans.S.F);
  else
    printf("-1 -1 -1\n");

  return 0;
}

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

int main(){
	int n,a,ans = 0;
	cin >> n;

	for(a = 1; a < n; a++){
		if(n%a != 0){
			ans = ans + n/a;
		}
		else{
			ans = ans + n/a - 1;
		}
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
vector<int>G[100000];
int pa[100001];
int prenum[100001];
int lowest[100001];
int visit[100001];
int in[100001];
int v, e;
int timer = 0;
void dfs(int root,int pre) {
	pa[root] = pre;
	lowest[root] = prenum[root] = timer;
	timer++;
	visit[root] = 1;
	for (int i = 0; i < G[root].size(); i++) {
		if (!visit[G[root][i]]) {
			dfs(G[root][i], root);
			lowest[root] = min(lowest[root], lowest[G[root][i]]);
		}
		else if(G[root][i] != pa[root]){
			lowest[root] = min(lowest[root], prenum[G[root][i]]);
		}
	}
} 
int main(void) {
	cin >> v >> e;
	int a, b;
	for (int i = 0; i < e; i++) {
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0, 0);
	int n = 0;
	priority_queue<int, vector<int>, greater<int> >q;
	for (int i = 0; i < v; i++) {
		if (pa[i] == 0) n++;
		else if(! in[pa[i]]){
			if (prenum[pa[i]] <= lowest[i]) { q.push(pa[i]); in[pa[i]] = 1; }
		}
	}
	if (n > 2) q.push(0);
	int key;
	while (!q.empty())
	{
		key = q.top();
		q.pop();
		cout << key << endl;
	}
}


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

int main() {
  int N;
  cin >> N;
  
  vector<tuple<string, int, int>> data;
  for (int i = 0; i < N; i++) {
    string city;
    int score;
    cin >> city >> score;
    data.push_back(make_tuple(city, 100 - score, i + 1));
  }
  
  sort(data.begin(), data.end());

  
  for (int i = 0; i < N; i++) {
    string f;
    int s, t;
    tie(f, s, t) = data.at(i);
    cout << t << endl;
  }
    
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

N = int(input())
A = [0]
for _ in range(N):
    A.append(int(input()))

pos = 1
ans = 0
reached_index = set([1])
while True:
    pos = A[pos]
    ans += 1
    if pos in reached_index:
        ans = -1
        break
    if pos == 2:
        break
    reached_index.add(pos)

print(ans)

Measured memory_bytes: 13216
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define fast ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define pi 3.14159265358979323846264338327950D
#define modd 1000000000
#define k 100000000

int main()
{
        fast;
        int t=1;
      //  cin>>t;
        while(t--)
        {
                int n;
                cin>>n;
                int count[n+1]={0};
                for(int i=1;i<n;i++)
                {
                        int x;
                        cin>>x;
                        count[x]++;
                }
                for(int i=1;i<=n;i++)
                        cout<<count[i]<<endl;
        }
}

Measured memory_bytes: 4408
# the sieve of Eratosthenes
primes = [1] * 1000000
primes[0] = 0
primes[1] = 0
for i in range(2, 1000):
    if primes[i]:
        primes[i*2::i] = [0] * len(primes[i*2::i])

from itertools import accumulate
acc_primes = list(accumulate(primes))

for i in range(30):
    try:
        n = int(input())
        print(acc_primes[n])
    except EOFError:
        break



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

using namespace std;

int main()
{
        long long h,r=1,s=0;
        cin>>h;
       // if(h>1)
        {
            while(h>=2)
            {
                    h=h/2;
                    s=s+r;
                    r=r*2;
                   // cout<<r<<endl;;
            }
            s=s+r;
            cout<<s<<endl;
        }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
#include<vector>

using namespace std;
int main() {
	string str;
	int count=0;

	cin >> str;
	for (int i = 0; i < str.size(); i++)
	{
		if (str[i]==',')
		{
			str[i] = ' ';
		}

	}


	cout << str << endl;

	return 0;

}


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

int main() {
    int D;
    cin >> D;
    vector<int> c(26);
    vector<vector<int>> s(D, vector<int>(26));
    rep(i, 26) cin >> c[i];
    rep(i, D) {
        rep(j, 26) { cin >> s[i][j]; }
    }

    vector<int> t(D);
    rep(i, D) {
        cin >> t[i];
        t[i]--;
    }

    vector<int> ans(D);
    vector<vector<ll>> Cost(D, vector<ll>(26, 0));
    rep(i, 26) Cost[0][i] = c[i];
    ll v = 0;
    rep(i, D) {
        int index = t[i];
        Cost[i][index] = 0;
        v += s[i][index];
        rep(j, 26) {
            v -= Cost[i][j];
            if(i + 1 < D)
                Cost[i + 1][j] = Cost[i][j] + c[j];
        }
        // cout << v << endl;
    }
    // cout << v << endl;
    int M;
    cin >> M;
    rep(i, M) {
        int d, q;
        cin >> d >> q;
        d--;
        q--;
        int x = d + 1;
        v += s[d][q] - s[d][t[d]];
        v += Cost[d][q];
        Cost[d][q] = 0;
        while(x < D && t[x] != q) {
            v += Cost[x][q];
            Cost[x][q] = Cost[x - 1][q] + c[q];
            v -= Cost[x][q];
            x++;
        }

        x = d + 1;
        int y = t[d];
        if(d == 0) {
            Cost[d][y] = c[y];
            v -= Cost[d][y];
        } else {
            Cost[d][y] = Cost[d - 1][y] + c[y];
            v -= Cost[d][y];
        }
        while(x < D && t[x] != y) {
            v += Cost[x][y];
            Cost[x][y] = Cost[x - 1][y] + c[y];
            v -= Cost[x][y];
            x++;
        }
        t[d] = q;
        cout << v << endl;
    }
}

Measured memory_bytes: 3724
from collections import defaultdict
N = int(input())
S = [''.join(sorted(input())) for _ in range(N)]
d = defaultdict(lambda:0)
for s in S:
    d[s] += 1
ans = 0
for s in d:
    n = d[s]
    ans += n*(n-1)//2

print(ans)

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

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

	int n = s.size();
	bool result = true;
	rep(i, n) {
		if (i % 2 == 0) {
			if (s[i] == 'L') {
				result = false;
			}
		}
		else {
			if (s[i] == 'R') {
				result = false;
			}
		}
	}

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


Measured memory_bytes: 256
def inpl(): return list(map(int, input().split()))


n = int(input())

nt, nx, ny = 0, 0, 0
for _ in range(n):
    t, x, y = inpl()
    if (abs(nx-x)+abs(ny-y))%2 != (t-nt)%2 or abs(nx-x)+abs(ny-y) > t-nt:
        # print((abs(nx-x)+abs(ny-y))%2 != (t-nt)%2,abs(nx-x)+abs(ny-y) > t-nt)
        # print((abs(nx-x)+abs(ny-y))%2,(t-nt)%2)
        print("No")
        exit()
    nt, nx, ny = t, x, y
print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,ans=0;
   cin >> n;
  for(int i=0;i<26;i++){
    for(int j=0;j<15;j++){
      if(i*4+j*7==n){
		cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    string s;
    cin >> s;
    s[5]= ' ',s[13]= ' ';
    
    cout << s << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int abcde[10], k;

    for (int i = 0; i < 5; ++i) {
        cin >> abcde[i];
    }
    cin >> k;
    bool tf = true;
    for (int i = 0; i < 5 && tf; ++i) {
        for (int j = i+1; j < 5 && tf; ++j) {
            if (abcde[j]-abcde[i] > k) tf = false;
        }
    }

    if (tf) cout << "Yay!" << endl;
    else cout << ":(" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define STEP 0.0005
// sort(a.begin(), a.end(), std::greater<int>());

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

int main()
{
    int a, b, k;
    set<int> st;
    cin >> a >> b >> k;
    rep(i, k)
    {
        st.insert(min(a + i, b));
    }
    rep(i, k)
    {
        st.insert(max(a, b - i));
    }
    for (auto itr = st.begin(); itr != st.end(); ++itr)
    {
        std::cout << *itr << "\n"; // イテレータの指す先のデータを表示
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		for(int i=0,pm,pe,pj;i<n;++i){
			cin>>pm>>pe>>pj;
			if(pm==100||pe==100||pj==100||(pm+pe)/2>=90||(pm+pe+pj)/3>=80) cout<<"A\n";
			else if((pm+pe+pj)/3>=70||((pm+pe+pj)/3>=50&&(pm>=80||pe>=80))) cout<<"B\n";
			else cout<<"C\n";
		}
		
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	ll S;
	cin >> S;
	ll x = (S - 1) / (ll)1e9 + 1;
	cout << "0 0 1 1000000000 " << x << " " << (x * (ll)1e9 - S);
}

Measured memory_bytes: 256