akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int min(int a, int b){
  if(a<b)return a;
  else return b;
}
int main(){
  int n,count,i;
  int c5,c2;
  while(1){
    count=0;
    c5=0;c2=0;
    scanf("%d",&n);
    if(n==0)break;
    while(n>0){
      i=n;
       if(n%5==0){
	while(i%5==0){
	  i/=5;c5++;
	}
      }
       if(n%2==0){
	while(i%2==0){
	  i/=2;c2++;
	}
      }
      n--;
    }
    count=min(c5,c2);
    printf("%d\n",count);
  }
  return 0;
}

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

int main() {
    vector<char> c1(3), c2(3);
    string s1, s2; cin >> s1 >> s2;
    for(int i = 0; i < s1.length(); i++) c1[i] = s1[i];
    for(int i = 0; i < s2.length(); i++) c2[i] = s2[i];
    reverse(c2.begin(), c2.end());
    for(int i = 0; i <s1.length(); i++) {
        if(c1[i] != c2[i]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}



Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    ll x;
    cin >> x;

    cout << (x/500)*1000 + (x%500/5)*5 << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
A.insert(0, 0)

ans = []
for i in reversed(range(1, N + 1)):
    if sum(A[i::i]) % 2 != A[i]:
        A[i] ^= 1
    if A[i] == 1:
        ans.append(i)

print(len(ans))
print(*ans)


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

#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define endl "\n"
#define ll long long int

void solve(ll caseNo)
{
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i].first >> v[i].second;
    }
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if (v[i].first == v[i].second)
        {
            cnt++;
        }
        else
        {
            cnt = 0;
        }
        if (cnt == 3)
        {
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
    return;
}

int main()
{
    IOS;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ll cases;
    cases = 1;
    for (ll i = 1; i <= cases; i++)
    {
        solve(i);
    }
    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>

int main(){
  int i;
  int n, t;
  int a,b,c,r;
  while(scanf("%d %d %d", &a,&b,&c), a+b+c!=0){
    scanf("%d", &n);
    if(a>c)t=c, c=a, a=t;
    if(b>c)t=c, c=b, b=t;
    for(i=0; i<n; i++){
      scanf("%d", &r);
      if((r*2)*(r*2)>a*a+b*b) puts("OK");
      else puts("NA");
    }
  }

  return 0;
}

Measured memory_bytes: 584
/*************************************************************************
    > File Name: e.cpp
    > Author: Amano Sei
    > Mail: amano_sei@outlook.com 
    > Created Time: 2020年01月03日 星期四 12时21分07秒
 ************************************************************************/

#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

const int maxn = 100005;

int a[maxn];
long long s[maxn];

int main(){
    int n;
    long long m;
    scanf("%d%lld", &n, &m);
    for(int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    sort(&a[1], &a[n+1]);
    for(int i = 1; i <= n; i++)
        s[i] = s[i-1]+a[i];
    for(int i = 0; i <= n; i++)
        s[i] = s[n]-s[i];

    register int cl = 2*a[1], cr = 2*a[n];
    register long long ans, cnt;
    while(cl <= cr){
        ans = cnt = 0;
        register int cm = (cl+cr)>>1;
        for(int i = 1; i <= n; i++){
            register int tl = 1, tr = n, cnum = cm-a[i];
            while(tl <= tr){
                register int tm = (tl+tr)>>1;
                if(a[tm] < cnum)
                    tl = tm+1;
                else if(a[tm] > cnum)
                    tr = tm-1;
                else{
                    tr = tm;
                    if(tl == tr)
                        break;
                }
            }
            tl--;
            tr = n-tl;
            cnt += tr;
            ans += (long long)tr*a[i]+s[tl];
        }
        if(cnt > m)
            cl = cm+1;
        else if(cnt < m)
            cr = cm-1;
        else
            break;
    }
    if(cnt != m)
        ans += cr*(m-cnt);
    printf("%lld\n", ans);
}



Measured memory_bytes: 1280
def inpl():
    return list(map(int, input().split()))


N = int(input())
A = inpl()
sumA = sum(A)

ans = 10**16
sunuke = 0
for a in A[:-1]:
    sunuke += a
    araiguma = sumA - sunuke
    if ans > abs(sunuke - araiguma):
        ans = abs(sunuke - araiguma)

print(ans)


Measured memory_bytes: 24824
import java.awt.geom.Point2D;
import java.util.*;

public class Main {
	String str;
	int pos;
	char [] data;
	int ind;
	int ansindex;
	boolean flg;
	
	private String exp(){
		if(flg) return "";
		StringBuilder res = new StringBuilder(term());
		if(flg) return "";
		char word = str.charAt(pos);
		while(!(word == ')' || word == '#' || word == '(')){
			res.append(term());
			if(flg) break;
			word = str.charAt(pos);
		}
		if(flg) return "";
		return res.toString();
	}
	
	private String term(){
		if(flg) return "";
		String res = fact();
		if(flg) return "";
		char input = res.charAt(0);
		if(Character.isDigit(input)){
			int times = Integer.parseInt(res);
			String word = fact();
			if(flg) return "";
			StringBuilder res2 = new StringBuilder(word);
			for(int i=1; i < times; i++){
				res2.append(word);
				for(int j=0; j < word.length();j++){
					data[ind++] = word.charAt(j);
					if(ind == ansindex + 1){
						flg = true;
						break;
					}
				}
				if(flg) break;
			}
			return res2.toString();
		}
		else{
			return res;
		}
	}
	
	private String fact(){
		if(flg) return "";
		if(Character.isDigit(str.charAt(pos))){
			StringBuilder t = new StringBuilder(""+str.charAt(pos++)) ;
			while(Character.isDigit(str.charAt(pos))){
				t.append("" +(str.charAt(pos++)));
			}
			return t.toString();
		}
		else if(str.charAt(pos) == '('){
			pos++;
			String res = exp();
			if(flg) return "";
			pos++;
			return res;
		}
		else{
			String res = "" + str.charAt(pos++);
			data[ind++] = res.charAt(0);
			if(ind == ansindex + 1) flg = true;
			return res;
		}
	}
	
	private void doit(){
		Scanner sc = new Scanner (System.in);
		final int MAX = 1000000 + 1;
		
		while(true){
			str = sc.next();
			ansindex = sc.nextInt();
			if(str.equals("0") && ansindex == 0) break;
//			for(int i=0; i < MAX; i++){
//				data[i] = '\u0000';
//			}
			data = new char[ansindex + 1];
			str += "#";
			pos = 0;
			ind = 0;
			flg = false;
			String result = exp();
			//debug
//			for(int i=0; i < data.length;i++){
//				System.out.print(data[i]);
//			}
//			System.out.println();
			if(data[ansindex] == '\u0000'){
				System.out.println(0);
				continue;
			}
			//System.out.print("ANS=");
			System.out.println(data[ansindex]);
		}
	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

Measured memory_bytes: 23000
a,b = list(map(int, input().split()))

if a > b:
    ans = ''
    for target_list in range(a):
        ans = ans + str(b)

    print(ans)

if b > a:
    ans = ''
    for target_list in range(b):
        ans = ans + str(a)

    print(ans)
    

if b == a:
    ans = ''
    for target_list in range(b):
        ans = ans + str(a)

    print(ans)


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

n= int(input())

sum = 0

while (n > 0):
    n_len = len(str(n))
    cnt = n - 10 ** (n_len - 1) + 1

    if n_len % 2 == 1:
        sum += cnt

    n -= cnt

print(sum)



Measured memory_bytes: 2940
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <string>

using namespace std;

#define sqr(x) x * x
#define all(x) x.begin(), x.end()
const int INF = 1e9;
const int MOD = 1e9 + 7;
typedef long long ll;

void solve() {
	int n;
	cin >> n;
	vector<int> h(n);
	for (int& e : h) cin >> e;
	vector<int> d(n);
	d[0] = 0;
	d[1] = abs(h[1] - h[0]);
	for (int i = 2; i < n; ++i)
		d[i] = min(d[i - 1] + abs(h[i] - h[i - 1]), d[i - 2] + abs(h[i] - h[i - 2]));
	cout << d.back();
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

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

UL N;
UL P;
char X[200001];
UL M[200001];
UL D[200001];
UL ans[200000]={};
UL B;

UL popcount(UL x){
 x=(x&0x55555555)+((x>>1)&0x55555555);
 x=(x&0x33333333)+((x>>2)&0x33333333);
 x=(x&0x0f0f0f0f)+((x>>4)&0x0f0f0f0f);
 x=(x&0x00ff00ff)+((x>>8)&0x00ff00ff);
 x=(x&0x0000ffff)+((x>>16)&0x0000ffff);
 return x;
}

void Calc(UL m){
 M[0]=1;
 for(UL i=1; i<=N; i++) M[i]=M[i-1]*2%m;
 D[0]=0;
 for(UL i=1; i<=N; i++){
  D[i]=D[i%popcount(i)]+1;
 }
 B=0;
 for(UL i=N-1; i!=~0u; i--){
  B=B*2+(X[i]-'0');
  B%=m;
 }
}

int main() {
 scanf("%u",&N);
 scanf("%s",X);
 reverse(X,X+N);
 P=0;
 rep(i,N) if(X[i]=='1') P++;
 
 Calc(P+1);
 rep(i,N){
  if(X[i]=='0'){
   UL b=(B+M[i])%(P+1);
   ans[N-1-i]=D[b]+1;
  }
 }
 if(P!=1){
  Calc(P-1);
  rep(i,N){
   if(X[i]=='1'){
    UL b=(B+(P-1)-M[i])%(P-1);
    ans[N-1-i]=D[b]+1;
   }
  }
 }

 rep(i,N) printf("%u\n",ans[i]);

 return 0;
}



Measured memory_bytes: 6256
use std::io;
use std::str::FromStr;
use std::collections::HashMap;
use std::cmp::min;

type Pair = (u64, u64);

fn input_tuple() -> (usize, usize) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<usize> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn calc(c: u64, map: &HashMap<u64, u64>, diff: &Vec<Vec<u64>>) -> u64 {
    let mut sum = 0;
    for (k, v) in map {
        if *k - 1 == c {
            continue;
        }
        sum += diff[*k as usize - 1][c as usize] * v;
    }
    sum
}

fn main() {
    let (n, c) = input_tuple();
    let mut diff: Vec<Vec<u64>> = Vec::new();
    let mut colors: Vec<Vec<u64>> = Vec::new();
    let mut elements: Vec<HashMap<u64, u64>> = vec![HashMap::new(); 3];

    for _ in 0..c {
        let d = input_vec();
        diff.push(d);
    }
    for _ in 0..n {
        let c = input_vec();
        colors.push(c);
    }
    for i in 0..n {
        for j in 0..n {
            let n = elements[(i+j) as usize % 3].entry(colors[i][j]).or_insert(0);
            *n += 1;
        }
    }
    let mut ans = std::u64::MAX;
    for i in 0..c {
        for j in 0..c {
            for k in 0..c {
                if i == j || j == k || k == i {
                    continue;
                }
                let tmp = calc(i as u64, &elements[0], &diff)
                    + calc(j as u64, &elements[1], &diff)
                    + calc(k as u64, &elements[2], &diff);
                ans = min(ans, tmp);
                // println!("({}, {}, {}) -> {}", i, j, k, tmp);
            }
        }
    }
    // println!("{:?}", elements);
    println!("{}", ans);
}


Measured memory_bytes: 6396
import java.util.*;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		String b=sc.next();
		
		if(b.equals("A")){
			System.out.println("T");
		}
		if(b.equals("T")){
			System.out.println("A");
		}
		if(b.equals("G")){
			System.out.println("C");
		}
		if(b.equals("C")){
			System.out.println("G");
		}
	}
}

Measured memory_bytes: 20948
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;

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;

void solve(){
	ll k,a,b;
    cin>>k>>a>>b;
    if((b-a)/2>1){
        ll ans=1;
        ans+=a-1;
        k-=(a-1);
        if(k%2){
            ans++;
            k--;
        }
        ans+=k*(b-a)/2;
        cout<<ans<<"\n";
    }
    else cout<<k+1<<"\n";
    return;
}

signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int A, B, C, D;
    2< A < 100;
    2< B < 100;
        scanf("%d", &A);
        scanf("%d", &B);
    C = A - 1;
    D = B - 1;
        printf("%d", C * D);
return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<math.h>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;
typedef long long ll;
 
vector<int> to[200005];
vector<int> ans;

void dfs(int v, int p = -1){
    for(int u : to[v]){
        if(u == p) continue;
        ans[u] += ans[v];
        dfs(u, v);
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    int a, b;
    rep(i,n-1) {
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    int p, x;
    ans.resize(n);
    rep(i, q){
        cin >> p >> x;
        p--;
        ans[p] += x;
    }
    dfs(0);
    rep(i, n){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 23424
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rrep(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
using ll=long long;
const int MX = 2200000;
const ll LINF = 1000000000000000000ll;
//const long long MOD = 1000000007;
//long long INF = 90000000001000;


int main(){

int n;cin >> n;
vector<ll> a(n),b(n),c(n);
for (int i = 0; i < n; ++i)
{
    cin >> a[i];
}
for (int i = 0; i < n; ++i)
{
    cin >> b[i];
}for (int i = 0; i < n; ++i)
{
   cin >> c[i];
}

sort(a.begin(),a.end());
sort(c.begin(),c.end());
ll sum = 0;
for (int i = 0; i < n; ++i)
{   ll na,nc;
    na = lower_bound(a.begin(),a.end(),b[i])-a.begin();
    
    nc = upper_bound(c.begin(),c.end(),b[i])-c.begin();
    nc = n-nc;
    sum += na*nc;
    //cout << b[i] << na << nc << endl;
}

cout << sum << endl;
return 0;

}

Measured memory_bytes: 2688
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const int INF = 1000000007;
int N, M;
unordered_map<int, int> Mp;
priority_queue<int, vector<int>, greater<int> >  que;

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

  cin >> N >> M;
  int a;
  rep(i, N){
    cin >> a;
    Mp[a]++;
  }
  if (M>=Mp.size()){
    cout << 0 << "\n";
    return 0;
  }
  for (auto it=Mp.begin(); it !=Mp.end(); ++it){
    int cnt = it->second;
    que.push(cnt);
  }
  int ans=0;
  rep(i, Mp.size()-M){
    ans+=que.top();
    que.pop();
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 10312
#pragma region cp-helper
#include <bits/stdc++.h>
using namespace std;
#define AC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(a, b)
#define umap unordered_map
#define uset unordered_set
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define qmod %mod
#define pls signed
#define give main()
const int mod = 1000000007;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

#pragma endregion

const int N = 4005;

int n, arr[3][N], ans;
string s;

pls give {
    AC;
    cin >> n >> s;
    for (int i=0; i<n; i++) {
        if (s[i] == 'R') arr[0][i]++;
        else if (s[i] == 'G') arr[1][i]++;
        else arr[2][i]++;
        for (int j=0; j<3; j++) {
            if (i) arr[j][i] += arr[j][i-1];
        }
    }
    for (int i=0; i<n-2; i++) {
        for (int j=i+1; j<n-1; j++) {
            if (s[i] == s[j]) continue;
            char target = 'R'+'G'+'B'-s[i]-s[j];
            int tint;
            if (target == 'R') tint = 0;
            else if (target == 'G') tint = 1;
            else tint = 2;
            ans += arr[tint][n-1] - arr[tint][j];
            if (j+(j-i) < n and s[j+(j-i)] == target) ans--;
        }
    }
    cout << ans << nl;
}

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

int main(){
  int N , M ; 
  cin >> N >> M ; 
  int K ; 
  vector<int> C(M) ; 
  
  for(int i = 0 ; i < M ; i++){
    C.at(i) = 0 ; 
  }
  
  for(int i = 0 ; i < N ; i++){
    cin >> K ; 
    vector<int> A(K) ; 
    
    for(int j = 0 ; j < K ; j++ ){
      cin >> A.at(j) ; 
      C.at(A.at(j)-1)++;
    }
  }
  int cnt = 0 ; 
  for(int i = 0  ; i < M ; i++ ){
    if(C.at(i) == N){
      cnt++ ; 
    }
  }
  cout << cnt << endl ; 
  
}

Measured memory_bytes: 3624
#include <cstdio>
#define MAX 100

int main(){
	int n, array[MAX];
	scanf("%d", &n);
	
	for(int i = 0; i < n; i++)
		scanf("%d", &array[i]);
		
	bool flag = true;
	int temp, count = 0;
	while(flag){
		flag = false;
		for(int i = n - 1; i > 0; i--)
		if(array[i] < array[i - 1]){
			temp = array[i];
			array[i] = array[i - 1];
			array[i - 1] = temp;
			flag = true;
			count++;
		}
	}
	
	for(int i = 0; i < n; i++)
		if(i != n - 1)
			printf("%d ", array[i]);
		else
			printf("%d\n", array[i]);
			
			printf("%d\n", count);
			
	return 0;
}

Measured memory_bytes: 1028
N = int(input())
T_current, A_current = 1,1

for i in range(N):
    T, A = map(int, input().split())
    m = max(((T_current - 1) // T) + 1, ((A_current - 1) // A) + 1)
    T_current = T * m
    A_current = A * m
print(int(A_current + T_current))


Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

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

#define f first
#define s second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

const int md = 1e9+7;
const ll inf = 1e18;
const int maxn = 2e5+5;

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

int main()
{
	int n; cin >> n;
	vi vec;
	for(int i = 0; i< n; i++)
	{
		int x; cin >> x;
		vec.pb(x);
	}
	sort(all(vec));

	n = vec.size();

	int ans = 0;
	for(int i = 0; i< n; i++)
	{
		for(int j = i+1; j< n; j++)
		{
			for(int k = j+1; k< n; k++)
			{
				if(vec[i] == vec[j] || vec[i] == vec[k] || vec[j] == vec[k]) continue;
				if(vec[i]+vec[j]> vec[k]) ans++;
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <math.h>
#include <stdlib.h>
#include <numeric>
 
 
int main(){
	int a, p;
	std::cin >> a >> p;
	std::cout << (a * 3 + p) / 2 << std::endl;
	return 0;
}


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

using namespace std;

int main(void) {
    long r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    constexpr long MOD = 1e9 + 7;
    vector<long> fact(3e6), ifact(3e6);
    fact[0] = 1;
    for(long i=1; i<3e6; i++)
        fact[i] = (fact[i-1] * i) % MOD;
    {
        long n = 3e6-1;
        long a = fact[n], b = MOD-2, r = 1;
        while(b) {
            if(b&1) r *= a, r %= MOD;
            a *= a, a %= MOD;
            b >>= 1;
        }
        ifact[n] = r;
    }
    for(long i=3e6-2; i>=0; i--)
        ifact[i] = (ifact[i+1] * (i+1)) % MOD;

    auto f = [&](long n, long a, long b) {
        // aCn + ... + bCn
        // nCn + ... bCn == b+1Cn+1
        // b+1Cn+1 - aCn+1
        long r = 1;
        r *= fact[b+1], r %= MOD;
        r *= ifact[n+1], r %= MOD;
        r *= ifact[b-n], r %= MOD;

        long s = 1;
        s *= fact[a], s %= MOD;
        s *= ifact[n+1], s %= MOD;
        s *= ifact[a-n-1], s %= MOD;
        return (MOD + r - s) % MOD;
    };

    long res = 0;
    for(long c=c1; c<=c2; c++)
        res += f(c, r1+c, r2+c), res %= MOD;
    cout << res << endl;
}


Measured memory_bytes: 47104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  int n, m;
  cin >> n >> m;
  vector<int> k(m), p(m);
  vector<vector<int>> s(m);
  rep(i, m) {
    cin >> k[i];
    rep(j, k[i]) {
      int S;
      cin >> S;
      S--;
      s[i].push_back(S);
    }
  }
  rep(i, m) {
    cin >> p[i];
  }

  int ans = 0;
  rep(bit, 1<<n) {
    bool flag = 1;
    rep(i, m) {
      int cnt = 0;
      rep(j, k[i]) {
        if (bit & 1 << s[i][j]) {
          cnt++;
        }
      }
      if (cnt%2 != p[i]) {
        flag = 0;
        break;
      }
    }
    if (flag) ans++;
  }

  cout << ans << endl;
}


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

int main() {
	int N;cin>>N;
	string s;cin>>s;
	bool flag;

	vector<int>white(N+1),black(N+1);

	for (int i = 0; i < N; i++)
	{
		if(s[i] == '#')black[i+1] = 1;
		if(s[i] == '.')white[i] = 1;		
	}
	for (int i = 0; i < N; i++)
	{		
		black[i + 1] += black[i];
	}
	for (int i = N; i > 0; i--)
	{
		white[i - 1] += white[i];
	}

	int ans = 1e9;
	for (int i = 0; i <= N; i++)
	{
		cerr<<black[i]<<" "<<white[i]<<endl;
		ans = min(ans, black[i]+white[i]);
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 2692
while True:
  n, x = map(int,input().split())
  c = 0
  if n == x == 0:
    break
  for r in range(1, n-1):
    for s in range(r+1, n):
      for t in range(s+1, n+1):
        if r+s+t == x:
          c += 1
  print(c)


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

using namespace std;

const int N = 1e5 + 10;

int n, p[N], t[N];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  for (int i = 1; i <= n; i++) t[p[i]] = i;
  for (int i = 1; i <= n; i++) cout << 30000 * i << " ";
  cout << endl;
  for (int i = 1; i <= n; i++) cout << 30000 * (n - i) + t[i] << " ";
  cout << endl;
  return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

int dy[5] = {-1, 0, 1, 0, 0};
int dx[5] = {0, -1, 0, 1, 0};

int main(void) {
    int n;
    int count =0;

    cin>>n;
    vector<int> a(n+1),b(n+1),c(n);
    FOR(i,1,n){
        cin>>a[i];
    }
    FOR(i,1,n){
        cin>>b[i];
    }
    FOR(i,1,n-1){
        cin>>c[i];
    }

    FOR(i,1,n){
        count+=b[a[i]];
        if(i!=1){
            if(a[i]-a[i-1]==1){
                count+=c[a[i-1]];
            }
        }
    }
    cout<<count<<endl;

}


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

int main() {
    ll N;
    cin >> N;
    ll t = 1;
    vector<ll> factors;
    while((t*t)<=N){
        if(N%t==0){
            factors.push_back(N/t);
        }
        ++t;
    }
    ll num = factors.back();
    // cerr <<"num="<< num << endl;
    ll ans = 0;
    while(num != 0){
        num /= 10;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 FOR(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define FOR1(i,m,n) for(int i=(int)(m); i<=(int)(n); i++)
#define SORT(v) sort(v.begin(), v.end())
#define REVERSE(v)  reverse(v.begin(), v.end())
typedef long long ll;
using namespace std;

int N, M, Q, L[200001], R[200001], X[501][501], C[501][501];

int main() {
  cin>>N>>M>>Q;
  
  REP1(i,M) {
    cin>>L[i]>>R[i];
    X[L[i]][R[i]]++;
  }
  REP1(i,N) {
    REP1(j,N) {
      C[i][j] = C[i][j-1] + X[i][j];
    }
  }
  REP1(i,Q) {
    int p,q; cin>>p>>q;
    int sum = 0;
    FOR1(j,p,q) sum += C[j][q] - C[j][p-1];
    cout<<sum<<endl;
  }
  return 0;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  set<char> S;
  char s;
  for (int i = 0; i < N; ++i) {
    cin >> s;
    S.insert(s);
  }
  if ((int)S.size() == 4) {
    cout << "Four" << endl;
  } else {
    cout << "Three" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int N;
	cin >> N;
	V<ll> x(N),y(N),dx(N),dy(N);
	rep(i,N){
		cin >> x[i] >> y[i];
		char d;
		cin >> d;
		if(d == 'L') dx[i] = -1;
		if(d == 'R') dx[i] = 1;
		if(d == 'D') dy[i] = -1;
		if(d == 'U') dy[i] = 1;
	}
	rep(i,N) x[i] *= 2, y[i] *= 2;

	ll inf = 1e9;

	V<ll> ts;
	
	rep(_,4){
		ll A = -inf, B = -inf, C = -inf;
		rep(i,N){
			if(dx[i] == -1) chmax(A,x[i]);
			else if(dx[i] == 1) chmax(C,x[i]);
			else chmax(B,x[i]);
		}
		ts.pb(A-B);
		ts.pb(B-C);
		ts.pb((A-C)/2);

		rep(i,N){
			swap(x[i],y[i]);
			x[i] = -x[i];
			swap(dx[i],dy[i]);
			dx[i] = -dx[i];
		}
	}
	ts.pb(0);
	show(ts);
	ll ans = 1e18;
	for(ll t : ts) if(t >= 0){
		ll mxx = -inf, mxy = -inf, mnx = inf, mny = inf;
		rep(i,N){
			ll X = x[i]+dx[i]*t, Y = y[i]+dy[i]*t;
			chmax(mxx,X);chmin(mnx,X);
			chmax(mxy,Y);chmin(mny,Y);
		}
		chmin(ans,(mxx-mnx)*(mxy-mny));
	}
	cout << (double)ans/4 << endl;
}


Measured memory_bytes: 3456
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <utility>
#include <stack>
using namespace std;


struct directory{
	set<string> file;
	map<string,directory*> child;

	directory(directory *par = 0){
		child.insert( make_pair(".", this) );
		child.insert( make_pair("..", par) );
	}

	~directory(){
		map<string,directory*>::iterator it;
		for(it = child.begin(); it != child.end(); ++it){
			if( it->first != "." && it->first != ".." )
				delete it->second;
		}

		file.clear();
		child.clear();
	}
};


directory *root;

char name[106];


set<string>::iterator find(string path_string){
	const char *path = path_string.c_str() + 1;

	set<string>::iterator it_s;
	map<string,directory*>::iterator it_m;

	directory *cur = root;
	int d = 0;
	while(*path != '\0'){
		sscanf(path, "%[^/]%n", name, &d);
		path += d;
		bool dir = false;

		if( *path == '/' ){
			dir = true;
		}
		else{
			it_s = cur->file.find(name);
			if( it_s == cur->file.end() ){
				it_m = cur->child.find(name);
				if( it_m == cur->child.end() ){
					throw 4;
				}
				dir = true;
			}
			else{
				return it_s;
			}
		}
		
		if( dir ){
			it_m = cur->child.find(name);
			if( it_m == cur->child.end() ){
				throw 1;
			}
			
			cur = it_m->second;
			
			if( *path == '/' ){
				++path;
			}
		}
	}

	it_s = cur->file.find("index.html");
	if( it_s == cur->file.end() ) throw 5;
	return it_s;
}


int main(){
	int n, m;
	string path_string;
	string path1, path2;
	
	map<string,directory*>::iterator it_m;

	while( cin >> n >> m, n != 0 ){
		root = new directory;

		for(int i = 0; i < n; ++i){
			cin >> path_string;
			const char *path = path_string.c_str() + 1;

			directory *cur = root;
			int d = 0;
			while(true){
				sscanf(path, "%[^/]%n", name, &d);
				path += d;
				if( *path == '/' ){
					++path;

					it_m = cur->child.find(name);
					if( it_m == cur->child.end() ){
						it_m = cur->child.insert( make_pair(name, new directory(cur)) ).first;
					}
					cur = it_m->second;
				}
				else{
					cur->file.insert(name);
					break;
				}
			}
		}

		root->child.erase("..");

		for(int i = 0; i < m; ++i){
			try{
				cin >> path1 >> path2;

				set<string>::iterator p1, p2;
				p1 = find(path1);
				p2 = find(path2);

				if( p1 == p2 ){
					cout << "yes\n";
				}
				else{
					cout << "no\n";
				}
			}
			catch(int){
				cout << "not found\n";
			}
		}
		
		delete root;
	}
}

Measured memory_bytes: 1336
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MAX_V 333
#define INF 2000000001
int da[MAX_V][MAX_V];
int V; 
int ans=0;


void warshall_floyd(){
  for(int k=0;k<V;k++)
    for(int i=0;i<V;i++)
      for(int j=0;j<V;j++){
	int tmp= da[i][j];
	da[i][j]=min(da[i][j],da[i][k]+da[k][j]);
	if(tmp!=da[i][j])ans=1;
      }
}

signed main(){
  cin>>V;

  for(int k=0;k<V;k++)
    for(int i=0;i<V;i++)
      cin>>da[k][i];
  
  warshall_floyd();
  if(ans)cout<<-1<<endl;
  else {
    int sum=0;
    for(int i=0;i<V;i++)
      for(int j=0;j<V;j++){
	int f=1;
	for(int k=0;k<V;k++){
	  if(k==i||k==j)continue;
	  if(da[i][k]+da[k][j]==da[i][j])f=0;
	}
	if(f)sum+=da[i][j];
      }
    cout<<sum/2<<endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define hell 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
void solve(){
    int n;
    cin>>n;
    cout<<(n*(n-1))/2<<endl;
    return;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    int tests = 1;
    //cin>>tests;
    while(tests--){
        solve();
    }
    return 0;
}

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

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

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

#define re(i,x,y) for(ll i=x;i<y;i++)

long long INF=1e9;
const long long mod=2019;
#define ll long long



int main(){
    ll n,m;
    cin>>n>>m;
    vector<vector<ll> > G(n);
    rep(i,m){
        ll a,b;
        cin>>a>>b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    ll buf;
    rep(i,G[0].size()){
        buf=G[0][i];
        rep(j,G[buf].size()){
            if(G[buf][j]==n-1){
                cout<<"POSSIBLE"<<endl;
                return 0;
            }
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
}

Measured memory_bytes: 12776
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <fstream>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <assert.h>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL 
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
 
 
#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
 
//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)
 
struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}
 
};
typedef vector<vector<Edge>> Graph;
typedef unsigned long long ull;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll m, ll n)
{
	return m * n / gcd(m, n);
}
ll mod_pow(ll x, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = (res * x) % MODU;
		x = (x*x)%MODU;
		n >>= 1;
	}
	return res;
}
ll divmod(ll a, ll b) { // a/b(mod m)
								  // a/b (mod m)
								  // a*b^-1
								  // b^-1 * b = 1
								  // b^(m-1) = 1 
								  // b^(m-2) * b = 1
								  // b^-1 = b^(m-2)

								  // a/b = a * b^(m-2)

	return (a * mod_pow(b, MODU - 2)) % MODU;
}


ll fmemo[10000] = {};
ll factorial(ll n) {//階乗

	if (n > 0) {
    assert(n < 10000);
if(fmemo[n] != 0) return fmemo[n];
		return fmemo[n] = (n * factorial(n - 1))%MODU;
	}
	else {
		return 1;
	}
}

  ll dp[200010][3][2] = {};
int main(){
  int n;
  cin >> n;
  vector<ll> a(n + 10);

  REP(i,n)cin >> a[i];
  Fill(dp, LLONG_MIN  / 3);

  dp[0][0][0] = 0;

  rep(i,0,n){
    REP(j, 3){
      if(dp[i][j][1] != LLONG_MIN  / 3)
        dp[i + 1][j][0] = dp[i][j][1];

      if(dp[i][j][0] != LLONG_MIN  / 3)
        dp[i + 1][j][1] = dp[i][j][0] + a[i];

      if(j){
        if(dp[i][j - 1][0] != LLONG_MIN  / 3)
          dp[i + 1][j][0] = max(dp[i][j-1][0],dp[i + 1][j][0]);
      }
    }
  }

  if(n % 2){
    cout << max(dp[n][1][0],dp[n][2][1]) << endl;
  }
  else 
    cout << max(dp[n][0][0],dp[n][1][1]) << endl;
  return 0;
} 

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

int main() {
  unsigned long long X;
  cin >> X;
  X = X;
  unsigned long long money = 100;
  //unsigned long long money_1;
//  unsigned long long money_2;
  int year = 0;

  while (money < X) {
    if (money <= 180000000000000000) {
      money = money * 101 / 100;
      year++;
    } else {
      money = money / 100 * 101;
      year++;
    }
  }
  cout << year << endl;
}


Measured memory_bytes: 3624
/**
  @file b.cpp
  @title
  @url https://atcoder.jp/contests/abc157/tasks/abc157_b
**/

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef unsigned long long uLL;
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SZ(x) ((int)(x).size())

#define REPI(i, a, b) for (LL i = LL(a); i < LL(b); ++i)
#define REP(i, N) for (LL i = LL(0); i < LL(N); ++i)
#define REPS(i, N) for (int i = 1; i <= (int)(N); i++)
#define RREP(i, N) for (int i = ((int)(N)-1); i >= 0; i--)
#define RREPS(i, N) for (int i = ((int)(N)); i > 0; i--)

#define chmax(ret, x) ret = max(ret, x)
#define chmin(ret, x) ret = min(ret, x)

#define FILL(x, e) memset(x, e, sizeof(x))
#define ZEROS(x) fill(x, 0)

#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(RALL(x))

#define UNIQ(x) x.erase(unique(ALL(x)), x.end());

#define BIT(n) (1LL << (n))

#define OUT(x) cout << (x) << "\n"
#define DEBUG(x) cerr << #x << " : " << x << "\n"
#define DEBUG2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second

const int MOD = 1e9 + 7;

void iostream_init() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.setf(ios::fixed);
  cout.precision(12);
  // cout.fill('0');
  // cout.width(3);
}

int main() {
  ::iostream_init();

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

  int N;
  cin >> N;
  vector<int> b(N, 0);
  REP(i, N) {
    cin >> b[i];
  }

  bool ok = false;

  int cnt = 0;
  REP(i, 3) {
    REP(j, 3) {
      REP(k, N) {
        if (A[i][j] == b[k]) {
          cnt++;
        }
      }
    }

    if (cnt == 3) {
      ok = true;
      break;
    } else {
      cnt = 0;
    }
  }

  REP(i, 3) {
    REP(j, 3) {
      REP(k, N) {
        if (A[j][i] == b[k]) {
          cnt++;
        }
      }
    }

    if (cnt == 3) {
      ok = true;
      break;
    } else {
      cnt = 0;
    }
  }

  REP(i, 3) {
    REP(k, N) {
      if (A[i][i] == b[k]) {
        cnt++;
      }
    }
  }
  if (cnt == 3) {
    ok = true;
  } else {
    cnt = 0;
  }

  REP(i, 3) {
    REP(k, N) {
      if (A[2 - i][i] == b[k]) {
        cnt++;
      }
    }
  }
  if (cnt == 3) {
    ok = true;
  } else {
    cnt = 0;
  }

  if (ok) {
    OUT("Yes");
  } else {
    OUT("No");
  }

  return 0;
}


Measured memory_bytes: 256
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
a,b,m = iim()
A = iil()
B = iil()
ans = min(A)+min(B)

for i in range(m):
    x,y,c = iim()
    ans = min(ans,A[x-1]+B[y-1]-c)
print(ans)

Measured memory_bytes: 18740
#include <iostream>
#include <cmath>

using namespace std;
int main() {
    // input
    int sunuke_num, okashi_num;
    cin >> sunuke_num >> okashi_num;

    // お菓子も持っている時点で対応するビットを立てる
    bool okashi_owner_flag[100] = {false};
    for(int okashi_i = 0; okashi_i < okashi_num; ++okashi_i) {
        int okashi_i_owner_num;
        cin >> okashi_i_owner_num;
        for(int sunuke_i = 0; sunuke_i < okashi_i_owner_num; ++sunuke_i) {
            int sunuke_i_idx;
            cin >> sunuke_i_idx;
            okashi_owner_flag[sunuke_i_idx - 1] = true;
        }
    }

    // お菓子を持っていないすぬけ君をカウントする
    int cnt = 0;
    for(int sunuke_i = 0; sunuke_i < sunuke_num; ++sunuke_i) {
        if(okashi_owner_flag[sunuke_i] == false) cnt++;
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define digit(a) to_string(a).size()
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;
int main(void)

{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> v(n);
    vector<ll> dis(n, (ll)INF), prev(n);
    rep(i, 0, m)
    {
        int a, b;
        cin >> a >> b;
        --a, --b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    priority_queue<ll> q;
    q.push(0);
    dis[0] = 0;
    ll cta = 1;
    while (!q.empty())
    {
        int temp = q.top();
        q.pop();
        for (auto i : v[temp])
        {
            if (dis[i] > dis[temp] + 1)
                dis[i] = dis[temp] + 1, q.push(i), prev[i] = temp, ++cta;
        }
    }
    if (cta < n)
        cout << "No" << endl;
    else
    {
        cout << "Yes" << endl;
        rep(i, 1, n) printf("%lld\n", prev[i] + 1);
    }
}


Measured memory_bytes: 17332
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

int dp[100001];

vector<P>v[100001];

signed main(){

	r(i,100001)dp[i]=1e15;

	dp[0]=0;

	int n;
	cin>>n;
	int a[n],b[n];
	vector<P>A,B;
	r(i,n)cin>>a[i],A.push_back(P(a[i],i));
	r(i,n)cin>>b[i],B.push_back(P(b[i],i));

	sort(A.begin(),A.end());
	sort(B.begin(),B.end());

	r(i,n-1){
		int x=A[i].second;
		int y=A[i+1].second;
		v[x].push_back(P(y,abs(A[i].first-A[i+1].first)));
		v[y].push_back(P(x,abs(A[i].first-A[i+1].first)));
	}
	r(i,n-1){
		int x=B[i].second;
		int y=B[i+1].second;
		v[x].push_back(P(y,abs(B[i].first-B[i+1].first)));
		v[y].push_back(P(x,abs(B[i].first-B[i+1].first)));
	}

	priority_queue<P,vector<P>,greater<P> >q;
	q.push(P(0,0));

	while(!q.empty()){
		P p=q.top();q.pop();
		int now=p.se;
		int cost=p.fi;

		if(dp[now]<cost)continue;

		r(i,v[now].size()){
			int nex=v[now][i].fi;
			int ncos=v[now][i].se+cost;

			if(dp[nex]<=ncos)continue;

			dp[nex]=ncos;
			q.push(P(ncos,nex));
		}
	}
	r(i,n){
		cout<<dp[i]<<endl;
	}
}


Measured memory_bytes: 21376
// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include <bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0) 
#define inf                  (ll)1<<60
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={-2,-2,1,-1,-1,-1,1,1};
int dy[8]={1,-1,-2,-2,-1,1,-1,1};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    ll n,W;
    cin>>n>>W;
    vector<vector<ll>> dp(n,vector<ll> (100010,inf));
    vector<ll> w(n),v(n);
    f(i,n)
    {
        cin>>w[i]>>v[i];
        dp[i][v[i]]=w[i];
    }
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<=100000;j++)
        {
            dp[i][j]=min(dp[i][j],dp[i-1][j]);
            if(j-v[i]>=0&&dp[i-1][j-v[i]]>0)
            {
                 dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
            }
        }
    }
    ll max=0;
    for(int i=1;i<=100000;i++)
    {
        if(dp[n-1][i]<=W)
        {
            max=i;
        }
    }
    cout<<max<<endl;
}


Measured memory_bytes: 79488
#include<bits/stdc++.h>
using namespace std ;
typedef pair<int,int> pii ;
typedef pair<int,pii> pi3 ;

int n = 0 ;
int ans[3][120] = {0} ;

void sortSp( bool flg )
{
  vector<pi3> cmp ;
  int x = 0 ;
  int y = 0 ;
  int z = 2 ;

  if ( flg ) y = 1 ;
  else x = 1 ;

  for ( int i = 0 ; i < n ; i++ )
  {
    cmp.push_back( pi3( ans[x][i], pii( ans[y][i], ans[z][i] ) ) ) ;
  }

  if ( flg )
  {
    sort( cmp.begin(), cmp.end() ) ;
  }
  else
  {
    sort( cmp.begin(), cmp.end(), greater<pi3>() ) ;
  }

  for ( int i = 0 ; i < n ; i++ )
  {
    ans[x][i] = cmp[i].first ;
    ans[y][i] = cmp[i].second.first ;
    ans[z][i] = cmp[i].second.second ;
  }
}

void Rank()
{
  sortSp(0) ;

  for ( int i = 1 ; i <= n ; i++ )
  {
    int cmp = 0 ;
    ans[2][ i-1 ] = i ;
    for ( int j = i ; j < n ; j++ )
    {
      if ( ans[1][ i-1 ] == ans[1][j] )
      {
        ans[2][j] = i ;
        cmp++ ;
      }
      else break ;
    }
    i += cmp ;
  }

  sortSp(1) ;
}

void solve( int A, int B, int C )
{
  if ( !C )
  {
    ans[1][ A-1 ] += 1 ;
    ans[1][ B-1 ] += 1 ;
  }
  else
  {
    if ( C > 0 )
    {
      ans[1][ A-1 ] += 3 ;
    }
    else if ( C < 0 )
    {
      ans[1][ B-1 ] += 3 ;
    }
  }
}

int main()
{
  int A = 0 ;
  int B = 0 ;
  int score[2] = {0} ;
  cin >> n ;
  for ( int i = 1 ; i <= n ; i++ )
  {
    ans[0][ i-1 ] = i ;
  }
  for ( int i = 0 ; i < n*(n-1)/2 ; i++ )
  {
    cin >> A >> B >> score[0] >> score[1] ;
    solve( A, B, (score[0]-score[1]) ) ;
  }
  Rank() ;
  for ( int i = 0 ; i < n ; i++ )
  {
    printf("%d\n", ans[2][i]) ;
  }
  return 0 ;
}

Measured memory_bytes: 3240
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

vector<string> dfs(string s, ll depth, vector<char> symbol)
{
    vector<string> ret;
    if (depth == 0)
    {
        ret.push_back(s);
        return ret;
    }

    for (ll i = 0; i < symbol.size(); i++)
    {
        auto vec = dfs(s + symbol[i], depth - 1, symbol);
        for (auto &&e : vec)
        {
            ret.push_back(e);
        }
    }
    return ret;
}

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return b;
    }
    return gcd(b, a % b);
}

enum Tenki
{
    Sunny,
    Cloudy,
    Rainy
};

int main()
{
    ll A, B, C;
    cin >> A >> B >> C;
    if (B - A == C - B)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
import heapq
def main():
    n, k = map(int, input().split())
    v = list(map(int, input().split()))
    ans = 0
    for L_i in range(min(k+1, n)):#左から取る回数
        R_i_max = k - L_i+1
        if n < L_i + R_i_max:
            R_i_max = n - L_i + 1
        for R_i in range(R_i_max):#右から取る回数
            pop_i = k - L_i - R_i
            q = []
            heapq.heapify(q)
            tmp = 0
            for L_j in range(L_i):
                tmp += v[L_j]
                heapq.heappush(q, v[L_j])
            for R_j in range(n-R_i, n):
                tmp += v[R_j]
                heapq.heappush(q, v[R_j])
            for _ in range(pop_i):
                if len(q) == 0:
                    break
                x = heapq.heappop(q)
                if 0 < x:
                    break
                tmp -= x
            if ans < tmp:
                ans = tmp
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188