akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split().Select(z => int.Parse(z)).ToArray();
            double t = line[0], x = line[1];

            Console.WriteLine(t / x);
        }
    }
}


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

int main(){
  ll n,k;
  vector<ll> v(1000000),c(1000000);
  cin >> n >> k;
  for(ll i=0;i<n;i++){
    cin >> v[i];
    v[i]--;
  }
  ll now = 0;
  bool can = true;
  for(ll i = 1; i <= k; i++){
    if(c[now] && can){
      can = false;
      ll tmp = abs(c[now] - i);
      i += tmp * ((k - i) / tmp);
    }
    c[now] = i;
    now = v[now];
  }
  cout << now + 1 << endl;
  return 0;
}


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

const ll MOD = 1e9+7;
ll dp[101][9];
//dp[i][j]:上からiの高さまでの1から出発した時の数
ll h,w,k;

bool invalid(ll bit)
{
	for(ll i = 0;i<w-1;++i)
	{
		if((bit)&(1<<i)&&(bit)&(1<<(i+1)))
		{
			//cout<<bit<<endl;
			return true;
		}
	}
	return false;
}

int main()
{
	cin >> h >> w >> k;
	dp[0][0] = 1;
	for(ll i = 0;i<h;++i)
	{
		for(ll bit = 0;bit <(1<<(w-1));++bit)
		{
			if(invalid(bit))continue;
			for(ll j = 0;j<w-1;j++)
			{
				if(bit&(1<<j))
				{
					(dp[i+1][j] += dp[i][j+1])%=MOD;
					(dp[i+1][j+1] += dp[i][j])%=MOD;
					j++;
				}
				else
				{
					(dp[i+1][j] += dp[i][j])%=MOD;
				}
			}
			if(!(bit&(1<<(w-2))))
			{
				//cout<<bit<<endl;
				(dp[i+1][w-1] += dp[i][w-1])%=MOD;
			}
		}
	}
	//for(ll i = 0;i<=h;i++){for(ll j = 0;j<w;j++){cout<<dp[i][j]<<' ';}cout<<endl;}
	cout<<dp[h][k-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np

n, m, k = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

a = [0]
b = [0]

a = np.append(a, np.cumsum(A))
b = np.append(b, np.cumsum(B))

j = m
ans = 0
for i in range(n + 1):
    if a[i] > k:
        break
    while a[i] + b[j] > k:
        j -= 1
    ans = max(ans, i + j)
    
print(ans)

Measured memory_bytes: 57492
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    counter = Counter()
    for a in A:
        counter[a - 1] += 1
        counter[a] += 1
        counter[a + 1] += 1

    ans = max(counter.values())

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 23756
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
// repeat for accumulational summention
#define Acu(i,n,m) for(int i=(n);i<=(m);i++)
#define ll long long
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
int MAX=1e9;
int MOD=1e9+7;


int main(){
  int n;cin>>n;
  ll ansI=0,ansJ;
  ll a[n],b[n];
  REP(i,n){
    cin>>a[i];
    b[i]=a[i];
    ansI=max(a[i],ansI);
  }
  ll MEAN;
  (ansI%2==1)?MEAN=ansI/2+1:MEAN=ansI/2;
  REP(i,n){
    b[i]=abs(b[i]-MEAN);
  }
  ll temp=b[0];
  REP(i,n){
    temp=min(temp,b[i]);
    if(temp==b[i])ansJ=a[i];
  }
  cout<<ansI<<" "<<ansJ<<endl;
}


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

int main() {
  int n = 3;
  vector<int> abc(n);
  rep(i,n){cin >> abc.at(i);}

  sort(abc.begin(),abc.end());

  int ans = 0;
  vector<int> even;
  vector<int> odd;
  rep(i,n){
    if(abc.at(i) % 2 == 0){
      even.push_back(abc.at(i));
    } else {
      odd.push_back(abc.at(i));
    }
  }

  if(even.size() == 0 || even.size() == 3){
    ans += ((abc.at(2) - abc.at(0)) / 2);
    ans += ((abc.at(2) - abc.at(1)) / 2);
  } else {
    if(even.size() > odd.size()){
      abc.at(0) = even.at(0) + 1;
      abc.at(1) = even.at(1) + 1;
      abc.at(2) = odd.at(0);
    } else {
      abc.at(0) = odd.at(0) + 1;
      abc.at(1) = odd.at(1) + 1;
      abc.at(2) = even.at(0);
    }
    ans++;
    sort(abc.begin(),abc.end());
    ans += ((abc.at(2) - abc.at(0)) / 2);
    ans += ((abc.at(2) - abc.at(1)) / 2);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int N;
    scanf("%d",&N);
    vector<int> H;
    int tmp;

    for(int i=0;i<N;i++){
        scanf("%d",&tmp);
        H.push_back(tmp);
    }

    vector<int> A;

    int c = 0;
    int a = 0;
    for(int i=0;i<N-1;i++){
        a++;
        //cout << "a:" << a << endl;
        if(H.at(i) >= H.at(i+1)){
            c++;
           // cout << "c:" << c << endl;
            if(a == N-1){
                A.push_back(c);
            }
        }else{
            A.push_back(c);
            c = 0;
        }
    }

    //std::sort(A.rbegin(), A.rend());

    int M = 0;

    for(int i=0;i<A.size();i++){
        int tmp = A.at(i);
        if(tmp > M){
            M = tmp;
        }
    }

    printf("%d\n",M);


    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    priority_queue<ll, vector<ll>, greater<ll>> p;
    priority_queue<ll, vector<ll>, greater<ll>> q;
    priority_queue<ll> r;
    
    priority_queue<pair<ll, int>> que;
    ll item;
    for(int i=0; i<A; i++){
        cin >> item;
        p.push(item);
    }
    for(int i=0; i<B; i++){
        cin >> item;
        q.push(item);
    }
    for(int i=0; i<C; i++){
        cin >> item;
        r.push(item);
    }

    while(p.size() > X){
        p.pop();
    }
    while(q.size() > Y){
        q.pop();
    }

    while(r.size()){
        // cout << "TOP:" << p.top() << " " << q.top() << endl;
        if(p.top() < q.top()){
            if(p.top() >= r.top()){
                break;
            }
            p.pop();
            p.push(r.top());
            r.pop();
        } else{
            if(q.top() >= r.top()){
                break;
            }
            q.pop();
            q.push(r.top());
            r.pop();
        }
    }

    ll ans = 0;
    while(p.size()) {
        // cout << "p:" << p.top() <<  endl;
        ans += p.top();
        p.pop();
    }
    while(q.size()) {
        // cout << "q:" << q.top() <<  endl;
        ans += q.top();
        q.pop();
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3316
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

class UnionFind {
 private:
  vector<ll> parents;

 public:
  UnionFind(ll n) : parents(n, -1) {}

  bool issame(ll x, ll y) { return root(x) == root(y); }

  bool merge(ll x, ll y) {
    if (issame(x, y)) return false;

    ll rx = root(x);
    ll ry = root(y);
    if (parents[rx] > parents[ry]) swap(rx, ry);
    // サイズ情報を更新
    parents[rx] += parents[ry];
    // yの親を更新
    parents[ry] = rx;

    return true;
  }

  ll size(ll x) { return -parents[root(x)]; }

 private:
  ll root(ll x) {
    if (parents[x] < 0) return x;
    // 根の親の値に木の(-)サイズの情報を入れる
    return parents[x] = root(parents[x]);
  }
};

int main() {
  cout << fixed << setprecision(15);

  ll N, M, K;
  cin >> N >> M >> K;

  UnionFind friends(N);
  // UnionFind blocked(N);

  vector<ll> numberOfFriends(N, 0);
  vector<ll> blockedFriends(N, 0);

  for (ll i = 0; i < M; i++) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    numberOfFriends[a]++;
    numberOfFriends[b]++;
    friends.merge(a, b);
  }

  vector<ll> ans(N, 0);
  for (ll i = 0; i < N; i++) {
    ans[i] = friends.size(i) - numberOfFriends[i] - 1;
  }

  for (ll i = 0; i < K; i++) {
    ll c, d;
    cin >> c >> d;
    c--;
    d--;
    if (friends.issame(c, d)) {
      ans[c]--;
      ans[d]--;
    }
  }

  for (ll i = 0; i < N; i++) {
    ll a = ans[i];
    if (i == N - 1) {
      cout << a;
    } else {
      cout << a << " ";
    }
  }

  cout << endl;

  return 0;
}


Measured memory_bytes: 3968
n, c, k=gets.split.map(&:to_i)
t=[]
n.times{t.push(gets.chomp.to_i)}
t=t.sort

b, d, m=0, 0, 0
n.times do |i|
  if d<c
    if t[i]<=b
      d+=1
    else
      m+=1
      b=t[i]+k
      d=1
    end
  else
    m+=1
    d=1
    b=t[i]+k
  end
  # puts "#{b} #{d} #{m}"
end

puts m

Measured memory_bytes: 4216
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <string>
#include <type_traits>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> x(n);
    for(int i = 0; i < n; i++) cin >> x[i];

    int ans = 0;
    for(int i = 0; i < n - 1; i++) {
        ans += min(abs(x[i + 1] - x[i]) * a, b);
    }

    cout << ans << endl;
    return 0;
}


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

int main (int argc, char **argv) {
  int W, H;
  int x, y, r;

  // Inputs
  cin >> W >> H >> x >> y >> r;

  string Ans;
  if ((x >= r) && (x <= (W -r)) && (y >= r) && (y <= (H - r))) {
    Ans = "Yes";
  } else {
    Ans = "No";
  }
  cout << Ans << endl;
}

Measured memory_bytes: 1196
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

signed main(void)
{
	double x = 0, y = 0;
	int ang = 90;
	while(true) {
		int r, t;
		cin >> r;
		x += r*cos(ang*PI/180);
		y += r*sin(ang*PI/180);
		cin.ignore(); cin >> t;
		if(!r && !t) break;
		ang -= t;
		ang = (ang + 360) % 360;
	}
	cout << (int)x << endl << (int)y << endl;

	return 0;
}

Measured memory_bytes: 3252
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <set>

using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    int N; cin >> N;
    cout << (N / 2) * ((N + 1) / 2) << "\n";
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  string S; cin >> S;
  int k = S.length();
  int lose = 0; rep(i,k) if (S[i]=='x') lose++;
  string result = lose<=7 ? "YES" : "NO";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
/* coordinate_compress_2D.cpp
    2Dの座標圧縮を行う

    verified: [AOJ] DSL_4_A Union of Rectangles
        http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_4_A&lang=ja
*/

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

/* compress
    (X1,Y1),(X2,Y2)という二点で表されるもの（長方形や直線など）について、行か列の片方（X1とX2 or Y1とY2）を座標圧縮する（副作用）
    返り値: ソートされ重複要素を除いた値
    計算量: O(n log n)
*/
template <typename T>
vector<T> compress(vector<T> &C1, vector<T> &C2) {
    vector<T> vals;
    int N = (int)C1.size();
    for (int i = 0; i < N; i++) {
        for (T d = 0; d <= 1; d++) {  // その位置と、一つ隣を確保(隣を確保しないと空白が埋まってしまうことがある)
            T tc1 = C1[i] + d;
            T tc2 = C2[i] + d;
            vals.push_back(tc1);
            vals.push_back(tc2);
        }
    }
    // ソート
    sort(vals.begin(), vals.end());
    // 隣り合う重複を削除(unique), 末端のゴミを削除(erase)
    vals.erase(unique(vals.begin(), vals.end()), vals.end());
    for (int i = 0; i < N; i++) {
        C1[i] = lower_bound(vals.begin(), vals.end(), C1[i]) - vals.begin();
        C2[i] = lower_bound(vals.begin(), vals.end(), C2[i]) - vals.begin();
    }
    return vals;
}

using ll = long long;
int main() {
    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (x >= a[i]) {
            x -= a[i];
            ans++;
        } else {
            x = 0;
            break;
        }
    }
    if (x > 0) {
        ans--;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
ans = 0
for b in B:
    a_max = bisect.bisect_left(A, b)
    c_min = bisect.bisect_right(C, b)
    ans += a_max * (N - c_min)
print(ans)

Measured memory_bytes: 23232
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;


int main() {
    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);



    ll a, b;
    cin >> a >> b;
    ll ans = 0;
    set<ll> aa, bb;

//    if (a % 2 == 0) {
//        aa.insert(2);
//        while (a % 2 == 0) a /= 2;
//    }
//
//
//    if (b % 2 == 0) {
//        bb.insert(2);
//        while (b % 2 == 0) b /= 2;
//    }

    for (ll i = 2; i < sqrt(a) + 1; i++) {
        if (a % i == 0) {
            aa.insert(i);
            while (a % i == 0) a /= i;
        }
    }

    for (ll i = 2; i < sqrt(b) + 1; i++) {
        if (b % i == 0) {
            bb.insert(i);
            while (b % i == 0) b /= i;
        }
    }

    if (a > 1) aa.insert(a);
    if (b > 1) bb.insert(b);
    for (ll e : aa) {
        ans += (bb.find(e) != bb.end());
    }

    cout << ans + 1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define PI 3.14159265359
using namespace std;
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 (b<a) {a = b; return 1;} return 0;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
vector<int> Eratosthenes(const int N)
{
    vector<bool> is_prime(N+1, true);
    vector<int> P;
    for(int i=2; i<=N; i++) {
        if (is_prime[i]) {
            for(int j=2*i; j<=N; j+=i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}

int main() {
    int n,m,a,b;
    cin >> n >> m;
    vector<int> res(n);
    rep(i,m) {
        cin >> a >> b;
        res[a-1]++;
        res[b-1]++;
    }
    rep(i,n) {
        cout << res[i] << "\n";
    }
}


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

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var vi = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var even = new Dictionary<int, int>();
            var odd = new Dictionary<int, int>();
            for (var i = 0; i < vi.Length; i++)
            {
                if (i % 2 == 0)
                {
                    if (even.ContainsKey(vi[i])) even[vi[i]]++;
                    else even.Add(vi[i], 1);
                }
                else
                {
                    if (odd.ContainsKey(vi[i])) odd[vi[i]]++;
                    else odd.Add(vi[i], 1);
                }
            }
            var evenOrder = even.Select(dict => new { X = dict.Key, Count = dict.Value }).OrderByDescending(x => x.Count).ToArray();
            var oddOrder = odd.Select(dict => new { X = dict.Key, Count = dict.Value }).OrderByDescending(x => x.Count).ToArray();

            var evenMax = evenOrder[0].Count;
            var oddMax = oddOrder[0].Count;
            if (evenOrder[0].X == oddOrder[0].X)
            {
                if (evenOrder[0].Count > oddOrder[0].Count)
                {
                    oddMax = oddOrder.Length > 1 ? oddOrder[1].Count : 0;
                }
                else if (evenOrder[0].Count < oddOrder[0].Count)
                {
                    evenMax = evenOrder.Length > 1 ? evenOrder[1].Count : 0;
                }
                else
                {
                    var tmpEven = evenOrder.Length > 1 ? evenOrder[1].Count : 0;
                    var tmpOdd = oddOrder.Length > 1 ? oddOrder[1].Count : 0;
                    if (tmpEven > tmpOdd) evenMax = tmpEven;
                    else oddMax = tmpOdd;
                }
            }

            var answer = vi.Length - evenMax - oddMax;
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 30812
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] data = new int[m][4];
		for(int i = 0; i < m; i++) {
			data[i][0] = i;
			data[i][1] = Integer.parseInt(sc.next());
			data[i][2] = Integer.parseInt(sc.next());
			data[i][3] = 1;
		}
		Arrays.sort(data, (x,y) -> x[1] == y[1] ? x[2]-y[2] : x[1] - y[1]);
		for(int i = 1; i < m; i++) {
			if(data[i][1] == data[i-1][1]) {
				data[i][3] = data[i-1][3] + 1;
			}
		}
		Arrays.sort(data, (x,y) -> x[0] - y[0]);
		StringBuilder string = new StringBuilder();
		for(int i = 0; i < m; i++){
			string.append(String.format("%06d%06d\n", data[i][1], data[i][3]));
		}
		System.out.print(string.toString());
	}

}

Measured memory_bytes: 108228
n = int(input())
count = [[[0 for x in range(10)] for x in range(3)] for x in range(4)]

for i in range(n):
    b, f, r, v = map(int, input().split())
    count[b-1][f-1][r-1] += v

for i in range(4):
    for j in range(3):
        print(" " + " ".join(map(str, count[i][j])))

    if i != 3:
        print("#"*20)



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

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

    ll ans = K;
    rep(i, N - 1) {
        ans *= K - 1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
  {
  char s[3];
  cin>>s;
  if(s[0]!=s[1]&&s[1]!=s[2]&&s[0]!=s[2])
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  }


Measured memory_bytes: 3588
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
int a,b;
string s;
int main(){
  cin >> a >> b;
  cin >> s;
  string ans = "Yes";
  REP(i,a){
    if(s[i]<'0'||s[i]>'9') ans = "No";
  }
  if(s[a]!='-') ans = "No";
  REP(i,b){
    if(s[a+1+i]<'0'||s[a+1+i]>'9') ans = "No";
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
/* ex 7_1
   potter0723sw */

#include <stdio.h>

typedef struct point{
    int x_elem;
    int y_elem;
}point;

point shift_point(point pre, int x_shift, int y_shift){
    point post;
    post.x_elem = pre.x_elem + x_shift;
    post.y_elem = pre.y_elem + y_shift;
    return post;
}

int main(void){
    int dif_x, dif_y;
    point point_a, point_b, point_c, point_d;
    scanf("%d %d %d %d", &point_a.x_elem, &point_a.y_elem, &point_b.x_elem, &point_b.y_elem);
    dif_x = point_a.x_elem - point_b.x_elem;//aからbへのx座標の動き
    dif_y = point_a.y_elem - point_b.y_elem;//y座標の動き
    point_c = shift_point(point_b, dif_y, -dif_x);//３つ目の頂点は２つ目からx方向にdif_y,y方向に-dif_x動けば良い 
    point_d = shift_point(point_a, dif_y, -dif_x);//４つ目は１つ目から上と同じ動きをすれば良い
    printf("%d %d %d %d\n", point_c.x_elem, point_c.y_elem, point_d.x_elem, point_d.y_elem);
    return 0;
}


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

if a > 0 :
    ans = "Positive"
elif a <= 0 and b >= 0 :
    ans = "Zero"
elif b < 0 and (b-a) % 2 == 0 :
    ans = "Negative"
else :
    ans = "Positive"
print(ans)


Measured memory_bytes: 2940
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから----------- 
int main(void){
    int k;
    cin >> k;
    string s;
    cin >> s;

    if(s.size() <= k){
        cout << s << endl;
    } else{
        cout << s.substr(0, k) << "..." << endl;
    }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<vector<int> > data;
int diameter=0;
int dfs(int vertex, int last){
    vector<int> h;
    int mx1=0, mx2=0;
    for (int i=0; i < data[vertex].size(); i++){
        int to = data[vertex][i];
        if (to == last) continue;
        int R = dfs(to, vertex);
        if (R > mx1){
            mx2 = mx1;
            mx1 = R;
        }
        else if (R > mx2) mx2 = R;
    }
    diameter = max(diameter, mx1+mx2);
    return mx1+1;
}
main()
{
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    data.resize(n, {});
    for (int i=0; i < n-1; i++){
        int u, v;
        cin >> u >> v;
        data[u-1].push_back({v-1});
        data[v-1].push_back({u-1});
    }
    dfs(0,-1);
    diameter++;
    if (diameter % 3 == 2) cout << "Second";
    else cout << "First";
}

Measured memory_bytes: 23168
//単一始点最短路 (Bellman Ford)
//ある 2 頂点間の距離を,その間の辺を使って短く更新できる限り更新するということを繰り返します．
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

template< typename T >
struct edge {
	int src, to;
	T cost;
	edge(int _to, T _cost) : src(-1), to(_to), cost(_cost) {}
	edge(int _src, int _to, T _cost) : src(_src), to(_to), cost(_cost) {}
	edge &operator=(const int &x) {
		to = x;
		return *this;
	}
	operator int() const { return to; }
};

template< typename T>
struct node {
	vector<edge<T>> edges;
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< node< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

//s start node
template< typename T >
vector< T > bellman_ford(const Edges< T > &edges, int V, int s) {
    const auto INF = numeric_limits< T >::max();
    vector< T > dist(V, INF);
    dist[s] = 0;
    for(int i = 0; i < V - 1; i++) {
        for(auto &e : edges) {
            if(dist[e.src] == INF) continue;
            dist[e.to] = min(dist[e.to], dist[e.src] + e.cost);
        }
    }
    for(auto &e : edges) {
        if(dist[e.src] == INF) continue;
        if(dist[e.src] + e.cost < dist[e.to]) return vector< T >();
    }
    return dist;
}

int main() {
    //aoj_grl_1_b
	  //https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/1/GRL_1_B
    ll V,E; cin>>V>>E;
    ll r; cin>>r;
    Edges<ll> edges;
    REP(e,E){
        int s,t; cin>>s>>t;
		    ll d; cin>>d;
        edges.emplace_back(s,t,d);
    }

    auto result = bellman_ford(edges, V, r);
    if (result.empty()) cout<<"NEGATIVE CYCLE"<<endl;
    else {
        for(const auto& d:result){
            if (d==numeric_limits<ll>::max()) cout<<"INF"<<endl;
            else cout<<d<<endl;;
        }
    }
    return 0;
}



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

using namespace std;

typedef long long ll;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

vector <int> series = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main() {
  int k; cin >> k;
  k--;
  cout << series[k] << '\n';
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    bool flag = true;
    int cx = 0, cy = 0, ct = 0;
    for (int i = 0; i < n; i++) {
        int t, x, y;
        cin >> t >> x >> y;
        int d = t - ct;
        int hoge = abs(x - cx) + abs(cy - y);
        if (hoge > d) {
            flag = false;
            break;
        }
        if ((d - hoge) % 2 == 1) {
            flag = false;
            break;
        }
    }
    cout << (flag ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#include <bits/stdc++.h>
#define pb(X) push_back(X)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
using namespace std;

int n, a, b, c, d, q, ans;

int main() {
	INIT
	cin >> n;
	vector<long long > A(n);
	long long ans = 0;
	for (int i = 0; i < n; ++i) {
		cin >> A[i];
		if (A[i] < 0) {
			++b;
			A[i] *= -1;
		}
		ans += A[i];
			
	}
	if(b % 2) {
		long long t = *min_element(A.begin(), A.end());
		ans -= 2 * t;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
// Aizu 0232: Life Game
// 2017.9.9 bal4u@uu

#include <stdio.h>
#include <string.h>

#define MAX 5000

typedef struct { int e, a; } T;

int y;
int v[5], x;
T n[52]; int z;
double p[MAX+3][52];

int main()
{
	int i, j, k, max;
	double ans;

	while (scanf("%d%d%d", &x, &y, &z) && x) {
		for (i = 1; i <= x; i++) scanf("%d", v+i);
		memset(n, 0, sizeof(n));
		for (max = 0, i = 1; i <= z; i++) {
			scanf("%d", &k), scanf("%d%d", &n[k].e, &n[k].a);
			if (n[k].e == 2) max += n[k].a;
		}
		memset(p, 0, sizeof(p));
		p[0][0] = 1.0;
		for (k = 0; k < y; k++) for (j = 0; j <= max; j++) {
			if (p[j][k] == 0) continue;
			for (i = 1; i <= x; i++) {
				int j2 = j;
				int k2 = k + v[i]; if (k2 > y) k2 = y;
				if      (n[k2].e == 1) { k2 += n[k2].a; if (k2 > y) k2 = y; }
				else if (n[k2].e == 2)   j2 += n[k2].a;
				else if (n[k2].e == 3) { j2 -= n[k2].a; if (j2 < 0) j2 = 0; }
				p[j2][k2] += p[j][k] / x;
			}
		}
		for (ans = 0, j = 1; j <= max; j++) ans += j * p[j][y];
		printf("%d\n", (int)ans);
	}
	return 0;
}

Measured memory_bytes: 3744
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑





int main() {
	int n, m;
	cin >> n >> m;
	if (n <= 5) { cout << 0 << endl; }
	else if (6 <= n && n <= 12) { cout << m / 2 << endl; }
	else { cout << m << endl; }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int H, W;
  cin >> H >> W;
  for (int w = 0; w <= W+1; w++) cout << "#";
  cout << endl;
  for (int h = 0; h < H; h++) {
    cout << "#";
    string a;
    cin >> a;
    cout << a << "#" << endl;
  }
  for (int w = 0; w <= W+1; w++) cout << "#";
  cout << endl;
  return 0;
}


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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;
  LL a, b, n;
  cin >> a >> b >> n;
  cout << (a * min(b - 1, n)) / b << "\n";
  return 0;
}

Measured memory_bytes: 3648
using System;
using System.Collections;
class Node
{
    public bool Visited { get; set; }
    public ArrayList Children = new ArrayList();
    public ArrayList EdgeLength = new ArrayList();
    public int x = int.MaxValue;
}
static class DFS
{
    public static void DepthFirstSearch(Node root)
    {
        if (root.Visited)
            return;
        {
            if (root.x == int.MaxValue)
                root.x = 0;
            for (int i = 0; i < root.Children.Count; i++)
            {
                if (((Node)root.Children[i]).x == int.MaxValue || ((Node)root.Children[i]).x == root.x + (int)root.EdgeLength[i])
                    ((Node)root.Children[i]).x = root.x + (int)root.EdgeLength[i];
                else
                {
                    Console.WriteLine("No");
                    Environment.Exit(0);
                }
            }
        }
        root.Visited = true;
        if (root.Children.Count != 0)
        {
            for (int i = 0; i < root.Children.Count; i++)
            {
                DepthFirstSearch((Node)root.Children[i]);
            }
        }
    }
}
class Program
{
    static int Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int n, m;
        n = int.Parse(str[0]);
        m = int.Parse(str[1]);
        Node[] nodes = new Node[n];
        for (int i = 0; i < n; i++)
            nodes[i] = new Node();
        for (int i = 0; i < m; i++)
        {
            str = Console.ReadLine().Split(' ');
            int l, r, d;
            l = int.Parse(str[0]) - 1;
            r = int.Parse(str[1]) - 1;
            d = int.Parse(str[2]);
            nodes[l].Children.Add(nodes[r]);
            nodes[l].EdgeLength.Add(d);
            nodes[r].Children.Add(nodes[l]);
            nodes[r].EdgeLength.Add(-d);
        }
        for (int i = 0; i < n; i++)
            DFS.DepthFirstSearch(nodes[i]);
        Console.WriteLine("Yes");
        return 0;
    }
}

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

// int/long:		-2147483648 - 2147483648 (-2^31 <= int < 2^31)
// long/long long:	-9223372036854775808 - 9223372036854775807 (-2^63 <= long < 2^63)
#define	INF (1<<29)
//536870912

#define	MOD 1000000007

int	main() {
	for (int i=0; i<2; i++) {
		char c;
		cin >>c;
		if ('9'==c) {
			cout <<"Yes" <<endl;
			return 0;
		}
	}
	cout <<"No" <<endl;
	return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <iostream>

using namespace std;

bool check(int m, int i, int v, int A[], int n) {

	if (v == m)
		return true;
	if (i == n || v > m)
		return false;

	return check(m, i + 1, v, A, n) || check(m, i + 1, v + A[i], A, n);
}

int main() {

	int n;
	scanf("%d", &n);
	int A[n];
	for (int i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
	}

	int q;
	scanf("%d", &q);
	int m[q];
	for (int i = 0; i < q; ++i) {
		scanf("%d", &m[i]);
	}

	for (int i = 0; i < q; ++i) {
		if (check(m[i], 0, 0, A, n)) {
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3212
N,K = map(int,input().split())
S = input()

B = 0
for n in range(N-1):
  if S[n]!=S[n+1]:
    B+=1

S = N-1 - B

if 2*K>=B:
  Sm = N-1
else:
  Sm = S+2*K
  
print(Sm)

Measured memory_bytes: 39536
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

int main(){
  string s, t;
  cin >> s >> t;

  int l = s.size();

  map<char, char> st, ts;

  REP(i, l){
    st[s[i]] = t[i];
    ts[t[i]] = s[i];
  }

  int rec = 0;

  REP(i, l){
    if(st[s[i]] != t[i] || ts[t[i]] != s[i]) rec++;
  }
  if(rec) cout << "No";
  else cout << "Yes";
  return 0;
}


Measured memory_bytes: 776
import sys
import math
import bisect

def main():
    s = input()
    ans = True
    for i in range(1, len(s)):
        if s[i] == s[i-1]:
            ans = False
    if ans:
        print('Good')
    else:
        print('Bad')
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> years = {111, 222, 333, 444, 555, 666, 777, 888, 999};
  for (int i = 0; i < 9; i++) {
    if (N > years.at(i)) {
      continue;
    } else {
      cout << years.at(i) << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using Graph = vector<vector<int>>;
using Wgraph = vector<vector<pair<int, long long int>>>;
constexpr long long int INF = 1001001001001001LL;
constexpr long long int MOD = 1000000007LL;
constexpr double PI = 3.1415926535897932;
constexpr long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
constexpr long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = 1; i <= (n); i++)
#define DREP(i,n) for(int i = (n)-1; i >= 0; i--)
#define SREP(i,s,t) for(int i = s; i < t; i++)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define PB push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

bool C(vector<lint> &a, lint k, lint id) {
  // カード a[id] が必要かどうか (必要なら true)
  // a[id] が必要 <=> a[id] 以外で部分和 x (k - a[i] <= x < k) が作れるか
  
  lint n = a.size();
  vector<vector<lint>> dp(n + 1, vector<lint> (k + 1, false));
  dp[0][0] = 1;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j <= k; j++) {
      if(dp[i][j] == 0) continue;

      // 取らない
      dp[i + 1][j] = 1;

      if(i == id) continue;
      lint nj = j + a[i];
      if(nj > k) continue;
      dp[i + 1][nj] = 1;
    }
  }

  bool ret = false;
  for(int x = max(0LL, k - a[id]); x < k; x++) {
    if(dp[n][x]) ret = true;
  }
  
  return ret;
}

int main(){
  
  int n, k; cin >> n >> k;
  vector<lint> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];

  sort(ALL(a));
  
  // 区間 [0, lb] が不必要
  lint lb = -1;
  lint ub = n;

  while(ub - lb > 1) {
    lint mid = (ub + lb) / 2;

    if(!C(a, k, mid)) { // もしa[lb] が不必要なら
      lb = mid;
    } else {
      ub = mid;
    }
  }

  cout << (lb + 1) << endl;
  return 0;
}


Measured memory_bytes: 195928
# include<bits/stdc++.h>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1000000000
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
# define AU(i,x)    for(auto i=x.begin(); i!=x.end(); ++i)
# define ALL(A) A.begin(),A.end()
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;
const int N=100005;
///Code begin..................................................................
inline LL Scan() {
    LL x=0;int f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

int a[105][15], b[105][15];

int main()
{
    int n;
    scanf("%d",&n);
    FOR(i,1,n) FOR(j,0,9) {
        scanf("%d",&a[i][j]);
    }
    FOR(i,1,n) FOR(j,0,10) {
        scanf("%d",&b[i][j]);
    }
    int top=(1<<10)-1;
    int ans=-INF;
    FOR(i,1,top) {
        int tmp=0;
        FOR(j,1,n) {
            int num=0;
            FOR(k,0,9) if (a[j][k]&&(i&(1<<k))) ++num;
            tmp+=b[j][num];
        }
        ans=max(ans,tmp);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int N;
	scanf("%d", &N);
	int V[N];
	int C[N];
	int sum=0;
	for(int i=0; i<N; i++) {
		scanf("%d", &V[i]);
	}
	for(int i=0; i<N; i++) {
		scanf("%d", &C[i]);
		if((V[i]-C[i])>0) {
			sum += V[i]-C[i];
		}
	}
	printf("%d\n", sum);
	return 0;
}

	


Measured memory_bytes: 128
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int t = 0;
	while (a > 0 && c > 0) {
		c -= b;
		if (c <= 0) { break; }
		a -= d;
		if (a <= 0) { t = 1; break; }
	}
	if (t == 0) cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) ((int)(v).size())
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1);

template <class T>
inline bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(void) {
    int n, m;
    cin >> n >> m;
    int ml = 1, mr = n;
    rep(i, m) {
        int l, r;
        cin >> l >> r;
        chmax(ml, l);
        chmin(mr, r);
    }
    if (ml > mr)
        cout << 0 << endl;
    else
        cout << mr - ml + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
// Best practice

#include<bits/stdc++.h>

#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;


// Code from Here -------------------------------------------------------------------------------


signed main() {
	tezz

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

	string s;
	int k;
	cin >> k;
	cin >> s;
	int n=s.length();
	if(n>k){
		cout << s.substr(0,k);
		cout << "...";
	}
	else{
		cout << s;
	}

	return 0;
}  


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

int main() {
  string A;
  cin >> A ;
  
  if(A == "ABC"){
  cout << "ARC" << endl;
  }else{
    cout << "ABC" << endl;
  }
}

Measured memory_bytes: 3624
import java.util.Scanner

object Main {
  def main(args:Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val x, a, b = sc.nextInt()

    if ((x - a).abs < (x - b).abs) {
      println("A")
    } else {
      println("B")
    }
  }
}

Measured memory_bytes: 25556
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

S = input().rstrip()

answer = 0
while S:
    if len(S) < 2:
        break
    L,R = S[0],S[-1]
    if L == R:
        S = S[1:-1]
        continue
    if L == 'x':
        answer += 1
        S = S[1:]
        continue
    if R == 'x':
        answer += 1
        S = S[:-1]
        continue
    answer = -1
    break

print(answer)

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

int main()
{
    string S;
    string T;
    cin >> S >> T;
    int ans = 0;
    for (int i = 0; i < 3; ++i)
    {
        if (S[i] == T[i])
        {
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main() {
    int N, Q; cin >> N >> Q;
    string S; cin >> S;
    vector<int> a(N+1, 0);
    for (int i = 1; i < N; i++) {
        a[i+1] = a[i];
        if (S[i-1] == 'A' && S[i] == 'C') a[i+1]++;
    }

    vector<int> ans(Q);
    for (int i = 0; i < Q; i++) {
        int l, r; cin >> l >> r;
        ans[i] = a[r]-a[l];
    }
    for (int i = 0; i < Q; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 1792
#include<iostream>
#include<bits/stdc++.h>
#define read_in_arr(a, n) for(int i=0;i<n;i++){ cin>>a[i];}
#define print_arr(a, n) for(int i=0;i<n;i++){ cout<<a[i];}
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
	int x, y;
	cin>>x>>y;
	if(((4*x)-y)%2==0 && (y-(2*x))%2==0 && ((4*x)-y)>=0 && (y-(2*x))>=0 ){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3652
X, Y = gets.split.map(&:to_i)
M = 10**9 + 7

require 'matrix'

def mpow(x, n)
  ret = 1
  while n > 0
    if n.even?
      x = x * x % M
      n >>= 1
    else
      ret = ret * x % M
      n -= 1
    end
  end
  ret
end

if (X + Y) % 3 != 0
  puts 0
else
  a, b = Matrix[[2, 1], [1, 2]].lup.solve([X, Y]).to_a.map(&:to_i)
  if a < 0 || b < 0
    puts 0
  else
    f = ->(a, b){(a .. b).inject(1){|r, x| r * x % M}}
    n = a + b
    k = [a, b].min
    puts f[n - k + 1, n] * mpow(f[1, k], M - 2) % M
  end
end

Measured memory_bytes: 2684
function Main(input){
    input = input.split(" ").map(Number);
    for(var i=0;input[0]%2==0&&input[1]%2==0&&input[2]%2==0&&i!=1000;i++){
        //console.log(input);
        var mem = [input[0],input[1],input[2]];
        input[0] = mem[1]/2+mem[2]/2;
        input[1] = mem[0]/2+mem[2]/2;
        input[2] = mem[1]/2+mem[2]/2;
    }
    if(i==1000) i=-1;
    console.log(i)
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

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

string p[] = {"maerd", "remaerd", "esare", "resare"};

int main(){
  string S; cin >> S;
  reverse(S.begin(), S.end());
  string T = "";
  while(S != T){
    bool cnt = false;
    int tl = T.size();
    for(int i = 0; i < 4; i++){
      if(S.size() < p[i].size() + tl) continue;
      if(p[i] == S.substr(tl, p[i].size())){
        T += p[i];
        cnt = true;
      }
      
    }
    if(!cnt) break;
  }
  cout << (S == T?"YES":"NO") << endl;
}

Measured memory_bytes: 640
use proconio::input;

fn main() {
    input! {
        x: f64,
    }

    let mut s = 100.0_f64;
    let mut r = 0;

    while s < x {
        s = (s * 1.01).trunc();
        r += 1;
    }

    println!("{}", r);
}


Measured memory_bytes: 2704
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int ans = 0;
    for(int i = 1; i<10; i++){
        if(N <= i * 111){
            ans = i*111;
            break;
        }
    }

    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 256
a,b,c , x,y =  map(int , input().split())




u = c*min(x ,  y)*2
uu = max(x , y) * 2 * c
ans = min(u , min(x , y) * a + min(x,y)*b)


resx = x - min(x,y)
resy = y - min(x,y)

ans = ans + (resx * a) + (resy * b)
ans = min(ans  , uu)
print(ans)


Measured memory_bytes: 3064