akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef pair<int,int>   ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef set<int>        si;
typedef set<ii>         sii;

#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define clr(x,v) memset(x,v,sizeof x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define re return

template<typename T> T sgn (T x)      {re x<0? -1:(x>0? 1:0); }
template<typename T> T gcd (T a, T b) {re a ? gcd (b % a, a) : b; }
template<typename T> T abs (T x)      {re x < 0 ? -x : x; }
template<typename T> T sqr (T x)      {re x*x;}

#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define popcount __builtin_popcount
#define mp make_pair
#define eb emplace_back
#define ins insert
#define y second
#define x first
#define endl "\n"
#define MOD ((int)1e9+7)
#define N ((int)2e5+123)

int n,m,q,ans, a[10];
vector<pair<ii,ii>> v;
void f(int i){
    if(i==n){
        int sum=0;
        forn(j,0,q){
            if(a[v[j].x.y]-a[v[j].x.x]==v[j].y.x){
                sum+=v[j].y.y;
            }
        }
        ans=max(sum,ans);
        return;
    }
    forn(j,a[i-1],m+1){
        a[i]=j;
        f(i+1);
    }
}
void solve(){
    cin >> n >> m >> q;
    for(int a,b,c,d,i=0;i<q;i++){
       cin >> a >> b >> c >> d;
       a--;b--;
       v.eb(ii(a,b),ii(c,d));
    }
    forn(i,1,m+1){
        a[0]=i;
        f(1);
    }
    cout << ans << endl;
    
}
int main(){_
    solve();
    /*
    int t; cin >> t;
    while(t--){
        solve();
    }
     */
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define fir first
#define sec second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 5;
const int M = 2e5 + 5;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = 1e-8;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
inline ull qpow(ull a, ull b, ull c)
{
    ull ans = 1;
    while (b)
    {
        if (b & 1)
            ans = ans * a % c;
        a = a * a % c;
        b >>= 1;
    }
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int sum = 0;
    vector<int> dis(n);
    for (int i = 0; i < n - 1; i++)
    {
        dis[i] = a[i + 1] - a[i];
        sum += dis[i];
    }
    sort(dis.begin(), dis.end());
    cout << min(k - dis[n - 1], sum);
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
    string s;
    cin >> s;
    size_t size = s.length();
    
    string ans;
    
    for(int i=0;i<size;i++){
        if(i%2==0){
            ans = ans+s[i];
            
        }
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 640
n, m, x = [0] * 3
c = []
a = []

def format_input(filename = None):
	global n, m, x
	global c
	global a
	if filename == None:
		n, m, x = list(map(int, input().split()))
		ca = [list(map(int, input().split())) for i in range(n)]
		for i in ca:
			c.append(i[0])
			a.append(i[1:])

	elif filename == '__random__':
		from random import randint as rng
		n = rng(1, 12)
		m = rng(1, 12)
		x = rng(1, 10**5)
		c = [rng(1, 10**5) for i in range(n)]
		a = [[rng(1, 10**5) for j in range(m)] for i in range(n)]
		print(n, m, x)
		[print(c[i], ' '.join(list(map(str, a[i])))) for i in range(n)]

def get_answer():
	answer = sum(c) + 1

	for k in range(2**n):
		understand = [0] * m
		price = 0
		bit = k
		i = 0
		while bit != 0:
			for j in range(m):
				understand[j] += a[i][j] * (bit & 1)
			price += c[i] * (bit & 1)
			bit >>= 1
			i += 1
		check = True
		for j in range(m):
			if understand[j] < x:
				check = False
		if check:
			answer = min(answer, price)

	if answer == sum(c) + 1:
		answer = -1

	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)


Measured memory_bytes: 9328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
map<ll,ll>s;
int main()
 { 
     IOS;
     string str;cin>>str;
     ll ans =0,cnt=0,k=1;
     s[0]=1;
     for(int i=str.length()-1;i>=0;i--)
       {
           ans=( ans+ (str[i]-'0')*k )%2019;
           cnt+=s[ans];
           s[ans]++;
           k= k*10%2019;
       }
       cout<<cnt<<endl;
     return 0;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> hai(3);
 
  cin >> hai.at(0)>>hai.at(1)>>hai.at(2);
  sort(hai.begin(), hai.end());
  if(hai.at(0)==5&&hai.at(1)==5&&hai.at(2)==7){cout<<"YES"<<endl;}
  else {cout<<"NO"<<endl;}
}

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

int main()
{
  string S;
  cin >> S;
  typedef long long ll;
  vector<ll> val;
  int total = 1 << (S.size() - 1);
  vector<int> sep;
  for (int i = 0; i < total; ++i)
  {
    sep.clear();
    for (int j = 0; j < S.size() - 1; ++j)
      if (1 == (1&(i >> j)))
        sep.push_back(j + 1);
    sep.push_back(S.size());
    for (int j = 0, k = 0; j < sep.size(); k = sep[j], ++j)
      val.push_back(stoll(S.substr(k, sep[j] - k)));
  }
  cout << accumulate(val.begin(), val.end(), static_cast<ll>(0));
  return 0;
}


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

class Progaram
{
    static void Main(string[] args)
    {
        var n = Int32.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var res = 0;
        for (var i = 1; n >= i; i++)
        {
            if (i < a[i - 1] && a[a[i - 1] - 1] == i) res++;
        }
        Console.WriteLine(res);
    }
}


Measured memory_bytes: 19424
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;

const int N = 5050;
const ll INF = 0x3f3f3f3f;

ll dp[N][N];
int n, w[N], h[N], a[N], ans;

bool cmp(int A,int B){
    return w[A] + h[A] < w[B] + h[B];
}

int main(){
    scanf("%d", &n);
    for(int i = 0;i<n;i++){
        scanf("%d%d", h + i, w + i);a[i] = i;
    }
    sort(a, a + n, cmp);
    for(int i = 0;i<=n;i++){
        dp[0][i] = INF * INF;
        dp[i][0] = 0;
    }
    dp[0][1] = w[a[0]];
    for(int i = 1;i<n;i++){
        for(int j = 1;j<=n;j++){
            dp[i][j] = dp[i - 1][j];
            if(h[a[i]] >= dp[i - 1][j - 1])
                dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + w[a[i]]);
        }
    }
    ans = n;
    while(dp[n - 1][ans] == INF * INF) ans--;
    printf("%d\n", ans);
}


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

int main() {
	int h,w;
	int a = 0;
	string b;
	while (a == 0) {
		cin >> h >> w;
		if (h == 0) {
			a = 1;
		} else {
			for (int i = 0; i < h; i++) {
				b = "";
				for (int j = 0; j < w; j++) {
					b = b + "#";
				}
				cout << b << endl;
			}
			cout << "" << endl;
		}
		
	}
	return 0;
}


Measured memory_bytes: 3156
/*
[arc098] D - Xor Sum 2
*/

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 200000;

int N;
ll a[MAX_N + 1];

ll solve() {
    ll ans = 0;
    int r = 0;
    ll sum_p = 0;
    int sum_x = 0;
    for (int l = 0; l < N + 1; l++) {
        for (; sum_p == sum_x && r < N + 1; r++) {
            sum_p += a[r];
            sum_x ^= a[r];
        }
        ans += r - l - 1;
        sum_p -= a[l];
        sum_x ^= a[l];
    }

    return ans;
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    a[N] = -1LL;

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 1792
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()

mn = 9999999999
ct = 0
for i in range(n):
    if mn > a[i]:
        ct += 1
        mn = a[i]
print(ct)


Measured memory_bytes: 71248
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < 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 FORR(i, m, n) for(int i = m;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define FI first
#define SE second
#define PB(a) push_back(a)
#define DEBUG(x) cerr << __LINE__ << ":" << #x << ": " << x << "\n";
#define SZ(x) ((int)(x).size())
#define SO(x) sizeof((x)) / sizeof((x)[0])
//#define int long long
using namespace std;
using lint = long long;
struct Fast{Fast(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};} fast;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
inline int in() {int x; cin >> x; return x;}
inline lint IN() {lint x; cin >> x; return x;}
inline void co(int a[], int n) {REP(i, n) cout << a[i] << " "; cout << "\n";}
//if (IO > 1e5){lint a;	scanf(%lld, &a);	printf("%lld\n", a);}

signed main(){
	
	int n = in();	int k = in();	int a[k] = {0};
	int cnt = 0;
	REP(i,n){
		if (cnt == k) cnt = 0;
		++a[cnt];
		++cnt;
		//co(a,k);
	}
	SORT(a,k);
	cout << a[k-1] - a[0] << "\n";
	//cout << "Hello World" << "\n";
	return 0;
}


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

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


Measured memory_bytes: 3984
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

score = 0
for i in range(0, n):
   menu = a[i]
   score += b[menu-1]
   if i != 0 and a[i] - a[i-1] == 1:
      beforeMenu = a[i-1]
      score += c[beforeMenu-1]

print(score)

Measured memory_bytes: 3064
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);		
		int N = in.nextInt();
        int M = in.nextInt();
      
      if((N+M)%2==0){System.out.print((N+M)/2);}
      else{System.out.print("IMPOSSIBLE");}
        
        
      }
	}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#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 showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


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

    vector<int> w_froml;
    vector<int> r_fromr;
    rep(i, n){
        if (s[i] == 'W') w_froml.push_back(i);
    }
    for (int i = n-1; i >= 0; i--)
    {
        if (s[i] == 'R') r_fromr.push_back(i);
    }
    
    int ans = 0;
    for (int i = 0; i < min(w_froml.size(), r_fromr.size()); i++)
    {
        if (w_froml[i] > r_fromr[i]) break;
        ans++;
    }
    

    cout << ans << endl;

}



Measured memory_bytes: 4608
//header{{{
//#define _GLIBCXX_DEBUG
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/math/common_factor_rt.hpp>
  
using namespace std;
//using namespace boost::multiprecision;  
//using namespace boost::math;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int_fast64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

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


signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(10);

    int x;
    cin >> x;

    vector<int> v = {600, 800, 1000, 1200, 1400, 1600, 1800, 2000};

    rep(i,8){
        if(x < v[i]){
            cout << 8 - i << '\n';
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>

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

int main(){
  long int a,b,c,k,i,j,l;
  cin >> a >> b >> c >> k;
  long int p=0;
  for(i=0;i<a;i++){
    if(i==k) {
      break;
    }
    p++;
  }

  if(a<k){
    for(j=0;j<b;j++){
      if((i+j)==k) {
	break;
      }
    }
  }
  
  if(a+b<k){
    for(l=0;l<c;l++){
      if((i+j+l)==k) {
	break;
      }
      p--;
    }
  }
  cout << p << endl;
}


Measured memory_bytes: 3632
#[allow(unused_imports)]
use std::cmp::Ordering::{Equal, Greater, Less};
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;

// author: Seong Yong-ju <sei40kr@gmail.com>

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let n: i64;
    let k: i64;

    input! {
        n: i64,
        k: i64,
    };

    let ans = n - k + 1;
    println!("{}", ans);
}


Measured memory_bytes: 4352
n,*l=map(int,open(0).read().split())
e=[1]
for i in range(n): e+=[(e[-1]-l[i])*2]
a=t=0
for i in range(n,-1,-1):
  if l[i]>e[i]: print(-1); break
  t=min(l[i]+t,e[i]); a+=t
else: print(a)

Measured memory_bytes: 674404
def main(s):
    res = 0
    val = 0
    lst = ["A","C","G","T"]
    for i in range(len(s)):
        if s[i] in lst:
            val += 1
        else:
            res = max(res, val)
            val = 0
    return max(res,val)

s = input()
print(main(s))

Measured memory_bytes: 3060
import os
import numpy as np

if os.path.exists('input.txt'):
    test_mode = True
else:
    test_mode = False

if test_mode:
    f = open('input.txt')
    
def get_input():
    if test_mode:
        return f.readline().rstrip()
    else:
        return input().rstrip()

def int_list(l):
    for i in range(len(l)):
        l[i] = int(l[i])
    
input_line = get_input().split()
X = int(input_line[0])
N = int(input_line[1])
p = get_input().split()
int_list(p)

i = 0
while True:
    if not (X-i) in p:
        print(X-i)
        break
    if not (X+i) in p:
        print(X+i)
        break
    i += 1

if test_mode:
    f.close()

Measured memory_bytes: 27140
N = int(input())
S = input()
r = 0
g = 0
b = 0
for s in S:
    if s == "R":
        r += 1
    if s == "G":
        g += 1
    if s == "B":
        b += 1
res = r * g * b
for i in range(N):
    for j in range(i + 1, N):
        if S[i] != S[j]:
            if j * 2 - i < N:
                if S[j * 2 - i] != S[i] and S[j * 2 - i] != S[j]:
                    res -= 1
print(res)


Measured memory_bytes: 73756
#include<bits/stdc++.h>
using namespace std;
#define     ll              long long
#define     MAX             100000
#define     FI              freopen("input.txt","r",stdin)
#define     FO              freopen("output.txt","w",stdout)
#define     fast            ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define     sc(a)           scanf("%d",&a)
#define     sc2(a,b)        scanf("%d %d",&a,&b)


int main()
{
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll sum = 0;
    if(a>=k)
    {
        sum+=k;
        k = 0;
    }
    else if(a<k)
    {
        sum+=a;
        k-=a;
    }
    if(k>0 && b>0)
    {
        if(b>=k)
        {
            k=0;
        }
        else
        {
            k-=b;
        }
    }
    if(k>0 && c>0)
    {
        if(c>=k)
        {
            sum+=(k*(-1));
            k=0;
        }
        else
        {
            sum+=(c*(-1));
            k-=c;
        }

    }
    cout<<sum<<"\n";
    return 0;
}


Measured memory_bytes: 3592
//ABC109D

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define VI vector<int>
#define VII vector<vector<int>>
#define all(v) (v.begin(),v.end())
#define MP make_pair
#define pb(n) push_back(n)


int main(){
    int H,W;
    cin>>H>>W;
    VII A(H,VI(W));
    rep(i,H){rep(j,W)cin>>A[i][j];}

    vector<pair<int,int>> P;
    int cnt = 0;

    rep(i,H){
        rep(j,W-1){
            if(A[i][j]&1){
                --A[i][j];
                ++A[i][j+1];
                P.pb(MP(i+1,j+1));
                P.pb(MP(i+1,j+2));
                ++cnt;
            }
        }
        if(A[i][W-1]&1&&i!=H-1){
            --A[i][W-1];
            ++A[i+1][W-1];
            P.pb(MP(i+1,W));
            P.pb(MP(i+2,W));
            ++cnt;
        }
    }

    put(cnt);
    rep(i,P.size()) cout<<P[i].first<<" "<<P[i].second<<(i%2?"\n":" ");
}

Measured memory_bytes: 5232
N,A,B,C,D=map(int,input().split())
S=input()
E=min(C,D)
F=max(C,D)
if S.find('##',A,F)>0:
  print('No')
else:
  if C<D:
    print('Yes')
  else:
    if S.find('...',B-2,E+1)>0:
      print('Yes')
    else:
      print('No')

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>

#define DEBUG 0

using namespace std;

int max(int a,int b){
	return a>b ? a:b;
}

int main(){
	int n;
	while(cin>>n){
		if(n==0)break;

		vector<int> *person;
		map<int, vector<int> > dayToPerson;
		person = new vector<int>[n];

		int first=0;
		int maxDay = 0;
		int ansFlag=0;

		for(int i=0;i<n;i++){
			int tmp;
			cin>>tmp;
			for(int j=0;j<tmp;j++){
				int tmp2;
				cin>>tmp2;
				if(i==0 && j==0){
					first = tmp2;
				}
				person[i].push_back(tmp2);
				dayToPerson[tmp2].push_back(i);
				maxDay=max(tmp2,maxDay);
			}
		}

		for(int day=1;day<=30;day++){
			queue<int> personQueue;
			priority_queue<int> beforeDay;
			int *flag;
			flag = new int[n];
			for(int i=0;i<n;i++){
				flag[i]=0;
			}

			int nowDay = day;
			if(DEBUG)cout<<"NOWDAY:"<<nowDay<<endl;
			while(nowDay>0){
				for(int i=0;i<dayToPerson[nowDay].size();i++){
					if(flag[dayToPerson[nowDay].at(i)]==0){
						personQueue.push(dayToPerson[nowDay].at(i));
						flag[dayToPerson[nowDay].at(i)]=1;
					}
				}

				while(personQueue.size()!=0){
					int nowPerson=personQueue.front();
					personQueue.pop();
					if(DEBUG)cout<<"NOW Person:"<<nowPerson<<endl;

					for(int i=0;i<person[nowPerson].size();i++){
						if(nowDay > person[nowPerson].at(i)){
						
							if(DEBUG)cout<<"beforeDay"<<person[nowPerson].at(i)<<"input"<<endl;
							beforeDay.push(person[nowPerson].at(i));

						}
					}
				}

				int changeFlag=0;
				if(beforeDay.size()==0){
					break;
				}
				while(beforeDay.size()!=0 && nowDay == beforeDay.top()){
					beforeDay.pop();
					if(beforeDay.size()==0){
						changeFlag=1;
						break;
					}
				}
				if(changeFlag==1){
					break;
				}
				nowDay=beforeDay.top();
				beforeDay.pop();
			}
			ansFlag=0;
			for(int i=0;i<n;i++){
				if(flag[i]==0){
					ansFlag=1;
					break;
				}
			}
			if(ansFlag==0){
				cout<<day<<endl;
				ansFlag=2;
				break;
			}
		}
		if(ansFlag!=2){
			cout<<-1<<endl;
		}
	}

	return 0;
}
		

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

int main() {
  int n;
  ll d;
  cin >> n >> d;
  int cnt = 0;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    if(x*x + y*y <= d*d) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3632
from copy import deepcopy
def check(S):
    n=0
    for ch in S:
        if ch=='#':
            n+=1
    return n
h,w,k=map(int, input().split())
tmp=[list(input()) for _ in range(h)]
c=deepcopy(tmp)

y=0
for l in c:
    x=check(''.join(l))
    y+=x

n=0
for i in range(h+w):
    n+=2**i
n+=1
m=0
for i in range(n):
    i=format(i, str(h+w).zfill(2)+'b')
    H=i[:h]
    W=i[h:]
    ans=0
    x=0
    for j in H:
        if j=='1':
            ans+=check(''.join(c[x]))
            #print(''.join(c[x]))
            c[x]=['.']*w
        x+=1
    x=0
    for j in W:
        if j=='1':
            s=str()
            for z in range(h):
                s+=c[z][x]
            ans+=check(s)
            for z in range(h):
                c[z][x]='.'
        x+=1
    #print(H,W,y-ans,k)
    if k==y-ans:
        m+=1
    c=deepcopy(tmp)

print(m)

Measured memory_bytes: 9220
#include<iostream>
using namespace std;
int main(){
    int min=100000000,max=-10000000,n,a;
    long long sum=0;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a;
        if(a<min){
            min = a;
        }
        if(a>max){
            max = a;
        }
        sum += a;
    }
    cout << min << " " << max << " " << sum << endl;
    return 0;  
}


Measured memory_bytes: 3080
#include <stdio.h>
main(){
  int n;scanf("%d",&n);
  switch(n%10){
    case 2:case 4:case 5:case 7:case 9:puts("hon");break;
    case 0:case 1:case 6:case 8:puts("pon");break;
    case 3:puts("bon");break;
  }
  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int INF = INT_MAX;
int CNT = 0;
void merge(vector<int> &S, int left, int mid, int right) {
  int nl = mid - left, nr = right - mid;
  vector<int> L(nl + 1), R(nr + 1);
  for (size_t i = 0; i < nl; i++) {
    L.at(i) = S.at(left + i);
  }
  L.at(nl) = INF;

  for (size_t i = 0; i < nr; i++) {
    R.at(i) = S.at(mid + i);
  }
  R.at(nr) = INF;

  int i = 0, j = 0;
  for (int k = left; k < right; k++) {
    CNT++;
    if (L[i] <= R[j]) {
      S[k] = L[i++];
    } else {
      S[k] = R[j++];
    }
  }
}
void mergeSort(vector<int> &S, int left, int right) {
  if ((right - left) == 1) return;
  int mid = (left + right) / 2;
  mergeSort(S, left, mid);
  mergeSort(S, mid, right);
  merge(S, left, mid, right);
}
int main() {
  int n;
  cin >> n;
  vector<int> S(n);
  for (size_t i = 0; i < n; i++) {
    cin >> S.at(i);
  }

  mergeSort(S, 0, n);

  int i = 0;
  while (i != n - 1) {
    cout << S.at(i) << ' ';
    i++;
  }
  cout << S.at(i) << endl;
  cout << CNT << endl;
}


Measured memory_bytes: 6864
#include <algorithm>
#include <iostream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define endll puts("")
#define mod 1000000007
#define ll long long
#define mp3(a,b,c) mp(a,mp(b,c))
#define sol (root+root)
#define sag (sol+1)
#define ort ((son+bas)/2)
#define pii pair<int,int>
#define pll pair<ll,ll>
using namespace std;
const int N=3e3+3;
ll n,m,x,y,z,h[N],hh[N],k,l,i,j,ii,jj,t,s,dp[N][N];
pll A[N];
ll f(int x,int y)
{
	if(x<=0 or y>n)
		return 0;
	ll &r=dp[x][y];
	if(r!=-1)
		return r;
	r=f(x,y+1);
	return r=max(r,f(x-A[y].st,y+1)+A[y].nd);

}
int main()
{
	cin>>n>>t;
	for(i=1;i<=n;i++)
	{
		cin>>A[i].first>>A[i].nd;
	}
	sort(A+1,A+n+1);
	memset(dp,-1,sizeof dp);
	cout<<f(t,1)<<endl;

}

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

using ll=long long;
int main(){
    int n;
    ll X;
    cin>>n>>X;
    vector<ll> x(n);
    for(int i=0;i<n;i++) cin>>x[i];
    vector<ll> sum(n+1);
    partial_sum(x.begin(),x.end(),sum.begin()+1);
    ll res=1e18;
    for(int i=n;i>=1;i--){
        ll sc=X*i+X*n;
        int ub=n;
        int k=1;
        // cerr<<sc<<endl;
        while(ub>0){
            int lb=max(ub-i,0);
            // cerr<<ub<<" "<<lb<<endl;
            sc+=(sum[ub]-sum[lb])*(2*k+1);
            if(sc>res) break;
            if(k==1) sc+=(sum[ub]-sum[lb])*2;
            k++;
            ub=lb;
            // cerr<<sc<<endl;
        }
        // cerr<<sc<<endl;
        res=min(res,sc);
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3328
//	auto a = readln.chomp.split(' ').map!(to!int).array;
import std.container;
import std.range;
import std.algorithm;
import std.array;
import std.string;
import std.conv;
import std.stdio;
import std.container;

long powmod(long x, long n, long mod) {
	x %= mod;

	long result = 1;
	while (n > 0) {
		if (n & 0x01L) {
			result = result * x % mod;
		}
		x = x * x % mod;

		n >>= 1;
	}

	return result;
}

// n == 1: 0, n == 2: 2, n == 3: 54, n == 4: 974, n == 5: 14670

void main() {
	enum long Mod = 10 ^^ 9 + 7;

	long n;
	readf("%s", &n);

	if (n <= 1) {
		writeln(0);
		return;
	}

	auto r = powmod(10, n, Mod) + powmod(8, n, Mod);
	r -= (powmod(9, n, Mod) * 2) % Mod;
	if (r < 0) {
		r += Mod;
	}

	writeln(r);
}


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

#define task "A"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
string s;
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> s;
    if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') cout << 3;
    else if ((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R')) cout << 2;
    else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') cout << 1;
    else cout << 0;
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
using Graph = vector<vector<int>>;
Graph G;

ll dp[100010][13]; // pos, value:mod 13
int main(){
    string s; cin >> s;
    int n = s.size();
    int k; cin >> k;

    rep(i, 100010)rep(j, 13) dp[i][j] = 0;
    dp[0][0] = 1;
    rep(i, n)rep(j, 13){
        if(s[i] == '?'){
            rep(d, 10){
                (dp[i + 1][(j * 10 + d) % 13] += dp[i][j]) %= mod;
            }
        }else{
            (dp[i + 1][(j * 10 + (s[i] - '0')) % 13] += dp[i][j]) %= mod;
        }
    }
    ll ans = dp[n][5];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13900
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
//***********//
ll Npow(ll x, ll n) {
	if (n == 0) return 1;
	if (n % 2 == 0) return Npow(x * x % MOD, n / 2);
	else return x * Npow(x, n - 1) % MOD;
}

int main() {
	ll D;
	cin >> N >> M >> D;
	if (D == 0) cout << fixed << setprecision(10) << (ld)(M - 1) / N;
	else cout << fixed << setprecision(10) << (ld) (M - 1) * 2 * max(z,(N - D)) / N / N;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static int pow(int num,int cnt){
        int ans = num;
        while(1 < cnt--){
            ans *= num;
        }
        return ans;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while( sc.hasNext() ){
            String[] line = sc.nextLine().split(" ");
            int innum = Integer.parseInt(line[0]);
            int ans = pow(innum,3);
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 26280
# Selection Sort

length = int(input())
array = [int(i) for i in input().rstrip().split()]

count = 0
for i in range(length):
    minj = i
    for j in range(i, length):
        if array[j] < array[minj]:
            minj = j
    if minj != i:
        count += 1
        array[i], array[minj] = array[minj], array[i]

for i in range(length):
    if i < length - 1:
        print(array[i], end = " ")
    else:
        print(array[i])
print(count)



Measured memory_bytes: 5608
# C - GeT AC
N,Q = map(int,input().split())
S = input()
L = []
R = []
for _ in range(Q):
    l,r = map(int,input().split())
    l -= 1;r -= 1
    L.append(l)
    R.append(r)

# 右隣に 'C' が存在する 'A' の個数をカウント
cnt = [0]*N
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        cnt[i] = 1

# s[i]: i 番目までに出てくる右隣に 'C' が存在する 'A' の個数
s = [0]*(N+1)
for i in range(N):
    s[i+1] = s[i] + cnt[i]

for l,r in zip(L,R):
    ans = s[r] - s[l]
    print(ans)

Measured memory_bytes: 88380
#include<stdio.h>
int main()
{
	int n,b[4][3][10]={0};
	while(scanf("%d",&n)!=EOF&&n)
	{
		int i,j,a[4]={0};
		for(i=0;i<n;i++)
		{
			scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3]);
			if(a[0]>5||a[0]<0||a[1]>4||a[1]<0||a[2]>11||a[2]<0)
			{
				b[a[0]-1][a[1]-1][a[2]-1]=0;
			}
			if(b[a[0]-1][a[1]-1][a[2]-1]>0)
			{
				b[a[0]-1][a[1]-1][a[2]-1]+=a[3];
			}
			else if(a[3]<0)
			{
				if(a[3]>b[a[0]-1][a[1]-1][a[2]-1])
				{
					//b[a[0]][a[1]][a[2]]=0;
				}
				else
				{
					b[a[0]-1][a[1]-1][a[2]-1]+=a[3];
				}
			} 
			else
			{
				b[a[0]-1][a[1]-1][a[2]-1]=a[3];
			}
			
			
		}
		for(i=0;i<3;i++)
		{
			for(j=0;j<10;j++)
			{
				printf(" %d",b[0][i][j]);
			}
			printf("\n");
		}
		printf("####################\n");
		for(i=0;i<3;i++)
		{
			for(j=0;j<10;j++)
			{
				printf(" %d",b[1][i][j]);
			}
			printf("\n");
		}
		
		printf("####################\n");
		for(i=0;i<3;i++)
		{
			for(j=0;j<10;j++)
			{
				printf(" %d",b[2][i][j]);
			}
			printf("\n");
		}
		printf("####################\n");
		for(i=0;i<3;i++)
		{
			for(j=0;j<10;j++)
			{
				printf(" %d",b[3][i][j]);
			}
			printf("\n");
		}
	}
	return 0;
} 

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

int fact(int n){
	return n > 1 ? n*fact(n-1):n;
}
int main(){
	int n;
	cin >>n;
	vector<int>x(n),y(n);
	vector<int>p(n);
	double ans=0;
	rep(i,n){
		p[i]=i;
		cin >>x[i]>>y[i];
	}
	do{
		rep(i,n-1){
			ans+=sqrt(pow(x[p[i]]-x[p[i+1]],2)+
						pow(y[p[i]]-y[p[i+1]],2)
					);
		}
	}while(	next_permutation(p.begin(),p.end()));
	cout <<setprecision(15)<<ans/fact(n)<<endl;
}

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

ll gcd (ll a , ll b ){ return b ? gcd(b,a%b) : a;}

int main() {
  int n ;
  cin >> n ;
  string S ;
  cin >> S ;
  vector<int> R ;
  vector<int> G ;
  vector<int> B ;
  rep(i,n){
    if( S[i] == 'R' ) R.push_back(i+1) ;
    if( S[i] == 'G' ) G.push_back(i+1) ;
    if( S[i] == 'B' ) B.push_back(i+1) ;
  }
  ll count = 0 ;
  rep(i,n){
      rep(j,n){
          if( i - j >= 0  && i + j < n ){
    if( S[i-j] == 'R' &&   S[i] == 'G'  &&  S[i+j] == 'B' ) count++ ;
    if( S[i-j] == 'R' &&   S[i] == 'B'  &&  S[i+j] == 'G' ) count++ ;
    if( S[i-j] == 'B' &&   S[i] == 'G'  &&  S[i+j] == 'R' ) count++ ;
    if( S[i-j] == 'B' &&   S[i] == 'R'  &&  S[i+j] == 'G' ) count++ ;
    if( S[i-j] == 'G' &&   S[i] == 'B'  &&  S[i+j] == 'R' ) count++ ;
    if( S[i-j] == 'G' &&   S[i] == 'R'  &&  S[i+j] == 'B' ) count++ ;
          }
      }
  }
  ll ans = (ll) R.size() * B.size() * G.size() ;
  //cout << R.size() << ' ' << B.size() << ' ' << G.size() << endl;
  cout << ans - count<< endl;
  //cout << ans << endl;
}

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

int main(void){
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  for(int i = 0; i < N; i++){
    cin >> H.at(i);
  }
  
  int A, B;
  vector<bool> good(N);
  for(int i = 0; i < N; i++){
    good.at(i) = true;
  }
    
  for(int i = 0; i < M; i++){
    cin >> A >> B;
    if(H.at(A-1) <= H.at(B-1)){
      good.at(A-1) = false;
//      cout << A << B << " Aです" << endl;
    }
    if(H.at(A-1) >= H.at(B-1)){
      good.at(B-1) = false;
//      cout << A << B << " Bです" << endl;
    }
  }
  
  int ans = 0;
  for(int i = 0; i < N; i++){
//    cout << good.at(i) << endl;
	if(good.at(i) == true){
      ans++;
    }
  }
  cout << ans << endl;

}

Measured memory_bytes: 3808
#include <cstdio>
#include <cstdlib>
#include <vector>

using namespace std;
vector<int> eds[299999];
vector<int> val[299999];
int R,C,N;
typedef struct {
	int vx;
	int vy;
	int vl;
}vss;
vss vs[299999];
int ind[299999];
int cmp1(const void *ka,const void *kb) {
	int ta=*(int *)ka;
	int tb=*(int *)kb;
	if(vs[ta].vy!=vs[tb].vy) return vs[ta].vy-vs[tb].vy;
	return vs[ta].vx-vs[tb].vx;
}
int cmp2(const void *ka,const void *kb) {
	int ta=*(int *)ka;
	int tb=*(int *)kb;
	if(vs[ta].vx!=vs[tb].vx) return vs[ta].vx-vs[tb].vx;
	return vs[ta].vy-vs[tb].vy;
}
int checked[299999];
int grp[299999];
long long pos[299999];
long long grpmin[299999];
int ng=0;
void add_edge(int va,int vb,int value) {
	eds[va].push_back(vb);
	val[va].push_back(value);
	eds[vb].push_back(va);
	val[vb].push_back(-value);
}
void dfs(int nw,long long cur,int grpnum) {
	if(checked[nw]) {
		if(pos[nw]!=cur) ng=1;
		return;
	}
	checked[nw]=1;
	grp[nw]=grpnum;
	if(grpmin[grpnum]>cur) grpmin[grpnum]=cur;
	pos[nw]=cur;
	for(int i=0;i<eds[nw].size();i++) dfs(eds[nw][i],cur+val[nw][i],grpnum);
}
int main() {
	scanf("%d%d%d",&R,&C,&N);
	for(int i=0;i<N;i++) {
		scanf("%d%d%d",&vs[i].vx,&vs[i].vy,&vs[i].vl);
		ind[i]=i;
	}
	qsort(ind,N,sizeof(int),cmp1);
	for(int i=1;i<N;i++) {
		int pa=ind[i-1];
		int pb=ind[i];
		if(vs[pa].vy==vs[pb].vy) add_edge(vs[pa].vx,vs[pb].vx,vs[pb].vl-vs[pa].vl);
	}
	qsort(ind,N,sizeof(int),cmp2);
	for(int i=1;i<N;i++) {
		int pa=ind[i-1];
		int pb=ind[i];
		if(vs[pa].vx==vs[pb].vx) add_edge(vs[pa].vy+100000,vs[pb].vy+100000,vs[pb].vl-vs[pa].vl);
	}
	for(int i=1;i<200001;i++) if(checked[i]==0) dfs(i,0,i);
	if(ng) {
		printf("No\n");
	} else {
		for(int i=0;i<N;i++) {
			int nx=vs[i].vx;
			int ny=vs[i].vy+100000;
			long long tmp=vs[i].vl;
			tmp+=grpmin[grp[nx]]-pos[nx];
			tmp+=grpmin[grp[ny]]-pos[ny];
			if(tmp<0) {
				printf("No\n");
				return 0;
			}
		}
		printf("Yes\n");
	}
	return 0;
}


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

#define ll long long int

const ll mod=1e9+7;
const int sz=2e5+100;

vector<int> ad[sz];
bool vis[sz];

int DFS(int p)
{
    vis[p]=true;
    int ct=1;
    int siz=ad[p].size();
    for(int i=0;i<siz;i++){
        int x=ad[p][i];
        if(!vis[x]) ct+=DFS(x);
    }

    return ct;
}
int main()
{
    int n,m,p,q,i,j,k;
    cin>>n>>m;

    for(i=1;i<=m;i++){
        cin>>p>>q;
        ad[p].push_back(q);
        ad[q].push_back(p);
    }

    int mx=0;
    for(i=1;i<=n;i++){
        if(vis[i]==false) mx=max(mx, DFS(i));
    }

    cout<<mx<<'\n';
}


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

using namespace std;

int main()
{
    int a , b , c , x , y ;
    cin>>a>>b>>c>>x>>y ;
    if(x == y)
     cout<<min(a*x + b * y , c*x*2);
    else if(x > y)
     cout<<min(a*x + b*y , min(c*x*2 , c*y*2 + a*(x-y)));
    else
     cout<<min(a*x + b*y , min(c*y*2 , c*x*2 + b*(y-x)));
    return 0 ;
}


Measured memory_bytes: 256
def main():
    n,k=map(int,input().split(' '))
    h=list(map(int,input().split(' ')))
    dp = [float('inf') for i in range(n)]
    dp[0]=0
    dp[1]=abs(h[1]-h[0])
    for i in range(n):
        for j in range(i,min(i+k+1,n)):
            if dp[j] > dp[i]+abs(h[i]-h[j]):
                dp[j] = dp[i]+abs(h[i]-h[j])
    print(dp[-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 55304
#include<bits/stdc++.h>
#define N 100005
using namespace std;
long long n,m,s[N],t[N],p[N],d[N],ans;

int bynary_search(int x){
  int l=0,r=m;
  while(l<r){
    int mid=(l+r)/2;
    if(x<=p[mid])r=mid;
    else l=mid+1;
  }
  return l;
}

int main(){
  cin>>n>>m;
  for(int i=0;i<n;i++)cin>>s[i]>>t[i];
  for(int i=0;i<m;i++)cin>>p[i];
  sort(p,p+m);
  d[0]=p[0],d[1]=p[1]-p[0];
  ans=0;
  for(int i=2;i<m;i++)d[i]=d[i-2]+p[i]-p[i-1];
  for(int i=0;i<n;i++){
    int r1=bynary_search(s[i]);
    int r2=bynary_search(t[i]);
    if(r1==r2)ans+=max(s[i],t[i])-min(s[i],t[i]);
    else if(abs(r1-r2)==1){
      if(s[i]<t[i])ans+=p[r1]-s[i];
      else ans+=s[i]-p[r1-1];
    }
    else if(s[i]<t[i]){
      if(r2%2==r1%2)ans+=p[r1]-s[i]+d[r2-2]-d[r1]+t[i]-p[r2-1];
      else ans+=p[r1]-s[i]+d[r2-1]-d[r1];
    }else{
      if(r2%2==r1%2)ans+=s[i]-p[r1-1]+d[r1-2]-d[r2]+p[r2]-t[i];
      else ans+=s[i]-p[r1-1]+d[r1-2]-d[r2-1];
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4300
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        var N = Read();
        var s = Reads();
        var t = Reads();
        var c = new List<long>();
        var v = new List<long>();
        for (int i = 0; i < N; i++)
            v.Add(s[i]);
        for (int i = 0; i < N; i++)
            c.Add(t[i]);

        long total = 0;
        for(int i = 0; i < N; i++)
        {
            if (v[i] > c[i])
                total += v[i] - c[i];
        }
        Console.WriteLine(total);
        Console.Out.Flush();
    }
}

Measured memory_bytes: 13396
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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 int INF = 1e9;
const ll MOD = 1000000007;

int main() {
    int x; cin>>x;
    int ans = 0;
    ans = pow(x,3);
    ct(ans);
}



Measured memory_bytes: 3120
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(void){
	int a,b,c;
	int i,j,k;
	char s[100];


	scanf("%d %d",&a,&b);
	c = a-2*b;
	if(c < 0 ){
		c = 0;
	}
	printf("%d\n",c);


	return 0;
}

Measured memory_bytes: 128
X, N = map(int, input().split())
P = list(map(int, input().split()))

if (X not in P):
    print(X)
    exit()

# Xを中心に+1 , -1をそれぞれ実行し、その整数が含まれているかチェック
left = -1
right = 1

lL = []
rL = []
while True:
    if (len(lL) != 0 or len(rL) != 0):
        break
    lX = X + left
    rX = X + right

    if (lX not in P):
        lL.append(lX)
    if (rX not in P):
        rL.append(rX)

    left -= 1
    right += 1

if (len(lL) != 0 and len(rL) == 0):
    print(lL[0])
elif (len(lL) == 0 and len(rL) != 0):
    print(rL[0])
else:
    ml = lL[0]
    mr = rL[0]
    print(min(ml, mr))


Measured memory_bytes: 9232
#include <bits/stdc++.h>
using namespace std;
int main(){
   int A,B;
   cin>>A>>B;
   int sum=A;
   if(B==1){
       cout<<"0"<<endl;
       return 0;
   }
   if(A>=B){
       cout<<"1"<<endl;
       return 0;
   }
   int count=1;
   bool f = true;
   while(f){
       if(sum<B){
           count++;
           sum=sum+A-1;
       }
       else{
           f = false;
           break;
       }
   }
   cout<<count<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main() 
{
    cin >> a >> b;
    if (a > 0 && b > 0) 
        puts("Positive");
     else if (max(a, b) >= 0 && min(a, b) <= 0 || a == 0 || b == 0) 
        puts("Zero");
     else 
        if ((abs(min(a, b)) - abs(max(a, b))) % 2 == 0) 
            puts("Negative");
         else 
            puts("Positive");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



int main(){
	
	int H,W;
	cin>>H>>W;
	
	vector<vector<int>> A(H,vector<int>(W));
	vector<vector<int>> B(H,vector<int>(W));
	
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>A[i][j];
		}
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>B[i][j];
		}
	}
	
	vector<vector<vector<bool>>> flag(H,vector<vector<bool>>(W,vector<bool>(14000,false)));
	
	flag[0][0][7000+A[0][0]-B[0][0]]=true;
	flag[0][0][7000-A[0][0]+B[0][0]]=true;
	
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			for(int k=0;k<14000;k++){
				if(flag[i][j][k]==false)continue;
				if(i!=H-1){
					int a = A[i+1][j]-B[i+1][j];
					int b = -a;
					if(k+a>=0&&k+a<14000)flag[i+1][j][k+a]=true;
					if(k+b>=0&&k+b<14000)flag[i+1][j][k+b]=true;
				}
				if(j!=W-1){
					int a = A[i][j+1]-B[i][j+1];
					int b = -a;
					if(k+a>=0&&k+a<14000)flag[i][j+1][k+a]=true;
					if(k+b>=0&&k+b<14000)flag[i][j+1][k+b]=true;
				}
			}
		}
	}
	int ans = 10000000;
	for(int i=0;i<14000;i++){
		if(flag[H-1][W-1][i]){
			ans = min(ans,abs(7000-i));
		}
	}
	
	cout<<ans<<endl;
	

	return 0;
}

Measured memory_bytes: 11776
a, b, c = map(int, input().split())
a_sho,b_sho,c_sho = a,b,c
ans = 0
mugen = False
while True:
    a_k = a
    b_k = b
    c_k = c
    if a%2 != 0 or b%2 != 0 or c%2 != 0:
        break
    else:
        a = b_k/2 + c_k/2
        b = a_k/2 + c_k/2
        c = a_k/2 + b_k/2
        ans += 1
    if a == a_sho and b == b_sho and c == c_sho:
        mugen = True
        break

if mugen:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9276
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int mx=0,a,b,ansA,ansB,ansC;
  cin >> a >> b;
  ansA = a + b ;
  ansB = a - b;
  ansC = a * b;

  if(ansA >= ansB && ansA >= ansC)cout << ansA << endl;
  else if(ansB >= ansA && ansB >= ansC)cout << ansB << endl;
  else cout << ansC << endl;
  return 0;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,K;
    cin>>N>>K;
    int sum=0;
    int x;
    for(int i=0;i<N;i++){
        cin>>x;
        sum+=2*min(x,abs(K-x));
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256