akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e18;

struct unionfind_tree{
    int par[500000], rank[500000], Size[500000];
    //要素数nの初期化されたUnion-Find木を構築
    unionfind_tree(int N){
        rep(i, N){par[i] = i, rank[i] = 0, Size[i] = 1;}
    }
    //ノードxの根を取得
    int find(int x){
        if(par[x] == x) return x;
        else return find(par[x]);
    }
    //xとyの属する集合を併合
    void unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return;
        elif(rank[x] < rank[y]){par[x] = y, Size[y] += Size[x];}
        else{
            par[y] = x, Size[x] += Size[y];
            if(rank[x] == rank[y]) rank[x]++;
        }
    }
    //xの属する集合の要素数を取得
    int size(int x){
        return Size[find(x)];
    }
    //xとyが同じ集合に属するか判定
    bool same(int x, int y){
        return find(x) == find(y);
    }
};

int main(){
    ll N, n = 1e5;
    cin >> N;
    unionfind_tree uft(2*n);
    rep(i, N){
        int x, y;
        cin >> x >> y;
        uft.unite(x-1, y+n-1);
    }
    ll cntx[2*n], cnty[2*n];
    fill_n(cntx, 2*n, 0);
    fill_n(cnty, 2*n, 0);
    rep(i, n) cntx[uft.find(i)]++;
    rep2(i, n, 2*n-1) cnty[uft.find(i)]++;
    ll ans = 0;
    rep(i, 2*n) ans += cntx[i]*cnty[i];
    ans -= N;
    cout << ans << endl;
}

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

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

Measured memory_bytes: 4044
object Main extends App {

  override def main(args: Array[String]): Unit = {
    val str, str2 = io.StdIn.readLine.split(' ')

    val dice = new Dice(str(0), str(1), str(2), str(3), str(4), str(5))
    val dice2 = new Dice(str2(0), str2(1), str2(2), str2(3), str2(4), str2(5))

    val res = dice2.getAsTopAndSouthIs(dice.top, dice.south).exists(rot => rot == dice)

    if (res) println("Yes")
    else println("No")
  }

  case class Dice(top: String, south: String, east: String, west: String, north: String, buttom: String) {

    def toNorth: Dice = {
      new Dice(south, buttom, east, west, top, north)
    }
    def toSouth: Dice = {
      new Dice(north, top, east, west, buttom, south)
    }
    def toEast: Dice = {
      new Dice(west, south, top, buttom, north, east)
    }
    def toWest: Dice = {
      new Dice(east, south, buttom, top, north, west)
    }
    def rotRight: Dice = {
      new Dice(top, east, north, south, west, buttom)
    }
    def rotLeft: Dice = {
      new Dice(top, west, south, north, east, buttom)
    }

    def getAsTop(toTop: String): List[Dice] =  List(
        if (top == toTop) List(this) else List.empty,
        if (south == toTop) List(toNorth) else List.empty,
        if (north == toTop) List(toSouth) else List.empty,
        if (west == toTop) List(toEast) else List.empty,
        if (east == toTop) List(toWest) else List.empty,
        if (buttom == toTop) List(toEast.toEast) else List.empty
        ).flatten

    def getAsSouthByRot(toSouth: String): List[Dice] = List(
        if (south == toSouth) List(this) else List.empty,
        if (north == toSouth) List(rotLeft.rotLeft) else List.empty,
        if (west == toSouth) List(rotLeft) else List.empty,
        if (east == toSouth) List(rotRight) else List.empty
        ).flatten

    def getAsTopAndSouthIs(top: String, south: String): List[Dice] = {
      getAsTop(top).flatMap(_.getAsSouthByRot(south))
    }

  }

}

Measured memory_bytes: 43884
#include "bits/stdc++.h"
using namespace std;
#define MODULO 1000000007
#define PI 3.14159265359
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
   int x;
   cin>>x;
   int z=360,y=x,ct;
   if(z%x==0)
   ct=1;
   else
   ct=1;
   while(y%z!=0)
   {
   	y+=x;
   	ct++;
   }
   cout<<ct<<endl;
    return 0;
}


Measured memory_bytes: 3648
n, m = map(int, input().split())
dat_m = [[] for x in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    dat_m[a].append(b)
c = False
for i in dat_m[1]:
    if n in dat_m[i]:
        c = True
print("POSSIBLE" if c else "IMPOSSIBLE")

Measured memory_bytes: 66764
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;

using namespace std;

int main()
{
   FAST/**/
    
   ll a,b;
   cin>>a>>b;
   b--;
   a--;
   a = ceil((ld)b/a);
   cout<<a;
   
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

const int N=305;
int n,m,a[N][N],cnt[N],nw[N],vis[N];

void init()
{
	scanf("%d%d",&n,&m);int i,j;
	for(i=1;i<=n;++i)
		for(j=1;j<=m;++j)
			scanf("%d",&a[i][j]);
}

bool ok(int x)
{
	int i,j;
	for(i=1;i<=n;++i) nw[i]=1,vis[i]=0;
	for(i=1;i<=n;++i)
	{
		for(j=1;j<=m;++j) cnt[j]=0;
		for(j=1;j<=n;++j) ++cnt[a[j][nw[j]]];
		int fl=0;
		for(j=1;j<=m;++j) if(cnt[j]>x) vis[j]=fl=1;
		if(!fl) return true;
		for(j=1;j<=n;++j)
		{
			while(vis[a[j][nw[j]]]&&nw[j]<=m)
				++nw[j];
			if(nw[j]>m) return false;
		}
		
	}
	return false;
}

void work()
{
	int l=1,r=n;
	while(l<r)
	{
		int mid=(l+r)>>1;
		if(ok(mid)) r=mid;
		else l=mid+1;
	}
	printf("%d\n",l);
}

int main()
{
	init();work();
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int taka_hp, taka_of, aoki_hp, aoki_of;
	scanf("%d %d %d %d", &taka_hp, &taka_of, &aoki_hp, &aoki_of);

	while (taka_hp > 0 && aoki_hp > 0)
	{
		aoki_hp = aoki_hp - taka_of;
		taka_hp = taka_hp - aoki_of;
		if (aoki_hp <= 0 && taka_hp <= 0)
			printf("Yes\n");
		else if (aoki_hp <= 0)
			printf("Yes\n");
		else if (taka_hp <= 0)
			printf("No\n");
	}
	return (0);
}

Measured memory_bytes: 1584
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int r,g,b,n;

int main(){
    cin >> r >> g >> b >> n;
    int ct = 0;
    rep(i,3001) rep(j,3001){
        int Bk = n-r*i-g*j;
        if(Bk >= 0 && Bk % b == 0) ct++;
    }
    cout << ct << '\n';
}

Measured memory_bytes: 256
N, ma, mb = map(int, raw_input().split())
A = [map(int, raw_input().split()) for _ in xrange(N)]

if N == 1:
    if ma * A[0][0] == mb * A[0][1]:
        print A[0][2]
    else:
        print -1
    exit()

n = N / 2
m = N / 2 + N % 2

B = [[0, 0, 0] for _ in xrange(2**n)]

for i in xrange(2**n):
    for j in xrange(n):
        if i & (1 << j):
            B[i][0] += A[j][0]
            B[i][1] += A[j][1]
            B[i][2] += A[j][2]

d = {}
ans = float('inf')

for i in xrange(2**m):
    a = 0
    b = 0
    c = 0
    for j in xrange(m):
        if i & (1 << j):
            a += A[n+j][0]
            b += A[n+j][1]
            c += A[n+j][2]
    x = ma * b - mb * a
    if x == 0 and c > 0:
        ans = min(ans, c)
    if x in d:
        d[x] = min(d[x], c)
    else:
        d[x] = c

for a, b, c in B:
    x = mb * a - ma * b
    if x == 0 and c > 0:
        ans = min(ans, c)
    if x in d and c + d[x] > 0:
        ans = min(ans, c + d[x])
print ans if ans != float('inf') else -1


Measured memory_bytes: 133532
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#define ll long long
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
template <typename T>
inline void w(T x) {
	if (x > 9) w(x / 10);
	putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x, char c) {
	w(x);
	putchar(c);
}
template <typename T>
inline void read(T &x) {
	x = 0;
	T f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}
int main(){
	ll n;
	cin >> n;
	ll ans = 0;
	for(ll i = 1; i <= n; i++){
		if(i % 3 != 0 && i % 5 != 0)
			ans += i;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

string s;

signed main() {
	int i;
	
	cin >> s;
	int n = s.length();
	
	rep(i, s.length()) {
		if (s[i] != s[n - 1 - i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	
	rep(i, n / 2) {
		if (s[i] != s[n / 2 - 1 - i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>

#define fin stdin
#define fout stdout
//FILE *fin = fopen("a.in", "r"), *fout = fopen("a.out", "w");

#define MOD 1000000007

int main() {
    int n, k;
    fscanf(fin, "%d%d", &n, &k);

    std::vector < int > a(n);
    for (int i = 0; i < n; i++)
        fscanf(fin, "%d", &a[i]);

    int ans = 0;
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
            if (a[i] < a[j])
                ans = (ans + 1LL * k * (k - 1) / 2) % MOD;
            else if (a[i] > a[j])
                ans = (ans + 1LL * k * (k + 1) / 2) % MOD;

    fprintf(fout, "%d\n", ans);

    fclose(fin);
    fclose(fout);
    return 0;
}


Measured memory_bytes: 256
# Generated by AtcoderGreedy on 2018-04-23
# CODE-FESTIVAL-2017-QUALB C
# Your code here

$N, $M = gets.chomp.split(' ').map(&:to_i)

$g = {}

$M.times do
  a, b = gets.chomp.split(' ').map(&:to_i)
  $g[a] ||= []
  $g[a] << b

  $g[b] ||= []
  $g[b] << a
end

def is_bipartite_graph(graph)
  stack = [[graph.keys.first, :white]]

  color = {}
  until stack.empty?
    point, color_candidate = stack.pop
    prev_color = color[point]
    return false if prev_color && prev_color != color_candidate
    next if prev_color
    color[point] =  color_candidate
    graph[point].each do |p|
      next_color = color_candidate == :white ? :red : :white
      stack << [p, next_color]
    end
  end
  num_reds = color.select { |_, v| v == :red }.size
  num_whites = color.select { |_, v| v == :white }.size
  [num_reds, num_whites]
end

data = is_bipartite_graph($g)

if data
  puts data[0] * data[1] - $M
else
  puts $N * ($N - 1) / 2 - $M
end


Measured memory_bytes: 30456
import numpy as np
from scipy.sparse import csr_matrix,linalg
import itertools
n = int(input())
b = np.array([int(i) for i in input().split()])
rows = []
cols = []
for i in range(n):
    rows.append(i%n)
    rows.append(i%n)
    cols.append(i%n)
    cols.append((i+1)%n)

A = csr_matrix((np.ones(n*2,dtype=np.int32),(rows,cols)),(n,n))
x = linalg.spsolve(A,b)
print(*(int(i) for i in 2*x))

Measured memory_bytes: 69940
#include <iostream>
#include <map>

using namespace std;

map<int,int> m;

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		m[x]++;
	}
	if (m.size() == 3) {
		auto it = m.begin();
		int a = it->first; it++;
		int b = it->first; it++;
		int c = it->first;
		if (m[a] == m[b] && m[b] == m[c] && (a^b) == c) cout << "Yes\n";
		else cout << "No\n";
	} else if (m.size() == 2) {
		auto it = m.begin();
		int a = it->first; it++;
		int b = it->first;
		if (a == 0 && 2*m[a] == m[b]) cout << "Yes\n";
		else cout << "No\n";
	} else if (m.size() == 1) {
		if (m[0]) cout << "Yes\n";
		else cout << "No\n";
	} else {
		cout << "No\n";
	}
}


Measured memory_bytes: 3840
using System;

namespace calc
{
    class Program
    {
        static void Main(string[] args)
        {
            double a;

            string inD0 = Console.ReadLine();

            a = double.Parse(inD0);

            Console.WriteLine(a+Math.Pow(a,2)+Math.Pow(a,3));
        }
    }
}


Measured memory_bytes: 27944
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<String> after = new ArrayList<>();
		List<String> ansArray = new ArrayList<>();
		
		String in, ans = "";
		String[] before;
		int tmp;
		while(sc.hasNext()) {
			in = sc.next();
			before = in.split("");
			
			for(int i = 0; i < before.length; i++) {
				if(before[i].equals("@")) {
					tmp = Integer.parseInt(before[i + 1]);
					for(int j = 0; j < tmp; j++) {
						after.add(before[i + 2]);
					}
					i += 2;
				} else {
					after.add(before[i]);
				}
			}
			
			for(int i = 0; i < after.size(); i++) {
				ans += after.get(i);
			}
			ansArray.add(ans);
			
			after.clear();
			ans = "";
		}
		
		for(String i : ansArray)	System.out.println(i);
	}
}

Measured memory_bytes: 26172
#include<bits/stdc++.h>
#define N 200100
using namespace std;
char s[N];
int main(){
	scanf("%s",s);
	int ans=0,sc=0;
	for(int i=0;s[i];i++){
		if(s[i]=='S') sc++;
		else if(sc) sc--;
		else ans++;
	}
	printf("%d\n",ans+sc);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin >> n;
	unordered_map<int, int> mp;
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		int no;
		cin >> no;
		sum += no;
		mp[no]++;
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int b, c;
		cin >> b >> c;
		sum = sum + (c - b) * mp[b];
		mp[c] += mp[b];
		mp[b] = 0;
		cout << sum << "\n";
	}
}



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

#define RATE2RANK(R) ((R)/400)
#define RED 7
int main(void){
  int n,acc[10]={0};
  int t=0;
  
  cin >> n;
  for (int i=0; i<n; i++){
    int a; cin >> a;
    if (a>=3200) a=3200;
    acc[RATE2RANK(a)]++;
  }
  for (int i=0; i<=RED; i++){
    if (acc[i]>0) t++;
  }
  if (t==0&&acc[RED+1]) cout << 1 << " " << acc[RED+1] << endl;
  else cout << t << " " << (t+acc[RED+1]) << endl;
  return 0;
}

Measured memory_bytes: 256
import heapq

def submit():
    n, h = map(int, input().split())
    
    attack = []
    for _ in range(n):
        a, b = map(int, input().split())
        heapq.heappush(attack, (-a, 'a'))
        heapq.heappush(attack, (-b, 'b'))
    
    count = 0
    while h > 0:
        d, t = heapq.heappop(attack)
        
        if t == 'b':
            count += 1
            h += d
        else:
            q, r = divmod(h, -d)
            count += q + (r > 0)
            h += d * count
    print(count)


submit()




Measured memory_bytes: 23812
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mk make_pair
#define pi pair<int, int>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;

constexpr int N = 2e5+5;
ll a[N];

int main()
{
   IOS;
   int n;
   cin >> n ;
   rep(i,1,n)cin >> a[i];
   ll sum = 0;
   rep(i,2,n)
   {
       if(a[i] < a[i-1])
       {
           sum += a[i-1]-a[i];
           a[i] = a[i-1];
       }
   }
   cout << sum;
}


Measured memory_bytes: 5208
import heapq

N,M = map(int, input().split())

A = list(map(lambda x: -1 * int(x), input().split()))

heapq.heapify(A)
for i in range(M):

    num = heapq.heappop(A)
    num *= -1
    num //= 2
    num *= -1
    heapq.heappush(A, num)


print(-1 * sum(A))


Measured memory_bytes: 14180
class Dice(object):
    def __init__(self,num):
        self.f=num[0]
        self.s=num[1]
        self.e=num[2]
        self.w=num[3]
        self.n=num[4]
        self.b=num[5]
    def create(self,order):
        if order=='N':
            return [self.s,self.b,self.e,self.w,self.f,self.n]
        elif order=='S':
            return [self.n,self.f,self.e,self.w,self.b,self.s]
        elif order=='E':
            return [self.w,self.s,self.f,self.b,self.n,self.e]
        else:
            return [self.e,self.s,self.b,self.f,self.n,self.w]
    def judge(self,dice_2):
        T={0:'N',1:'E',2:'S',3:'W'}
        m=[dice_2.s,dice_2.w,dice_2.n,dice_2.e,dice_2.f,dice_2.b]
        for i in range(6):
            if m[i]==self.f:#?????¢??¨?????´???????????????????????????
                if i==4:temp=dice_2#?????¢??????????????´
                elif i==5:temp=Dice(Dice(dice_2.create('N')).create('N'))#?????¢??¨?????´
                else:temp=Dice(dice_2.create(T[i]))#??´??¢??¨?????´

                if self.b==temp.b:
                        side_1=''.join(list(map(str,[self.s,self.w,self.n,self.e])))*2
                        side_2=''.join(list(map(str,[temp.s,temp.w,temp.n,temp.e])))
                        if side_2 in side_1:return 'Yes'
        return 'No'
num_1=list(map(int,input().split()))
num_2=list(map(int,input().split()))
dice_1=Dice(num_1)
dice_2=Dice(num_2)
print(dice_1.judge(dice_2))

Measured memory_bytes: 7880
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W, K; cin >> H >> W >> K;
	vector<vector<char>> v(H, vector<char>(W));
	int si, sj;
	rep(i, 0, H) rep(j, 0, W) {
		cin >> v[i][j];
		if (v[i][j] == 'S')si = i, sj = j;
	}

	//最短距離
	vector<vector<int>> d(H, vector<int>(W, INF));
	d[si][sj] = 0;

	auto inrange = [&](int i, int j) { return i >= 0 && i < H && j >= 0 && j < W; };
	static const int di[] = { 1,0,-1,0 };
	static const int dj[] = { 0,1,0,-1 };

	using P = pair<int, int>;
	queue<P> Q;
	Q.push(P(si, sj));
	for (P u; !Q.empty();) {
		u = Q.front(); Q.pop();
		for (int i = 0; i < 4; i++) {
			int ni = u.first + di[i], nj = u.second + dj[i];
			if (!inrange(ni, nj))continue;
			if (v[ni][nj] == '#')continue;
			if (d[ni][nj] != INF)continue;
			d[ni][nj] = d[u.first][u.second] + 1;
			Q.push(P(ni, nj));
		}
	}
	int ans = INF;
	rep(i, 0, H)rep(j, 0, W) {
		if (d[i][j] == INF)continue;
		if (d[i][j] > K)continue;
		if (i == 0 || j == 0 || i == H - 1 || j == W - 1) {
			if (d[i][j] != K) {
				chmin(ans, 1);
			}
		}
		int h = min(i, H - i - 1), w = min(j, W - j - 1);
		int t = min(h, w);
		dump(i, j, t);
		chmin(ans, t / K + !!(t%K) + 1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3456
<?php
  fscanf(STDIN, "%d %d", $N, $M);
  $L = 1;
  $R = $N;

  for ($i = 0; $i < $M; $i++) {
      fscanf(STDIN, "%d %d", $Li, $Ri);
      $L = max($L, $Li);
      $R = min($R, $Ri);
  }
  if ($L > $R) {
    echo "0";
  } else {
    echo $R - $L + 1;
  }


Measured memory_bytes: 4728
function myout(text){console.log(text);}//standard output
function Main(input) {
	input = input.trim();
	//input = input.trim().split(" ");
	//input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  myout(Math.pow(parseInt(input),3));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;

    if (x - r < 0 || y - r < 0 || x + r > W || y + r > H) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}


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

typedef long double     ld;
typedef long long       ll;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;

const int inf = 0x3f3f3f3f;
const ll  INF = 0x3f3f3f3f3f3f3f3f;

#define FOR(i, b, e)    for(int i=b; i<=e; i++)
#define FORD(i, b, e)   for(int i=b; i>=e; i--)
#define SIZE(x)         ((int)(x).size())
#define pb              push_back
#define st              first
#define nd              second
#define all(a)          begin(a), end(a)
#define watch(x)        cerr << (#x) << " is " << (x) << '\n';
ld t[51];

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

    int n;
    cin>>n;


    FOR(i,1,n){
        cin>>t[i];
    }

    sort(t,t+n+1);

    FOR(i,2,n){
        t[i]=(t[i-1]+t[i])/2;
    }

    cout<<t[n];

    return 0;
}


Measured memory_bytes: 256
#include <stdint.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

using int_type = int64_t;

#define FOR(i, n) for (int_type i = 0; i < n; ++i)

int_type gcd(int_type a, int_type b) {
    return b == 0 ? a : gcd(b, a % b);
}
int_type lcm(int_type a, int_type b) {
    return (a * b) / gcd(a, b);
}

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

    int_type N;
    cin >> N;

    int_type A[200000];
    FOR(i, N) cin >> A[i];

    int_type n = 1;
    FOR(i, N) if (A[i] == n) n++;

    if (n == 1) {
        cout << -1;
    } else {
        cout << N - n + 1;
    }

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n,m;
    cin >> n >> m;
    vector<vi> k(m);
    rep(i,m){
        int a;
        cin >> a;
        rep(j,a){
            int b;
            cin >> b;
            k[i].push_back(b);
        }
    }
    vi p(m);
    rep(i,m) cin >> p[i];
    bool ok = false;
    int ans = 0;
    for(int i=0;i<(1<<n);i++){
        bitset<10> bit(i);
        ok = false;
        rep(j,m){
            int sum = 0;
            rep(l,k[j].size()){
                if(bit.test(k[j][l]-1)) sum++;
            }
            if(sum%2==p[j]){
                ok = true;
                continue;
            }
            else{
                ok = false;
                break;
            }

        }
        if(ok) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long long N,ans=0;
    cin >> N;
    for(long long int i = 1;i * i + i < N; ++i){
        if(N%i==0){
                ans += N/i-1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//AtCoder ABC073 A - September 9
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    string N;
    cin>>N;
    bool ans=false;
    for(auto& s:N){
        if (s=='9') ans=true; 
    }
    cout<<(ans?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 256
/* [Template].cpp 
Example code to use when starting new code. This particular problem was problem 
977A_Wrong_Subtraction from CodeForces

Compile: g++  -o D.exe D.cpp 
Execute: ./D
*/ 

#include <cstdio>
#include <iostream>
#include <cmath> 
#include <limits> 
#include <iomanip>
#include <cstring> 
#include <bits/stdc++.h>
#include <string>  
#include <algorithm> 
using namespace std;

int main() { 	
	int s; 
	long long r[2001]; 
	long long mod = 1000000007; 

	cin >> s; 
	
	// Base cases 
	fill_n(r, 2001, 1); 
	r[0] = 0; 
	r[1] = 0; 
	r[2] = 0; 
	
	for(int i = 6; i <= 2000; i++) {
		for(int j = 3; j <= i-3; j++) {
			r[i] += r[j]; 
			r[i] %= mod; 
		}
	}
	
	cout << r[s] << endl; 
	
	return 0; 
} 


Measured memory_bytes: 3652
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true) {
            int h = sc.nextInt();
            int w = sc.nextInt();
            if(h == 0 && w == 0) break;
            for(int i = 0; i < h; i++) {
                for(int j = 0; j < w; j++) {
                    if(i == 0 || i == h-1 || j == 0 || j == w-1) {
                        System.out.print("#");
                    } else {
                        System.out.print(".");
                    }
                }
                System.out.println();
            }
            System.out.println();
        }
        
    }
}


Measured memory_bytes: 37284
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

N = ri()
a = ri_()
s = 100000000000000
for i in range(N):
    if s == 100000000000000:
        s = a[i]
    else:
        s = s ^ a[i]
ans = [0] * N
for i in range(N):
    print(s ^ a[i], end = ' ' if i < N - 1 else '\n')


Measured memory_bytes: 30704
N,K = map(int,input().split())
div = []
div2 =[]

for i in range(1,N+1):
    if (i%K == 0):
        div.append(i)
    elif (2*i%K == 0):
        div2.append(i)
    else :
        continue
l1 = len(div)
l2 = len(div2)
print(l2*l2*l2 + l1*l1*l1)

Measured memory_bytes: 11028
from functools import lru_cache

N = int(input())
 
@lru_cache(maxsize=1000)
def main(K):
    ans = 0
    for i in range(1, N+1):
        if i % 15 != 0 and i % 3 != 0 and i % 5 != 0:
            ans = ans + i
    return(ans)
 
print(main(N))

Measured memory_bytes: 9548
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int M, K;
	cin >> M >> K;

	int p = (int)pow(2, M);

	if (p - 1 < K || M == 1 && K == 1)
	{
		cout << "-1" << endl;
		return 0;
	}

	vector<int> ans;

	if (K == 0)
	{
		rep(i, 0, p)
		{
			ans.push_back(i);
		}
		rrep(i, 0, p)
		{
			ans.push_back(i);
		}
	}
	else
	{
		rep(i, 0, p)
		{
			if (i != K)
			{
				ans.push_back(i);
			}
		}
		ans.push_back(K);
		rrep(i, 0, p)
		{
			if (i != K)
			{
				ans.push_back(i);
			}
		}
		ans.push_back(K);
	}

	rep(i, 0, SZ(ans))
	{
		cout << ans[i];
		if (i == SZ(ans) - 1)
		{
			cout << endl;
		}
		else
		{
			cout << ' ';
		}
	}

	return 0;
}

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

int main(){
	int n, slen;
	long long int res = 0, count=1;
	string s;
	cin >> n;
	vector<string> arr;
	bool ana;
	for(int i=0; i<n; ++i){
		cin >> s;
		sort(s.begin(), s.end());
		arr.push_back(s);
	}
	sort(arr.begin(), arr.end());
	//
	for(int i=0; i<arr.size()-1; ++i){
		if(arr[i] == arr[i+1]){
			count += 1;
			ana = true;
		}
		else {
			if(count > 1){
				//cout << "Apply inner sumatoria de: " << count << '\n';
				res = res + ((count-1)*(count)/2);
				ana = false;
				count = 1;
			}
		}
	}
	if(ana){
		//cout << "Apply sumatoria de: " << count << '\n';
		res = res + ((count-1)*(count)/2);
	}
	cout << res << '\n';
	return 0;
}

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

int main(){
  int n;cin >> n;
  vector<int> a(n),b(n);rep(i,n)cin >> a[i];
  b = a;
  sort(a.begin(),a.end(),greater<>());
  rep(i,n){if(b[i] == a[0]){cout << a[1] << endl;}else{cout << a[0] << endl;}}
  return 0;
}

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

int main(){
    int a[3];
    for(int i=0;i<3;i++)cin>>a[i];
    int f=0,s=0;
    for(int i=0;i<3;i++){
        if(a[i]==5)f++;
        else if(a[i]==7)s++;
    }
    if(s==1 && f==2)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <cstdio>

int H, W, flag1[110], flag2[110];
char map[110][100];

int main() {
	scanf("%d%d", &H, &W);
	for (int i = 0; i < H; i++) {
		scanf("%s", map[i]);
		for (int j = 0; j < W; j++)
			if (map[i][j] == '#') flag1[i] = flag2[j] = 1;
	}
	for (int i = 0; i < H; i++) {
		int out = 0;
		for (int j = 0; j < W; j++) 
			if (flag1[i] && flag2[j]) putchar(map[i][j]), out = 1;
		if (out) putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 128
import sys
import math
import bisect

def main():
    n = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    alice = 0
    for i in range(0, n, 2):
        alice += A[i]
    bob = sum(A) - alice
    print(alice - bob)

if __name__ == "__main__":
    main()


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

using namespace std;

int n,k,len[10050];
char str[10050];
string as;
bool vis;

int main()
{
    scanf("%d%d%s",&n,&k,str + 1);
    int minn = 998244353;
    for(int i = 1;i <= n; ++ i)
        minn = min(minn,(int)(str[n * 2 + 1 - i] = str[i]));
    if(k >= 15)
    {
        for(int i = 1;i <= n; ++ i)
            putchar(minn);
        return 0;
    }
    if(k == 1)
    {
        for(int i = 1;i <= n + 1; ++ i)
        {
            string s = "";
            for(int j = i;j <= i + n - 1; ++ j)
                s.push_back(str[j]);
            if(!vis)
            {
                vis = 1;
                as = s;
            }
            else if(s < as) as = s;
        }
        cout << as << endl;
        return 0;
    }
    int maxn = 0;
    for(int i = 1;i <= 2 * n; ++ i)
        len[i] = (str[i] == minn ? len[i - 1] + 1 : 0),maxn = max(maxn,len[i]);
    int as_len = maxn << k - 1;
    if(as_len >= n)
    {
        for(int i = 1;i <= n; ++ i)
            putchar(minn);
        return 0;
    }
    for(int i = n;i <= 2 * n; ++ i)
    {
        if(len[i] == maxn)
        {
            string s = "";
            for(int j = i;j >= i - n + 1; -- j)
                s.push_back(str[j]);
            if(!vis)
            {
                vis = 1;
                as = s;
            }
            else if(s < as) as = s;
        }
    }
    for(int i = 1;i <= as_len; ++ i) putchar(minn);
    int cur = maxn;
    while(as_len < n)
    {
        putchar(as[cur ++]);
        as_len ++;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
 
int main()
{
    int a, b;
    std::string s;

    std::cin >> a >> b >> s;

    for(int i = 0;i < a;i++){
        if(!('0' <= s[i] && s[i] <= '9')){
            std::cout << "No";

            return 0;
        }
    }
    
    for(int i = a + 1;i < a + b + 1;i++){
        if(!('0' <= s[i] && s[i] <= '9')){
            std::cout << "No";

            return 0;
        }
    }

    if(s.length() != a + b + 1){
        std::cout << "No";

        return 0;
    }
    else if(s[a] != '-'){
        std::cout << "No";

        return 0;
    }
    
    std::cout << "Yes";

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main() {
  int N, X[110];
  cin >> N;
  for (int i = 0; i < N; i++) cin >> X[i];
  int min_sum = 1e+8;
  for (int p = 1; p <= 100; p++) {
    int sum = 0;
    for (int i = 0; i < N; i++) sum += (X[i] - p) * (X[i] - p);
    min_sum = min(min_sum, sum);
  }
  cout << min_sum << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
S = input()
S += "#"
S_list = []
if S[0] == "0":
    S_list.append(0)

count = 1
before_s = S[0]
for s in S[1:]:
    count += 1
    if before_s != s:
        S_list.append(count-1)
        count = 1
    before_s = s

if S[-2] == "0":
    S_list.append(0)

# print(S_list)

if len(S_list) < 2 * K:
    print(sum(S_list))
else:
    ans = 0
    ans_list = []
    for i in range(0, len(S_list) - (2 * K), 2):
        left = i
        right = i + 2 * K
        # print(S_list[left:right+1])
        if i == 0:
            ans = sum(S_list[left:right+1])
            ans_list.append(ans)
        else:
            # print(S_list[left-2:left], S_list[right-1:right+1])
            ans = ans - sum(S_list[left-2:left]) + sum(S_list[right-1:right+1])
            ans_list.append(ans)
    print(max(ans_list))

Measured memory_bytes: 46192
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define _D(p) std::cout<<"L"<<__LINE__<<" : " #p " = "<<(p)<<std::endl;
#define _D2(p,q) std::cout<<"L"<<__LINE__<<" : " #p " = "<<(p) << ", " #q " = "<<(q)<<std::endl;
#define _DN(v) std::cout<<"L"<<__LINE__<<" : " #v " = ["; rep(i,(v).size()) {std::cout<<v[i]<<(i==v.size()-1?"":", ");}std::cout<<"]"<<std::endl;
#define _DNN(v) std::cout<<"L"<<__LINE__<<" : " #v " = [" << std::endl; rep(i,(v).size()) {std::cout<<"    [";rep(j,(v)[0].size()){std::cout<<v[i][j]<<(j==v[0].size()-1?"":", ");}std::cout<<"],"<<std::endl;}std::cout<<"]"<<std::endl;
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int main(int argc, char const *argv[]) {
    int N;
    cin >> N;
    int cnt = 0;
    for (int i = 0; i < N; ++i) {
        int l, r;
        cin >> l >> r;
        cnt += r - l + 1;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e5 + 5;

ll A,B,M;
ll a[maxn],b[maxn];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>A>>B>>M;
	for(int i=1;i<=A;i++)
		cin>>a[i];
	for(int i=1;i<=B;i++)
		cin>>b[i];
	ll res=INF;
	for(int i=1;i<=M;i++){
		int x,y,c;
		cin>>x>>y>>c;
		ll temp=a[x]+b[y]-c;
		res=min(res,temp);
	}
	sort(a+1,a+1+A);
	sort(b+1,b+1+B);
	res=min(res,a[1]+b[1]);
	cout<<res;
	return 0;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

vector<int64> CumulatedSum(const vector<int64>& xs) {
  vector<int64> ys(xs.size() + 1);
  for (int i = 0; i < xs.size(); i++) {
    ys[i + 1] = ys[i] + xs[i];
  }
  return ys;
}

template<class T> inline bool UpdateMin(T& a, T b) {
  if (a > b) { a = b; return 1; } return 0;
}

template<class T> inline bool UpdateMax(T& a, T b) {
  if (a < b) { a = b; return 1; } return 0;
}

// Vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  s << "[";
	for (int i = 0; i < len; i++) {
    if (i > 0) s << ", ";
		s << v[i];
  }
  s << "]";
  return s;
}

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

  int n, m;
  cin >> n >> m;
  int64 k;
  cin >> k;
  vector<int64> xs(n), ys(m);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> ys[i];
  }

  vector<int64> c_xs = CumulatedSum(xs);
  vector<int64> c_ys = CumulatedSum(ys);
  // cout << c_xs << endl;
  // cout << c_ys << endl;

  int ans = 0;
  for (int i1 = 0; i1 < c_xs.size(); i1++) {
    if (c_xs[i1] > k) continue;
    int64 r = k - c_xs[i1];
    // cout << *(lower_bound(c_ys.begin(), c_ys.end(), r)) << endl;
    int i2 = distance(c_ys.begin(), upper_bound(c_ys.begin(), c_ys.end(), r));
    // cout << i1 << " " << i2 << endl;
    UpdateMax(ans, i1 + i2 - 1);
  }
  cout << ans << endl;
}

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

constexpr int MOD = 998244353;
constexpr int MAX = 200200;

template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(long long e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e % 2 == 0) {p = (p * p) % mod; e /= 2;}
            else {a = (a * p) % mod; e--;}
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

template<int mod> struct Combination {
    vector<ModInt<mod>> fact, ifact;
    Combination(int n) : fact(n+1), ifact(n+1) {
        fact[0] = 1;
        for (int i = 1; i <= n; i++) fact[i] = (fact[i - 1] * i);
        ifact[n] = fact[n].inverse();
        for (int i = n; i > 0; i--) ifact[i - 1] = ifact[i] * i;
    }
    ModInt<mod> operator() (int n, int r) {
        if (r < 0 or r > n) return 0;
        return fact[n] * ifact[n-r] * ifact[r];
    }
    const ModInt<mod> &operator[] (int i) const {
        return fact[i];
    }
};

int main() {
	Combination<MOD> binom(MAX);
	int n, m, k;
	cin >> n >> m >> k;
	
	ModInt<MOD> ans = 0;
	ModInt<MOD> mm = m - 1, nn = n - 1;
	for (int x = 0; x <= k; x++) {
		ModInt<MOD> res = mm.pow(n - x - 1) * m;
		res *= binom(n - 1, n - x - 1);
		ans += res;
	}
	
	cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 4624
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace abc155
{
    class Program
    {
        static void Main(string[] args)
        {
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
			solve_abc155B();
        }

        public static void solve_abc155B()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            bool ok = true;
            for (int i = 0; i < n; i++)
            {
                if (a[i] % 2 == 0)
                {
                    if (a[i] % 3 != 0 && a[i] % 5 != 0)
                    {
                        ok = false;
                        break;
                    }
                }
            }

            if (ok)
            {
                Console.WriteLine("APPROVED");
            }
            else
            {
                Console.WriteLine("DENIED");
            }
        }

        public static void solve_abc155A()
        {
            int[] abc = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

            if ((abc[0] == abc[1] && abc[2] != abc[0]) || (abc[0] == abc[2] && abc[1] != abc[0]) || (abc[1] == abc[2] && abc[0] != abc[1]))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


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

int main()
{
    string s, t;
    cin >> s >> t;
    for (int i = s.size() - 1; i >= t.size() - 1; i--) {
        bool ok = true;
        for (int j = 0; j < t.size(); j++) {
            if (s[i - j] != '?' && s[i - j] != t[t.size() - 1 - j]) {
                ok = false;
            }
        }
        if (ok) {
            for (int j = 0; j < t.size(); j++) {
                s[i - j] = t[t.size() - 1 - j];
            }
            for (int j = 0; j < s.size(); j++) {
                if (s[j] == '?') {
                    s[j] = 'a';
                }
            }
            cout << s << endl;
            return 0;
        }
    }
    cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
#include<iostream>

int main(){
  int n;
  std::cin >> n;
  int a[n];
  
  for(int i = 0; i < n; i++){
    std::cin >> a[i];
  }

  for(int i = n - 1 ; i >= 0; i--){
    std::cout << a[i];
    if(i > 0){
      std::cout << " ";
    }
  }

  std::cout << std::endl;
  return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <fstream>
using namespace std;
const int nmax=100005;
char a[nmax],b[nmax];
string s;
int i,nr,j,moves;
bool pali()
{
    for(i=1;i<=nr;i++)
        if(b[i]!=b[nr-i+1])
           return 0;
    return 1;
}
int main()
{
    cin>>s;
    for(i=0;i<s.size();i++)
    {
        if(s[i]=='x') a[i]=1;
        else b[++nr]=s[i];
    }
    if(!pali())
    {
        cout<<"-1";
        return 0;
    }
    i=0;j=s.size();j--;
    while(i<j)
    {
        if(a[i]==a[j])
        {
            i++;j--;
        }
        else
        {
            if(a[i]==1) i++;
            else j--;
            moves++;
        }
    }
    cout<<moves;
    return 0;
}


Measured memory_bytes: 640
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
total=sum(B)
for i in range(N-1):
    if A[i+1]-A[i]==1:
        total+=C[A[i]-1]
print(total)

Measured memory_bytes: 3064
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if a*500+b*100+c*50 == X:
                ans += 1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

constexpr int INFI = 1145141919;

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

    int N;
    std::cin >> N;

    std::vector<double> v;
    for(int i=0; i<N; i++){
        double buf;
        std::cin >> buf;
        v.push_back(buf);
    }

    std::sort(v.begin(), v.end());

    //価値の低いものを先に合成した方がいい気がする
    while(v.size()>1){
        v.at(1) = ( v.at(0) + v.at(1) )/ 2.0;
        v.erase(v.begin());
    }

    std::cout << v.front();

    return 0;
}


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

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);(i)++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;(i)>=(int)(m);(i)--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)

#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'

using ll = long long;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;


typedef vector<ll> Array;
typedef vector<Array> Matrix;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

//constexpr long long MOD = (ll) 1e9+7;
constexpr long long MOD = 998244353;

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

struct Edge {
	int to, cap, rev;
	Edge(int _to, int _cap, int _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, int from, int to, int cap, bool revFlag, int revCap) {
	G[from].push_back(Edge(to, cap, G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, G[from].size() - 1));
}

void solve() {
	ll n;
	cin >> n;
	vvec<string> s(2, vec<string>(n));
	vec<ll> c(n);
	REP(i, n) {
		cin >> s[0][i] >> c[i];
		s[1][i] = s[0][i];
		reverse(all(s[1][i]));
	}
	using T = tuple<ll, bool, string>;
	priority_queue<T, vec<T>, greater<T>> que;

	vec<map<string, ll>> mp(2);
	auto push = [&](ll cost, bool flag, string t) {
		if (!mp[flag].count(t) or mp[flag][t] > cost) {
			mp[flag][t] = cost;
			que.push({ cost,flag,t });
		}
	};
	REP(i, n) {
		push(c[i], 1, s[0][i] );
	}
	while (que.size()) {
		auto [cost, flag, t] = que.top();
		que.pop();
		
		ll m = t.size();
		bool pal = true;
		REP(i, m / 2) {
			if (t[i] != t[m - 1 - i])pal=false;
		}
		if (pal) {
			cout << cost << en;
			return;
		}

		REP(i, n) {
			ll mm = s[flag][i].size();
			ll k = min(mm, m);
			bool same = true;
			REP(j, k) {
				if (s[flag][i][j] != t[j])same = false;
			}
			if (same) {
				if (m == mm) {
				push(cost + c[i],0,"" );
				}
				else if (m < mm) {
					push( cost + c[i],!flag,s[flag][i].substr(k,mm - m));
				}
				else {
					push( cost + c[i],flag,t.substr(k,m-mm) );
				}
			}
		}
	}

	cout << -1 << en;


}

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

	solve();
	//int t; cin >> t; REP(i, t) solve();

	return 0;
}


Measured memory_bytes: 3760
import Control.Monad
import Control.Applicative
import Data.List

main :: IO()
main = do
  [a,b,c] <- (map read . words <$> getLine) :: IO [Int]
  let d = a * c
  let e = b `div` d
  let ans = if e == 0 then b `div` a else e * c
  print ans


Measured memory_bytes: 508