akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n, k;
int a[500];

int getCost(int x) {
	vector<int> vec;
	int i;
	
	rep(i, n) {
		vec.push_back(a[i] % x);
	}
	sort(vec.begin(), vec.end());
	
	int lcost[514];
	int rcost[514];
	
	lcost[0] = 0;
	rep(i, n) {
		lcost[i + 1] = lcost[i] + vec[i];
	}
	
	rcost[0] = 0;
	rep(i, n) {
		rcost[i + 1] = rcost[i] + (x - vec[n - 1 - i]);
	}
	
	rep(i, n) {
		if (lcost[i] >= rcost[n - i]) break;
	}
	
	int id = i;
	int ret = 0;
	rep(i, n) {
		if (i < id) ret += vec[i];
		else ret += x - vec[i];
	}
	//cout << "x = " << x << ", ret = " << ret << endl;
	return ret / 2;
}

signed main() {
	int i;
	
	cin >> n >> k;
	rep(i, n) cin >> a[i];
	
	int sumA = 0;
	rep(i, n) sumA += a[i];
	
	vector<int> yaku;
	for (i = 1; i * i <= sumA; i++) {
		if (sumA % i == 0) {
			yaku.push_back(i);
			if (sumA / i != i) yaku.push_back(sumA / i);
		}
	}
	
	int ans = 0;
	for (i = 0; i < yaku.size(); i++) {
		int x = yaku[i];
		int res = getCost(x);
		if (res <= k) {
			ans = max(ans, x);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)

	c0, c1, c2, c3 := 0, 0, 0, 0
	var s string
	for i := 0; i < n; i++ {
		fmt.Scan(&s)

		c0 += strings.Count(s, "AB")

		l := len(s) - 1
		if s[0] == 'B' && s[l] == 'A' {
			c1++
		} else if s[0] == 'B' && s[l] != 'A' {
			c2++
		} else if s[0] != 'B' && s[l] == 'A' {
			c3++
		}
	}

	var ab int
	if c1 == 0 {
		ab = min(c2, c3)
	} else if c2+c3 > 0 {
		ab = min(c2, c3) + c1
	} else if c2+c3 == 0 {
		ab = c1 - 1
	}

	fmt.Println(c0 + ab)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


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

int main() {
  int n;
  cin>>n;
  long long int a;
  vector<long long int> vec(60);
  for(int i=0;i<n;i++){
    cin>>a;
    bitset<60> bit(a);
    for(int j=0;j<60;j++){
      if(bit.test(j)){
        vec.at(j)++;
      }
    }
  }
  
  //for(int i=0;i<60;i++){
   // cout<<vec.at(i);
  //}
  
  long long int mod=1000000007;
  long long int answer=0,p=1,q=0;
  for(int i=0;i<60;i++){
    for(int j=0;j<i;j++){
      p*=2;
      p%=mod;
    }
    q+=p*(vec.at(i)%mod);
    q%=mod;
    q*=(n-vec.at(i))%mod;
    answer+=q;
    answer%=mod;
    p=1,q=0;
  }
  cout<<answer%mod<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long util( vector<vector<long long>> & dp,int val[],int wei[],int n,int w)
{
    if(n==0 || w<=0)
    return 0;
    
    if(dp[n][w]!=-1)
    return dp[n][w];
    if(wei[n-1]>w)
    dp[n][w]=util(dp,val,wei,n-1,w);
    else
    dp[n][w]=max(util(dp,val,wei,n-1,w-wei[n-1])+val[n-1],util(dp,val,wei,n-1,w));
    
    return dp[n][w];
}

int main() {
	int n;
	cin>>n;
	int w;
	cin>>w;
	int val[n];
	int wei[n];
	for(int i=0;i<n;i++)
	{
	    cin>>wei[i];
	    cin>>val[i];
	}
	vector<vector<long long>> dp(n+1,vector<long long> (w+1,-1));
	
	cout<<util(dp,val,wei,n,w);
	
	

	return 0;
}

Measured memory_bytes: 80256
import bisect
f = lambda: map(int,input().split())
n = int(input())
a = sorted(list(f()))
b = sorted(list(f()))
c = sorted(list(f()))

ans = 0
for i in b:
    ans += bisect.bisect_left(a,i)*(n-bisect.bisect(c,i))
print(ans)

Measured memory_bytes: 23244
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using pint = pair<int,int>;

long long N, Q, K, D;
void solve() {
    --K, --D;
    long long pK = K, pD = D;
    for (int i = 0; i < Q; ++i) D = D * 2 % N;
    long long diff = (K - D + N) % N;

    // tmp: 逆順で見たときの 0: 2x、1: 2x+1
    vector<long long> tmp;
    while (diff) {
        tmp.push_back(diff & 1);
        diff >>= 1;
    }
    if (tmp.size() > Q) { cout << -1 << endl; return; }
    while (tmp.size() < Q) tmp.push_back(0);
    reverse(tmp.begin(), tmp.end());

    // 実際の操作に適合した復元
    vector<long long> res;
    for (int q = 0; q < tmp.size(); ++q) {
        long long nD = pD * 2;
        if (tmp[q]) ++nD;
        nD %= N;

        // nD -> pD が実際には 0 なのか 1 なのかを判定
        if (nD % 2 == 0) {
            if (pD == nD/2) res.push_back(0);
            else res.push_back(1);
        }
        else {
            if (pD == nD/2) res.push_back(1);
            else res.push_back(0);
        }
        pD = nD;
    }
    reverse(res.begin(), res.end());
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

int main() {
    cin >> N >> Q >> K >> D;
    solve();
}



Measured memory_bytes: 22288
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
#define ll long long
#define inf 0x7fffffff
inline int read()
{
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
} 
int main()
{
	int n=read(),a=read(),b=read();
	if((a+b)&1) puts("Borys");
	else puts("Alice");
}

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

using namespace std;

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

   if (abs(a - c) <= d) {
      cout << "Yes" << endl;
   } else if (abs(b - c) <= d && abs(a - b) <= d) {
      cout << "Yes" << endl;
   } else {
      cout << "No" << endl;
   }
   return 0;
}


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

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

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

    vector<ll> a(n);
    REP(i, n){
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());

    vector<ll> f(n);
    REP(i, n){
        cin >> f.at(i);
    }
    sort(f.begin(), f.end(), greater<ll>());

    ll lo = 0;
    ll hi = *max_element(a.begin(), a.end()) * *max_element(f.begin(), f.end());
    while(lo < hi){
        const ll mid = (lo + hi) / 2;

        ll tmp = 0;
        REP(i, n){
            const ll fi2 = mid / f.at(i);
            tmp += max(0LL, a.at(i) - fi2);
        }
        bool is_ok = (tmp <= k);

        if(is_ok){
            hi = mid;
        }else{
            lo = mid + 1;
        }
    }
    cout << lo << endl;
    return 0;
}


Measured memory_bytes: 3328
using System.Collections.Generic;
using static System.Console;

class Program {
	static void Main() {
		var S = ReadLine();
		var dic = new HashSet<char> { };

		foreach (var c in S) {
			if (dic.Contains(c)) {
				WriteLine("no");
				return;
			}
			dic.Add(c);
		}
		WriteLine("yes");
	}
}


Measured memory_bytes: 11348
N = int(input())
monster = list(map(int, input().split()))
def gcd(a, b):
	if b > 0 :
		return gcd(b, a % b)
	else:
		return a
if len(monster) == 1 :
	print(monster[0])
else:
	mon = gcd(monster[0], monster[1])
	if len(monster) != 2 :
		for i in range(2, N) :
			mon = gcd(mon, monster[i])
print(mon)

Measured memory_bytes: 14252
N=int(input())
A=list(map(int, input().split()))
cnt=0
for i in range(N):
  if A[i]<0:
    A[i]*=-1
    cnt+=1
A=list(map(abs, A))
A.sort()
if cnt&1==0:
  print(sum(A))
else:
  print(sum(A[1:])-A[0])

Measured memory_bytes: 14412
n = gets.chomp.to_i
a, t = 1, 1
n.times do
  aa, tt = gets.chomp.split(' ').map(&:to_i)
  base = aa + tt
  n = case
    when a % aa == 0 && t % tt == 0 then
      [a / aa, t / tt].max
    when a % aa == 0 && t % tt != 0 then
      [a / aa, t / tt + 1].max
    when a % aa != 0 && t % tt == 0 then
      [a / aa + 1, t / tt].max
    when a % aa != 0 && t % tt != 0 then
      [a / aa + 1, t / tt + 1].max
  end
  a = n * aa
  t = n * tt
end

puts (a + t)

Measured memory_bytes: 1916
from collections import Counter


def resolve():
    n = int(input())
    d = list(map(int, input().split()))
    c = Counter(d)
    m = sorted(c)[-1]
    ans = 1
    if d[0] != 0 or c[0] != 1:
        print(0)
        return
    for i in range(1, m + 1):
        if not i in c:
            print(0)
            return
        ans *= c[i - 1] ** c[i]
        ans %= 998244353
    print(ans)


if __name__ == '__main__':
    resolve()


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

int main(){
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i=1;i<N;i++){
    int A;
    cin >> A;
    int B=v.at(A-1);
    v.at(A-1) = B+1;
  }
  for (int i=0;i<N;i++){
    cout << v.at(i) << endl;
  }
}

Measured memory_bytes: 4052
import java.util.Scanner;

public class Main {
static final String APPLE = "apple";
static final String PEACH = "peach";
static final String D     = "\nP\n";

public static void main(String[] args) {
  Scanner in = new Scanner(System.in);
  while (in.hasNextLine()) {
	String text =
	    in.nextLine().replace(APPLE, D)
	        .replace(PEACH, APPLE)
	        .replace(D, PEACH);
	System.out.println(text);
  }
}
}

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

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ull unsigned long long
#define rep(n) for(ll i = 0 ; i<n ; i++) 
#define rep2(n) for(ll j=0 ; j<n ; ++j )
#define repd(n) for(ll i = n-1 ; i>=0 ; i--)
#define MOD 1000000007
#define pii pair<ll,ll>
#define vll vector<ll>
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define INF 1e18
#define sz(a) a.size() 
#define all(a) a.begin(),a.end()
#define M 998244353
#define limit 100000000
void solve() {
	ll n, a ,b ; cin >> n >> a >> b ;
	if(n%(a+b)==0) cout << n/(a+b)*a ;
	else cout << n/(a+b)*a + min(n%(a+b),a) ;
}

int main() {

    fast;
	ll t=1;
	// cin>>t;
	rep(t) {
		solve() ;
	}
	return 0;
}

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

int h, w, m, t;
bool s[2010][2010];
int l[2010][2010], r[2010][2010], u[2010][2010], d[2010][2010];
char c;

int main(){
	cin >> h >> w;
	for (int i = 0; i < h; ++i){
		for (int j = 0; j < w; ++j){
			cin >> c;
			s[i][j] = (c == '#');
		}
	}
	for (int i = 0; i < h; ++i){
		for (int j = 0; j < w; ++j){
			if (s[i][j]){
				l[i][j] = 0;
				d[i][j] = 0;
			}
			else{
				if (j == 0) l[i][j] = 1;
				else l[i][j] = l[i][j-1] + 1;
				if (i == 0) d[i][j] = 1;
				else d[i][j] = d[i-1][j] + 1;
			}
		}
	}
	for (int i = h-1; i >= 0; --i){
		for (int j = w-1; j >= 0; --j){
			if (s[i][j]){
				r[i][j] = 0;
				u[i][j] = 0;
			}
			else{
				if (j == w-1) r[i][j] = 1;
				else r[i][j] = r[i][j+1] + 1;
				if (i == h-1) u[i][j] = 1;
				else u[i][j] = u[i+1][j] + 1;
			}
		}
	}
	m = 0;
	for (int i = 0; i < h; ++i){
		for (int j = 0; j < w; ++j){
			t = l[i][j] + r[i][j] + u[i][j] + d[i][j];
			if (m < t) m = t;
		}
	}
	cout << (m-3);
}

Measured memory_bytes: 67328
#include <bits/stdc++.h>
 
#define int long long
 
// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << x << '\n'
 
// typedef
typedef std::vector<int> VI;
typedef std::vector<VI> VII;
typedef std::vector<bool> VB;
typedef std::vector<std::string> VS;

std::string yes = "Yes\n";
std::string no = "No\n";

void solve();

signed main() {
  solve();
  return 0;
}

void solve() {
  int a, p;
  std::cin >> a >> p;
  cout((3 * a + p) / 2);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fastio std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int inf = 1e9 +5;
using namespace std;

int main() {
	fastio;
	int n,k;
	cin>>n>>k;
	vector<int> h(n);
	for(int i=0;i<n;i++)
	    cin>>h[i];
	vector<int> dp(n,inf);
	dp[0]=0;
	for(int i=0;i<n;i++){
	    for(int j = i+1; j<=i+k;j++)
	        if(j<n)
	            dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
	}
	cout<<dp[n-1];
	return 0;
}

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

string s;
ll ans = 0;
ll ds(string s)
{
	ll res= 0;
	for(ll i =0;i<s.size();i++)
	{
		res += s[i]-'0';
	}
	return res;
}

int main()
{
	cin >> s;
	ans = ds(s);
	for(ll i = 0;i<s.size()-1;i++)
	{
		string t = s;
		if('0'<t[i])
		{
			t[i]-=1;
			for(int j = i+1;j<s.size();j++)
			{
				t[j]='9';
			}
			ans = max(ans,ds(t));
			//cout<<t<<endl;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define mid ((l + r) >> 1)
#define lson (x << 1)
#define rson ((x << 1) | 1)
using namespace std;
typedef long long LL;

LL val[800005] = {0};

void pushup(LL x){
	val[x] = max(val[lson],val[rson]);
}

void modify(LL x,LL l,LL r,LL L,LL R,LL v){
	if(L > R) return;
	if(L <= l && r <= R){
		val[x] = max(val[x],v);
		return;
	}
	if(L <= mid) modify(lson,l,mid,L,R,v);
	if(R > mid) modify(rson,mid + 1,r,L,R,v);
	pushup(x);
}

LL query(LL x,LL l,LL r,LL L,LL R){
	if(L > R) return 0;
	if(L <= l && r <= R) return val[x];
	LL ret = 0;
	if(L <= mid) ret = max(ret,query(lson,l,mid,L,R));
	if(R > mid) ret = max(ret,query(rson,mid + 1,r,L,R));
	pushup(x); return ret;
}

LL n;
LL h[200005];
LL a[200005];
LL dp[200005] = {0};

int main(){
	scanf("%lld",&n);
	for(LL i = 1;i <= n;i ++) scanf("%lld",&h[i]);
	for(LL i = 1;i <= n;i ++) scanf("%lld",&a[i]);
	LL ans = 0;
	for(LL i = 1;i <= n;i ++){
		dp[i] = query(1,1,n,1,h[i]) + a[i];
		modify(1,1,n,h[i],h[i],dp[i]);
		ans = max(ans,dp[i]);
	}
	printf("%lld\n",ans);
	return 0;
}
//

Measured memory_bytes: 10496
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def f(A, B):
    return max(len(str(A)), len(str(B)))


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    ret = MAX
    for n in range(1, int(math.sqrt(N)) + 1):
        if N % n == 0:
            b = N // n
            r = f(n, b)
            ret = min(r, ret)
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10136
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <limits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
int main(){
    int n,d;
    int count = 0;
    cin >> n >> d;
    int point[11][11];
    rep1(i,n){
        rep1(j,d){
            cin >> point[i][j];
        }
    }
    rep1(i,n){
        for(int j = i + 1;j <= n;j++){
            int sum = 0;
            rep1(k,d){
                sum += pow(point[i][k] - point[j][k],2);
            }
            double a = sqrt(sum);
            int b = a;
            if(a == b) count++;
        }
    }

    cout << count << endl;
}

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

public class App
{
    public static void Main(string[] args)
    {
        long n=long.Parse(Console.ReadLine())-1;
        long[] a = new long[5];
        a[0]=long.Parse(Console.ReadLine());
        a[1]=long.Parse(Console.ReadLine());
        a[2]=long.Parse(Console.ReadLine());
        a[3]=long.Parse(Console.ReadLine());
        a[4]=long.Parse(Console.ReadLine());
      	Console.WriteLine(n/a.Min()+5);
    }
}


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

//A,Bの最大要素数
#define MAX_SIZE 100
//使用する変数の宣言と初期化
int A=0,B=0,result=0,n;

int main()
{
  //A,B入出力受取り
  cin >> A >> B;

  //処理
  if(A<=2*B) result = 0;
  else result = A-2*B;
  
  cout << result;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	long long N;
	scanf("%lld", &N);
	
	int p, q;
	long long div = 0, ans = 1;
	for (p = 2; p <= N; p++) {
		for (q = 2; q * q <= p; q++) if (p / q * q == p) break;
		if (q * q <= p) continue;
		for (q = (int)N / p, div = 0; q >= 1; q /= p) div += q;
		ans = ans * (div + 1) % 1000000007;
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

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

int main() {

  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];

  sort(a.begin(), a.end());

  cout << a[0] << " " << a[1] << " " << a[2] << endl;

  return 0;

}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
vector<string>v;
vector<int>ansl;
string s;
int ary[100005] = {0};
int mp[51][51];
int cnt = 0;
int d_x[] = {0,1,0,-1};
int d_y[] = {1,0,-1,0};
int W,H;

void dfs(int x,int y){
  mp[y][x] = 0;
  for(int dx = -1;dx<2;dx++){
    for(int dy = -1;dy<2;dy++){
    int nx = x+dx,ny = y+dy;
    if((nx>=0)&&(ny>=0)&&(ny<H)&&(nx<W)&&(mp[ny][nx] == 1)){
      dfs(nx,ny);
    }
  }
}
}
int main(){
  cin >>W>>H;

  while((W!=0)&&(H!=0)){
    cnt = 0;
    for(int i = 0;i<51;i++){
      for(int j = 0;j<51;j++){
        mp[i][j] = 0;
      }
    }
    for(int i = 0;i<H;i++){
      for(int j = 0;j<W;j++){
        cin >>mp[i][j];
      }
    }
    for (int y = 0; y < H; y++){
      for (int x = 0; x < W; x++) {
        if (mp[y][x] == 1) {
          dfs(x, y);
          cnt++;
        }
      }
    }
    cout <<cnt<<endl;
    cin >>W>>H;
  }
  return 0;
}



Measured memory_bytes: 3312
#include <iostream>
using namespace std;
int main()
{
	int a,b,c,d,e,k;
	cin >> a >> b >> c >> d >> e >> k;
	if(e-a<=k)
		cout << "Yay!" << endl;
	
	else cout << ":(" << endl;
	
	return 0;
}

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

using namespace std;

int a[105];

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < 2 * n; i++) {
		scanf("%d", a + i);
	}
	int ans = 0;
	sort(a, a + 2 * n);
	for (int i = 1; i < 2 * n; i += 2) {
		ans += min(a[i], a[i - 1]);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n;
    P a[212345];

    cin >> n;
    REP(i, n)
    cin >> a[i].second >> a[i].first;

    sort(a, a + n);

    int t = 0;

    REP(i, n)
    {
        swap(a[i].first, a[i].second);

        t += a[i].first;

        if (t > a[i].second)
        {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 1920
n,k=map(int,input().split())
a=list(map(int,input().split()))
p=[0]*n
s=0
for i in range(n):
    p[i]=(a[i]*(a[i]+1))/2*1/a[i]
for i in range(k):
    s+=p[i]
ans=s
for i in range(k,n):
    s+=p[i]
    s-=p[i-k]
    ans=max(ans,s)
print(ans)


Measured memory_bytes: 24552
// Lec05-A Print a Rectangle
#include<iostream>
int main(){
  int i,j,h,w;
  while(1){
    std::cin >> h >> w;
    if(h == 0 && w == 0) return 0;
    for(i=0; i<h; i++){
      for(j=0; j<w; j++) std::cout << "#";
      std::cout << std::endl;
    }
    std::cout << std::endl;
  }
}

Measured memory_bytes: 3068
/*
    Author : Pranav_Raut.
*/

#include<bits/stdc++.h>
using namespace std;
#define input(arr,n) for(ll i=0;i<n;i++){cin>>arr[i];}
typedef long long int ll;
ll MOD = 1000000007;
ll MAXN = 100005;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll t = 1;
    while(t--)
    {
        /* JUST CODE TILL YOU CRACK IT !!! */
		ll n;
      	cin>>n;
      	ll a[n],b[n],c[n];
      	for(ll i=0;i<n;++i)
        {
        	cin>>a[i]>>b[i]>>c[i];
        }
      	for(ll i=n-2;i>=0;--i)
        {
          	a[i] += max(b[i+1],c[i+1]);
          	b[i] += max(a[i+1],c[i+1]);
          	c[i] += max(b[i+1],a[i+1]);
        }
        cout<<max(a[0],max(b[0],c[0]))<<endl;
    }
    return 0;
}


Measured memory_bytes: 2560
import sys


class SegTree():
    def __init__(self, lists, function, basement):
        self.n = len(lists)
        self.K = (self.n-1).bit_length()
        self.f = function
        self.b = basement
        self.seg = [basement]*2**(self.K+1)
        X = 2**self.K
        for i, v in enumerate(lists):
            self.seg[i+X-1] = v

        for i in range(2*X-2, 0, -2):
            self.seg[(i-1) >> 1] = self.f(self.seg[i], self.seg[i-1])

    def update(self, k, value):
        X = 2**self.K
        k += X-1
        self.seg[k] = value
        while k:
            k = (k-1) >> 1
            self.seg[k] = self.f(self.seg[(k << 1)+1], self.seg[(k << 1)+2])

    def query(self, L, R):
        num = 2**self.K-1
        L += num
        R += num
        vL = self.b
        vR = self.b
        while L < R:
            if L & 1 == 0:
                vL = self.f(vL, self.seg[L])
                L += 1
            if R & 1 == 0:
                R -= 1
                vR = self.f(self.seg[R], vR)
            L >>= 1
            R >>= 1
        return self.f(vL, vR)


input = sys.stdin.readline


def main():
    N = int(input())
    S = list(input())
    Q = int(input())
    que = [tuple(input().split()) for i in range(Q)]
    alpha = "abcdefghijklmnopqrstuvwxyz"
    Data = {alpha[i]: [0]*N for i in range(26)}
    for i in range(N):
        Data[S[i]][i] += 1
    SEG = {alpha[i]: SegTree(Data[alpha[i]], max, 0) for i in range(26)}
    for X, u, v in que:
        if X == "1":
            u = int(u)-1
            NOW = S[u]
            S[u] = v
            SEG[NOW].update(u, 0)
            SEG[v].update(u, 1)
        else:
            u, v = int(u)-1, int(v)-1
            res = 0
            for j in range(26):
                res += SEG[alpha[j]].query(u, v+1)
            print(res)


if __name__ == "__main__":
    main()

Measured memory_bytes: 392196
#include<stdio.h>
#include<string.h>

#define N 1000000
#define L 12


int insert(char *);
int hash1(int);
int hash2(int);
int find(char *);
long long getkey(char *);
char H[N][L];

int main() {
  int i,n,h;
  char str[L],com[9];
  for(i = 0;i < N;i++){
    H[i][0]='\0';
  }
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%s%s",com,str);

    if(com[0] == 'i'){
      insert(str);
    }else {
      if(find(str)){
        printf("yes\n");
      }
      else{
        printf("no\n");
      }
    }
  }
  return 0;
}

int A(char ch){ //??????????????°????????????
  if(ch == 'A'){
    return 1;
  }
  else if(ch == 'C'){
    return 2;
  }
  else if(ch == 'G'){
    return 3;
  }
  else if(ch == 'T'){
    return 4;
  }
  else return 0;
}

long long getkey(char str[]){//??????????????°??????key
  long long sum=0,p=1,i;
  for(i = 0;i < strlen(str);i++){
    sum += p*(A(str[i]));
    p *= 5;
  }
  return sum;
}

int hash1(int key){
  return key%N;
}

int hash2(int key){
  return 1+(key%(N-1));
}

int find(char str[]){
  long long key,i,h;
  key = getkey(str);//??????????????°???
  for(i = 0;;i++){
    h = (hash1(key)+i*hash2(key))%N;
    if(strcmp(H[h],str)==0){
      return 1;
    }
    else if(strlen(H[h])==0){
      return 0;
    }
  }
  return 0;
}

int insert(char str[]){
  long long key,i,h;
  key = getkey(str);//??????????????°???
  for(i = 0;;i++){
    h=(hash1(key)+i*hash2(key))%N;
    if(strcmp(H[h],str)==0){
      return 1;
    }
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 12324
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{

    class Program
    {
        private const long COMDIV = 1000000007;

        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            Console.WriteLine(s.Count(x => x == '2'));
        }
    }
}

Measured memory_bytes: 26104
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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 main() {
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n) cin >> a[i];
    int s = 0;
    rep(i,n) {
        s ^= a[i];
    }
    vector<int>ans;
    rep(i,n) {
        ans.push_back(s^a[i]);
    }
    rep(i,ans.size()) {
        cout << ans[i] <<" ";
    }
    cout << endl;
}

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

#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, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
// constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;


int main(){
  string S;
  cin >> S;
  cout << S[0]<<S[1]<<S[2] << endl;
  return 0;
}


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

#define ll long long
#define MAX 500001
#define node pair<int,int>

vector<int> yoi(MAX);
vector<int> tree(MAX);
vector<int> ans(MAX);
vector<node> save_idx;

vector<int> balls;
vector<node> intes;

ll N,Q;


void update_tree(int index, int value)
{
    while (index <= N)
    {
        tree[index] += value;
        index += index & (-index);
    }
}

int get_sum(int index)
{
    int s = 0;
    while (index > 0)
    {
        s+= tree[index];
        index -= index & (-index);
    }

    return s;
}

bool cmpfn(node a, node b){
    return a.second < b.second;
}

int main() 
{
    cin >> N >> Q;
    for (int i = 0; i < N; i++)
    {
        int tmp;
        cin >> tmp;
        balls.push_back(tmp);
    }

    for (int i = 0; i < Q; i++)
    {
        int l,r;
        cin >> l >> r;
        // index + 1
        intes.push_back(make_pair(l,r));
        save_idx.push_back(make_pair(i, r));
    }

    sort(intes.begin(), intes.end(), cmpfn);
    sort(save_idx.begin(), save_idx.end(), cmpfn);

    for (int i = 0; i < N+1; i++)
    {
        tree[i] = 0;
    }

    int prev_r = 0;
    int count = 0;
    for (auto inte: intes)
    {
        int cu_r = inte.second;
        if (cu_r > prev_r)
        {
            for (int i = prev_r+1; i <= cu_r; i++)
            {
                int c = balls[i-1];
                if (yoi[c] == 0)
                {
                    update_tree(i, 1);
                }
                else
                {
                    update_tree(yoi[c], -1);
                    update_tree(i, 1);
                }

                yoi[c] = i;
            }
        }

        int sum = get_sum(cu_r) - get_sum(inte.first - 1);

        ans[save_idx[count].first] = sum;
        // ans[count] = sum;
        prev_r = cu_r;
        count++;
    }

    for (int i = 0; i < Q; i++)
    {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 22752
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int h = in.nextInt();
            int n = in.nextInt();
            int[] a = new int[n];
            int[] b = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                b[i] = in.nextInt();
            }
            int MAX = 20007;
            int[] dp = new int[MAX + 1];
            Arrays.fill(dp, Integer.MAX_VALUE);
            for (int i = 0; i < n; i++) {
                dp[a[i]] = Math.min(dp[a[i]], b[i]);
                for (int j = 1; j <= MAX; j++)
                    if (dp[j] != Integer.MAX_VALUE) {
                        int nextValue = j + a[i];
                        if (nextValue <= MAX)
                            dp[nextValue] = Math.min(dp[nextValue], dp[j] + b[i]);
                    }
            }
            int ans = Integer.MAX_VALUE;
            for (int i = MAX; i >= h; i--)
                ans = Math.min(ans, dp[i]);
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 23892
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int n = sc.nextInt();
        int[] v = new int[102];

        if (n == 0) {
            System.out.println(x);
            return;
        }

        for (int i = 0; i < n; i++) {
            int p = sc.nextInt();
            v[p] = 1;
        }

        int left = 0, right = 0, ans_le = 0, ans_ri = 0;
        for (int i = x; i < v.length; i++) {
            if (v[i] == 0) {
                right = i - x;
                ans_ri = i;
                break;
            }
        }

        for (int i = x; i >= 0; i--) {
            if (v[i] == 0) {
                left = x - i;
                ans_le = i;
                break;
            }
        }

        if (left > right) {
            System.out.println(ans_ri);
        } else {
            System.out.println(ans_le);
        }
    }
}

Measured memory_bytes: 35716
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b;
  std::ios::sync_with_stdio(false);
   cin>>n>>a>>b;
   if(a+b>n+1||(long long)a*b<n)
   {
       puts("-1");

   }
   else
   {
       while(n)
       {
           int mi=min(a,n-(b-1));
           for(int i=n-mi+1;i<=n;i++)
            cout<<i<<' ';
            n-=mi;
            b--;
       }
   }

    return 0;
}


Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		String s = scanner.next();

		int cntE = 0;
		int cntW = 0;
		for (int i = 0; i < n; i++) {
			if (s.charAt(i) == 'E')
				cntE++;
		}

		int min = 1000000000;
		for (int i = 0; i < n; i++) {
			int tmp = 0;
			if (s.charAt(i) == 'E') {
				cntE--;
				tmp = cntE + cntW;
			} else {
				tmp = cntE + cntW;
				cntW++;
			}
			min = Math.min(min, tmp);
		}

		System.out.println(min);
	}
}


Measured memory_bytes: 29160
from fractions import gcd

N,K=map(int,input().split())
A=list(map(int,input().split()))

if max(A)<K:
    ans="IMPOSSIBLE"
elif K in A:
    ans="POSSIBLE"

else:
    g=gcd(A[0],A[1])
    for i in range(2,N):
        g=gcd(g,A[i])
    if g!=0 and K%g==0:
        ans="POSSIBLE"
    else:
        ans="IMPOSSIBLE"

print(ans)

Measured memory_bytes: 16236
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    static class Program
    {
        static ulong K;
        static List<ulong> A;
        static List<BitArray> Ab;

        static void Main(string[] args)
        {
            var input = ReadLineSplitInt32();
            Console.WriteLine(Math.Min(input[1]/ input[0], input[2]));
        }

#if DEBUG
        static string input = @"
2 11 4
";
        static string _ReadLineImpl() => queue.Dequeue();
        static Queue<string> queue;
        static Program()
        {
            queue = new Queue<string>();
            foreach (var line in input.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
                queue.Enqueue(line);
        }
#else
        private static string _ReadLineImpl() => Console.ReadLine();
#endif
        static string ReadLine() => _ReadLineImpl();
        static int ReadLineInt32() => int.Parse(ReadLine());
        static long ReadLineInt64() => long.Parse(ReadLine());
        static ulong ReadLineUInt64() => ulong.Parse(ReadLine());
        static double ReadLineDouble() => double.Parse(ReadLine());
        static List<string> ReadLineSplit() => ReadLine().Split().ToList();
        static List<int> ReadLineSplitInt32() => ReadLine().Split().Select(s => int.Parse(s)).ToList();
        static List<long> ReadLineSplitInt64() => ReadLine().Split().Select(s => long.Parse(s)).ToList();
        static List<ulong> ReadLineSplitUInt64() => ReadLine().Split().Select(s => ulong.Parse(s)).ToList();
        static List<double> ReadLineSplitDouble() => ReadLine().Split().Select(s => double.Parse(s)).ToList();

        static IEnumerable<string> RepeatReadLines(int count)
        {
            for (int i = 0; i < count; i++)
                yield return ReadLine();
        }
        static IEnumerable<int> RepeatReadLinesInt32(int count)
        {
            for (int i = 0; i < count; i++)
                yield return ReadLineInt32();
        }
        static IEnumerable<List<string>> RepeatReadLinesSplit(int count)
        {
            for (int i = 0; i < count; i++)
                yield return ReadLineSplit();
        }

        static BitArray ToBitArray(this long l)
        {
            return new BitArray(BitConverter.GetBytes(l));
        }
        static long ToInt64(this BitArray bitArray)
        {
            var array = new byte[8];
            bitArray.CopyTo(array, 0);
            return BitConverter.ToInt64(array, 0);
        }
        static BitArray ToBitArray(this ulong l)
        {
            return new BitArray(BitConverter.GetBytes(l));
        }
        static ulong ToUInt64(this BitArray bitArray)
        {
            var array = new byte[8];
            bitArray.CopyTo(array, 0);
            return BitConverter.ToUInt64(array, 0);
        }
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <climits>

using namespace std;

typedef long long ll;
typedef vector<int> ivec;
typedef pair<int, int> ipair;

int N;
int A[100005];
int main() {
    cin >> N;
    A[0] = A[N+1] = 0;
    for (int i = 0; i < N; i++) cin >> A[i+1];

    ll sum = 0;
    for (int i = 1; i <= N+1; i++) {
        sum += abs(A[i] - A[i-1]);
    }

    for (int i = 1; i <= N; i++) {
        if ((A[i] - A[i-1]) * (A[i] - A[i+1]) < 0 || A[i] == A[i+1] || A[i] == A[i-1]) {
            cout << sum << endl;
        } else if((A[i-1] - A[i]) * (A[i-1] - A[i+1]) < 0) {
            cout << (sum - 2 * abs(A[i-1] - A[i])) << endl;
        } else {
            cout << (sum - 2 * abs(A[i] - A[i+1]))  << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 1664
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
place = 0
tmp = 10e9
for i in range(len(h)) :
  temp = t - h[i]*0.006
  if(tmp > abs(temp - a)) : 
    tmp = abs(temp - a)
    place = i
print(place+1)
  

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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

void solve()
{
        int a, b; cin >> a >> b;
        string s; cin >> s;
        bool ok = true;
        for (int i = 0; i < a; ++i)
        {
                if ((int)(s[i] - '0') > 9 || (int)(s[i] - '0') < 0)
                        ok = false;
        }
        if (s[a] != '-') ok = false;
        for (int i = a + 1; i <= a + b; ++i)
        {
                if ((int)(s[i] - '0') > 9 || (int)(s[i] - '0') < 0)
                        ok = false;
        }
        cout << (ok ? "Yes" : "No") << endl;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
}


Measured memory_bytes: 3632
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
#include <utility>
//#include <set>
//#include <map>
#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1e9+7 ;
//long double pie = acos(-1) ;
ll INF = 1e15 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}


void DFS(vector<vector<pll>> &r,vector<bool> &ok,int cur){
	ok.at(cur) = true ;
	for(int i=0;i<r.at(cur).size();i++){
		if(!ok.at(r.at(cur).at(i).first)){
			DFS(r,ok,r.at(cur).at(i).first) ;
		}
	}
}

int main(){
	ll n,m,p ;
	cin >> n >> m >> p ;
	vector<vector<pll>> g(n),r(n) ;
	for(int i=0;i<m;i++){
		ll a,b,c ;
		cin >> a >> b >> c ;
		a-- ; b-- ; c = p-c ;
		g.at(a).emplace_back(b,c) ;
		r.at(b).emplace_back(a,c) ;
	}
	vector<bool> ok(n,false),ok2(n,false) ;
	DFS(r,ok,n-1) ;
	DFS(g,ok2,0) ;
	if(!ok.at(0)){
		cout << -1 << endl ;
		return 0 ;
	}
	vll d(n,INF) ;
	d.at(0) = 0 ;
	ll cnt = 0 ;
	bool flag = true ;
	while(flag){
		if(cnt>n) break ;
		flag = false ;
		for(int i=0;i<n;i++){
			if(!ok.at(i)) continue ;
			if(!ok2.at(i)) continue ;
			for(int j=0;j<g.at(i).size();j++){
				if(d.at(g.at(i).at(j).first)>d.at(i)+g.at(i).at(j).second){
					flag = true ;
					d.at(g.at(i).at(j).first) = d.at(i)+g.at(i).at(j).second ;
				}
			}
		}
		cnt++ ;
	}
	if(flag) cout << -1 << endl ;
	else cout << max(0ll,-d.at(n-1)) << endl ;
}


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

//atcoder123
int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;

  if(e-a > k){
    cout << ":(";
  }else{
    cout << "Yay!";
  }
  
  }


Measured memory_bytes: 256
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()

if N == 1:
    print(X[-1] - X[0])
else:
    a = []
    for i in range(len(X) - 1):
        a.append(X[i + 1] - X[i])
    a.sort()
    print(X[-1] - X[0] - sum(a[-(N - 1):]))

Measured memory_bytes: 13968
#include <cstdio>
#include <iostream>
#include <algorithm>
 
using namespace std;
 
const int maxn = 300005;
 
int n, m;
 
#define lowbit(x) (x & (-x))
 
struct Tree
{
	int no[maxn];
	
	inline void add(int pla, int x)
	{
		for (; pla <= m; pla += lowbit(pla))
			no[pla] += x;
	}
	
	inline void add_qj(int l, int r)
	{
//		cout << "add " << l << ' ' << r << endl;
		add(l, 1);
		if (r < m)
			add(r + 1, -1);
	}
	
	inline int query(int pla)
	{
		int ans = 0;
		for (; pla; pla -= lowbit(pla))
			ans += no[pla];
		return ans;
	}
} tr;
 
struct QJ
{
	int l, r;
	inline int len() { return r - l + 1; }
	friend bool operator < (QJ a, QJ b)
	{ return a.r - a.l < b.r - b.l; }
} qj[maxn];
 
int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i)
		scanf("%d%d", &qj[i].l, &qj[i].r);
	sort(qj + 1, qj + n + 1);
//	cout << "qj\n";
//	for (int i = 1; i <= n; ++i)
//		cout << qj[i].l << ' ' << qj[i].r << endl;
	int now = 1;
	for (int i = 1; i <= m; ++i)
	{
		while (now <= n && qj[now].len() < i)
		{
			tr.add_qj(qj[now].l, qj[now].r);
			now++;
		}
		int ans = n - now + 1;
//		cout << "ans = " << i << ' ' << ans << ' ' << now << endl;
		for (int j = 0; j <= m; j += i)
//		{
			ans += tr.query(j);
//			cout << j << ' ' << tr.query(j) << endl;
//		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3712
a,b=map(int,input().split())
a = str(a)

b = str(b)
ab=int(a+b)
flag=0
for i in range(int(ab**0.5)+3):
    if i**2==ab:
        print('Yes')
        flag+=1
    if flag==0 and (i==int(ab**0.5)+2):
        
        print('No')

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

const int mod = 998244353;
int n, ans;
struct pnt
{
    int x, y;
    double angle;
    pnt() {}
    pnt(int x, int y) : x(x), y(y) {}
} p[210];
pnt operator+(pnt x, pnt y) { return pnt(x.x + y.x, x.y + y.y); }
pnt operator-(pnt x, pnt y) { return pnt(x.x - y.x, x.y - y.y); }
int operator*(pnt x, pnt y) { return x.x * y.y - x.y * y.x; }

long long Pow2(int x)
{
    if (x <= 60) return (1LL << x) % mod;
    long long ans = Pow2(x >> 1);
    ans = ans * ans % mod;
    if (x & 1) ans = (ans << 1) % mod;
    return ans;
}
bool in(pnt x, pnt y, pnt p)
{
    if (x.x > y.x) swap(x.x, y.x);
    if (x.y > y.y) swap(x.y, y.y);
    return p.x >= x.x && p.x <= y.x && p.y >= x.y && p.y <= y.y;
}
int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d%d", &p[i].x, &p[i].y);
    ans = Pow2(n) - 1 - n;
    for (int i = 1; i < n; i++)
    {
        for (int j = 0; j < i; j++)
        {
            int cnt = 0;
            for (int k = 0; k < n; k++)
                if ((p[i] - p[k]) * (p[j] - p[k]) == 0)
                {
                    if (!in(p[i], p[j], p[k]))
                    {
                        // printf("%d %d %d\n", i, j, k);
                        cnt = -1;
                        break;
                    }
                    cnt++;
                }
            // printf("%d %d %d\n", i, j, cnt);
            if (~cnt)
            {
                (ans -= Pow2(cnt) - 1 - cnt) %= mod;
            }
        }
    }
    printf("%d\n", (ans + mod) % mod);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 1e9 + 7;

int dp[575][7][7][7];
string ch[4] = {"A","C","G","T"};

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

	dp[3][0][2][1] = -1;
	dp[3][0][1][2] = -1;
	dp[3][2][0][1] = -1;
	for(int i=0;i<4;++i){
		for(int j=0;j<4;++j){
			for(int k=0;k<4;++k){
				++dp[3][i][j][k];
			}
		}
	} 

	auto check = [&](int j,int k,int l, int m){
								 string tmp = ch[j] + ch[k] + ch[l] + ch[m];
								 bool ng = false;
								 for(int i=0;i<3;++i){
									 string _tmp = tmp;
									 for(int j=0;j<2;++j){
										 string sub_tmp = _tmp.substr(j,3);
										 ng |= sub_tmp == "AGC";
									 }
									 swap(_tmp[i], _tmp[i+1]);
									 for(int j=0;j<2;++j){
										 string sub_tmp = _tmp.substr(j,3);
										 ng |= sub_tmp == "AGC";
									 }
								 }
								 //if(ng) cerr<<tmp<<endl;
								 return !ng;
							 };
	
	for(int i=0;i<n;++i){
		for(int j=0;j<4;++j){
			for(int k=0;k<4;++k){
				for(int l=0;l<4;++l){
					for(int m=0;m<4;++m){
						if(check(j,k,l,m)) (dp[i+1][k][l][m] += dp[i][j][k][l]) %= MOD;
					}
				}
			}
		}
	}

	int ans=0;
	for(int i=0;i<4;++i){
		for(int j=0;j<4;++j){
			for(int k=0;k<4;++k){
				(ans += dp[n][i][j][k]) %= MOD;
			}
		}
	}
	cout << ans << endl;
 
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,flag=0;
	cin>> n;
	int a[n+1];
	for(int i=1;i<=n;i++)cin>>a[i];
	a[0]=0;int ans=0;
	for(int i=1;i<=n;i++)
	{
		flag=0;
		for(int j=1;j<=i;j++){
			if(a[i]<a[j]){
				flag=1;
				break;
			}
		}
		if(!flag)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int anum, bcnum;
long long ans;
int main(){
    int i;
    cin>>s;
    for(i=0;i<s.length();i++){
        if(s[i]=='A'){
            anum++;
        }
        else if(i+1<s.length() && s[i]=='B' && s[i+1]=='C'){
            ans+=anum;
            i++;
        }
        else{
            anum=0;
        }
    }
    printf("%lld",ans);
    return 0;
}


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

int main(){

  int n;  int q;

  cin >> n;  cin >> q;

  char s[n];
  for(int i = 0; i < n; ++i){
    cin >> s[i];
  }

  vector<int> S(n+1, 0);
  for(int i = 0; i < n; ++i){
    if(i+1 < n && s[i] == 'A' && s[i+1] == 'C'){
      S[i+1] = S[i] + 1;
    }else{
      S[i+1] = S[i];
    }
  }

  for(int i = 0; i < q; ++i){
    int l, r;
    cin >> l >> r;
    --l;
    --r;

    cout << S[r] - S[l] << endl;
  }

}

Measured memory_bytes: 3696
import math
n=int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
a=0
b=0
x=[i+1 for i in range(n)]
y=[i+1 for i in range(n)]

for i in range(n-1):
    a+=x.index(p[i])*math.factorial(n-1-i)
    b+=y.index(q[i])*math.factorial(n-1-i)
    x.remove(p[i])
    y.remove(q[i])


print(abs(a-b))

Measured memory_bytes: 38256