akhauriyash/Code-Regression huggingface dataset:
using System;
using System.IO;
using System.Linq;

class Program
{
    static void Solve()
    {
        var N = ReadInt();
        var V = ReadInts();
        var C = ReadInts();

        var ans = 0;
        for (var i = 0; i < N; i++)
        {
            if (V[i] > C[i]) ans += V[i] - C[i];
        }

        Console.WriteLine(ans);
    }

    static void Main(string[] args)
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }

    public static string Read() { return Console.ReadLine(); }
    public static int ReadInt() { return int.Parse(Read()); }
    public static long ReadLong() { return long.Parse(Read()); }
    public static double ReadDouble() { return double.Parse(Read()); }

    public static string[] Reads() { return Console.ReadLine().Split(' '); }
    public static int[] ReadInts() { return Reads().Select(_ => int.Parse(_)).ToArray(); }
    public static long[] ReadLongs() { return Reads().Select(_ => long.Parse(_)).ToArray(); }
    public static double[] ReadDoubles() { return Reads().Select(_ => double.Parse(_)).ToArray(); }
}

Measured memory_bytes: 13396
prilen = 10 ** 6 + 1
prime = [True] * prilen
prime[0] = prime[1] = False
for i in range(2, int(prilen ** 0.5)):
    if prime[i]:
        for j in range(i * 2, prilen, i):
            prime[j] = False

while True:
    a, d, n = map(int, input().split())
    if a == d == n == 0:
        break
    while True:
        if prime[a]:
            n -= 1
        if n == 0:
            break
        a += d
    print(a)

Measured memory_bytes: 14968
//	-*- mode: C++ -*-
//	Transformation

//		Write a program which performs a sequence of commands to a given string str. The command is one of:

//		print a b: print from the a-th character to the b-th character of str
//		reverse a b: reverse from the a-th character to the b-th character of str
//		replace a b p: replace from the a-th character to the b-th character of str with p
//		Note that the indices of str start with 0.

//	Input
//		In the first line, a string str is given. str consists of lowercase letters. In the second line, the number of commands q is given. In the next q lines, each command is given in the above mentioned format.

//	Output
//		For each print command, print a string in a line.

//	Constraints
//		1≤ length of str≤1000
//		1≤q≤100
//		0≤a≤b< length of str
//		for replace command, b−a+1= length of p
//	Sample Input 1
//		abcde
//		3
//		replace 1 3 xyz
//		reverse 0 2
//		print 1 4
//	Sample Output 1
//		xaze
//	Sample Input 2
//		xyz
//		3
//		print 0 2
//		replace 0 2 abc
//		print 0 2
//	Sample Output 2
//		xyz
//		abc

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

char	separator	{' '};

void print(std::string&	str,
		   std::string&	args);
void replace(std::string&	str,
			 std::string&	args);
void reverse(std::string&	str,
			 std::string&	args);

int	main(int	argc,
		 char*	argv[])
{
	std::string	str	{};

	std::cin >> str;

	unsigned int	q	{0};

	std::cin >> q;

	std::vector<std::string> commands	{};

	std::cin.ignore();

	for(unsigned int i = 0; i < q; i++){
		std::string	command	{};
		std::getline(std::cin, command);
		commands.push_back(command);
	}

	for(auto command : commands){
		auto	pos	= command.find(separator);
		std::string	op		= command.substr(0, pos);
		std::string	args	= command.substr(pos + 1);

		//		std::cout << op << '\n';
		//		std::cout << args << '\n';
		if(op == "print"){
			print(str, args);
		}
		else if(op == "replace"){
			replace(str, args);
		}
		else{
			reverse(str, args);
		}
	}

	return 0;
}

void print(std::string&	str,
		   std::string&	args)
{
	auto	pos = args.find(separator);
	auto	a	= stoi(args.substr(0, pos));
	auto	b	= stoi(args.substr(pos + 1));

	std::cout << str.substr(a, (b - a) + 1) << '\n';
}

void replace(std::string&	str,
			 std::string&	args)
{
	auto	pos = args.find(separator);
	auto	a	= stoi(args.substr(0, pos));
	args.replace(0, pos + 1, "");
	pos			= args.find(separator);
	auto	b	= stoi(args.substr(0, pos));
	args.replace(0, pos + 1, "");
	str.replace(a, (b - a) + 1, args);
}

void reverse(std::string&	str,
			 std::string&	args)
{
	auto	pos = args.find(separator);
	auto	a	= stoi(args.substr(0, pos));
	auto	b	= stoi(args.substr(pos + 1));

	std::string	rep	= str.substr(a, (b - a) + 1);
	std::reverse(rep.begin(), rep.end());

	str.replace(a, (b - a) + 1, rep);
}



Measured memory_bytes: 3232
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct Restaurant {
  int idx;
  string city;
  int score;
};
bool operator<(const Restaurant& a, const Restaurant& b) {
  if (a.city != b.city) {
    return a.city < b.city;
  }
  return a.score > b.score;
}

int main() {
  int N;
  cin >> N;
  string  str;
  vector<Restaurant> rs;
  for (int n = 1; n <= N; ++n) {
	int S;
    cin >> str >> S;
    rs.push_back(Restaurant{n, str, S});
  }
  std::sort(rs.begin(), rs.end());
  
  for (const Restaurant &r : rs) {
    cout << r.idx << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 100001

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
    #endif
    ll dp[10001] = {0};
    ifr(i, 1, 101) ifr(j, 1, 101) ifr(k, 1, 101) {
        ll x = i*i + j*j + k*k + i*j + j*k + k*i;
        if(x>=10001) continue;
        dp[x]++;
    }
    // int T;cin>>T;while(T--) 
    {
        int n;
        cin>>n;
        ifr(i, 1, n+1) cout<<dp[i]<<endl;
    }
    return 0;
}

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

int main(){

    int k, a, b; cin >> k >> a >> b;
    for (int i=a; i<=b; i++){
        if (i%k==0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3636
from math import gcd
N=int(input())
A = list(map(int,input().split()))

val = A[0]
for i in range(1,N):
    val = gcd(val,A[i])

if val > 1:
    print("not coprime")
    exit()

D = [i for i in range(max(A)+1)]
p = 2

while(p*p<=max(A)):
    if D[p]==p:
        for i in range(2*p,len(D),p):
            if D[i]==i:
                D[i]=p

    p+=1

prime = set()
for a in A:
    tmp=D[a]
    L=set()
    while(a>1):
        a=a//tmp
        L.add(tmp)
        tmp=D[a]
    #print(L)
    for l in L:
        if l in prime:
            #print(D)
            #print(prime)
            print("setwise coprime")
            exit()
        else:
            prime.add(l)
#print(D)
#print(prime)
print("pairwise coprime")

Measured memory_bytes: 217068
#include<stdio.h>
int main(void)
{
	double h,m;
	int cMA,cHA;
	int cMB,cHB;
	int cMC,cHC;
	int cMD,cHD;
	cMA=0;
	cHA=0;
	cMB=0;
	cHB=0;
	cMC=0;
	cHC=0;
	cMD=0;
	cHD=0;
		while(scanf("%lf %lf",&h,&m)!=EOF){
			if(h>=1.1){
				cHA++;
			}
			else if(0.6<=h){
				cHB++;
			}
			else if(0.2<=h){
				cHC++;
			}
			else{
				cHD++;
			}
			if(m>=1.1){
				cMA++;
			}
			else if(0.6<=m && m<1.1){
				cMB++;
			}
			else if(0.2<=m && m<0.6){
				cMC++;
			}
			else if(0.2>m){
				cMD++;
			}
		}
	printf("%d %d\n%d %d\n%d %d\n%d %d\n",cHA,cMA,cHB,cMB,cHC,cMC,cHD,cMD);
	return 0;
}

Measured memory_bytes: 1056
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

int main(){

    int N;
    cin >> N;

    int i;
    vector<int> x(N);
    vector<int> y(N);
    for(i=0; i<N; i++) cin >> x.at(i) >> y.at(i);

    vector<int> array(N);
    for(i=0; i<N; i++) array.at(i) = i;

    int ave = 1;
    for(i=2; i<=N; i++) ave *= i;

    double ans = 0.0;
    double dist = 0;
    double tmp = 0;
    
    if(N == 2){
        dist = pow(x.at(0) - x.at(1), 2.0) + pow(y.at(0) - y.at(1), 2.0);
        ans = sqrt(dist);

    }
    else{

        do{
            for(i=0; i<N-1; i++){
                
                tmp += sqrt(pow(x.at(array.at(i)) - x.at(array.at(i+1)), 2.0) + pow(y.at(array.at(i)) - y.at(array.at(i+1)), 2.0)); 
            }

            dist += tmp;
            tmp = 0;

        }while(next_permutation(array.begin(), array.end()));
    
        ans = dist / ave;
    }

    printf("%.16lf\n", ans);
    return 0;
}



Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

const int N = 2e5 + 10;

typedef long long LL;

int n;
int a[N];

int main()
{
	cin >> n;
	for(int i = 1;i <= n;i ++) scanf("%d",&a[i]);
	
	LL res = 0;
	for(int i = 1;i < n;i ++)
		if(a[i + 1] < a[i])
		{
			res += a[i] - a[i + 1];
			a[i + 1] += a[i] - a[i + 1];
		}
	
	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 4020
#include<bits/stdc++.h>
#define endl "\n"
#define int long long
#pragma GCC optimize(3)
using namespace std;
int n,a[10005],b[10005],s1,s2;
signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n*2;i++)
		(i>n)?(cin>>b[i-n]):(cin>>a[i]);
	for(int i=1;i<=n;i++)
		(a[i]>b[i])?(s1+=(a[i]-b[i])):(s2+=(b[i]-a[i])/2);
	cout<<(s1<=s2?"Yes\n":"No\n");
}



Measured memory_bytes: 384
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
a = list(map(int, readline().split()))
if a[0] > 0:
    cnt2 = a[0] + 1
    now2 = -1
    cnt1 = 0
    now1 = a[0]
elif a[0] == 0:
    cnt2 = 1
    now2 = -1
    cnt1 = 1
    now1 = 1
else:
    cnt2 = 0
    now2 = a[0]
    cnt1 = -a[0] + 1
    now1 = 1
for i, aa in enumerate(a[1:]):
    if i % 2 == 0:
        if aa + now2 > 0:
            now2 += aa
        else:
            cnt2 += abs(now2 + aa) + 1
            now2 = 1
        if now1 + aa < 0:
            now1 += aa
        else:
            cnt1 += now1 + aa + 1
            now1 = -1
    else:
        if aa + now1 > 0:
            now1 += aa
        else:
            cnt1 += abs(now1 + aa) + 1
            now1 = 1
        if now2 + aa < 0:
            now2 += aa
        else:
            cnt2 += now2 + aa + 1
            now2 = -1
print(min(cnt1, cnt2))


Measured memory_bytes: 13024
#include<stdio.h>
int main(){
  char maz[10];
  int i=0,n,count=0,m,e=0,b=0;
  for(i=0;i<10;i++){
    scanf("%c",&maz[i]);
    if(maz[i]=='\n')break;
    
  }

  m=i-1;
  for(n=0;n<i/2;n++){

    if(maz[n] != maz[m]){
      if( (maz[n]=='(' && maz[m]==')') || (maz[n]==')' && maz[m]=='(')){
	e++;
      }
      count++;
    }else{
      if((maz[n]==')' && maz[m]==')') || (maz[n]=='(' && maz[m]=='(')){
	b++;
      }
    } 
    m--;
  
   
}
  
  if(i%2==1){
    if(!(maz[i-i/2-1]=='i' || maz[i-i/2-1]=='w'))
      count++;
  }



  printf("%d\n",count-e+b);
  return 0;
  }

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

#define f first
#define s second
#define all(x) x.begin(),x.end()
#define pb push_back
#define ll long long

using namespace std;

int main()
{
    int A,B,M;
    cin>>A>>B>>M;
    int mnA=INT_MAX,mnB=INT_MAX;
    vector<int> a(A),b(B);
    for(int i=0;i<A;i++)
        scanf("%i",&a[i]),mnA=min(mnA,a[i]);
    for(int i=0;i<B;i++)
        scanf("%i",&b[i]),mnB=min(mnB,b[i]);
    int sol=mnA+mnB;
    for(int i=0;i<M;i++){
        int x,y,c;
        scanf("%i %i %i",&x,&y,&c);
        x--;y--;
        sol=min(sol,a[x]+b[y]-c);
    }
    printf("%i\n",sol);
    return 0;
}


Measured memory_bytes: 1024
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n, m, xc, yc; readV(n, m, xc, yc);
  int[] x; readA(n, x);
  int[] y; readA(m, y);

  x ~= xc; y ~= yc;
  writeln(x.reduce!max < y.reduce!min ? "No War" : "War");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    
   ll n, k;
   cin >> n >> k;
   ll a[n+1];
   for(ll i = 1 ; i <=  n ; i++)
   cin >> a[i];

   ll dp[k+1];
   memset(dp , 0 , sizeof(dp));
   for(ll i = 1 ; i <= k ; i++)
   {    
       for(ll j = 1 ; j <= n ; j++)
       {
           if(i >= a[j] && !dp[i-a[j]])
           {
               dp[i] =1;
           }
       }
   } 
   if(dp[k])
   cout << "First" << "\n";
   else
   cout << "Second" << "\n";
}


Measured memory_bytes: 4448
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

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

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n){
        cin >> a[i];
    }
    lint ans = LINF;
    lint tmp = 0;
    REP(i, n){
        tmp = 0;
        while(a[i] % 2 == 0){
            tmp++;
            a[i] /= 2;
        }
        ans = min(ans, tmp);
    } 
    cout << ans << endl;
    return 0;
}

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

int main() {
    
    int N;
    cin >> N;
    vector<int> H(N);
    for(int i = 0; i < N; i++){
        cin >> H[i];
    }
    reverse(H.begin(), H.end());

    int ans = 0;
    int val = 0;

    for(int i = 1; i < N; i++){
        if(H[i-1] <= H[i]){
            val++;
        } else {
            val = 0;
        }
        ans = max(ans, val);
    }
    cout << ans << endl;

    return 0;
}
    

Measured memory_bytes: 3604
def gcd(x, y):
  while(y):
    x, y = y, x % y
  return x
a, b, k = map(int, input().split())
g = gcd(a, b)
dlist = []
for i in range(1, g + 1):
  if (g % i == 0):
    dlist.append(i)
dlist.sort(reverse=True)
print(dlist[k - 1])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long int
using namespace std;
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,b) for(i=a;i<b;i++)
#define vll vector<ll>
#define vlll vector<vll>
#define all(x) x.begin(),x.end()
int main()
{
  ll k;
  cin>>k;
  ll p=0;
  for(int i=0;i<1e7;i++)
  {
    p=p*10+7;
    p=p%k;
    if(p==0)
    {
      cout<<i+1;
      goto end;
      
    }
  }
  cout<<-1;
  end:    
  ;
  return 0;
}


Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
# モジュールのインポート
import math


def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N, X, T = list(map(int, input().split()))

    return N, X, T


def main(N: int, X: int, T: int) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 作るたこ焼きの個数(1 <= N <= 1000)
        X (int): 1度に作ることができるたこ焼きの個数(1 <= X <= 1000)
        T (int): たこ焼きを焼くのにかかる時間
    """
    # 求解処理
    ans = math.ceil(N / X) * T

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N, X, T = get_input()

    # メイン処理
    main(N, X, T)


Measured memory_bytes: 9160
/*
  AOJ 0231
  Title:
  @kankichi573
*/
#include <stdio.h>


int n,m[100],a[100],b[100];

int total_weight(int tim)
{
  int i,ret;
  for(i=ret=0;i<n;i++)
    {
      if(tim>=a[i] && tim<b[i])
	ret+=m[i];
    }
  return(ret);
}

main()
{
  int i,ret;

  while(scanf("%d",&n)  && (n))
    {
      for(i=0;i<n;i++)
	scanf("%d %d %d",&m[i],&a[i],&b[i]);
      ret=1;
      for(i=0;i<n;i++)
	{
	  if(total_weight(a[i])>150||total_weight(b[i])>150)
	    {
	      ret=0;
	      break;
	    }
	}
      printf("%s\n",ret?"OK":"NG");
    }
  return(0);
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N; cin >> N;
    vecl D(N); REP(i,N) cin >> D[i];
    int M; cin >> M;
    vecl T(M); REP(i,M) cin >> T[i];
    map<ll,int> mp;
    REP(i,N) {
        mp[D[i]]++;
    }
    REP(i,M) {
        if(mp.count(T[i])) {
            if(mp[T[i]] == 0) {
                cout << "NO" << endl;
                return 0;
            } else mp[T[i]]--;
        } else {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 18816
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
//typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  for(int i=0;i<(int)s.size();i++){cout<<"x";}
  cout<<endl;

  return 0;
}


Measured memory_bytes: 256
def permutation(items)
	if items.length <= 1 then
		return [items]
	else
		result = Array.new
		for i in 0...items.length do
			tmp = Array.new(items)

			result1 = [tmp.delete_at(i)]

			permutation(tmp).each do |item|
				result.push(result1 + item)
			end
		end
		return result
	end
end

cost = gets.split("\s").map(&:to_i)
cost_list = permutation(cost)

result_list = Array.new

cost_list.each do |item|
	result = 0
	for i in 1...item.length do
		result += (item[i] - item[i-1]).abs
	end
	result_list.push(result)
end

puts result_list.min

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

using namespace std;

//#define int long long
#define FOR(i, j, k) for(int i = j; i < (int)k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 30)

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

const int MOD = 1e9 + 7;
const int dy[] = {0, 0, 1, -1};
const int dx[] = {1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

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

    int n;
    cin >> n;
    rep(i, n) {
        int k, p;
        cin >> k >> p;
        (k % p == 0) ? cout << p : cout << k % p;
        cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 3160
#include <stdio.h>
int d, k, x;
char s[100001];
int main() {
	scanf("%s", s);
	scanf("%d", &k);
	while (s[d] != NULL)d++;
	for (int i = 0; i < d; i++) {
		x = 26 - (s[i] - 'a');
		x %= 26;
		if (x <= k) {
			k -= x;
			s[i] = 'a';
		}
	}
	k %= 26;
	s[d - 1] = 'a' + (s[d - 1] + k - 'a') % 26;
	printf("%s\n", s);
}

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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#ifdef LOCAL
#define dmp(x) cerr << __LINE__ << " " << #x << " " << x << endl
#else
#define dmp(x) void(0)
#endif

template <class t, class u>
void chmax(t &a, u b)
{
  if (a < b)
    a = b;
}
template <class t, class u>
void chmin(t &a, u b)
{
  if (b < a)
    a = b;
}
const int mod = 1000000007;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

template <class t>
using vc = vector<t>;
template <class t>
using vvc = vc<vc<t>>;

using vi = vc<int>;
int gcd(int a, int b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int lcm(int a, int b)
{
  return (a * b) / gcd(a, b);
}

int main()
{
ll n,k,s;cin>>n>>k>>s;
  if( s==1e9){
  rep(i,k){
   cout<<s<<" "<<endl; 
  }
    rep(i,n-k){
    cout<<1<<" "<<endl;
    }
  }else{
  rep(i,k){
  cout<<s<<" ";
  }
  rep(i,n-k){
  cout<<s+1<<" ";
  }
  }
 }

Measured memory_bytes: 1408
def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())
    bc = [None for _ in range(q)]
    for i in range(q):
        bc[i] = list(map(int, input().split()))

    count = [0 for i in range(100001)]
    for i in range(n):
        count[a[i]] += 1

    ans = [0 for _ in range(q+1)]
    for i in range(100001):
        ans[0] += i * count[i]
    for i in range(q):
        ans[i+1] = ans[i] - count[bc[i][0]] * bc[i][0] + count[bc[i][0]] * bc[i][1]
        count[bc[i][1]] += count[bc[i][0]]
        count[bc[i][0]] = 0

    for i in range(1, q+1):
        print(ans[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 37852
<?php
fscanf(STDIN, "%d%d", $n, $l);

$total = 0;
$min = 0;
$absmin = 99999999;
for($i = 0; $i < $n; $i++){
  $num = $i+$l;
  $total+=$num;
  if($num < $absmin){
    $absmin = abs($num);
    $min = $num;
  }
}
echo $total-$min;


Measured memory_bytes: 4728
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

typedef long long ll;
const int N=5e5+9;

ll to[N<<1],nxt[N<<1],beg[N],tot;
ll n,m,c[N],w[N<<1];
ll ans,f[4],flag;

inline void add(int u,int v,int c)
{
	to[++tot]=v;
	nxt[tot]=beg[u];
	w[tot]=c;
	beg[u]=tot;
}

inline void dfs(int u)
{
	f[c[u]]++;
	for(int i=beg[u];i;i=nxt[i])
	{
		if(w[i]==1)f[3]++;
		if(!(~c[to[i]]))
		{
			c[to[i]]=(c[u]+w[i])%3;
			dfs(to[i]);
		}
		else if (c[to[i]]!=(c[u]+w[i])%3)
			flag=1;
	}
}

int main()
{
	if(fopen("vj.in","r"))
	{
		freopen("vj.in","r",stdin);
		freopen("vj.out","w",stdout);
	}

	scanf("%d%d",&n,&m);
	for(int i=1,u,v;i<=m;i++)
	{
		scanf("%d%d",&u,&v);
		add(u,v,1);add(v,u,2);
	}

	memset(c,-1,sizeof(c));
	for(int i=1;i<=n;i++)
		if(!(~c[i]))
		{
			f[c[i]=0]=f[1]=f[2]=f[3]=flag=0;
			dfs(i);
			if(flag)
			{
				ll cnt=f[0]+f[1]+f[2];
				ans+=cnt*cnt;
				goto nxt;
			}
			if((!f[0]) || (!f[1]) || (!f[2]))
			{
				ans+=f[3];
				goto nxt;
			}
			
			ans+=f[0]*f[1];
			ans+=f[1]*f[2];
			ans+=f[2]*f[0];

			nxt:;
		}

	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 20096
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace LogicSummoner
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var nums = GetNumbersInt();
                if (nums[0] == 0 && nums[1] == 0)
                {
                    break;
                }

                var row1 = string.Join("", Enumerable.Repeat("#.", nums[1] / 2).ToArray());
                var row2 = string.Join("", Enumerable.Repeat(".#", nums[1] / 2).ToArray());

                if (nums[1] % 2 == 1)
                {
                    row1 += "#";
                    row2 += ".";
                }

                for (int i = 0; i < nums[0]; i++)
                {
                    if (i % 2 == 0)
                    {
                        System.Console.WriteLine(row1);
                    }
                    else
                    {
                        System.Console.WriteLine(row2);
                    }
                }

                System.Console.WriteLine();
            }
        }

        //static StreamReader Console = new StreamReader("input.txt");

        static int GetNumber()
        {
            return int.Parse(Console.ReadLine().Trim());
        }

        static double GetDounble()
        {
            return double.Parse(Console.ReadLine().Trim());
        }

        static List<int> GetNumbersInt(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
        }

        static List<long> GetNumbersLong(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToList();
        }

        static List<double> GetNumbersDouble(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => double.Parse(x)).ToList();
        }

        static List<string> GetStrings()
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToList();
        }
    }
}

Measured memory_bytes: 10052
#include <iostream>

using namespace std;

int main(void){
    int n, k;

    cin >> n >> k;
    
    int a;

    if(n % 2 == 0){
        a = n / 2;
    }
    else{
        a = n / 2 + 1;
    }
    
    if(a >= k){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    
    return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int MOD = 1000000007;
const int MX = 2010;

int N, M, K;
int dp[MX * 2][MX];

inline void add(int &x, int y) { x += y; if (x >= MOD) x -= MOD; }

int main() {
	cin >> N >> M >> K;

	for (int i = 1; i < K; ++i) {
		if (i <= N && (K - 1 - i) <= M - 1) {
			dp[1][i] = 1;
		}
	}

	int ret = 0;

	for (int i = 1; i < MX * 2 - 1; ++i) {
		rep(j, MX) if (dp[i][j]) {
			if ((j - N) % (K - 1) == 0 && (j + (M - 1)) % (K - 1) == 0) {
				add(ret, dp[i][j]);
			}

			rep(k, K) { //add k to the front
				if (j + k <= N && (K - 1) * (i + 1) - j - k <= M-1) {
					add(dp[i + 1][j + k], dp[i][j]);
				}
			}
		}
	}

	cout << ret << endl;

	return 0;
}

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

#define INF (INT64_MAX)
#define MOD (1000000000+7)
#define MAX 200000

int main() {
	int N, H, W;

	cin >> N >> H >> W;

	int ans = ( N - H  + 1) * ( N - W + 1);

	cout << ans << endl;

	return 0;
}


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

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int main(int argc, const char * argv[]) {
    int h,w;
    cin>>h>>w;
    string s[h];
    int ans[51][51];
    for (int i=0; i<h; i++) {
            cin>>s[i];
    }
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            ans[i][j]=0;
            if (i-1>=0 &&j-1>=0 && s[i-1][j-1]=='#') {
                ans[i][j]+=1;
            }
            
            if (i-1>=0 && s[i-1][j]=='#') {
                ans[i][j]+=1;
            }
            if (i-1>=0 &&j+1<w&& s[i-1][j+1]=='#') {
                ans[i][j]+=1;
            }
            
            if (i+1<h && s[i+1][j]=='#') {
                ans[i][j]+=1;
            }
            if (i+1<h &&j-1>=0 &&s[i+1][j-1]=='#') {
                ans[i][j]+=1;
            }
            if (i+1<h && j+1<w&&s[i+1][j+1]=='#') {
                ans[i][j]+=1;
            }
            
            
            
            if (j-1>=0 && s[i][j-1]=='#') {
                ans[i][j]+=1;
            }
            if (j+1<w && s[i][j+1]=='#') {
                ans[i][j]+=1;
            }
            
            
            
            if (s[i][j]=='#') {
                ans[i][j]=-1;
            }
        }
    }
    
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            if (ans[i][j]==-1) {
                cout<<'#';
            }else cout<<ans[i][j];
        }
        cout<<endl;
    }
    return 0;
}


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

int main()
{
    int n, a[100], max, i, j;

    cin >> n;

    for (i = 0;i < n;i++) {
        cin >> a[i];
        if (a[i] < 0) {
            a[i] = -a[i];
        }
    }

    max = 0;
    for (i = 0;i < n;i++) {
        for (j = i + 1;j < n;j++) {
            if(abs(a[i] - a[j]) > max) {
                max = abs(a[i] - a[j]);
            }
        }
        
    }

    cout << max <<"\n";


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

typedef pair<int, int> P;
int main() {
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,n){
        cin>>v[i];
    }
    vector<P> ki(100001);
    vector<P> gu(100001);
    rep(i,100001){
        ki[i].second=i;
        gu[i].second=i;
    }
    int ki_co=0;
    int gu_co=0;
    for(int i=0; i<n; i+=2){
        ki[v[i]].first-=1;
        ki_co++;
    }
    for(int i=1; i<n; i+=2){
        gu[v[i]].first-=1;
        gu_co++;
    }
    sort(ki.begin(),ki.end());
    sort(gu.begin(),gu.end());
    if(ki[0].first==gu[0].first && ki[0].second==gu[0].second){
        if(ki[1].first<=gu[1].first){
            cout<<ki_co+ki[1].first+gu_co+gu[0].first<<endl;
        }
        else{
            cout<<ki_co+ki[0].first+gu_co+gu[1].first<<endl;
        }
    }
    else{
        cout<<ki_co+ki[0].first+gu_co+gu[0].first<<endl;
    }

}


Measured memory_bytes: 2176
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k, ans int
	fmt.Scan(&n, &k)
	p := make([]int, n)
	for i := range p {
		fmt.Scan(&p[i])
	}
	sort.Ints(p)
	for i := 0; i < k; i++ {
		ans += p[i]
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1900
#include <stdio.h>
#include <iostream>
#include <climits>
#include <map>
#include <cmath>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <vector>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <utility>
#include <queue>
//#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define scl(n) scanf("%lld", &n)
#define scd(n) scanf("%lf", &n)
#define scc(n) scanf(" %c", &n)
#define scs(n) scanf(" %s", n)
#define pll pair<ll, ll>
#define bigprime 9867589359258017
#define pbase 925943
#define pmod 1351782499
#define pi acos(-1.0)

int main()
{
    ll a, b;
    scl(a);
    scl(b);
    if(a%3==0 || b%3==0 || (a+b)%3==0)
        printf("Possible\n");
    else
        printf("Impossible\n");
    return 0;



}






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

int main(){
    int a,b,ans=0;
    cin>>a>>b;
    if(a>=b){
    	ans=a;
    	a--;
    }
    else ans=b,b--;
    if(a>=b){
    	ans+=a;
    }
    else ans+=b;
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 250000
ll MOD=998244353;

main(){
    int n=in();
    vec p;
    rep(i,n){
        p.pb(in());
    }
    vec s=p;
    sort(all(s));
    rep(i,n){
        rep(j,n){
            vec t=p;
            swap(t[i],t[j]);
            if(t==s){
                cout<<"YES";return 0;
            }
        }
    }
    cout<<"NO";return  0;
}



Measured memory_bytes: 256
N = int(input())
S = input().strip()

import collections
import string
ans = 0
for i in range(N):
  X = S[:i]
  Y = S[i:]
  cntX = collections.Counter(X)
  cntY = collections.Counter(Y)
  
  tmp = 0
  for c in string.ascii_lowercase:
    tmp += 0 if min(cntX[c], cntY[c]) == 0 else 1
  ans = max(ans, tmp)
print(ans)

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

ll check(const vector<int>& A, const vector<tuple<int, int, int, int>>& q) {
    ll ans = 0;
    for (const auto& t : q) {
        int a = get<0>(t);
        int b = get<1>(t);
        int c = get<2>(t);
        int d = get<3>(t);
        if (A[b] - A[a] == c) ans += d;
    }
    return ans;
}

bool next(vector<int>& A, int m) {
    int end = A.size() - 1;
    while (A[end] == m) end--;
    if (end == -1) return false;
    A[end]++;
    for (end++; end < A.size(); end++) {
        A[end] = A[end-1];
    }
    return true;
}

int main() {
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<int> A(N);
    vector<tuple<int, int, int, int>> q(Q);
    for (int i = 0; i < Q; ++i) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--; b--;
        q[i] = make_tuple(a, b, c, d);
    }
    ll m = 0;
    for (int i = 0; i < N; ++i) {
        A[i] = 1;
    }
    m = check(A, q);
    while (next(A, M)) {
        m = max(m, check(A, q));
    }
    cout << m << endl;
}


Measured memory_bytes: 3592
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	string S;
	cin>>S;
	for(int i=S.length()-1;i>=0;i--)
	{
		string x=S.substr(0,i);
		if(x.length()%2==0)
		{
			string a=x.substr(0,x.length()/2);
			string b=x.substr(x.length()/2,x.length()/2);
			if(a==b)
			{
				printf("%d\n",x.length());
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))
inf = float('inf')
dp = [inf]*(N+3)
dp[0] = 0
dp[1] = abs(H[0]-H[1])
#dp[2] = abs(H[1]-H[0])
for i in range(2,N):
    dp[i] = min(dp[i-1]+abs(H[i-1]-H[i]), dp[i-2]+abs(H[i-2]-H[i]))
print(dp[N-1])
#print(dp)

Measured memory_bytes: 13908
#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 all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll N, K;
    cin >> N >> K;
    vll A(N), F(N);
    for (size_t i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    sort(all(A));
    for (size_t i = 0; i < N; i++)
    {
        cin >> F[i];
    }
    sort(all(F), greater<ll>());
    auto can = [&](ll X) {
        ll need = 0;
        for (size_t i = 0; i < N; i++)
        {
            if (A[i] * F[i] > X)
            {
                need += A[i] - (X / F[i]);
            }
        }
        return (need <= K);
    };
    ll ok = INF / 2, ng = -1;
    while (abs(ok - ng) > 1)
    {
        ll mid = (ok + ng) / 2;
        if (can(mid))
        {
            ok = mid;
        }
        else
        {
            ng = mid;
        }
    }
    cout << ok;
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>

using namespace std;

int main() {
    int a,b,c,d,e,f,g,h;
    cin >>a>>b>>c;
    d=1;
    if(a!=b){
        if(b!=c){
            if(a!=c){
                 d=3;
             }
           else{
               d=2;
            }
        }
        else{
            if(a!=c){
                 d=2;
             }
            else{
                d=4;
            }
        }
    }
    else{
        if(b!=c){
            if(a!=c){
                 d=2;
             }
           else{
                d=4;
            }
        }
        else{
            if(a!=c){
                 d=4;
             }
            else{
                d=1;
            }
        }
    }
    cout<<d;
}

Measured memory_bytes: 256
#include<stdio.h>
int prime(int x){
  int i;
  for(int i=2;i*i<=x;++i)
    if(x%i==0) return 0;
  return 1;
}
int main(){
  int n,x,i,cnt=0;
  scanf("%d",&n);
  for(i=1;i<=n;++i){
    scanf("%d",&x);
    cnt+=prime(x);
  }
  printf("%d\n",cnt);
  return 0;
}



Measured memory_bytes: 2692
import java.util.Scanner;

public class Main {

    private static int findPositiveIndex(int[] h) {
        for(int i = 0; i < h.length; i++) {
            if (h[i] > 0) return i;
        }
        return -1;
    }

    private static int solve(int[] h) {
        int cur = findPositiveIndex(h);
        int count = 0;

        while (cur >= 0) {
            for(int i = cur; i < h.length; i++) {
                if(h[i] > 0) {
                    h[i] -= 1;
                } else {
                    break;
                }
            }
            count += 1;
            cur = findPositiveIndex(h);
        }

        return count;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] h = new int[N];
        for(int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }

        int ans = solve(h);
        System.out.println(ans);
    }
}


Measured memory_bytes: 23124
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int l = s.length();
        boolean flag = true;
        if(s.charAt(l - 1) == '1' || s.charAt(0) == '0') flag = false;
        else{
            for(int i = 0; i < l / 2; i++){
                if(s.charAt(i) != s.charAt(l - i - 2)){
                    flag = false;
                    break;
                }
            }
        }
        if(flag){
            int[] from = new int[l-1];
            int[] to = new int[l-1];
            int[] t = new int[l];
            int tnum = -1;
            for(int i = 0; i < l; i++){
                if(s.charAt(i) == '1'){
                    t[++tnum] = i;
                }
            }
            for(int i = 0; i < l-1; i++){
                from[i] = i; 
            }
            int tind = 0;
            for(int i = 0; i < l-2; i++){
                if(s.charAt(i) == '1'){
                    to[i] = t[++tind];
                }
                else{
                    to[i] = t[tind];
                }
                System.out.println((from[i]+1) + " " + (to[i]+1));
            }
            System.out.println((l-1) + " " + l);
        }
        else{
            System.out.println(-1);
        }
    }
 }




Measured memory_bytes: 59012
#include <iostream>
#include <vector>
#include <memory>
using namespace std;
using uint = unsigned int;

struct Edge{
	int a, b, c;
};

void dfs(const int pv, const int pc, const int v, vector<vector<shared_ptr<Edge>>>& g) {
	int c = 1;
	for(uint i=0; i<g[v].size(); i++) {
		shared_ptr<Edge> e = g[v][i];
		int nv = (e->a == v) ? e->b : e->a;
		if(nv == pv) { // edge to parent
			continue;
		} else { // cedge to hild
			if(c == pc) {
				c++;
			}
			e->c = c;
			dfs(v, c, nv, g);
			c++;
		}
	}
}

int main(){
	uint N;
	cin >> N;

	vector<vector<shared_ptr<Edge>>> G(N, vector<shared_ptr<Edge>>());
	vector<shared_ptr<Edge>> ab;
	uint max_dgree = 0;
	
	for(uint i=0; i<N-1; i++) {
		int a, b;
		cin >> a >> b;
		shared_ptr<Edge> edge(new Edge());
		edge->a = --a;
		edge->b = --b;
		ab.push_back(edge);
		G[a].push_back(edge);
		G[b].push_back(edge);
		max_dgree = max(max_dgree, (uint)max(G[a].size(), G[b].size()));
	}
	
	cout << max_dgree << endl;
	
	dfs(-1, 0, 0, G);

	for(uint i=0; i<N-1; i++) {
		cout << ab[i]->c << endl;
	}

	
	return 0;
}


Measured memory_bytes: 15728
# -*- coding: utf-8 -*-

n = int(input())
a = list(map(int, input().split()))
l = []


for i in range(len(a) - 1):
    if a[i + 1] < a[i]:
        l.append(a[i]-a[i + 1])
        a[i + 1] = a[i]


print(sum(l))


Measured memory_bytes: 105424
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long long ll;

int a, b;

int main(void) {
    scanf("%d %d", &a, &b);
    
    int x = b - a - 1;
    int h = 0;
    REP(i, 1, x+1) h += i; 
    printf("%d\n", h - a);

	return 0;
}


Measured memory_bytes: 256
c=[list(map(int,input().split())) for _ in [0]*3]
x1,x2,y1,y2=c[0][0]-c[0][1],c[0][1]-c[0][2],c[0][0]-c[1][0],c[1][0]-c[2][0]
for i in range(1,3):
  if c[i][0]-c[i][1]!=x1 or c[i][1]-c[i][2]!=x2:
    print('No')
    exit()
  if c[0][i]-c[1][i]!=y1 or c[1][i]-c[2][i]!=y2:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 3064