akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define eps 1e-9
#define maxp 1000400
#define mod 1000000007
#define pi 3.141592653589793238
#define sin(s) scanf("%lld",&s);
#define sout(s) printf("%lld\n",s);
#define in(s) cin>>s
#define in2(a,b) cin>>a>>b
#define in3(a,b,c) cin>>a>>b>>c
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl '\n'
#define sp ' '
#define gear_change ios_base::sync_with_stdio(false),cin.tie(0)
#define nfl(i,n) for(i=0;i<n;i++)
#define sfl(i,s,e) for(i=s;i<e;i++)
#define ufl(i,n) for(i=n-1;i>=0;i--)
ll power(ll x,ll y){
    ll ret=1;
    while(y>0){
        if(y&1)
            ret=(ret*x);
        y/=2;
        x=(x*x);
    }
    return ret;
}
string rot(string s){
	string ret="";
	ll i;
	for(i=1;s[i];i++){
		ret+=s[i];
	}
	ret+=s[0];
	return ret;
}
void solve(){
	string s,t;
	cin>>s>>t;
	string s2=s;
	if(s==t){
		cout<<"Yes"<<endl;
		return;
	}
	s=rot(s);
	while(s!=s2){
		if(s==t){
			cout<<"Yes"<<endl;
			return;
		}
		s=rot(s);
	}
	cout<<"No"<<endl;
}	
int main(){
	gear_change;
	ll test=1;
	// in(test);
	while(test--){
		solve();
	}
}	


Measured memory_bytes: 256
from itertools import accumulate
n, k = map(int, input().split())
As = list(map(int, input().split()))

acc = [0]+list(accumulate(As))
mx = 0
sums = []
for i in range(n+1):
    for j in range(i+1,n+1):
        s = acc[j]-acc[i]
        sums.append(s)

# 計算
now = 0
for d in range(40,-1,-1):
    cnt = 0
    for s in sums:
        # 上から見て、bitが立っている数がk個以上かどうか
        # 最上位がkこ未満だったら、そのbitはもう使わない
        # 1000 -> 1100 -> 1100 -> 1101 みたいな絞り込み
        if s & (now|(1<<d)) == now|(1<<d):
            cnt += 1
    # print(d,cnt)
    if cnt >= k:
        now |= 1<<d
print(now)

Measured memory_bytes: 108732
require "date"

$refer=Date.new(2012,12,21)
loop{
  s=gets.chomp
  if s=="#"
    break
  end
  date=s.split(".").map(&:to_i)
  if date.length == 3
    _date=Date.new(date[0],date[1],date[2])
    dif=_date-$refer
    ki=(dif%20).to_i
    dif=(dif/20).to_i
    w=(dif%18).to_i
    dif=(dif/18).to_i
    t=(dif%20).to_i
    dif=(dif/20).to_i
    ka=(dif%20).to_i
    dif=(dif/20).to_i
    b=(dif%13).to_i
    puts "#{b}.#{ka}.#{t}.#{w}.#{ki}"
  else
    dif=(((date[0]*20+date[1])*20+date[2])*18+date[3])*20+date[4]
    _date=$refer+dif
    puts "#{_date.year}.#{_date.month}.#{_date.day}"
  end
}

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

using namespace std;
#define ll long long
const int N = 5e3 + 5;
int dp[N][N];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        for (int j = n - 1; j >= i; j--) {
            if (s[i] == s[j]) dp[i][j] = 1 + dp[i + 1][j + 1];
            ans = max(ans, min(dp[i][j], j - i));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 96768
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
ans = ''
if n == 0:
    print(0)
    quit()
while 1:
    if n == 0:
        break
    if n % -2:
        ans += '1'
        n -= 1
    else:
        ans += '0'
    n //= -2
print(ans[::-1])

Measured memory_bytes: 38384
#pragma GCC optimize("Ofast")   //Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)     for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)     for(ll i = (a); i >= n; i--)
#define  fo(i,n)        for(ll i = 0; i < n; i++)
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  newl           cout<<"\n"
#define  pb             push_back
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define  deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define  deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   MAXN  =  1e+5+7;

vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll n;ld a[3005];
ld dp[3005];
//<<-----Implement Functions Here---->>//


//<<-----Start of Main--------------->>//
void MAIN(){
		cin>>n;
		for(ll i=0;i<n;i++){cin>>a[i];dp[i] =0;}dp[0] = 1;dp[n] = 0;
       	for(ll i=0;i<n;i++)
       	{
       		for(ll j=i+1;j>=0;j--)
       		{
       			dp[j] = (j==0? 0 : dp[j-1]*a[i]) + dp[j]*(1-a[i]);
       		}
       	}
       
		ld ans = 0;
		for(ll i=n/2+1;i<=n;i++)ans += (ld)dp[i];
		cout<<ans;
		
}

int main(){
	fastio;randomINIT;

	//cin>>t;
	while(t--){
		MAIN();
	}

}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define inv(n, a) for(int i = 0; i < n; i++) cin >> a[i]
#define MOD 1000000007
#define INF 1e7
#define LINF 1e15
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
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; }
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25

int main() {
    string s; cin >> s;
    if(s == "ABC"){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
}


Measured memory_bytes: 3628
# encoding:utf-8
def main():
	n, k = list(map(int, input().split()))
	
	if k % 2 == 0:
		ans = (n // k) ** 3 + ((n + k / 2) // k) ** 3
	else:
		ans = (n // k) ** 3
	print(int(ans))

if __name__ == '__main__':
	main()


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

using namespace std;

const long long MOD = (long long)1e9 + 7;

int main(){
	long long n, ans = 0;
	string s1, s2;
	vector<int> a;
	cin >> n >> s1 >> s2;
	int p = 0;
	while(p < n){
		if(s1[p] == s2[p]){
			a.push_back(0);
			p++;
		}else{
			a.push_back(1);
			p += 2;
		}
	}
	if(a[0] == 0){
		ans = 3;
	}else{
		ans = 6;
	}
	for(int i = 1; i < a.size(); i++){
		if(a[i - 1] == 0){
			ans = (ans * 2) % MOD;
		}else{
			if(a[i] == 1){
				ans = (ans * 3) % MOD;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
ListMaster=[]
for i in range(M):
  ListMaster.append(i+1)
s =set(ListMaster)
mid = set()
List = []
for i in range(N):
  List.append(list(map(int, input().split())))
for i in range(N):
  List[i].pop(0)
for i in range(N):
  mid = set(List[i])
  s = s&mid
print(len(s))

Measured memory_bytes: 9104
#include<iostream>
using namespace std;
int main(){
  	int a,b;
  	cin >> a >> b;
  	if((a+b)%3==0 || a%3==0 || b%3==0){
    	cout << "Possible\n";
    }
  	else{
    	cout << "Impossible\n";
    }
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        
        if(n > 888){
            System.out.println(999);
        }else if(n > 777){
            System.out.println(888);
        }else if(n > 666){
            System.out.println(777);
        }else if(n > 555){
            System.out.println(666);
        }else if(n > 444){
            System.out.println(555);
        }else if(n > 333){
            System.out.println(444);
        }else if(n > 222){
            System.out.println(333);
        }else if(n > 111){
            System.out.println(222);
        }else{
            System.out.println(111);
        }
    }
}

Measured memory_bytes: 23252
/**
*	created: 23.08.2020 11:37:07
**/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
using ll = long long;
using P = pair<int,int>;
// #define endl '\n'
#define int long long
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
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;}
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1ll << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n; cin >> n;
    vector<int> v1, v2;
    rep(i,n) {
        int a; cin >> a;
        if (i % 2 == 0) v1.push_back(a);
        else v2.push_back(a);
    }
    map<int,int> m1, m2;
    rep(i,n/2) {
        m1[v1[i]]++;
        m2[v2[i]]++;
    }
    vector<P> mv1, mv2;
    for (auto p : m1) mv1.push_back(make_pair(p.second,p.first));
    for (auto p : m2) mv2.push_back(make_pair(p.second,p.first));
    sort(rall(mv1));
    sort(rall(mv2));
    if (mv1[0].second != mv2[0].second) cout << n - mv1[0].first - mv2[0].first << endl;
    else if (m1.size() > 1 && m2.size() > 1) {
        int m1 = n - mv1[1].first - mv2[0].first;
        int m2 = n - mv1[0].first - mv2[1].first;
        cout << min(m1,m2) << endl;
    }
    else if (m1.size() == 1 && m2.size() == 1) cout << n/2 << endl;
    else if (m1.size() == 1) cout << n - mv2[1].first << endl;
    else cout << n - mv1[1].first << endl;
    return 0;
}


Measured memory_bytes: 11280
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i,ans = 0,a,k,v;scanf("%d",&n);
  unordered_map<int,int> m;
  for(i=0;i<n;i++){
    scanf("%d",&a);
    if(m.find(a) != m.end()) m[a]++;
    else m[a] = 1;
  }
  for(auto itr=m.begin();itr!=m.end();itr++){
    k = itr->first;v = itr->second;
    if(k>v) ans += v;
    else ans += v-k;
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 4260
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = int64_t;

bool check(i64 x, i64 k, const vector<i64> &a) {
  i64 cnt = 0;
  i64 n = a.size();
 
  rep(i, n) {
    i64 ci = 0;
    long double t = 0;
    if (a[i] == 0) {
      if (x >= 0) {
        cnt += n - 1 - i;
      }
    } else {
      t = x / (long double)a[i];
      if (a[i] > 0) {
        ci = upper_bound(all(a), t) - a.begin();
        if(ci <= i){continue;}
        cnt += ci-i-1;
      } else {
        ci = lower_bound(all(a), t) - a.begin();
        if(ci <= i) ci = i+1;
        cnt += n - ci;
      }
    }
  }
    return cnt >= k;
}

int main(){
    i64 n,k;
    cin >> n >> k;
  	vector<i64> a(n);
    rep(i,n){cin >> a[i];}
    sort(all(a));
    const i64 MAX = 1e18 * 2;
    i64 ok = MAX;
    i64 ng = -MAX;
    while(abs(ok-ng) > 1){
        i64 mid = (ok+ng)/2;
        if(check(mid,k,a)) 
            ok = mid;
        else 
            ng = mid;
    }
    cout << ok << endl;
  return 0;
}


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

int main() {
    vector <int> x(5);
    int idx = 0;

    for (int i = 0; i < 5; ++i) {
        cin >> x[i];

        if (x[i] == 0) {
            idx = i + 1;
            break;
        }
    }

    cout << idx << endl;

    return 0;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
// #define map unordered_map
// #define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

ll calc(vector<ll> &list1, vector<ll> &list2, vector<ll> &list3, set<ll> &set2,
        set<ll> &set3) {
  ll ans = 0;

  for (ll i = 0; i < list1.size(); i++) {
    ll index1 = list1[i];

    // cout << "index1:" << index1 << endl;

    {
      auto ite2 = lower_bound(list2.begin(), list2.end(), index1);
      ll len2 = list2.end() - ite2;
      for (; ite2 != list2.end(); ite2++) {
        ll index2 = *ite2;

        auto ite3 = lower_bound(list3.begin(), list3.end(), index2);
        ll len = list3.end() - ite3;
        ans += (len);
        // cout << "len:" << len << endl;

        ll df = index2 - index1;
        ll sindex = index2 + df;
        if ((set3.find(sindex) != set3.end())) {
          ans -= 1;
        }
      }
    }

    // cout << "----" << endl;

    {
      auto ite2 = lower_bound(list3.begin(), list3.end(), index1);
      ll len2 = list3.end() - ite2;
      for (; ite2 != list3.end(); ite2++) {
        ll index2 = *ite2;
        auto ite3 = lower_bound(list2.begin(), list2.end(), index2);
        ll len = list2.end() - ite3;
        ans += (len);
        // cout << "len:" << len << endl;

        ll df = index2 - index1;
        ll sindex = index2 + df;
        if ((set2.find(sindex) != set2.end())) {
          ans -= 1;
        }
      }
    }

    // cout << "======================" << endl;
  }

  // cout << "ans:" << ans << endl;
  return ans;
}

int main() {
  ll N;
  scanf("%lld", &N);

  string S;
  cin >> S;

  vector<ll> listR;
  vector<ll> listG;
  vector<ll> listB;

  set<ll> setR;
  set<ll> setG;
  set<ll> setB;

  for (ll i = S.size() - 1; i >= 0; i--) {
    // R[i - 1] = R[i];
    // G[i - 1] = G[i];
    // B[i - 1] = B[i];

    char ch = S[i];
    if (ch == 'R') {
      // R[i - 1] += 1;
      listR.emplace_back(i);
      setR.insert(i);
    }
    if (ch == 'G') {
      // G[i - 1] += 1;
      listG.emplace_back(i);
      setG.insert(i);
    }
    if (ch == 'B') {
      // B[i - 1] += 1;
      listB.emplace_back(i);
      setB.insert(i);
    }
  }

  ll ans = 0;

  sort(listR.begin(), listR.end());
  sort(listG.begin(), listG.end());
  sort(listB.begin(), listB.end());

  ans += calc(listR, listG, listB, setG, setB);
  ans += calc(listG, listB, listR, setB, setR);
  ans += calc(listB, listR, listG, setR, setG);

  // for (ll i = 0; i < S.size(); i++) {
  //   if (S[i] == 'R') {
  //     ll plus = (G[i] * B[i]);
  //     ans += plus;
  //   }
  //   if (S[i] == 'G') {
  //     ll plus = (R[i] * B[i]);
  //     ans += plus;
  //   }
  //   if (S[i] == 'B') {
  //     ll plus = (R[i] * G[i]);
  //     ans += plus;
  //   }
  // }

  cout << ans << endl;
}

// RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB


Measured memory_bytes: 3920
#include <iostream>
#include <vector>
#include <cmath>

double distance(const std::vector<int>& x1, const std::vector<int>& x2) {
    int sum = 0;
    for (size_t i = 0; i < x1.size(); ++i) {
        const auto dx = x1[i] - x2[i];
        sum += dx*dx;
    }
    return std::sqrt(sum);
}

bool is_integer(double x) {
    constexpr double tol = 1e-3;
    return std::fabs(x - std::round(x)) < tol;
}

int main() {
    int n, d;
    std::cin >> n >> d;

    std::vector<std::vector<int>> x(n);
    for (auto&& xi : x) {
        xi.resize(d);
        for (auto&& xij : xi) std::cin >> xij;
    }

    int count = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            const double dist = distance(x[i], x[j]);
            if (is_integer(dist)) ++count;
        }
    }
    std::cout << count << std::endl;
}

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

int main(){
  int n;
  cin >> n;
  int num = n;
  int x;
  int search = 1;
  while(num--){
    cin >> x;
    if (x == search){
      search++;
    }
  }
  if (search == 1){
    cout << "-1";
  }
  else {
    cout << n - search + 1;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  ll i,j,x,y,z,a[1010],b[1010],c[1010],k;
  cin >> x >> y >> z >> k;
  for(i=0;i<x;i++){
    scanf("%lld",&a[i]);
    a[i]*=-1;
  }
  for(i=0;i<y;i++){
    scanf("%lld",&b[i]);
    b[i]*=-1;
  }
  for(i=0;i<z;i++){
    scanf("%lld",&c[i]);
    c[i]*=-1;
  }
  sort(a,a+x);
  sort(b,b+y);
  sort(c,c+z);
  ll min=-30000000001,max=-2;
  while(abs(min-max)>1){
    ll mid=(min+max)/2;
    ll sum=0;
    for(i=0;i<x;i++){
      for(j=0;j<y;j++){
        if(a[i]+b[j]<=mid){
          sum+=z;
          continue;
        }
        ll mi=-1,ma=z;
        while(abs(mi-ma)>1){
          ll md=(mi+ma)/2;
          if(c[md]<=mid-a[i]-b[j]){
            mi=md;
          }
          else{
            ma=md;
          }
        }
        sum+=mi+1;
      }
    }
    if(sum>=k){
      max=mid;
    }
    else{
      min=mid;
    }
  }
  vector<ll> ans;
  for(i=0;i<x;i++){
    for(j=0;j<y;j++){
      ll mi=-1,ma=z;
      while(abs(mi-ma)>1){
        ll md=(mi+ma)/2;
        if(c[md]<=max-a[i]-b[j]){
          mi=md;
        }
        else{
          ma=md;
        }
      }
      for(int l=0;l<=mi;l++){
        ans.push_back(a[i]+b[j]+c[l]);
      }
    }
  }
  sort(ans.begin(),ans.end());
  for(i=0;i<k;i++){
    cout << ans[i]*(-1) << endl;
  }
}

Measured memory_bytes: 134480
#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int lli;
int main() {fio; // remove during scanf
	lli A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;
	lli ans = 1e18;
	for(int i = 0; i <= 1e6; i++) {
		ans = min(ans, max((X - i/2), 0LL) * A + i * C + max((Y - i/2), 0LL) * B);
	}
	cout << ans;
    return 0;
}

Measured memory_bytes: 256
import numpy as np

h, w, k = map(int, input().split(" "))

first = True
former_exist = None
#outs = [[None for i in range(h)] for i in range(h)]
outs = np.zeros((h, w), dtype=int)
ichigo_i = 1
before_i = -1
for i in range(h):
    arus = [j for j, c in enumerate(input()) if c == "#"]
    
    #print("arus", arus)
    if len(arus) >= 1:
        exist_arus = arus
        before_j = -1
        last_aru = arus[-1]
        last_start_ichigo_i = ichigo_i
        for j in arus:
            if j != last_aru:
                outs[before_i+1:i+1, before_j+1:j+1] = ichigo_i
            else:
                outs[before_i+1:i+1, before_j+1:] = ichigo_i
            ichigo_i += 1
            before_j = j
        before_i = i

last_i = before_i
last_arus = exist_arus

if last_i != h-1:
    arus = last_arus
    before_j = -1
    last_aru = arus[-1]
    ichigo_i = last_start_ichigo_i
    for j in arus:
        if j != last_aru:
            outs[before_i+1:i+1, before_j+1:j+1] = ichigo_i
        else:
            outs[before_i+1:i+1, before_j+1:] = ichigo_i
        ichigo_i += 1
        before_j = j

#print(outs)
for i in range(h):
    print(" ".join([str(elm) for elm in outs[i]] ))

Measured memory_bytes: 13684
def main():
    n = int(input())
    A,B = [],[]
    for i in range(n):
        a,b = map(int,input().split())
        A.append(a)
        B.append(b)
    A = sorted(A)
    B = sorted(B)
    if n%2==0:
        print(int(((B[n//2-1]+B[n//2])/2-(A[n//2-1]+A[n//2])/2)*2)+1)
    else:
        print(B[(n+1)//2-1]-A[(n+1)//2-1]+1)
if __name__ == "__main__":
    main()


Measured memory_bytes: 27100
/*  ***  In The Name of God ... ***  */
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define bug() cout << "BUG" << endl ;
#define X first
#define Y second
#define per(how) cout << fixed << setprecision(how)
#define bit(a , b) (a >> b) & 1
#define all(v) v.begin() , v.end()
#define LB(x) (x & -x)
typedef long long ll;
typedef long double ld;
const ll INF = 1e18 , MOD = 1e9 + 7 , SQRT = 350 ;
inline void smin(ll &x , ll y) { x = min(x , y) ; }
inline void smax(ll &x , ll y) { x = max(x , y) ; }




int main ()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	ll n , m;
	cin >> n >> m;
	n-- , m--;
	cout << n * m << endl ;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#pragma region Macros
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define all(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
int gcd(int a, int b) // assuming a,b >= 1
{
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    if (a % b == 0)
        return b;
    return gcd(b, a % b);
}
int lcm(int a, int b) // assuming a,b >= 1
{
    return  a * b / gcd(a, b);
}
using namespace std;
#pragma endregion
signed main() {
    int A,B;
    cin >> A >> B;
    if (A >= 13) {
        cout << B;
        return 0;
    }
    if (5 < A && A <= 12) {
        cout << B / 2;
        return 0;
    }
    cout << 0;
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
  int N;
  int ans;
  cin >> N;
  int odd = (N+1)/2;
  double a = (double)odd / (double)N;
  cout << a << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

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

int main() {
	int K,X;
	cin>>K>>X;
	for (int i = X-K+1; i <= X+K-1; ++i){
		if(-1000000<=i&&i<=1000000){
			cout<<i<<" ";	
		}

	}
	cout<<endl;
}

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

public class Main {
	int n, q;
	int[] s, t;
	void run() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		s = new int[n];
		for (int i = 0; i < n; i++)
			s[i] = scan.nextInt();
		q = scan.nextInt();
		t = new int[q];
		for (int i = 0; i < q; i++)
			t[i] = scan.nextInt();
		int ans = 0;
		for (int i = 0; i < q; i++) {
			if (binarySearch(t[i]))
				ans++;
		}
		System.out.println(ans);
	}

	boolean binarySearch(int val) {
		int low = 0;
		int high = n - 1;
		while (low <= high) {
			int mid = (low + high) / 2;
			if (s[mid] == val)
				return true;
			else if (s[mid] > val)
				high = mid - 1;
			else
				low = mid + 1;
		}
		return false;
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn long long

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


int main()
{
  map<string, string> mp;
  cin >> mp["a"] >> mp["b"] >> mp["c"];
  string now = "a";
  while(true)
  {
    if(int(mp[now].size()) == 0)
    {
      if(now == "a") cout << "A" << endl;
      if(now == "b") cout << "B" << endl;
      if(now == "c") cout << "C" << endl;
      return 0;
    }
    char tmp = mp[now][0];
    mp[now] = mp[now].substr(1);
    now = tmp;
  }


}

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

int main() {
  int H, W, a;
  cin >> H >> W;
  vector<int> A(H);
  for (int i = 0; i < W*2; i++) {
    cin >> a;
    A.at(a-1)++;
  }

  for (int i = 0; i < H; i++) {
    cout << A.at(i) << endl;
  }
}

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

using namespace std;

int main() {
    int N,M,K;
    cin>>N>>M>>K;
    vector<string> v(N);
    for(int c=0;c<N;c++) cin>>v[c];
    vector<vector<int> > res(N,vector<int>(M,0));
    int color = 1;

    int mini = 1e6, maxi = -1e6;

    for(int c=0;c<N;c++) {
        int nbStrawS=0;
        for(int c2=0;c2<M;c2++) {
            res[c][c2]=color;
            if(v[c][c2]=='#') {
                nbStrawS++;
                if(nbStrawS > 1) {
                    res[c][c2]=++color;
                }
            }
        }
        if(nbStrawS==0) {
            for(int c2=0;c2<M;c2++) res[c][c2]=0;
        } else {
            mini = min(c,mini);
            maxi = max(c,maxi);
            color++;
        }
    }

    bool specialColumn = true;

    for(int c=mini-1;c>=0;c--) {
        int nbstraws=0;

        for(int c2=0;c2<M;c2++) {

            if(res[c][c2]!=0) nbstraws++;
        }

        for(int c2=0;c2<M;c2++) {
            if(res[c][c2]==0) {
                res[c][c2]=res[c+1][c2];
            }
        }

    }

    for(int c=0;c<N;c++) {
        int nbstraws=0;

        for(int c2=0;c2<M;c2++) {

            if(res[c][c2]!=0) nbstraws++;
        }

        for(int c2=0;c2<M;c2++) {
            if(res[c][c2]==0) {
                if(c>0) {
                    res[c][c2]=res[c-1][c2];
                } else {
                    res[c][c2]=res[c+1][c2];
                }
            }
        }

    }

    for(int c=0;c<N;c++) {
        for(int c2=0;c2<M;c2++) {
            cout<<res[c][c2]<<" ";
        }
        cout<<"\n";
    }

}


Measured memory_bytes: 1280
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<cmath>
using namespace std;

int main(void)
{
	int M,N;
	cin >> N >> M;

	long long ret = (1900*M + 100*(N-M)) * pow(2, M);
	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 384
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()

    val E = Vector.fill(N)(new scala.collection.mutable.ArrayBuffer[(Int, Byte)]())
    val ru, rv, rw = sc.nextInt()
    E(ru-1).append((rv-1, (rw % 2).toByte))
    E(rv-1).append((ru-1, (rw % 2).toByte))
    (0 until N - 2) foreach { _ =>
      val u, v, w = sc.nextInt()
      E(u-1).append((v-1, (w % 2).toByte))
      E(v-1).append((u-1, (w % 2).toByte))
    }

    def dfs(root: Int, E: IndexedSeq[Seq[(Int, Byte)]]): IndexedSeq[Int] = {
      import scala.collection.immutable.Queue
      val visited = new Array[Boolean](N)
      val color = new Array[Int](N)
      visited(root) = true

      def recursive(queue: Queue[Int]): Unit =
        if (queue.nonEmpty) {
          val (u, dequeued) = queue.dequeue
          recursive(
            E(u). collect {
              case (v, w) if !visited(v) =>
                visited(v) = true
                if (w == 0)
                  color(v) = color(u)
                else
                  color(v) = 1 - color(u)
                v
            }. foldLeft(dequeued)((q, n) => q.enqueue(n)))
        }

      recursive(Queue[Int]().enqueue(root))
      color
    }

    dfs(ru, E).foreach(println)
  }

}

Measured memory_bytes: 126200
#include<bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define mrp(i,n) for(int i=n-1;i>=0;i--)
#define mrep(i,m,n) for(int i=m;i>=n;i--)
#define mlrp(i,n) for(long long i=n;i>=0;i--)
#define mlrep(i,m,n) for(long long i=m;i>=n;i--)
#define ll long long
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
ll abs(ll a,ll b){
    return(a>b?a-b:b-a);
}

int main(){
    string s;
    cin >> s;
    if(s.at(0)!='A'){
        cout << "WA" << endl;
        return 0;
    }
    int cnt=0;
    rep(i,2,s.size()-2){
        if(s.at(i)=='C'){
            cnt++;
        }
    }
    if(cnt!=1){
        cout << "WA" << endl;
        return 0;
    }
    cnt=0;
    rp(i,s.size()){
        switch(s.at(i)){
            case 'a':cnt++;break;
            case 'b':cnt++;break;
            case 'c':cnt++;break;
            case 'd':cnt++;break;
            case 'e':cnt++;break;
            case 'f':cnt++;break;
            case 'g':cnt++;break;
            case 'h':cnt++;break;
            case 'i':cnt++;break;
            case 'j':cnt++;break;
            case 'k':cnt++;break;
            case 'l':cnt++;break;
            case 'm':cnt++;break;
            case 'n':cnt++;break;
            case 'o':cnt++;break;
            case 'p':cnt++;break;
            case 'q':cnt++;break;
            case 'r':cnt++;break;
            case 's':cnt++;break;
            case 't':cnt++;break;
            case 'u':cnt++;break;
            case 'v':cnt++;break;
            case 'w':cnt++;break;
            case 'x':cnt++;break;
            case 'y':cnt++;break;
            case 'z':cnt++;break;
        }
    }
    if(cnt!=s.size()-2){
        cout << "WA" << endl;
        return 0;
    }
    cout << "AC" << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [0, 0]
A.extend(list(map(int, input().split())))
to = [[] for _ in range(N+1)]
for i in range(2, N+1):
    to[A[i]].append(i)
for i in range(1, N+1):
    print(len(to[i]))

Measured memory_bytes: 44056
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000 , mod = 1000000009;
#define PI 3.14159265
int dp[100005];
int main()
{
    fastio;
    int n,k;
    cin>>n>>k;
    int h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    dp[0] = 0;
    for(int i=1;i<n;i++)
    {
        dp[i] =  INT_MAX;
        for(int j=i-1;j>=max(i-k,0);j--)
        {
            dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]));
        }
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1024
s = input()
t = input()

f = True
for (s1, s2) in [(s, t), (t, s)]:
    d = dict()
    for c1, c2 in zip(s1, s2):
        if c1 not in d:
            d[c1] = c2
        elif d[c1] != c2:
            f = False
            break

if f:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 41840
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1000000007
#define itn int 
itn dp[105][100005];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int a,b,q=0;
  int c[1000],d[1000];
  cin>>a>>b;
  for(int i=0;i<a;i++) cin>>c[i]>>d[i];
  memset(dp,INF,sizeof(dp));
  dp[0][0]=0;
  for(int i=1;i<=a;i++){
    for(int j=0;j<=100000;j++){
      if(j-d[i-1]>=0){
	dp[i][j]=min(dp[i-1][j-d[i-1]]+c[i-1],dp[i-1][j]);
      }
      else dp[i][j]=dp[i-1][j];
    }
  }
  for(int i=100000;i>=0;i--){
    if(dp[a][i]<=b){
      q=i;
      break;
    }
  }
  cout<<q<<"\n";
}


Measured memory_bytes: 82304
N = int(input())
H = list(map(int, input().split()))
count = 0
count1 = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        count1 += 1
    else:
        count = max(count, count1)
        count1 = 0

print(max(count, count1))

Measured memory_bytes: 14228
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<map>
#include<functional>
using namespace std;

const int mod = 1e9+7;
const int INFINT = INT_MAX/2;
typedef long long ll;
typedef unsigned long long ull;

int main(){
    string S;
    cin >> S;
    int N = S.size();
    ull res = 0;
    for (int i=0;i<(1<<(N-1));i++){
        int start = 0;
        for(int j=0;j<(N-1);j++){
            if(i>>j & 1){
                res += stoll(S.substr(start, j - start + 1));
                start = j + 1;
            }
        }
        res += stoll(S.substr(start, N - start));
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
fun power(base: Long, exp: Long): Long {
    return when(exp) {
        0L -> 1L
        1L -> base % 998244353
        else -> power(base * base % 998244353, exp shr 1) * power(base, exp and 1) % 998244353
    }
}
fun main() {
    val MOD = 998244353L
    val (n, s) = readLine()!!.trim().split(' ').map(String::toInt)
    val nums = readLine()!!.trim().split(' ').map(String::toInt)
    val memo = LongArray(s + 1){0}
    memo[0] = power(2, n.toLong())
    val inv2 = power(2, MOD - 2)
    for (a in nums) {
        var sum = s
        while (sum >= a) {
            memo[sum] += memo[sum - a] * inv2 % MOD
            memo[sum] %= MOD
            --sum
        }
    }
    println(
        memo.last()
    )
}


Measured memory_bytes: 41860
#include<stdio.h>

int A[101][101],d[101],f[101],color[101],n,time;

#define WHITE 0
#define BLACK 1
#define GRAY 3


void dfs()
{
  int i;
  for(i=0;i<n;i++)
    {
      color[i]=WHITE;
      d[i]=0;
      f[i]=0;
    }
  time=0;
  for(i=0;i<n;i++)
    {
      if(color[i]==WHITE) visit(i);
    }
}

void visit(int u)
{
  int i;
  color[u]=GRAY;
  d[u]=++time;
  for(i=0;i<n;i++)
    {
      if(A[u][i]==0) continue;
      if(color[i]==WHITE) visit(i);
    }
  color[u]=BLACK;
  f[u]=++time;
}
  

int main()
{
  int i,j,m,k,l;
  scanf("%d",&n);

    for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
	{
	  A[i][j]=0;
	}
    }
  for(l=0;l<n;l++)
    {
      scanf("%d",&i);
      scanf("%d",&k);
      for(m=0;m<k;m++)
	{
	  scanf("%d",&j);
	  A[i-1][j-1]=1;
	}
    }

  dfs();

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

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

int main() {
  int N,cnt;
  cin >> N;
  cnt = 0;
  for(int i = 0;i < N;i++)
  {
  	int r,L;
  	cin >> r >> L;
  	cnt += L - r + 1;
  }
  cout << cnt;
  
}


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

int gcd_func(int a, int b){
    return b? gcd_func(b, a%b) : a;
} 
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    long long a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
    return 0;
}

Measured memory_bytes: 3660
N = int(input())
*A, = map(int, input().split())

def partition(A, p, r):
    x = A[r]
    i = p
    for j in range(p, r):
        if A[j] <= x:
            A[i], A[j] = A[j], A[i]
            i += 1
    A[i], A[r] = A[r], A[i]
    return i

j = partition(A, 0, N-1)
print(*(str(x) if i != j else "[%d]" % x for i, x in enumerate(A)))



Measured memory_bytes: 16392
import java.math.BigInteger;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long n = sc.nextLong();
		sc.close();

		StringBuilder sb = new StringBuilder();
		while (n > 0) {
			n -= 1;
			sb.append((char) ('a' + n % 26));
			n /= 26;
		}
		System.out.println(sb.reverse().toString());
	}
}

Measured memory_bytes: 27104
import java.util.*;

public class Main {
    public static void main(String[] args){
        
        Scanner scanner = new Scanner(System.in);
        int K = scanner.nextInt();
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        
        if(K==1||(B/K-A/K)>=1||A%K==0||B%K==0){
            System.out.println("OK");
        }else{
            System.out.println("NG");
        }

    }
}


Measured memory_bytes: 35560
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define inf 1e16
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define mx 1000010

int main(){
	IOS;
	ll n;cin>>n;
	ll a[n];rep(i,0,n)cin>>a[i];
	ll c=0;
	rep(i,0,n){
		bool f=0;
		rep(j,0,i)if(a[j]>a[i])f=1;
		if(!f)c++;
	}cout<<c;
	return 0;
}



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

using namespace std;

int n, k, cnt, ans;

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

	cin >> n >> k;

	
	cnt = 0;
	ans = 0;

	for (int i = 0; i < n; i++) {
		cnt++;

		if (cnt ==k) {
			cnt = 1;
			ans++;
		}
	}

	if (cnt > 1) ans++;

	cout << ans << "\n";

	return 0;
}

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

int main(void) {

    int a,b;
    cin >> a >> b;
    if(a*b%2==0){
        cout << "Even" << endl;
    }else{
        cout << "Odd" << endl;
    }

    return 0;
    
}

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

int main() {
    int n, m, a, b, src, dst;
    cin >> n;
    unordered_map<int, vector<int>> e;
    map<pair<int, int>, int> mm;
    for(int i = 0; i < n-1; i++) {
        cin >> a >> b;
        e[a].push_back(b);
        e[b].push_back(a);
        if (a > b)
            swap(a, b);
        mm[{a, b}] = i;
    }
    vector<ll> rules;
    cin >> m;
    for(int i = 0; i < m; i++) {
        cin >> src >> dst;
        vector<int> parent(n+1, 0);
        vector<bool> visit(n+1, false);
        visit[src] = true;
        parent[src] = src;
        vector<int> dq = {src};
        while (!dq.empty()) {
            vector<int> new_dq;
            for(int node: dq) {
                for(int neibor: e[node]) {
                    if (visit[neibor] == false) {
                        visit[neibor] = true;
                        parent[neibor] = node;
                        new_dq.push_back(neibor);
                    }
                }
            }
            new_dq.swap(dq);
        }
        int cur = dst;
        ll num = 0;
        while (cur != src) {
            a = cur;
            b = parent[cur];
            if (a > b)
                swap(a, b);
            num = num | (1LL << mm[{a, b}]);
            cur = parent[cur];
        }
        rules.push_back(num);
    }
    // inclusive - exclusive
    ll ans = 0;
    for(int state = 0; state < (1<<m); state++) {
        ll x = state, bit_cnt = 0;
        while (x > 0) {
            x -= x & (-x);
            bit_cnt += 1;
        }
        ll mask = 0;
        for(int j = 0; j < m; j++) {
            if (state >> j & 1) {
                mask = mask | rules[j];
            }
        }
        x = mask;
        ll bit_cnt2 = 0;
        while (x > 0) {
            x -= x & (-x);
            bit_cnt2 += 1;
        }
        ll comb = 1LL << (n-1-bit_cnt2);
        if (bit_cnt % 2 == 1)
            ans -= comb;
        else
            ans += comb;
    }
    cout << ans << endl;
    return 0;
}


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

#define P_MAX 999984
using namespace std;

vector<int> Prime;
bool isPrime[P_MAX];

void make() {
  fill(isPrime, isPrime+P_MAX, true);
  isPrime[0] = isPrime[1] = false;
  for(int i = 2; i < P_MAX; ++i) {
    if(isPrime[i]) {
      Prime.push_back(i);
      for(int j = i*2; j < P_MAX; j += i) isPrime[j] = false;
    }
  }
}

int n, p, m, sum;

int calcX() {
  int a = p - m;
  int b = p + m;
  vector<int>::iterator it1 = lower_bound(Prime.begin(), Prime.end(), a);
  vector<int>::iterator it2 = upper_bound(Prime.begin(), Prime.end(), b);
  return distance(it1, it2);
}

void add() {
  int X = calcX();
  if(X == 0) sum -= 1;
  else       sum += X - 1;
}

main() {
  make();
  while((cin >> n) && n) {
    sum = 0;
    for(int i = 0; i < n; ++i) {
      cin >> p >> m;
      add();
    }
    cout << sum << endl;
  }
}

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

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

  int number1 = x / 500;       //500円で両替した時の枚数
  int number2 = (x % 500) / 5; //5円で両替した時の枚数

  long long total = number1 * 1000 + number2 * 5;

  cout << total << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int n;
    int a[1000];
    
    scanf("%d\n",&n);
    for(int i=0;i<n;i++){
     scanf("%d ",&a[i]);   
    }
    
    for(int j=n-1;j>=0;j--){
        if(j==n-1) printf("%d",a[j]);
        else printf(" %d",a[j]);
    }
    printf("\n");
    return 0;
}


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

mt19937 rnd;
uniform_real_distribution<> dist01(0.0, 1.0);
double rnd01(){ return dist01(rnd);}

const double TIME_LIMIT = 1950;
double elapsed;
chrono::system_clock::time_point t_start;
void update_time(){
    auto t_now = chrono::system_clock::now();
    elapsed = chrono::duration_cast<chrono::milliseconds>(t_now - t_start).count();
}
bool timeover(){ return (elapsed > TIME_LIMIT);}

const int D = 365, T = 26;
int C[T], S[D][T];
int CS[D+2][T];

set<int> st[T];

int ans[D];
int opt = -1e9;

int calc_score(){
    int last[T];
    for(int i=0; i<T; i++) last[i] = -1;
    int res = 0;
    for(int i=0; i<D; i++){
        res += S[i][ans[i]];
        last[ans[i]] = i;
        for(int j=0; j<T; j++) res -= C[j] * (i-last[j]);
    }
    return res;
}

int calc_diff(int t, int bef, int aft){
    int res = opt + S[t][aft] - S[t][bef];
    {
        auto it = st[bef].lower_bound(t);
        int d1 = *next(it) - t, d2 = t - *prev(it);
        res -= CS[d1+d2][bef] - CS[d1][bef] - CS[d2][bef];
        st[bef].erase(it);
    }
    {
        st[aft].insert(t);
        auto it = st[aft].lower_bound(t);
        int d1 = *next(it) - t, d2 = t - *prev(it);
        res += CS[d1+d2][aft] - CS[d1][aft] - CS[d2][aft];
    }
    return res;
}

void try_update(){
    // pick random & update
    int t = rnd() % D;
    int bef = ans[t], aft = rnd() % T;
    ans[t] = aft;

    // calculate
    int score = calc_diff(t, bef, aft);
    const int T = 100;
    double temp = T * (1 - elapsed/TIME_LIMIT);
    double prob = exp((score - opt) / temp);
    if(rnd01() < prob){
        opt = score;
    }else{
        // rollback
        ans[t] = bef;
        st[aft].erase(t);
        st[bef].insert(t);
    }
}

int main(){
    t_start = chrono::system_clock::now();
    // get input & initialize
    int _; cin >> _;
    for(int j=0; j<T; j++) cin >> C[j];
    for(int i=0; i<D; i++) for(int j=0; j<T; j++) cin >> S[i][j];
    for(int i=0; i<=D+1; i++) for(int j=0; j<T; j++) CS[i][j] = i*(i-1)/2*C[j];

    for(int i=0; i<D; i++) for(int j=0; j<T; j++) if(S[i][ans[i]] < S[i][j]) ans[i] = j;
    opt = calc_score();
    cerr << "before score: " << opt << endl;
    for(int i=0; i<D; i++) st[ans[i]].insert(i);
    for(int j=0; j<T; j++){
        st[j].insert(-1);
        st[j].insert(D);
    }

    // iterate
    int iter = 0;
    while(!timeover()){
        iter++;
        try_update();
        if(iter % 1000 == 0) update_time();
    }

    // output result
    for(int i=0; i<D; i++) cout << ans[i]+1 << endl;


    // output debug
    cerr << "score: " << opt << endl;
    cerr << "iter: " << iter << endl;
    update_time();
    cerr << "elapsed: " << elapsed << endl;
    return 0;
}


Measured memory_bytes: 4552
n,m=map(int, input().split())
s=[[float('inf')]*n for i in range(n)]
d=[list(map(int, input().split())) for i in range(m)]
for a,b,c in d:
    s[a-1][b-1]=c
    s[b-1][a-1]=c
from scipy.sparse.csgraph import floyd_warshall 
cost=floyd_warshall(s)
ans=0
for a,b,c in d:
    if cost[a-1][b-1]!=c:
        ans+=1
print(ans)

Measured memory_bytes: 26512
#include <bits/stdc++.h>
using namespace std;
inline void rd(int &x) {
	char ch; for(;!isdigit(ch=getchar()););
	for(x=ch-'0';isdigit(ch=getchar());)x=x*10+ch-'0';
}
typedef long long LL;
const int MAXN = 300005;
int N, n, a[MAXN], cnt[MAXN];
LL sum[MAXN];
int ans[MAXN];

inline bool chk(int k, int x) {
	int pos = upper_bound(a + 1, a + n + 1, x) - a;
	return sum[pos-1] + 1ll*(n-pos+1)*x >= 1ll*k*x;
}

int main() {
	rd(N);
	for(int i = 1, x; i <= N; ++i) rd(x), ++cnt[x];
	for(int i = 1; i <= 300000; ++i) if(cnt[i]) a[++n] = cnt[i];
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; ++i) sum[i] = sum[i-1] + a[i];
	int now = 0;
	for(int k = n; k >= 1; --k) {
		while(now < N && chk(k, now+1)) ++now;
		ans[k] = now;
	}
	for(int i = 1; i <= N; ++i) printf("%d\n", ans[i]);
}

Measured memory_bytes: 6528