akhauriyash/Code-Regression huggingface dataset:
w,h,n=map(int,input().split())
xya = [list(map(int, input().split())) for _ in range(n)]
wl,wr,hu,ht=0,w,0,h
for i in range(n):
    if xya[i][2]==1:
        wl=max(wl,int(xya[i][0]))
    elif xya[i][2]==2:
        wr=min(wr,int(xya[i][0]))
    elif xya[i][2]==3:
        hu=max(hu,int(xya[i][1]))
    elif xya[i][2]==4:
        ht=min(ht,int(xya[i][1]))
    else:pass
if wl>wr or hu>ht:print(0)
else:print((wr-wl)*(ht-hu))


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    string s;
    cin >> s;
    int n = s.length();
    vector<vector<int>> pos(26);
    for(int i = 0; i < n; ++i){
        pos[s[i] - 'a'].emplace_back(i);
    }
    for(int i = 0; i < 26; ++i){
        if(!pos[i].size()){
            cout << (char)(i + 'a') << endl;
            return 0;
        }
        pos[i].emplace_back(n);
    }

    vector<int> dp(n + 1, INF);
    dp[n] = 0;
    auto MemoRec = [&](auto&& self, int cur_pos = 0) -> int {
        if(dp[cur_pos] != INF)  return dp[cur_pos];
        int res = INF;
        for(int i = 0; i < 26; ++i){
            int nxt_pos = *upper_bound(pos[i].begin(), pos[i].end(), cur_pos);
            chmin(res, self(self, nxt_pos));
        }
        return dp[cur_pos] = res + 1;
    };
    MemoRec(MemoRec);

    int len = INF;
    int cur_pos = -1;
    int idx = 0;
    for(int i = 0; i < 26; ++i){
        if(chmin(len, dp[pos[i][0]])){
            cur_pos = pos[i][0];
            idx = i;
        }
    }
    string ans = string(1, (char)(idx + 'a'));
    while(len > 0){
        for(int i = 0; i < 26; ++i){
            int nxt_pos = *upper_bound(pos[i].begin(), pos[i].end(), cur_pos);
            if(dp[nxt_pos] == len - 1){
                ans += (char)(i + 'a');
                --len;
                cur_pos = nxt_pos;
                break;
            }
        }
    }
    cout << ans << endl;
}

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define fork(i, n) for (ll i = 0; i < (n); i++)
#define forn for (ll i = 0; i < (n); i++)
#define fori(i, k, n) for (ll i = k; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}
template <typename T>
void print(vector<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(deque<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(vector<vector<T>> &a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

int main()
{
	fast;
	int n, k;
	cin >> n >> k;
	ll ans = 0;
	vi a(n);
	forn
	{
		cin >> a[i];
	}
	nth_element(a.begin(), a.begin() + k, a.end());
	fork(i, k) ans += a[i];
	cout << ans << en;
}

Measured memory_bytes: 3660
# AGC 004: A – Divide a Cuboid
a, b, c = [int(s) for s in input().split()]
sides = [a, b, c]

sides.sort()

if sides[0] % 2 == 0 or sides[1] % 2 == 0 or sides[2] % 2== 0:
    print(0)
else:
    print(sides[0] * sides[1])

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int h, w;
  cin >> h >> w;
  
  vector<vector<int>> a(h, vector<int>(w));
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> a.at(i).at(j);
    }
  }
  int b;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> b;
      a.at(i).at(j) = abs(a.at(i).at(j) - b);
    }
  }
  
  bool dp[h][w][13000];
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      for(int k = 0; k < 13000; k++){
        dp[i][j][k] = false;
      }
    }
  }
  
  dp[0][0][a.at(0).at(0)] = true;
  for(int i = 1; i < w; i++){
    for(int j = 0; j < 13000; j++){
      if(dp[0][i - 1][j] == true){
        dp[0][i][j + a.at(0).at(i)] = true;
        dp[0][i][abs(j - a.at(0).at(i))] = true;
      }
    }
  }
  
  for(int i = 1; i < h; i++){
    for(int j = 0; j < 13000; j++){
      if(dp[i - 1][0][j] == true){
        dp[i][0][j + a.at(i).at(0)] = true;
        dp[i][0][abs(j - a.at(i).at(0))] = true;
      }
    }
  }
  
  for(int i = 1; i < h; i++){
    for(int j = 1; j < w; j++){
      for(int k = 0; k < 13000; k++){
        if(dp[i - 1][j][k] == true){
          dp[i][j][k + a.at(i).at(j)] = true;
          dp[i][j][abs(k - a.at(i).at(j))] = true;
        }
        if(dp[i][j - 1][k] == true){
          dp[i][j][k + a.at(i).at(j)] = true;
          dp[i][j][abs(k - a.at(i).at(j))] = true;
        }
      }
    }
  }
  
  for(int i = 0; i < 13000; i++){
    if(dp[h - 1][w - 1][i] == true){
      cout << i << "\n";
      return 0;
    }
  }
}

Measured memory_bytes: 81536
n = int(input())
a_li = list(map(int,input().split()))
b_li = list(map(int,input().split()))
all_li = []
for i,a in enumerate(a_li):
    x = sum(a_li[:i+1])
    y = sum(b_li[i:])
    all_li.append(x+y)
print(max(all_li))

Measured memory_bytes: 38512
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
bool all_equal(const string &s, char ch) {
    for (auto c : s) if (c != ch) return false;
    return true;
}
int f(const string &s) {
    int ans = 0;
    string t = s;
    for (int i = 1; i < t.size(); i++) {
        if (t[i - 1] == t[i]) {
            t[i] = '@';
            ans++;
        }
    }
    return ans;
}
int main() {
    string S; cin >> S;
    Int K; cin >> K;
    if (all_equal(S, S.front())) {
        cout << (S.size() * K) / 2 << endl;
    } else if (K <= 10) {
        string s1;
        for (int i = 0; i < K; i++) s1 += S;
        cout << f(s1) << endl;
    } else {
        string s1, s2, s3, prefix;
        s1 = s2 = s3 = S;
        while (s1.back() == S.front()) {
            s1.pop_back();
            s2.pop_back();
            prefix += S.front();
        }
        s2 = prefix + s2;
        s3 = prefix + s3;
        cout << f(s1) + f(s2) * (K - 2) + f(s3) << endl;
    }
    return 0;
}


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

typedef long long ll;
ll MOD = 1e9+7;

pair<int,int> odd[100001];
pair<int,int> even[100001];
int v[100000];

int main()
{
	int n;
	int ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	for(int i=0;i<100001;i++)
	{
		odd[i]=make_pair(0,i);
		even[i]=make_pair(0,i);
	}
	for(int i=0;i<n;i+=2)
	{
		odd[v[i]].first++;
	}
	for(int i=1;i<n;i+=2)
		even[v[i]].first++;
	sort(odd,odd+100001);
	reverse(odd,odd+100001);
	sort(even,even+100001);
	reverse(even,even+100001);
	if(odd[0].second==even[0].second)
	{
		ans=min(n-odd[1].first-even[0].first,n-odd[0].first-even[1].first);
	}else{
		ans=n-odd[0].first-even[0].first;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2176
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, input().split())
lst = list(range(N + 1))

MOD = 10 ** 9 + 7

small = 0
for i in range(K-1):
    small += lst[i]

big = 0
for i in range(1, K):
    big += lst[-i]

ans = 0
for i in range(K, N + 2):
    small += lst[i - 1]
    big += lst[-i]

    ans += big - small + 1
    ans %= MOD


print(ans % MOD)


Measured memory_bytes: 16716
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>

using namespace std;
/*
int find(int x, vector<int> &p) {
if (p[x] == x)return x;
return p[x] = find(p[x], p);
}

void uni(int x, int y, vector<int> &p) {
x = find(x, p);
y = find(y, p);
p[x] = y;
}

int same(int x, int y, vector<int> p) {
if (find(x, p) == find(y, p))return 1;
return 0;
}
*/

//long long a[1002];


int main()
{
	long long A, B, cnt = 0, tmp, ans = 0;
	cin >> A >> B;

	if (B%A == 0) {
		cout << A + B;
	}
	else {
		cout << B - A;
	}

	char qq;
	cin >> qq;
	return 0;
}

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

string s;
void r (string t,int n){
  if(s==t)
    cout<<n;
}

int main(){
  cin>>s;
  r("SUN",7);
  r("MON",6);
  r("TUE",5);
  r("WED",4);
  r("THU",3);
  r("FRI",2);
  r("SAT",1);
}
  



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

namespace ProblemB
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var Ws = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            var ret = int.MaxValue;
            for (int i = 1; i < N; i++)
            {
                var S1 = Ws.GetRange(0, i).Sum();
                var S2 = Ws.GetRange(i, N - i).Sum();
                var temp = Math.Abs(S1 - S2);
                if (temp < ret)
                    ret = temp;
            }
            Console.WriteLine(ret);
        }
    }
}


Measured memory_bytes: 13268
import math
a, b, h, m = [int(x) for x in input().split(' ')]

arc_h = 2 * math.pi * ((h + m / 60) / 12)
arc_m = 2 * math.pi * (m/60)
dx = a * math.cos(arc_h) - b * math.cos(arc_m)
dy = a * math.sin(arc_h) - b * math.sin(arc_m)
d = math.sqrt(dx ** 2 + dy ** 2)
print(d)

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

ll A, B;

ll f(ll x){
    if(x < 0){
        return 0;
    }

    ll y = x >> 1, z = x & 1;
    return y * 2 * !(x & 1) + ((y + z) & 1);
}

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

    std::cin >> A >> B;

    ll res = f(A - 1) ^ f(B);
    std::cout << res << std::endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var atof = Input.ar;
         var d= (100 * (double)atof[4] / (100 + atof[4]));
        var max = 0d;
        var pa = new Pair(0, 0);
        var wat = new List<int>();
        var sug = new List<int>();
        for(var i = 0; i <= atof[5]; i++)
            for(var j = 0; j <= atof[5]; j++)
            {if (i == 0 && j == 0) continue;
                var val = 100 * i * atof[0] + 100 * j * atof[1];
                if (val <= atof[5]) wat.Add(val);
                val = i * atof[2] + j * atof[3];
                if (val <= atof[5]) sug.Add(val);
            }
        wat = wat.Distinct().ToList();
        sug = sug.Distinct().ToList();
        for(var i=0;i<wat.Count;i++)
            for(var j = 0; j < sug.Count; j++)
            {
                if (wat[i] + sug[j] > atof[5]) continue;
                var val = 100 * (double)sug[j] / (wat[i] + sug[j]);
                if (val <= d && val > max)
                {
                    max = val;
                    pa = new Pair(wat[i], sug[j]);
                }
            }
        if (pa.Item1 == 0)
            pa = new Pair(atof[0] * 100, pa.Item2);
        WriteLine($"{pa.Item1+pa.Item2} {pa.Item2}");
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static string[] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read).ToArray();
    public static int[][] twodim(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] twodimL(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-11;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 13792
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int,int> P;
struct edge{int to,cost;};

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

string field[60];
int d[30][30];
int main(){
    int W,H;
    while(cin >> W >> H, W){
        for(int i=0;i<2*H-1;i++){
            string line;
            getline(cin, line);
            if(line.size()==0){
                i--;
                continue;
            }
            if(line.size()<2*W-1){
                line.push_back(' ');
            }
            field[i] = line;
        }

        for(int i=0;i<H;i++)for(int j=0;j<W;j++)d[i][j] = INF;
        d[0][0] = 1;
        queue<P> que;
        que.push(P(0, 0));
        while(que.size()){
            P p = que.front(); que.pop();
            int y = p.first, x = p.second;
            if(y==H-1&&x==W-1){
                break;
            }
            for(int i=0;i<4;i++){
                int ny = y + dy[i], nx = x + dx[i];
                if(ny<0||H<=ny||nx<0||W<=nx)continue;
                if(field[2*y+dy[i]][2*x+dx[i]]=='0' && d[ny][nx] > d[y][x]+1){
                    d[ny][nx] = d[y][x]+1;
                    que.push(P(ny, nx));
                }
            }
        }
        if(d[H-1][W-1]==INF) cout << 0 << endl;
        else cout << d[H-1][W-1] << endl;
    }

    return 0;
}

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  string ans;
  while (true) {
    c -= b;
    if (c<=0) {
      ans = "Yes";
      break;
    }
    a -= d;
    if (a <=0) {
      ans = "No";
      break;
    }
  }
  
  cout << ans; 
    
}


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

ans = N + X
for n in range(N):
    ans += len(list(filter(lambda x: x <= D, [i*A[n] + 1for i in range(1, D+1)])))
print(ans)


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

int main() {
  int A,B;
  cin>>A>>B;
  if (3*A+B % 2== 1){
  cout<<(3*A+B-1)/2<<endl;
    }
  else {
    cout<<(3*A+B)/2<<endl;
  }
  }

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

using namespace std;
using ll = long long;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  ll GCD;
  for (int i = 0; i < n; ++i)
  {
    cin >> a[i];
    if (i)
    {
      GCD = gcd(GCD, a[i]);
    }
    else
    {
      GCD = a[i];
    }
  }
  cout << GCD << endl;
}

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

int main(){
  int K;
  cin >> K;
  int sum=0;
  
  for(int a=1;a<=K;a++){
    for(int b=1;b<=K;b++){
      for(int c=1;c<=K;c++){
        for(int d=(min(min(a,b),c));d>=1;d--){
          if(a%d==0 && b%d==0 && c%d==0){
            sum+=d;
            break;
          }
        }
      }
    }
  }
  
  cout << sum << endl;
}


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

namespace IO {
	const int maxn((1 << 21) + 1);

	char ibuf[maxn], *iS, *iT, c;
	int f;

	inline char Getc() {
		return iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, maxn, stdin), iS == iT ? EOF : *iS++) : *iS++;
	}

	template <class Int> inline void In(Int &x) {
		for (f = 1, c = Getc(); c < '0' || c > '9'; c = Getc()) f = c == '-' ? -1 : 1;
		for (x = 0; c >= '0' && c <= '9'; c = Getc()) x = (x << 1) + (x << 3) + (c ^ 48);
		x *= f;
	}
}

using IO :: In;

int n, l, bit;

struct Info {
	int u, v, w;
};

vector <Info> ans;

inline void Add(int u, int v, int w) {
	ans.push_back((Info){u, v, w});
}

int main() {
	In(l);
	for (bit = 1; bit <= l; bit <<= 1) ++n;
	for (int i = 1; i < n; ++i) Add(i, i + 1, 0), Add(i, i + 1, 1 << (n - i - 1));
	for (int i = n, s = 0; ~i; --i)
		if ((l >> i) & 1) {
			if (s) Add(1, n - i, s);
			s += 1 << i;
		}
	printf("%d %d\n", n, l = ans.size());
	for (int i = 0; i < l; ++i) printf("%d %d %d\n", ans[i].u, ans[i].v, ans[i].w);
	return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::Chars;
use permutohedron::LexicalPermutation;

#[fastout]
fn main() {
    input! {
        mut s: Chars,
    }

    if s.len() < 26 {
        let unused = (b'a'..=b'z').map(char::from).filter(|c| !s.contains(c)).collect::<Vec<_>>();
        let add = unused[0];
        
        s.push(add);
        let ans = s.iter().collect::<String>();
        println!("{}", ans);
        return;
    }

    let mut next_s = s.clone();
    let has_next = next_s.next_permutation();

    if !has_next {
        println!("-1");
        return;
    }

    let mut ans = vec![];

    for (n, o) in next_s.iter().zip(s.iter()) {
        ans.push(n);
        if n != o {
            break;
        }
    }
    let ans = ans.into_iter().collect::<String>();
    println!("{}", ans);
}

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


using namespace std;

int main(){
    string s;
    cin >> s;
    if(s[0]=='A')cout << 'T' << endl; 
    if(s[0]=='T')cout << 'A' << endl; 
    if(s[0]=='C')cout << 'G' << endl; 
    if(s[0]=='G')cout << 'C' << endl; 
}


Measured memory_bytes: 256
N, M=map(int, input().split())
X=list(map(int, input().split()))
X.sort()
if N>=M:
  print(0)
else:
  dif=[]
  for i in range(M-1):
    dif.append(X[i+1]-X[i])
  dif.sort(reverse=True)
  ans=sum(dif[N-1:])
  print(ans)

Measured memory_bytes: 13960
//                                      KiSmAt
#include "bits/stdc++.h"
using namespace std;
 
using ll = long long;
 
const ll inf = 1e18;
const int N = 2 * 1e5 + 10;

ll res;
ll a[N], b[N];
ll dp[N][109];

void solve(){
	ll n, W;
	cin >> n >> W;
	for(int i = 1; i <= n; ++i){
		cin >> a[i] >> b[i];
	}
	for(int i = 1; i < N; ++i){
		for(int j = 0; j <= n; ++j){
			dp[i][j] = inf;
		}
	}
	for(int i = 1; i < N; ++i){
		for(int j = 1; j <= n; ++j){
			dp[i][j] = dp[i][j - 1];
			if(b[j] <= i)	dp[i][j] = min(dp[i][j], a[j] + dp[i - b[j]][j - 1]);
		}
	}
	for(int i = 0; i < N; ++i){
		if(dp[i][n] <= W)	res = max((ll)i, res);
	}
	cout << res;
}
 
int main(int argc, char const *argv[]){
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
    	solve();
    }
}
// nEro

Measured memory_bytes: 172288
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define ld long double
#define pii pair<int,int>
#define fi first
#define se second
#define mex 1000005
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
vector<int> adj[mex];
		
int main(){
	int n;
	cin>>n;
	int y=n%10;
	if(y==2 || y==4||y==5||y==7||y==9)
	 cout<<"hon\n";
	else if(y==3)
	 cout<<"bon";
	else
	 cout<<"pon"; 
}



Measured memory_bytes: 27056
#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <stack>

using namespace std;

int main() {
  string tmp;
  while (getline(cin, tmp)) {
    stringstream ss(tmp);

    string str;
    stack<double> s;
    while (ss >> str) {
      if (any_of(str.cbegin(), str.cend(),
                 [](char ch) { return isdigit(ch); })) {
        s.push(stoi(str));
      } else {
        double b = s.top();
        s.pop();
        double a = s.top();
        s.pop();

        switch (str[0]) {
        case '+':
          s.push(a + b);
          break;
        case '-':
          s.push(a - b);
          break;
        case '*':
          s.push(a * b);
          break;
        case '/':
          s.push(a / b);
          break;
        }
      }
    }
    cout << fixed << setprecision(5) << s.top() << endl;
  }
}


Measured memory_bytes: 3216
#include<cstdio>
int n,a[100001],b[100001],m,d[100001];
bool ok;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i)scanf("%d%d",a+i,b+i),d[a[i]]++,d[b[i]]++;
	for(int i=1;i<=n;++i)if(d[i]&1){puts("NO");return 0;}
	puts("YES");
	return 0;
}

Measured memory_bytes: 1280
#include<algorithm>
#include<iostream>
using namespace std;
const int MAX = 200000;
int main() 
{
	int n,i,j;
	int r[MAX];
	cin >> n ; 
	for (i = 0 ; i < n ; i++) 
	{
		cin >> r[i];
	}
	int maxv = -2000000000;
	int minv = r[0];
	for (i = 1 ; i < n ; i++)
	{
		maxv = max(maxv , r[i]-minv) ;
		minv = min(minv , r[i]);
	} 
	cout << maxv << endl;
	return 0;
}


Measured memory_bytes: 3900
import sys
import math
from fractions import gcd

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

a, b = map(int, input().split())
g = gcd(a, b) # gは最大公約数
if g == 1:
    print(1)
    sys.exit()

li = [1]
true_li = make_divisors(g)
#print(true_li)

for i in true_li:
    if i == 1:
        continue
    count = 0
    for l in li:
        if gcd(l,i) != 1:
            count += 1
    if count == 0:
        li.append(i)
print(len(li))


Measured memory_bytes: 5212
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  for(int i=0; i<s.size(); i++){
    if(i % 2 == 0){
      if(s[i]=='L') {
        cout << "No" << endl;
        return 0;
      }
    }
    else {
      if(s[i]=='R') {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc044/tasks/abc044_a
N = int(input())
K = int(input())
X = int(input())
Y = int(input())


def totalPrice(N, K, X, Y):
    total = 0
    for i in range(1, N + 1):
        if i <= K:
            total += X
        else:
            total += Y
    return total

print(totalPrice(N, K, X, Y))

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

const int MAX_N = 100000;

int main(){
    int n;
    int ans=0;
    int a,b;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a >> b;
        ans += b-a+1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int h, w;
	char mp[505][505];

	scanf("%d %d", &h, &w);
	for (int i = 0; i < h; i++) {
		scanf("%s", mp[i]);
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if ((!(i & 1) || j == 0 || mp[i][j] == '#') && j != w - 1) {
				putchar('#');
			} else {
				putchar('.');
			}
		}
		putchar('\n');
	}

	putchar('\n');

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if ((i & 1 || j == w - 1 || mp[i][j] == '#') && j != 0) {
				putchar('#');
			} else {
				putchar('.');
			}
		}
		putchar('\n');
	}

	return 0;
}


Measured memory_bytes: 896
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <regex>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1000000007;

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//myfuncs
//素数判定
template<class T> inline T isPrime(T x) {
	bool ret = true;
	if (x < 2) {
		ret = false;
	}
	for (LL i = 2; i <= sqrt(x); i++) {
		if (x%i == 0) {
			ret = false;
		}
	}
	return ret;
}

//Union FInd
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//main code

int main(int argc, char const* argv[])
{
	string s;
	cin >> s;
	int ans = 0;
	char now = 'n';
	for (int i = 1; i < s.size(); i++) {
		if (s[i] != s[i-1]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
using namespace std;


int main(){
	char w1[7][7],w2[7][7],dir;
	int x=1,y=1;
	for(int i=0;i<7;i++){
		for(int j=0;j<7;j++){
			w1[i][j] = '0';
			w2[i][j] = '0';
		}
	}
	fgets(w1[1],7,stdin);
	fgets(w2[1],7,stdin);
	fgets(w1[2],7,stdin);
	fgets(w2[2],7,stdin);
	fgets(w1[3],7,stdin);
	fgets(w2[3],7,stdin);
	fgets(w1[4],7,stdin);
	fgets(w2[4],7,stdin);
	fgets(w1[5],7,stdin);
	
	for(int i=5;i>=0;i--){
		w1[1][i+1]=w1[1][i];
		w2[1][i+1]=w2[1][i];
		w1[2][i+1]=w1[2][i];
		w2[2][i+1]=w2[2][i];
		w1[3][i+1]=w1[3][i];
		w2[3][i+1]=w2[3][i];
		w1[4][i+1]=w1[4][i];
		w2[4][i+1]=w2[4][i];
		w1[5][i+1]=w1[5][i];
	}
	w1[1][0]='0';
	w2[1][0]='0';
	w1[2][0]='0';
	w2[2][0]='0';
	w1[3][0]='0';
	w2[3][0]='0';
	w1[4][0]='0';
	w2[4][0]='0';
	w1[5][0]='0';/*
	for(int i=0;i<7;i++){
		for(int j=0;j<7;j++){
			if(w1[i][j]=='1') printf("+-");
			else printf("+ ");
		}
		printf("+\n");
		for(int j=0;j<7;j++){
			if(w2[i][j]=='1') printf("| ");
			else printf("  ");
		}
		
		printf("\n");
	}*/
	printf("R");
	dir = 'R';
	while(1){
		if(dir=='R'){
			if(w2[x-1][y+1]=='1'){
				dir = 'U';
				x = x-1;
				y = y+1;
			}
			else if(w1[x][y+1]=='1'){
				dir = 'R';
				x = x;
				y = y+1;
			}
			else if(w2[x][y+1]=='1'){
				dir = 'D';
				x = x;
				y = y+1;
			}
			else {
				dir = 'L';
				x = x;
				y = y;
			}
		}
		else if(dir=='L'){
			if(w2[x][y]=='1'){
				dir = 'D';
				x = x;
				y = y;
			}
			else if(w1[x][y-1]=='1'){
				dir = 'L';
				x = x;
				y = y-1;
			}
			else if(w2[x-1][y]=='1'){
				dir = 'U';
				x = x-1;
				y = y;
			}
			else {
				dir = 'R';
				x = x;
				y = y;
			}
		}
		else if(dir=='U'){
			if(w1[x][y-1]=='1'){
				dir = 'L';
				x = x;
				y = y-1;
			}
			else if(w2[x-1][y]=='1'){
				dir = 'U';
				x = x-1;
				y = y;
			}
			else if(w1[x][y]=='1'){
				dir = 'R';
				x = x;
				y = y;
			}
			else {
				dir = 'D';
				x = x;
				y = y;
			}
		}
		
		else if(dir=='D'){
			if(w1[x+1][y]=='1'){
				dir = 'R';
				x = x+1;
				y = y;
			}
			else if(w2[x+1][y]=='1'){
				dir = 'D';
				x = x+1;
				y = y;
			}
			else if(w1[x+1][y-1]=='1'){
				dir = 'L';
				x = x+1;
				y = y-1;
			}
			else {
				dir = 'U';
				x = x;
				y = y;
			}
		}
		printf("%c",dir);
		if(x==1&&y==1)break;
	}
	printf("\n");
	return 0;
}


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    ll n;
    cin>> n;

    ll a[n];



    for(ll i=0; i<n; i++)
        cin>> a[i];

    cout <<  *max_element(a, a+ n)- *min_element(a,a+n);
    nl;
    return 0;
}



Measured memory_bytes: 3668
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static long count = 0;
	public static long answer = 0;
	public static long dfs(final int limit, final int deep, int prev, long number) {
		if(deep >= limit) {
			if(number == 0) { return 0; }
			count--;
			if(count == 0) {
				answer = number;
			}
			return 1;
		}
		
		long ret = 0;
		if(deep == 0) {
			for(int digit = 1; digit <= 9; digit++) {
				ret += dfs(limit, deep + 1, digit, number * 10 + digit);
			}
		}else {
			for(int digit = Math.max(0, prev - 1); digit <= Math.min(9, prev + 1); digit++) {
				ret += dfs(limit, deep + 1, digit, number * 10 + digit);
			}
		}
		
		return ret;
	}
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int K = sc.nextInt();
			
			long rest = K;
			count = K;
			for(int limit = 1; ; limit++) {
				final long ret = dfs(limit, 0, -1, 0);
				if(rest <= ret) {
					break;
				}

				rest -= ret;
			}
			
			System.out.println(answer);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 21588
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
#define MAX_H 100
using namespace std;

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

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n, m;
  cin >> n >> m;
  string s[MAX_H];
  for(int i = 0; i < n; i++){
    cin >> s[i];
  }

  int c[26];
  fill(c, c + 26, 0);
  for(int i = 0; i < n; i++){
    for(char ch: s[i]){
      c[ch - 'a']++;
    }
  }

  int sum = 0;
  for(int i = 0; i < 26; i++){
    sum += c[i] / 4;
    c[i] -= 4 * (c[i] / 4);
  }

  int r = (n * m) - (sum * 4);

  if(r <= (m * (n % 2) + n * (m % 2))){
    int t = 0;
    for(int i = 0; i < 26; i++){
      t += c[i] % 2;
    }
    if(t == r % 2) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

int main()
{
    fastinput;
    LL n, i, j, k, t, temp, health;
    cin >> health >> n;
    LL a[n], b[n];
    for (i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
    }

    LL dp[health + 1];
    dp[0] = 0;
    for (i = 1; i <= health; i++)
    {
        dp[i] = 1000000000000000;
    }

    for (i = 0; i <= health; i++)
    {
        for (j = 0; j < n; j++)
        {

            dp[min(health, i + a[j])] = min(dp[min(health, i + a[j])], dp[i] + b[j]);
        }
    }
    cout << dp[health] << endl;

    return 0;
}


Measured memory_bytes: 384
N, M = tuple(map(int,input().split()))
A =[]
for i in range(M):
    A.append(tuple(map(int,input().split())))
prev = [0,0]
dic ={}
for city,year in sorted(A):
    if city != prev[0]:
        prev[1] = 1
    dic[(city,year)] = prev[1]
    prev = [city,prev[1]+1]
for i in A:
    print(str.zfill(str(i[0]),6)+str.zfill(str(dic[i]),6))
    


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

int main() {
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<unsigned long> A(N + 1), B(N);
    copy_n(istream_iterator<unsigned long>(cin), N + 1, A.begin());
    copy_n(istream_iterator<unsigned long>(cin), N, B.begin());
    unsigned long ans{0};
    for(unsigned long i = 0; i < N; ++i){
        auto k = min(A[i], B[i]);
        A[i] -= k;
        B[i] -= k;
        ans += k;
        k = min(A[i + 1], B[i]);
        A[i + 1] -= k;
        B[i] -= k;
        ans += k;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
char a[55][55],b[55][55];
bool ch(int m,int n){
	if (m<n)return 0;
	bool f=1;
	for (int i =1 ;i<=m-n+1;++i){
		for (int j =1;j<=m-n+1;++j){
			f=1;
			for (int ii=1;ii<=n;++ii){
				if (!f)break;
				for (int jj=1;jj<=n;++jj){
					if (a[i + ii -1][j + jj -1]!=b[ii][jj]){
					//	cout << i << " "<< j <<" "<<ii<<" "<<jj<<endl;
						f=0;
						break;
					}
				}
			}
			if (f)return 1;
		}
	}
	return 0;
}
int main(){
	int m,n;
	cin >> m >> n;
//	cout<<endl;
	for (int i = 1;i<=m;++i){
		for (int j=1;j<=m;++j){
			cin >> a[i][j];
		}
}
	for (int i =1;i<=n;++i){
		for (int j =1;j<=n;++j)
		cin >> b[i][j];
	}
	if (ch(m,n))puts("Yes");else puts("No");
	return 0;
}

Measured memory_bytes: 256
mn,dn=map(int,input().split(" "))
ne_zai=[]
for _ in range(mn):
    ne_zai.append(list(map(int,input().split(" "))))
ne_zai.sort()
kin=0
for i in range(mn):
    if ne_zai[i][1]<dn:
        kin+=ne_zai[i][0]*ne_zai[i][1]
        dn-=ne_zai[i][1]
    else:
        kin+=dn*ne_zai[i][0]
        break
print(kin)

Measured memory_bytes: 27760
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const ll MOD = 1000000007LL;
/*メモ XOR問題のまとめ
性質 1「交換則、結合則が成り立つ」
　　 2「a xor a = 0」
　　 3「ある数xのb番目のビットが1である <=> x mod 2^(b+1) ≧ 2^b」
　　 4「0≦aのとき、4a, 4a+1, 4a+2, 4a+3のxor和は0」
方針 
!!!!!1「xor計算は各ビットで独立なので別々に計算」
　　 2「trieを使ったxorの最大最小探索がある解説」
・しゃくとり法は[ｌ,r)で考えるとわかりやすいよ！
*/
int main(){
    int n,k;
    std::cin >> n>>k;
    VEC(int,a,n);
    std::cout << ceil(double(n-1)/(k-1)) << std::endl;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void){
	int a;
	char buf[128];
	fgets(buf, 127, stdin);
	sscanf(buf, "%d", &a);
	if(a > 0 && a < 1000){
		printf("%s\n", "ABC");
	} else if(a > 999 && a < 1999){
		printf("%s\n", "ABD");
	}
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    for (int i = 0; i < N; i++)
    {
        cin >> P.at(i);
    }
    for (int i = 0; i < N; i++)
    {
        cin >> Q.at(i);
    }

    int a, b, cnt = 0;
    vector<int> l(N);
    for (int i = 0; i < N; i++)
    {
        l.at(i) = i + 1;
    }
    do
    {
        if (l == P)
        {
            a = cnt;
        }
        if (l == Q)
        {
            b = cnt;
        }
        cnt++;
    } while (next_permutation(l.begin(), l.end()));
    cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
import scala.io.StdIn.readLine
import Math.sqrt

object Main {

  def main(args: Array[String]) = {
      val Array(a,b) = readLine.split(" ").map(_.toInt)
      print(a/b);print(" ");print(a%b);print(" ");println("%.5f".format(a.toDouble/b))
  }
}

Measured memory_bytes: 44176
import Foundation

let n = Int(readLine()!)!
var ai: [Int] = []
var ans = 0
var index = 0
for _ in 0..<n {
  ai.append(Int(readLine()!)!)
}
while true {
  ans += 1
  if ans > n || ai[index] == 2 {
    break
  }
  index = ai[index] - 1
}
print(ans > n ? -1 : ans)

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

int main(){
  int K, S;
  cin >> K >> S;
  int Ans;
  for(int x=0; x<=K; x++){
    for(int y=0; y<=K; y++){
      if(0<=S-x-y && S-x-y<=K){
        Ans++;
      } 
    }
  }
  cout << Ans << endl;
}
    

Measured memory_bytes: 256
from collections import Counter

N = int(input())
A = [int(i) for i in input().split()]

l = []
for i in A:
	l.extend([i-1, i, i+1])

count = Counter(l)
cand = sorted(count.most_common(), key=lambda x: x[1], reverse=True)[:3]
cand = list(filter(lambda x: cand[2][1]<=x[1], count.most_common()))
ans = 0
for tpl in cand:
    n = len(list(filter(lambda x: x == tpl[0] or x+1 == tpl[0] or x-1 == tpl[0], A)))
    ans = max(ans, n)

print(ans)


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

int main() {
  int n,j=1000000000;
  cin >> n;
  for (int i=0; i<n; i++) {
    int k=0,p;
    cin >> p;
    for (;; k++) {
      if (p%2==0) p/=2;
      else break;
    }
    if (j>k) j=k;
  }
  cout << j << endl;
}


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

int main() {
  long N, M;
  cin >> N >> M;
  if (N == 1 && M == 1) cout << 1 << endl;
  else if (N == 1) cout << M - 2 << endl;
  else if (M == 1) cout << N - 2 << endl;
  else cout << (N-2) * (M-2) << endl;
}

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

int bits[11];
const char *ptr;

vector<int> parse(){
	vector<int> ret(16);
	if(*ptr == '('){
		++ptr;
		vector<int> v1 = parse();
		++ptr;
		vector<int> v2 = parse();
		++ptr;

		for(int i = 0; i < 16; ++i)
		for(int j = 0; j < 16; ++j){
			int x = v1[i] * v2[j];
			ret[i & j] += x;
			ret[i | j] += x;
			ret[i ^ j] += x;
		}
	}
	else{
		char *endp;
		int k = strtol(ptr, &endp, 10);
		ptr = endp;
		ret[bits[k]] = 1;
	}
	return ret;
}

int main(){
	int num[16] = {};
	for(int i = 0; i < 15; ++i){
		for(int j = 0; j < 4; ++j){
			if(i >> j & 1) ++num[i];
		}
	}

	string s;
	int n, x;
	while(getline(cin, s), s[0] != 'E'){
		ptr = s.c_str();

		cin >> n;
		for(int i = 1; i <= n; ++i){
			int t = 0;
			for(int j = 0; j < 4; ++j){
				cin >> x;
				t = t << 1 | x;
			}
			bits[i] = t;
		}
		cin.ignore();

		vector<int> ret = parse();
		cout << ret[15] << '\n';
	}
}

Measured memory_bytes: 1212
#include <iostream>

using namespace std;


int main() {
	unsigned int s;
	cin >> s;
	if ((s / 100 <= 12) && (s / 100 > 0)) {
		if ((s % 100 <= 12) && (s % 100 > 0)) {
			cout << "AMBIGUOUS" << endl;
		}
		else {
			cout << "MMYY" << endl;
		}
	}
	else {
		if ((s % 100 <= 12) && (s % 100 > 0)) {
			cout << "YYMM" << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
	
	return 0;
}

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

char S[2][53];      //ドミノの敷き詰め方
long long DP;       //横iマスを塗り分ける場合の数
const long long MOD=1000000007;


int main() {
    int N;      //横のマス数
    cin >> N;
    for (int i=1; i<=N; ++i) cin >> S[0][i];
    for (int i=1; i<=N; ++i) cin >> S[1][i];
    //以上読み込み

    int x;      //現在のx座標,初期値によって変わる
    if (S[0][1] == S[1][1]) {
        x = 2;
        DP = 3;     //縦3通り
    }
    else {
        x = 3;
        DP = 6;     //横横で3*2通り
    }
    //以上初期値の場合分け

    while (x <= N) {

        if (S[0][x] == S[1][x]) {       //縦の右に
            if (S[0][x-1] == S[1][x-1]) //縦が並ぶなら *2
                DP = 2 * DP % MOD;      //横が並ぶなら *1
            ++x;                        
        }

        else {                          //横の右に
            if (S[0][x-1] == S[1][x-1]) //縦が並ぶなら横の上下の入れ替えで *2
                DP = 2 * DP % MOD;            
            else                        //横が並ぶなら *(2+1)
                DP = 3 * DP % MOD;      
            x += 2;
        }
    }

    cout << DP << endl;
    return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long 
using namespace std;
ll mod = 1e9 + 7;
 
template <typename T>
T power(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1; 
    //cin >> t;
    for(int T = 0; T < t ; T++){
        ll n;
        cin >> n;
        if(n == 1)
            cout << 0 << endl;
        else{
            ll x = power<ll>((ll)8, n, mod)%mod;
            //x /= 2;
            x %= mod;
            ll y = power<ll>((ll)10, n, mod)%mod;
            ll z = power<ll>((ll)9,n , mod)%mod;
            z *= 2;
            z %= mod;
            cout << (y + x - z + mod)%mod << endl; 
        }
    }
    return 0;
}

Measured memory_bytes: 3612
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
using namespace std;
const ll mod =1e9+7;
const int N = 1e6+7;

 
int main()
{
	ll a,b,n;
	lscf(a),lscf(b),lscf(n);

	ll ans=0;
	ll x=n;

	if(n<b)	
	ans=floor((a*x)/b*1.0)-a*floor((x*1.0)/b);
	

	ll r=x%b;
	x-=r;
	x--;

	if(n>=b)
	ans=floor((a*x)/b*1.0)-a*floor((x*1.0)/b);

	lprin(ans);




}

Measured memory_bytes: 3820
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
#define pb push_back
#define mp make_pair
using ll = long long;
using vi = vector <int>;
using pii = pair <int, int>;
#define rep(i,n) for (int i = 0; i < (int) (n); ++ i)
#define foreach(it,c) for (auto it = c.begin(); it != c.end(); ++ it)

inline int read() {
	int x = 0, f = 1, c = getchar();
	for (;!isdigit(c);c = getchar()) if (c == 45) f ^= 1;
	for (; isdigit(c);c = getchar()) x = x * 10 + c - 48;
	return f ? x : -x;
}

vi g[100005];
int dis[100005];
int tmp[100005];

void dfs(int u, int p) {
	rep(i, g[u].size()) {
		int v = g[u][i];
		if (v != p) {
			dis[v] = dis[u] + 1;
			dfs(v, u);
		}
	}
}

int main() {
	int n = read();
	rep(i, n - 1) {
		int u = read() - 1;
		int v = read() - 1;
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(0, -1);
	memcpy(tmp, dis, sizeof(dis));
	dis[n - 1] = 0; dfs(n - 1, -1);
	int siz = 0;
	rep(i, n) {
		if (dis[i] < tmp[i]) ++ siz;
	}
	if (siz >= n - siz) puts("Snuke");
	else puts("Fennec");
	return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()

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

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const int INF = 0x3fffffff;


string a="CODEFESTIVAL2016";
int main(){
	int ans=0;
	string s;
	cin >> s;
	rep(i,s.length()){
		if( a[i] != s[i] ) ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
divisors = set()
for i in range(1, int(m**.5)+1):
    if m % i == 0:
        divisors |= {i, m//i}
divisors = sorted(divisors)
for div in divisors:
    if n <= div:
        print(m//div)
        break


Measured memory_bytes: 3060