akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())

if n == 1 and m == 1:
    ans = 0
elif n <= 1 and m > 1:
    ans = m * (m - 1) / 2
elif n > 1 and m <= 1:
    ans = n * (n - 1) / 2
else:
    ans = n * (n - 1) / 2 + m * (m - 1) / 2

print(int(ans))

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

namespace ALDS1_9_A {
    class Program {
        static void Main(string[] args) {
            int H = int.Parse(Console.ReadLine());
            Dictionary<int, string> keys = Console.ReadLine().Split(' ')
                .Select((key, index) => new { index, key })
                .ToDictionary(n => n.index + 1, n => n.key);

            StringBuilder sb = new StringBuilder();
            for(int i = 1; i <= H; i++) {
                int p = i / 2;
                int l = 2 * i;
                int r = 2 * i + 1;

                sb.Append("node " + i);
                sb.Append(": key = " + keys[i] + ", ");
                if (p > 0)
                    sb.Append("parent key = " + keys[p] + ", ");
                if (l <= H)
                    sb.Append("left key = " + keys[l] + ", ");
                if (r <= H)
                    sb.Append("right key = " + keys[r] + ", ");
                sb.AppendLine();
            }
            Console.Write(sb);
        }
    }
}

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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = new string[3][];
            for(int i = 0; i < a.Length; i++)
            {
                a[i] = Console.ReadLine().Split(' ');
            }
            var time = int.Parse(Console.ReadLine());
            var nums = new string[time];
            for(int i = 0; i < time; i++)
            {
                nums[i] = Console.ReadLine();
            }
            for(int i = 0; i < a.Length; i++)
            {
                for(int j = 0; j < a[i].Length; j++)
                {
                    for(int k = 0; k < time; k++)
                    {
                        if(nums[k] == a[i][j])
                        {
                            a[i][j] = "O";
                        }
                    }
                }
            }
            Console.WriteLine(Check(a));
            //Console.ReadKey();
        }

        static string Check(string[][] a)
        {
            string check = "No";
            if(a[0][0] == "O" && a[0][1] == "O" &&a[0][2] == "O")
            {
                check = "Yes";
            }
            else if(a[1][0] == "O" && a[1][1] == "O" && a[1][2] == "O")
            {
                check = "Yes";
            }
            else if (a[2][0] == "O" && a[2][1] == "O" && a[2][2] == "O")
            {
                check = "Yes";
            }
            else if (a[0][0] == "O" && a[1][0] == "O" && a[2][0] == "O")
            {
                check = "Yes";
            }
            else if (a[0][1] == "O" && a[1][1] == "O" && a[2][1] == "O")
            {
                check = "Yes";
            }
            else if (a[0][2] == "O" && a[1][2] == "O" && a[2][2] == "O")
            {
                check = "Yes";
            }
            else if (a[0][0] == "O" && a[1][1] == "O" && a[2][2] == "O")
            {
                check = "Yes";
            }
            else if (a[0][2] == "O" && a[1][1] == "O" && a[2][0] == "O")
            {
                check = "Yes";
            }
            return check;
        }
    }
}

Measured memory_bytes: 11348
n = int(input())
a = input()
b = input()
c = input()
count = 0
for i in range(n):
    ab = a[i] + b[i]
    bc = b[i] + c[i]
    ca = c[i] + a[i]
    count += 2 - max(ab.count(c[i]), bc.count(a[i]), ca.count(b[i]))
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
int main()
{
    int N;
    cin >> N;
    vector<int> A;
    REP(i, N)
    {
        int a;
        cin >> a;
        A.push_back(a);
    }
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());
    if (A.size() == N)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod=1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int dp[100005][13];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    int n=s.length();
    dp[0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<13;j++){
            if(s[i]=='?'){
                for(int k=0;k<10;k++){
                    dp[i+1][(j*10+k)%13]+=dp[i][j];
                    dp[i+1][(j*10+k)%13]%=mod;
                }
            }
            else{
                dp[i+1][(j*10+s[i]-'0')%13]+=dp[i][j];
                dp[i+1][(j*10+s[i]-'0')%13]%=mod;
            }
        }
    }
    cout<<dp[n][5]<<endl;
    return 0;
    }


Measured memory_bytes: 5584
#include <iostream>
#include <map>
#include <queue>
using namespace std;

int main() {
  long long N;
  cin >> N;
  long long A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  
  long long sum[N];
  map<long long, long long> Map;
  queue<long long> Que;
  bool flag = false;
  Map[0] = 1;
  for (int i = 0; i < N; i++){
    if (i == 0) sum[i] = A[i];
    else sum[i] = sum[i - 1] + A[i];
    Map[sum[i]]++;
    if (Map[sum[i]] == 2) Que.push(sum[i]);
  }
  
  long long count = 0;
  while (!Que.empty()){
    long long a = Que.front();
    Que.pop();
    count += Map[a] * (Map[a] - 1) / 2;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 19004
a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k==x:
                ans+=1
print(ans)

Measured memory_bytes: 3060
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y


N,M=LI()
RES=[[0,0] for _ in range(N+1)]
WA=0
AC=0
for i in range(M):
    ps, re = input().split()
    n = int(ps)
    if not RES[n][0]:
        if re == "AC": RES[n][0] = 1
        else: RES[n][1] += 1


for i,j in RES:
    AC += i
    if i: WA += j

print("{} {}".format(AC, WA))


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

using namespace std;
using ll =long long;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
#define leftunique(a) {sort((a).begin(),(a).end());(a).erase(unique((a).begin(),(a).end()),(a).end());}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
static const ll INF = 1LL << 60;
//Write From this Line

int main()
{
	int n, k;
	cin >> n >> k;
	ll ans = 0;
	For(i,1,n+1){
		int tmp = max(0,i-k);
		ans += tmp * (n / i) + max(0, n%i - k + 1);
	}
	if(k == 0){
		ans -= n;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
	cin>>n;
	n%=10;
	if (n==2 || n==4 || n==5 || n==7 || n==9) cout<<"hon"<<endl;
	if (n==0 || n==1 || n==6 || n==8) cout<<"pon"<<endl;
	if (n==3) cout<<"bon"<<endl;
	return 0;
}


Measured memory_bytes: 3624
n=int(input())

N=[0]*(n+1)

def f(n):
    M=[]
    while n%2==0:
        n//=2
        M.append(2)
    i=3
    while n>=i:
        while n%i==0:
            n//=i
            M.append(i)
        i+=2
    return M

for i in range(2,n+1):
    for j in f(i):
        N[j]+=1

def num(m):
    return len(list(filter(lambda x:x>=m-1,N)))

print(num(75)+num(25)*(num(3)-1)+num(15)*(num(5)-1)+num(5)*(num(5)-1)*(num(3)-2)//2)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n, x;
	cin >> n >> x;
	int sum = 0;
	vi m(n);
	rep(i, 0, n) {
		cin >> m[i];
		sum += m[i];
	}
	int ans = n;
	x -= sum;
	int min = *(min_element(all(m)));
	ans += x / min;
	cout << ans << endl;
	return 0;
}

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

namespace abc144_d
{
    class Program
    {
        static void Main(string[] args)
        {
            var al = (from xx in Console.ReadLine().Split(' ') select decimal.Parse(xx)).ToList();

            var a = al[0];
            var b = al[1];
            var x = al[2];
            var wh = x / (a * a);
            double s = 0;

            if (wh >= b/2)
            {
                var h = b - wh;
                s = Math.Atan2((double)h, (double)a / 2);
                
            }
            else 
            {
                var h = ((x / a) * 2) / b;
                s = Math.Atan2((double)b, (double)h);
            }

            Console.WriteLine(s * 180 / Math.PI);
        }
    }
}


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

#define trav(a, A) for (auto & a : A)
#define f first
#define s second

typedef long long ll;

ll MOD = 1e+9+7;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 1e+5+7;

int main ()
{
	ios_base::sync_with_stdio (0);
	cin.tie (0);
	ll i, j, n, ans = 0;
	cin >> n;
	for (i = 1; i < n; ++i)
		for (j = 1; j < n/i + 1 && j <= i; ++j)
			if (i*j < n)
				ans += 1 + (i!=j);
	cout << ans << '\n';

	return 0;
}



Measured memory_bytes: 3644
def count_bomb(grid, height, width, h, w)
    cnt = 0
    #上のマス
    if h > 0
        cnt += 1 if grid[h-1][w] == "#"
        if 0 < w #左のマスが存在
            cnt += 1 if grid[h-1][w-1] == "#"
        end
        if w < width-1 #右のマスが存在
            cnt += 1 if grid[h-1][w+1] == "#"
        end
    end

    #同じ段のマス
    if 0 < w #左のマスが存在
        cnt += 1 if grid[h][w-1] == "#"
    end
    if w < width-1 #右のマスが存在
        cnt += 1 if grid[h][w+1] == "#"
    end

    # 下のマス
    if h < height-1
        cnt += 1 if grid[h+1][w] == "#"
        if 0 < w #左のマスが存在
            cnt += 1 if grid[h+1][w-1] == "#"
        end
        if w < width-1 #右のマスが存在
            cnt += 1 if grid[h+1][w+1] == "#"
        end
    end

    return cnt
end

mass = gets.chomp.split(" ").map(&:to_i)
height = mass[0]
width = mass[1]
grid = []
(0..height-1).each do
    grid.push(gets.chomp.split(""))
end

(0..height-1).each do |h|
    (0..width-1).each do |w|
        if grid[h][w] == "."
            grid[h][w] = count_bomb(grid, height, width, h, w).to_s
        end
    end
end

(0..height-1).each do |h|
    puts grid[h].join
end

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

# define s(n)           scanf("%d",&n)
# define sl(n)          scanf("%lld",&n)
# define sc(n)          scanf("%c",&n)
# define forall(i,a,b)  for(i=a;i<b;i++)
# define all(a)         a.begin(),a.end()
# define gcd            __gcd
# define pb             push_back
# define ll             long long int
# define vl             vector<long long int> 

int main(){
ll n,t,i,j,k,p,sum;
vl vec;
array<ll,100005> dp;
cin>>n>>k;
forall(i,0,n){
    cin>>p;
    vec.pb(p);
}
dp.fill(INT_MAX);
dp[1]=0;
for(i=2;i<=n;i++){
    for(j=1;j<=k;j++)
    if(i-(j+1)>=0)
    dp[i]=min(dp[i-j]+abs(vec[i-1]-vec[i-(j+1)]),dp[i]);
}
cout<<dp[n];
}

Measured memory_bytes: 4856
#include<bits/stdc++.h>
// iteration and input/output stream
#define rep(i,a,b) for(int i = int(a);i<=int(b);i++)
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define printarr(x) rep(i,0,x.size()-1) cout<<x[i]<<" "; cout<<endl;
#define all(v) v.begin(),v.end()
 
#define si(x) int x; scanf("%d", &x)
#define sll(x) ll x; scanf("%lld", &x)
#define pi(x) printf("%d", x)
#define pll(x) printf("%lld", x)
#define nl printf("\n")
#define tr(cont,it) \
for(decltype(cont.begin()) it = cont.begin(); it!= cont.end() ; it++)
 
#define endl "\n"
#define tc() int t; cin >> t ; while (t--)
//STL shortcuts
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define F first
#define S second
#define MP make_pair
 
// Error detection
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
 
using namespace std;
 
typedef long long int ll; // 64 bit integer
typedef unsigned long long int  ull; // 64 bit unsigned integer
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<int,ll> pill;
 
inline void smax(int &x , int y) { x = max(x , y) ; }
inline void smin(int &x , int y) { x = min(x , y) ; }
 
#define MOD 1000000007
#define inf 4000000000000000000LL
#define SYNC std::ios::sync_with_stdio(false);  cin.tie(NULL);
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("err.txt","w",stderr);
    #endif
    SYNC
    int n,k;
    cin>>n>>k;
    vi a(n);
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    sort(all(a));
    ll s = 0;
    for (int i = 0; i < k; i++)
    {
        s+=(a[i]);
    }
    cout<<s<<"\n";
    return 0;
}

Measured memory_bytes: 3660
import collections

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = int(input())

c = collections.Counter(prime_factorize(n))

l = len(list(c.keys()))
it = list(c.values())

ans = 0

#print(it)

for i in range(l):
    p = 1
    while (it[i] - p >= 0):
        it[i] -= p
        ans += 1
        p += 1
print(ans)


Measured memory_bytes: 9468
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] a = readArray(scanner);
        int[] b = readArray(scanner);

        int count = 0;
        for (int i = 0; i < b.length; i++) {
            for (int j = 0; j < a.length; j++) {
                if (b[i] == a[j]) {
                    count++;
                    break;
                }
            }
        }

        System.out.println(count);
    }

    private static int[] readArray(Scanner scanner) {
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = scanner.nextInt();
        return a;
    }

}



Measured memory_bytes: 39716
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

class UnionFindTree {
public:
    this(size_t n) {
        parent = iota(n).array();
        rank = new size_t[](n);
    }
    size_t find(size_t n) {
        if(n == parent[n]) {
            return n;
        } else {
            parent[n] = find(parent[n]);
            return parent[n];
        }
    }
    void unite(size_t n, size_t m) {
        auto p1 = find(n);
        auto p2 = find(m);
        if(n == m) {
            return;
        }
        if(rank[p1] < rank[p2]) {
            swap(p1, p2);
        }
        if(rank[p1] == rank[p2]) {
            ++rank[p1];
        }
        parent[p2] = p1;
    }
private:
    size_t[] parent;
    size_t[] rank;
}
unittest {
    auto uft = new UnionFindTree(10);
    foreach(i; iota(10)) {
        assert(uft.find(i) == i);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0).drop(1)) {
        uft.unite(i, i-3);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0)) {
        assert(uft.find(0) == uft.find(i));
    }
    foreach(i; iota(10).filter!(a => a%3 != 0)) {
        assert(uft.find(0) != uft.find(i));
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    auto n = readLong();
    auto a = readLongs();

    long solve(long s, long i) {
        if(i == n) {
            return 0;
        }
        if(s > 0) {
            if(s + a[i] >= 0) {
                return s + a[i] + 1 + solve(-1, i+1);
            } else {
                return solve(s + a[i], i+1);
            }
        } else {
            if(s + a[i] <= 0) {
                return -(s + a[i]) + 1 + solve(1, i+1);
            } else {
                return solve(s + a[i], i+1);
            }
        }
    }
    if(a[0] == 0) {
        writeln(1 + min(solve(1, 1), solve(-1, 1)));
    } else {
        if(a[0] > 0) {
            writeln(min(solve(a[0], 1), a[0] + 1 + solve(-1, 1)));
        } else {
            writeln(min(solve(a[0], 1), -a[0] + 1 + solve(1, 1)));
        }
    }
}



Measured memory_bytes: 7556
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;

int main(){

    string s;
    cin >> s;

    s[0]++;

    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

const int N = 1e4 + 1;

int pa[N];

void init() {
  for (int i = 0; i < N; ++i) pa[i] = i;
}

int find(int x) {
  return pa[x] == x ? x : pa[x] = find(pa[x]);
}

void unite(int x, int y) {
  int px = find(x);
  int py = find(y);
  if (px != py) pa[px] = py;
}

bool check(int x, int y) {
  int px = find(x);
  int py = find(y);
  return px == py;
}

int main() {
  int n, q;
  while (std::cin >> n >> q) {
    init();
    while (q --) {
      int op, x, y;
      std::cin >> op >> x >> y;
      if (op == 0) unite(x, y);
      else std::cout << (check(x, y) == true ? 1 : 0) << std::endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3216
unittest
{
	assert( [ "2 3 1 1" ].parse.expand.solve == 2 );
	assert( [ "10 7 3 4" ].parse.expand.solve == 3570 );
	assert( [ "100000 100000 99999 99999" ].parse.expand.solve == 1 );
	assert( [ "100000 100000 44444 55555" ].parse.expand.solve == 738162020 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto hwab = input.front.split.to!( long[] );
	return tuple( hwab[ 0 ], hwab[ 1 ], hwab[ 2 ], hwab[ 3 ] );
}

auto solve( long h, long w, long a, long b )
{
	auto ans = 0L;
	auto y1 = h - a - 1;
	auto y2 = h - y1 - 2;
	for( auto x1 = b; x1 < w; x1++ )
	{
		auto x2 = w - x1 - 1;
		ans = ans.addMod( ( y1 + x1 ).combinationMod( x1 ).mulMod( ( y2 + x2 ).combinationMod( x2 ) ) );
	}
	return ans;
}

// 足し算
auto addMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return ( x + y ) % MOD;
}

// 掛け算
auto mulMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return x * y % MOD;
}

// 割り算
auto divMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return x * y.powMod!MOD( MOD - 2 ) % MOD;
}

// べき乗
auto powMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	auto a = 1L;
	for( ; 0 < y; y >>= 1 )
	{
		if( y & 1 ) a = a * x % MOD;
		x = x ^^ 2 % MOD;
	}
	return a;
}

// 階乗
auto factorialMod( long MOD = 10L ^^ 9 + 7 )( long x )
{
	static memo = [ 1L ];
	if( memo.length <= x )
	{
		auto i = memo.length;
		memo.length = x + 1;
		for( ; i <= x; i++ ) memo[ i ] = memo[ i - 1 ] * i % MOD;
	}
	return memo[ x ];
}

// 組み合わせ数
auto combinationMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return x.factorialMod!MOD.divMod!MOD( y.factorialMod!MOD.mulMod!MOD( ( x - y ).factorialMod!MOD ) );
}


Measured memory_bytes: 3452
#include <stdio.h>

#define MAX 100005

int min(int a, int b) {
    return a < b ? a : b;
}

int abs(int a) {
    return a >= 0 ? a : -a;
}

int main() {
    int N;
    int h[MAX];
    int opt[MAX];
    opt[0] = opt[1] = 0;
    
    scanf("%d", &N);
    
    for (int i=0; i < N; i++) {
        scanf("%d", &h[i]);
        if (i >= 2)
            opt[i] = min(opt[i-1] + abs(h[i] - h[i-1]), opt[i-2] + abs(h[i]-h[i-2]));
        else if (i == 1)
            opt[i] = abs(h[i] - h[i-1]);
        else
            opt[i] = 0;
    }
    printf("%d\n", opt[N-1]);
    return 0;
}


Measured memory_bytes: 896
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long ans = 0L;
        for (long i = 1; i < Math.sqrt(n)+1; i++) {
            if((n - i) / i <= i) break;
            if((n - i) % i == 0) ans += (n - i) / i;
        }
        System.out.println(ans);
        sc.close();
    }

}


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

typedef long long ll;
ll const inf = 1e18;

vector<vector<pair<ll,ll>>> tree;
vector<ll> depth;

void dfs(ll v, ll p, ll d){
    depth.at(v) = d;
    for(int i=0; i<tree.at(v).size(); i++){
        if(tree.at(v).at(i).first == p){
            continue;
        }
        dfs(tree.at(v).at(i).first, v, d + tree.at(v).at(i).second);
    }
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    tree.resize(n);
    depth.resize(n);
    for(int i=0; i<n-1; i++){
        int a, b, c;
        cin >> a >> b >> c;
        tree.at(a-1).push_back({b-1,c});
        tree.at(b-1).push_back({a-1,c});
    }
    int q, k;
    cin >> q >> k;

    dfs(k-1, -1, 0);

    for(int i=0; i<q; i++){
        int x, y;
        cin >> x >> y;
        cout << depth.at(x-1) + depth.at(y-1) << "\n";
    }

    return 0;
}

Measured memory_bytes: 15872
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#define WOULD
#define YOU
#define PLEASE
#define ACCEPT
#define MY
#define SUBMISSION
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

int main() {
    int N;cin >> N;
    vector<int> retu(N);
    for(int i = 0;i<N;i++) cin >> retu.at(i);
    int mini = 1145141919;
    int cost = 0;
    int avg = 0;
    for(int i = 0;i<N;i++){
        avg += retu.at(i);
    }
    avg /= N;
    for(int i = avg-100;i<=avg+100;i++){
        for(int j = 0;j<N;j++){
            cost += pow(retu.at(j)-i,2);
        }
        mini = min(mini,cost);
        cost = 0;
    }
    cout << mini << endl;
}

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

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

  int n, m;
  cin >> n >> m;
  vi a(n);
  vector<pii> l(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> l[i].first >> l[i].second;

  sort(all(a));
  sort(all(l), [](pii l, pii r){return l.second > r.second;});

//  rep(i, n) cerr << a[i] << endl;
//  rep(i, m) cerr << l[i].first << " " << l[i].second << endl;

  int ind = 0;
  rep(i, n) {
    if (l[ind].second <= a[i]) break;
    a[i] = l[ind].second;
    l[ind].first--;
    if(l[ind].first==0) ind++;
  }
  
  ll ans = 0;
  rep(i, n) {
    ans += a[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    cout << min(A,B) + min(C,D) << endl;
    
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)1e5
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	ll a,b;cin>>a>>b;
	cout<<min(a%b,b-a%b)<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int main(void){
	int n;
	cin>>n;
	for(int k=0;k<n;k++){
		string s,o;
		cin>>o>>s;
		int t=o.size(),si=s.size();
		for(int i=t-1;i>=0;i--){
			if(o[i]=='J'){
				char temp=s[si-1];
				rep(j,1,si){
					s[si-j]=s[si-j-1];
				}
				s[0]=temp;
			}else if(o[i]=='C'){
				char temp=s[0];
				rep(j,0,si-1){
					s[j]=s[j+1];
				}
				s[si-1]=temp;
			}else if(o[i]=='A'){
				rep(j,0,si/2){
					swap(s[j],s[si-1-j]);
				}
			}else if(o[i]=='E'){
				string b,m,e;
				rep(j,0,si/2){
					b+=s[j];
				}
				int l=0;
				if(si%2==1){
					m=s[si/2];
					l++;
				}
				rep(j,si/2+l,si){
					e+=s[j];
				}
				s=e;
				s+=m;
				s+=b;

			}else if(o[i]=='P'){
				rep(j,0,si){
					if(s[j]>='0'&&s[j]<='9'){
						s[j]--;
						if(s[j]<'0'){
							s[j]='9';
						}
					}
				}
			}else{
					rep(j,0,si){
					if(s[j]>='0'&&s[j]<='9'){
						s[j]++;
						if(s[j]>'9'){
							s[j]='0';
						}
					}
				}
			}
		}
		cout<<s<<endl;

	}
	return 0;
}

Measured memory_bytes: 3132
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	s := r.nextString()

	pre := s[0:1]
	cnt := 1
	for i, end := 1, len(s); i < end; {
		j := i + 1
		for ; j <= end; j++ {
			cur := s[i:j]
			if pre != cur {
				pre = cur
				cnt++
				break
			}
		}
		i = j
	}
	fmt.Fprintln(stdout, cnt)
}


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

using namespace std;

int main()
{
	string str;

	cin >> str;

	int *b = new int[ str.size() ];

	int n = str.size();
	for ( int i=0; i < str.size(); i ++ ) {
		b[i] = i&0x01;
	}

	int c1 = 0, c2 = 0;
	for ( int i = 0; i < n; i ++ ) {
		if ( (b[i] == 0 && str[i] == '1' ) ||
		     (b[i] == 1 && str[i] == '0' ) ) {
			 c1 ++;
		}

		if ( (b[i] == 1 && str[i] == '1' ) ||
		     (b[i] == 0 && str[i] == '0' ) ) {
			 c2 ++;
		}

	}

	if ( c1 < c2 ) {
		cout << c1 << endl;
	} else {
		cout << c2 << endl;
		
	}

	return 0;
}

Measured memory_bytes: 896
#include <iostream>

using namespace std;

int main()
{
	while (1)
	{
		int n;
		cin >> n;
		if (cin.fail()) break;

		int count = 0;

		for (int i = 0; i < 10; ++i)
		{
			for (int j = 0; j < 10; ++j)
			{
				for (int k = 0; k < 10; ++k)
				{
					for (int l = 0; l < 10; ++l)
					{
						if (i + j + k + l == n)
						{
							++count;
						}
					}
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

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

int main()
{
	char N[18];
	cin >> N;
	int i, j, k, l,flag;
	flag = 1;
	for (i = 0; i < strlen(N)-1; i++) {
		if (N[i+1] != '9')
			flag = 0;

	}
	k = N[0] - '0';
	if (strlen(N) != 1) {
		if (flag) {
			cout <<k+ 9 * (strlen(N)-1) << endl;
		}
		else
			cout << k - 1 + 9 * (strlen(N) - 1) << endl;
	}
	else
		cout << k << endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int n, k;
    static int[] a;
    static int modP = 1000000007;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        char[] s = in.next().toCharArray();

        int[] wOnLeftCnt  = new int[n];
        int[] eOnLeftCnt  = new int[n];
        int[] wOnRightCnt = new int[n];
        int[] eOnRightCnt = new int[n];

        int wCnt = 0;
        for(int i = 0; i < n; i++) {
            wOnLeftCnt[i] = wCnt;
            if(s[i] == 'W') {
                wCnt++;
            }
        }

        int eCnt = 0;
        for(int i = n-1; i >= 0; i--) {
            eOnRightCnt[i] = eCnt;
            if(s[i] == 'E'){
                eCnt++;
            }
        }

        int minTurned = Integer.MAX_VALUE;
        for(int i = 0; i < n; i++) {
            if(minTurned > wOnLeftCnt[i] + eOnRightCnt[i]) {
                minTurned = wOnLeftCnt[i] + eOnRightCnt[i];
            }

            minTurned = Math.min(minTurned, wOnLeftCnt[i] + eOnRightCnt[i]);
        }

        System.out.println(minTurned);
    }
}

Measured memory_bytes: 33124
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
#define rep(n) for (int i = 0; i < (n); ++i)
int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(n) cin>>v[i];
    sort(v.begin(),v.end());
    double s=v[0];
    rep(n) s=(s+v[i])/2;
    
    printf("%.5f\n",s);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
//#include <bits/stdc++.h>

using namespace std;

typedef long long li;

int main() {
    li n;
    cin >> n;
    vector<li> a(n), b(n), c(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    li ans = 0;
    for (int i = 0; i < n; ++i) {
        li ac = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        li cc = c.end() - upper_bound(c.begin(), c.end(), b[i]);
        ans += ac * cc;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;

#define FOR(i,n) for(ll i=0;i<n;i++) 
#define RFOR(i,n) for(ll i=n-1;i>=0;--i)
#define COUT(str) cout << str << endl


int A[3]; 
bool a = true;
int ANS[3] = {5,5,7};


int main() {

	int a[3];
	int b[3] = { 5,5,7 };
	bool flag = false;
	int count = 0;
	FOR(i,3){
		cin >> a[i];
	}
	sort(a, a + 3);
	FOR(i, 3) {
		if (a[i] == b[i]) {
			count++;
			if(count==3)flag = true;
		}
	}
	(flag ? cout << "YES" << endl : cout << "NO" << endl);

	return 0;
}

Measured memory_bytes: 256
n = int(input())
sa = []
for i in range(n):
  a,b = list(map(int, input().split()))
  if ( a > b ):
    print('No')
    exit()    
  sa.append({'a': a, 'b': b})

sa.sort(key=lambda x: x['b'])

aa = 0

for i in range(n):
  aa = aa + sa[i]['a']
  b = sa[i]['b']
  if (aa > sa[i]['b']):
    print('No')
    exit()

print('Yes')


Measured memory_bytes: 72336
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
x1,y1,x2,y2 = map(int, input().split())
x3,y3 =x2-(y2-y1),y2-(x1-x2)
x4,y4 =x3-(y3-y2),y3-(x2-x3)
print(x3,y3,x4,y4)

Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef DEBBY
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define ll long long
#define rep(i,a,b) for(int i=int(a); i<=int(b); i++)
#define sz(v)  (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pi>
#define fs first
#define sd second
#define pb push_back


void solve(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    int x = (a+d-1)/d;
    int y = (c+b-1)/b;
    cout << (x>=y?"Yes": "No"); 
} 

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}
    





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

def solve():
    s1 = list(map(int,input().split()))
    s2 = list(map(int,input().split()))
    s3 = list(map(int,input().split()))
    s4 = [s[0] for s in [s1,s2,s3]]
    s5 = [s[1] for s in [s1,s2,s3]]
    s6 = [s[2] for s in [s1,s2,s3]]
    s7 = [s[i] for i,s in zip([0,1,2], [s1,s2,s3])]
    s8 = [s[i] for i,s in zip([2,1,0], [s1,s2,s3])]
    S = set(int(input()) for _ in range(int(input())))
    if any(set(s).issubset(S) for s in [s1,s2,s3,s4,s5,s6,s7,s8]):
        return 'Yes'
    else:
        return 'No'

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



Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <limits>
#include <type_traits>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

unsigned gcd(unsigned a, unsigned b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

int main()
{
	int N;
	cin >> N;

	int maxH = 0;
	int ans = 0;

	for (size_t i = 0; i < N; i++)
	{
		int h;
		cin >> h;
		if (maxH <= h)
		{
			ans++;
			maxH = h;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
// Problem : B - Go to Jail
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)
#define vt vector
#define bug(x) cout<<#x<<"="<<x<<endl;

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char cl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int cnt=0;
	string ans="No";
	int n;
	cin>>n; 
	loop(i,n){
		if(cnt==3)
			ans="Yes";
		int a,b;
		cin>>a>>b;
		if(a==b)
			cnt++;
		else
			cnt=0;
	}
	if(cnt==3)
	ans="Yes";
	cout<<ans;
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(long long i=0;i<int(N);++i)
using ll = long long;
// const int INF = 2147483647;
const ll MOD = 1e9+7;
const ll INF = 1000000000000000000LL;
 
 
 int main() {
	 ll n;
	 cin >> n;
	 ll nin = INF;
	 for(ll i=1;i*i<=n;i++){
		 if(n%i==0){
			 ll bigger = n/i;
			 nin = min(nin,bigger);
		 }
	 }
	 //桁を数える
	 int keta=0;
	 while(nin>0){
		 nin/=10;
		 keta++;
	 }
	 cout << keta << endl;
	 return 0;
 }


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n;
  string s;
  cin >> n >> s;
  int cnt = 0;
  for(int i = 2; i < n; i++){
    if(s.at(i) == 'C' && s.at(i-1) == 'B' && s.at(i-2) == 'A'){
      cnt++;
    }
  }
  cout << cnt << endl;
  
  }


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int cmp(const void *a,const void *b){
  return *(int *)a-*(int *)b;
}
int main(void){
  int n[4],l,s,i,c,t,a;
  while(1){
    scanf("%1d%1d%1d%1d",&n[0],&n[1],&n[2],&n[3]);
    if(n[0]+n[1]+n[2]+n[3]==0)
      break;
    if(n[0]==n[1]&&n[1]==n[2]&&n[2]==n[3]){
      puts("NA");
      continue;
    }
    c=0;
    t=n[0]*1000+n[1]*100+n[2]*10+n[3];
    while(t!=6174){
      c++;
      l=s=0;
      qsort(n,4,sizeof(int),cmp);
      for(i=0;i<4;i++){
	l=l*10+n[3-i];
	s=s*10+n[i];
      }
      t=l-s;

      a=t;
      for(i=3;i>=0;i--){
	n[i]=a%10;
	a/=10;
      }
    }
    printf("%d\n",c);
  }
  return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
const int64_t MAXN = 200010;
vector<int64_t> f(MAXN, -1);

int64_t calcf(int64_t n)
{
  if (f[n] != -1)
    return f[n];
  return f[n] = (calcf(n % __builtin_popcount(n)) + 1);
}

int main()
{
  int64_t N, cnt = 0;
  cin >> N;
  string X;
  cin >> X;
  for (int i = 0; i < N; i++)
  {
    if (X[i] == '1')
      cnt++;
  }
  int64_t cnta = cnt + 1, cntb = cnt - 1;
  vector<int64_t> moda(MAXN), modb(MAXN);
  int64_t ra = 1, rb = 1;
  for (int i = 0; i < MAXN; i++)
  {
    moda[i] = ra % cnta;
    ra = (ra * 2) % cnta;
    if (cntb > 0)
    {
      modb[i] = rb % cntb;
      rb = (rb * 2) % cntb;
    }
  }
  reverse(X.begin(), X.end());
  int64_t initra = 0, initrb = 0;
  for (int i = 0; i < N; i++)
  {
    if (X[i] == '1')
    {
      initra = (initra + moda[i]) % cnta;
      if (cntb > 0)
        initrb = (initrb + modb[i]) % cntb;
    }
  }
  f[0] = 0;
  f[1] = 1;
  for (int i = 2; i < MAXN; i++)
  {
    calcf(i);
  }
  for (int i = N - 1; i >= 0; i--)
  {
    int mod;
    if (X[i] == '1' && cntb > 0) // cntb
    {
      mod = (initrb - modb[i] + cntb) % cntb;
      cout << f.at(mod) + 1 << endl;
    }
    else if (X[i] == '1' && cntb == 0)
    {
      cout << 0 << endl;
    }
    else // cnta
    {
      mod = (initra + moda[i] + cnta) % cnta;
      cout << f.at(mod) + 1 << endl;
    }
  }
}


Measured memory_bytes: 8360
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, W; cin >> N >> W;
	vector<int> v(N), w(N); rep(i, 0, N) { cin >> v[i] >> w[i]; }
	vector<int>dp(W + 1, 0);
	rep(i, 0, N)rrep(j, w[i], W + 1)
		chmax(dp[j], dp[j - w[i]] + v[i]);
	cout << dp[W] << endl;
	return 0;
}

Measured memory_bytes: 3228
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

#define MOD 1000000007

int main()
{
  ll n;
  vector<bool> as = {};

  cin >> n;
  as.resize(1000000001, false);

  for (auto i = 0; i < n; i++)
  {
    ll a;
    cin >> a;

    if (as[a])
    {
      cout << "NO" << endl;
      return 0;
    }
    else
    {
      as[a] = true;
    }
  }
  cout << "YES" << endl;
  return 0;
}


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

using namespace std;

int main(){
  string s;
  long long x;
  cin >> s;
  cin >> x;
  for(int i=0;i<(int)s.size()-1;i++){
    if(s[i]!='a' && 'z'-s[i]+1<=x){
      x-='z'-s[i]+1;
      s[i]='a';
    }
    cout << s[i];
  }
  long long t = s[(int)s.size()-1]-'a';
  t=(t+x)%26;
  cout << (char)('a'+t) << endl;
  return 0;
}


Measured memory_bytes: 512