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

#define pb         push_back

const int INF = 100000000;

int ma[200][200];

int main(void) {
	while(1){
		int n;
		int w, h;
		int s, t;

		cin >> n;
		if(n == 0) break;
		cin >> w >> h;
		memset(ma, 0, sizeof(ma));
		for(int i=0; i<n; i++){
			int x, y;
			cin >> x >> y;
			ma[y][x] = 1;
		}
		cin >> s >> t;
		int max_p = 0;

		for(int i=1; i<=h; i++){
			for(int j=1; j<=w; j++){

				int cnt = 0;
				for(int k=0; k<t; k++){
					for(int l=0; l<s; l++){
						if(i+k > h || j+l > w) break;
						if(ma[i+k][j+l] == 1){
							cnt++;
						}
					}
				}
				if(cnt > max_p)  max_p = cnt;

			}
		}
		
		cout << max_p << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1324
#include <stdio.h>

int main(void)
{
	int chu,kim,sai,i;

	
	while (1)
	{
		scanf("%d %d %d", &chu, &kim, &sai);

		if (chu == -1 && kim == -1 && sai == -1)
		{
			break;
		}
		else if (chu == -1 || kim == -1 || chu + kim < 30)
		{
			printf("F\n");
		}
		else if (chu + kim >= 80)
		{
			printf("A\n");
		}
		else if (chu + kim >= 65)
		{
			printf("B\n");
		}
		else if (chu + kim >= 50)
		{
			printf("C\n");
		}
		else if (chu + kim >= 30)
		{
			if (sai >= 50)
			{
				printf("C\n");
			}
			else
			{
				printf("D\n");
			}
		}

	}

	return 0;
}


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

int main() {
    string s;
    cin >> s;
    if (s == "RRR") cout << 3 << endl;
    else if (s == "RRS" or s == "SRR") cout << 2 << endl;
    else if (s == "SSS") cout << 0 << endl;
    else cout << 1 << endl;
}


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

#define int long long
#define rep(i,a,n) for(int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define ALL(x) (x).begin(),(x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort(ALL(c), greater<int>());
#define fi first
#define se second
int INF = 1e9 + 7;

typedef pair<int,int> P;
typedef vector<int> vi;

bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.fi < secondElof.fi;
}

int n,m;
vector<P> a;

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

    cin>>n>>m;
    rep(i,0,n) {
        int A,B; cin>>A>>B;
        a.pb(P(A,B));
    }

    sort(ALL(a),pairCompare);
    int index=0,ans=0;
    while(m>0) {
        if(m>a[index].se) {
            m-=a[index].se;
            ans+=a[index].se*a[index].fi;
            index++;
        }else{
            ans+=m*a[index].fi;
            m=0;
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
    int q=0;char ch=' ';
    while(ch<'0'||ch>'9') ch=getchar();
    while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
    return q;
}
const int N=100005;
int n,tot,h[N],ne[N],to[N],st[N],f[N];
void add(int x,int y) {to[++tot]=y,ne[tot]=h[x],h[x]=tot;}
bool cmp(int x,int y) {return x>y;}
void dfs(int x) {
    int top=0;
    for(RI i=h[x];i;i=ne[i]) dfs(to[i]);
    for(RI i=h[x];i;i=ne[i]) st[++top]=f[to[i]];
    sort(st+1,st+1+top,cmp);
    for(RI i=1;i<=top;++i) f[x]=max(f[x],st[i]+i);
}
int main()
{
    int x;n=read();
    for(RI i=2;i<=n;++i) x=read(),add(x,i);
    dfs(1),printf("%d\n",f[1]);
    return 0;
}

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

typedef long long ll;
typedef long double ld; 
typedef double db; 
typedef string str; 

typedef pair<int, int> pi;
typedef pair<ll,ll> pl; 
typedef pair<ld,ld> pd; 

typedef vector<int> vi; 
typedef vector<ll> vl;
typedef vector<ld> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound 
#define ub upper_bound 

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll MX = 2000005;

namespace Modop {
    ll modAdd(ll a, ll b) {
        return (a + b) % MOD;
    }
    
    ll modSub(ll a, ll b) {
        return (((a - b) % MOD) + MOD) % MOD;
    }
    
    ll modMul(ll a, ll b) {
        return ((a % MOD) * (b % MOD)) % MOD;
    }

    ll modExp(ll base, ll power) {
        if (power == 0) {
            return 1;
        } else {
            ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
            if (power % 2 == 1) cur = cur * base;
            cur = cur % MOD;
            return cur;
        }
    }
    
    ll modInv(ll a) {
        return modExp(a, MOD - 2);
    }
    
    ll modDiv(ll a, ll b) {
        return modMul(a, modInv(b));
    }
}

using namespace Modop;

ll X, Y;
ll fac[MX];

void pre() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MX; i++) {
        fac[i] = modMul(i, fac[i - 1]);
    }
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    pre();
	cin >> X >> Y;
	if ((X + Y) % 3) {
		cout << "0";
		return 0;
	} else {
		ll rightMoves = (X - (Y - X)) / 3;
		ll upMoves = X - (2 * rightMoves);
        if (rightMoves < 0 || upMoves < 0) {
            cout << 0;
            return 0;
        }
		ll totalMoves = rightMoves + upMoves;		
		
        ll ans = fac[totalMoves];
        ans = modDiv(ans, fac[rightMoves]);
        ans = modDiv(ans, fac[totalMoves - rightMoves]);
        cout << ans;
	}
	
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result */


Measured memory_bytes: 15872
# coding: utf-8
status = ['NA', 'NA', 'NA', 'NA', 'NA', 'NA', 'MMYY', 'MMYY', 'NA', 'YYMM', 'NA', 'YYMM', 'NA', 'YYMM', 'MMYY', 'AMBIGUOUS']

def isMonth(a):
    return a > 0 and a < 13

def isYear(a):
    return a > -1 and a < 100

t = input()
t1 = int(t[:2])
t2 = int(t[2:])

judge = isYear(t1) * 8 + isMonth(t1) * 4 + isYear(t2) * 2 + isMonth(t2)
print(status[judge])


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Linq;
using static System.Math;

class Program{
    static void Main(){
        int ans = 0;
        int count = 0;
        string s = Console.ReadLine();
        for (int i = 0;i < s.Length;i++){
            if (s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C'){
                count++;
                continue;
            }
            ans = Max(ans,count);
            count = 0;
        }
        ans = Max(ans,count);
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7;
vector<ll> fact;

void init_fact(int n) {
    fact = vector<ll>(n);
    fact[0] = 1;
    for (int i = 1; i < n; i++) fact[i] = fact[i - 1] * i % MOD;
}

ll calc_pow(ll x, ll pow) {
    if (pow == 0) return 1;
    ll a = calc_pow(x, pow / 2);
    a = a * a % MOD;
    if (pow % 2 == 1) a *= x;
    return a % MOD;
}

ll calc_div(ll a, ll b) {
    return a * calc_pow(b, MOD - 2) % MOD;
}

ll calc_comb(ll n, ll r) {
    if (n < r)return 0;
    return calc_div(fact[n], fact[r] * fact[n - r] % MOD);
}

int main() {
    init_fact(300000);
    int n, k;
    cin >> n >> k;

    ll ret = 0;
    for (int i = 0; i <= min(k, n - 1); i++) {
        ret += calc_comb(n, i) * calc_comb(n - 1, i) % MOD, ret %= MOD;
    }
    cout << ret << endl;
    return 0;
}

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

using namespace std;


typedef long long int64;
const int mod = 1e9 + 7;

inline int64 modPow(int64 x, int64 n)
{
  if(n == 0) return (1);
  int64 ret = modPow(x, n / 2);
  (ret *= ret) %= mod;
  if(n & 1) (ret *= x) %= mod;
  return (ret);
}

int main()
{
  int N, K;
  cin >> N >> K;
  vector< int > divisor;
  for(int i = 1; i * i <= N; i++) {
    if(N % i == 0) {
      divisor.push_back(i);
      if(i * i != N) divisor.push_back(N / i);
    }
  }
  sort(begin(divisor), end(divisor));
  vector< int64 > dp(divisor.size());
  int64 ret = 0LL;
  for(int i = 0; i < divisor.size(); i++) {
    dp[i] = modPow(K, (divisor[i] + 1) / 2);
    for(int j = 0; j < i; j++) {
      if(divisor[i] % divisor[j] == 0) (dp[i] += mod - dp[j]) %= mod;
    }
    if(divisor[i] % 2 == 0) ret += divisor[i] / 2 * dp[i] % mod;
    else ret += divisor[i] * dp[i] % mod;
    ret %= mod;
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#pragma region

#include "bits/stdc++.h"
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10) << boolalpha;
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  string S, T, U;
  int A, B;
  cin >> S >> T >> A >> B >> U;
  if (U == S) {
    cout << A - 1 << " " << B << "\n";
  } else {
    cout << A << " " << B - 1 << "\n";
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <assert.h>
#include <algorithm>
#include <string>

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

    int32_t N, K;
    std::cin >> N >> K;
    std::string S;
    std::cin >> S;
    
    // maximize consec '1'
    //std::list<int32_t> stand_index;
    int32_t stand_index[N] = {0};
    int8_t prev = '1';
    int8_t tmp = '0';
    int32_t start_idx = 0;
    int32_t max_consec_handstands = 0;
    int32_t stand_first = 0, stand_last = 0;
    for(int32_t i = 0; i < (int32_t) S.size(); i++){
        tmp = S[i];
        if(prev == '1' && tmp == '0'){
            //stand_index.push_back(i);
            stand_index[stand_last] = i;
            stand_last++;
        }
        else if(prev == '0' && tmp == '0'){
            //stand_index.back() += 1; 
            stand_index[stand_last-1]++;
        }
        prev = tmp;

        //if((int32_t)stand_index.size() > K){
        if(stand_last - stand_first > K){
            int32_t consec_handstands = i - start_idx;
            max_consec_handstands = std::max(max_consec_handstands, consec_handstands);
            //start_idx = stand_index.front() + 1;
            //stand_index.pop_front();
            start_idx = stand_index[stand_first] + 1;
            stand_first++;

            //debug
            //std::cout << "cond met at:" << i << std::endl;
            //std::cout << "Length = :" << consec_handstands << std::endl;
        }

        //std::cout << "idex:" << i << std::endl;
        //for(auto& s_i : stand_index){
        //    std::cout << s_i << ",";
        //}
        //std::cout << std::endl;
    }
    // last check
    int32_t consec_handstands = (int32_t) S.size() - start_idx;
    max_consec_handstands = std::max(max_consec_handstands, consec_handstands);

    std::cout << max_consec_handstands;

    return 0;
}


Measured memory_bytes: 848
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = 1;
		long n = sc.nextInt();
		for(int i = (int)n ; i >= 1 ; i--){
			a = i * a;

		}
		System.out.println(a);
		sc.close();
	}

}

Measured memory_bytes: 17148
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

struct edge {
  int to;
  ll cost;
};
typedef vector<P> VP;
typedef greater<P> GP;

int n, m;
vector<edge> g[100000];
const ll INF = 1e16;

// 始点sから各頂点への最短距離を求める
vector<ll> dijkstra(int s) {
  priority_queue<P, VP, GP> que;  // 最短距離の小さい順に取り出す
  vector<ll> d(n, INF);
  d[s] = 0;
  que.push(P(0, s));
  while (que.size()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    REP(i, g[v].size()) {
      edge e = g[v][i];
      if (d[v] + e.cost < d[e.to]) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
  return d;
}

int main() {
  cin >> n >> m;
  edge e1 = {n - 1, INF};
  edge e2 = {0, INF};
  g[0].push_back(e1);
  g[n - 1].push_back(e2);
  REP(i, n) {
    if (i == 0) continue;
    edge e = {i - 1, 0};
    g[i].push_back(e);
  }
  while (m--) {
    int l, r, c;
    cin >> l >> r >> c;
    l--, r--;
    edge e1 = {r, c};
    edge e2 = {l, c};
    g[l].push_back(e1);
    g[r].push_back(e2);
  }
  vector<ll> dist = dijkstra(0);
  cout << (dist[n - 1] == INF ? -1 : dist[n - 1]) << endl;
  return 0;
}

Measured memory_bytes: 13304
import collections
n = int(raw_input())
ais = map(int, raw_input().split(' '))
bis = map(int, raw_input().split(' '))
cis = map(int, raw_input().split(' '))


c = 0
q = collections.deque([])
for a in ais:
	c += bis[a - 1]
	if q:
		p = q.popleft()
		if p + 1== a - 1:
			c += cis[p]
	q.append(a - 1)

print c

Measured memory_bytes: 28396
open System

[<Literal>] 
let m = 2019

let S = Console.ReadLine()

let cusum = 
    let x = Array.zeroCreate (1 + S.Length) 
    let y = 
        let y = ref 1
        fun() -> 
            let r = !y
            y := !y * 10 % m 
            r
    for i in 1 .. S.Length do 
        let i' = S.Length - i;
        x.[i] <- ((int << string) S.[i'] * y() + x.[i - 1]) % m  
    x

cusum
|> Array.fold (fun (m, ans) x -> 
    match Map.tryFind x m with 
    | Some v -> Map.add x (v + 1) m, ans + v 
    | _ -> Map.add x 1 m, ans 
    ) (Map.empty, 0)
|> snd
|> printfn "%i"


Measured memory_bytes: 50204
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt();
		char rooms[][][]=new char[4][3][10];
		for(int i=0;i<4;i++) {
			for(int j=0;j<3;j++) {
				for(int k=0;k<10;k++)rooms[i][j][k]=0;
			}
		}
		
		for(int i=0;i<n;i++) {
			int b=cin.nextInt(),f=cin.nextInt(),r=cin.nextInt(),v=cin.nextInt();
			rooms[b-1][f-1][r-1]+=v;
		}
		
		for(int i=0;i<4;i++) {
			for(int j=0;j<3;j++) {
				for(int k=0;k<10;k++)System.out.print(" "+(int)rooms[i][j][k]);
				System.out.println();
			}
			if(i!=3)System.out.println("####################");
		}
	}
}


Measured memory_bytes: 29908
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << '\n';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    print(p.first, p.second);
}


int main(){
    ll n,m; cin >> n >> m;
    vector<vector<ll>> graph(n);
    vector<ll> ans(n, INF), in(n, 0);

    rep(i,n - 1 + m) {
        ll a,b;cin >> a >> b;
        a--;b--;
        graph[a].emplace_back(b);
        // graph[b].emplace_back(a);
        in[b]++;
    }
    ll root;
    rep(i,n)if(in[i] == 0){
        root = i;
        ans[root] = 0;
    }
    // print(in);
    queue<Pll> que;
    que.push(Pll(root, 0));
    while(!que.empty()){
        Pll t = que.front();que.pop();
        for(auto to : graph[t.first]){
            if(in[to] == 1){
                ans[to] = t.first + 1;
                que.push(Pll(to, t.second + 1));
            }
            in[to]--;
        }
    }

    print(ans);
}

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

using namespace std;
#define INFS (1LL<<28)
#define INF (1LL<<60)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
#define all(n) n.begin(),n.end()



signed main(){
	int n;
	cin>>n;
	int ans=-1;
	int bef=-1;
	int now=0;
	lp(i,n){
		int a;
		cin>>a;
		if(a<=bef)now++;
		else{
			ans=max(ans,now);
			now=0;
		}
		bef=a;
	}
	ans=max(ans,now);
	cout<<ans<<endl;
	return 0;
}

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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const ld pi=2*acos(0.0);

int main(){
    nimble
    string s;
    cin>>s;
    ll x=0;
    rep(i,0,_sz(s))
        x+=(s[i]-'0');
    if(x%3==0)cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 3744
#include <stdio.h>
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
//#define rep(i,n) for(i=0; i < n; i++)
#define MAX 100000

vector<int> V(MAX);

int main(){
   int N, A, B;
   cin >> N >> A >> B;
   int sum = 0;
   for(int i = 0; i <= N; i++){
    int tmp  = 0;
    for(int j = 4; j >= 0; j--){
        int p =pow(10,j);
        int s = i / p;
        if(s%10>=1) tmp += s%10;
    }
    if (tmp >=A && tmp <= B) sum += i;
   }
   cout << sum << endl;
}


Measured memory_bytes: 640
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  };
  ($e:expr => $i:expr; $t:ty) => {
    (0..$i).map(|_| $e.get::<$t>()).collect::<Vec<$t>>()
  };
  ($e:expr => $row:expr, $col:expr; $t:ty) => {
    (0..$i).map(|_| scan!($e => $col; $t)).collect::<Vec<$t>>()
  }
}

struct Scanner<R: Read> {
  reader: R
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader: reader }
  }
  fn safe_get<T: FromStr>(&mut self) -> Option<T> {
    let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
      .skip_while(|c| c.is_whitespace())
      .take_while(|c| !c.is_whitespace())
      .collect::<String>();
    if token.is_empty() { None } else { token.parse().ok() }
  }
  fn get<T: FromStr>(&mut self) -> T {
    if let Some(v) = self.safe_get() { v } else {
      writeln!(stderr(), "Terminated with EOF").unwrap();
      std::process::exit(0);
    }
  }
}

fn merge(vec: &mut Vec<i32>, left: usize, mid: usize, right: usize, cmp_n: &mut i32) {
  let n1 = mid - left;
  let n2 = right - mid;
  let mut l = Vec::with_capacity(n1 + 1);
  let mut r = Vec::with_capacity(n2 + 1);
  for i in 0..n1 {
    l.push(vec[left + i]);
  }
  for i in 0..n2 {
    r.push(vec[mid + i]);
  }
  l.push(std::i32::MAX);
  r.push(std::i32::MAX);
  let (mut i, mut j) = (0, 0);
  for k in left..right {
    *cmp_n += 1;
    if l[i] <= r[j] {
      vec[k] = l[i];
      i += 1;
    }
    else {
      vec[k] = r[j];
      j += 1;
    }
  }
}

fn merge_sort(vec: &mut Vec<i32>, left: usize, right: usize, cmp_n: &mut i32) {
  if left + 1 < right {
    let mid = (left + right) / 2;
    merge_sort(vec, left, mid, cmp_n);
    merge_sort(vec, mid, right, cmp_n);
    merge(vec, left, mid, right, cmp_n);
  }
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut sc = Scanner::new(cin);
  let n = scan!(sc; usize);
  let mut s = scan!(sc => n; i32);
  let mut cmp_n = 0;
  merge_sort(&mut s, 0, n, &mut cmp_n);
  println!("{}", s.iter().map(|&elem| elem.to_string()).collect::<Vec<String>>().join(" "));
  println!("{}", cmp_n);
}



Measured memory_bytes: 31640
#include <algorithm>
#include <iostream>
#include <set>
#include <utility>
#include <vector>
using namespace std;

long long f(long long x, long long y, long long l, long long t, bool b) {
  long long d = y - x;
  if (!b)
    d = l - d;
  return (2 * t - d + l) / l;
}

int main() {
  long long n;
  long long l, t;
  cin >> n >> l >> t;
  vector<pair<long long, long long>> p(n);
  for (int i = 0; i < n; i++)
    cin >> p[i].first >> p[i].second;
  long long m = p[0].second;
  vector<long long> q;
  for (int i = 0; i < n; i++) {
    if (p[i].second != m)
      q.push_back(p[i].first);
  }
  long long ret = 0;
  for (int i = 0; i < q.size(); i++) {
    ret += f(p[0].first, q[i], l, t, m == 1);
  }
  vector<long long> v(n);
  for (int i = 0; i < n; i++) {
    if (p[i].second == 1)
      v[i] = (p[i].first + t) % l;
    else
      v[i] = ((p[i].first - t) % l + l) % l;
  }
  sort(v.begin(), v.end());
  long long w;
  if (m == 1)
    w = (p[0].first + t) % l;
  else
    w = ((p[0].first - t) % l + l) % l;
  int id;
  for (int i = 0; i < n; i++) {
    if (w == v[i]) {
      id = i;
      if (m == 2)
        break;
    }
  }
  vector<long long> c(n);
  if (m == 2)
    ret *= -1;
  for (int i = 0; i < n; i++) {
    c[((ret + i) % n + n) % n] = v[(id + i) % n];
  }
  for (int i = 0; i < n; i++)
    cout << c[i] << endl;
  return 0;
}


Measured memory_bytes: 4856
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    H,N = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    inf=10**9
    dp=[inf]*(H+1)
    dp[0]=0
    for A,B in S:
        for i in range(0,H):
            dp[min(i+A,H)]=min(dp[i]+B,dp[min(i+A,H)])
    print(dp[-1])




if __name__ == "__main__":
    main()

Measured memory_bytes: 77856
import heapq # 優先度付きキュー(最小値取り出し)

inf = 10**15
mod = 10**9+7
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort(key = lambda x:x[0], reverse = True)
q = []
heapq.heapify(q)   # ヒープ化
ans = 0
for i in range(1,m+1): # m-i日目からスタートして間に合う仕事
    while ab and ab[-1][0] == i:
        _,val = ab.pop()
        heapq.heappush(q, (-1) * val)
    if q:
        ans += heapq.heappop(q) * (-1)

print(ans)

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001

int n, k, t, u, v, l;
int d[202];

int main(){
    cin >> n >> k >> t >> u >> v >> l;
    d[0] = 0;
    rep(i, n) cin >> d[i + 1];
    d[n + 1] = l;

    double time = 0, boost = 0;
    int carrot = 0;
    repl(i, 1, n + 2) {
        double a = d[i] - d[i - 1];
        double b = (carrot * t + boost) * v;
        if (a > b) {
            a -= b;
            time += (carrot * t + boost) + a / u;
            boost = 0;
            carrot = 0;
        } else {
            b -= a;
            time += a / v;
            carrot = (int)(b / v) / t;
            boost = (b / v) - (carrot * t);
        }
        if (carrot < k) carrot++;
        else boost = t;
    }

    printf("%.10f\n", time);

    return 0;
}

Measured memory_bytes: 3180
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a),i##Len_=(b);i<i##Len_;i++)
 

int main() 
{    
    int N;
    int res;

    cin >> N;

    res = (N-2) * 180;

    cout << res << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using P = pair<int, int>;
constexpr array<int, 4> dx = {1, 0, -1, 0};
constexpr array<int, 4> dy = {0, 1, 0, -1};
constexpr int INF = 1234567890;
constexpr int MOD = 1000000000 + 7;
// constexpr int MOD = 998244353;
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;
}
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int fact(int n) { return n > 1 ? n * fact(n - 1) % MOD : 1; }
int modinv(int a)
{
    int b = MOD, u = 1, v = 0;
    while (b)
    {
        int t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= MOD;
    if (u < 0)
        u += MOD;
    return u;
}
constexpr int modpow(int a, int n)
{
    int rtn = 1;
    while (n > 0)
    {
        if (n & 1)
            rtn = rtn * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return rtn;
}

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

    int a, b;
    cin >> a >> b;

    const int ans = a * b / gcd(a, b);
    cout << ans << endl;
}


Measured memory_bytes: 256
s = [int(input()) for i in range(4)]
#s[0]=N,s[1]=K,s[2]=X,s[3]=Y
if s[0] < s[1]:
    print(s[0] * s[2])
else:
    print(s[1] * s[2] + (s[0] - s[1]) * s[3])

Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<algorithm>
const int MAXN=100010;

struct edge{
	int v;
	edge *nxt;
	edge(){
		v=0;
		nxt=NULL;
	}
}*head[MAXN];
void adde(int u,int v){
	edge *p=new edge;
	p->v=v;
	p->nxt=head[u];
	head[u]=p;
}
int n,m,f[MAXN];

int dfs(int u){
	if(f[u])
		return f[u];
	for(edge *i=head[u];i!=NULL;i=i->nxt){
		int v=i->v;
		f[u]=std::max(f[u],dfs(v)+1);
	}
	return f[u];
}

int main(){
	scanf("%d%d",&n,&m);
	while(m--){
		int u,v;scanf("%d%d",&u,&v);
		adde(u,v);
	}
	for(int i=1;i<=n;i++)
		if(!f[i])
			dfs(i);
	int ans=0;
	for(int i=1;i<=n;i++)
		ans=std::max(ans,f[i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    string S, T;
    cin >> S >> T;
    string U;
    u32 A, B;
    cin >> A >> B;
    cin >> U;
    if (S == U) A--;
    else B--;
    cout << A << " " << B << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h> 
int main(void)
{
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	if(abs(a-b)%2==0)
	printf("Alice\n");
	else
	printf("Borys\n");
	return 0;
 } 

Measured memory_bytes: 128
#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;

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;
    cin>>a>>b>>c;
    if(a==b)co(c);
    else if(a==c)co(b);
    else co(a);
}

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

public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count = 0;
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		int i = 0;
		while(a[i] % 2 == 0) {
			count++;
			a[i] /= 2; 
			i++;
			i = i % n;
			}
		
		System.out.println(count/n);

	}
}


Measured memory_bytes: 23252
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#define SENTINEL INT_MAX
 
int A[500000],c=0;
int L[300000], R[300000];
 
void Merge(int left, int mid, int right){
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
 
 
    for (i = 0; i < n1;i++){
        L[i] = A[left + i];
    }
    for (i = 0; i < n2;i++){
        R[i] = A[mid + i];
    }
    L[n1] = SENTINEL;
    R[n2] = SENTINEL;
    i = 0;
    j = 0;
    for (k = left; k < right;k++){
        c++;
        if (L[i] <= R[j]){
            A[k] = L[i];
            i = i + 1;
        }else{
            A[k] = R[j];
            j = j + 1;
        }
    }
}
 
void Merge_Sort(int left, int right){
    int mid;
    if (left + 1 < right){
        mid = (left + right) / 2;
        Merge_Sort(left, mid);
        Merge_Sort(mid, right);
        Merge(left, mid, right);
    }
}
 
int main(){
    int i, j, k;
    scanf("%d",&i);
    for (j = 0; j < i;j++){
        scanf("%d",&A[j]);
    }
 
    Merge_Sort(0,j);
 
     
    for (i = 0; i < j; i++){
        printf("%d", A[i]);
        if (i < j - 1){
            printf(" ");
        }
    }
printf("\n%d\n",c);
return 0;
}

Measured memory_bytes: 4708
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//ABC110B
int compare_int(const void *a, const void *b) { //sort
  return *(int*) a-*(int*) b;
}
int main(void) {
  int n, m, k, i, cou=0, tmp;
  scanf("%d %d", &n, &m);
  int x[n+1], y[m+1];
  scanf(" %d %d", &x[0], &y[0]);
  for(i=1; i<=n; i++)
    scanf(" %d", &x[i]);
  for(i=1; i<=m; i++)
    scanf(" %d", &y[i]);
  qsort(x, n+1, sizeof(int), compare_int); //sort
  qsort(y, m+1, sizeof(int), compare_int); //sort
  if(x[n]<y[0]) printf("No War");
  else printf("War");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <climits>
#include <queue>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <cstdlib>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

struct Data
{
	int len;
	int num;
	Data(int len, int num) : len(len), num(num) {}
	bool operator< (const Data& d)const
	{
		return len > d.len;
	}
};

int main()
{
	int s, d;
	while(scanf("%d%d", &s, &d), s||d){
		int n = s+d;
		vvi dist(n, vi(n, INT_MAX/3));
		rep(i, s) rep(j, d){
			int di;
			scanf("%d", &di);
			if(di)
				dist[i][s+j] = dist[s+j][i] = di;
		}
		rep(i, d-1) rep(j, d-i-1){
			int di;
			scanf("%d", &di);
			if(di)
				dist[s+i][s+i+j+1] = dist[s+i+j+1][s+i] = di;
		}
		
		priority_queue<Data> Q;
		vi visited(n, 0);
		int connect = 0;
		int sum = 0;
		
		rep(i, s)
			Q.push(Data(0, i));
		
		while(connect < d){
			Data d = Q.top();
			Q.pop();
			if(visited[d.num])
				continue;
			//printf("d.num = %d, len = %d\n", d.num, d.len);
			visited[d.num] = 1;
			connect += d.num >= s;
			sum += d.len;
			rep(i, n){
				if(!visited[i]){
					Data next(dist[d.num][i], i);
					Q.push(next);
				}
			}
		}
		
		printf("%d\n", sum);
	}
	
	return 0;
}

Measured memory_bytes: 0
let i=readLine()!.characters.split(" ").map{Int(String($0))!},C=i[2],D=i[3];func f(x:Int)->Int{return i[1]/x-(i[0]-1)/x};func g(x:Int,_ y:Int)->Int{return y>0 ?g(y,x%y):x};print(f(1)-f(C)-f(D)+f(C*D/g(C,D)))

Measured memory_bytes: 3568
n=int(input())
g=1
while g<=n:
    out=0
    #0ランナーなし、1ランナーあり,4番目得点
    runner=[0,0,0,0]
    #3アウトまで
    while out<3:
        batter=str(input())
    #アウト
        if batter=="OUT":
            out+=1
    #ヒット
        if batter=="HIT":
            for i in range(3):
                if i==0:
                    runner[0]+=1

                if runner[i]==2:
                    runner[i]=1
                    runner[i+1]+=1
    #ホームラン
        if batter=="HOMERUN":
            for i in range(3):
                if runner[i]==1:
                    runner[i]=0
                    runner[3]+=1
            runner[3]+=1

    print(runner[3])
    g+=1
    
  


Measured memory_bytes: 5592
import collections
import itertools
n = int(input())
li = []
for i in range(n):
    li.append(input()[0])

c = collections.Counter(li)
c_li = [c['M'],c['A'],c['R'],c['C'],c['H']]
#print(li,c,c_li)

count = 0
combination = list(itertools.combinations([0,1, 2, 3,4], 3))
for co in combination:
    tmp = 1
    for c in co:
        if c_li[c] == 0:
            tmp = 0
            break
        tmp *= c_li[c]
    count += tmp
print(count)

Measured memory_bytes: 4224
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,N,s=0; cin>>n;
    N=n;
    rep(i,12){
        s+=N%10;
        N/=10;
    }
    cout<<(n%s==0 ? "Yes" : "No")<<endl;
}

Measured memory_bytes: 3604
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, vis[200], ans;
string s[200];
vector<pair<int, int> > edges;
vector<int> vec[200];
queue<int> qu;

void dfs(int x, int co)
{
	vis[x] = co;
	if (co == 1) co = -1;
	else co = 1;
	for (int i = 0; i < n; i++) {
		if (vis[i] == 0 && s[x][i] == '1') {
			dfs(i, co);
		}
	}
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		for (int j = i + 1; j < n; j++) {
			if (s[i][j] == '1') {
				edges.pb({ i, j });
			}
		}
		for (int j = 0; j < n; j++) {
			if (s[i][j] == '1') {
				vec[i].pb(j);
				vec[j].pb(i);
			}
		}
	}
	dfs(0, 1);
	bool flag = false;
	for (int i = 0; i < (int)edges.size(); i++) {
		auto tmp = edges[i];
		if (vis[tmp.fi] == vis[tmp.se]) {
			flag = true;
			break;
		}
	}
	if (flag) {
		ans = -1;
	}
	else {
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				memset(vis, 0, sizeof(vis));
				qu.push(i);
				vis[i] = 1;
				int lst = i, mx = 0;
				while (!qu.empty()) {
					int cur = qu.front();
					qu.pop();
					for (int k = 0; k < (int)vec[cur].size(); k++) {
						if (vis[vec[cur][k]] == 0) {
							vis[vec[cur][k]] = 1;
							qu.push(vec[cur][k]);
						}
					}
					if (lst == cur) {
						mx++;
						if (!qu.empty()) lst = qu.back();
					}
				}
				ans = max(ans, mx);
			}
		}
	}
	cout << ans << E;
	//system("pause");
	return 0;
}

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

string reverseString(string str){
	string strTemp;
	
	for(int i=0 ; i<str.size() ; i++){
		strTemp[str.size()-i-1] = str[i];
	}
	for(int i=0 ; i<str.size() ; i++){
		str[i] = strTemp[i];
	}
	return str;
} 
 
int main(){
	string str;

	while ( cin >> str ) {
		cout << reverseString( str ) << endl;
	}
} 

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] Eigyo = new String[n];
		for(int i = 0; i < n; i++) {
			StringBuilder sb = new StringBuilder();
			for(int j = 0; j < 10; j++) {
				sb.append(sc.next());
			}
			Eigyo[i] = sb.toString();
		}
		int[][] p = new int[n][11];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < 11; j++) {
				p[i][j] = sc.nextInt();//i番目の店がj個被ると
			}
		}
		Long ans = Long.MIN_VALUE;
		//自分の営業日を全探索2^10
		for(int i = 1; i < 1<<10 ; i++) {
			long rieki = 0;
			for(int j = 0; j < n; j++) {
				int howKaburi = kaburi(Eigyo[j], i);
				rieki += p[j][howKaburi];
			}
			ans = Math.max(rieki, ans);
		}
		System.out.println(ans);
	}

	private static int kaburi(String str, int j) {
		int count = 0;
		char[] s = str.toCharArray();
		String g = Integer.toBinaryString(j);
		for(int i = g.length(); i < 10; i++) {
			g = "0"+g;
		}
		char[] own = g.toCharArray();
		for(int i = 0; i < 10; i++) {
			if(s[i]=='1'&&own[i]=='1') {
				count++;
			}
		}
		return count;
	}
}

Measured memory_bytes: 40172
N=int(input())
A=list(map(int,input().split()))
B=[A[0]] #累積和
C=[0]*N #ここで切った時の差分
for i in range(1,N):
  B.append(B[-1]+A[i])
  
for j in range(N):
  C[j]=abs((B[-1]-B[j])-B[j])

#print(C)
print(min(C))

Measured memory_bytes: 29500
#include <iostream>

using namespace std;

int main()
{
    int n, k, h, i, t=0;
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>h;
        if(h>=k)
        {
            t++;
        }
    }
    cout<<t;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll D, G, i, p[11], c[11], min=INF, sum, num;

    cin >> D >> G;

    for(i=1; i<=D; i++){
        cin >> p[i] >> c[i];
    }

    // {0, 1, ..., N-1} の部分集合の全探索(SとTに分ける)
    for (ll bit = 0; bit < (1<<D); bit++) {
        vector<ll> S, T;
        sum = 0;
        num = 0;

        for (ll i = 0; i < D; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                // Sの末尾にiを追加する
                S.push_back(i);
            }
            else{
                T.push_back(i);
            }
        }

        for (ll i = 0; i < (ll)S.size(); ++i) {
            // 完全に解く
            sum += 100*(S[i]+1)*p[S[i]+1]+c[S[i]+1];
            num += p[S[i]+1];
        }

        if(T.size()>=1){
            if(sum + T.size()*100*(p[T.size()]-1) >= G){
                while(sum < G){
                    sum += T.size()*100;
                    num++;
                }
                chmin(min, num);
            }
        }
        else{
            if(sum >= G){
                chmin(min, num);
            }
        }
    }

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
X, K, D = map(int, input().split())

if X > 0 and X > K * D:
    print(X - K * D)
elif X < 0 and abs(X) > K * D:
    print(abs(X) - K * D)
elif X == 0:
    if K % 2 == 0:
        print(0)
    else:
        print(D)
elif X > 0:
    K -= int(X / D)
    X = X - int(X / D) * D
    if X == 0:
        if K % 2 == 0:
            print(0)
        else:
            print(D)
    else:
        if K % 2 == 0:
            print(X)
        else:
            print(abs(X-D))
elif X < 0:
    K -= int (abs(X)/D)
    X = X + int(abs(X)/D) * D
    if X == 0:
        if K % 2 == 0:
            print(0)
        else:
            print(D)
    else:
        if K % 2 == 0:
            print(abs(X))
        else:
            print(X + D)


Measured memory_bytes: 61976
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var sc *bufio.Scanner

const bufferSize = 1024

func nextInt() int {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, bufferSize)
	sc.Buffer(buf, 1e+7)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := nextInt()
	b := nextInt()
	ans := (n / (a + b)) * a
	if n%(a+b) > a {
		ans += a
	} else {
		ans += n % (a + b)
	}

	_, _ = fmt.Fprintf(writer, "%d", ans)
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
// 9x9

#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>

using namespace std;

int main()
{
    int A,B;
    cin >> A >> B;

    if (A < 10 && B < 10) {
        cout << A * B << endl;
    }
    else {
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 888
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    d = list(map(int, input().split()))
    d.sort()
    a = n//2
    if d[a-1]==d[a]:
        print(0)
    else:
        print(d[a]-d[a-1])

if __name__ == '__main__':
    main()

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

int main(){
  int64_t N,K;
  cin>>N>>K;
  vector<int64_t> A(N),F(N);
  int64_t A_sum;
  for(int i=0;i<N;++i){
    cin>>A.at(i);
    A_sum += A.at(i);
  }
  for(int i=0;i<N;++i){
    cin>>F.at(i);
  }
  
  sort(A.begin(),A.end());
  sort(F.begin(),F.end(),greater<int64_t>());

  int64_t X=0;
  for(int i=0;i<N;++i){
    X=max(X,A.at(i)*F.at(i));
  }
  
  int64_t left=0,right=X;
  while(right-left>1){

    if(K>=A_sum){
      cout<<0<<endl;
      break;
    }
    
    int64_t mid=(left+right)/2;
    int64_t sum=0;
    for(int i=0;i<N;++i){
      if(A.at(i)*F.at(i)>X-mid){
        sum += A.at(i)-(X-mid)/F.at(i);
      }
    }

    if(sum<=K){
      left=mid;
    }
    else{
      right=mid;
    }

    if(right-left==1){
      cout<<X-left<<endl;
    }
  }

}

Measured memory_bytes: 3328
let w, h, n = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let xyas = Array.init n @@ fun _ -> Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let l, r, b, t = ref 0, ref w, ref 0, ref h
let _ = Array.iter (fun (x, y, a) -> match a with 1 -> l := max !l x | 2 -> r := min !r x | 3 -> b := max !b y | _ -> t := min !t y) xyas; Printf.printf "%d\n" @@ max 0 (!r - !l) * max 0 (!t - !b)

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>

using namespace std;

int main () {
  long long N;
  cin >> N;
  
  if (N == 1) {
    cout << 0;
    return 0;
  } 
  long long ans = 0;
  for (long long i = 1; i*i <= N; i++) {
    if (N % i == 0) {
      if (N % (N / i - 1) == floor(N / (N / i - 1))) {
        ans += N / i - 1;
      }
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
c = [list(map(int, input().split())) for i in range(3)]
l = []
for i in range(3):
    l.append((c[i][1]-c[i][0], c[i][2]-c[i][1]))
for j in range(3):
    l.append((c[1][j]-c[0][j], c[2][j]-c[1][j]))
if l[0] == l[1] == l[2] and l[3] == l[4] == l[5]:
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 3064