akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

struct UnionFind{
   vector<int> par;
   UnionFind(int n):par(n,-1){}
   int find(int x){
       if(par[x]<0)return x;
       return par[x]=find(par[x]);
   }
   bool unite(int x,int y){
       x=find(x);
       y=find(y);
       if(x==y)return false;
       if(par[x]>par[y]){
           par[y]+=par[x];
           par[x]=y;
       }
       else{
           par[x]+=par[y];
           par[y]=x;
       }
       return true;
   }

   bool same(int x,int y){
       return find(x)==find(y);
   }
   int size(int x){
       return -par[find(x)];
   }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    UnionFind uf(n);
    int m;
    cin>>m;
    int ans=n-1;
    rep(i,m){
        int x,y;
        cin>>x>>y;
        ans -= uf.unite(--x,--y);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3732
N=int(input())
li=[]

for n in range(N):
  a=int(input())
  li.append(a)

s=0
count=0

while s!=1:
  if count==N:
    break
  else:
    s=li[s]-1
    count+=1

if s==1:
  print(count)
else:
  print(-1)

Measured memory_bytes: 7084
import java.util.LinkedList;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		LinkedList<Integer> list = new LinkedList<Integer>();

		for (int i=0; i<n; i++) {
			String str = br.readLine();

			if (str.startsWith("insert")) {
				list.addFirst(Integer.parseInt(str.substring(str.indexOf(" ")+1)));
			}else if (str.equals("deleteFirst")) {
				list.pollFirst();
			}else if (str.equals("deleteLast")){
				list.pollLast();
			}else {
				list.remove((Integer)Integer.parseInt(str.substring(str.indexOf(" ")+1)));
			}
		}

		StringBuilder sb = new StringBuilder();
		sb.append(list.poll());
		for (Integer s : list) {
			sb.append(" ").append(s);
		}
		System.out.println(sb.toString());

		br.close();
	}
}

Measured memory_bytes: 134996
import Data.List
import Data.Array
import qualified Data.Array.Unboxed as UA
import Control.Monad
import Control.Monad.ST
import qualified Data.Set as S
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV

main=interact$show.f.map read.words

f (h:w:r)=sum $ map (\n-> xs V.! n) ar
    where
    (cs,as) = splitAt 100 r
    ca = UA.listArray ((0,0),(9,9)) cs
    ar = filter (\a->a/=1&&a/=(-1)) as
    ds = map (dks ca) (0:[2..9])
    xs = dks ca 1

dks ca 1=runST $ do
    dv <- MV.replicate 10 maxBound :: ST s (MV.STVector s Int)
    MV.unsafeWrite dv 1 0
    let q=S.singleton (0,1)
    dksl ca dv q
    V.unsafeFreeze dv

dksl::UA.Array (Int,Int) Int -> MV.STVector s Int -> S.Set (Int,Int) -> ST s ()
dksl ca dv q
    | S.null q = return ()
    | otherwise = do
        let ((d,u),q') = S.deleteFindMin q
        q'' <- f dv d u q' [0..9]
        dksl ca dv q''
    where
        f _ _ _ q [] = return q
        f dv d u q (v:r) = do
            let a = d + ca ! (v,u)
            lv <- MV.unsafeRead dv v
            if lv > a then do
                MV.unsafeWrite dv v a
                f dv d u (S.insert (a, v) q) r
            else
                f dv d u q r


Measured memory_bytes: 2428
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = {}
for i in range(len(a)):
    if a[i] in b:
        b[a[i]] += 1
    else:
        b[a[i]] = 1
twins = []
now = 1
while now <= a[-1]:
    now *= 2
    twins.append(now)
for i in range(len(a) - 1, -1, -1):
    tmpa = 0
    if  b[a[i]] == 0:
        continue
    for j in range(len(twins) - 1, -1, -1):
        if twins[j] <= a[i]:
            break
        tmpa = twins[j] - a[i]
    if tmpa == a[i]:
        if b[tmpa] >= 2:
            b[tmpa] -= 2
    elif tmpa in b and b[tmpa] != 0:
        b[tmpa] -= 1
        b[a[i]] -= 1
countb = 0
for i in b:
    countb += b[i]
print((n - countb) // 2)

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

int topping(char str[]) {
	int i;
	int num = 0;

	for (i = 0; i < 3; i++) {
		if (str[i] == 'o') {
			num++;
		}
	}
	return num * 100;
}

int main() {
	char S[4];
	int ramen = 700;
	cin.getline(S, 4);
	ramen += topping(S);
	cout << ramen << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<String> sl = new ArrayList<String>();
        List<Integer> il = new ArrayList<Integer>();
        for(int i = 0; i < n; i++){
            sl.add(sc.next());
            il.add(sc.nextInt());
        }
        String last = sc.next();
        int lastInd = sl.indexOf(last);
        int ans = 0;
        for(int i = lastInd+1; i < n; i++){
            ans += il.get(i);
        }
        System.out.println(ans);
    }
}



Measured memory_bytes: 23636
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <array>
#include <climits>

using namespace std;

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

const ll MOD = 10e9 + 7;
const ll INF = LLONG_MAX;
const ll MAX_V = 10e3;
const double EPS = 10e-6;
const double PI = 3.14159265359;

//int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
//int d[] = {0,1,0,-1};
//int nx = x + d[i];
//int ny = y + d[(i+1)%4]

ll n, c, x[100005], v[100005], sum[100005]{},memo[2][100005][2],ans = 0;

int main() {

	cin >> n >> c;
	x[0] = 0; v[0] = 0;
	x[n + 1] = 0; v[n + 1] = 0;
	for (int i = 1; i <= n; i++) {
		cin >> x[i] >> v[i];
		sum[i] = sum[i-1] + v[i];
	}

	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++)memo[i][0][j] = 0;
	}
	for (int i = 1; i <= n; i++) {
		memo[0][i][0] = max(memo[0][i-1][0], sum[i] - sum[0] - x[i]);
		memo[0][i][1] = max(memo[0][i-1][1], sum[i] - sum[0] - x[i] * 2);
	}
	for (int i = 1; i <= n; i++) {
		memo[1][i][0] = max(memo[1][i-1][0],sum[n] - sum[n-i] - (c - x[n-i+1]));
		memo[1][i][1] = max(memo[1][i-1][1],sum[n] - sum[n-i] - (c - x[n-i+1]) * 2);
	}

	for (int i = 0; i <= n; i++) {
		ans = max(ans,max(memo[0][i][1] + memo[1][n - i][0], memo[0][i][0] + memo[1][n - i][1]));
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5760
N,D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]

dbl = []
for i in range(1,1000):
        dbl.append(i**2)

ans = 0
for idx,val in enumerate(X):
        for idx2, val2 in enumerate(X):
                if idx == idx2:
                        continue
                elif idx < idx2:
                        break
                tmp = 0
                for d in range(D):
                        tmp += abs(val[d] - val2[d]) ** 2
                if tmp in dbl:
                        ans += 1

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
struct student{
    int a;
    int b;
};
bool cmp(student a,student b){
    return a.a<b.a;
};
int main(){
    int n,i;
    cin >> n;
    student a[n];
    for (i=0;i<n;i++){
        cin >> a[i].a;
        a[i].b=i+1;
    }
    sort(a,a+n,cmp);
    for (i=0;i<n-1;i++)
        cout << a[i].b << " ";
    cout << a[n-1].b << endl;
    return 0;
}


Measured memory_bytes: 1536
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
	if(!b)return 1;	if(b&1)return modpow(a,b-1,m)*a%m;
	int memo = modpow(a,b>>1,m);
	return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a;
  cin>>a;
  vector<int> b(a);
  rep(i,a)
    cin>>b[i];
  int c=0;
  rep(i,a-2){
  if(b[i+1]==mid(b[i],b[i+1],b[i+2]))
    c++;
  }
  out(c);
}


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

signed main(void)
{
	int n , p;
	long long ans, cnt;
	cin >> n >> p;
	
	ans = cnt = 0;
	rep(i, n) 
	{
		int a;
		cin >> a;
		if (a % 2 == 0)
			cnt++;
	}
	if (cnt == n)
	{
		if (p == 0)
			ans = pow(2, n);
	}
	else
	{
		ans = pow(2, n - 1);
	}
	cout << ans << endl;
	return 0;
}


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

// exp1 = exp2 [ ('+'|'-') exp2 ]*
// exp2 = exp3 [ ('*'|'/') exp3 ]*
// exp3 = '(' exp1 ')' | number
int exp1(const string& s, int& i);
int exp2(const string& s, int& i);
int exp3(const string& s, int& i);
int number(const string& s, int& i);
int exp1(const string& s, int& i) {
  int acc = exp2(s, i);
  while (1) {
    if (s[i] == '+') acc += exp2(s, ++i);
    else if (s[i] == '-') acc -= exp2(s, ++i);
    else return acc;
  }
}
int exp2(const string& s, int& i) {
  int acc = exp3(s, i);
  while (1) {
    if (s[i] == '*') acc *= exp3(s, ++i);
    else if (s[i] == '/') acc /= exp3(s, ++i);
    else return acc;
  }
}
int exp3(const string& s, int& i) {
  if (s[i] == '(') {
    int ret = exp1(s, ++i);
    assert(s[i] == ')');
    i++;
    return ret;
  }
  return number(s, i);
}
int number(const string& s, int& i) {
  int acc = 0;
  while (isdigit(s[i])) {
    acc = acc * 10 + (s[i++] - '0');
  }
  return acc;
}

void solve() {
  string s; cin >> s;
  int i = 0;
  cout << exp1(s, i) << endl;
  assert(s[i] == '=');
}
signed main() {
  int T; cin >> T;
  while (T--) solve();
}



Measured memory_bytes: 3068
#include<bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;
int main()
{
	SPEED
	int n;
	cin >> n;
	if (n%1000==0)
	{
		cout <<  0;
	}
	else
		cout << 1000 - (n%1000);
	return 0;
}

Measured memory_bytes: 3648
#ABC080C
import numpy as np
N=int(input())
F = []
for i in range(N):
    F.append(list(map(int, input().split())))
P = []
for i in range(N):
    P.append(list(map(int, input().split())))

ans=-1*pow(10,10)
ans_tmp=0
Self=[0]*10
c=0
#営業時間を仮定
for i in range(pow(2,10)):
    ans_tmp=0
    if i !=0:
        i_tmp = i
        for j in range(10):
            Self[j]=i_tmp//pow(2,9-j)
            i_tmp-=Self[j]*pow(2,9-j)
        for k in range(N):
            c=np.dot(F[k],Self)
            ans_tmp+=P[k][c]
        if ans<ans_tmp:
            ans=ans_tmp
print(ans)

Measured memory_bytes: 21024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
const long long MOD = 1e9+7;
int main(){
    int n;
    cin >> n;
    long long c[n];
    rep(i,n) cin >> c[i];
    sort(c,c+n);
    long long nibeki[2*n];
    nibeki[0]=1;
    rep(i,2*n-1){
        nibeki[i+1]=2*nibeki[i];
        nibeki[i+1]%=MOD;
    } 
    long long ans = 0;
    rep(i,n){
        long long tmp = c[i];
        tmp%=MOD;
        long long rank = n-i;
        long long tmp2 = (rank-1)*nibeki[rank-2]+nibeki[rank-1];
        tmp2%=MOD;
        tmp*=tmp2;
        tmp%=MOD;
        tmp*=nibeki[2*n-rank];
        tmp%=MOD;
        ans+=tmp;
        ans%=MOD;
    }
    cout << ans << endl;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())
#define allsortg(v)sort(v.begin(),v.end(),greater<int>());
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
	cin.sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	cout << a + b + c - max(a, max(b, c)) << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int x,n;
	cin>>x;
	if(x==1) {cout<<1;return 0;}
	for(int i=2;i*i<=x;i++)
	for(int j=1;pow(i,j)<=x;j++)
	{
		if((x-pow(i,j))<(x-n)) n=pow(i,j);
	}
	cout<<n;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin >> s;
    vector<int> cnt (2, 0);
    for(int i = 0; i < s.size(); i++) cnt[s[i]-'0']++;
    int ans = min(cnt[0], cnt[1])*2;
    cout << ans;
}


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

int main() {
  int n;
  cin >> n ;
  
  int n1,n2,n3,n4;
  
  n4 = n%10;
  n=n/10;
  n3 = n%10;
  n=n/10;
  n2 = n%10;
  n=n/10;
  n1 = n;
  
  if ( ((n1==n2)&&(n2==n3)) ||  ((n2==n3)&&(n3==n4)) )
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
}


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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//
/* 最大公約数 */
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

/* 最小公倍数 */
long long lcm(long long a, long long b) {
  long long g = gcd(a, b);
  return a / g * b;  // Be careful not to overflow
}

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

  lint a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;

  return 0;
}

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

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define ffrvs(ii,nn,mm) for(int ii=nn;ii>=mm;ii--)
#define srt(vvv) sort(vvv.begin(),vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(),vvv.end())
#define Graph vector<vector<int>>
i64 inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;

//メモリ置き場
int h, w, n;

//inputします
void input() {
    cin >> h >> w >> n;
}

//ライブラリ置き場



//main
int main() {
    input();
    int x = max(h, w);
    int sum = 0;
    int ans = 0;
    while (sum < n) {
        sum += x;
        ans++;
    }
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 256
import Foundation

extension String {
    var argi: [Int] { return self.characters.split(" ").map { Int(String($0))! } }
}

let arr = readLine()!.argi

let h: Int = arr[0]
var w: Int = arr[1]

w += 2

var res: String = ""

for i in 0..<w {
    res += "#"
}
res += "\n"

for i in 0..<h {
    let input = readLine()
    res += "#" + input! + "#\n"
}

for i in 0..<w {
    res += "#"
}
res += "\n"

print(res)


Measured memory_bytes: 7008
import java.io.*
import java.util.*

fun solve(N: Int, v: IntArray){
    v.sorted().map{ it.toDouble() }.reduce{ a, b -> (a+b) / 2 }.let{ println(it) }
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val v = IntArray(N)
    for (i in 0 until N) {
        v[i] = sc.next().toInt()
    }
    solve(N, v)
}



Measured memory_bytes: 34088
#include <stdio.h>

int main(void) {
	int A, B, X;
	int asumikana;
	int ayaneru, mikakosi;
	if (scanf("%d%d%d", &A, &B, &X) != 3) return 1;
	asumikana = (X + 499) / 500;
	ayaneru = A * ((asumikana + 1) / 2);
	mikakosi = B * asumikana;
	if (ayaneru > mikakosi) ayaneru = mikakosi;
	if (asumikana % 2 == 1) {
		mikakosi = A * (asumikana / 2) + B;
		if (ayaneru > mikakosi) ayaneru = mikakosi;
	}
	printf("%d\n", ayaneru);
	return 0;
}



Measured memory_bytes: 2144
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int n, k;
double x[60], y[60], c[60];

double dist(double x1, double y1, double x2, double y2) {
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

bool jd(double tm) {
	int ct;

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

		for (int j = 0; j < n; j++)
			if (tm / c[j] >= dist(x[i], y[i], x[j], y[j]))
				ct++;

		if (ct >= k)
			return true;
	}

	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			double c1r = tm / c[i], c2r = tm / c[j];

			if (c1r + c2r >= dist(x[i], y[i], x[j], y[j])) {
				double a, b, s, t, u;
				double v[2], w[2];

				if (y[i] == y[j]) {
					b = (x[i] + x[j] + (c1r * c1r - c2r * c2r) / (x[j] - x[i])) / 2;
					v[0] = b;
					v[1] = b;
					w[0] = y[i] - sqrt(c1r * c1r - (b - x[i]) * (b - x[i]));
					w[1] = y[i] + sqrt(c1r * c1r - (b - x[i]) * (b - x[i]));
				}
				else {
					a = (x[i] - x[j]) / (y[j] - y[i]);
					b = (c1r * c1r - c2r * c2r - x[i] * x[i] - y[i] * y[i] 
						+ x[j] * x[j] + y[j] * y[j]) / (2 * (y[j] - y[i]));

					s = a * a + 1;
					t = a * b - a * y[i] - x[i];
					u = x[i] * x[i] + (b - y[i]) * (b - y[i]) - c1r * c1r;

					v[0] = (-t - sqrt(t * t - s * u)) / s;
					v[1] = (-t + sqrt(t * t - s * u)) / s;
					w[0] = a * v[0] + b;
					w[1] = a * v[1] + b;
				}

				for (int q = 0; q < 2; q++){
					ct = 0;

					for (int k1 = 0; k1 < n; k1++) {
						if (k1 == i || k1 == j || tm / c[k1] >= dist(v[q], w[q], x[k1], y[k1]))
							ct++;
					}

					if (ct >= k)
						return true;
				}
			}
		}
	}

	return false;
}

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

	for (int i = 0; i < n; i++)
		cin >> x[i] >> y[i] >> c[i];

	if (k == 1)
		cout << 0 << endl;
	else {
		double tmax = 1;

		while (!jd(tmax))
			tmax *= 2;

		double tmin = tmax / 2;

		while (tmax - tmin > 0.0000001) {
			double t1 = (tmax + tmin) / 2;

			if (jd(t1))
				tmax = t1;
			else
				tmin = t1;
		}

		cout << setiosflags(ios::fixed | ios::showpoint) << tmax << endl;
	}
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7



// void dfs(int r, int c, char p, int score) {
//     // cout << r << ", " << c << endl;
//     char curt = S[r][c];
//     if (p != '#' && curt == '#') score++;
//     if (r == H - 1 && c == W - 1) 
//     {
//         ans = min(ans, score);
//         return;
//     }

//     if (r == H - 1) 
//     {
//         dfs(r, c + 1, curt, score);
//     }
//     else if (c == W - 1)
//     {
//         dfs(r + 1, c, curt, score);
//     }
//     else
//     {
//         dfs(r + 1, c, curt, score);
//         dfs(r, c + 1, curt, score);
//     }
//     return;
// }

int main() {
    // https://atcoder.jp/contests/agc043/tasks/agc043_a

    int H, W;
    vector<string> S;
    vector<vector<int>> score;
    cin >> H >> W;
    S.resize(H);
    score.resize(H);
    rep(i, 0, H)
    {
        cin >> S[i];
        if (i == 0)
        {
            score[i].push_back((S[i][0] == '#') ? 1 : 0);
        }
        else
        {
            if (S[i - 1][0] == '.' && S[i][0] == '#')
            {
                score[i].push_back(score[i - 1][0] + 1);
            }
            else
            {
                score[i].push_back(score[i - 1][0]);
            }
        }
    }

    rep(i, 0, H)
    {
        rep(k, 1, W)
        {
            if (i == 0)
            {
                if (S[i][k - 1] == '.' && S[i][k] == '#')
                {
                    score[i].push_back(score[i][k - 1] + 1);
                }
                else
                {
                    score[i].push_back(score[i][k - 1]);
                }
            }
            else
            {
                int scoreUp = score[i - 1][k];
                if (S[i - 1][k] == '.' && S[i][k] == '#') scoreUp++;

                int scoreLeft = score[i][k - 1];
                if (S[i][k - 1] == '.' && S[i][k] == '#') scoreLeft++;

                score[i].push_back(min(scoreUp, scoreLeft));
            }
        }
    }

    cout << score[H - 1][W - 1] << endl;
    // dfs(0, 0, ' ', 0);

    // cout << ans << endl;
}


Measured memory_bytes: 384
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <time.h>
#include <random>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
long long eas[200000] = {};
int main() {
#define int long long
	int n;
	cin >> n;
	vector<int> a;
	REP(i, n) {
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}
	sort(a.begin(), a.end());
	long long ans = 0;
	for (int i = 1;i < n;++i) {
		ans += a[i - 1];
		if (a[i] > ans * 2) eas[i] = 1;
	}
	for (int i = n - 1;i >= 0;--i) {
		if (eas[i] == 1) {
			cout << n - i << endl;
			return 0;
		}
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 1400
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#define MOD 1000000007
#define rep(i,l,r) for(ll i=l;i<r;i++)

typedef long long ll;

ll calc(ll x) {
    if (x <= 0) return 1;
    else return 2 * calc(x - 1)%MOD;
}

int main() {
    ll n, a, cnt[50001] = {};
    bool flag = false;
    scanf("%lld", &n);
    rep(i, 0, n) {
        scanf("%lld", &a);
        if (n % 2 == a % 2) flag = true;
        cnt[a / 2]++;
    }
    if (n % 2) {
        if (cnt[0] != 1) flag = true;
        rep(i, 1, n / 2+1) {
            if (cnt[i] != 2) flag = true;
        }
    }
    else {
        rep(i, 0, n / 2) {
            if (cnt[i] != 2) flag = true;
        }
    }
    if (flag) printf("0");
    else {
        ll ans = calc(n / 2);
        printf("%lld", ans);
    }

    return 0;
}

Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define inf 1e13

struct knapsack{
    int wt, val;
};

int32_t main() {
    int N, W; cin>>N>>W;
    knapsack arr[N+1];
    for(int i=1; i<=N; i++) {
        cin>>arr[i].wt;
        cin>>arr[i].val;
    }

    int maxVal = N*1000;
    int dp[N+1][maxVal+1];
    for(int i=0; i<=maxVal; i++) dp[1][i] = inf;

    dp[1][0] = 0;
    dp[1][arr[1].val] = arr[1].wt;

    for(int i=2; i<=N; i++) {
        for(int j=0; j<=maxVal; j++) {
            dp[i][j] = dp[i-1][j];
            if(arr[i].val > j) continue;
            dp[i][j] = min(dp[i][j], arr[i].wt + dp[i-1][j - arr[i].val]);
        }
    }

    int res = 0;
    for(int i=0; i<=maxVal; i++) {
        if(dp[N][i] <= W) res = i;
    }

    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 81748
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){

  int x1, x2, x3, x4, x5;
  cin >>x1>>x2>> x3>> x4>> x5;

  if(x1 == 0) cout << 1 << endl;
  if(x2 == 0) cout << 2 << endl;
  if(x3 == 0) cout << 3 << endl;
  if(x4 == 0) cout << 4 << endl;
  if(x5 == 0) cout << 5 << endl;

  return 0;
}

Measured memory_bytes: 3516
#include <iostream>

using namespace std;

int main()
{
	int a,b,c,k;cin>>a>>b>>c>>k;

	int count=0;

	while(b<=a) b=b*2,count++;
	while(c<=b) c=c*2,count++;

	if(count<=k) cout<<"Yes";
	else cout<<"No";
}

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

void fastin(int &num) {
  bool negative = false;
  int c;
  num = 0;
  c = getchar();
  if (c == '-') {
    negative = true;
    c = getchar();
  }
  for (; (c > 47 && c < 58); c = getchar()) num = (num << 3) + (num << 1) + c - 48;
  if (negative) num *= -1;
}

void fastout(int64_t &n) {
  int64_t N = n, rev, count = 0;
  rev = N;
  if (N == 0) { 
    putchar('0');
    putchar('\n');
    return;
  }
  while ((rev % 10) == 0) { 
    ++count; rev /= 10;
  }
  rev = 0;
  while (N != 0) { 
    rev = (rev << 3) + (rev << 1) + N % 10;
    N /= 10;
  }
  while (rev != 0) { 
    putchar(rev % 10 + '0');
    rev /= 10;
  }
  while (count--) putchar('0');
  putchar('\n');
}

int main(){
    int N; fastin(N);
    vector<int> v(N);
    for (int i = 0; i < N; ++i) {
        fastin(v[i]); v[i] -= (i + 1);
    }
    sort(v.begin(), v.end());
    
    int b = v[N / 2];

    int64_t answer = 0;
    for (int i = 0; i < N; ++i) {
        answer += abs(v[i] - b);
    }
    
    fastout(answer);

    return 0;
}


Measured memory_bytes: 1024
from collections import Counter


def solve(n, arr):
    if arr[0] != 0:
        return 0

    c = Counter(arr)

    if c[0] != 1:
        return 0

    for i in range(max(c) + 1):
        if i not in c:
            return 0

    c = list(c.items())
    c.sort()

    prev = 1
    ans = 1
    mod = 998244353

    for _, i in c[1:]:
        ans *= pow(prev, i) % mod
        ans %= mod
        prev = i

    return ans


n = int(input())
arr = list(map(int, input().split()))

print(solve(n, arr))

Measured memory_bytes: 21468
n = int(input())
a = [int(i) for i in input().split()]
ans1 = [(i+1)*n for i in range(n)]
ans2 = [(i+1)*n for i in range(n-1,-1,-1)]
for i in range(n):
  ans2[a[i]-1] += i
print(*ans1)
print(*ans2)

Measured memory_bytes: 45700
#include<bits/stdc++.h>
using namespace std;
long long ans;
const int mod = 1e9+7;
struct Combination {
    long long *fac, *facInv, *inv;
    explicit Combination(int size) {
        fac = (long long *) malloc(sizeof(long long) * (size+1));
        facInv = (long long *) malloc(sizeof(long long) * (size+1));
        inv = (long long *) malloc(sizeof(long long) * (size+1));
        fac[0] = fac[1] = 1;
        facInv[0] = facInv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i <= size; ++i) {
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
            facInv[i] = facInv[i - 1] * inv[i] % mod;
        }
    }
    long long operator()(int n, int r) {
        if (n < r || n < 0 || r < 0) return 0;
        return fac[n] * facInv[r] % mod * facInv[n - r] % mod;
    }
};
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (auto & a : A) cin >> a;
    sort(A.begin(), A.end());
    long long tmp;
    auto ncr = Combination(100005);
    for (int i = K-1; i < N; ++i) {
        tmp = 0;
        if ((tmp += A[i]) < 0) tmp += mod;
        if ((tmp -= A[N-i-1]) < 0) tmp += mod;
        tmp %= mod;
        if ((ans += ncr(i, K-1) * tmp % mod) >= mod) ans -= mod;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3072
n=int(input())
ans = [0 for _ in range(n+1)]
for i in range(1,int((n+1)**0.5)):
    for j in range(1,n+1):
        for k in range(1,n+1):
            v = i*i+j*j+k*k+i*j+j*k+k*i
            if v > n:
                break
            ans[v]+=1
for i in range(n):
    print(ans[i+1])

Measured memory_bytes: 9592
#include<cstdio>
#include<cctype>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define mid (l+r>>1)
#define reg register
typedef long long ll;
template<typename T>inline T read(){
    reg T x=0;reg short f=1;reg char c=getchar();
    for(;!isdigit(c);f=c=='-'?-1:1,c=getchar());
    for(;isdigit(c);x=x*10+(c^48),c=getchar());
    return x*f;
}
char ch[10];
bool f1[11],f2[11];
inline bool query(ll k){
	printf("? %lld\n",k);fflush(stdout);
	scanf("%s",ch);return ch[0]=='Y';
}
inline void search(ll l,ll r){
	reg int res=0;
	while(l<=r)
		if(query(1ll*mid*10))res=mid,r=mid-1;
		else l=mid+1;
	printf("! %d\n",res);
}
int main(){
	reg int f=1;
	for(reg int i=1,x=10;i<=9;i++,x*=10){
		f1[i]=query(x);f2[i]=query(x-1);f&=f1[i];
	}
	if(f){
		reg int l=1,r=1e9;
		for(reg int i=1,x=10;i<=9;i++,x*=10){
			if(!f2[i])l=x;
			else r=min(r,x-1);
		}
		search(l,r);
	}
	else{
		reg int last=9,res=1e9;
		while(last&&!f1[last])last--,res/=10;
		search(res,1ll*res*10-1);
	}
    return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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; }

int main(void){
    int n; cin >> n;
    VI S(n); REP(i,n) cin >> S[i];
    int q; cin >> q;
    VI T(q); REP(i,q) cin >> T[i];
    int ans = 0;
    REP(i,q){
        int it = LB(S, T[i]);
        if(S[it] == T[i]) ans++;
    }
    cout << ans << en;
    return 0;
}


Measured memory_bytes: 3284
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define pi(n,m) n.insert(n.begin(),m);
#define ee(n) n.erase(n.end()-1)
#define eb(n) n.erase(n.begin())
#define check(n) reverse(all(n));rep(z,0,n.size())cout<<n[z];co("");reverse(all(n));
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  ll b,c=0,n,m;
  cin>>n>>m;
  vector<ll> a={};
  bool f=true;
  rep(i,0,n){
    cin>>b;
    pb(a,b);
  }
  vector<vector<ll>> x={};
  
  rep(i,0,n) pb(x,{});
  rep(i,0,m){
    ll na,nb;
    cin>>na>>nb;
    pb(x[na-1],nb-1);
    pb(x[nb-1],na-1);
  }
  rep(i,0,n){
    rep(j,0,x[i].size()){
      if(a[i]<=a[x[i][j]]) f=false;
    }
    if(f==true){
      c++;
    }
    f=true;
  }
  co(c);
    
  return 0;
}

Measured memory_bytes: 9824
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int main(void)
{
  for(;;){
    int m,a,b;
    cin >> m >> a >> b;
    if(m==0) return 0;
    vector<int> p(m);
    REP(i,m) cin >> p[i];
    pair<int,int> answer=make_pair(0,0);
    FOR(i,a,b+1){
      answer=max(answer,make_pair(p[i-1]-p[i],i));
    }
    cout << answer.second << endl;
  }
}

Measured memory_bytes: 3084
#include <iostream>
using namespace std;
int main(){
    long long int q, h, s, d, n;
    cin>>q>>h>>s>>d>>n;
    if(q*2<h) h=q*2;
    if(h*2<s) s=h*2;
    if(s*2<d) d=s*2;
    long long int ans=0;
    ans+=n/2*d;
    n%=2;
    ans+=n*s;
    cout<<ans;
    return 0;
}


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

using namespace std;

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

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<double> vd;

#define max_n 100
#define max_e (max_n * max_n)

double c[max_n][4];

double d(int a, int b){
    double x = c[a][0] - c[b][0];
    double y = c[a][1] - c[b][1];
    double z = c[a][2] - c[b][2];
    double ret = sqrt(x*x + y*y + z*z);
    ret = ret - c[a][3] - c[b][3];
    return ret;
}





class UnionFind{

private:
    vector<int> rank,p;

    void makeSet(int x){
      p[x] = x;
      rank[x] = 0;
    }

  public:
      UnionFind(){};
      UnionFind(int size){
        rank.resize(size,0);
        p.resize(size,0);
        for(int i = 0; i < size; i++){
          makeSet(i);
        }
      }

    bool same(int x, int y){
      return  find(x) == find(y);
    }

    void unite(int x, int y){
      link(find(x), find(y));
    }

    int find(int x){
      if(x != p[x]) p[x] = find(p[x]);
      return p[x];
    }

private:
    void link(int x, int y){
      if(rank[x] > rank[y]){
        p[y] = x;
      }else{
        p[x] = y;
        if(rank[x] == rank[y]) rank[y]++;
      }
    }

};




struct edge{
     int u, v;
     double cost;
 };

bool comp(const edge& e1, const edge& e2){
    return e1.cost < e2.cost;
}

edge es[max_e];
int v,e;

double kruskal(){
    sort(es, es+e, comp);
    UnionFind uf = UnionFind(v);
    double ret = 0;
    int i;
    rep(i,e){
        edge ee = es[i];
        if(!uf.same(ee.u, ee.v)){
            uf.unite(ee.u, ee.v);
            if(ee.cost > EPS)ret += ee.cost;
        }
    }
    return ret;
}


int main(void) {
    int i,j;
    int n;
    while(cin >> n, n){

        v = n;
        e = 0;

        rep(i,n)rep(j,4) cin >> c[i][j];
        double ans = 0;
        rep(i,n)rep(j,i){
            edge ee;
            ee.u = i;
            ee.v = j;
            ee.cost = d(i,j);
            es[e] = ee;
            e++;
        }

        cout << shosu(3) << kruskal() << endl;
    }
}



Measured memory_bytes: 3248
s = input()
#s = 'erasedream'

a1 = 'dreamerase'
a2 = 'dreamer'
a4 = 'dream'
a3 = 'eraser'
a5 = 'erase'

end = False
while (not end) and (len(s) > 0):
    if s.endswith(a1):
        s = s[:-len(a1)]
    elif s.endswith(a2):
        s = s[:-len(a2)]
    elif s.endswith(a3):
        s = s[:-len(a3)]
    elif s.endswith(a4):
        s = s[:-len(a4)]
    elif s.endswith(a5):
        s = s[:-len(a5)]
    else:
        end = True

if len(s) == 0:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3188
#include <stdio.h>

int main() {

	int a, hour, min, second;

	scanf("%d", &a);

	hour = a / (60 * 60);
	min = (a - hour * 60* 60) / 60;
	second = a - hour * 60 * 60 - min * 60;

	printf("%d:%d:%d\n", hour, min, second);

	return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    string s;
    cin >> s;
    vector<bool> dp(s.size() + 1, false);
    dp[0] = true;
    for (int i = 1; i < dp.size(); i++) {
        if (i >= 5 && dp[i - 5]) {
            if (s[i - 5] == 'd' && s[i - 4] == 'r' && s[i - 3] == 'e' && s[i - 2] == 'a' && s[i - 1] == 'm')
                dp[i] = true;
            else if (s[i - 5] == 'e' && s[i - 4] == 'r' && s[i - 3] == 'a' && s[i - 2] == 's' && s[i - 1] == 'e')
                dp[i] = true;
        }
        if (i >= 6 && dp[i - 6]) {
            if (s[i - 6] == 'e' && s[i - 5] == 'r' && s[i - 4] == 'a' && s[i - 3] == 's' && s[i - 2] == 'e' && s[i - 1] == 'r')
                dp[i] = true;
        }
        if (i >= 7 && dp[i - 7]) {
            if (s[i - 7] == 'd' && s[i - 6] == 'r' && s[i - 5] == 'e' && s[i - 4] == 'a' && s[i - 3] == 'm' && s[i - 2] == 'e' && s[i - 1] == 'r')
                dp[i] = true;
        }
    }
    if (dp[dp.size() - 1])
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;

using namespace std;

bool comp_second(pair<ll, ll>& a, pair<ll,ll>& b)
{
    return (a.second < b.second);
}

int main()
{
    ll n;

    cin >> n;
    vector<pair<ll, ll>> data(n);

    for (ll i=0; i<n; ++i)
    {
        cin >> data[i].first >> data[i].second;
    }

    sort(data.begin(), data.end(), comp_second);

    ll sum (0);
    for (auto j: data)
    {
        sum += j.first;
        if (sum > j.second)
        {
                cout << "No" << endl;
                return 0;
        }
    }
    
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    int k,n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int mx = a[0]+k-a[n-1];
    rep(i,n-1) {
        chmax(mx,a[i+1]-a[i]);
    }
    cout << k-mx << endl;
}

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

int main() {
  int cnt = 0;
  int col, row;
  cin >> col >> row;
  char a[col][row];
  
  for( int i = 0; i < col; i++){
    for( int j = 0; j < row; j++){
      cin >> a[i][j];
    }
  }
  
  const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
  const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
  
  for( int i = 0; i < col; i++){
    for( int j = 0; j < row; j++){
      
      if(a[i][j] == '.'){
        cnt = 0;
        
        for(int d = 0; d < 8; d++){
          const int ni = i + dy[d];
          const int nj = j + dx[d];

          if (ni < 0 or col <= ni) continue;
          if (nj < 0 or row <= nj) continue;
          if (a[ni][nj] == '#') cnt++;
        }
        cout << cnt;
      }
      else
        cout << '#';
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#pragma comment (linker, "/STACK:526000000")
#define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(100);
}

void solve(){
	string s;
	cin >> s;
	REP(i, s.length()) {
		cout << "x";
	}
	cout << endl;
}

int main() {
	init();
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B =0, C =0, D =0;
  
  cin >> A;
  vector<int> OOT(100);
  for(int YUNI =0; YUNI < A;YUNI++){
    cin >> OOT.at(YUNI);
  }
  
  for(int YUNI =0; YUNI < A;YUNI++){
    B = *max_element(OOT.begin(), OOT.end());
    if(B != C){
      D ++;
    }
    C = B;
    vector<int>::iterator E = max_element(OOT.begin(), OOT.end());
    size_t F = distance(OOT.begin(), E);
    OOT.at(F) = 0;
  }
  cout << D << endl;
}

Measured memory_bytes: 3612
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }

  while (a % b != 0) {
    ll tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

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

ll N, M;
string S, T;
ll L;

ll solve() {
  map<ll, char> mp;
  for (ll i = 0; i < N; i++) {
    ll idx = i * (L / N) + 1;
    mp[idx] = S[i];
  }

  for (ll i = 0; i < M; i++) {
    ll idx = i * (L / M) + 1;
    if (mp.find(idx) != mp.end() && mp[idx] != T[i]) {
      return -1;
    }
  }

  return L;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  cin >> S >> T;
  L = lcm(N, M);

  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
int h,w,cnt[26],ok[5];
char s[105][105];
int main()
{
    scanf("%d%d",&h,&w);
    for (int i=0;i<h;++i)
        scanf("%s",s[i]);
    for (int i=0;i<h;++i)
        for (int j=0;j<w;++j)
            ++cnt[s[i][j]-'a'];
    for (int i=0;i<26;++i) {
        ok[4]+=cnt[i]/4;
        cnt[i]%=4;
        ok[2]+=cnt[i]/2;
        cnt[i]%=2;
        ok[1]+=cnt[i];
    }
    if (w%2==1)
        swap(h,w);
    if (h%2==0&&w%2==0) {
        if (ok[1]||ok[2])
            puts("No");
        else
            puts("Yes");
        return 0;
    }
    if (h%2==1&&w%2==0) {
        if (ok[1]) {
            puts("No");
            return 0;
        }
        int four=(h-1)*w/4;
        if (four>ok[4]) {
            puts("No");
            return 0;
        }
        puts("Yes");
        return 0;
    }
    if (h%2==1&&w%2==1) {
        if (ok[1]>1) {
            puts("No");
            return 0;
        }
        int four=(h-1)*(w-1)/4;
        if (four>ok[4]) {
            puts("No");
            return 0;
        }
        puts("Yes");
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
ll f(int n,int k){
  if(n==1)return 0;
  return (f(n-1,k)+k)%n;
}
void solve(){
  ll n,k,m;
  cin >> n >> k >> m;
  if(n==0) return;
  cout << (f(n-1,k)+m)%n+1<<endl;
  solve();
}
int main(){
  solve();
}



Measured memory_bytes: 3276
#include<iostream>
using namespace std;
int main() {
	int n = 1, Acard,Bcard,Ascore=0,Bscore=0;
	while (n) {
		cin >> n;
		if (n == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> Acard >> Bcard;
			if (Acard > Bcard) {
				Ascore += Acard + Bcard;
			}
			else if (Acard < Bcard) {
				Bscore += Acard + Bcard;
			}
			else {
				Ascore += Acard;
				Bscore += Bcard;
			}
		}
		cout << Ascore << " " << Bscore<<endl;
		Ascore = 0; Bscore = 0;
	}
	return 0;
}

Measured memory_bytes: 2980
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>

using namespace std;

int main() {
	int n;
	cin >> n;
	map<string, int > m;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		if (m[s] == 1)continue;
		m[s] = 1;
		ans++;
	}
	cout << ans;
}

Measured memory_bytes: 19180
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,m;
    cin >> n >> m;
    cout << max(max(n + m, n - m), n * m) << endl;
    return 0;
}

Measured memory_bytes: 256