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

int main (){
	int N,pl=0,l=0;
	string s;
	cin>>N>>s;

	for(int t=0;t<N;t++){
		if(s[t]==')'){
			if(l-1<0){
				pl++;
				continue;
			}else{
				l--;
			}
		}else if(s[t]=='('){
			l++;
		}
	}

	for(int t=0;t<pl;t++)cout<<'(';
	cout<<s;
	for(int t=0;t<l;t++)cout<<')';
	return 0;
}


Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2019/12/29
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;

int A[1001] = {0};
int main()
{
	int N = 0, i = 0, ans = 0;
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
		if (A[i]%2 == 0) {

		}
	}
	for (i = 0; i < N; i++) {
		if (A[i]%2 == 0) {
			if ((A[i]%3 == 0) || (A[i]%5 == 0)) {
			} else {
				ans = 1;
			}
		}
	}
	if (ans == 0) {
		printf("APPROVED\n");
	} else {
		printf("DENIED\n");
	}
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<set<int>> v(26);
    for(int i=0;i<n;i++)
    v[s[i]-'a'].insert(i);
    int q;
    cin>>q;
    while(q--)
    {
        int t;
        cin>>t;
        if(t==1)
        {
            int pos;
            cin>>pos;
            pos--;
            char c;
            cin>>c;
            v[s[pos]-'a'].erase(pos);
            v[c-'a'].insert(pos);
            s[pos]=c;
        }
        else
        {
            int l,r;
            cin>>l>>r;
            l--;
            r--;
            int ans=0;
            for(int i=0;i<26;i++)
            {
              	if(v[i].empty())
                  continue;
                auto it=v[i].lower_bound(l);
                if(it!=v[i].end() && (*it)>=l && (*it)<=r)
                ans++;
            }
            cout<<ans<<endl;
        }
    }
	return 0;
}


Measured memory_bytes: 24196
N = int(input())
D, X = map(int, input().split())
A = [int(input()) for _ in range(N)]

cnt = 0
for i in range(N):
    interval = 0
    while True:
        if 1 + A[i] * interval <= D:
            cnt += 1
            interval += 1
        else:
            break
print(cnt+X)




Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long  K = sc.nextLong();
		int A[] = new int[N];
		for (int i=0;i<N;i++) {
			A[i] = sc.nextInt();
		}
		double sum =0;
		for (int i=0;i<N;i++) {
			sum +=A[i];
		}
		double min =1;
		double max = sum/(K+1);
		double mid= 0;
		for (int i=0;i<100;i++) {
			mid = (min+max)/2;
			long num =0;
			for (int j=0;j<N;j++) {
				num +=(int)(A[j]/mid);
			}
			if (num <K+1) {
				max =mid;
			} else {
				min = mid;
			}
		}
		if (K>0) {
			System.out.println((long)Math.ceil(mid));
		} else {
			System.out.println((long)mid);
		}

	}
}

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

using namespace std;

#define loop(i, n) for(int i = 0;i < int(n);i++)
#define rloop(i, n) for(int i = int(n);i >= 0;i--)
#define range(i, a, b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

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

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
vi adj[N];
int can[N], forb[N];
int n, k;

int mul(int x, int y) {
    return 1LL * x * y % MOD;
}

void dfs(int u, int par, int f) {
    can[u] = k - f;
    f = 2;
    for (int nxt : adj[u]) {
        if (nxt == par)continue;
        dfs(nxt, u, f++);
    }
}


int main() {

#ifndef ONLINE_JUDGE
    //freopen("in.in", "r", stdin);
    //freopen("out.in", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b;
    cin >> n >> k;
    loop(i, n - 1) {
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    can[1] = k;
    int f = 1;
    for (int nxt : adj[1]) {
        dfs(nxt, 1, f++);
    }

    int ans = 1;
    range(i, 1, n) {
        ans = mul(ans, can[i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9600
N,M = map(int, input().split())
shop = []
for i in range(N):
    a,b = map(int, input().split())
    shop.append([a,b])

shop.sort()
ans = 0
for s in shop:
    if M <= 0:
        break
    tmp = min(s[1],M)
    ans += tmp * s[0]
    M -= tmp
print(ans)


Measured memory_bytes: 20072
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        
        int[] a = new int[n];
        
        int sum = 0;
        
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
            sum+=a[i];
        }
        
        double tmp = (double)sum/n;
        
        double[] distance = new double[n];
        
        for(int i = 0; i < n; i++){
            distance[i] = Math.abs(a[i] - tmp);
        }
        
        double min = Double.MAX_VALUE;
        int index = 0;
        
        for(int i = 0; i < n; i++){
            if(distance[i] < min){
                min = distance[i];
                index = i;
            }
        }
        
        System.out.println(index);
        
    }
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

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

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

struct UnionFind {
  vi parent, rank, count;
  UnionFind(const int nodeSize)
    : parent(nodeSize), rank(nodeSize, 1), count(nodeSize) {
    rep(i, nodeSize) parent[i] = i, count[i] = 1;
  }
  int find(int x) {
    if (parent[x] == x) return x;
    return parent[x] = find(parent[x]);
  }
  void unite(int x, int y) {
    int rx = find(x);
    int ry = find(y);
    if (rx == ry) return;
    if (rank[rx] < rank[ry]) swap(rx, ry);
    parent[ry] = rx;
    count[rx] += count[ry];
    if (rank[rx] == rank[ry]) ++rank[rx];
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  int num(int x) {
    return count[find(x)];
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n, m; std::cin >> n >> m;
  vi p(n); rep(i, n) std::cin >> p[i], p[i]--;
  UnionFind uf(n);
  rep(i, m) {
    int x, y; std::cin >> x >> y;
    --x, --y;
    uf.unite(x, y);
  }

  int ans = 0;
  rep(i, n) {
    ans += uf.same(p[i], i);
  }
  std::cout << ans << "\n";
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    int c = max(0, a - 2 * b);
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const int SIZE = 1000000;

ll kai[1000001];
ll dp[1000001];
ll n;

ll mod_pow (ll x, ll y) {
    ll ret = 1;
    while (y) {
        if (y&1) ret = ret*x%MOD;
        x = x * x % MOD;
        y /= 2;
    }
    return ret;
}

ll conb (ll x, ll y) {
    y = kai[y]*kai[x-y]%MOD;
    y = mod_pow(y, MOD-2);
    return kai[x]*y%MOD;
}

void init() {
    kai[0] = 1;
    for (ll i = 1; i <= SIZE; i++) kai[i] = kai[i-1]*i%MOD;
}

int main() {
    init();
    cin >> n;
    if (n == 2) {
        cout << 1 << endl;
        return 0;
    }
    if (n == 3) {
        cout << 4 << endl;
        return 0;
    }
    ll ans = 0;
    for (ll k = 2; k <= n-1; k++) {
        if (k-1 < n-1-k) continue;
        ll add = kai[k]*kai[n-1-k]%MOD;
        add = (add * conb(k-1, n-1-k))%MOD;
        dp[k] = add;
        ans = (ans+(dp[k]-dp[k-1]+MOD)*k)%MOD;
    }
    cout << ans << endl;
}



Measured memory_bytes: 13824
import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    T, A = 1, 1
    for _ in range(N):
        Ti, Ai = read_ints()
        # T  A   T    A
        # Ti Ai  Ti*x Ai*x
        #
        # Ti*x >= T, Ai*x >= A, min x?
        # x >= T/Ti
        # x >= A/Ai
        if T%Ti == 0:
            x0 = T//Ti
        else:
            x0 = T//Ti+1
        if A%Ai == 0:
            x1 = A//Ai
        else:
            x1 = A//Ai+1
        x = max(x0, x1)
        T, A = Ti*x, Ai*x
    return T+A


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 73732
#include <cstdio>
#include <iostream>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

int main(void) {
  int a, b;
  cin >> a >> b;
  if(a >= 13) {
    cout << b << endl;
  } else if(a >= 6) {
    cout << b/2 << endl;
  } else {
    cout << 0 << endl;
  }
    
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int C(int A,int B){
  int buf =1;
  for(int i=0; i<B ; i++){
    buf *= (A-i);
    buf /= (i+1);
  }
  return buf;
}
 
int main() {
  int N,M;// N even M odd
  int all=0,ans=0;
  cin >> N >> M;
  // zenbu N+M C k (k==0 ~ k==N+M)
  for(int k=0; k<=(N+M); k++){
    int buf=1;
    for(int i=0; i<k; i++){
      buf *= (N+M-i);
      buf /= (i+1);
    }
    all += buf;
  }
  // M kisuuko
  for(int i=1; i<=M; i+=2){
    // (M C i)
    int A;
    A=C(M,i);
    for(int j=0;j<N;j++){
      // (M C i) * (N C j)
      ans += (A*C(N,j));
    }
  }
  int NM = N+M,B=0;
  //2ko
  B=C(NM,2);
  //1 ko odd
  int odd;
  odd = N*M;
  ans = B - odd;
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;

	
	public static void Main(string[] args)
	{
		var s = Console.ReadLine();
		bool c = false;
		for(int i = 0; i < s.Length; i++)
		{
			if(!c && s[i] == 'C')
				c= true;
			
			if(c && s[i]=='F')
			{
				Console.WriteLine("Yes");
				return;
			}
		}
		Console.WriteLine("No");
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define int long long int
using namespace std;
map<ii,int>edge;
vector<int>adj[100005];
vector<int>deg(100005,0);
vector<int>color(100005,-1);
void dfs(int x,int pre){
      int ban=-1;
      if(pre!=0)
      ban=color[edge[{pre,x}]];
      int c=1;
      for(int i=0;i<adj[x].size();i++){
            int y=adj[x][i];
            if(y==pre)continue;
            if(c==ban)c++;
            color[edge[{x,y}]]=c++;
            dfs(y,x);
      }
}
int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
  //    freopen("q.gir","r",stdin);
  //    freopen("q.cik","w",stdout);
      int n;
      cin>>n;
      for(int i=0;i<n-1;i++){
            int x,y;
            cin>>x>>y;
            adj[x].pb(y);
            adj[y].pb(x);
            edge[{x,y}]=i;
            edge[{y,x}]=i;
            deg[x]++;
            deg[y]++;
      }
      int G=*max_element(all(deg));
      cout<<G<<"\n";
      dfs(1,0);
      for(int i=0;i<n-1;i++)cout<<color[i]<<"\n";
}


Measured memory_bytes: 21632
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

use std::cmp;
use std::collections::{HashSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;
fn main() {
    input!{
        x: usize,
    }

    let mut times = (x / 11) * 2;
    let res = x % 11;
    match res {
        1...6 => times += 1,
        7...11 => times += 2,
        _ => (),
    }
    println!("{}", times);
}

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

#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
#define CLR(arr,val) memset(arr,val,sizeof(arr))

typedef long long LL;

int main(){
    int a,b;
    cin>>a>>b;
    if((a*b)%2==0) cout<<"Even"<<endl;
    else cout<<"Odd"<<endl;

    return 0;
}


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

int main() {
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int ans=min(k,a);
    k=max(0,k-a);
    k=max(0,k-b);
    ans-=min(k,c);
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3636
def water(a):
    if len(a)==0:return 0
    ma=min(a)
    x=ma
    l=[]
    for i in range(len(a)):
        y=a[i]-ma
        if y>0:l.append(y)
        else:
            x+=water(l)
            l=[]
    x+=water(l)
    return x

n=input()
a=list(map(int,input().split()))
print(water(a))

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

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	int d = a-b;
	if(d <= 0) d = 0;
	int e = c -d;
	if(e < 0) e = 0;
	cout << e << endl;
}

// cout << fixed << setprecision(15) <<  << endl;

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <numeric>
#include <iomanip>
using namespace std;
    
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
    
using ll = long long;
const ll INF = LLONG_MAX - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
    
class fact {
public:
    int fmod = 1e9+7;
    vector<int> fac, inv;
    fact (int n, int Mod = 1e9+7) {
        fmod = Mod;
        fac = vector<int>(n,0);
        inv = vector<int>(n,0);
        fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
        for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
    }
    ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
    ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
    
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}
int poorpow(int b, int a) {
    int tmp = 1;
    REP (i,a) {
        tmp *= b;
    }
    return tmp;
}


bool solve() {
    int n,m; cin >> n >> m;
    cout << (n-1) * (m-1) << endl;
}

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


Measured memory_bytes: 256
#include<ios>

int main(){
    int iN;
    scanf("%d",&iN);
    int a[iN];
    for (int i=0;i<iN;i++){
        scanf("%d" ,&a[i]);
    }
    for (int i = 0;i<iN;i++){
        a[i] = a[i] -1;
    }
    int iC = 0;
    int iV ;
    for(int i = 0;i<iN;i++){
        iC++;
        if (i == 0){
            iV = a[0];
        }else{
            iV = a[iV];
        }
        if (iV == 1){
            break;
        }
    }
    if (iV == 1){
        printf("%d\n",iC);
    }else{
        printf("%d\n",-1);
    }
    return 0;
}


Measured memory_bytes: 512
from copy import deepcopy
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools
import copy


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


def gcd(a, b):
    while(b != 0):
        a, b = b, a % b
    return a


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
if n % 1000 == 0:
    print(0)
    exit()
for i in range(1, 10001):
    if(0 < 1000*i-n):
        print(1000*i-n)
        exit()


Measured memory_bytes: 72852
# 今日の天気を入力
today_weather = input()

# 今日の天気から明日の天気をSunny,Cloudy,Rainyの周期で予測して出力
if today_weather == "Sunny":
    print("Cloudy")
elif today_weather == "Cloudy":
    print("Rainy")
else:
    print("Sunny")

Measured memory_bytes: 9096
# -*- coding: utf-8 -*-
def solve(): 
    N, M =  map(int, input().split())
    l = 1
    r = N
    for _ in range(M):
        L, R = map(int, input().split())
        l = max(l, L)
        r = min(r, R)
    res = max(r-l+1, 0)
    return str(res)

if __name__ == '__main__':
    print(solve())



Measured memory_bytes: 3060
N = int(input())

A = 0
min_score = len(str(N))

while True:

    A += 1

    if A * A > N:
        break

    if N%A != 0:
        continue

    B = N//A

    # check
    cur = max([len(str(A)), len(str(B))])
    if min_score > cur:
        min_score = cur

print(min_score)

Measured memory_bytes: 3060
function main()
  n,m=map(x->parse(Int,x),split(readline()))
  s=chomp(readline())
  t=chomp(readline())
    k=gcd(n,m)
    flg = 0
    for i in 0:k-1
      if s[i*div(n,k)+1]!=t[i*div(m,k)+1]
        flg=1
        break
      end
    end
    if flg==1
      print(-1)
    else
      print(lcm(n,m))
    end
end
main()


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

using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
string s;
bool ok1,ok2;
int main()
{
    cin>>s;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='A')
            ok1=true;
        else
            ok2=true;
    }
    ok1==ok2&&ok1==true ? cout<<"Yes" : cout<<"No";
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) = println(run {
    var x = readLine()!!.toLong()
    
    while (!isPrime(x)) ++x
    x
})

fun isPrime(x: Long): Boolean {
    val sqrtX = Math.sqrt(x.toDouble()).toLong()
    return (2..sqrtX).all { x % it != 0L }
}

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

int main(){
  long long int a,b,c;
  vector<long long int> tmpall;
  for(int i=0;i<3;i++){
    long long int tmp=0;
    cin>>tmp;
    tmpall.emplace_back(tmp);
  }
  sort(tmpall.begin(),tmpall.end());
  a=tmpall[0];b=tmpall[1];c=tmpall[2];
  
  long long int ab,abc,ans;
  ab=a*b;
  abc=a*b*c;
  ans=abc-(ab*(c/2)*2);
  
  cout<<ans<<endl;

  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n)  for (int i=(int)(a); i<=(int)(n); ++i)
#define rrep(i,a,n) for (int i=(int)(a); i>=(int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(f, 0, (x.size()-1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K;
vector<int> A,B;
vector<int> C,S,F;

//=============================
void input()
{
    cin>>N;
    C.resize(N);S.resize(N);F.resize(N);
    rep(i,0,N-1){
        cin>>C[i]>>S[i]>>F[i];
    }

}
//=============================
void func(){}
/*
 - 樹形図をかく
*/
//=============================
void solve()
{

    rep(i,0,N-1){
        int t=0;
        rep(j,i,N-2){
            if (t<S[j]) t=S[j];
            else if (t%F[j] == 0)t=t;
            else t = t+F[j]-t%F[j];
            t += C[j];
        }
        cout<<t<<endl;
    }
}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int; //任意長整数 
using Real32 = mp::number<mp::cpp_dec_float<32>>;
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
using Rat = boost::rational<Bint>;//有理数*/
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
ll mod = 1000000007;
const ll INF = 100010;
//cin.tie(0);
//ios::sync_with_stdio(false);

ll a[INF],ab[INF],abc[INF],pat[INF];

signed main(){
    string s;
    cin>>s;
    pat[0]=1;
    for(int i=1;i <= siz(s);i++)
    {
        if(s.at(i-1)=='?'){
            a[i]=3*a[i-1]+pat[i-1];
            ab[i]=3*ab[i-1]+a[i-1];
            abc[i]=3*abc[i-1]+ab[i-1];
            pat[i]=pat[i-1]*3;
            pat[i]%=mod;
        }else{
            a[i]=a[i-1];
            ab[i]=ab[i-1];
            abc[i]=abc[i-1];
            pat[i]=pat[i-1];
            pat[i]%=mod;
            
            if(s.at(i-1)=='A') a[i]+=pat[i-1];//不十分、新たに追加されたaの前のパターン数を考慮していない
            else if(s.at(i-1)=='B')ab[i]+=a[i-1];
            else abc[i]+=ab[i-1];
        }
        a[i]%=mod;
        ab[i]%=mod;
        abc[i]%=mod;  
        //cout << abc[siz(s)] << endl;
    }
    cout << abc[siz(s)] << endl;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii              pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define PI              3.14159265
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define __              ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rep(i,a,b) 		for(int i=a;i<b;i++)
#define repb(i,a,b) 	for(int i=a;i>=b;i--)
#define endl			"\n"
#define m(a)		    memset(a,0,sizeof(a))
#define all(x)          begin(x), end(x)

/*
// warning this works with cpp14 only...register depricated in 17
void fastscan(int &x){
bool neg = false;register int c;
x = 0;c = getchar();
if(c=='-'){neg = true;c = getchar();}
for(; (c>47 && c<58); c=getchar()){x = x *10 + c - 48;}
if(neg){x *= -1;}}

*/

void file(){
	#ifndef ONLINE_JUDGE
	freopen("in.txt" , "r" , stdin);
	freopen("out.txt" , "w" , stdout);
	#endif
}

int bs(int a[] , int s , int e, int x){
	if(s<=e){
		int m = (s+e)/2;
		if(a[m]==x)
			return m;
		else if(a[m] > x)
			return bs(a,s,m-1,x);
		else return bs(a,m+1,e,x);
	}
	return -1;
}

#define tr(x) cout<<x<<endl;
#define tr2(x,y) cout<<x<<" "<<y<<endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(w,x,y,z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<endl;
#define tr5(v,w,x,y,z) cout<<v<<" "<<w<<" "<<x<<" "<<y<<" "<<z<<endl;
#define tr6(u,v,w,x,y,z) cout<<u<<" "<<v<<" "<<w<<" "<<x<<" "<<y<<" "<<z<<endl;

#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define deb3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl
#define deba(a) for(auto &x:a) cout<<x<<" ";

#define sd(x) cin >> x;
#define sd2(x,y) cin >> x >> y;
#define sd3(x,y,z) cin >> x >> y >> z;
#define sd4(w,x,y,z) cin >> w >> x >> y >> z;

bool is_pal(string s) {return equal(all(s), s.rbegin());}

int fxp(int a, int b ,int p){       //(logn) fast exponentiation
    int res = 1;            		// call int x = fxp(2,5);
    while (b > 0) {
        if (b & 1)
            res = (res * a)%p;
        a = (a * a)%p;
        b >>= 1;
    }
    return (res%p);
}

void solve(){
	int n; cin >> n;
	int a[n]; for(int i=0 ; i<n ; ++i) cin >> a[i];
	int ans=0;
	int mx = a[0];
	for(int i=0 ; i<n ; ++i){
		if(a[i] < mx){
			ans+=(mx-a[i]);
		}
		if(a[i] > mx)
			mx = a[i];
	}
	cout << ans << endl;
}

int32_t main(){	
	__;
	file();
	solve();
	return 0;
}







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

int main(){
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int ans = 0;
    for (int a = 0; a <= A; ++a){
        for (int b = 0; b <= B; ++b){
            for (int c = 0; c <= C; ++c){
                if(500*a + 100*b + 50*c == X){
                    ++ans;
                }
            }
        }
    } 
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int curr = a[0];
        int index = 1;
        long profit = 1000;
        int buyPrice = 0;
        long buyCount = 0;
        while (index < n) {
            while (index < n && curr >= a[index]) {
                curr = a[index++];
            }
            buyCount = profit / curr;
            buyPrice = curr;
            while (index < n && curr <= a[index]) {
                curr = a[index++];
            }
            profit += ((curr - buyPrice) * buyCount);
        }
        System.out.println(profit);
    }
}


Measured memory_bytes: 27228
n = gets.to_i
s = gets.chomp
t = gets.chomp

overlapped = 0

1.upto(n) do |i|
  sub_s = s.reverse[0, i].reverse
  sub_t = t[0, i]
  overlapped = i if sub_s == sub_t
end

puts 2 * n - overlapped

Measured memory_bytes: 1788
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 105;
const int mod = 1000000007;



int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n,m;
  cin>>n>>m;
  int ret = 0;
  while(n){
    ret++;
    n/=m;
  }
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  int k, a, b;
  cin >> k >> a >> b;
  int i=1;
  int cnt=0;
  while(k*i<=b) {
    if(a<=k*i&&k*i<=b) {
      cout << "OK" << endl;
      cnt++;
      break;
    }
    i++;
  }
  if (cnt==0) cout << "NG" << endl;
}

Measured memory_bytes: 3620
N = int(input())
nums = list(map(int, input().split()))
ans = [0] * N

for i in reversed(range(1,N+1)):
    count = 0
    total = 0
    # 倍数
    for j in range(i, N+1, i):
        count += 1
        total += ans[j-1]
    # 倍数が一つのとき
    if count == 1:
        if nums[i-1] == 0:
            ans[i-1] = 0
        else:
            ans[i-1] = 1
    # 倍数が複数ある
    else:
        # 指定が偶数
        if nums[i-1] == 0:
            if total % 2 != 0:
                ans[i-1] = 1
        else:
            if total % 2 == 0:
                ans[i-1] = 1


# 出力フォーマット処理
result = [i+1 for i in range(len(ans)) if ans[i] == 1]
result = [str(i) for i in result]
print(len(result))
print(" ".join(result))

Measured memory_bytes: 19764
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[100100][3];
    for(int i=0;i<n;i++)
    {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }

    int dp[100100][3];

    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];

    for(int i=1;i<n;i++)
    {
        dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=a[i][2]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) << endl;
    return 0;
}

Measured memory_bytes: 2560
import math

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

for i in range(N):
  x, y = xy[i]
  lmin = 0
  lmax = 180
  rmin = 180
  rmax = 360
  for j in range(N):
    if i == j: continue
    p, q = xy[j][0] - x, xy[j][1] - y
    lt = math.degrees(math.atan2(q, p)) % 360
    rt = (lt + 180) % 360
    if lt > rt:
      rt, lt = lt, rt
      lmax = min(lmax, lt)
      rmin = max(rmin, rt)
    else:
      lmin = max(lmin, lt)
      rmax = min(rmax, rt)
  ans = 0
  if lmin < lmax:
    ans += (lmax - lmin) / 360
  if rmin < rmax:
    ans += (rmax - rmin) / 360
  print(ans)



Measured memory_bytes: 68692
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    int a[4]={0,0,0,0};
    for(int i=0;i<3;i++){
        int p,q;
        cin>>p>>q;
        a[p-1]++;
        a[q-1]++;
    }
    int one=0,two=0;
    for(int i=0;i<4;i++){
        if(a[i]==2)two++;
        if(a[i]==1)one++;
    }
    if(one==2 and two==2){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100005
#define maxn 	  200005
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int cost[maxn];
int dp[maxn];
int main()
{
	int n;
	cin >> n;
	for (int i=0 ; i<n ; i++) cin >> cost[i];
	dp[0] = 0;
	for (int i=1 ; i<n ; i++)
	{
		if(i==1) dp[i] = dp[i-1] + abs(cost[i] - cost[i-1]);
		else
		dp[i] = min(dp[i-1] + abs(cost[i] - cost[i-1]) , dp[i-2] + abs(cost[i] -  cost[i-2]));
	}
	cout << dp[n-1] << endl;
	return 0;
}


Measured memory_bytes: 4344
import sys
input = sys.stdin.readline
from collections import deque
def main():
    n,q = map(int,input().split())
    node = [[]for _ in range(n)]
    looked = [1]*n
    for i in range(n-1):
        a,b = map(int,input().split())
        node[b-1].append(a-1)
        node[a-1].append(b-1)
    counter = [0]*n
    for i in range(q):
        p,x = map(int,input().split())
        counter[p-1] += x
    queue = deque([0])
    looked[0] = 0
    while queue:
        now = queue.pop()
        for i in node[now]:
            if looked[i]:
                queue.append(i)
                counter[i] += counter[now]
                looked[i] = 0
    print(*counter)
main()

Measured memory_bytes: 93716
import sys

use_clipboard=True
bbn=1000000007
	
#+++++

class dd:
	def __init__(self, a_h):
		self.h=a_h

		
def main():
	h=int(input())
	ret = 0
	ec=1
	while h >= 1:
		ret += ec
		ec *= 2
		h = h // 2 
	print(ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
class input_clipboard:
	def __init__(self,s):
		self.input_l=s.splitlines()
		self.ii=0
		
	def input(self):
		ret = self.input_l[self.ii]
		self.ii+=1
		return ret

if __name__ == "__main__":
	if sys.platform =='ios':
		if use_clipboard:
			import clipboard
			input_text=clipboard.get()
			ic=input_clipboard(input_text)
			input = lambda : ic.input()
		else:
			sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int N;
vector<int> a;
int n1,n2,n4;

int main(){
    cin >> N;
    a.resize(N);
    rep(i,N){
        cin >> a[i];
        if(a[i]%4==0) n4++;
        else if(a[i]%2==0) n2++;
        else n1++;
    }

    int mae=4,now=0;

    if(n1>0) now=1;
    else if(n2>0) now=2;
    else now=4;

    if(now==1) n1--;
    else if(now==2) n2--;
    else if(now==4) n4--;

    for(int i=0;i<N-1;i++){
        if(now == 1){
            if(n4==0){
                cout << "No" << endl;
                return 0;
            }else{
                n4--;
                now = 4;
            }
        }else if(now==2){
            if(n2 > 0){
                n2--;
                now = 2;
            }else if(n4 > 0){
                n4--;
                now = 4;
            }else{
                cout << "No" << endl;
                return 0;
            }
        }else if(now==4){
            if(n1 > 0){
                n1--;
                now = 1;
            }else if(n2 > 0){
                n2--;
                now = 2;
            }
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 640
import math
 
a, b, x = map(int, input().split())
if x > a**2*b/2:
  degree = math.degrees(math.atan2(2*a**2*b-2*x, a**3))
  print(degree)
else:
  degree = math.atan2(a*(b**2),2*x)
  print(math.degrees(degree))

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<cstdio>
#include<iomanip>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int INF = 1e9 + 7;
int main() {
	int N;
	int h[110];
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> h[i];
	}
	int ans = 0;
	while (true) {
		int l, r;
		bool can = false;
		for (int i = 0; i < N; ++i) {
			if (h[i] != 0) {
				l = i;
				can = true;
				break;
			}
		}
		for (int i = l; i < N; ++i) {
			if (i == N - 1)r = N - 1;
			else {
				if (h[i + 1] == 0) {
					r = i;
					break;
				}
			}
		}
		for (int i = l; i <= r; ++i) {
			h[i]--;
		}
		if (!can)break;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
typedef pair<int , int > pii;
#define MOD 1000000007
#define MOD1 998244353
#define ff first
#define ss second
#define bn cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define sz(a) int((a).size())
#define o(a) cout << a
#define MAX6 1000006
#define int ll
#define all(x) x.begin(), x.end()
#define ppii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define viii vector<ppii>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define endl '\n'
#define MAX5 300005
#define MAX7 10000007
#define rep(i,a,b)  for (__typeof((b)) i=(a);i<=(b);i++)
#define nrep(i,b,a)  for (__typeof((b)) i=(b);i>=(a);i--)
#define mem(a) memset(a,0,sizeof(a))
#define memneg(a) memset(a,-1,sizeof(a))
//#define se second
#define LN 14
#define LIM 22
#define MAX_ALPHA 26
const long long INF64 = 1e18;
const ll INF = 1e9;
const double PI = acos(-1);
#define ld long double
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
inline void max_self(ll &a, ll b)
{
  a = max(a,b);
}
 
inline void min_self(ll &a,ll b)
{
  a = min(a,b);
}
 
inline void add_self(ll &a, ll b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
 
inline void sub_self(ll &a, ll b) {
  a -= b;
  if (a < 0) a += MOD;
}
 
inline int mul(int a, int b) {
  return (int) ((long long) a * b % MOD);
}
 
 
ll gcd(ll a,ll b)
{
  if(b == 0)
    return a;
  else 
    return gcd(b, a%b);
}
 
 
int countDigits(int x)
{
  int cnt = 0;
  while(x)
  {
    x /= 10;
    cnt++;
  }
  return cnt;
}
 
 
ll binExpo(ll a,ll b)
{
  ll res = 1;
  while(b)
  {
    if(b&1)
      res = (res * a)%MOD;
    a = (a * a)%MOD;
    b /= 2;
  }
  return res%MOD;
}
 
int sum(int a) {
    int result = 0;
    while (a > 0) {
        result += a % 10;
        a /= 10;
    }
    return result;
}



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

  int h,w;
  cin>>h>>w;
  vector<string > mat;
  rep(i, 0, h-1)
  {
    string x;
    cin>>x;
    mat.pb(x);
  }
  vector<vector<int > > dp(h + 1, vector<int > (w + 1));
  dp[0][0] = 1;
  rep(row, 0, h-1)
  {
    rep(col, 0, w-1)
    {
      for(auto r2 : {row, row + 1})
      {
        int c2 = col;
        if(r2 == row)
        {
          c2 = col + 1;
        }
        if(r2 < h and c2 < w and mat[r2][c2] == '.')
          add_self(dp[r2][c2], dp[row][col]);
      }
    }
  }
  cout<<dp[h-1][w-1]<<endl;

  return 0;
}

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

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

  for (int i = S.size() - 1; i > 0; i--) {
    if (i % 2 == 0 && S.substr(0, i / 2) == S.substr(i / 2, i / 2)) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
N,A,B = map(int, input().split())
if A % 2 == B % 2:
    print((B-A) // 2)
else:
    x = min(B - 1, N - A)
    y = 1 + min(A - 1, N - B) + (B - A) // 2
    print(min(x, y))


Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
#define int long long int
pair<int,int> stu[55];
pair<int,int> checkp[55];
int dist(pair<int,int>a,pair<int,int>b){
	return abs(a.first-b.first)+abs(a.second-b.second);
}
int32_t main(){
	int n,m;cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>stu[i].first>>stu[i].second;
	}
	for(int i=1;i<=m;i++){
		cin>>checkp[i].first>>checkp[i].second;
	}
	for(int i=1;i<=n;i++){
		int mn=1e13,mni=0;
		for(int j=1;j<=m;j++){
			if(dist(stu[i],checkp[j])<mn){
				mn=dist(stu[i],checkp[j]);
				mni=j;
			}
		}
		cout<<mni<<"\n";
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define speed ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);

int main()
{
    speed;

    int n,x,t;
    cin>>n>>x>>t;

    int ans=(n/x);

    if(n%x!=0) ans+=1;

    cout<<ans*t<<"\n";
}

Measured memory_bytes: 3608
#include<cstdio>
int n, m;
int deg[100100];
int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		deg[u]++; deg[v]++;
	}
	bool flag = false;
	for (int i = 1; i <= n; i++)
	{
		if (deg[i] & 1) { flag = true; break; }
	}
	if (flag) printf("NO\n");
	else printf("YES\n");
	return 0;
}


Measured memory_bytes: 640
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    grid = []
    for _ in range(3):
        grid.append(LI())
    
    ans = True
    l1 = grid[0][1] - grid[0][0]
    l2 = grid[0][2] - grid[0][1]
    ans &= grid[1][1] - grid[1][0] == l1 and grid[1][2] - grid[1][1] == l2
    ans &= grid[2][1] - grid[2][0] == l1 and grid[2][2] - grid[2][1] == l2

    r1 = grid[1][0] - grid[0][0]
    r2 = grid[1][0] - grid[0][0]
    ans &= grid[1][1] - grid[0][1] == r1 and grid[1][1] - grid[0][1] == r2
    ans &= grid[1][2] - grid[0][2] == r1 and grid[1][2] - grid[0][2] == r2
    print("Yes" if ans else "No")
main()            


Measured memory_bytes: 74308
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n,c,k;
    cin>>n>>c>>k;
    
    vector<int> t(n);
    rep(i,n)cin>>t[i];
    
    sort(all(t));
    
    queue<int> que;
    rep(i,t.size())que.push(2*t[i]);
    
    
    
    int ans = 0;
    while(que.size()){
        int t = que.front() + (2*k+1);
        
        rep(i,c){
            if(que.size() && que.front()<=t)que.pop();
            else break;
        }
        ans++;
    }
    
    cout<<ans<<endl;
}


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

int n,ac,wa,tle,re;
string s;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    while(n--){
        cin>>s;
        
        if (s=="AC") ac++;
        else if (s=="WA") wa++;
        else if (s=="TLE") tle++;
        else re++;
    }
    
    cout<<"AC x "<<ac<<"\n";
    cout<<"WA x "<<wa<<"\n";
    cout<<"TLE x "<<tle<<"\n";
    cout<<"RE x "<<re<<"\n";
    
    
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<string>
using namespace std;
int main() {
	int N, L,a,b;
	cin >> N >> L;
	a = L + N - 1;
	if (a <= 0) {
		b = a;
	}
	else if (L >= 0) {
		b = L;
	}
	else {
		b = 0;
	}
	int ans = (L + a) * N / 2 - b;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
// const ll MOD = 1e9 + 7;
const ll MOD = 998244353;

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








int main(){
    ll n, k;
    string s;
    cin >> n >> s >> k;
    k--;
    REP(i, n){
        if(s[i] != s[k]){
            s[i] = '*';
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 256