akhauriyash/Code-Regression huggingface dataset:
import random
d=int(input())
c=list(map(int,input().split()))
num=[0]*26
ans=[]
numans=0
s=[]
for i in range(1,d+1):
    num1=1
    num2=-(10**100)
    num3=[0]*26
    for j in range(26):
        num3[j]=-1*((i-num[j])*c[j])
    s.append(list(map(int,input().split())))
    for j in range(26):
        num5=s[i-1][j]-num3[j]
        if num5>num2:
            num1=j+1
            num2=num5
    ans.append(num1)
    numans+=num2+s[i-1][num1-1]
    num[num1-1]=i
def sco(n1,n2,n3):
    n0=0
    n01=[0]*26
    old=ans[n1]
    ans[n1]=n2
    for k in range(n3):
        n0+=s[k][ans[k]-1]
        n01[ans[k]-1]=k+1
        for l in range(26):
            n0-=(k+1-n01[l])*c[l]
    return n0
for i in range(1540):
    num6=random.randint(1,26)
    num7=random.randint(1,d)
    num100=sco(num7-1,num6,d)
    if num100>=numans:
        ans[num7-1]=num6
for i in range(d):
    print(ans[i])


Measured memory_bytes: 9904
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <list>

class Edge{
public:
    int from, to;
    long long cost;
    Edge(): from(0), to(0), cost(0){}
    Edge(int u, int v, long long w): from(u), to(v), cost(w){}
    ~Edge(){}
    bool operator<(const Edge &e)const{
        return cost < e.cost;
    }
};

// Dijkstra's Algorithm
void Dijkstra(std::vector<Edge> &edge, int N, int start, std::vector<long long> &distance)
{
    typedef std::pair<long long, int> P;
    const long long infty = 1e+18;

    // initialize
    distance.clear();
    for(int i=0; i<N; i++) distance.push_back(infty);
    distance[start] = 0;
    std::priority_queue<P, std::vector<P>, std::greater<P> > q;
    q.push(P(0, start));

    std::vector<std::list<P> > edge_list(N);
    for(auto &&itr = edge.begin(); itr != edge.end(); itr++){
        edge_list[itr->from].push_back(P(itr->cost, itr->to));
    }

    // update
    while(!q.empty()){
        int d = q.top().first;
        int u = q.top().second;
        q.pop();
        if(distance[u] < d) continue; // not updated

        for(auto &&itr = edge_list[u].begin(); itr != edge_list[u].end(); itr++){
            int v = itr->second;
            long long w = itr->first;
            if(distance[u] + w < distance[v]){
                distance[v] = distance[u] + w;
                q.push(P(distance[v], v));
            }
        }
    }
}

int main()
{
    int N, M, S, T;
    scanf("%d %d", &N, &M);
    std::vector<Edge> edge;
    for(int i=0; i<M; i++){
        int u, v;
        scanf(" %d %d", &u, &v);
        u--; v--;
        edge.push_back(Edge(3*u  , 3*v+1, 1));
        edge.push_back(Edge(3*u+1, 3*v+2, 1));
        edge.push_back(Edge(3*u+2, 3*v  , 1));
    }
    scanf(" %d %d", &S, &T);
    S--; T--;

    std::vector<long long> distance;
    Dijkstra(edge, 3*N, 3*S, distance);

    if(distance[3*T] > 1e+17) std::cout << -1 << std::endl;
    else std::cout << distance[3*T] / 3 << std::endl;
}

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

// macros
#define overload_rep(_1, _2 ,_3 ,name, ...) name
#define re_p(i, n) for(int i = 0; i < (n); ++i)
#define r_ep(i, x, y) for(int i = (x); i < (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, r_ep, re_p,)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do{ cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << setprecision(20);
    }
} iosetup;

// Let's get AC!
int main(){

    int N;
    cin >> N;

    map<int, int> mp;
    rep(i, N){
        int a;
        cin >> a;
        mp[a]++;
    }

    int ans = mp.size();
    cout << (ans % 2 == 0 ? ans - 1 : ans) << endl;

}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	vector<vector<int>> M(10, vector<int>(10, 0));
	int n; cin >> n;
	int c = 1;
	for (int i=1; i<=n; i++) {
		if (i >= c*10) c *= 10;
		int a = i%10;
		int b = i / c;
		M[a][b]++;
	}
	int ret = 0;
	for (int i=1; i<10; i++) {
		for (int j=i; j<10; j++) {
			if (i==j) ret += pow(M[i][j], 2);
			else ret += M[i][j] * M[j][i] * 2;
		}
	}
	cout << ret << endl;
	return 0;
}

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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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

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

    int a, b, c; cin >> a >> b >> c;
    if(b - a == c - b) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int n;
vector<vector<P> > g;
vector<int> ans;

void dfs(int v, int p, int c)
{
    ans[v] = c;
    for (auto e : g[v])
    {
        if (e.first == p) continue;
        if (e.second & 1) dfs(e.first, v, 1 - c); //odd
        else dfs(e.first, v, c); //even
    }
}

int main()
{
    cin >> n;
    g.assign(n, vector<P>());

    rep(i, n - 1)
    {
        int u, v, w; cin >> u >> v >> w; --u;--v;
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }

    ans.assign(n, 0);
    dfs(0, -1, 1);
    for (auto v : ans) cout << v << endl;
}

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

int main(){
  int n; cin>>n;
  vector<int> num(n);
  for(int i=0;i<n;i++){
    cin>>num[i];
  }
  sort(num.begin(),num.end());
  long long count=0;
  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      int x=j+1;
      while(num[i]+num[j]>num[x]){
        count++; x++;
        if(x==n) break;
      }
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
while line = gets
y,m,d = line.split.map(&:to_i)
ymd = sprintf("%04d%02d%02d",y,m,d).to_i
if ymd < 18680908
  puts "pre-meiji"
  elsif 18680908 <= ymd && ymd <= 19120729 
  puts "meiji #{y - 1867} #{m} #{d}"
  elsif 19120730 <= ymd && ymd <=19261224
  puts "taisho #{y - 1911} #{m} #{d}"
  elsif 19261225 <= ymd && ymd <= 19890107
  puts "showa #{y - 1925} #{m} #{d}"
else
  puts "heisei #{y - 1988} #{m} #{d}"
end
end


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

int main() {
    int a,b,c;cin>>a>>b>>c;
    int flag=0;
    for(int i=0;i<=100;i++){
        if((i*a)%b==c) flag=1;
    }
    if(flag==1) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

constexpr char kBlack = '#';
constexpr char kWhite = '.';

typedef std::pair<int, int> Point;
bool is_done[1001][1001];

int main() {
  int H, W; std::cin >> H >> W;

  std::vector<Point> ps;
  for (int r = 0; r < H; ++r) {
    for (int c = 0; c < W; ++c) {
      char ch; std::cin >> ch;
      if (ch == kBlack) {
        ps.push_back({r, c});
        is_done[r][c] = true;
      } else {
        is_done[r][c] = false;
      }
    }
  }

  int cnt = 0;
  while (true) {
    std::vector<Point> next;
    for (Point p : ps) {
      int r = p.first;
      int c = p.second;

      if (r-1>=0 && !is_done[r-1][c]) { //up
        is_done[r-1][c] = true;
        next.push_back({r-1, c});
      }
      if (r+1<H && !is_done[r+1][c]) { //down
        is_done[r+1][c] = true;
        next.push_back({r+1, c});
      }
      if (c-1>=0 && !is_done[r][c-1]) { //left
        is_done[r][c-1] = true;
        next.push_back({r, c-1});
      }
      if (c+1<W && !is_done[r][c+1]) { //right
        is_done[r][c+1] = true;
        next.push_back({r, c+1});
      }
    }

    if (next.empty()) break;
    ++cnt;
    ps = next;
  }

  std::cout << cnt << std::endl;
}


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

int main() {
	int a,b;

	cin >> a >>b ;
	
	int n = a*b;
	
	if (n %2 ==0) {
		cout << "Even" << endl;
	}
	else {
		cout << "Odd" << endl;
	}
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))

buka=dict()
for x in a:
    if x not in buka:
        buka[x]=1
    else:
        buka[x]+=1
for i in range(n):
    if (i+1) not in buka:
        print(0)
    else:
        print(buka[i+1])

Measured memory_bytes: 33660
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

const ll p=1e9+7;
const int MAX_N=100000;

map<ll,map<ll,ll>> memo;
ll f(ll S, ll X) {
  if(memo[S].find(X)!=memo[S].end()) {
    return memo[S][X];
  }
  ll ret=0;
  if(S-2>=0)
    ret+=f((S-2)/2,X/2);
  if(S-1>=0&&X-1>=0)
    ret+=f((S-1)/2,(X-1)/2);
  ret+=f(S/2,X/2);
  return memo[S][X]=ret%p;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  ll n;
  cin>>n;
  memo[0][0]=1;
  memo[1][0]=1;
  memo[0][1]=1;
  memo[1][1]=2;
  cout << f(n,n)<<endl;
  return 0;
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main()
{
    lint k;cin >> k;
    string s;
    cin >> s;
    lint ans=0;
    if(SZ(s)<=k){
        cout << s << "\n";
        return 0;
    }else{
        REP(i,k){
            cout << s[i];
        }
        cout << "..."
             << "\n";
    }


    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>m;

    for(int i=0;i<n;i++){
        cin>>x;
        pq.push(x);
    }

    while(m--){
        cur = pq.top(); pq.pop();
        cur>>=1;
        pq.push(cur);
    }

    ll res = 0;

    while(n--){
        cur = pq.top(); pq.pop();
        res+=(ll)cur;
    }

    cout<<res<<"\n";

    return 0;
}


Measured memory_bytes: 892
#include <stdio.h>

#define MAX 100005
#define NIL -1

typedef struct {int p, l, r;} Node;

Node T[MAX];
int n, D[MAX];

void print(int u) {
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);

  if( T[u].p == NIL ) printf("root, ");
  else if( T[u].l == NIL ) printf("leaf, ");
  else printf("internal node, ");

  printf("[");

  for(i=0, c=T[u].l; c != NIL; i++, c=T[c].r) {
    if(i) printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}

void rec(int u, int p) {
  D[u] = p;
  if(T[u].r != NIL) rec(T[u].r,p);
  if(T[u].l != NIL) rec(T[u].l,p+1);
}

int main(void) {
  int i,j,d,v,c,l,r;
  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].p = T[i].l = T[i].r = NIL;
  for(i=0;i<n;i++) {
    scanf("%d %d",&v,&d);
    for(j=0;j<d;j++) {
      scanf("%d",&c);
      if(j==0) T[v].l=c;
      else T[l].r =c;
      l = c;
      T[c].p = v;
    }
  }
  for(i=0;i<n;i++) {
    if(T[i].p == NIL) r = i;
  }
  
  rec(r,0);
  
  for(i=0;i<n;i++) print(i);
  
  return 0;
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    s.erase(unique(all(s)), s.end());
    cout << sz(s) << endl;
    return 0;
}


Measured memory_bytes: 3684
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

ll cdigit(ll N, ll digit) {
  ll num = digit;
  ll count = 0;
  ll mcount = N;
  while (num * digit <= N) num *= digit;
  while (N >= digit) {
    while (N < num) num /= digit;
    N -= num;
    count++;
    mcount = min(mcount, count + cdigit(N, digit == 6 ? 9 : 6));
  }
  return min(mcount, count + N);

}

int main()
{
  ll N;
  cin >> N;
  cout << min(cdigit(N, 6), cdigit(N, 9)) << endl;

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int) (n); i++)
typedef long long ll;


int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int          N;
    int          max = 0;
    vector <int> input(0);
    vector <int> ans(0);
    cin >> N;
    rep(i, N - 1) {
        int buf;
        cin >> buf;
        input.push_back(buf);
    }
    rep(i, N) {
        if (i == 0) {
            ans.push_back(input.at(i));
            continue;
        }
        if (i == N - 1) {
            ans.push_back(input.at(i - 1));
            continue;
        }
        ans.push_back(min(input.at(i), input.at(i - 1)));
    }
    for (int x : ans) {
        max += x;
    }
    cout << max << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>

using namespace std;

int main() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  array<long long, 4> multis = {a*c, a*d, b*c, b*d};
  cout << *max_element(multis.begin(), multis.end()) << "\n";
}

Measured memory_bytes: 3616
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(1000000)
from collections import deque

# スペース区切りの整数の入力
H, W = map(int, input().split())

#配列の入力
s = [list(input()) for _ in range(H)]

dist = [[-1 for _ in range(W)]for _ in range(H)]


def bfs():
    que = deque()
    que.append((0, 0))
    dist[0][0] = 0
    offset = ((1,0),(-1,0),(0,1),(0,-1))
    while que:
        now_h, now_w = que.popleft()
        if now_h < 0 or H-1 < now_h or now_w < 0 or W-1 < now_w:
            continue
        if s[now_h][now_w] == '#':
            continue
        for oh, ow in offset:
            if now_h+oh < 0 or H-1 < now_h+oh or now_w+ow < 0 or W-1 < now_w+ow:
                continue
            if dist[now_h+oh][now_w+ow] != -1:
                continue
            else:
                dist[now_h+oh][now_w+ow] = dist[now_h][now_w]+1
                que.append((now_h+oh, now_w+ow))





bfs()
m = dist[H-1][W-1]

if m == -1:
    print(-1)
else:
    count = 0
    for t in s:
        count += t.count('.')
    
    print(count - m- 1)



Measured memory_bytes: 9404
#include <stdio.h>
int main(){
	int n,i,a[100][2],b=0,f=0;
	scanf("%d",&n);
	for(i=1;i<n;i++){
		if(n%i==0){
			a[b][0]=i;
			a[b][1]=n/i;
			b++;
			}
		}
	for(i=0;i<b;i++){
		if(a[i][0]<=9&&a[i][0]>=1&&a[i][1]<=9&&a[i][1]>=1){
			f=1;
			break;
		}}
	if(f==1||n==1)printf("Yes\n");
	if(f==0&&n!=1) printf("No\n");
	
	
	
	
	
	 
	
	
	
	
	
	
	
	
	
	
	
	
	
} 


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }



void solve(void)
{
  int R,G,B,N;
  cin>>R>>G>>B>>N;
  int ANS = 0;
  for (int r = 0; r < 3001; r++)
  {
    for (int g = 0; g < 3001; g++)
    {
      int X = N - r*R - g*G;
      if(X%B == 0 && X >= 0)ANS++;
    }
    
  }
  cout<<ANS<<endl;
  
  return;
}




int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> g[123456];
int d[123456], vis[123456];
int dfs(int x) {
	if(vis[x]) return d[x];
	vis[x] = 1;
	d[x] = 0;
	for(int i = 0; i < g[x].size(); i++) {
		int nxt = g[x][i];
		d[x] = max(d[x], dfs(nxt) + 1);
	}
	return d[x];
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		g[x].push_back(y);
	}
	for(int i = 0; i < n; i++) {
		if(vis[i]) continue;
		d[i] = dfs(i);
	}
	int ans = 0;
	for(int i = 0; i < n; i++) {
		ans = max(ans, d[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9088
IDENTIFICATION DIVISION.
      PROGRAM-ID. 145A.
      DATA DIVISION.
      WORKING-STORAGE SECTION.
      01 INP PIC X(3).
      01 R   PIC 9(3).
      01 ANS PIC ZZZZZZ9.

      PROCEDURE DIVISION.
      ACCEPT INP.
      MOVE INP TO R.
      COMPUTE ANS = R * R
      
      DISPLAY FUNCTION TRIM(ANS).
      
      STOP RUN.

Measured memory_bytes: 636
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int coin[] = {1, 5, 10, 50, 100, 500};
    int INF = INT_MAX / 2;

    for(;;){
        int p;
        cin >> p;
        if(p == 0)
            return 0;

        vector<int> n(6);
        for(int i=0; i<6; ++i)
            cin >> n[i];

        int ret = 0;
        for(int i=5; i>=0; --i){
            while(p > 500 && n[i] > 0){
                p -= coin[i];
                -- n[i];
                ++ ret;
            }
        }

        vector<int> dp(1001, INF);
        dp[0] = 0;
        for(int i=0; i<6; ++i){
            for(int j=1000; j>=1; --j){
                for(int k=1; k<=n[i]; ++k){
                    if(j-k*coin[i] < 0)
                        break;
                    dp[j] = min(dp[j], dp[j-k*coin[i]] + k);
                }
            }
        }

        int ret2 = INF;
        for(int i=p; i<=1000; ++i){
            if(dp[i] == INF)
                continue;
            int a = i - p;
            int b = 0;
            for(int i=5; i>=0; --i){
                b += a / coin[i];
                a %= coin[i];
            }
            ret2 = min(ret2, dp[i] + b);
        }

        ret += ret2;
        cout << ret << endl;
    }
}

Measured memory_bytes: 908
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s,t,u;cin>>s>>t;
  ll a,b,ans;cin>>a>>b; cin>>u;
  if(u==s) a--; else b--;
  cout<<a<<' '<<b<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define gc getchar_unlocked
#define cases int t;  cin>>t;   while(t--)
ll mod =1e9+7;
//template<typename T> 
inline ll pwr(ll base,ll n){ll ans=1;while(n>0){ if(n%2==1)ans=ans*base;  base=base*base; n/=2;} return ans;}
struct range{int l,h;}; 
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll int n;
    cin>>n;
    n--;

    ll int ans=(n*(n+1LL))/2;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
def gcd(a,b):
    c = a % b
    if c == 0:
        return b
    else:
        return gcd(b, c)
    
if __name__ == "__main__":
    import sys
    a, b = [ int(e) for e in sys.stdin.readline().strip().split() ]
    print gcd(max(a,b), min(a,b))

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

const int MAX = 1e5 + 10;

ll a[MAX],b[MAX],c[MAX];

bool cmp(int l,int r){
	return a[l]+b[l] > a[r]+b[r];
}

int main()
{
	int n; cin>>n;
	for(int i=0;i<n;i++) {cin>>a[i]>>b[i];c[i]=i;}
	ll ans = 0;
	sort(c,c+n,cmp);
	
	for(int i=0;i<n;i++){
		if(i%2) ans -= b[c[i]];
		else ans += a[c[i]];
	}	

	cout<<ans;
}

Measured memory_bytes: 2560
N,K = map(int, input().split())
R,S,P = map(int, input().split())
T = input()

L = [0]*N
ans = 0
for i in range(N):
    if i < K:
        if T[i] == "r":
            L[i] = "p"
            ans += P
        elif T[i] == "s":
            L[i] = "r"
            ans += R
        else:
            L[i] = "s"
            ans += S
    else:
        if T[i] == "r" and L[i-K] != "p":
            ans += P
            L[i] = "p"
        if T[i] == "s" and L[i-K] != "r":
            ans += R
            L[i] = "r"
        if T[i] == "p" and L[i-K] != "s":
            ans += S
            L[i] = "s"
                
print(ans)

Measured memory_bytes: 44532
#include <bits/stdc++.h>
#define MAX 1000005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
 
ll gcd(ll n1,ll n2){
	if(n2==0)
		return n1;
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent)
{
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
ll arr[MAX];
ll dp[MAX][3];
int main()
{
	ll n,p;
	cin>>n>>p;
	for(int i=1;i<=n;i++)
	{
		cin>>arr[i];
		/*if(arr[i]&1)
			odd++;
		else
			even++;*/
	}
	if(arr[1]&1)
	{
		dp[1][0]=1;
		dp[1][1]=1;
	}
	else
	{
		dp[1][1]=0;
		dp[1][0]=2;
	}
	for(int i=2;i<=n;i++)
	{
		if(arr[i]&1)
		{
			dp[i][0]=dp[i-1][0]+dp[i-1][1];
			dp[i][1]=dp[i-1][1]+dp[i-1][0];
		}
		else
		{
			dp[i][0]=dp[i-1][0]+dp[i-1][0];
			dp[i][1]=dp[i-1][1]+dp[i-1][1];
		}
		//cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
	}
	cout<<dp[n][p]<<endl;
}

Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <typeinfo>
#include <list>
#include <queue>
#include <stack>
#include <limits.h>
#include <unordered_set>
#include <map>
#include <cstring>

using namespace std;

typedef long long ll;

int mod = 1e9 + 7;

int Solve(int h[], int N) {
    int res = h[0];
    for (int i = 1; i < N; i++) {
        if (h[i] > h[i - 1]) {
            res += h[i] - h[i - 1];
        }
    }
    return res;
}


int main() {
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int* h = new int(N);
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }
    cout << Solve(h, N);
    return 0;
}


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 pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    ll a; cin >> a;
    double b; cin >> b;
    ll c = b * 100 + 0.5;
    cout << a * c / 100 << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 100005;
vector<int> g[N];
int d[N], p[N], sz[N];

void dfs(int v, int par = -1, int __dist = 0){
	sz[v] = 1;
	p[v] = par;
	d[v] = __dist;
	for(auto u : g[v]){
		if(u != par){
			dfs(u, v, __dist + 1);
			sz[v] += sz[u];
		}
	}
}

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

	int n; cin>>n;
	for(int i = 1; i < n; i++){
		int u, v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1);
	int dist = (d[n] - 1)/2;
	int v = n;
	while(dist--)v = p[v];
	if(2*sz[v] >= n){
		cout<<"Snuke\n";
	}else{
		cout<<"Fennec\n";
	}


	return 0;
}

Measured memory_bytes: 14720
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
#define rep(i,n) for(int i = 0 ; i < n ; i++)
 
int main(){
    int mon[100][100];
    int tim[100][100];
    int n,m;
    while(cin >> m >> n && n ){
        rep(i,n)rep(j,n) mon[i][j] = tim[i][j] = 1e9;
        for(int i = 0 ; i < m ; i++){
            int a,b,c,d;
            cin >> a >> b >> c >> d;
            a--,b--;
            mon[a][b] = mon[b][a] = c;
            tim[a][b] = tim[b][a] = d;
        }
        rep(i,n)rep(j,n)rep(k,n){
            mon[j][k] = min(mon[j][k],mon[j][i]+mon[i][k]);
            tim[j][k] = min(tim[j][k],tim[j][i]+tim[i][k]);
        }
        int R;
        cin >> R;
        rep(i,R){
            int a,b,c;
            cin >> a >> b >> c;
            a--,b--;
            if(c) cout << tim[a][b];
            else cout << mon[a][b];
            cout << endl;
        }
    }
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int mod=1e9+7;

int main(){
    int n,q;cin>>n>>q;
    vector<int> G[n];
    rep(i,n-1){
        int a,b;cin>>a>>b;
        --a;--b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int ctr[n]={};
    rep(i,q){
        int p,x;cin>>p>>x;
        ctr[--p]+=x;
    }
    int reached[n]={};
    reached[0]=1;
    queue<int> Q;
    Q.push(0);
    while(!Q.empty()){
        int f=Q.front();
        Q.pop();
        for(auto v:G[f]){
            if(reached[v])continue;
            ctr[v]+=ctr[f];
            reached[v]=1;
            Q.push(v);
        }
    }
    rep(i,n){
        if(i)cout<<" ";
        cout<<ctr[i];
    }
    cout<<endl;
}


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

int main(){
    long A, B, K; cin >> A >> B >> K;
    if(A>K) A -= K;
    else if (A<=K && A+B>=K){
        B -= (K - A); 
        A = 0;
    }
    else {
        A = 0;
        B = 0;
    }
    cout << A << " " << B << endl;    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
int  t,k,n, i, j, m;
int a[10009]={0};
cin>>n;
for(i= 0; i < n; i++){
cin>>t;
a[t]++;
}
k=0;
for(i = 0; i <10009; i++){
if(a[i]!=0){
for(j = 0; j < a[i]; j++){
cout<<i;
k++;
if(k<=n-1) cout<<" ";
}
}
}
cout<<endl;
return 0;
}

Measured memory_bytes: 3116
a,b = map(str, input().split())

abint = int(a+b)

ans = 0

for i in range(1,1001):
    for j in range(1,1001):
        if i*j == abint and i == j:
            ans = ans + 1

if ans == 0:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 2940
m,i,j,k,c[],p;main(n){for(;scanf("%d%d",&n,&m),n;printf("%d\n",j>m?k:j)){for(k=3;k--;)for(scanf("%d",&i);i--;c[j]=k)scanf("%d",&j);for(j=i=0;i++<n;p+=c[i]*2)j+=pow(3,n-i)*abs(p%4-c[i]);j=fmin(j,pow(3,n)+~j);}}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>

int main()
{ int n,m,a,b,c,t;
  while(~scanf("%d %d",&n,&m))
  {  a=n+m;
     b=n-m;
     c=n*m;
     if(a<c)
        t=a,a=c,c=t;
     if(a<b)
        t=a,a=b,b=t;
     if(b<c)
         t=b,b=c,c=t;
    printf("%d\n",a);

  }
    return 0;
}


Measured memory_bytes: 128
// AtCode.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>

using namespace std;

typedef vector<vector<char>> Graph;
typedef vector<vector<bool>> Seen;

typedef struct {
	int x = 0;
	int y = 0;
	int dist = 0;
} P;


int main() {

	int H, W;
	cin >> H >> W;

	Graph graph;
	graph.resize(H);
	Seen seen;
	seen.resize(H);

	queue<P> que;  // キューを用意して、初期探索点をセット

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			char tmp;
			cin >> tmp;
			graph[i].push_back(tmp);
			seen[i].push_back(false);
			if (tmp == '#') {
				que.push(P{ i, j, 0 }); // if black add que
				seen[i][j] = true;
			}
		}
	}
	// #=black, .=white

	int max_dist = 0;
	while (!que.empty()) {
		// キューの先頭のセルを取得
		P v = que.front(); que.pop();
		int x = v.x;
		int y = v.y;
		int dist = v.dist;
		max_dist = max(max_dist, dist);

		if (x + 1 < H) {
			if (!seen[x+1][y] && graph[x + 1][y] == '.') { // 処理以降条件
				que.push(P{ x+1, y, dist+1 });
				seen[x+1][y] = true;
			}
		}
		if (x - 1 >= 0) {
			if (!seen[x - 1][y] && graph[x - 1][y] == '.') { // 処理以降条件
				que.push(P{ x - 1, y, dist + 1 });
				seen[x-1][y] = true;
			}
		}
		if (y + 1 < W) {
			if (!seen[x][y + 1] && graph[x][y + 1] == '.') { // 処理以降条件
				que.push(P{ x, y + 1, dist + 1 });
				seen[x][y+1] = true;
			}
		}
		if (y - 1 >= 0) {
			if (!seen[x][y - 1] && graph[x][y - 1] == '.') { // 処理以降条件
				que.push(P{ x, y - 1, dist + 1 });
				seen[x][y-1] = true;
			}
		}
	}

	cout << max_dist << endl;

	return 0;

}


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

int main(void)
{
    string w;
    cin >> w;
    map<char,int> mp;
    for(int i = 0; i < w.size(); i++) mp[w[i]]++;
    for(char i = 'a';i <= 'z'; i++){
        if(mp[i]%2 != 0){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}



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

using namespace std;

const long long M = 1e9+7;
int a[10003], cnt[1000003];

long long Pow(int x, int n)
{
    if (n == 1) return x;
    if (n % 2) return x * Pow(x, n-1) % M;
    long long memo = Pow(x, n/2);
    return memo * memo % M;
}

void f(int x)
{
    for (int i = 2; i*i <= x; ++i) if (x % i == 0) {
        int c = 0;
        while (x % i == 0) {
            c++;
            x /= i;
        }
        cnt[i] = max(cnt[i], c);
    }
    if (x > 1) {
        cnt[x] = max(cnt[x], 1);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        f(a[i]);
    }

    long long all = 1;
    for (int i = 2; i < 1000003; ++i) {
        while (cnt[i]) {
            cnt[i]--;
            all *= i;
            all %= M;
        }
    }

    long long an = 0;
    for (int i = 0; i < n; ++i) {
        an += all * Pow(a[i], M-2);
        an %= M;
    }
    cout << an << endl;

    return 0;
}


Measured memory_bytes: 4224
#-*- coding:utf-8 -*-
#approach:
#????????????????????±??????N???S??????????????¨W???E??????????????¨????????????
rolls = raw_input().split()
order = raw_input().strip()
nsrolls = [rolls[0],rolls[1],rolls[5],rolls[4]]
werolls = [rolls[0],rolls[2],rolls[5],rolls[3]]
while True:
    if order == "":
        break
    o = order[0]
    if o=="N":
        tmp = nsrolls[0]
        nsrolls.pop(0)
        nsrolls.append(tmp)
        werolls[0]=nsrolls[0]
        werolls[2]=nsrolls[2]
    elif o=="S":
        tmp = nsrolls[-1]
        nsrolls.pop(-1)
        nsrolls.insert(0,tmp)
        werolls[0]=nsrolls[0]
        werolls[2]=nsrolls[2]
    elif o=="W":
        tmp = werolls[0]
        werolls.pop(0)
        werolls.append(tmp)
        nsrolls[0]=werolls[0]
        nsrolls[2]=werolls[2]
    elif o=="E":
        tmp = werolls[-1]
        werolls.pop(-1)
        werolls.insert(0,tmp)
        nsrolls[0]=werolls[0]
        nsrolls[2]=werolls[2]
    else:
        print "invalid order"
    order = order[1:]
print nsrolls[0]

Measured memory_bytes: 6480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int N;
P a[500000];
bool compare_y(P a,P b){
	return a.second<b.second;
}
ll closest_pair(P *a,int n){
	if(n<=1)	return LLONG_MAX;
	int m=n/2;
	ll x=a[m].first;
	ll d=min(closest_pair(a,m),closest_pair(a+m,n-m));
	inplace_merge(a,a+m,a+n,compare_y);
	vector<P> b;
	for(int i=0;i<n;i++){
		if(llabs(a[i].first-x)>=d)	continue;
		for(int j=0;j<(int)b.size();j++){
			ll dx=a[i].first-b[b.size()-j-1].first;
			ll dy=a[i].second-b[b.size()-j-1].second;
			if(dy>=d)	break;
			d=min(d,dx*dx+dy*dy);
		}
		b.push_back(a[i]);
	}
	return d;
}
void solve(){
	sort(a,a+N);
	printf("%lld\n",closest_pair(a,N));
}
int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%lld %lld",&a[i].first,&a[i].second);
	}
	solve();
	return 0;
}

Measured memory_bytes: 20464
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  long long ans;
  for(int i=0;i<N;i++){
    if(i==0) ans=K;
    else ans*=K-1;
  }
  cout<<ans<<endl;
}

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

int mod = 1000000007;
int64_t large = 9223372036854775807;

int main()
{
    string S;
    cin >> S;
    int x = 0;
    int y = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] == '0')
            x++;
        if (S[i] == '1')
            y++;
    }
        cout << min(x, y) * 2;
}

Measured memory_bytes: 512
import sys,math,collections,itertools
input = sys.stdin.readline

N = int(input())
red = []
blue=[]
for _ in range(N):
    a,b=list(map(int,input().split()))
    red.append([a,b])
for _ in range(N):
    a,b=list(map(int,input().split()))
    blue.append([a,b])

red.sort()
blue.sort(reverse=1)
cnt =0

while blue:
    a,b = blue.pop()
    idx = -1
    tmp = -1
    for ai in range(len(red)):
        if red[ai][0]>a:
                break
        else:
            if red[ai][1]>tmp and red[ai][1]<b:
                idx=ai
                tmp = red[ai][1]
    if idx != -1:
        red.pop(idx)
        cnt +=1
print(cnt)
                
    


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

namespace ABC131A
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            List<int[]> vs = new List<int[]>();

            for (int i = 0; i < n; i++)
            {
                var ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                vs.Add(ab);
            }

            var svs = vs.OrderBy(x => x[1]);
            int sum = 0;
            bool isOK = true;

            foreach (var tmp in svs)
            {
                sum += tmp[0];
                if (sum > tmp[1])
                {
                    isOK = false;
                    break;
                }

            }
            if (isOK)
            {
                Console.WriteLine("Yes");

            }
            else
            {
                Console.WriteLine("No");
            }

        }
    }
}


Measured memory_bytes: 33808
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (a);)
#define all(v) (v).begin(),(v).end()
#define trav(x,v) for(auto &x : v)
#define sz(v) int(v.size())
typedef long long ll;
typedef vector<ll> vl;

ll mod;
int n;

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

	cin >> n >> mod;

	vl cnt(n+1);
	cnt[n] = 1;
	rep(i,1,n){
		int c = min(i, n+1-i);
		rrep(j,c,n+1) cnt[j-c] = (cnt[j-c]+cnt[j]) % mod;
	}
	ll ans = 0;
	rep(i,1,n+1) ans += i * cnt[i];
	cout << ans % mod << endl;
}


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

typedef long long int ll;
ll a, b, k;

int main() {
    cin >> k >> a >> b;
    for(ll i = a; i <= b; ++i) {
        if(i%k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h> 
using namespace std;
const int N = 1e5+5;
vector<int> dp(N), n[N]; 
 
int lp(int i) {
  if(dp[i]) 
    return dp[i];
  for(auto p:n[i])
    dp[i]=max(dp[i], lp(p) + 1);
  return dp[i];
} 
int main() { 
  int N, M, x, y;
  cin >> N >> M; 
  for(int i = 0; i < M; i++) 
    cin >> x >> y, n[x].push_back(y); 
  int rez = 0; 
  for(int i = 1; i <= N; i++) 
    rez  = max(rez, lp(i)); 
  cout << rez; 
  return 0; 
}

Measured memory_bytes: 8192
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

int main(){
	
	int L;
	
	while(true){
		
		cin >> L;
		if(L == 0){
			break;
		}
		
		int ans = 0;
		bool check = true;
		
		for(int i = 0; i < 12; i++){
			int M, N;
			cin >> M >> N;
			L -= (M - N);
			if(check && L <= 0){
				check = false;
				ans = i + 1;
			}
		}
		
		if(check){
			cout << "NA" << endl;
		}else{
			cout << ans << endl;
		}
		
	}
	
	return 0;
}

Measured memory_bytes: 3064
import java.lang.Math.ceil

fun main (args:Array<String>) {
    val (N, M) = readLine()!!.split(" ").map(String::toInt)
    val productList = readLine()!!.split(" ").map(String::toInt).sortedWith(reverseOrder())
    // prntln(productList)  // debug
    val minChooseablePoint = ceil(productList.sum() / (4.0 * M))
    // println(productList.sum().toString() + ", " + minChooseablePoint.toString())  // debug
    var chooseableCount = 0
    for (product in productList) {
        if (product < minChooseablePoint) break
        chooseableCount++
        if (chooseableCount == M) break
    }
    if (chooseableCount == M) print("Yes")
    else print("No")
}


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

int N, M, X, Y, x[105], y[105];
int x_max = -100, y_min = 100;

int main()
{
  cin >> N >> M >> X >> Y;
  for (int i = 0; i < N; i++) {
    cin >> x[i];
    if (x_max < x[i]) {
      x_max = x[i];
    }
  }
  for (int i = 0; i < M; i++) {
    cin >> y[i];
    if (y_min > y[i]) {
      y_min = y[i];
    }
  }

  if (y_min - x_max > 0 && x_max > X && y_min < Y) {
    cout << "No War" << endl;
  } else {
    cout << "War" << endl;
  }
  return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;


// now += mint(2).pow(s) - 1; こんな感じで、2のs乗を求められrう
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
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*(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;
  }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n)cin>>a[i];

	mint sum = 0;
	rep(i,n) {
		sum += a[i];
	}
	mint ans = 0;
	rep(i,n){
		ans += (sum - a[i]) * a[i];
		sum -= a[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 3988
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		if(a>=13) System.out.println(b);
		else if(a>=6) System.out.println(b/2);
		else System.out.println(0);
		in.close();
	}

}


Measured memory_bytes: 21844
from fractions import gcd

def prime_factors(n):
  i = 2
  factors = []
  while i * i <= n:
    if n % i:
      i += 1
    else:
      n //= i
      factors.append(i)
  if n > 1:
    factors.append(n)
  return factors

A,B = map(int,input().split())
G = gcd(A,B)
#print(G)
plist = prime_factors(G)
ans = 1
prep = 1
for p in plist:
  if p != prep:
    ans += 1
    prep = p
print(ans)


Measured memory_bytes: 65516
#include<bits/stdc++.h>
using namespace std;
int main() {
    string str;
    cin >> str;
    int cnt = 0;

    for(int i=0; i<3; i++) {
        if(str[i] == '1') {
            cnt++;
        }
    }
    //cout << cnt << endl;
    cout << cnt << endl;
}

Measured memory_bytes: 256
N      = input()
A_list = list(map(int, input().split()))
answer = 1

if 0 in A_list:
  answer = 0
  print(answer)
else:
  for a in A_list:
    answer *= a
    if answer > 10**18:
      answer = -1
      print(answer)
      break
  else:
    print(answer)

Measured memory_bytes: 21648
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b;
    cin>>a>>b;
    if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0])
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc= new Scanner(System.in);
		
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		
		ArrayList<Integer> list=new ArrayList<>();
		
		list.add(a);
		list.add(b);
		list.add(c);
		
		System.out.println(list.get(2)+" "+list.get(0)+" "+list.get(1));
		
	}
}


Measured memory_bytes: 25300