akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
         int K,S;
        cin >> K >> S;
        int ans = 0;
        for(int x = 0; x <= K; x++){
            for(int y = 0; y <= K; y++){
                int z = S - x - y;
                if(0 <= z && z <= K){
                    ans = ans + 1;
                    }
                }
            }

        cout << ans << endl;
        }


Measured memory_bytes: 256
D, G = map(int, input().split())
P = []

for i in range(D):
  p, c = map(int, input().split())
  P.append((p, c))

ans = float("inf")

for i in range(2 ** D):
  score = 0
  index = []
  attempt = 0

  for j in range(D):
    if ((i >> j) & 1):
      p, c = map(int, P[j])
      score += (c + p * (100 * (j+1) ))
      attempt += p
      index.append(j)

  if score >= G: # コンプリートボーナスのみでスコアを超えている場合
    ans = min(ans, attempt)
    continue

  for i in range(D)[::-1]: # 個別に計算して足していく
    if score >= G: # スコアを達成した場合は終了
      break

    if i in index: # コンプリートしてたりするやつはスキップ
      continue

    p, c = map(int, P[i])
    for j in range(p):
      score += 100 * (i+1)
      attempt += 1
      if score >= G: # スコアを達成した場合は終了
        ans = min(ans, attempt)
        break
    else:
      index.append(i)

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
  int n;cin>>n;
  ll ans=1;
  repi(i,1,n+1){
    ans*=i;
    ans%=1000000007;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << - 1 << endl;}
void unhap() {cout << ":(" << endl;}

int main() {
  string s;
  cin >> s;
  vector<string> a(s.size() - 2);
  int ans = 1000;
  for (int i = 0; i < s.size() - 2; i++) {
    a.at(i).push_back(s.at(i));
    a.at(i).push_back(s.at(i + 1));
    a.at(i).push_back(s.at(i + 2));
    ans = min(ans,
              max(stoi(a.at(i)) - 753, 753 - stoi(a.at(i))));
  }
  cout << ans << endl;
}

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

int con(int x, int y){
    if (x == y) return 1;
    if (x != y) return 0;
}

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if (con(A, B) + con(A, C) + con(B, C) == 1){
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
H, W, K = map(int, input().split())

c = []
for i in range(H):
    c.append(list(input()))

ans = 0

for i in range(1<<H):
    for j in range(1<<W):
        v = 0
        for k in range(H):
            for l in range(W):
                if c[k][l] == '#' and i >> k & 1 == 0 and j >> l & 1 == 0:
                    v += 1
        if v == K:
            ans += 1

print(ans)

Measured memory_bytes: 9152
function Main (input) {
    const houses = input.split(' ');
    if((houses[2] - houses[0]) * (houses[1] - houses[2]) >= 0) {
        console.log('Yes');
    } else {
        console.log('No');
    }
}

Main(require('fs').readFileSync('/dev/stdin', 'utf-8'));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i=0; i<N; i++){
        cin >> vec.at(i);
    }

    int count=0;
    for(int i=0; i<N; i++){
        if(vec.at(i)==i+1){
            count++;
        }
    }
    if(count == N){
        cout << "YES" << endl;
        return 0;
    }

    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            swap(vec.at(i),vec.at(j));
            int count =0;
            for(int k=0; k<N; k++){
                if(vec.at(k) == k+1){
                    count++;
                }
            }
            if(count ==N){
                cout << "YES" << endl;
                return 0;
            }
            swap(vec.at(i),vec.at(j));
        }
    }

    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  
  ll N;
  cin>>N;
    ll eve=0;
  ll fif=0;
  ll index=1;
  if(N%2==1){
    cout<<0<<endl;
  }

else{
  
  while(N>=power(2,index)){
eve+=(N/power(2,index));
    index++;
  }
  index=1;

  while(N>=power(5,index)){
    fif+=(N/power(5,index))/2;
    index++;
  }
 
  if(fif==0&&N>=5){
    fif++;
  }

  cout<<min(eve,fif)<<endl;
}
}


  

    



Measured memory_bytes: 256
n,m=map(int,input().split())
a=[0]*n
b=[0]*n
for i in range(n):
  a[i],b[i]=map(int,input().split())
c=[0]*m
d=[0]*m
for j in range(m):
  c[j],d[j]=map(int,input().split())
e=[0]*n
g=[0]*m
for k in range(n):
  for l in range(m):
    g[l]=abs(a[k]-c[l])+abs(b[k]-d[l])
  e[k]=int(g.index(min(g))+1)
  print(e[k])

Measured memory_bytes: 3064
n , m , x = map(int , input().split())
book = [list(map(int , input().split())) for _ in range(n)]

A = []
C = []
ans = float("Inf")

for c , *a in book:
    C.append(c)
    A.append(a)

for bit in range(1<<n):
    algo = [0]*m
    cost = 0
    for i in range(n):
        if bit & (1<<i):
            cost += C[i]
            for idx , a in enumerate(A[i]):
                algo[idx] += a
    if all([True if a >= x else False for a in algo]):
        ans = min(ans , cost)

print(ans if ans != float("Inf") else -1)    

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

bool nonprime[1000001] = {};
int accum[1000001] = {};

int main(){
    nonprime[0] = nonprime[1] = true;
    for(int i = 2; i <= 1000000; i++){
        if(!nonprime[i]){
            for(int j = i+i; j <= 1000000; j+=i){
                nonprime[j] = true;
            }
        }
    }

    for(int i = 2; i <= 1000000; i++){
        if(nonprime[i-1]){
            accum[i] = accum[i-1];
        }else{
            accum[i] = accum[i-1] + 1;
        }
    }

    while(1){
        int n;
        cin >> n;
        if(n == 0)  break;

        int ans = 0;

        for(int i = 0; i < n; i++){
            int p, m;
            cin >> p >> m;

            int cnt = accum[min(p+m, 1000000)] - accum[max(0, p-m)];
            if(p+m <= 1000000 && !nonprime[p+m])    cnt++;

            if(cnt == 0)    ans--;
            else            ans += cnt-1;
        }
        
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 7872
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>N;
    ll ans = 0;
    rep(i,N){
        cin>>A;
        --A;
        ans += A;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()    
    #define bit(n) (1LL<<(n))
    template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
    template<class T> inline bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
#pragma endregion library

int main(){
    ll a,b,c,d; cin >> a >> b >> c >> d;
    ll mx = max({a*c, a*d, b*c, b*d});
    cout << mx << '\n';
    
}


Measured memory_bytes: 3644
[a, b, k] = list(map(int, input().split()))

def do(a, b):
    if a % 2 == 1:
        a -= 1
    a = a // 2
    return a, b + a

flag = True
for i in range(k):
    if flag:
        a, b = do(a, b)
        flag = False
    else:
        b, a = do(b, a)
        flag = True

print(a, b)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here! 
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        
        // ans: n以下の(a, b)で、a % b >= kになるパターン数
        long ans = 0;
        
        if (k == 0) {
            System.out.println((long)n * n);
            return;
        }
        
        // 2 5 8 ... 
        // 2 3 6 7 ...
        // 2 3 4 7 8 9
        
        // [k, i]
        
        // 15 / 4 3
        // 10 / 3 3
        
        for (int i = k + 1; i <= n; i++) {
            long block = n / i;
            long start = block * i + (k-1);
            long end = n;
            
            ans += block * (i-k);
            if (start <= end) {
                ans += end - start;
            }
        }
        System.out.println(ans);
    }
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W;
	cin >> H >> W;
	vector<string> s(H);
	for (int i = 0; i < H; i++) {
		cin >> s[i];
	}

	vector< vector<ll> > dp(H, vector<ll>(W, 0));
	dp[0][0] = 1;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '#') {
				dp[i][j] = 0;
				continue;
			}
			if (j + 1 < W) {
				(dp[i][j + 1] += dp[i][j]) %= MOD;
			}
			if (i + 1 < H) {
				(dp[i + 1][j] += dp[i][j]) %= MOD;
			}
		}
	}
	cout << dp[H - 1][W - 1] << endl;
	return 0;
}

Measured memory_bytes: 9216
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//typedef int ll;
typedef long double ld;
#define int ll
#define pb push_back
using vint = vector<int>;
using pii = pair<int,int>;
using pdd = pair<ld,ld>;
using vpii = vector<pii>;
#define F first
#define S second
const int N = 2e5+5;//(1 << 18) + 5;
//const ll inf = 1e18+7;
const int mod = 998244353;
const int Inf = 1e9+7;
const ld eps = 1e-9;
#ifndef M_PI
#define M_PI 3.1415926535
#endif
 
void io()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cerr.tie(NULL);
//	freopen("game.in", "r", stdin);
//	freopen("game.out", "w", stdout);
//  cout << setprecision(10) << fixed;
}
 
int n, m, k, a[N], b[N], pb[N];

signed main()
{
	io();
	cin >> n >> m >> k;
	for (int i = 1; i <= n; ++i)
		cin >> a[i];
	for (int i = 0; i < m; ++i)
	{
		cin >> b[i];
		pb[i + 1] = pb[i] + b[i];
	}
	int t = 0, ans = 0;
	for (int i = 0; i <= n; ++i)
	{
		t += a[i];
		if (t > k)
			break;
		int lb = 0, rb = m + 1;
		while (rb - lb > 1)
		{
			int m = (lb + rb) >> 1;
			if (pb[m] <= k - t)
				lb = m;
			else
				rb = m;
		}
		ans = max(ans, i + lb);
	}
	cout << ans;
}

Measured memory_bytes: 8292
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		// 所持しているカードの入力

		ArrayList<HashMap<String, String>> existCards = new ArrayList<>();

		for(int i=0; i<n; i++) {
			HashMap<String, String> card = new HashMap<>();
			card.put("mark", sc.next());
			card.put("rank", sc.next());
			existCards.add(card);
		}

		sc.close();

		// 抜けているカードを割り出す
		ArrayList<HashMap<String, String>> notExistsCards = new ArrayList<>();

		// １つづつカードを調べる
		String marks[] = {"S", "H", "C", "D"};
		for(String mark : marks) {
			for(int i=1; i<=13; i++) {
				HashMap<String, String> checkCard = new HashMap<>();
				checkCard.put("mark", mark);
				checkCard.put("rank", String.valueOf(i));
				if(existCards.indexOf(checkCard) == -1) {
					notExistsCards.add(checkCard);
				}
			}
		}

		// 出力
		for(HashMap<String, String> card : notExistsCards) {
			System.out.print(card.get("mark") + " " + card.get("rank") + "\n");
		}

	}

}


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

int main(){
  int n,a, now;
  cin >> n;
  int ball[n];
  int cnt[n+1] = {0};
  long long sum=0,ans,b;
  rep(i,n){
    cin >> a;
    ball[i] = a;
    cnt[a]++;
  }
  rep(i,n+1){
    b = cnt[i];
    if(b>1){
      sum += b*(b-1)/2;
    }
  }
  rep(i,n){
    b = cnt[ball[i]];
    ans = sum;
    if(b>1){
      ans -= (b - 1);
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b[1000],c=0;
  cin>>a;
  for(int i=0;i<a;i++){ 
    cin>>b[i];
    c+=b[i];
  }
  sort(b,b+a);
  if(b[a-1]<c-b[a-1]) cout<<"Yes\n";
  else cout<<"No\n";
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    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;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};
  

int main()
{
  int n; cin >> n;
  for(int i = 1; i <= 10; ++i) {
    if(1000*i >= n) {
      cout << 1000*i-n << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3624
N, K = map(int, input().split())
A = list(map(int, input().split()))

for i in range(K):
    P = [0 for _ in range(N)] + [0]
    for j in range(N):
        P[max(0, j - A[j])] += 1
        P[min(N, j + A[j] + 1)] -= 1
    A = [0 for _ in range(N)]
    for j in range(N):
        P[j + 1] += P[j]
    flag = False
    for j in range(N):
        A[j] = P[j]
        if A[j] < N:
            flag = True
    if not flag:
        break

print(*A)

Measured memory_bytes: 182336
import std.stdio;
import std.conv;
import std.algorithm;
import std.string;
import std.file;
import std.math;
 
int main() {
        string l;
        while((l = readln()).length >= 2){
                int a, b, aorg, borg, r;
                a = aorg = to!int(l.split()[0]), b = borg = to!int(l.split()[1]);
                while(b > 0){
                        a = a - (a / b) * b;
                        r = a, a = b, b = r;
                        }
                printf("%d %d\n", a, aorg / a * borg);
                }
        return 0;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

vector<l_l> calc(vector<ll> list) {
  mll m;
  for (ll i = 0; i < list.size(); i++) {
    auto v = list[i];
    m[v] += 1;
  }

  vector<l_l> r;

  auto ite = m.begin();
  for (; ite != end(m); ite++) {
    ll key = (*ite).first;
    ll val = (*ite).second;
    // cout << key << ":" << val << endl;

    r.emplace_back(make_pair(val, key));
  }

  return r;
}

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll N;
  scanf("%lld", &N);

  vector<ll> list0;
  vector<ll> list1;
  for (ll i = 0; i < N; i++) {
    ll v;
    scanf("%lld", &v);
    if (i % 2 == 0) {
      list0.emplace_back(v);
    } else {
      list1.emplace_back(v);
    }
  }

  vector<l_l> m0 = calc(list0);
  vector<l_l> m1 = calc(list1);
  sort(m0.rbegin(), m0.rend());
  sort(m1.rbegin(), m1.rend());

  if (N == 2) {
    if (list0[0] == list1[0]) {
      cout << (1) << endl;
    } else {
      cout << (0) << endl;
    }
    return 0;
  }

  ll ans = INF;

  for (ll i0 = 0; i0 < 2; i0++) {
    if (i0 >= m0.size()) {
      continue;
    }
    for (ll i1 = 0; i1 < 2; i1++) {
      if (i1 >= m1.size()) {
        continue;
      }
      ll cnt0 = m0[i0].first;
      ll cnt1 = m1[i1].first;

      ll a;
      if (m0[i0].second == m1[i1].second) {
        a = min((N / 2 - cnt0 + N / 2), (N / 2 - cnt1 + N / 2));
      } else {
        ll change0 = N / 2 - cnt0;
        ll change1 = N / 2 - cnt1;
        a = change0 + change1;
        // cout << "a@:" << (a) << endl;
      }
      ans = min(ans, a);
      // cout << "ans:" << (ans) << endl;
    }
  }

  cout << (ans) << endl;
}


Measured memory_bytes: 8716
#include <iostream>
int main(void){
	long long int dp[100][21];
	int value[100];
	int n;
	std::cin>>n;
	for(int i=0;i<n;i++){
		std::cin>>value[i];
	}
	for(int i=0;i<100;i++){
		for(int j=0;j<21;j++){
			dp[i][j]=0;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<21;j++){
			if(i==0){
				dp[i][value[i]]=1;
			}else {
				if(j+value[i]<=20 && j+value[i]>=0){
					dp[i][j]+=dp[i-1][j+value[i]];
				}
				if(j-value[i]<=20 && j-value[i]>=0){
					dp[i][j]+=dp[i-1][j-value[i]];
				}
			}
		}
	}
/*	for(int i=0;i<n;i++){
		for(int j=0;j<21;j++){
			std::cout<<dp[i][j]<<" ";
		}
		std::cout<<std::endl;
	}*/
	std::cout<<dp[n-2][value[n-1]]<<std::endl;
	return 0;
}

Measured memory_bytes: 3096
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// rの入力
		int r = sc.nextInt();
		
		// 結果の出力
		System.out.println(r * r);
		
		sc.close();
	}

}


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

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            long sum = 0;
            var ans = "Yes";

            for(int i = 0; i < s.Length; i++)
            {
                string a = "" + s[i];
                sum += int.Parse(a);
            }
            if (sum % 9 == 0) ans = "Yes";
            else ans = "No";

            Console.WriteLine(ans);





        }

        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }
        
        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }

        public static long Gcd(long a, long b)
        {
            long x = Math.Max(a, b);
            long y = Math.Min(a, b);
            if (x % y == 0) return y;
            else return Gcd(y, x % y);
        }
    }
}


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

bool check(string a,string b){
  for(int i=0;i<8;i++){
    if(a[i]=='*')continue;
    if(a[i]!=b[i])return 0;
  }
  return 1;
}

int main(){
  int n,m;
  while(1){
    cin>>n>>m;
    if(!n&&!m)break;
    string a[101],b[1001];
    int mon[1001];;
    for(int i=0;i<n;i++) cin>>a[i]>>mon[i];
    for(int i=0;i<m;i++) cin>>b[i];

    long long ans=0;
    for(int i=0;i<m;i++)
      for(int j=0;j<n;j++)
	if(check(a[j],b[i])) ans+=mon[j]; 
    cout <<ans<<endl;
  }

  return 0;
}

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

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            long a = long.Parse(str[0]);
            long b = long.Parse(str[1]);

            var v = new[] { a, b };
            while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
            long gcd = v[0];

            Console.WriteLine(a / gcd * b);
       
           


            //ここまで
        }
    }
}


Measured memory_bytes: 13140
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    vector<int> cnts(n + 1, 0);
    for (int i = 1; i <= n; ++i) {
        int x = i;
        for (int i = 2; i * i <= x; ++i) {
            int cnt = 0;
            while (x % i == 0) {
                ++cnt;
                x /= i;
            }
            cnts[i] += cnt;
        }
        if (x > 1) {
            cnts[x] += 1;
        }
    }


    const int M = 75;
    vector<long long> dp(M + 1, 0);
    dp[1] = 1;

    for (int i = 2; i <= n; ++i) {
        // cout << i << " " << cnts[i] << endl;
        int m = cnts[i];
        for (int j = M; j > 0; --j) {
            for (int k = 1; k <= m; ++k) {
                long long nj = j * 1LL * (k + 1);
                if (nj > M) {
                    break;
                }
                dp[nj] += dp[j];
            }
        }
    }

    cout << dp[M] << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;

//	(long long)√n を計算する。O(logn)で計算するから速いよ
//	実は double sqrt(double x) を使った方が高速だけど、計算誤差が気になる...
//	l_sqrtは整数のまま計算してるから誤差の心配はないよ
ll l_sqrt(ll n) {
	if (n <= 0) { return 0; }

	if (n > 256) {
		ll k = l_sqrt(n / 4) * 2;
		while ((k + 1) * (k + 1) <= n) { k++; }
		return k;
	}
	else {
		for (ll i = 16; i >= 1; i--) {
			if (i * i <= n) { return i; }
		}
	}
	return 0;
}

int main() {
	ll N; cin >> N;
	ll m = l_sqrt(N) + 1;
	ll ans = -1;
	for (ll i = 1; i <= m; i++) {
		if (N % i == 0) {
			if (ans == -1) { ans = i + (N / i); }
			ans = min(ans, i + (N / i));
		}
	}

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


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#define MOD 1000000007LL
using namespace std;

int main(){
	string s;
	cin >> s;
	int length = 0;
	for(int i = 1; i <= (s.size() - 1) / 2; i++){
		int flag = 1;
		for(int j = 0; j < i; j++){
			if(s[j] != s[j+i]) flag = 0;
		}
		if(flag == 1) length = i;
	}
	cout << 2 * length << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

int main()
{
    int n;
    std::cin >> n;

    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if (i * j == n) {
                std::cout << "Yes" << std::endl;
                return 0;
            }
        }
    }

    std::cout << "No" << std::endl;
}


Measured memory_bytes: 888
function main(input){
  var str = input.split(' ');
  var int = [];
  int.push(parseInt(str[0]));//入っているお札の枚数:N
  int.push(parseInt(str[1]));//合計金額:Y
  
  money:
  for(let i=0;i<=int[0];i++){
    for(let j=0;j<=int[0];j++){
      var com = 9*i+4*j;
      if(com === int[1]/1000-int[0]){
        var thou = int[0] - (i+j);
      	if(thou >=0){
          var fiveThou = j;
          var tenThou = i;
           break money;
        }else{
          continue;
        }
      }else{
        var thou = -1;
        var fiveThou = -1;
        var tenThou = -1;
      }
    }
  }
  console.log(tenThou+' '+fiveThou+' '+thou);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 32448
from math import ceil
n=int(input())
a=list(map(int,input().split()))
b=sum(a)
s=0
lis=[]
lis2=[]
if sum(a)%2==0:
  for i in range(n):
    s+=a[i]
    lis.append(abs(b//2-s))
  print(2*min(lis))
else:
  for i in range(n):
    s+=a[i]
    lis.append(abs(b//2-s))
    lis2.append(abs(ceil(b/2)-s))
  print(2*min(min(lis),min(lis2))+1)

Measured memory_bytes: 29760
S = input()

def solve(T) :
    while 1:
        flag = True
        for i in ("dream", "dreamer", "erase", "eraser"):
            if T.endswith(i):
                T = T[: -len(i)]
                flag = False
                break
        
        if flag:
            print("NO")
            break
        
        if len(T) == 0:
            print("YES")
            break

solve(S)

Measured memory_bytes: 9320
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

calc :: [Integer] -> Integer -> Integer
calc [] n = n
calc (x:xs) n | result > 10 ^18 = -1
              | otherwise = calc xs result
  where result = n * x
  
main = do
  n <- getInt
  as <- getIntList
  if 0 `elem` as
    then print 0
    else print $ calc as 1

Measured memory_bytes: 13372
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll A, B;

int main() {
	scanf("%lld %lld", &A, &B);
	ll X = A;
	ll cnt = 1;
	if(B == 1) {
		printf("0\n");
		return 0;
	}
	while(X < B) {
		X -= 1;
		X += A;
		// cout << X << " \n";
		cnt++;
	} 
	printf("%lld\n", cnt);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
  char a[10005],b[10005],c[10005];
  int n;
  cin>>n;
  cin>>a>>b;
  for(int i=0,j=0;a[j]!='\0';j++,i+=2)
  {
      c[i]=a[j];
      c[i+1]=b[j];
      
  }
  cout<<c;
  
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define BUF_CLEAR (scanf("%*[^\n]"))
#define BUF_AFTERC (getchar())

int main(void)
{
	char tbl[256];
	int n, i;
	char cbuf, cbuf2;
	
	while (1){
		scanf("%d", &n);
		BUF_CLEAR;BUF_AFTERC;
		if (!n) break;
		for (i = 0; i < 256; i++) tbl[i] = i;
		while (n--){
			scanf("%c%*c%c", &cbuf, &cbuf2);
			BUF_CLEAR;BUF_AFTERC;
			tbl[cbuf] = cbuf2;
		}
		scanf("%d", &n);
		BUF_CLEAR;BUF_AFTERC;
		while (n--){
			scanf("%c", &cbuf);
			BUF_CLEAR;BUF_AFTERC;
			printf("%c", tbl[cbuf]);
		}
		puts("");
	}
	return (0);
}

Measured memory_bytes: 396
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

int a[10000005];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		for (int j = i; j <= n; j += i) {
			a[j]++;
		}
	}
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += 1LL * i * a[i];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 40788
// https://atcoder.jp/contests/dp/tasks/dp_p

#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <limits>

using namespace std;

const long long mod = 1000000007;

void helper(const vector<vector<int>>& edges, vector<vector<long long>>& dp, int idx, int prev) {
	if (dp[idx][0] >= 0) return;

	for (int edge : edges[idx]) {
		if (edge == prev) continue;
		helper(edges, dp, edge, idx);
	}

	long long put_white = 1;
	long long put_black = 1;
	for (int edge : edges[idx]) {
		if (edge == prev) continue;
		put_white = (put_white * ((dp[edge][0] + dp[edge][1]) % mod)) % mod;
		put_black = (put_black * dp[edge][0]) % mod;
	}
	dp[idx][0] = put_white;
	dp[idx][1] = put_black;
}

int main (int argc, char* argv[]) {
	int n;
	cin >> n;

	vector<vector<int>> edges(n);
	for (int i = 0; i < n - 1; i++) {
		int from, to;
		cin >> from >> to;
		from--; to--;
		edges[from].push_back(to);
		edges[to].push_back(from);
	}

	vector<vector<long long>> dp(n, vector<long long>(2, -1));
	helper(edges, dp, 0, -1);
	cout << (dp.front().front() + dp.front().back()) % mod << endl;
}


Measured memory_bytes: 18176
[n,y]=require('fs').readFileSync('/dev/stdin','utf8').split(' ').map(n=>n|0)
a=b=c=-1
Array(n+1).fill().map((_,i)=>
	Array(n+1).fill().map((_,j)=>{
		if(i+j>n){return}
		k=n-i-j
		i*10000+j*5000+k*1000==y&&(a=i,b=j,c=k)
	})
)
console.log(a+' '+b+' '+c)


Measured memory_bytes: 62960
import sys
input = sys.stdin.readline


def main():
    S = input().strip()
    N = len(S)
    dp = [[0]*13 for _ in range(N+1)]
    dp[0][0] = 1
    m = 1
    for n in range(N):
        c = S[N-n-1]
        for i in range(10):
            if c == "?" or int(c) == i:
                for j in range(13):
                    dp[n+1][(j + i*m)%13] += dp[n][j]
        for i in range(13):
            dp[n+1][i] %= 10**9+7
        m = m * 10 % 13
    print(dp[N][5])


if __name__ == '__main__':
    main()


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

ll p(ll n) {
  ll ans=1;
  for(ll i=1; i<=n; i++) {
    ans *= i;
    ans %= 1000000007;
  }
  return ans;
}
int main(){
  ll mod = 1e9+7;
  ll n,m; cin>>n>>m;
  if(n-1==m || m-1==n || n==m) {
    if(n==m) cout<<2*p(n)*p(m)%mod;
    else cout<<p(n)*p(m)%mod;
  }
  else {
    cout<<0;
    return 0;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
#include <unordered_map>
#include <algorithm>
#include <unordered_set>
int main()
{
	int n;
	cin >>n;
	unordered_map<ll,long long>mp;
	unordered_set<ll>st;
	ll c = 0, k = 0,a;
	for(int i = 0;i<n;i++)
	{
		cin>>a;
		st.insert(a);
		mp[a]++;
	}
	for(auto &x : st)
	{
//		cout<<"x = "<<x<<" c = "<<c<<" k = "<<k<<endl;
		if(mp[x]==2||mp[x]==3)
		{
			if(x>=c)
			{
				k = c;
				c = x;
			}
			else if(x>=k)
			{
				k = x;
			}
		}
		else if(mp[x]>=4)
		{
			if(x>=c)
			{
				k = x;
				c = x;
			}
			else if(x>=k)
			{
				k = x;
			}
		}
	}
	
	cout << k*c<<endl;
	return 0;
}

Measured memory_bytes: 8520
//セグ木区間和的な
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775807LL
using vi = vector<ll>;
using vvi = vector<vi>;

ll n,q;

//2つの要素をまとめてソート、前の変数が優先。flag=0で小さい順、1で大きい順
void mysort3(vi &a,vi &b,vi &c,ll flag){
  if (a.size()>0){
    vector<pair<ll, pair<ll,ll>>> p(a.size());
    REP(i,a.size()){
      p[i].first=a[i];
      p[i].second.first=b[i];
	  p[i].second.second=c[i];
    }
    sort(p.begin(),p.end());
    if (flag==1){
      reverse(p.begin(),p.end());
    }
    REP(i,a.size()){
      a[i]=p[i].first;
      b[i]=p[i].second.first;
      c[i]=p[i].second.second;
    }
  }
  return;
}


//区間和とかのための
class SegTree_r
{
  public:
  ll n2,ln2;//2のべき乗になる数でn以上の数//n2のlog2値
  vector<ll> data;//●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
  SegTree_r(ll inn)
  {
    ln2=ceil(log2(inn));
    n2=1<<ln2;
    data.resize(n2*2);
    for(ll i=0;i<n2*2;i++)
      data[i]=0;//●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
  }
  //ある要素の値を取得、今まで加算した区間和 O(logn)
  ll GetVal(ll posi)
  {
    ll v=0;//●●●●●●●●●●●●●●●●●●●
    ll myi=posi+n2;
    v+=data[myi];//葉
    for(ll i=0;i<ln2;i++){//中間要素
      myi/=2;
      v+=data[myi];
    }
    return v;
  }
  //lを含むrを含まないところまでの区間にv値を加算
  void AddRange(ll l,ll r,ll v)
  {
    ll ret=data[l];
    ll l_=l;
    ll r_=r;
    for(ll i=0;(l_+r_)>0;i++){
      ll offset=1<<(ln2-i);
      if (r_%2==1){
          if (r_-1>=l_){
            data[offset+r_-1]+=v;
            r_--;
          }
      }
      if (l_%2==1){
          if (l_<r_){
            data[offset+l_]+=v;
            l_++;
          }
      }
      r_>>=1;
      l_>>=1;
    }
  }
};




int main(){
  cin>>n>>q;
  
  vi c(n);
  vi lll(q),rrr(q);
  vi ans(q);
  REP(i,n){
	  cin>>c[i];
	  c[i]--;
  }
  REP(i,q){
	  cin>>lll[i]>>rrr[i];
	  lll[i]--;
	  rrr[i]--;
  }

  vi idx(q);
  REP(i,q) idx[i]=i;
  
  mysort3(lll,rrr,idx,0);
  
  vector<vector<int>> g;
  vi lastcolnum(n);//同じ色で最後にでてきた場所はどこか
  g.resize(n*2);
  
  REP(i,n){
	g[i].push_back(-1);
  }
  REP(i,n){
	lastcolnum[i]=g[c[i]].back();
	g[c[i]].push_back(i);//i番目の色がどの位置にあるか
  }


  vector<vector<int>> endno;
  endno.resize(max(n,q));
  
  REP(i,q){
	endno[rrr[i]].push_back(i);//位置を入力するとその場所で打ち止めになるｑがわかる
  }
  


  SegTree_r segtree_r(q);//nが200000なら18をいれる
  

  for(ll i=0;i<n;i++){
	ll col=c[i];
	ll y=lastcolnum[i];
	if (y!=-1)
	{
		auto Iter2 = upper_bound(lll.begin(),lll.end(), y);//y以下の数がわかる
		ll ynum=(Iter2-lll.begin());
        segtree_r.AddRange(0,ynum,1);
	}


	for(auto r:endno[i])
	{
		ans[r]=segtree_r.GetVal(r);
	}

  }



  vi realans(q);
  for(ll i=0;i<q;i++){
	  realans[idx[i]]=rrr[i]+1-lll[i]-ans[i];
  }
  

  
  for(ll i=0;i<q;i++){
	  cout<<realans[i]<<endl;
  }






  return 0;
}

Measured memory_bytes: 101096
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define ff first 
#define ss second  
typedef pair<int,int> pp;
bool com(pp x,pp y){
    return x.ff<y.ff;
} 
int N=1e5+9;
int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s,t;
	cin>>s;
	cin>>t;
	int n=s.length(),m=0;
	int k=t.length();
	for(int i=0;i<n;i++){
	    int cnt=0;
	    if(i+k-1<n){
    	    for(int j=0;j<k;j++){
    	        if(s[i+j]==t[j]) cnt++;
    	    }
	    }
	    //cout<<cnt<<" ";
	    m=max(m,cnt);
	}
	cout<<k-m;
	return 0; 
	
}


Measured memory_bytes: 3656
N, W = map(int, input().split())

# dp[i][w]: i番目の荷物で重さwの状態であるときの最大価値
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

# 配るDPで考える
for nimotsu in range(N):
    # 行取得
    w_weight, w_val = map(int, input().split())
    
    for w in range(W+1):
        # 品物を選ぶとき (上限超えなければ)
        sum_ = w + w_weight
        if sum_ <= W :
            dp[nimotsu+1][sum_] = max(dp[nimotsu+1][sum_], dp[nimotsu][w] + w_val)
            
        # 品物を選ばないとき
        dp[nimotsu+1][w] = max(dp[nimotsu+1][w] ,dp[nimotsu][w])

print(dp[N][W])

Measured memory_bytes: 171784
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
#define llx(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len) {char ss[len];scanf("%s",ss);(st)=ss;}
using namespace std;
long long n,m,i,j,k,num[200005],ans=1ll<<55,l,r,mid,ss,cnt[200005];
vector<long long> a,b,c,d;
long long gts(long long x,long long y)
{
	return cnt[y]-cnt[x-1];
}
int main()
{
	scanf("%lld",&n);
	for (i=1;i<=n;i++)
	{
		scanf("%lld",&num[i]);
		cnt[i]=cnt[i-1]+num[i];
	}
	for (i=2;i+1<n;i++)
	{
		a.clear();
		b.clear();
		c.clear();
		d.clear();
		l=ss=1;r=i;
		while (l<r)
		{
			mid=(l+r)/2;
			if (gts(1,mid)<=gts(mid+1,i))
			{
				ss=mid;
				l=mid+1;
			}
			else r=mid;
		}
		a.push_back(gts(1,ss));
		b.push_back(gts(ss+1,i));
		if (ss+1<=i)
		{
			a.push_back(gts(1,ss+1));
			b.push_back(gts(ss+2,i));
		}
		l=ss=i+1;r=n;
		while (l<r)
		{
			mid=(l+r)/2;
			if (gts(i+1,mid)<=gts(mid+1,n))
			{
				ss=mid;
				l=mid+1;
			}
			else r=mid;
		}
		c.push_back(gts(i+1,ss));
		d.push_back(gts(ss+1,n));
		if (ss+1<=n)
		{
			c.push_back(gts(i+1,ss+1));
			d.push_back(gts(ss+2,n));
		}
		for (j=0;j<a.size();j++)
		{
			for (k=0;k<c.size();k++)
			{
				ans=min(ans,max(max(a[j],b[j]),max(c[k],d[k]))-min(min(a[j],b[j]),min(c[k],d[k])));
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#define D(x) std::cout << __LINE__ << ' ' << #x << " = " << x << std::endl;

int main() {
#ifndef LOCAL_STJO
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
	std::string w;
	std::cin >> w;
	std::cout << w.substr(0, w.size() - 8) << std::endl;
    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define tsort(v) sort((v).begin(), (v).end())
#define trev(v) tsort(v); reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#ifdef tqktmp_1
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
typedef long long lint;

lint dx[8] = { 0,1,1,1,0,-1,-1,-1 },
	 dy[8] = { 1,1,0,-1,-1,-1,0,1 };

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; }

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

	lint a, b, c, x, ans = 0;
	cin >> a >> b >> c >> x;
	rep(i, a + 1)rep(j, b + 1)rep(k, c + 1)if (500 * i + 100 * j + 50 * k == x)ans++;
	co(ans);
	gc();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
  int n,m;cin >> n>> m;
  graph G(n);
  for(int i = 0; i < m; ++i){ 
    int a,b;cin >> a>> b;
    G[a].push_back(b);
  }
  string ans="IMPOSSIBLE";
  for(int i = 0; i < G[1].size(); ++i){
    int p = G[1][i];
    for(int j = 0; j < G[p].size(); ++j){
      if(G[p][j]==n)ans="POSSIBLE";
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 8576
#include <iostream>

int main() {
    int A, B, C, D, E, F;
    std::cin >> A >> B >> C >> D >> E >> F;

    double limit_density = (double)E / (double)(100 + E);
    
    double max_density = -1;
    int total_mass_at_max = 0;
    int sugar_mass_at_max = 0;

    for (int a = 0; 100 * A * a <= F; a ++) {
        for (int b = 0; 100 * A * a + 100 * B * b <= F; b ++) {
            int water = 100 * A * a + 100 * B * b;

            for (int c = 0; C * c <= F - water; c ++) {
                for (int d = 0; D * d <= F - water - C * c; d ++) {
                    int sugar = C * c + D * d;
                    double density = (double)sugar / (double)(water + sugar);
                    if (density > max_density && density <= limit_density) {
                        max_density = density;
                        total_mass_at_max = water + sugar;
                        sugar_mass_at_max = sugar;
                    }
                }
            }
        }
    }
    std::cout << total_mass_at_max << " " << sugar_mass_at_max << std::endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        String line = sc.next();
        
        String result = "";
        
        if(line.equals("ABC"))
        {
            result = "ARC";
        }
        else
        {
            result = "ABC";
        }
        
        System.out.println(result);
    }
}


Measured memory_bytes: 35556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

void solve(long long N, vector<long long> A){
	vector<long long> a(N-1), b(N-1);
	SORT(A);
	ll c = N;
	repn(i,N-2) {
		if (A[i]>0) {
			c = i;
			break;
		}
	}
	ll cnt = 0;
	for (int i=1; i<=min(c-1,N-2); i++) {
		a[cnt] = A[N-1];
		b[cnt] = A[i];
		A[N-1] = a[cnt]-b[cnt];
		cnt++;
	}
	for (int i=max(c,1LL); i<=N-2; i++) {
		a[cnt] = A[0];
		b[cnt] = A[i];
		A[0] = a[cnt]-b[cnt];
		cnt++;
	}
	a[N-2] = A[N-1];
	b[N-2] = A[0];
	cout << A[N-1]-A[0] << endl;
	rep(i,N-1) {
		cout << a[i] << " " << b[i] << endl;
	}
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> A(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
	}
	solve(N, A);
	return 0;
}



Measured memory_bytes: 4992
import java.util.*;

public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        char[] s = sc.next().toCharArray();
        int[] a = new int[n];
        for(int i=0; i<n-1; i++){
            if(s[i]=='A'&&s[i+1]=='C'){
                a[i+1] = 1;
            }
        }
        for(int i=0; i<n-1; i++){
            a[i+1] += a[i];
        }
        
        for(int i=0; i<q; i++){
            int l = Integer.parseInt(sc.next())-1;
            int r = Integer.parseInt(sc.next())-1;
            System.out.println(a[r]-a[l]);
        }
    }
}


Measured memory_bytes: 59712
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long,long>>;

ll H,W;

int main() {
    cin >> H >> W;
    if(H == 1 || W == 1) cout << 1 << endl;
    else if(H%2 == 0) cout << H/2*W << endl;
    else cout << (H+1)/2*(W-W/2) + H/2*(W/2) << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()
typedef long long ll;

int SURP = 1000000007;

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

	bool isBeki[1001] = {0};
	isBeki[1] = true;

	FOR(i,2,32){
		int j = i * i;

		while(j <= 1000){
			isBeki[j] = true;
			j *= i;
		}
	}

	int ret;
	for(int i = p;i >= 0;i--){
		if (isBeki[i]) {
			ret = i;
			break;
		}
	}

	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
B = input()

B_1 = B.count("1") # pc
mod_p1 = int(B, 2) % (B_1 + 1) # pc + 1
if B_1 != 1:
    mod_m1 = int(B, 2) % (B_1 - 1) # pc - 1

# 小さい数字は直接計算しても一瞬
def calc_small(n, count):
    count += 1
    mod = n % bin(n).count("1")
    if mod == 0:
        return count
    else:
        return calc_small(mod, count)

for i in range(N):
    if B_1 == 1 and int(B[i]) == 1:
        print(0)
        continue

    # はBiが1か0かで，元のmodから差分計算できる
    if B[i] == '1':
        # 反転して-する場合 (mod PC - 1)
        mod = (mod_m1 - pow(2, N - i - 1, B_1 - 1)) % (B_1 - 1)
    else:
        # 反転して+する場合 (mod PC + 1)
        mod = (mod_p1 + pow(2, N - i - 1, B_1 + 1)) % (B_1 + 1)
    count = 1
    if mod == 0:
        print(count)
    else:
        print(calc_small(mod, count))


Measured memory_bytes: 79392