akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include<iostream>

int main() {
	int locate[5];
	for (int i = 0; i < 5; i++) {
		int N = 0;
		scanf("%d", &N);
		locate[i] = N;
	}
	int K = 0;
	scanf("%d", &K);
	if (locate[4] - locate[0] <= K) {
		std::cout << "Yay!" << std::endl;
	}
	else {
		std::cout << ":(" << std::endl;
	}
}



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

ll abs(ll x,ll y){
    ll ret;
    if(x > y) ret = x - y;
    else ret = y - x;
    return ret;
}

ll chmin(ll x,ll y){
    if(x > y){
        return y;
    }
    else{
        return x;
    }
}

int main() {
    int n;
    cin >> n;
    vector<int> h (n);
    for(int i=0; i<n; i++){
        cin >> h.at(i);
    }
    vector<ll> dp (n,10000000000);
    dp.at(0) = 0;
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<=min(n-1,i+2); j++){
            dp.at(j) = chmin(dp.at(i) + abs(h.at(i),h.at(j)) , dp.at(j));
        }
    }
    cout << dp.at(n-1) << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <vector>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (n); i++)

using namespace std;

int main()
{
	long long n; cin >> n;
	int h[200001]; REP(i, n)cin >> h[i];
	long long ans = 0;
	// key: id-height, value: id
	map<long long, int> v;
	REP(i, n) {
		v[i - h[i]]++;
	}
	// if my(id + height) == someone's (id-height) it's ok
	REP(i, n) {
		ans += v[i + h[i]];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 27000
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    int resa=-1;
    int resb=0;
    double val=-1;
    for(int x=0;x<=100;x++){
        for(int y=0;y<=100;y++){
            if(x==0 && y==0) continue;
            for(int z=0;z<=100;z++){
                int water=x*100*a+y*100*b;
                int solt=c*z;
                if((water/100)*e<solt) continue;
                if(solt+water>f) continue;
                int rest=(((water/100)*e-solt)/d)*d;
                rest=min(rest,max(0,((f-water-solt)/d)*d));
                
                solt+=rest;
                if(solt+water>f) continue;
                double ans=double(solt)/water;
                if(ans>val){
                    val=ans;
                    resa=water;
                    resb=solt;
                }
            }
        }
    }
    cout<<resa+resb<<" "<<resb<<endl;
 
    return 0;
}

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

int main() {
  int N,K,Q;
  cin >> N >> K >> Q;
  vector<int> vec(N,0);
  int a;
  for (int i=0; i<Q; ++i) {
    cin >> a;
    vec.at(a-1) += 1;
  }
  for (int j=0; j<N; ++j) {
    if (K-Q+vec.at(j) >= 1) {
      cout << "Yes" << endl;
  }else{
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 1024
using System;
class Program
{
    static void Main(string[] args)
    {
        // 整数の入力

        //// スペース区切りの整数の入力
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int A = int.Parse(input[1]);
        int B = int.Parse(input[2]);


        int res = 0;


        for (int i = 1; i <= N; i++)
        {
            var n = i;
            int sum = 0;
            while (n > 0)
            {
                sum += n % 10;
                n = n / 10;
            }
            if (A <= sum && sum <= B)
            {
                res += i;
            }
        }


        //出力
        Console.WriteLine(res.ToString());
    }
}


Measured memory_bytes: 11092
/*
██████╗  ███████╗  
██╔══██╗ ██╔════╝ 
██████╔╝ ███████╗ 
██╔══██╗ ╚════██║  
██║  ██║ ███████║      
╚═╝  ╚═╝ ╚══════╝                                                                                                             
*/

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define haha(j,a,n) for(int j=a;j<n;j++)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define endl "\n"
#define bc(v) v.begin(),v.end()
#define vl vector<ll>
#define vi vector<int>
#define why 1000000007
#define NUM 100005
#define F first
#define S second
#define bhar(a) rep(i,a.size()) cin>>a[i];
#define show(a) rep(i,a.size()) cout<<a[i]<<" ";
#define sott(a) sort(bc(a))
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define mapp map<ll,ll>
#define dkac cout<<fixed<<setprecision(15);
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define yeah(n) while(n--)
ll gcd(int a, int b){if(b==0) return a; else return gcd(b,a%b);}
ll bitfun(ll x){
  return (x&(-x));
}
void solve(){
  ll n; cin>>n;
  ll sm=0;
  haha(i,1,n+1){
    if(i%3!=0 && i%5!=0) sm+=i;
  }
  cout<<sm;
}
int main(){
    ios
    int t=1; 
    //cin>>t;
    yeah(t){
      solve();
    }
}

Measured memory_bytes: 3640
def is_strong_palindrome(s):
    if len(s) < 1:
        return True
    elif s != s[::-1]:
        return False

    left = s[:len(s) // 2]
    right = s[len(s) // 2 + (1 if len(s) % 2 != 0 else 0):]
    return left == left[::-1] and right == right[::-1]


if __name__ == '__main__':
    s = input()

    print("Yes" if is_strong_palindrome(s) else "No")


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for (int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

int main()
{
	ll ans = 0;
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	rep (i, n) cin >> h.at(i);
	sort(h.rbegin(), h.rend());
	for (int i=k; i<n; i++) {
		ans += h.at(i);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)	for(int i=0;i<n;i++)
int main(){
  int n;	cin >> n;
  vector<int>	w(n);
  rep(i,n)	cin >> w[i];
  
  int sum=0;
  rep(i,n)	sum+=w[i];
  
  int now=0;
  int ans=sum;
  rep(i,n){
    now+=w[i];
    ans=min(ans,abs(sum-now*2));
  }
   cout << ans; 
}

Measured memory_bytes: 3624
import sys
input = sys.stdin.readline
from collections import Counter


N, K = map(int, input().split())
A = list(map(int, input().split()))
A_count = Counter(A)
A_unique = list(set(A))
A_list = []
if len(A_unique) <= K:
    print(0)
    exit()
else:
    del_num = len(A_unique) - K
    for i in A_unique:
        A_list.append(A_count[i])
    A_list.sort()
    print(sum(A_list[:del_num]))

Measured memory_bytes: 39920
#include<stdio.h>
int main() {
	int i, x[10000];

	for (i = 0; i < 10000; i++) {
		scanf("%d", &x[i]);
		if (!x[i]) break;
	}
	for (i = 0; i < 10000 && x[i]; i++) {
		printf("Case %d: %d\n", i+1, x[i]);
	}
	return 0;
}

Measured memory_bytes: 2648
#include <bits/stdc++.h>
    using namespace std;
    #define all(x) (x).begin(),(x).end() 
    #define int long long
    #define vi vector<int>
    #define pii pair<int,int>
    #define F first
    #define S second
    #define pb push_back
    #define rep(i, a, b) for(int i = a; i < b; i++)
    #define repr(i, a, b) for(int i = a - 1; i >= b; i--)
    #define iter(m) for(auto it = m.begin(); it != m.end(); it++)
    #define iterr(m) for(auto it = m.rbegin(); it != m.rend(); it++)
    #define N 500500
    #define PI 3.14159265358979323846264338327950L
    #define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);

    signed main(){
        speed;
        int a, b, c, d; cin >> a >> b >> c >> d;
        vector<int> ans = {b * d, a * c, a * d, b * c};
        if(a <= 0 && b >= 0) ans.push_back(0);
        if(c <= 0 && d >= 0 ) ans.push_back(0);
        sort(all(ans));
        cout << ans[ans.size() - 1];
        return 0;
    }

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >>b;
  if (a + b == 3) {
    cout << 3 << endl;
  }
  else if (a + b == 4) {
    cout << 2 << endl;
  }
  else {
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
import numpy as np
H, W = map(int, input().split())
mat = np.array([list(input()) for _ in range(H)])
mat = mat[:, ~np.where(mat == '.', True, False).all(axis=0)]
mat = mat[~np.where(mat == '.', True, False).all(axis=1)]

print('\n'.join([''.join(row) for row in mat]))


Measured memory_bytes: 12536
# Aizu Problem ALDS_1_1_A: Insertion Sort
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt")


def printA(A):
    print(' '.join([str(a) for a in A]))

def insertion_sort(A):
    for i in range(1, len(A)):
        key = A[i]
        # insert A[i] into the sorted sequence A[0,...,j-1] 
        j = i - 1
        while j >= 0 and A[j] > key:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = key
        printA(A)

        
N = int(input())
A = [int(_) for _ in input().split()]
printA(A)
insertion_sort(A)

Measured memory_bytes: 7812
// https://atcoder.jp/contests/abc085/tasks/abc085_b

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	var d []int

	sc.Split(bufio.ScanWords)
	n := nextInt()

	for i := 0; i < n; i++ {
		d = append(d, nextInt())
	}

	m := make(map[int]bool)
	uniq := []int{}

	for _, ele := range d {
		if !m[ele] {
			m[ele] = true
			uniq = append(uniq, ele)
		}
	}

	fmt.Printf("%v\n", len(uniq))
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)


int main()
{
    fast;
     ll n;
     cin>>n;
     if(n%2||(n<10))
      cout<<0;
      else
      {
         ll count=0;
         n=(n/2);
         ll p=5;
         while(p<=n)
         {
             count+=(n/p);
             p*=5;
         }
         cout<<count;
      }
         return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main()
{
  string str;
  cin >> str;

  long long res = 0;
  for (int i = 0; i < (1 << (str.size() - 1)); i++) {
	int st = 0;
	for (int j = 0; j < str.size(); j++) {
	  if (i & (1 << j)) {
		res += stoll(str.substr(st, (j + 1) - st));
		st = j + 1;
	  }
	}
	res += stoll(str.substr(st, (str.size() - st)));
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m;
  string s;
  cin >> n >> m >> s;
  vector<P> v;
  ll c=1;
  REP(i,1,n) {
    if(s[i-1]!=s[i]) {
      v.pb(P(c,s[i-1]-'0'));
      c=1;
    } else c++;
  }
  v.pb(P(c,s.back()-'0'));
  ll d[v.size()+1];
  mem(d);
  rep(i,v.size()) d[i+1]=d[i]+v[i].F;
  ll ans=0;
  rep(i,v.size()) {
    ll k=m*2;
    if(v[i].S) k++;
    ans=max(ans,d[min((ll)v.size(),i+k)]-d[i]);
  }
  pr(ans);
}

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


Measured memory_bytes: 2880
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	
	int N, K;
	cin >> N >> K;
	
	if(2 * K - 1 <= N){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        int n, sum = 0;

        Scanner input = new Scanner(System.in);

        n = input.nextInt();

        if (n >= 1 && n <= 100) {

            for (int i = 1; i <= n; i++) {

                sum = sum + i;
            }

            System.out.println(sum);
        }

    }

  }

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

bool is_prime(int x)
{
	if (x <= 1)
		return false;
	else if (x <= 3)
		return true;

	for (int i = 2; i <= sqrt(x) + 10; ++i) {
		if (x % i == 0)
			return false;
	}
	return true;
}

int main()
{
	long long a;
	cin >> a;

	if (is_prime(a)) {
		cout << a;
	}
	else {
		while (!is_prime(++a));
		cout << a;
	}

}


Measured memory_bytes: 256
class Dice():
	def __init__(self):
		self.number = [int(i) for i in range(1,7)]
	
	def set_number(self,n0,n1,n2,n3,n4,n5):
		self.number[0] = n0
		self.number[1] = n1
		self.number[2] = n2
		self.number[3] = n3
		self.number[4] = n4
		self.number[5] = n5

	def roll(self,s):
		tmp = self.number
		if s == "S":
			self.set_number(tmp[4],tmp[0],tmp[2],tmp[3],tmp[5],tmp[1])
		elif s == "E":
			self.set_number(tmp[3],tmp[1],tmp[0],tmp[5],tmp[4],tmp[2])
		elif s == "N":
			self.set_number(tmp[1],tmp[5],tmp[2],tmp[3],tmp[0],tmp[4])
		elif s == "W":
			self.set_number(tmp[2],tmp[1],tmp[5],tmp[0],tmp[4],tmp[3])

	def get_number(self,i):
		# top: 0, front: 1, right: 2, left: 3, back: 4, bottom: 5 
		return self.number[i]

	def get_position(self,i):
		return self.number.index(i)
	
	def get_dice(self):
		return [self.number[0],self.number[1],self.number[2],self.number[3],self.number[4],self.number[5]]

def check_dice(diceA,diceB):
	dice_numA = diceA.get_dice()
	dice_numB = diceB.get_dice()
	dice_numA.sort()
	dice_numB.sort()
	if dice_numA == dice_numB:
		top = diceA.get_number(0)
		front = diceA.get_number(1)
		while diceB.get_number(1) != front:
			if diceB.get_position(front) == 2 or diceB.get_position(front) == 3:
				diceB.roll("E")
			else:
				diceB.roll("S")
		if diceB.get_number(4) != top:
			while diceB.get_number(0) != top:
				diceB.roll("E")
			if diceA.get_dice() == diceB.get_dice():
				return 0
	return 1

if __name__ == '__main__':
	num = int(input())
	dice_num = []
	for i in range(num):
		dice_num.append([int(s) for s in input().split()])

	dice = []
	for i in range(num):
		dice.append(Dice())
		dice[i].set_number(dice_num[i][0],dice_num[i][1],dice_num[i][2],dice_num[i][3],dice_num[i][4],dice_num[i][5])

	flag = 0

	for i in range(num):
		for k in range(i+1,num):
			if check_dice(dice[i],dice[k]) == 0:
				print("No")	
				exit()
	print("Yes")



Measured memory_bytes: 5664
#include <bits/stdc++.h>
const int INF = 1e9;
const int MO = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define rt return
#define ENDL cout<<endl
#define MAXE(a,b) a=max(a,b)
#define MINE(a,b) a=min(a,b)
#define s second
#define f first

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    int N;cin >> N;
    string s;
    cin >> s;
    if(count(s.begin(),s.end(),'R') > count(s.begin(),s.end(),'B')){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <string.h>
#include <iomanip>
using namespace std;
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define div 1000000007
#define pi 3.14159265358979323846

void solve()
{
    double r;cin>>r;
    cout<<2*pi*r<<nl;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t=1;
    //cin>>t;
    //int i=1;
    while(t--)
    {
        //cout<<"Case #"<<i<<": ";
        solve();
        //i++;
    }
    return 0;
}


Measured memory_bytes: 3804
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict,deque

N=input()
M=[[None]]

for i in range(N):
	A=map(int, sys.stdin.readline().split())
	M.append(A)

position=[0]*(N+1)

ans=0
goal_cnt=0
day=0
q=deque()

game=set()
for me in range(1,N+1):
	p=position[me]
	opp=M[me][p]	#Opponent
	if me>opp: me,opp=opp,me
	game.add((me,opp))


while game:
	Visit=defaultdict(lambda: None) 
	next_game=set()
	for me,opp in game:
		opp_of_me=M[me][position[me]]
		opp_of_opp=M[opp][position[opp]]
		if me==opp_of_opp and opp==opp_of_me and Visit[me] is None and Visit[opp] is None:
			Visit[me]=1
			Visit[opp]=1
			position[me]+=1
			position[opp]+=1
			try:
				next_opp_of_me=M[me][position[me]]
				if me>next_opp_of_me: me,next_opp_of_me=next_opp_of_me,me
				next_game.add((me,next_opp_of_me))
			except:
				goal_cnt+=1
			try:
				next_opp_of_opp=M[opp][position[opp]]
				if opp>next_opp_of_opp: opp,next_opp_of_opp=next_opp_of_opp,opp
				next_game.add((opp,next_opp_of_opp))
			except:
				goal_cnt+=1
	day+=1
	game=next_game

if goal_cnt!=N:
	print -1
else:
	print day

Measured memory_bytes: 42908
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int ans = 700;
    string s; cin >> s;
    if(s[0]=='o') ans += 100;
    if(s[1]=='o') ans += 100;
    if(s[2]=='o') ans += 100;
    cout << ans;
    cout << endl;
    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int A, B, F, H, I, J, K, L, M, N, S, T;
// long long int A, B, F, H, I, J, K, L, M, N, S, T;
int ans;

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

	cin >> A >> B >> M;

	vector<int> av(A);
	rep(i, A) {
		cin >> av[i];
	}
	vector<int> bv(B);
	rep(i, B) {
		cin >> bv[i];
	}

	ans = *min_element(av.begin(), av.end())
		+ *min_element(bv.begin(), bv.end());

	rep(i, M) {
		cin >> F >> S >> T;
		F--;
		S--;
		ans = min(ans, av[F] + bv[S] - T);
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), cout, ", ") << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, ostream &os = cout, string sep = " ")
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), os, ", ") << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    AIN(string, S, N);
    map<string, ll> c;
    ll m = 0;
    FOR(s, S)
    {
        ++c[s];
        CH(max, m, c[s]);
    }
    vs ans;
    FOR(s, S)
    {
        if (c[s] == m)
        {
            ans.push_back(s);
            --c[s];
        }
    }
    SORT(ans);
    FOR(a, ans)
    {
        OUT(a);
    }
}

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

typedef long long int ll;

#define rep(i,n) for(ll i = 0; i < n; i++)

int main() {
  ll n,y;
  cin >> n >> y;
  rep(i,n+1) {
    rep(j,n+1) {
      if (n-i-j < 0) {
        continue;
      }
      if (10000*i + 5000*j + 1000*(n-i-j) == y) {
        cout << i << " " << j << " " << n-i-j << endl;
        exit(EXIT_SUCCESS);
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n;
    cin >> n;
    vector<i64> d(n + 1);
    for (i64 i = 0; i < n; i++) cin >> d[i];
    sort(all(d));

    for (i64 i = 0; i < n + 1; i++) {
        if (i % 2) d[i] = -d[i];
    }
    sort(all(d));

    i64 ans = d.back() - d.front();
    ans = min(ans, 24 - ans);
    for (i64 i = 0; i + 1 < n + 1; i++) {
        ans = min(ans, d[i + 1] - d[i]);
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
//#include <fstream>
#include <complex>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
const ll INF = (1LL << 50);
typedef pair<int, int> P;

int main() {

	int h, n;
	cin >> h >> n;

	vector<int>a(n);
	REP(i, n) cin >> a[i];

	REP(i, n) {
		h -= a[i];
	}

	if (h > 0) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

	return 0;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n, a, b, c;
  cin >> n;
  a = n / 3, b = n / 5; c = n / 15;
  cout << n * (n + 1) / 2 - a * (a + 1) / 2 * 3 - b * (b + 1) / 2 * 5 + c * (c + 1) / 2 * 15;
  return 0;
}

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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll h, a, b, c;
string s, t;

int main(){
	cin >> h >> a;
	p((h+a-1) / a);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    unsigned long long H,W; //1-10^9
    unsigned long long masu_num = 0;

    cin >> H >> W;

    //HかWが1 -> 1を出力（動けない）
    if( H == 1 ||
        W == 1)
    {
        cout << 1 << endl;
        return 0;
    }

    //H,Wが奇数 -> 全マスの半分+1
    if( H % 2 == 1 &&
        W % 2 == 1)
    {
        masu_num = ((H*W)/2) + 1;
        cout << masu_num << endl;
        return 0;
    }

    //H,Wが偶数 / H,Wが偶数奇数の組み合わせ -> 全マスのちょうど半分
    masu_num = (H*W)/2;
    cout << masu_num << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

ll dp[200010][3];

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,200010)rep(j,3) dp[i][j] = -LINF;
    dp[1][0] = a[0];
    dp[2][1] = a[1];
    if(n >= 3) dp[3][2] = a[2];
    rep(i,n+1)rep(j,3){
        if(i-2 >= 1 && dp[i-2][j] != -LINF) dp[i][j] = max(dp[i][j],dp[i-2][j]+a[i-1]);
        if(j >= 1){
            if(i-3 >= 1 && dp[i-3][j-1] != -LINF) dp[i][j] = max(dp[i][j],dp[i-3][j-1]+a[i-1]);
        }
        if(j == 2){
            if(i-4 >= 1 && dp[i-4][j-2] != -LINF) dp[i][j] = max(dp[i][j],dp[i-4][j-2]+a[i-1]);
        }
    }
    ll ans = -LINF;
    if(n%2 == 0){
        ans = max({ans,dp[n-1][0],dp[n][1]});
    }
    else{
        ans = max({ans,dp[n-2][0],dp[n-1][1],dp[n][2]});
    }
    cout << ans << endl;
} 




Measured memory_bytes: 8804
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

vector<string> dp(10001," ");
vector<pair<int,char>> a(10);



string string_max(int i,int j){
	string s = dp[i];
	string t = dp[i + a[j].fs];
	char c = a[j].sc;
	if(s == "0"){
		s = c;
	}	
	else{
		auto index = lower_bound(RALL(s),c);
		s.insert(index.base(),c);
	}
	string ans;
	// cout << "s" << s << " t " << t << endl;
	// cout << (s > t) << endl;
	if (t == " "){
		ans =  s;
	}
	else{
		if(s.size() > t.size()){
			ans = s;
		}
		else if(s > t){
			ans =  s;
		}
		else{
			ans =  t;
		}
	}
	return ans; 
}


int main(){
	int n,m;cin>>n>>m;
	a.resize(m);
	int match[9] = {2,5,5,4,5,6,3,7,6};
	for(int i = 0; i < m; i++) {
		char x;cin>>x;
		a[i] = mp(match[x - '0' - 1],x);
	}
	sort(ALL(a));
	// for(int i = 0; i < m; i++) {
	// 	cout << a[i].fs << endl;
	// }


	dp[0] = "0";
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			if(dp[i] != " " && i + a[j].fs <= n){
				dp[i + a[j].fs] = string_max(i,j);
				// cout << "i " << i << " j " << j << endl;

			}
			// for(int i = 0; i <= n; i++) {
			// 	cout << dp[i] << " ";
			// }
			// cout << endl;
		}
	}
	// for(int i = 0; i <= n; i++) {
	// 	cout << dp[n] << endl;
	// }
	cout << dp[n] << endl;
	return 0;
}

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

const ll MOD=1000000007;

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b){
  ll p=1;
  for(int i=0;i<b;i++){
    p*=a;
  }
  return p;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p){
  ll n=solveLinear(a,p,1);
  n=n%p;
  if(n<0)return n+p;
  return n;
}

int main(){
  int i,j,cnt=0;
  int n;
  cin>>n;
  int a[n+1];
  for(i=1;i<=n;i++)cin>>a[i];
  ll sum=0;
  for(i=1;i<n;i++){
    if(a[i]>0 && a[i+1]>0){
      int mi=min(a[i],a[i+1]);
      sum+=mi;
      a[i]-=mi;
      a[i+1]-=mi;
      if(a[i]%2==1){
        a[i]++;
        a[i+1]++;
        sum--;
      }
    }
  }
  for(i=1;i<=n;i++){
    sum+=a[i]/2;
  }
  cout<<sum<<endl;
}

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

int main() {
  vector<int> a(5);

  int ans = 0;
  int tem = 10;
  for (int i = 0; i < 5; i++) {
    cin >> a.at(i);
    if (a.at(i) % 10 < tem && a.at(i) % 10 != 0) {
      tem = a.at(i) % 10;
    }
    ans += (a.at(i) + 9) / 10 * 10;
  }

  cout << ans - 10 + tem;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
using ll=long long;
vector<ll> fact(200001);
void init_fact(int n){
	fact[0]=1;
	for (int i = 1; i < n+1; i++){
		fact[i]=fact[i-1]*i;
		fact[i]%=MOD;
	}
}
ll mod_pow(ll x, ll p){
	ll res=1;
	ll n=x;
	while(p>0){
		if(p&1==1)res=(res*n)%MOD;
		n=(n*n)%MOD;
		p=(p>>1);
	}
	return res;
}
ll nCr(int n, int r){
	ll res=1;
	res*=fact[n];
	res*=mod_pow(fact[r],MOD-2);
	res%=MOD;
	res*=mod_pow(fact[n-r],MOD-2);
	res%=MOD;
	return res;
}

int main() {
    int N,K;
    cin>>N>>K;
    init_fact(N+1);
    vector<ll> A(N);
    for (int i = 0; i < N; i++){
        cin>>A[i];
    }
    ll ans=0;
    sort(A.begin(),A.end());
    for (int i = N-1; i >= K-1; i--){
        ans+=(A[i]*nCr(i,K-1))%MOD;
        ans%=MOD;
    }
    for (int i = 0; i <= N-K; i++){
        ans-=(A[i]*nCr(N-i-1,K-1))%MOD;
        ans%=MOD;
    }
    ans=(ans+MOD)%MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int n;
  cin >> n;
  if (n<1200) cout << "ABC" << endl;
  else if (n<2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int height[n],dp[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>height[i];
	}
	dp[0]=0;
	dp[1]=abs(height[1]-height[0]);
	for(int i=2;i<n;i++)
	{
		dp[i]=min(dp[i-1]+abs(height[i]-height[i-1]),dp[i-2]+abs(height[i]-height[i-2]));
	}
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main() {
    long long N;string str;
    long long count=0;
    long long R=0;
    long long G=0;
    long long B=0;
    long long answer=0;
    cin>>N>>str;
   
   for(long long i=0;i<N;i++)
   {
      if(str[i]=='R')R++;
      if(str[i]=='G')G++;
      if(str[i]=='B')B++;
   }
   answer=(R*G*B);
 
   
   for(long long i= 0;i<=N-2;i++)
      for(long long j=i+1;j<=N-1;j++)
      {
        long long k=2*j-i;
        if(k<N){
        if((str[i]!=str[j])&&(str[j]!=str[k])&&(str[k]!=str[i]))
           count++;
        }
      }
 
    answer=answer-count;
    if(answer<=0)answer=0;
    cout<<answer<<endl;
 
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n;
    int N = pow(2, n);
    int k, mask = 0, b;
    cin >> k;
    rep(i, k) {
        cin >> b;
        mask |= 1 << b;
    }
    rep(i, N) {
        if((i | mask) == mask) {
            cout << i << ":";
            m = i;
            for(int j = 0; m > 0; j++) {
                if(m & 1) cout << " " << j;
                m /= 2;
            }
            cout << "\n";
        }
    }
}



Measured memory_bytes: 3312
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define PI 3.1415926535897932
#define MOD 1000000007;
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
long long LCM(long long A,long long B){
  long long g=GCD(A,B);
  return A/g*B;
}
long long num_order(long long X){
  long long ans=0;
  while(true){
    if(X==0){
      break;
    }
    else{
      X/=10;
      ans++;
    }
  }
  return ans;
}
int main() {
  
  int N;
  cin>>N;
  
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  
  int sum=-N;
  for(int i=0;i<N;i++){
    sum+=A[i];
  }
  
  cout<<sum<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
// #define DEBUGGING

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

template <typename T> 
const T& clamp(const T &t, const T &low, const T &high) { 
    if(t < low) {
        return low;
    } else if(high < t) {
        return high;
    } else {
        return t;
    }
}

template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace __init {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    ll R, G, B, N;
    cin >> R >> G >> B >> N;
    ll ans = 0;
    for(ll r = 0; r * R <= N; r++) {
        for(ll g = 0; r * R + g * G <= N; g++) {
            ll rest = N - (r * R + g * G);
            ans += !(rest % B);
        }
    }
    cout << ans << endl;
    return 0;
}


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

int n, q;
int a, b;

int p(int x) { return (x + n - 2) / n; }

int main() {
	cin >> n >> q;
	for (int i = 0; i < q; i++) {
		cin >> a >> b;
		
		if (n == 1) { cout << min(a, b) << endl; }
		
		else {
			while (a != b) {
				if (a > b) a = p(a);
				else b = p(b);
			}
			cout << a << endl;
		}
	}
	return 0;
}

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

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
 
#define ll long long
#define ld long double
#define pii pair<int,int>
 
#define files1 freopen("input.txt","r",stdin)
#define files2 freopen("output.txt","w",stdout)
#define files files1;files2
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0)
 
#define endl '\n'
#define ln(i,n) " \n"[(i) == (n) - 1]
 
void bad(string mes = "Impossible"){cout << mes;exit(0);}
template<typename ... T> void shit(T& ... x){}
template<typename ... T> void dec(T& ... x){shit(--x...);}
template<typename ... T> void inc(T& ... x){shit(++x...);}
#include <unordered_map>
// #include <unordered_mda>
 
template<typename T>
string bin(T x, int st = 2){
    string ans = "";
    while (x > 0){
        ans += char('0' + x % st);
        x /= st;
    }
    reverse(ans.begin(), ans.end());
    return ans.empty() ? "0" : ans;
}
 
template<typename T>
T input(){
    T ans = 0, m = 1;
    char c = ' ';
 
    while (!((c >= '0' && c <= '9') || c == '-')) {
        c = getchar();
    }
 
    if (c == '-')
        m = -1, c = getchar();
    while (c >= '0' && c <= '9'){
        ans = ans * 10 + (c - '0'), c = getchar();
    }
    return ans * m;
}
 
template<typename T>
void read(T& a) {
    a = input<T>();
}
 
template<typename T>
void read(T& a, T& b) {
    read(a), read(b);
}
 
template<typename T>
void read(T& a, T& b, T& c) {
    read(a, b), read(c);
}
 
template<typename T>
void read(T& a, T& b, T& c, T& d) {
    read(a, b), read(c, d);
}
 
const int inf = 1e9;
const double eps = 1e-9;
const int maxn = 1e5 + 10, base = 1e9 + 7;
const ll llinf = 1e18 + 1;
 
template<typename T>
T binpow(T n, T s)
{
    if (s <= 0)
        return 1LL;
    if (s % 2 == 0){
        T b = binpow(n, s / 2);
        return ( 1LL * b * b ) % base;
    } else {
        return (1LL* binpow(n, s - 1) * n) % base;
    }
}

int a[maxn];
int main() {
    int n;
//    files1;
    read(n);

    for (int i = 0; i < n; i++) {
        read(a[i]);
        a[i]--;
    }

    int res = 0;
    for (int i = 0; i < n; i++) {
        int j = a[i];
        if (a[j] == i)
            res++;
    }
    cout << res / 2;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int h,w,a,b;
	while(1){
	scanf("%d %d",&h,&w);
	if(h==0)
	if(w==0)
	break;
		
	for(a=0;a<h;a++){
		for(b=0;b<w;b++){
		printf("#");}
	printf("\n");
	}
	printf("\n");
}
	return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll; 
typedef pair<ll, ll> PL;

ll  n, b, c;
bool a[1000100];

int main(){
	REP(i, 1000100){
		a[i] = 1;
	}
	a[0] = 0;
	a[1] = 0;
	for (int i = 2; i <= 100000; i++){
		if (a[i]){
			for (int j = 0; i * (j + 2) < 1000000; j++){
				a[i *(j + 2)] = 0;
			}
		}
	}
	while (cin >> n){
		for (int i = n - 1; i > 0; i--){
			if (a[i] == 1){
				cout << i << " ";
				break;
			}
		}
		for (int i = n + 1; i < 100000; i++){
			if (a[i] == 1){
				cout << i << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 2136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

ll mult(ll n,ll m){//n^m%modを求める
    if(m==0) return 1;
    if(m==1){
        return n%mod;
    }else if(m%2==0){//オーバーフロー防止のためにn^(m/2)*n^(m/2)を考える
        ll t=mult(n,m/2);
        return (t*t)%mod;
    }else{//奇数の時はn^(m-1)*nを考える
        ll t=mult(n,m-1);
        return (t*n)%mod;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    if(b-a==c-b) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
/*
  AtCoder Beginner Contest 107
  B - Grid Compression
*/

#include<iostream>
#include<vector>
using namespace std;

int H, W;

int main() {
  scanf("%d%d", &H, &W);
  // true: 黒, false: 白
  vector<vector<bool>> a(H, vector<bool>(W, false));
  // true: 黒を含む, false: 全部白
  vector<bool> col(W, false), row(H, false);

  for (int h = 0; h < H; ++h) {
    string buf;
    cin >> buf;
    for (int w = 0; w < W; ++w) {
      if (buf[w] == '#') {
        a[h][w] = true;
        col[w] = true;
        row[h] = true;
      }
    }
  }

  for (int h = 0; h < H; ++h) {
    if (!row[h]) continue;
    for (int w = 0; w < W; ++w) {
      if (!col[w]) continue;
      if (a[h][w]) printf("#");
      else printf(".");
    }
    printf("\n");
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
 
const int N=1e6+5,MAX=3e7,MOD=1e9+7;
 
using namespace std;
 
int n,a[N],k;
int dp[N];
int main(){
   //#ifndef ONLINE_JUDGE
     //   freopen("test.txt","r",stdin);
    //#endif
   
     scanf("%d %d",&n,&k);
 
 
     for(int i=0;i<N;i++)dp[i]=1e9;
 
     for(int i=0;i<n;i++)scanf("%d",&a[i]);
     dp[0]=0;
     for(int i=0;i<n-1;i++){
           
         for(int j=1;j<=k;j++){
             if(i+j > n)break;
           	 dp[i+j]=min(dp[i+j],dp[i]+abs(a[i+j]-a[i]));
         }
     	 
     }
 
     printf("%d\n",dp[n-1] );
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto &it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vl vector<long>
#define P pair<int,int>
using namespace std;

main()
{
        int n; cin>>n;
        int ans;
        int i=0;
        while(pow(2,i)<100)
        {
                if(n>=pow(2,i))ans=pow(2,i);
                i++;
        }
        cout<<ans<<endl;
}

Measured memory_bytes: 256
#N: モンスターの数, K: 必殺技を使える回数
N, K = map(int,input().split())
#i番目のモンスターの体力
H_list = list(map(int, input().split()))

#攻撃回数の最小値を求める
#1. モンスターの体力の合計を求める。
#２．多い順にK個の体力の合計値を求める。
#３．体力の全合計からK番目までの合計の差を求める。

H_sum = sum(H_list) 

Hk_sum = 0
H_list = sorted(H_list, reverse=True)
rep = K if K< N else N
for i in range(rep):
    Hk_sum += H_list[i]
    
Attack_num = H_sum - Hk_sum

print(Attack_num)

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

int main() {
  int n,a=0;
  cin >> n;
  vector<int> p(n);
  vector<int> q(n);
  for(int i=0;i<n;i++) {
    cin >> p.at(i);
    q.at(i)=p.at(i);
  };
  sort(q.begin(),q.end());
  for(int i=0;i<n;i++) {
    if(q.at(i)!=p.at(i)) a++;
  };
  if(a<3) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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 mint {
  ll x;
  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;
  }
  /* 変数名.pow(n) */
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // 以降は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;
  }
};

int main() {
  int N;
  cin >> N;
  vector<string> S(2);
  rep(i, 2) cin >> S[i];

  mint ans = 1;

  rep(j, N) {
    if (S[0][j] == S[1][j]) {
      if (j == 0)
        ans *= 3;
      else {
        if (S[0][j - 1] == S[1][j - 1]) {
          ans *= 2;
        }
      }
    } else {
      if (j == 0)
        ans *= 6;
      else {
        if (S[0][j - 1] == S[1][j - 1])
          ans *= 2;
        else
          ans *= 3;
      }
      j++;
    }
  }

  cout << ans.x << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

int main(){
    int b;
    while(1){
        cin>>b;
        if(b==0)break;
        int ans1,ans2;
        for(int h=1;h*(h+1)/2<=b;h++){
            if(((2*b-h*(h-1))%(2*h)==0) && (2*b>h*(h-1))){
                ans1=(2*b-h*(h-1))/(2*h);
                ans2=h;
            }
        }
        cout << ans1 << " " << ans2 << endl;
    }
}


Measured memory_bytes: 3096
// BEGINNING WITH NAME OF ALMIGHTY GOD ALLAH
// AUTHOR:: MOHAMMAD FAISAL
// ATCODER BEGINNERS PROBLEMS 
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.flush();
	string s;
    cin >> s;
    if(s[0]=='9' || s[1]=='9')
      cout<<"Yes";
  	else
      cout<<"No";
	return 0;
	// Bye Bye 2019
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin>>n;
  vector<int> retu(n);
  for(int i=0;i<n;i++){
    cin>>retu.at(i);
  }
  int count=0;
  
  for(int i=1;i<n-1;i++){
  
    vector<int> vec;
    vec={retu.at(i-1),retu.at(i),retu.at(i+1)};
    sort(vec.begin(),vec.end());
    if(retu.at(i)==vec.at(1)){
      count++;
    }
  }
   cout<<count<<endl;
  
}//main

Measured memory_bytes: 256