akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n - 1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

map<char,int> symb={{'S', 0},{'H', 1},{'C', 2},{'D', 3}};
string symb_s ="SHCD";
bool cards[4][13] = {false};

void solve()
{
	int n; cin >> n;
	rep(i, n)
	{
		char c;int x;
		cin >> c >> x;
		x--;
		cards[symb[c]][x] = true;
	}
	rep(i,4)rep(j,13)
	{
		if(!cards[i][j])cout << symb_s[i]<<" "<< j+1 << endl;
	}
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}



Measured memory_bytes: 3228
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
 
#pragma warning(disable : 4996)
 
#define INF (1 << 29)
 
using namespace std;
 
int main()
{
    int n, sum;
     
    while (true)
    {
        scanf("%d", &n); sum = 0;
 
        if (n == 0) break;
 
        vector<int> p(n - 1);
        vector<int> d(n - 1);
 
        vector<vector<pair<int, int> > > T(n);
 
        for (int i = 0; i < n - 1; i++) { scanf("%d", &p[i]); }
        for (int i = 0; i < n - 1; i++) { scanf("%d", &d[i]); sum += d[i]; }
 
        for (int i = 0; i < n - 1; i++)
        {
            T[i + 1].push_back(make_pair(p[i] - 1, d[i]));
            T[p[i] - 1].push_back(make_pair(i + 1, d[i]));
        }
 
        vector<vector<int> > dists(n, vector<int>(n, INF));
 
        for (int i = 0; i < n; i++)
        {
            priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > que;
 
            que.push(make_pair(0, i)); dists[i][i] = 0;
 
            while (!que.empty())
            {
                pair<int, int> p1 = que.top(); que.pop();
 
                int node = p1.second;
                int dist = p1.first;
 
                for (int j = 0; j < T[node].size(); j++)
                {
                    if (dists[i][T[node][j].first] == INF)
                    {
                        dists[i][T[node][j].first] = dist + T[node][j].second;
 
                        que.push(make_pair(dists[i][T[node][j].first], T[node][j].first));
                    }
                }
            }
        }
 
        vector<int> nodes(n);
 
        for (int i = 0; i < n; i++)
        {
            nodes[i] = T[i].size();
        }
        
        int sum2 = 0;
        
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < nodes[i]; j++)
            {
                if(nodes[i] >= 2 && nodes[T[i][j].first] >= 2)
                {
                    sum2 += T[i][j].second;
                }
            }
        }
 
        int ret = 0;
 
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (nodes[i] > 1 && nodes[j] > 1)
                {
                    ret = max(ret, dists[i][j]);
                }
            }
        }

        printf("%d\n", sum + sum2 - ret);
    }
 
    return 0;
}

Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<string>> ve_ves;
#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 rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) max_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)

int H, W,N;
int field[305][305];
int field2[305][305];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};


void dfs(int x, int y, int h) {
    field[x][y] = 0;
    rep(i,4){
        int nx = x + dx[i];
        int ny = y + dy[i];
        if(0 <= nx and nx < H and 0 <= ny and ny < W and field[nx][ny] > h) dfs(nx, ny, h);
    }
    return ;
}

int main() {
	int n; cin >> n;
	for (int i = 1; i <= n; i++) {
		int x = i;
		if (x % 3 == 0) {
			cout << " " << i;
		}
		else {
			while (x) {
				if (x % 10 == 3) {
					cout << " " << i;
					break;
				}
				x /= 10;
			}
		}
	}
	cout << endl;
}


Measured memory_bytes: 3036
n,a,b,c,d=map(int,input().split())
s=input()
if c<b:
    if not '##' in s[a-1:c] and not '##' in s[b-1:d]:
        print('Yes')
    else:
        print('No')
elif b<c<d:
    if not '##' in s[a-1:d]:
        print('Yes')
    else:
        print('No')
else:
    if '##' in s[a-1:c]:
        print('No')
    else:
        if '...' in s[b-2:d+1]:
            print('Yes')
        else:
            print('No')


Measured memory_bytes: 40560
// C - Write and Erase
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	map<int,int> F;
	rp(i, 0, N){
		int a; cin>>a;
		F[a]++;
	}
	int ans = 0;
	for(auto f:F) ans += f.second%2? 1:0;
	cout<< ans <<endl;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define int long long int
set<string> se;
int32_t main(){
	int n;cin>>n;
	string s,tmp;cin>>s;se.insert(s);
	for(int i=1;i<n;i++){
		cin>>tmp;if(se.count(tmp)||tmp[0]!=s[s.length()-1]){
			cout<<"No";
			return 0;
		}
		se.insert(tmp);
		s = tmp;
	}
	cout<<"Yes";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(){
int i = 0;
int data = 0;
int V = 0;
int j = 0;
int *insert;
int k;

scanf("%d",&data);
insert = (int *)malloc(sizeof(int)*data);

for(i = 0 ; i < data ; i++){
scanf("%d",&insert[i]);
}
for(i = 0; i < data ; i++){
V = insert[i];
j = i - 1;

while(j >= 0 && insert[j] > V){
  insert[j + 1] = insert[j];
  j--;
  insert[j + 1] = V;

}
for(k=0; k<data; k++){
 if(k!=data-1)printf("%d ",insert[k]);
 else printf("%d",insert[k]);
}
printf("\n");
}
return 0;
}


Measured memory_bytes: 2084
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}



int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	// freopen("settling.in", "r", stdin);
	// freopen("settling.out", "w", stdout);

	string s;
	cin >> s;

	if(s == "ABC")
		cout << "ARC" << endl;
	else
		cout << "ABC" << endl;

	return 0;
}


Measured memory_bytes: 3580
import java.util.Scanner;
     
     
    public class Main {
        public static void main(String[] args) {
     
            Scanner sc = new Scanner(System.in);
            String n = sc.next();
            if (n.contains("7")){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }
    }

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

int main() {
    int64_t n, m;
    cin >> n >> m;
    priority_queue<int64_t> pq;
    for (size_t i = 0; i < n; i++) {
        int64_t a;
        cin >> a;
        pq.push(a);
    }
    for (size_t i = 0; i < m; i++) {
        int64_t a = pq.top(); pq.pop();
        a /= 2;
        pq.push(a);
    }
    int64_t ans = 0;
    while (!pq.empty()) {
        int64_t a = pq.top(); pq.pop();
        ans += a;
    }
    
    cout << ans << endl;
}


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

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

    float ans = n / 1.08;
    int ref = ans;

    if (ans == ref){ // 1.08で割り切れたとき
        cout << ref << endl;
        return 0;
    }
    else{ //　課税で切り捨てがある場合
        float tmp = (ref + 1) * 1.08;
        int tmp2 = tmp;
        if (tmp2 == n){
            cout << ref + 1 << endl;
            return 0;
        }
        else{
            cout <<":(" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
A,B,C = [ list(input()) for _ in range(3) ]
user = A
card = 0
while(True):
    if len(user) == 0:
        print(card.upper())
        break

    card = user.pop(0)
    if card == "a":
        user = A
    elif card == "b":
        user = B
    else:
        user = C

Measured memory_bytes: 3060
# GRL_1_C : ALL Pairs Shortest Path
import sys

debug = False
v, e = map(int, sys.stdin.readline().strip().split())

g = [[float('inf')] * v for _ in range(v)]
for _ in range(e):
    s, t, d = map(int, sys.stdin.readline().strip().split())
    if debug: print('s : {}  t : {}'.format(s, t))
    g[s][t] = d

for i in range(v):
    g[i][i] = 0

for k in range(v):
    for i in range(v):
        for j in range(v):
            g[i][j] = min(g[i][j], g[i][k] + g[k][j])

negative = False
for i in range(v):
    if g[i][i] < 0:
        negative = True
        break

if not negative:
    for i in range(v):
        ans = ' '.join(list(map(str, g[i])))
        ans = ans.replace('inf', 'INF')
        print(ans)
else:
    print('NEGATIVE CYCLE')


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

int N;
long long ans, x;

int main() {

	scanf("%d", &N);
	while (N--) {
		scanf("%lld", &x);

		ans ^= x;
	}

	if (ans & 1)
		printf("NO\n");
	else
		printf("YES\n");

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){ 
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    long long r, d, x;
    cin >> r >> d >> x;
    long long a[11];
    a[0] = x;
    for(int i = 1; i < 11; i++) {
        a[i] = r * a[i-1] - d;
    }
    for(int i = 1; i < 11; i++)
        cout << a[i] << '\n';

}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 345;
int a[MAXN][MAXN];
bool gone[MAXN];
int cnt[MAXN];

bool check(int x, int N, int M) {
     memset(gone, 0, sizeof(gone));
     vector<deque<int>> cand;
     for (int i = 0; i < N; i++) {
         deque<int> tmp;
         for (int j = 0; j < M; j++) {
             tmp.push_back(a[i][j]);
         }
         cand.push_back(tmp);
     }
     for (int i = 0; i < M; i++) {
         memset(cnt, 0, sizeof(cnt));
         for (int j = 0; j < N; j++) {
             while (gone[cand[j].front()]) {
                   cand[j].pop_front();
             }
             cnt[cand[j].front()]++;
         }
         bool upd = false;
         for (int i = 1; i <= M; i++) {
             if (gone[i]) continue;
             if (cnt[i] > x) {
                gone[i] = 1;
                upd = true;
                break;
             }
         }
         if (!upd) return true;
     }
     return false;
}

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    int l = 1, r = N + 1;
    while (l < r) {
          int mid = (l + r) / 2;
          if (check(mid, N, M)) r = mid;
          else l = mid + 1;
    }
    printf("%d\n", l);
    return 0;
}


Measured memory_bytes: 1536
import java.util.Scanner;
import java.lang.Math;
import java.math.BigDecimal;

public class Main{
	
	public static void main(String[] args){

		Scanner s = new Scanner(System.in);
		s.useDelimiter("\\s*,\\s*|\\s");
		
		int w = s.nextInt();
		int n = s.nextInt();
				
		int[] x = new int[w];
		
		for(int i = 0; i < w; i++){
			x[i] = i+1;
		}
		
		for(int i = 0; i < n; i++){
			
			int a = s.nextInt();
			int b = s.nextInt();
			
			int tmp = x[a-1];
			x[a-1] = x[b-1];
			x[b-1] = tmp;
			
		}
		
		for(int i = 0; i < w; i++){
			System.out.println(x[i]);
		}
		
	}
	
}


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

using namespace std;

int main()
{
    int N;
    cin >> N;
    
    int p_t = 0, p_h = 0;
     
    for(int i = 0; i < N; ++i)
    {
        string t, h;
        
        cin >> t >> h;
        
        if(t > h)
        { p_t += 3; }
        else if(t < h)
        { p_h += 3; }
        else 
        { p_t += 1; p_h += 1; }
    
    }
    
    cout << p_t << " " << p_h << endl;
    
    return 0;
}


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

int main(){
  double N,D;
  double x,y;
  int cnt=0;
  cin >> N >> D;
  
  for(int i=0; i<N; i++){
      cin >> x >> y;
    if((x*x)+(y*y)<=D*D){
    cnt++;
    }      
  }
  cout << cnt << endl;
  
return 0;
}


Measured memory_bytes: 3776
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

//--- 変数宣言 ---//
int d, g;
vector<int> p(10), c(10);
const int INF = 10000;
int score;  //いまの得点
int num;    //解いた問題数
int rest;   //部分的に解く問題の問題番号
int need;   //残り解く問題数
int ans = INF;  //解く問題数の最小値(INFで初期化)
vector<int> a(10);  //a[i]が0または1の配列(0＆1列)

//ansを計算する関数
void calc() {   
    score = 0;  
    num = 0;    
    rest = -1;  

    //a[i]が0か1か調べる
    rep(i, d) {
    //a[i]が1だったら
        if(a[i]) {
            //i番目の問題をすべて解く。コンプリボーナスも得点に加える
            score += ((i+1)*100*p[i] + c[i]);
            //解いた問題数をp[i]増やす
            num += p[i];
        }
        //a[i]が0だったら
        else {
            /* i番目の問題を部分的に解く候補にする。ループが終わるときには、
                aの0のものの中で最も得点の高い問題番号がrestに入る。*/
            rest = i;
        }
    }

    //aの1の問題をすべて解いてもスコアがgに届かない場合
    if(g > score) {
        //100*(rest+1)は、rest番目の問題を1問解くごとに得られる点数
        //p[rest]はrest番目の問題数の最大値
        /* (g-score-1)/(100*(rest+1)) + 1で、残りg-score点必要で
            1問ごとに100*(rest+1)点入るときに解く必要のある最低問題数
            が求まる。これをp[rest]と比べればよい */
        need = min( (g-score-1)/(100*(rest+1)) + 1, p[rest] );
        //部分的に解く問題の合計点数を得点に加える
        score += (rest+1)*100*need;
        //解いた問題数をneed増やす
        num += need;
    }

    //スコアがgを超えたら
    if(score >= g) {
        //numの最小値がansに入る
        ans = min(ans, num);
    }
}

//全ての0＆1列を列挙してcalcでansを計算するDFS
void dfs(int depth) {
    if(depth == d) {  //深さがdに達したら
        calc(); //ansを計算して
        return; //一つ上の深さに戻る
    }

    //a[depth]に0を書いて1つ下の深さに行く
    a[depth] = 0;  dfs(depth+1);

    //a[depth]に1を書いて1つ下の深さに行く
    a[depth] = 1;  dfs(depth+1);
}

int main() {
    cin >> d >> g;
    rep(i, d) {
        cin >> p[i] >> c[i];
    }

    dfs(0); //深さ0からスタート

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

Measured memory_bytes: 256
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
//10の1/2乗（ルート）pow(10, 0.5)
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  ll n;
  cin >> n;
  vector<ll>a(n);
  rep(i,n) cin >>a.at(i);
  ll q;
  cin >> q;
  vector<ll>b(q);
  vector<ll>c(q);
  rep(i,q) cin >> b.at(i) >> c.at(i);
  //初期入力完了
  //bakettohou
  vector<ll>bkt(100010);
  ull sum = 0;
  rep(i,n) sum += a.at(i);
  rep(i,n) bkt.at(a.at(i))++;
//  cout << sum << endl;
  rep(i,q){
    sum += bkt.at(b.at(i)) * c.at(i);
    sum -= bkt.at(b.at(i)) * b.at(i);
    bkt.at(c.at(i)) += bkt.at(b.at(i));
    bkt.at(b.at(i)) = 0;
    cout << sum << endl;
  }
}

Measured memory_bytes: 6416
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;

typedef long long ll;
ll MOD = 1e9+7;

ll dp[100001];
ll h[100000];
int main()
{
	int n;
	int ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>h[i];
	fill(dp,dp+100001,1e14-1);
	dp[0]=0;
	dp[1]=0;
	dp[2]=abs(h[1]-h[0]);
	for(int i=3;i<n+1;i++)
	{
		dp[i]=min(dp[i-2]+abs(h[i-1]-h[i-3]),dp[i-1]+abs(h[i-1]-h[i-2]));
	}
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
 int main()
 {
     int a,b,c;
     scanf("%d %d %d",&a,&b,&c);
     if(a<b){
        if(b<c){
            printf("Yes\n");
        }
        else{
            printf("No\n");
        }
     }
     else{
        printf("No\n");
     }
 }



Measured memory_bytes: 2044
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    int ab = a + b;
    
    if (ab >= 10) {
      System.out.println("error");
    } else {
      System.out.println(ab);
    }
  }
}

Measured memory_bytes: 21716
#include<stdio.h>
int main(){
  int a,b,ans;
  char m;
  while(1){
    scanf("%d %c %d", &a, &m, &b);
    if(m == '+'){
      ans = a + b;
    }else if(m == '-'){
      ans = a - b;
    }else if(m == '*'){
      ans = a * b;
    }else if(m == '/'){
      ans = a / b;
    }else if(m == '?'){
      return 0;
    }
    printf("%d\n",ans);
  }
  return 0;
}



Measured memory_bytes: 2060
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, m, q, res, a[MAXN], b[MAXN], c[MAXN], d[MAXN], f[MAXN];

void dq(int u, int x) {
    if (u > n) {
        int now = 0;
        FOR(i,1,q)
            if (f[b[i]] - f[a[i]] == c[i]) now += d[i];
        res = max(res, now);
        return;
    }
    FOR(i,x,m) {
        f[u] = i;
        dq(u+1, i);
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m >> q;
    FOR(i,1,q) cin >> a[i] >> b[i] >> c[i] >> d[i];
    dq(1, 1);
    cout << res;
    return 0;
}


Measured memory_bytes: 3636
n=int(input())
ps=list(map(float,input().split()))
lim=(n+1)//2
dp=[0]*(lim+1)
dp[0]=1
for pi,p in enumerate(ps):
    if pi+1>=lim:
        st=lim-1
        dp[lim]=dp[lim]+dp[lim-1]*p
    else:
        st=pi+1
    for i in range(st,0,-1):
        dp[i]=dp[i-1]*p+dp[i]*(1-p)
    dp[0]=dp[0]*(1-p)
print(dp[-1])

Measured memory_bytes: 3316
#include <iostream>

using namespace std;

int main()
{
    int n;
    int step = 0, maxStep = 0, buf = 0;
    int h;

    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> h;

        if(buf >= h) ++step;
        else step = 0;

        maxStep = max(maxStep, step);
        buf = h;
    }

    cout << maxStep << '\n';
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100
int main(void){
  int i,j,v,n,m,x,t;
  int a[N];
  scanf("%d",&n);
  m=0;
  while(m<n){
    scanf("%d",&a[m]);
    m++;
  }
  i=1;
  while(i<n){
    for(v=0;v<n-1;v++){
      printf("%d ",a[v]);
    }
    printf("%d\n",a[n-1]);
    t=a[i];
    j=i;
    i++;
    while(j>0&&a[j-1]>t){
      a[j]=a[j-1];
      j--;
    }
    a[j]=t;
  }
  x=0;
  while(x<n-1){
    printf("%d ",a[x]);
    x++;
  }
  printf("%d\n",a[n-1]);
  return 0;
}



Measured memory_bytes: 2072
import sys
input = sys.stdin.readline

def gcd(a, b):
    if b != 0:
        return gcd(b, a%b)
    else:
        return a

a, b, c, d = map(int, input().split())
lcd = c*d//gcd(c, d)
a -= 1
ans = (b - b//c - b//d + b//lcd) - (a - a//c - a//d + a//lcd)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <stdio.h>
#define ff(i,x,y)for(int i=x;i<y+1;i++)
#define fs(i,x,y)for(int i=x;i>y-1;i--)
#define all(x) x.begin(),x.end()
#define Ins(x) inserter(x,x.begin())
using namespace std;
int n,m,sum,c[10010],res[110][110];
int main()
{
    scanf("%d%d",&n,&m);
    scanf("%d",&sum);
    ff(i,1,sum)
    scanf("%d",&c[i]);
    int row=1,col=1,d=1;
    ff(i,1,sum)
    {
        int now=c[i];
        while(now--)
        {
            res[row][col]=i;
            col+=d;
            if(col==m+1)
            {
                col=m;
                d=-1;
                row++;
            }
            else if(col==0)
            {
                col=1;
                d=1;
                row++;
            }
        }
    }
    ff(i,1,n)
    {
        printf("%d",res[i][1]);
        ff(j,2,m)
        printf(" %d",res[i][j]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 384
from collections import deque

S=input()



d=deque()
for i in range(len(S)):
    if S[i]!="B":
        d.append(S[i])
    elif len(d)!=0 and S[i]=="B":
        tmp=d.pop()

    
Z=list(d)
Z=[str(a) for a in Z]
Z="".join(Z)
print(Z)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
using P = pair<int, int>;
#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

int in() {int x; cin>>x; return x;}
string stin() {string s; cin>>s; return s;}
/***** MAIN *****/
signed main() {
  int n = in();
  vector<P> v(n);
  REP(i,n) {
    int needed_time = in();
    int limit = in();
    v[i] = P(limit, needed_time);
  }
  SORT(v);
  int current_time = 0;
  REP(i,n) {
    current_time += v[i].second;
    if(current_time > v[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes";
  cout << "\n";
  return 0;
}
/***** MAIN *****/


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


int main()
{
    ll N;
    cin >> N;
    double sq_N=sqrt(N);
    long i;
    long k=1;
    for(i=2;i<=sq_N;i++){
        if(N%i==0&&k<i){
            k=i;
        }
    }
    long j=N/k;
    cout << k-1+j-1 << endl;
}

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

int main(){
	string s;
	cin>>s;
	if(s=="Sunny"){
		cout<<"Cloudy"<<endl;
	}else if(s=="Cloudy"){
		cout<<"Rainy"<<endl;
	}else{
		cout<<"Sunny"<<endl;
	}
	return 0;
}

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

#define F first
#define S second
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(int i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
typedef long long ll; typedef pair <int, int> ii; typedef vector <int> vi; const int inf = 1e9 + 7;
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cout << str << " : " << t << endl;}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cout << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cout << "["; for (T i = a; i != b; ++i) {if (i != a) cout << ", "; cout << *i;} cout << "]";cout<<endl;}

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

	ll n; cin >> n; vector<ll> a(n);
	FOR (i, 0, n - 1) cin >> a[i];


	auto f = [&] (ll x) {
		ll alpha = n - 1 - x;
		ll req = 0;
		FOR (i, 0, n - 1) if (a[i] > alpha) req += (a[i] - alpha + n) / (n + 1);
		return req <= x;
	};

	ll st = 0, en = 1e18;

	// FOR (i, 0, 200) pr(i, f(i));

	while (st < en) {
		ll mid = (st + en) >> 1;
		bool can = false;
		FOR (i, 0, n) can |= f(mid + i);
		if (can) en = mid;
		else st = mid + 1;
	}

	FOR (i, 0, n) if (f(st + i)) {
		cout << st + i;
		return 0;
	}

	return 0;
}


Measured memory_bytes: 256
n,m = gets.chomp.split(' ').map(&:to_i)
arr = gets.chomp.split(' ').map(&:to_i).sort.reverse
if m - n <= 0
  puts 0
  exit
end
ans = 0
intervals = []
i = 1
while i < arr.size
  intervals << arr[i-1] - arr[i]
  i += 1
end
intervals.sort!
puts intervals[0..(m-n-1)].sum

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 2e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n, p[maxn], q[maxn];
ll ans;
set<int> st;

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

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> p[i];
		q[p[i]] = i;
	}
	st.insert(-1);
	st.insert(n);

	for (int i = 1; i <= n; i++)
	{
		auto it = st.upper_bound(q[i]);
		int r = *it;
		it--;
		int l = *it;
		
		ans += (ll)i * (r - q[i]) * (q[i] - l);
		st.insert(q[i]);
	}
	cout << ans << endl;
}



Measured memory_bytes: 11264
from operator import itemgetter, attrgetter
n = int(input())
s = [input().split() for i in range(n)]
ss = []
ll = []
l = []
for i in range(0, n):
  l.insert(i, [s[i][0], int(s[i][1]), i+1])
ss = sorted(l, key=itemgetter(1), reverse=True)
ll = sorted(ss, key=itemgetter(0))
for i in ll:
  print(i[2])

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    T = inputList()
    
    M = inputInt()
    px = []
    for i in range(M):
        p,x = inputMap()
        px.append((p,x))
        
    ans = []
    for i,val in enumerate(px):
        tmp = 0
        p,x = val
        for j,vol in enumerate(T):
            if j == p-1:
                tmp += x
            else:
                tmp += vol
        ans.append(tmp)
        
    for i in ans:
        print(i)
    
if __name__ == "__main__":
	main()


Measured memory_bytes: 40304
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int A,B,K;
vi d;

signed main(){

    in(A,B,K);
    REP(i,1,min(A,B)+1){
        if(A%i==0&&B%i==0) d.pb(i);
    }
    reverse(all(d));
    out(d[K-1]);

    return 0;
}


Measured memory_bytes: 256
x, y, z, k = map(int, input().split())
m = []
for _ in range(3):
    m.append(sorted(list(map(int, input().split())), reverse=True))

def sorted_sum(list_a, list_b, limit):
    s = []
    for x in list_a:
        for y in list_b:
            s.append(x + y)
    return sorted(s, reverse=True)[0:limit]


def consume_diff(s, a_val, list_b, b_index):
    diff = a_val - list_b[b_index]
    for i in range(b_index + 1, len(list_b)):
        if list_b[b_index] - list_b[i] > diff:
            break
        s.append(a_val + list_b[i])



ans = sorted_sum(sorted_sum(m[0], m[1], k), m[2], k)
for i in range(min([k, len(ans)])):
    print(ans[i])

Measured memory_bytes: 186456
a = []
for _ in range(3):
    ex = map(int, input().split())
    a.extend(ex)
n = int(input())
b = [int(input()) for _ in range(n)]

for bi in b:
    if bi in a:
        a[a.index(bi)] = 0

bingo = [
    a[0] + a[1] + a[2],
    a[3] + a[4] + a[5],
    a[6] + a[7] + a[8],
    a[0] + a[3] + a[6],
    a[1] + a[4] + a[7],
    a[2] + a[5] + a[8],
    a[0] + a[4] + a[8],
    a[2] + a[4] + a[6],
]

if min(bingo) == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;

int DP[100005];
int DP1[100005];

int main() {
    for(int i=2;i<=100000;++i){
        DP[i] = 1;
    }
    for(int i=2;i<=100000;++i){
        if(DP[i] == 0) continue;
        for(int j=2;i*j<=100000;++j){
            DP[i*j] = 0;
        }
    }
    for(int i=2;i<=100000;++i){
        if(i%2==0) continue;
        if((DP[i]==1) & (DP[(i+1)/2]==1)) DP1[i] = 1;
    }

    for(int i=2;i<=100000;++i){
        DP1[i] += DP1[i-1];
    }

    int Q;
    cin>>Q;
    int ans[Q];
    int l, r;
    for(int i=0;i<Q;++i){
        cin>>l>>r;
        ans[i] = DP1[r] - DP1[l-1];
    }
    for(int i=0;i<Q;++i){
        cout<<ans[i]<<endl;
    }
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> par;
int s[511][511],n,m,d;
vector<par>g;
set<par>st;
void dfs(int x,int y,int v){
	if(st.count(par(x,y)))return ;
	st.insert(par(x,y));
	bool flag=0;
	for(int i=0;i<g.size();++i){
		int a=x+g[i].first,b=g[i].second+y;
		if(a>=1&&a<=n&&b>=1&&b<=m)s[a][b]=v,flag=1;//printf("[%d,%d]",a,b);
	}
	if(!flag)return ;
	dfs(x+d,y+d,v^2),dfs(x-d,y-d,v^2);
	dfs(x+d,y-d,v^1),dfs(x-d,y+d,v^1);
}
int main(){
	scanf("%d%d%d",&n,&m,&d);
	if(d&1){
		for(int i=0;i<n;++i,puts(""))for(int j=0;j<m;++j)
			printf("%c",(i+j)&1?'R':'G');
		return 0;
	}  else {
		for(int i=0;i<d;++i)g.push_back(par(i,0));
		for(int i=1;i<=d/2;++i)for(int j=0;j<d-i*2;++j)
			g.push_back(par(i+j,i)),g.push_back(par(i+j,-i));
		d/=2;
		dfs(1,1,0);
		for(int i=1;i<=n;++i,puts(""))
			for(int j=1;j<=m;++j)
				switch(s[i][j]){
					case 0:putchar('R');break;
					case 1:putchar('G');break;
					case 2:putchar('B');break;
					case 3:putchar('Y');break;
				}	
	}
}

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

int main(){
    
    int i, n, t, t1=2000, t2=0;
    
    cin >> n;
    
    for(i=0;i<n;i++){
        cin >> t;
        if(t<t1){
            t1=t;
        }
        if(t2<t){
            t2=t;
        }
    }
    cout << (t2-t1+1)/2 << endl;
    
}


Measured memory_bytes: 3116
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N, M;
    cin >> N >> M;
    if (N >= M) {
        cout << 0 << endl;
        return 0;
    }

    vector<int> X(M);
    vector<int> D(M - 1);
    rep(i, M) cin >> X[i];
    sort(begin(X), end(X));
    rep(i, M - 1) {
        D[i] = X[i+1] - X[i];
    }
    sort(begin(D), end(D), greater<int>());
    int sum = 0;
    for (int i = 0; i < N - 1; i++) {
        sum += *next(begin(D), i);
    }
    cout << X[X.size() - 1] - X[0] - sum << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>

typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;

int N, K, L;

void init(int a[]) {
    REP(i, N + 1) a[i] = i;
}

int root(int a[], int x) {
    if (a[x] == x) return x;
    else           return a[x] = root(a, a[x]);
}

void unite(int a[], int x, int y) {
    x = root(a, x);
    y = root(a, y);
    if (x != y) a[x] = y;
}

int main() {
    int p, q;
    int road[200001], train[200001];
    cin >> N >> K >> L;
    init(road), init(train);

    REP(i, K) {
        cin >> p >> q;
        unite(road, p, q);
    }
    REP(i, L) {
        cin >> p >> q;
        unite(train, p, q);
    }

    map<pair<int, int>, int> link;
    FOR(i, 1, N + 1) link[{root(road, i), root(train, i)}]++;
    FOR(i, 1, N + 1) cout << link[{root(road, i), root(train, i)}] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 13568
n = int(input())
s = input()

alpha2num = lambda c: ord(c) - ord('A') + 1


num2alpha = lambda c: chr(c+64)

num2alpha(3) #==> C 

ans = []

for i in range(len(s)):
    #print(alpha2num(s[i])+n,(alpha2num(s[i])+n)%26)
    if (alpha2num(s[i])+n) % 26 == 0:
        ans.append(num2alpha(26))
        continue
    ans.append(num2alpha((alpha2num(s[i])+n)%26))
    
print(*ans,sep='')

Measured memory_bytes: 4724
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
   /* #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        

fast();
//ll t;cin>>t;while(t--)
{
   ll n;
   cin>>n;
   ll a[n],b[n];
   for(int i=0;i<n;i++)
    {
      cin>>a[i];
      b[i]=a[i];
    }
    sort(b,b+n,greater<ll>());
    ll f=(n)/2-1;
    ll s=f+1;
    ll x=b[f],y=b[s];
    for(int i=0;i<n;i++)
    {
      if(a[i]<x)
        cout<<x<<endl;
      else
        cout<<y<<endl;
    }


}
return 0;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<min(b,c)<<" ";
	if(b+c<a){
		cout<<0<<endl;
	}
	else 
		cout<<b+c-a<<endl;
		
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int K=0;
  cin>>N;
  vector<int>vec(N);
  for(int X=0;X<N;X++){
    cin>>vec.at(X);
    if(X%2==0&&vec.at(X)%2==1){
      K++;
    }
  }
  cout<<K<<endl;
}

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

using namespace std;
#define local
#ifdef local

template<class T>
void _E(T x) { cerr << x; }

void _E(double x) { cerr << fixed << setprecision(6) << x; }

void _E(string s) { cerr << "\"" << s << "\""; }

template<class A, class B>
void _E(pair<A, B> x) {
    cerr << '(';
    _E(x.first);
    cerr << ", ";
    _E(x.second);
    cerr << ")";
}

template<class T>
void _E(vector<T> x) {
    cerr << "[";
    for (auto it = x.begin(); it != x.end(); ++it) {
        if (it != x.begin()) cerr << ", ";
        _E(*it);
    }
    cerr << "]";
}

void ERR() {}

template<class A, class... B>
void ERR(A x, B... y) {
    _E(x);
    cerr << (sizeof...(y) ? ", " : " ");
    ERR(y...);
}

#define debug(x...) do { cerr << "{ "#x" } -> { "; ERR(x); cerr << "}" << endl; } while(false)
#else
#define debug(...) 114514.1919810
#endif
#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f3f3f
#define ll  long long
#define db long double
#define eps 1e-3
#define bin(x) cerr << bitset<10>(x) << endl
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<ll, ll>
#define pdd pair<db, db>
#define endl "\n"
const ll mod = 1e9 + 7;
const ll maxn = 1e6 + 10;
const db pi = acos(-1.0);

ll qpow(ll a, ll b) {
    ll ret = 1;
    for (; b; a = a * a % mod, b >>= 1) {
        if (b & 1) {
            ret = ret * a % mod;
        }
    }
    return ret;
}

vector<ll> f(maxn), invf(maxn);

ll inv(ll a) {
    return qpow(a, mod - 2);
}

void prework() {
    f[0] = 1;
    _rep(i, 1, maxn - 1) {
        f[i] = f[i - 1] * i % mod;
    }
    invf[maxn - 1] = qpow(f[maxn - 1], mod - 2);
    for (ll i = maxn - 2; i >= 0; i--) {
        invf[i] = invf[i + 1] * (i + 1) % mod;
    }
}

ll C(ll n, ll m) {
    if (n > m || m < 0)return 0;
    if (n == 0 || m == n) return 1;
    ll res = (f[m] * invf[m - n] % mod * invf[n]) % mod;
    return res;
}

ll mx[4], mn[4];

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

    int n;
    cin >> n;
    _for(i, 0, 4) {
        mx[i] = -1e18;
        mn[i] = 1e18;
    }
    _rep(i, 1, n) {
        ll x, y;
        cin >> x >> y;
        mx[0] = max(mx[0], x + y);
        mx[1] = max(mx[1], x - y);
        mx[2] = max(mx[2], y - x);
        mx[3] = max(mx[3], -y - x);
        mn[0] = min(mn[0], x + y);
        mn[1] = min(mn[1], x - y);
        mn[2] = min(mn[2], y - x);
        mn[3] = min(mn[3], -y - x);
    }
    ll res = 0;
    _for(i, 0, 4){
        res = max(mx[i] - mn[i], res);
    }

    cout << res << endl;
}

Measured memory_bytes: 18688
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int i,j,dice,dice1[]=new int[6],dice2[]=new int[6],f=0,swap;
        for(i=0;i<6;i++) {
        	dice1[i]=scan.nextInt();
        }
        for(i=0;i<6;i++) {
        	dice2[i]=scan.nextInt();
        }
        for(i=0;i<=6;i++) {
        	if(dice1[0]==dice2[0] && dice1[5]==dice2[5]) {
    			for(j=0;j<4;j++) {
    				if(dice1[1]==dice2[1] && dice1[2]==dice2[2] && dice1[3]==dice2[3] && dice1[4]==dice2[4]) {
    					f=1;
    					break;
    				}
    				swap=dice2[1];
            		dice2[1]=dice2[2];
            		dice2[2]=dice2[4];
            		dice2[4]=dice2[3];
            		dice2[3]=swap;
    			}
    		}
        	if(i%2==0) {
        		swap=dice2[0];
        		dice2[0]=dice2[1];
        		dice2[1]=dice2[5];
        		dice2[5]=dice2[4];
        		dice2[4]=swap;
        	}

        	else {
        		swap=dice2[0];
        		dice2[0]=dice2[3];
        		dice2[3]=dice2[5];
        		dice2[5]=dice2[2];
        		dice2[2]=swap;
        	}
        	if(f==1) {
        		break;
        	}
        }
        if(f==1) {
        	System.out.println("Yes");
        }
        else {
        	System.out.println("No");
        }
    }
}


Measured memory_bytes: 26272
from scipy.sparse.csgraph import floyd_warshall


N, M, L = map(int, input().split())
graph = [[0] * N for _ in range(N)]
for _ in range(M):
    s, t, w = map(int, input().split())
    graph[s-1][t-1] = graph[t-1][s-1] = w
dist = floyd_warshall(graph, directed=False)
graph = [[0] * N for _ in range(N)]
for i in range(N):
    for j in range(i+1, N):
        if dist[i][j] <= L:
            graph[i][j] = graph[i][j] = 1
dist = floyd_warshall(graph, directed=False)

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    ans = dist[s-1][t-1]
    if ans == float("inf"):
        print(-1)
    else:
        print(int(ans - 1))


Measured memory_bytes: 18652
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define REP(i,n) for (int i = 0; i < n; ++ i)
#define FOR(i,a,b) for (int i = a; i <= b; ++ i)
#define FORD(i,b,a) for (int i = b; i >= a; -- i)
#define debug(x) cerr << #x << ": " << x << "\n"
#define task "BULMART"
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef vector<int> vi;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen(task".inp", "r", stdin);
    //freopen(task".out", "w", stdout);
    int n, k;
    cin >> n >> k;
    cout << (n - 1 + k - 2) / (k - 1);
}



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

int C[400];
int S[400][30];
int last[30] = {};
int main()
{
	int d;
	cin >> d;

	for (int i = 1; i <= 26; ++i)
		scanf("%d", &C[i]);
	for (int i = 1; i <= d; ++i)
	{
		for (int j = 1; j <= 26; ++j)
			scanf("%d", &S[i][j]);
	}

	int t;
	int v = 0;
	for (int i = 1; i <= d; ++i)
	{
		cin >> t;

		last[t] = i;
		v += S[i][t];

		for (int j = 1; j <= 26; ++j)
			v -= C[j] * (i - last[j]);
		cout << v << '\n';
	}
	return 0;
}

Measured memory_bytes: 3708
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define pb(b) push_back(b) 
#define all(a) a.begin(),a.end()
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
/* 
UnionFind：素集合系管理の構造体(union by size)
isSame(x, y): x と y が同じ集合にいるか。 計算量はならし O(α(n))
unite(x, y): x と y を同じ集合にする。計算量はならし O(α(n))
treeSize(x): x を含む集合の要素数。
*/
struct UnionFind{
 vector<int>size,parents;
 UnionFind(){}
 UnionFind(int n){//make n trees.
  size.resize(n,0);
  parents.resize(n,0);
  for(int i=0;i<n;i++)makeTree(i);
 }
 void makeTree(int x){
   parents[x]=x;//the parent of x is x
   size[x]=1;
  }
 bool isSame(int x,int y){return findRoot(x)==findRoot(y);}
 bool unite(int x,int y){
  x = findRoot(x);
  y = findRoot(y);
  if(x==y)return false;
  if(size[x]>size[y]){
   parents[y]=x;
   size[x]+=size[y];
  } 
  else{
   parents[x]=y;
   size[y]+=size[x];
  }
  return true;
 }
 int findRoot(int x){//木の根を探す,計算量削減のため低く
  if(x!=parents[x])parents[x]=findRoot(parents[x]);
  return parents[x];
 }
 int treeSize(int x){return size[findRoot(x)];}
};
/*mod*/const int mod=1e9+7;
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗 1*/ll llpow(ll x,ll n){ll ans=1,i;rep(i,0,n){ans*=x;ans%=mod;}return ans;}
/*n乗 2*/ll modpow(ll x,ll n){ll ans=x,i,tmp=x,t1=1;i=1; while(i<n){if(i*2<n){ans*=ans;ans%=mod;i*=2;}else{t1=1;tmp=x;while(t1*2<n-i){tmp*=tmp;tmp%=mod;t1*=2;}ans*=tmp;ans%=mod;i+=t1;}}return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x){ans*=(x-i);ans%=mod;}return ans;}
/*逆元*/ll inv(ll x){return modpow(x,mod-2);}
/*nCr*/ll ncr(ll n,ll r){ll a=fact(n),b=modpow(fact(n-r),mod-2),c=modpow(fact(r),mod-2);ll ans=a*b;ans%=mod;ans*=c;ans%=mod;return ans;}
/*nPr*/ll npr(ll n,ll r){ll a=fact(n),b=modpow(fact(n-r),mod-2);return (a*b)%mod;}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*迷路移動*/const int dx[4]={1,0,-1,0};const int dy[4]={0,1,0,-1};
llfor;////////////////////////////////////////////////////////////
int main(){
 ll n;
 cin>>n;
 ll a;
 rep(i,0,n){
  cin>>a;
  if(a%2!=0){
   puts("first");
   return 0;
  }
 }
 puts("second");
return 0;}

Measured memory_bytes: 3544