akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}init;

typedef long long LL;

template<typename T>void chmin(T &a,T b){a=min(a,b);}
template<typename T>void chmax(T &a,T b){a=max(a,b);}
template<typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
typedef vector<int> V;
typedef vector<V> Graph;
int main(){
    int R,C,N;
    cin>>R>>C>>N;
    V r(N),c(N),a(N);
    V used(R+C,0);
    vector<LL> val(R+C);
    Graph g(R+C);
    for(int i=0;i<N;i++){
        cin>>r[i]>>c[i]>>a[i];
        r[i]--;
        c[i]+=R-1;
        g[r[i]].push_back(i);
        g[c[i]].push_back(i);
    }
    queue<int> que;
    for(int v=0;v<R+C;v++){
        if(used[v])continue;
        used[v]=1;
        val[v]=0;
        LL min_c=1e16;
        LL min_r=1e16;
        if(v<R)min_r=0;
        else min_c=0;
        for(auto &it:g[v])que.push(it);
        while(que.size()){
            int e=que.front();que.pop();
            if(used[r[e]]&&used[c[e]]){
                if(val[r[e]]+val[c[e]]==a[e])continue;
                else{
                    cout<<"No"<<endl;
                    return 0;
                }
            }
            else{
                int now;
                if(used[r[e]]){
                    used[now=c[e]]=1;
                    val[c[e]]=a[e]-val[r[e]];
                    chmin(min_c,val[c[e]]);
                    //   cout<<"C:"<<c[e]-R<<" "<<val[c[e]]<<endl;
                }
                else{
                    used[now=r[e]]=1;
                    val[r[e]]=a[e]-val[c[e]];
                    chmin(min_r,val[r[e]]);
                    //      cout<<"R:"<<r[e]<<" "<<val[r[e]]<<endl;
                }
                for(auto &it:g[now])que.push(it);
            }
        }
        if(min_c+min_r<0){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 14720
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    if(S[0] == '9' || S[1] == '9') {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3648
import sys
import itertools
input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def main():
    N, M = read_values()
    Q = [read_list() for _ in range(M)]
    Q.sort()

    res = 0
    end = 10 ** 6
    for q in Q:
        if q[0] >= end:
            res += 1
            end = q[1]
        else:
            end = min(end, q[1])
    
    res += 1
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 29724
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 100000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;
int main(){
    LL n,m;
    scanf("%lld%lld",&n,&m);

    LL res=0;
    if(n*2<=m){
        res+=n;
        m-=n*2;
        if(m>=4)
            res+=m/4;
    }
    else{
        res+=m/2;
    }
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void debug() { std::cerr << '\n'; }
template <class H, class... T> void debug(H &&head, T &&... args) {
    std::cerr << head;
    sizeof...(args) == 0 ? std::cerr << "" : std::cerr << ' ';
    debug(std::forward<T>(args)...);
}
template <class T> void debug(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cerr << v[i];
        i == v.size() - 1 ? std::cerr << '\n' : std::cerr << ' ';
    }
}
template <class T> void debug(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cerr << v[i][j];
            j == v[i].size() - 1 ? std::cerr << '\n' : std::cerr << ' ';
        }
    }
}

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

    ll N;
    cin >> N;
    // vector<int> a(N);
    // REP(i, N) { a[i] = i + 1; }

    ll ans = N * (N - 1) / 2;

    print(ans);

    return 0;
}

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

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main() {
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();
    set<string> st;
    string ans;
    rep(i, n) {
        REP(j, i + 1, n + 1) {
            string t = s.substr(i, j - i);
            if (ans == "") {
                st.insert(t);
                if (st.size() == k) {
                    auto it = st.end();
                    --it;
                    ans = *it;
                }
            }
            else {
                if(ans <= t) break;
                if(st.count(t)) continue;
                st.erase(ans);
                st.insert(t);
                auto it = st.end();
                --it;
                ans = *it;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#coding:UTF-8
# 4$ cake
# 7$ donuts
n = int(input())
count = 0
for i in range(25+1):
  for j in range(17+1):
    if 4*i+7*j == n:
      count = count+1
if count > 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
n, q = list(map(int, input().split(' ')))
stacks = [[] for i in range(n)]

for i in range(q):
    op = list(map(int, input().split(' ')))
    if op[0] == 0:
        stacks[op[1]].append(op[2])
    elif op[0] == 1:
        print(' '.join(list(map(str, stacks[op[1]]))))
    elif op[0] == 2:
        stacks[op[1]] = []


Measured memory_bytes: 60544
#include<bits/stdc++.h>
#define int long long

using namespace std;



signed main() {
  int n; cin >> n;
  int sm = 0;
  vector<int> vec;
  for(int i = 0; i < n;i++) {
    int x; cin >> x;
    sm += x;
    vec.push_back(x);
  }

  int ans = 10000000;

  for(int p = 1; p <= 100;p++) {
    int a = 0;
    for(int i = 0; i < n;i++) {
      a += (p-vec[i]) * (p-vec[i]);
    }
    ans = min(a, ans);
  }
  cout << ans << endl;

}


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

int main() {

  int n;
  char c;
  string input;
  int ans[4] = {0};

  while( cin >> n >> c >> input ) {

    if ( input == "A" ) {
      ans[0]++;
    }else if ( input == "B" ) {
      ans[1]++;
    }else if ( input == "O" ) {
      ans[3]++;
    }else {
      ans[2]++;
    }

  }

  cout << ans[0] << endl << ans[1] << endl << ans[2] << endl << ans[3] << endl;

  return 0;

}

Measured memory_bytes: 1204
def doc_string():
	"""
	I can fly.
	"""

for i in xrange(int(raw_input())):
	x = str(int(raw_input()) ** 2)
	x = "0" * (8 - len(x)) + x
	
	print "Case " + str(i + 1) + ":"
	for _ in xrange(10):
		print int(x[2:6])
		x = str(int(x[2:6]) ** 2)
		x = "0" * (8 - len(x)) + x

Measured memory_bytes: 6432
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef int64_t  ll;
typedef uint64_t ull;

#define rep(i,n)   for (int i = 0; i < (n); i++)
#define rrep(i,n)  for (int i = (n)-1; i >= 0; i--)
#define rep1(i,n)  for (int i = 1; i <= (n); i++)
#define rrep1(i,n) for (int i = (n); i > 0; i--)

ll n;
vector<pair<ll,ll>> v[100001];
vector<ll> d(100001, -1);
int main(void) {
    cin >> n;
    rep(i,n-1) {
        ll a,b,c;
        cin >> a >> b >> c;
        v[a].push_back(make_pair(b,c));
        v[b].push_back(make_pair(a,c));
    }
    vector<ll> q;
    d[1] = 0;
    q.push_back(1);
    while (q.size() != 0) {
        ll idx = q.back();
        q.pop_back();
        while (v[idx].size() != 0) {
            auto p = v[idx].back();
            v[idx].pop_back();
            if (d[p.first] != -1) continue;
            if (p.second%2 == 0) d[p.first] = d[idx];
            else d[p.first] = (d[idx] == 0 ? 1 : 0);
            q.push_back(p.first);
        }
    }
    rep1(i,n) {
        cout << d[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 8704
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> n;
    cin >> S;
    rep(i, n) {
        if(S[i] == 'R')
            a++;
        if(S[i] == 'G')
            b++;
        if(S[i] == 'B')
            c++;
    }
    ans = a * b * c;
    rep(i, n) {
        rep(h, min(i, n - 1 - i)) {
            ll j = h + 1;
            if(S[i] != S[i - j] && S[i] != S[i + j] && S[i - j] != S[i + j]) {
                ans--;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var K = int.Parse(Console.ReadLine());
            var X = int.Parse(Console.ReadLine());
            var Y = int.Parse(Console.ReadLine());
            var ans = N <= K ? X*N : X*K + Y*(N - K);
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 2648
M,D=list(map(int,input().split()))

cal=[[m+1,d+1] for m in range(M) for d in range(D)]

ans=0
for i in cal:
  day=[(i[1]-i[1]%10)/10,i[1]%10]
  if day[0]>1 and day[1]>1:
    if day[0]*day[1]==i[0]:
      ans+=1

print(ans)

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

#define ll long long
#define ar array
#define up(i,a,b) for(int i=a; i<b; i++)
#define down(i,a,b) for(int i=a; i>b; i--)
#define pb push_back
#define mp make_pair

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    cout << (n>=30?"Yes":"No") << endl;
}


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

#define mp make_pair
typedef long long ll;
typedef pair<int,int>pii;
const ll mod = 1e9+7;
const int N = 1e5;
ll two[N+100],three[N+100];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	two[0] = 1,three[0] = 1;
	for(int i=1;i<=N;i++){
		two[i] = (two[i-1]*2)%mod;
		three[i] = (three[i-1]*3)%mod;
	}
	string s;
	cin >> s;
	ll ans = 0;
	int sz = s.size(),cnt = 0;
	for(int i=0;i<sz;i++){
		if(s[i]=='1'){
			ans = (ans+((two[cnt]*three[sz-1-i])%mod))%mod;
			cnt++;
		}
	}
	ans = (ans+two[cnt])%mod;
	cout << ans << "\n";
}


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

int main() {
  int N;
  int s = 0;
  cin >> N;
  
	for (int i = 0; i < N; i++) {
      int l, r;      
      cin >> l >> r;
      
     s += r-l+1;
 
    }
  
  cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll a,b,c,k,a1,b1,c1;

int main(){
  std::cin >> a >> b >> c >> k;
  if(k&1){
    ll res = b-a;
    if(res>1e18){
      std::cout << "Unfair" << '\n';
    }
    else std::cout << res << '\n';
  }
  else{
    ll res = a-b;
    if(res>1e18){
      std::cout << "Unfair" << '\n';
    }
    else std::cout << res << '\n';

  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	long long sum;
	string a;
	while (true){
		sum = 0;
		cin >> a;
		if (a=="0")
			break;
		for (int i = 0; i<a.size(); i++){
			sum += (int)a[i]-'0';
		}
		cout << sum<<endl;
	}
}



Measured memory_bytes: 3160
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int n, q, a[123456];
string s;
signed main() {
	cin >> n >> q >> s;
	for1(i, n - 1) {
		a[i] = a[i - 1];
		if (s[i - 1] == 'A' && s[i] == 'C')a[i]++;
	}
	for1(i, q) {
		int l, r;
		cin >> l >> r; l--; r--;
		cout << a[r] - a[l] << endl;
	}
}

Measured memory_bytes: 1792
<?php
// Your code here!
    $num = intval(trim(fgets(STDIN)));
    
    for($i=0;$i<$num;$i++){
        $array[] = trim(fgets(STDIN));
    }
    // print_r($array);
    usort($array, "strnatcmp");
    // print_r($array);
    $count=1;
    
    for($i=0;$i<$num-1;$i++){
        // echo $array[$i]." ".$array[$i+1]."\n";
        if($array[$i] != $array[$i+1]){
            $count++;
        }else{
        }
    }
    echo $count."\n";
?>

Measured memory_bytes: 36400
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const MOD: i64 = 1e+9 as i64 + 7;
fn main() {
    let l = read::<String>().chars().collect::<Vec<char>>();
    let n = l.len();
    let mut threes = vec![1; n + 1];
    let mut twos = vec![1; n + 1];
    for i in 0..n {
        threes[i + 1] = (threes[i] * 3) % MOD;
        twos[i + 1] = (twos[i] * 2) % MOD;
    }
    let mut ans = 0;
    let mut ones = 0;
    for i in 0..n {
        if l[i] == '1' {
            let rest = n - i - 1;
            ans = (ans + twos[ones] * threes[rest]) % MOD;
            ones += 1;
        }
    }
    ans = (ans + twos[ones]) % MOD;
    println!("{}", ans);
}


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


#define LLINF 1e18+7
#define N 250000
ll MOD=1e9+7;
main(){
    int n=in();
    vector<pll> v;
    rep(i,n){
        v.pb({in(),in()});
    }
    double M=500000.0;
    double pi=3.14159265358979;
    double m=2*pi/M;
    double ans=0;
    rep(i,M){
        double t=m*i;
        double tmp=0.0;
        rep(j,n){
            double T=cos(t)*v[j].first+sin(t)*v[j].second;
            if(T>0)tmp+=T;
        }
        ans=max(ans,tmp);
    }
    printf("%.15f",ans);
}

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

int main() {
  int k,x;
  cin >> k >> x;
  rep(i,x-k+1,x+k-1) cout << i << " ";
  cout << x+k-1 << endl;
  return 0;
}


Measured memory_bytes: 3608
#include <iostream>
using namespace std;
int main()
{
    string s;
    cin >> s;
    if(s[1] == s[2] && (s[0] == s[1] || s[3] == s[1])){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
count = 0
while True:
    try:
        a, b = map(int, raw_input().split())
        if a + b == 0:
            break
        if count > 0:
            print ""
        flag = 0
        for i in range(a,b+1):
            if i%4 == 0 and (i%100 != 0 or i%400 == 0):
                print i
                flag = 1
        if flag == 0:
            print "NA"
        count += 1
    except:
        break

Measured memory_bytes: 4288
N = int(input())
red = [tuple([int(i) for i in input().split()]) for _ in range(N)]
blue = [tuple([int(i) for i in input().split()]) for _ in range(N)]
red.sort(key=lambda x: x[1], reverse=True)
blue.sort(key=lambda x: x[0])
ans = 0
for b in blue:
    for i, r in enumerate(red):
        if b[0] > r[0] and b[1] > r[1]:
            ans += 1
            red.pop(i)
            break
print(ans)


Measured memory_bytes: 38896
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define ll long long
//int 2×10の9乗
 
int main() {
  int n, x, X=0, ans=1;
  cin >> n >> x;
  vector<int> l(n);
  rep(i, n){
      cin >> l[i];
      X += l[i];
      if(X<=x) ans++;
  } 
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

typedef char* String;

String string_input(void){
    int i,len;
    char buf[30];
    String str;
    scanf("%s",buf);//buf=入力した文字列が入るchar型の配列
    
    len=strlen(buf);//len=文字列の長さを表すint型変数
    NEW(str,len+1);//strはただのポインタだから、ここでNEWを使ってメモリを確保しなくちゃいけない
    for(i=0;i<len;i++){
        str[i]=buf[i];
    }
    str[len]=0;
    
    return str;
}

int main(void){
    String S=string_input();
    int N=strlen(S);

    int* A;
    NEW(A,N);
    for(int i=0;i<N;i++) A[i]=S[i]-'0';

    long ans=0;
    for(int i=0;i<(1<<(N-1));i++){
        long tmp=0;
        long t=A[0];
        for(int j=0;j<N-1;j++){
            if(i&(1<<j)) t=t*10+A[j+1];
            else{
                tmp+=t;
                t=A[j+1];
            }
        }
        tmp+=t;
        ans+=tmp;
    }
    printf("%ld\n",ans);

    return 0;
}

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

int main() {
  int N,i,v;
  cin >> N;
  vector<int> a(N);
  for(i=0;i<N;i++) cin >> a.at(i); 
  v=0;
  for(i=0;i<N;i++){
    v = a.at(v) -1;
    if(v == 0) break;
    if(v == 1){
      cout << i+1 <<endl;
      break;
    }
  }
  if(v != 1) cout << -1 << endl;
}



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

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

    int ans = -1;
    for (int i = 0; i < S.size();) {
        int res = 0;
        for (int k = 0; i + k < S.size(); k++) {
            if (S[i] == S[i + k]) {
                res++;
                continue;
            }
            else {
                break;
            }
        }
        ans++;
        i += res;
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
 
int main(){
    long long N, M;
    cin>>N;
    M=N;
    //cout<<N<<endl;
    int sum = 0;
	for (long long i = 2; i*i<= N; i++) {
        int count = 0;
        //cout<<i<<endl;
        while (1) { // 素数で割り切れなくなるまで割っていく
            if(N%i == 0) {
                count++;
			    N = N/ i;
            }else{
                break;
            }
        }
        int count2=1;
        //if(count>0){
        //    cout<<i<<" "<<count<<endl;
        //}
        
        if(count>0){
            //cout<<i<<endl;
            while(1){
                count = count-count2;
                if(count<0) break;
                count2++;
                sum++;
                //cout<<sum<<endl;
            }
        }
    }
    if(N!=1) sum++;
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;

int main() {
    ll x, y;
    cin >> x >> y;
    int cnt = 0;
    while (true) {
        ll p = pow(2, cnt++);
        if (p * x > y) break;
    }
    cout << (cnt - 1) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <cstdio>

using namespace std;

int main() {
    int N, K, T, U, V, L;
    cin >> N >> K >> T >> U >> V >> L;

    priority_queue<pair<int, int> > q;
    vector<int> v(N);
    for(int i = 0; i < N; ++i) {
        cin >> v[i];
        q.push(make_pair(-v[i], 1));
    }

    bool boost = false;
    int boost_dist = 0;
    int ignore = 0;
    int prev = 0;
    int carrots = 0;
    q.push(make_pair(-L, 2));
    while(!q.empty()) {
        int pos = -q.top().first;
        int type = q.top().second;
        q.pop();

        if(boost) {
            boost_dist += pos - prev;
        }
        prev = pos;

        if(type == 0) {
            if(ignore) {
                --ignore;
                continue;
            }

            if(carrots) {
                --carrots;
                q.push(make_pair(-(pos+V*T), 0));
            }
            else {
                boost = false;
            }
        }
        else if(type == 1) {
            if(boost) {
                if(carrots == K) {
                    q.push(make_pair(-(pos+V*T), 0));
                    ++ignore;
                }
                else {
                    ++carrots;
                }
            }
            else {
                q.push(make_pair(-(pos+V*T), 0));
                boost = true;
            }
        }
        else if(type == 2) {
            break;
        }

    }

    printf("%.7f\n", (double)boost_dist / V + (double)(L-boost_dist) / U);

    return 0;
}

Measured memory_bytes: 0
import java.util.*;

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

        int A = sc.nextInt();
        int B = sc.nextInt();

        if(B%A==0){
            System.out.println(A+B);
        }
        else{
            System.out.println(B-A);
        }
    }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  string s;
  cin >> s;
  rep(i, 0, s.length() - 1) {
    if(s[i] == s[i + 1]) {
      cout << i + 1 << " " << i + 2 << endl;
      return 0;
    }
    if(i < s.length() - 2 && s[i] == s[i + 2]) {
      cout << i + 1 << " " << i + 3 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
}


Measured memory_bytes: 512
n = gets.to_i
d,x = gets.split.map(&:to_i)
ar = []
n.times do
  ar << gets.to_i
end

sum_arr = [ar.count,x]

ar.each do |v|
  (d/v).times do |i|
    if v*(i+1) < d
      sum_arr << 1
    end
  end
end

puts sum_arr.inject(&:+)


Measured memory_bytes: 1788
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord
import Data.Maybe


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


main :: IO ()
main = do
    [n,k] <- r' 
    print $ min (n`mod`k) ((-n)`mod`k)



Measured memory_bytes: 380
n=int(input())
s=list(input())
t=list(input())
t.reverse()
ans=float("inf")
if s==t:
    print(n)
    exit()
else:
    for i in range(n):
        a=t[i:]
        a.reverse()
        if s[i:]==a:
            ans=i
    if ans==float("inf"):
        print(2*n)
        exit()
    del s[ans:]
    print(len(s+t))


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)

int Sum(int a)
{
  return (a*(a+1))/2;
}

int main()
{
  ll n,k;
  cin >> n >> k;
  vector<int> p;
  for(int i = 0;i < n;i++)
  {
    int P;
    cin >> P;
    p.push_back(P);
  }

  // double ans = 0.0;

  if(k == 1)
  {
    sort(p.rbegin(),p.rend());
    cout << fixed << setprecision(12) << double(1+p[0])/2.0 << endl;
  }
  else
  {
    vector<pair<int , int > > p1;
  // int sum = 0;
    vector<int> sum(n);
    sum[0] = p[0];
    for(int i = 1;i < n;i++)
    {
      sum[i] = sum[i-1]+p[i];
    }
    for(int i = n-1;i >= k-1;i--)
    {
      p1.push_back(make_pair(sum[i]-sum[i-k],i-k+1));
    }
    // for(int i = 0;i < p1.size();i++)
    // {
    //   cout << p1[i].second << " " << p1[i].first << endl;
    // }
    int ans = 0;
    int j = 0;
    sort(p1.rbegin(),p1.rend());
    double b = 0.0;
    // cout << p1.size() << endl;
    // cout << j << endl;
    for(int i = p1[0].second;i < p1[0].second+k;i++)
    {
      b += double(1+p[i])/2.0;
    }
    cout << fixed << setprecision(12) << b << endl;
  }
}


Measured memory_bytes: 3956
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>

using namespace std;
typedef long long ll;
int mod(ll a){
    int c=a%1000000007;
    if(c>=0)return c;
    else return c+1000000007;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/

/////////////////////////////////


int a[10];
stack<int>b,c;
bool flag=false;
void dfs(int k){
    if(k==10){
        flag=true;
        return;
    }
    if(b.top()<a[k]){
        b.push(a[k]);
        dfs(k+1);
        b.pop();
    }
    if(c.top()<a[k]){
        c.push(a[k]);
        dfs(k+1);
        c.pop();
    }
    return;
}


int main(){
    int n;cin>>n;
    while(n--){
        flag=false;
        for(int i=0;i<=9;i++)scanf("%d",&a[i]);
        b.push(a[0]),c.push(0);
        dfs(1);
        if(flag==true)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}




Measured memory_bytes: 3164
N=int(input())
p=list(map(int,input().split()))
cnt=0
for i in range(N-2):
    if p[i]<p[i+1] and p[i+1]<p[i+2]:
        cnt += 1
    elif p[i]>p[i+1] and p[i+1]>p[i+2]:
        cnt += 1
print(cnt)

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

int main() {
  bool check = true;
  string S;
  cin >> S;
  int N =S.size();
  vector<char> moji(N);
  for(int i=0; i < N ; i++){
    moji.at(i) = S.at(i);
  }
  vector<char> mojirev(N);
  vector<char> mojirev1((N-1)/2);
  vector<char> mojirev2((N-1)/2);
  for(int i=0; i<N ; i++){
    mojirev.at(i) = moji.at(N-1-i);
    if(i < (N-1)/2){
      mojirev1.at(i) = moji.at((N-3-2*i)/2);
      mojirev2.at(i) = moji.at(N-1-i);
    }
  }
  for(int i=0; i<N; i++){
    if(moji.at(i) != mojirev.at(i)){
      check = false;
    }
    if(i < (N-1)/2){
      if(moji.at(i) != mojirev1.at(i)){
        check = false;
      }
      if(moji.at(i+(N+1)/2) != mojirev2.at(i)){
        check = false;
      }
         }
         if(check == false){
           break;
         }
         }
         
         if(check){
           cout << "Yes" << endl;
         }
         else 
         {cout << "No" << endl;
         }
         }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i = x; i < (int)(n); i++)
#define rep_ll(i,x,n) for(ll i = x; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main(){
    string s, t;
    cin >> s >> t;
    int cnt=0;
    rep(i, 0, s.size()){
        if(s[i]!=t[i]) cnt++;
    }
    cout << cnt;
}

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

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.1415926535897932384626

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

int n, sel[10005];
PII s[10005], pp[10005];

struct info{
	int id, fb, pos;
	bool operator<(const info &k) const{
		return pos < k.pos;
	}
};

info u[20005];

int q[20005], ql, qr, ok;

void dfs(int id, int cho, int d){
	ql = qr = 0;
	q[++qr] = id;
	sel[id] = cho;
	while(ql < qr){
		int cur = q[++ql], cp;
		if(sel[cur] == 0) cp = pp[cur].fi;
		else cp = pp[cur].se;
		
		FD(i, cp - 1, 1){
			if(u[i].pos + d <= u[cp].pos) break;
			if(sel[u[i].id] == -1){
				sel[u[i].id] = 1 - u[i].fb;
				q[++qr] = u[i].id;
			}
			else if(sel[u[i].id] == u[i].fb){
				ok = false;
				return;
			}
		}
		FI(i, cp + 1, n + n){
			if(u[i].pos - d >= u[cp].pos) break;
			if(sel[u[i].id] == -1){
				sel[u[i].id] = 1 - u[i].fb;
				q[++qr] = u[i].id;
			}
			else if(sel[u[i].id] == u[i].fb){
				ok = false;
				return;
			}
		}
	}
	return;
}

bool good(int d){
	//preliminary test
	int cnt = 0, pd = -d;
	FI(i, 1, n + n){
		if(u[i].pos >= pd + d){
			pd = u[i].pos;
			cnt++;
		}
	}
	if(cnt < n) return false;
	
	FI(i, 1, n) sel[i] = -1;
	FI(i, 1, n) if(sel[i] == -1){
		ok = true;
		dfs(i, 0, d);
		if(!ok){
			FI(i, 1, qr) sel[q[i]] = -1;
			ok = true;
			dfs(i, 1, d);
			if(!ok) return false;
		}
	}
	return true;
}

int main(){
	scanf("%d", &n);
	FI(i, 1, n){
		scanf("%d %d", &s[i].fi, &s[i].se);
		if(s[i].fi > s[i].se) swap(s[i].fi, s[i].se);
		u[i + i - 1] = (info){i, 0, s[i].fi};
		u[i + i] = (info){i, 1, s[i].se};
	}
	
	sort(s + 1, s + n + 1);
	sort(u + 1, u + n + n + 1);
	
	FI(i, 1, n + n){
		if(u[i].fb == 0) pp[u[i].id].fi = i;
		else pp[u[i].id].se = i;
	}
	
	int l = 0, r = 1000000001;
	while(r - l > 1){
		int m = (l + r) >> 1;
		if(good(m)) l = m;
		else r = m;
	}
	printf("%d\n", l);
	return 0;
}


Measured memory_bytes: 768
INF = 10 ** 10
N, M, X = map(int, input().split())
C = list()
A = list()
for n in range(N):
    ca = list(map(int, input().split()))
    C.append(ca[0])
    A.append(ca[1:])
ans = INF
for n in range(2 ** N):
    m = [0] * M
    c = 0
    for nn in range(N):
        if (n & (1 << nn)) > 0:
            c += C[nn]
            for mm in range(M):
                m[mm] += A[nn][mm]
    if all([x >= X for x in m]):
        ans = min(ans, c)
print(ans if ans < INF else -1)

Measured memory_bytes: 68808
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define N 100100
#define PI 3.141592653589793238
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans%p;
}
ll inv(ll a,ll m)
{
    return power(a,m-2,m);
}
//code begins
void solve(){
    ll n;cin>>n;
    ll a[n+1];
    for(ll i=1;i<=n;i++)cin>>a[i];
    ll ans=0;
    for(ll i=1;i<=n;i+=2)
        if(a[i]&1)ans++;
    cout<<ans<<endl;
}
signed main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

//    ll t;cin>>t;while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 3584
import java.util.Scanner;

public 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");
            
        }else if(b.equals("T")){
            System.out.println("A");
            
        }else if(b.equals("C")){
            System.out.println("G");
            
        }else if(b.equals("G")){
            System.out.println("C");
        }
    }
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
priority_queue<int> pq[1005];
int n, q, c, a, b;
int main() {
	cin >> n >> q;
	for (int i=0; i<q; i++) {
		cin >> c;
		if (c==0) {
			cin >> a >> b;
			pq[a].push(b);
		} else if (c==1) {
			cin >> a;
			if (!pq[a].empty()) cout << pq[a].top() << "\n";
		} else if (c==2) {
			cin >> a;
			if (!pq[a].empty()) pq[a].pop();
		}
	}
}


Measured memory_bytes: 4056
#include<stdio.h>
int main(){
  int a,b,d,j,i,c;
  int A[100][100]={};
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d%d",&b,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      A[b-1][c-1]=1;
    }
  }
  for(i=0;i<a;i++){
    for(j=0;j<a;j++){
      if(j==a-1)printf("%d",A[i][j]);
      else printf("%d ",A[i][j]);
    }
    printf("\n");
  }
}



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


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    vector<int> v(n);
    for(int i=0;i<n;i++){
    	cin>>v[i];
	}
	int dp[n];
	dp[0]=0;
	dp[1]=abs(v[1]-v[0]);
	for(int i=2;i<n;i++){
		int minval = INT_MAX;
		for(int j=1;j<=min(i,k);j++){
			if((abs(v[i]-v[i-j])+dp[i-j])<=minval){
				minval = (abs(v[i]-v[i-j])+dp[i-j]);
			}
		}
		dp[i]=minval;
	}
	cout<<dp[n-1];
    return 0;
}


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

using namespace std;
typedef long long ll;

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

  string ans = "";
  while (n > 0) {
    ll remain = n % 26;
    if (remain == 0) remain = 26;
    char add = 'a' + (remain - 1);
    ans += add;
    n /= 26;
    if (remain == 26) n--;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
int main() {
  int N,M,C;
  cin >> N >> M >> C;
  int a[N][M], b[M], d[N];
  int cnt = 0;
  
  for(int i = 0;i < M; ++i){
    cin >> b[i];
  }
  for(int i = 0;i < N;++i){
    d[i] = 0;
    for(int j = 0;j < M; ++j){   
      cin >> a[i][j];
      d[i] += a[i][j] * b[j];
    }
    if(d[i] + C > 0)
      cnt++;
  }
      
  cout << cnt << endl;    
}

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

using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[n][3];
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin >> a[i][j];
        }
    }
    int cnt[n];
    for(int i=0;i<n;i++){
        cnt[i]=0;
    }
    
    for(int i=0;i<3;i++){
        for(int j=0;j<n;j++){
            int c=0;
            for(int k=0;k<n;k++){
                if(j!=k){
                    if(a[j][i]==a[k][i]){
                        c++;
                    }
                }
            }
            if(c==0){
                cnt[j]+=a[j][i];
            }
        }
    }
    
    for(int i=0;i<n;i++){
        cout << cnt[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <stdio.h>

void swap(unsigned long *a, unsigned long *b) {
  unsigned long tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}

unsigned long gcd(unsigned long a, unsigned long b) {
  unsigned long tmp;

  while (b) {
    tmp = b;
    b = a % b;
    a = tmp;
  }

  return a;
}

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

int main(void) {
  unsigned long a, b;

  while (scanf("%lu %lu", &a, &b) != EOF) {
    if (a < b) swap(&a, &b);

    printf("%lu %lu\n", gcd(a, b), lcm(a, b));
  }

  return 0;
}

Measured memory_bytes: 600
def f(n):
  if n%2==0:
    return n//2
  else:
    return 3*n+1
S=int(input())
pre=S
dic={S:1}
while True:
  a=f(pre)
  if a not in dic:
    dic[a] = 1
  else:
    break
  pre = a
print(len(dic)+1)



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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  bool p=true,m=true;
  for(int i=0;i<N;i++){
    if(A[i]>0)m=false;
    if(A[i]<0)p=false;
  }
  sort(rng(A));
  vector<pii>res;
  ll ans=0;
  if(p&&!m){
    ll S=A[0];
    for(int i=1;i<N-1;i++){
      res.push_back({S,A[i]});
      S-=A[i];
    }
    res.push_back({A[N-1],S});
    ans=A[N-1]-S;
  }
  else if(!p&&m){
    reverse(rng(A));
    ll S=A[0];
    for(int i=1;i<N;i++){
      res.push_back({S,A[i]});
      S-=A[i];
    }
    ans=S;
  }
  else if(p&&m){
    for(int i=0;i<N-1;i++){
      res.push_back({0,0});
    }
    ans=0;
  }
  else if(!p&&!m){
    ll S=A[0];
    for(int i=1;i<N-1;i++){
      if(A[i]<0)continue;
      res.push_back({S,A[i]});
      S-=A[i];
    }
    res.push_back({A[N-1],S});
    S=A[N-1]-S;
    for(int i=1;i<N-1;i++){
      if(A[i]>=0)continue;
      res.push_back({S,A[i]});
      S-=A[i];
    }
    ans=S;
  }
  cout<<ans<<endl;
  for(auto it:res)cout<<it.first<<" "<<it.second<<endl;
  return 0;
}


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

int main() {
    string s,t;
    cin >> s;
    cin >> t;
    // sを辞書順最小にし、tを辞書順最大にして比較、s<tになれば条件を満たす
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end()); //tを辞書順最大にしている

    if (s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;

void main() {
    while(true) {
        int n = readln.chomp.to!int;
        if (n==0) break;
        int[] h = readln.split.to!(int[]);

        foreach(i; 0..h.length) {
            int[] _h = h[0..i] ~ h[i+1..$];
            int[] sa = new int[n-1];
            foreach(j, ref e; sa) {
                e = _h[j+1]-_h[j];
            }
            if (sa.count!(a=>a==sa[0]) == sa.length) {
                writeln(h[i]);
                break;
            }
        }
    }
}

Measured memory_bytes: 3116
package main

import "fmt"

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

	as := make([]int, n+1)
	bs := make([]int, n)

	for i := range as {
		fmt.Scan(&as[i])
	}

	for i := range bs {
		fmt.Scan(&bs[i])
	}

	var sum int
	for i := 0; i <= n-1; i++ {
		a := as[i]
		b := bs[i]
		if a <= b {
			sum += a
			b -= a
			if i+1 <= n {
				an := as[i+1]
				if an <= b {
					sum += an
					as[i+1] = 0
				} else {
					sum += b
					as[i+1] -= b
				}
			}
		} else {
			sum += b
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll r, d, x;
int main() {
    cin>>r>>d>>x;

    ll tmp=r*x-d;
    REP(i, 0, 10){
        cout<<tmp<<endl;
        tmp=r*tmp-d;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
vector<int> primeFactors(int n) {
    vector<int> v;
    int i = 2;
    while (i * i <= n) {
        if (n % i == 0) {
            v.push_back(i);
            n /= i;
        } else {
            i++;
        }
    }
    if(n != 1)v.push_back(n);
    return v;
}
class modcomb {
public:
    int maxn,MOD;
    vector<int>fac,finv,inv;
    modcomb(int _maxn,int _mod) : maxn(_maxn),MOD(_mod),fac(_maxn),finv(_maxn),inv(_maxn){
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < maxn; i++){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    };
    int modComb(int n,int k){
        if (n < k) return 0LL;
        if (n < 0 || k < 0) return 0LL;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
    
};
signed main(){
    auto dp = vector<vector<int>>(101);
    rep(i,101)dp[i] = primeFactors(i);
    int n; cin >> n;
    map<int,int>mp;
    for(int i = 1; i <= n;i++){
        for(auto val : dp[i]){mp[val]++;}
    }
    map<int,int>a,b,c;
    //int f = 0,t = 0;
    int temp = 0;
    for(auto i : mp){
        for(auto j : mp){
            for (auto k :mp){
                if(i == j or j == k or k == i)continue;
                if(i.second >= 4 and j.second>=4 and k.second>=2)++temp;
            }
        }
    }
    int ta = 0; int tb = 0;
    for(auto i : mp){
        for(auto j : mp){
            if(i.first == j.first)continue;
            if(i.second >= 14 and j.second >= 4){
                ta++;
            }
        }
    }
    int subans = 0;
    for(auto i : mp){
        for(auto j : mp){
            if(i.first == j.first)continue;
            if(i.second >= 24 and j.second >= 2){
                tb++;
            }
        }
        if(i.second >= 74)subans++;
    }
    cout << temp/2 + ta + tb + subans << endl;
    
}




Measured memory_bytes: 256
s = str((input()))
count = 0

if len(s) % 2 == 1:
    print("No")
    exit()

for i in range(len(s)-1):
    if s[i] == "h" and s[i+1] == "i":
        count += 1
if count == len(s) // 2:
    print("Yes")
else:
    print("No")

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

struct a
{
    ll f,s;
};
bool cmp(a z,a x)
{
    if(z.s !=x.s)
    return z.s<x.s;
    return z.f>x.f;
}
int main()
{
    ll n,m;
    cin>>n>>m;
    a q;
    vector < a > w;
    while(m--)
    {
        cin>>q.f>>q.s;
        w.push_back(q);
    }
    sort(w.begin(),w.end(),cmp);
    ll last=0;
    ll ans=0;
    ll j=0;
   // for(ll i=0;i<w.size();i++)
        //cout<<" w [i] " <<w[i].f<<" "<<w[i].s<<endl;
    for(ll i=1;i<=n;i++)
    {
        if(j>=w.size()) break;
        if(w[j].s==i)
        {
            if(w[j].f>=last)
            {
                ans++;
                j++;
                last=i;
            }
            else
                j++;
            if(j>=w.size()) break;
            //cout<<i<< " w["<<j-1<<" ] "<<endl;
            //cout<<ans<<" last = "<<last<<endl;
            while(w[j].s<=i)
            {
                j++;
                if(j>=w.size()) break;
            }
        }
        if(j>=w.size()) break;

    }
    cout<<ans<<endl;
}


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

typedef double f64;
typedef long long i64;
typedef int i32;
typedef pair<i32, i32> pi32;
typedef unsigned long long u64;
typedef unsigned int u32;
typedef vector<i32> vi32;
typedef deque<i32> di32;

#define all(c) (c).begin(), (c).end()
#define REP(i, a, b) for (auto i = a; i < b; i++)
#define REPA(i, a, b, acc) for (auto i = a; i < b; i += acc)
#define PB push_back
#define PF push_front
#define TR(c, it) for (auto(it) = (c).begin(); (it) != (c).end(); (it)++)

i32 main() {
  ios::sync_with_stdio(false);  // Makes IO faster, remove this line if C style scanf/printf needed.

  i32 n, m;
  cin >> n >> m;
  i32 a[m];
  REP(i, 0, m) {
    cin >> a[i];
  }
  sort(a, a + m);
  i32 totalMove = a[m - 1] - a[0];

  i32 b[m];
  // There are (m - 1) "segments", each piece can reduce exactly one segment.
  REP(i, 0, m - 1) {
    b[i] = a[i + 1] - a[i];
  }
  sort(b, b + m - 1);

  i32 choices = min(m - 1, n - 1);
  REP(i, 0, choices) {
    // b's length is m - 1, need extra (-i - 1) to map the index.
    totalMove -= b[m - i - 2];
  }
  cout << totalMove << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
 
int main(void){
  int i,e;
  static int n[26];
  char st,al[53] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
   
  do{
    e = scanf("%c", &st);
 
    for(i=0;i<52;i++)
      if(al[i] == st){
        n[ i%26 ]++;
      }
 
  }while(e != EOF);
 
  for(i=0;i<26;i++)
    printf("%c : %d\n", al[i] , n[i]);
 
  return 0;
}


Measured memory_bytes: 2112