akhauriyash/Code-Regression huggingface dataset:
N = int(input())
D = None

for i in range(int(N/4)+1):
    for j in range(int(N/7)+1):
        if 4*i+7*j == N:
            D = True
            break
        elif j == int(N/7)+1:
            D = False

if D:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
def root(a, x)
  a[x] < 0 ? x : a[x] = root(a, a[x])
end

def unite(a, x, y)
  x, y = root(a, x), root(a, y)
  if x != y
    x, y = y, x if a[y] < a[x]
    a[x] += a[y]
    a[y] = x
  end
end

def connected?(a)
  a.any?{|e| e == -N}
end

N, M = gets.split.map(&:to_i)
ABs = readlines.map{|l| l.split.map(&:to_i)}

ans = 0
ABs.each do |a, b|
  @p = Array.new(N + 1, -1)
  (ABs - [[a, b]]).each{|c, d| unite(@p, c, d)}
  ans += 1 unless connected?(@p)
end
puts ans

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

ll x[3000],r,d;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>r>>d>>x[2000];
    for(int i=2001;i<=2010;i++){
        x[i] = x[i-1]*r - d;
        cout<<x[i]<<newl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x,h,w) (y) < 0 || (h) <= (y) || (x) < 0 || (w) <= (x)
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int h, w, d; cin >> h >> w >> d;
    vector<VI> a(h, VI(w));
    vector<pair<int, int>> we(h * w);
    FOR(i, 0, h)FOR(j, 0, w) {
        cin >> a[i][j]; --a[i][j];
        we[a[i][j]] = make_pair(i, j);
    }

    VL cost(h* w);
    FOR(i, 0, d) {
        for (int j = i + d; j < h * w; j += d) {
            cost[j] = cost[j - d];
            cost[j] += +abs(we[j - d].first - we[j].first);
            cost[j] += +abs(we[j - d].second - we[j].second);
        }
    }

    int q; cin >> q;
    while (q--) {
        int l, r; cin >> l >> r;
        --l, --r;
        cout << cost[r] - cost[l] << "\n";
    }
}


Measured memory_bytes: 2944
N,Y = map(int,input().split())
flag = False
if 10000*N < Y:print('-1 -1 -1')
else:
  for i in range(N+1):
    if flag == True:break
    if 10000*i + 5000*(N-i) < Y:
      pass
    else:
      for j in range(N-i+1):
        k = N - i - j
        if k < 0:print(k)
        if 10000*i + 5000*j + 1000*k == Y:
          flag = True
          print(str(i)+' '+str(j)+' '+str(k))
          break
  if flag == False:
    print('-1 -1 -1')

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    ll n;
    cin>>n;
    V<ll> a(n);
    set<ll> st;
    map<ll,ll> mp;
    rep(i,n){
        cin>>a[i];
        st.insert(i+1);
        mp[a[i]]=i+1;
    }
    st.insert(-1);
    st.insert(0);
    st.insert(n+1);
    st.insert(n+2);
    ll ans=0;
    for(ll i=1;i<n;i++){
        ll s,t,u,v;
        auto it1=st.find(mp[i]);
        auto it2=st.find(mp[i]);
        auto it3=st.find(mp[i]);
        auto it4=st.find(mp[i]);
        auto it=st.find(mp[i]);
        it1--;
        it1--;
        it2--;
        it3++;
        it4++;
        it4++;
        if(*it1==-1) s=0;
        else s=*it1;
        t=*it2;
        u=*it3;
        if(*it4==n+2) v=n+1;
        else v=*it4;
        ans+=((t-s)*(u-*it)+(*it-t)*(v-u))*i;
        it=st.erase(it);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 12032
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    if (N == 1) {
        cout << "Hello World" << endl;
    } else {
        int A, B;
        cin >> A >> B;
        cout << A + B << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){



		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		String s = sc.next();	
		for(int i =0;i<s.length();i++) {
			char c = s.charAt(i);
			int limit = (int)'Z'-(int)'A';
			int target = (int)c + n;
			if(target>(int)'Z') {
				target = target-limit-1;
			}
			System.out.print((char)target);
		}
	}

}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/


Measured memory_bytes: 26324
#include <bits/stdc++.h>
using namespace std;
// clang-format off

using LL = long long;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
 
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
// clang-format on

int main() {
  long long N;
  scanf("%lld", &N);

  std::map<string, LL, greater<>> S;

  int max_num = 0;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    S[s]++;

    int tmp = S[s];
    max_num = max(max_num, tmp);
  }

  // for (auto e : S) {
  //   cout << e << endl;
  // }

  vector<string> str;
  for (auto e : S) {
    // cout << e << endl;
    if (e.second == max_num) {
      str.push_back(e.first);
    }
  }

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

  for (auto e : str) {
    cout << e << endl;
  }

  // vector<string> str;
  // for (auto e : S) {
  //   COUT(e.second);
  //   // cout if (e.second == max_num) {
  //   //   str.push_back(e.first);
  //   // }
  // }

  // sort(str.begin(), str.end());

  // for (auto e : str) {
  //   cout << e << endl;
  // }

  return 0;
}


Measured memory_bytes: 26868
#include<iostream>
#include<string>
#include <cmath>
#include <algorithm>
#define MOD 1e9+7
using namespace std;
typedef long long ll;

int main(){

int n,m;
int a[1000],b[1000],c[1000],dist[100][100];

cin >> n >> m;

for(int i = 0; i <m; i++){
cin >> a[i] >> b[i] >> c[i];
a[i]--; b[i]--;           // インデックスに合わせる //
}

//     距離の初期化     //
for(int i = 0; i<n; i++){
 for(int j = 0; j<n; j++){
  if(i == j) dist[i][j] = 0;
  else      dist[i][j] = MOD;
 }
}

// 各隣接頂点間の距離 //
for(int i = 0; i < m; i++){
dist[a[i]][b[i]]=min(dist[a[i]][b[i]],c[i]);
dist[b[i]][a[i]]=min(dist[b[i]][a[i]],c[i]);
}

// 全経路を探索(ワーシャルフロイド法、O(n^3)だがn=100程度なら問題なし.)  //
for(int k = 0; k<n; k++){
 for(int i = 0; i<n; i++){
  for(int j = 0; j<n; j++){
dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]);  // kを経由する方が短い？？//
  }
 }
}

// 辺ｋを最短経路に含むかどうか？ //
// 辺ｋ以降の長さが等しいことは自明なため省略可能.O(mn^2) -> O(mn). //
int ans = 0;
for(int i = 0; i<m; i++){
int flag = 0;
  for(int j = 0; j<n; j++){
if(dist[j][b[i]] == dist[j][a[i]] + c[i]) flag = 1;
  }
if(flag == 0) ans++;
 }

cout << ans << endl;

return 0;
}

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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int a, b;
  cin >> a >> b;

  int k = 50;
  char grid[110][110];
  rep(y, 2 * k) rep(x, 2 * k) {
    if (y < k)
      grid[y][x] = '#';
    else
      grid[y][x] = '.';
  }

  for (int y = 0; y < k - 1; y += 2) {
    for (int x = 0; x < 2 * k; x += 2) {
      if (a <= 1) continue;
      grid[y][x] = '.';
      a--;
    }
  }

  for (int y = k + 1; y < 2 * k - 1; y += 2) {
    for (int x = 0; x < 2 * k; x += 2) {
      if (b <= 1) continue;
      grid[y][x] = '#';
      b--;
    }
  }

  cout << 2 * k << " " << 2 * k << endl;
  rep(y, 2 * k) {
    rep(x, 2 * k) cout << grid[y][x];
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int n;
	scanf("%d", &n);
	std::vector<ll> a(n);
	REP(i, 0, n) scanf("%ld", &a[i]);
	a.push_back(0);

	ll sell = a[0], ans = 1000;
	REP(i, 0, n){
		if(sell>a[i]) sell = a[i];
		else if(a[i]>a[i+1]){
			ans = ans%sell + ans / sell * a[i];
			sell = a[i];
		}
	}
	printf("%ld\n", ans);
	return 0;
}



Measured memory_bytes: 3784
def main():
    s = input()
    mod = 2019

    n = 0
    R = [0] * mod
    R[0] += 1
    for i in range(len(s)):
        n += int(s[-i - 1]) * pow(10, i, mod)
        R[n % mod] += 1

    print(sum([r * (r - 1) // 2 for r in R]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 68492
import sys
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd

class UnionFind:
    def __init__(self, n):
        self._parents = list(range(n))
        self._ranks = [0] * n
        self._size = [1] * n

    def root(self, x):
        if self._parents[x] == x:
            return x
        self._parents[x] = self.root(self._parents[x])
        return self._parents[x]

    def size(self, x):
        return self._size[self.root(x)]

    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry:
            return

        if self._ranks[rx] < self._ranks[ry]:
            self._parents[rx] = ry
            self._size[ry] += self._size[rx]
        else:
            self._parents[ry] = rx
            self._size[rx] += self._size[ry]
            if self._ranks[rx] == self._ranks[ry]:
                self._ranks[rx] += 1

    def same(self, x, y):
        return self.root(x) == self.root(y)


def solve(H: int, W: int, S: "List[str]"):
    uf_h = UnionFind(H * W)
    uf_v = UnionFind(H * W)
    for y in range(H):
        for x in range(W):
            i = y * W + x
            phi =  y * W + (x - 1)
            pvi = (y-1) * W + x
            if 0 < x and S[y][x] == '.' and S[y][x-1] == '.':
                uf_h.unite(i, phi)
            if 0 < y and S[y][x] == '.' and S[y-1][x] == '.':
                uf_v.unite(i, pvi)

    ret = 0
    for i in range(H * W):
        ret = max(ret, uf_h.size(i) + uf_v.size(i) - 1)
    return ret


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [ next(tokens) for _ in range(H) ]  # type: "List[str]"
    result = solve(H, W, S)
    print(result)

if __name__ == '__main__':
    main()

Measured memory_bytes: 255852
N,M=map(int,input().split())
H=list(map(int,input().split()))
tunagari=[[] for i in range(N)]
TF=[True for i in range(N)]
for i in range(M):
  A,B=map(int,input().split())
  if H[A-1]>H[B-1]:
    TF[B-1]=False
  elif H[A-1]<H[B-1]:
    TF[A-1]=False
  else:
    TF[A-1]=False
    TF[B-1]=False
ans=0
for i in range(N):
  if TF[i]==True:
    ans+=1
print(ans)

Measured memory_bytes: 20920
use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let a_b = lines.next().unwrap().unwrap();
    let mut a_b = a_b.split_whitespace();
    let a = a_b.next().unwrap().parse::<i64>().unwrap();
    let b = a_b.next().unwrap().parse::<i64>().unwrap();

    let ans = lcm(a, b);
    println!("{}", ans);
}

fn gcd(a: i64, b: i64) -> i64 {
    let mut t = (a, b);
    while t.1 != 0 {
        t = (t.1, t.0 % t.1);
    }
    t.0
}

fn lcm(a: i64, b: i64) -> i64 {
    a * b / gcd(a, b)
}


Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int main()
{
    int n,i,t,a[1000],q,b,e,k;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>a[i];
    cin>>q;
    for(i=1;i<=q;i++)
        {cin>>b>>e>>k;
        int count=0;
      for(t=b;t<e;t++)
      {

          if(k==a[t])
            count++;
      }
      cout<<count<<endl;
}
return 0;
}



Measured memory_bytes: 3112
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 500000

typedef struct _n{
  int number;
  struct _n *parent;
  struct _n *successor;
  struct _n *left;
  struct _n *right;

}Node;

Node root;

void insert(int);
void output(Node *);
void out(Node *);
int cmp(Node *, int);

int main(){

  int i;
  int n, number;
  char order[7];

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%s", order);
    if(strcmp(order, "insert") == 0){
      scanf("%d", &number);
      insert(number);
    }

    else if(strcmp(order, "print") == 0){
      output(&root);
      printf("\n");
      out(&root);
      printf("\n");

    }

    else if(strcmp(order, "find") == 0){
      scanf("%d", &number);
      if(cmp(&root, number) == 1) printf("yes\n");
	else printf("no\n");
    }

  }

  return 0;
}

void insert(int number){
  
  int i;
  Node *p, *q;
  Node *set;  

  if(root.number == 0){
    root.number = number;
    root.left = NULL;
    root.right = NULL;
  }
  else{
    set = (Node *)malloc(sizeof(Node));
    set->number = number;
    set->left = NULL;
    set->right = NULL;
    
    q = NULL;
    p = &root;
    
    while(p != NULL){
      q = p;
      
      if(set->number < p->number) p = p->left;
      else p = p->right;
      
    }
    
    set->parent = q;

    if(set->number < q->number) q->left = set;
    else q->right = set;

  }


}


void output(Node *a){

  if(a == NULL) return;

  output(a->left);
  printf(" %d", a->number);
  output(a->right);
  
}

void out(Node *a){
  if(a == NULL) return;
  printf(" %d", a->number);
  out(a->left);
  out(a->right);

}

int cmp(Node *a, int num){

  Node *p, *q;

  q = NULL;
  p = &root;
  
  while(p != NULL){
    q = p;
    
    if(num == q->number) return 1;
    if(num < p->number) p = p->left;
    else p = p->right;
    
  }
  
  return 0;
}

Measured memory_bytes: 19792
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    int N,K;
    cin >> N >> K;
    vector<int> h(N);
    REP(i,N) cin >> h[i];
    sort(ALL(h));
    int minimum = INF;
    FOR(i,K-1,N) {
        auto hmax = h[i];
        auto hmin = h[i-(K-1)];
        chmin(minimum,hmax-hmin);
    }
    cout << minimum << endl;
    return 0;
}


Measured memory_bytes: 640
def tonum(suit):
    if suit == 'S': return 0
    if suit == 'H': return 1
    if suit == 'C': return 2
    if suit == 'D': return 3
    
def tosuit(num):
    suits = ['S', 'H', 'C', 'D']
    return suits[num]
    
def main():
    n = int(input())
    cards = [i for i in range(52)]
    for i in range(n):
        a = input().split()
        cards.remove(tonum(a[0]) * 13 + int(a[1]) - 1)
    cards.sort()
    for i in cards:
        print(tosuit(i // 13) + " " + str(i % 13 + 1))
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 5604
// abc175_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    vector<ll> L(N);
    REP(i, N) cin >> L[i];

    int ans = 0;
    REP(i, N) REPN(j, i+1, N) REPN(k, j+1, N){

        if (L[i] == L[j] || L[j] == L[k] || L[k] == L[i]){
            continue;
        }
        vector<ll> v{L[i], L[j], L[k]};
        ll mx = *max_element(ALL(v));
        ll sm = accumulate(ALL(v), 0ll);

        if (mx < sm - mx){
            ans++;
        }
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define re register
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define lb long double
const int N=1e4+10;
const int mod=10086;
const int mod2=19260811;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
int main()
{
    int x;
    read(x);
    ll ans=0;
    ans+=(ll)x/500*1000;
    x-=x/500*500;
    ans+=x/5*5;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n, a[105];
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int i = n;
    cout << a[--i];
    while (i > 0) {
        cout << ' ' << a[--i];
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3116
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i + 100*j + 50*k == x:
                count += 1

print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <queue>
#include <vector>
#include <utility>

auto dfs(int current, const std::vector<std::vector<int>>& links, std::vector<bool> &passed) -> int
{
    //std::cout << current << std::endl;
    if(passed[current])
    {
        //std::cout << "already: : " << current << std::endl;
        return 0;
    }

    passed[current] = true;
    for(auto p: passed)
    {
        if(!p)
        {
            goto cont;
        }
    }
    //std::cout << "goal: : " << current << std::endl;
    return 1;

cont:

    auto reached_num = 0;
    for(auto next: links[current])
    {
        auto n_passed = std::vector<bool>(passed.size());
        std::copy(passed.begin(), passed.end(), n_passed.begin());
        reached_num += dfs(next, links, n_passed);
    }

    //std::cout << "finish: "  << current << std::endl;
    return reached_num;
}

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

    auto links = std::vector<std::vector<int>>(n, std::vector<int>());
    for(int i=0; i<m;++i)
    {
        int n1, n2;
        std::cin >> n1 >> n2;

        links[n1 - 1].push_back(n2 - 1);
        links[n2 - 1].push_back(n1 - 1);
    }

    auto passed = std::vector<bool>(n, false);
    std::cout << dfs(0, links, passed) << std::endl;
}

Measured memory_bytes: 256
import bisect
N = int(input())
L = list(map(int,input().split()))
L.sort()
sum = 0
for i in range(0,N):
  L_1st= L[i]
  for j in range(i+1,N):
    L_2nd = L[j]
    c_min = L_2nd-L_1st+1
    c_max = L_2nd+L_1st-1
    l = bisect.bisect_left(L,c_min,lo = j+1)
    if l!= N:
      r = bisect.bisect_right(L,c_max,lo = j+1)
      if r:
        r = r-1
        if r>= l:
          sum += r-l+1
print(sum)


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

#define pout(n)  printf ("%d\n", n)
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)

typedef long long ll;
using namespace std;
 
int main (){
  string o,e;
  cin >> o >> e;

  rep(i,0,o.size()){
    printf("%c",o[i]);
    if(i < e.size()) printf("%c",e[i]);
  }
  printf("\n");
  
  return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  atcoder
//
//  Created by Đỗ Ngọc thanh on 2019/04/14.
//  Copyright © 2019 Đỗ Ngọc thanh. All rights reserved.
//

#include <iostream>

int main(int argc, const char * argv[]) {
    int a,b,c=0,i;
   
    scanf("%d %d",&a,&b);
    
    for(i=0;i<2;i++){
        if(a>b){
            c=c+a;
            a=a-1;
        }
        else{c=c+b;
            b=b-1;
        }
    }
    printf("%d\n",c);
   
    return 0;
}


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


int check(long P, int A[], int n, int k) {
	int i = 0;
	for (int j = 0; j < k; j++) {
		long sum = 0;
		while (sum + A[i] <= P) {
			sum += A[i];
			i++;
			if (i == n) return n;
		}
	}
	return i;
}

long solve(int A[], int n, int k) {
	long left = 0;
	long right = n * 10000;
	long mid;
	while (right - left > 1) {
		mid = (left + right) / 2;
		long t = check(mid, A, n, k);
		if (t >= n) right = mid;
		else left = mid;
	}
	return right;
}

int main() {
	int n, k;
	cin >> n >> k;
	int A[n];
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}

	long ans = solve(A, n, k);
	cout << ans <<endl;

	return 0;
}

Measured memory_bytes: 1552
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();// æÔ
			int m = sc.nextInt();// PÌ¨©Ë
			if (n == 0 && m == 0) {
				break;
			}
			int c = 0;
			int dp[][] = new int[n][2];
			for (int i = 0; i < n; i++) {
				dp[i][0] = sc.nextInt();
				dp[i][1] = sc.nextInt();
			}
			for (int k = 10; k > 0 && m > 0; k--) {
				for (int i = 0; i < n && m > 0; i++) {
					if (dp[i][1] == k) {
						if (dp[i][0] <= m) {
							m -= dp[i][0];
							dp[i][0] = 0;
						} else {
							dp[i][0] -= m;
							m = 0;
							break;
						}
					}
				}
			}

			for (int i = 0; i < n; i++) {
				c += dp[i][0] * dp[i][1];
			}
			System.out.println(c);
		}
	}
}

Measured memory_bytes: 0
main :: IO ()
main = do
  [x, y] <- map toInt . words <$> getLine
  putStrLn $ if group x == group y then "Yes" else "No"

toInt :: String -> Int
toInt = read 

data G = A | B | C deriving Eq

group :: Int -> G
group n = case n of
  1  -> A
  3  -> A
  5  -> A
  7  -> A
  8  -> A
  10 -> A
  12 -> A
  4  -> B
  6  -> B
  9  -> B
  11 -> B
  2  -> C
  _  -> error "error"

Measured memory_bytes: 508
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <numeric>
#include <sstream>
#include <iomanip>
using lint = long long;

int main()
{
    std::string s;
    std::cin >> s;

    lint len = s.size();

    lint left = 0;
    lint right = len - 1;

    lint ans = 0;
    lint ng = 0;

    while (left < right)
    {
        char sl = s[left];
        char sr = s[right];
        if (sl == sr)
        {
            left++;
            right--;
        }
        else if (sl == 'x')
        {
            left++;
            ans++;
        }
        else if (sr == 'x')
        {
            right--;
            ans++;
        }
        else
        {
            ng = 1;
            break;
        }
    }

    if (ng)
        printf("-1");
    else
        printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>


int main() {
	int f[3000] = {}, n[3000] = {}, k, d, t = 0;
	char s[100];
	while(gets(s)){
		if(s[0] == NULL)
			t++;
		else{
			sscanf(s, "%d,%d", &k, &d);
			if(t == 0){
				f[k]++;
			}
			else{
				n[k]++;
			}
		}
	}
	int i = 0;
	for(i = 0; i < 3000; ++i){
		if(n[i] && f[i])
			printf("%d %d\n", i, n[i] + f[i]);
	}
	return 0;
}

Measured memory_bytes: 628
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll visited[200010];
ll nodes=0;
vector<ll>A[200010];
int dfs(ll ind){
	if(visited[ind]) return 0;
	
	nodes++;
	visited[ind]=1;
	for(auto i:A[ind]){
		dfs(i);
	}
	return nodes;
}
int  main(){


// #ifndef ONLINE_JUDGE   
// freopen("input.txt", "r", stdin); 
// // freopen("output.txt", "w", stdout);    
// #endif 
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
memset(visited,0,sizeof(visited));

ll n,m,u,v;
cin>>n>>m;


for(ll i=0;i<m;i++){
	cin>>u>>v;
	A[v].push_back(u);
	A[u].push_back(v);
}

 ll ans =0;
for(ll i=1;i<=n;i++){

	if(visited[i]==0){
	nodes=0;
	dfs(i);
	ans = max(ans,nodes);
}
	
}
cout<<ans;
return 0;
}





Measured memory_bytes: 22284
N, T = map(int, input().split())
C = []
ts = []
for i in range(N):
    c, t = map(int, input().split())
    C.append(c)
    ts.append(t)

ans = 1e100
for i in range(N):
    if ts[i] <= T:
        ans = min(ans, C[i])
if ans == 1e100:
    print("TLE")
else:
    print(ans)


Measured memory_bytes: 3060
N = int(input())
guide = dict()
for i in range(N):
  s, p = input().split()
  city, point = str(s), int(p)
  # 辞書 key:都市 -> val:(点数, 通し番号)
  if city in guide.keys():
    guide[city].append((point, i))
  else:
    guide[city] = [(point, i)]
#print(guide)

# 都市名で昇順
guide_asc = sorted(guide.items(), key=lambda x: x[0])
#print(guide_asc)

for city_guide in guide_asc:
  # 市内のレストラン点数で降順
  city_guide_desc = sorted(city_guide[1], key=lambda x: x[0], reverse=True)
  #print(city_guide[0], city_guide_desc)
  # 通し番号を出力
  for rest in city_guide_desc:
    print(rest[1] + 1)

Measured memory_bytes: 3064
def print(input)
  case input
  when 25
    puts "Christmas"
  when 24
    puts "Christmas Eve"
  when 23
    puts "Christmas Eve Eve"
  when 22
    puts "Christmas Eve Eve Eve"
  else
    raise ArgumentError, "invalid input: #{input}"
  end
end

input = gets.chomp.to_i
print(input)

Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;

public class Main {
	public static void main(String[] args) throws IOException, ParseException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		final int X = Integer.parseInt(str);
		
		if (X == 3 || X == 5 || X == 7) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
//#define MOD (1000000000+7)

using namespace std;
using lint = long long;


const int MAX = 1000000;
const int MOD = 1000000007;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

lint comb(lint n, lint r)
{
    lint num = 1;
    if(n < r) return 0;
    for(lint i = 1; i <= r; i++){
        num = (num * (n - i + 1) % MOD * modinv(i, MOD) ) % MOD;
    }
    return num;
    
}

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

int main(void)
{
    //COMinit();
    lint n;
    lint a, b;
    cin >> n >> a >> b;

    lint sum = (modpow(2, n, MOD) - 1);
    //cout << sum << endl;
    sum = (sum - comb(n, a)) % MOD;
    if(sum < 0) sum += MOD;
    sum = (sum - comb(n, b)) % MOD;
    if(sum < 0) sum += MOD;

    cout << sum << endl;
   

    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>

#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second

using namespace std;
using ll = long long;
using namespace __gnu_pbds;

//#define int ll

template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 2e5 + 10 , inf = 2e9 + 7;
const ll INF = 1e18 , mod = 1e9+7;

void solve() {
    int x;
    cin >> x;
    cout << !x;
}

/*
*/
main() {
    ios;
    int tt = 1;
    //cin >> tt;
    while(tt --) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
int abs(int n){
		if(n<0){
		return -1*n;}else
		return n;}
int main(void)
{int N,A,M,B,C,x,i,a,b,c,l,r,g,m,tmp;
	scanf("%d%d",&A,&B);
if((A%3==0)||(B%3==0)||((A+B)%3==0)){
	printf("Possible");}
	else
	printf("Impossible");


	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define erep(e,v) for(auto && e :v)
using namespace std;
auto f(int y,int x,int my,int mx){
    return to_string (y+1) + " " +to_string(x+1)+" " + to_string(my+1) + " " +to_string(mx+1);
}
signed main(){
    int h,w; cin >> h >> w;
    
    vector<vector<int>>g(h,vector<int>(w));
    rep(i,h)rep(j,w) cin >> g[i][j];
    vector<string>res;
    int ans = 0;
    
    rep(y,h){
        for(int x = w-1;x > 0;--x){
            if (g[y][x] % 2 and g[y][x] != 0){
                ans ++;
                g[y][x-1]++;
                res.push_back(f(y,x,y,x-1));
            }
        }
    }
    rep(y,h-1){
        if(g[y][0] % 2 and g[y][0] != 0){
            ans ++;
            g[y+1][0]++;
            res.push_back(f(y,0,y+1,0));
        }
    }
    cout << ans << endl;
    erep(e,res)cout << e << endl;
}






Measured memory_bytes: 12916
H,W,K = map(int,input().split())
L = [input() for i in range(H)]

res = [[0]*W for i in range(H)]
r = 1
for y in range(H) :
    if L[y].count("#") :
        for x in range(W) :
            res[y][x] = r
            if L[y][x] == "#" :
                r += 1
        
        if L[y][-1] != "#" :
            for x in range(W) :
                if res[y][x] == r :
                    res[y][x] = r-1

for x in range(W) :
    for y in range(H-1) :
        if res[y][x] == 0 :
            for z in range(y+1,H) :
                if res[z][x] != 0 :
                    res[y] = res[z]
                    break
        if res[y][x] == 0 :
            for z in range(y-1,-1,-1) :
                if res[z][x] != 0 :
                    res[y] = res[z]
                    break
        

for x in range(W) :
    if res[H-1][x] == 0 :
        for z in range(H-2,-1,-1) :
            if res[z][x] != 0 :
                res[H-1] = res[z]
                break

for i in range(H) :
    print(*res[i])


Measured memory_bytes: 46368
//#include "/usr/local/bits"
#include <bits/stdc++.h>
using namespace std;    
#define ll long long
#define pb push_back
#define mp make_pair
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp> 
//using namespace __gnu_pbds; 
  
//#define ordered_set tree<pair<int,int>, null_type,less< pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update> 
//find_by_order(k) - k is the kth element of the set
//order_of_key(k) - Number of elements striclty samller than k
void build(ll segt[],ll arr[],ll l,ll r,ll ind)
{
    if(l==r)
    {
        segt[ind]=arr[l];
        return;
    }
    ll mid=l+(r-l)/2;
    build(segt,arr,l,mid,2*ind+1);
    build(segt,arr,mid+1,r,2*ind+2);
    segt[ind]=min(segt[2*ind+1],segt[2*ind+2]);
}
//llim-lower limit of array,rlim-upper limit of array
//l,r- range of query
ll sum(ll segt[],ll llim,ll rlim,ll l,ll r,ll ind)
{
    //cout<<llim<<" "<<rlim<<endl;
    if(l<=llim && rlim<=r)
    {
        //cout<<"here "<<segt[ind]<<" "<<ind<<endl;
        return segt[ind];
    }
    if(r<llim || rlim<l)
    {
        return 1e18;
    }
    ll mid=llim+(rlim-llim)/2;
    return min(sum(segt,llim,mid,l,r,2*ind+1),sum(segt,mid+1,rlim,l,r,2*ind+2));
}
void update(ll segt[],ll llim,ll rlim,ll diff,ll upind,ll ind)
{
    if(upind<llim || upind>rlim)
        return;
    segt[ind]=min(segt[ind],diff);
    if(llim==rlim)
    {
        segt[ind]=diff;
        return;
    }
    if(llim!=rlim)
    {
        ll mid=llim+(rlim-llim)/2;
        update(segt,llim,mid,diff,upind,2*ind+1);
        update(segt,mid+1,rlim,diff,upind,2*ind+2); 
    }
}
ll modularExponentiation(ll x,ll n,ll M=1000000007)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return modularExponentiation((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*modularExponentiation((x*x)%M,(n-1)/2,M))%M;
 
}
ll modInverse(ll A,ll M=1000000007)
{
    return modularExponentiation(A,M-2,M);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
    ll k,n;
    cin>>k>>n;
    ll arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    multiset<ll> mst;
    ll ans=0;
    mst.insert(arr[0]+(k-arr[n-1]));
    ans+=arr[0]+(k-arr[n-1]);
    for(int i=1;i<n;i++)
    {
        mst.insert(arr[i]-arr[i-1]);
        ans+=arr[i]-arr[i-1];
    }
    multiset<ll>::iterator itr;
    itr=mst.end();
    itr--;
    ans-=(*itr);
    cout<<ans<<endl;
}






















Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long int a,b;
	cin>>a>>b;
	if(a==1){
		cout<<1;
		return 0;
	}
	if(b==1){
		cout<<1;
		return 0;
	}
	if(a%2==0||b%2==0){
		cout<<a*b/2; 
	}
	else{
		cout<<a*b/2+1;
	}

	return 0;
}


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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz size
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i=(a);i>=(b);i--)
#define FORR(i,a,b) for (int i=(a);i>(b);i--)
typedef unsigned long long ull;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

    //the same number i.e. town cannot appear 3 times
    
    map<int,int> M;

    FOR(i,0,3){
        int a,b;
        cin >> a >> b;
        M[a]++;
        M[b]++;
    }

    if(M[1]<=2 && M[2]<=2 && M[3]<=2 && M[4]<=2)
        cout << "YES\n";
    else
        cout << "NO\n";

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define F first
#define S second
#define s(x) #x<<" "<<x<<" | "<<
#define f(i,j,k) for(int i = j;i<=k;i++)
#define fr(i,j,k) for(int i = j;i>=k;i--)
#define all(A)  A.begin(),A.end()  
#define has(m,x)   (m.find(x)!=m.end())
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);  
#define endl "\n"
const int MSIZE = 2e5+5;
const int MOD = 1e9+7 ;



int main(){

    FIO
    char c; cin>>c;
    if(97<=c)   cout<<'a'<<endl;
    else cout<<'A'<<endl;
    
    
    return 0;
}
    


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

using namespace std;

long n,a,b,c;
vector<long> l;
const long mod=1000000007;

long dfs(long num, long p,long q, long r){

 if(num==n){
    if(p&&q&&r) return abs(p-a)+abs(q-b)+abs(r-c)-30; 
    else return mod;
  }
  
  long res0=dfs(num+1,p,q,r);
  long res1=dfs(num+1,p+l[num],q,r)+10;
  long res2=dfs(num+1,p,q+l[num],r)+10;
  long res3=dfs(num+1,p,q,r+l[num])+10;

  return min({res0,res1,res2,res3});
}


int main(){
  
   cin >>n >> a >> b >>c;
  l.resize(n);
   for(int i=0;i<n;i++) cin >> l[i];

  cout << dfs(0,0,0,0) << endl; 
}
  

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

using namespace std;

int main() {

    int N, Y;
    cin >> N >> Y;

    int c = 0;
    int ans10000 = -1, ans5000 = -1, ans1000 = -1;

    for(int a = 0; a <= N; a++) {
        for(int b = 0; a + b <= N; b++) {
            int c = N - a - b;
            int total = a * 10000 + b * 5000 + c * 1000;

            if (total == Y) {
                ans10000 = a;
                ans5000 = b;
                ans1000 = c;
            }
        }
    }

    cout << ans10000 << " " << ans5000 << " " << ans1000 << endl;

    return 0;
}

Measured memory_bytes: 256
#単位元を設定
ide = float('inf')

class SegmentTree:
	def __init__(self,n):
        #セグ木の頂点はindex == 1から。index == 0は無視すること。
        #つまり、STtable[0]は無視。頂点はSTtable[1]。
		self.n = n
		tmp = 0
		while True:
			if 2 ** tmp >= self.n:
				break
			tmp += 1
		self.STtable = [ide] * (2*2**tmp)
		self.STtable_size = len(self.STtable)

	def update(self,i,a):
        #更新のためのインデックスの指定は0_indexedで。
		i += self.STtable_size//2
		self.STtable[i] = a
		while i > 0:
			i //= 2
			self.STtable[i] = min(self.STtable[i*2], self.STtable[i*2+1])

	def find(self,a,b,k=1,l=0,r=None):
        #kは頂点番号。初期値は1にすること。
		#[a,b)の最小を返す。
		#[l,r)からです。
        #初期値のrは、self.STtable_size//2にすると、ちょうど要素数と同じ値になって[l,r)のrになる。
		if r == None:
			r = self.STtable_size//2        
		if a >= r or b <= l:
			return ide
		elif a <= l and b >= r:
			return self.STtable[k]
		else:
			v1 = self.find(a,b,2*k,l,(l+r)/2)
			v2 = self.find(a,b,2*k+1,(l+r)/2,r)
			return min(v1,v2)

n,q = map(int, input().split())
solve = SegmentTree(n)
ans = []
for _ in range(q):
    cond, x, y = map(int, input().split())
    if cond == 0:
        solve.update(x,y)
    else:
        ans.append(solve.find(x,y+1))

for a in ans:
    if a == ide:
        print(2147483647)
    else:
        print(a)


Measured memory_bytes: 10508
use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::cmp::*;
use std::collections::HashSet;
use std::iter::Iterator;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
  input! {
  n: usize,
  m: i64,
  a: [i64; m],
  }

  let mut bf = vec![false;n+1];
  let mut dp = vec![0_i64;n+2];
  let MOD = 1_000_000_007;

  for i in a {
    bf[i as usize]=true;
  }

  dp[0] = 1;
  if !bf[1] {dp[1] = 1;}
  for i in 2..n+1 {
    if !bf[i as usize] {
      dp[i as usize] = (dp[(i-1) as usize] + dp[(i-2) as usize]) % MOD;
    }
  }

  println!("{}", dp[n as usize]);
}


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

long long dfs(long long h){
	if(h == 1)
		return 1;
	return dfs(h/2)*2 + 1;
}

int main(){
	long long h;
	cin >> h;
	cout << dfs(h) << endl;
}

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

int r1, c1, r2, c2;

const int MAX = 2000100;
const int MOD = 1000000007;
int fact[MAX], finv[MAX], inv[MAX];

void Cinit() {
    fact[0] = fact[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i=2; i<MAX; i++) {
        fact[i] = fact[i-1]*i%MOD;
        inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}

int C(int n, int k) {
    if (n<k) return 0;
    if (n<0 || k<0) return 0;
    return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int f(int r, int c) {
    int res = (r+2)*C(r+c+2, c)%MOD;
    res = (res-(c+1)+MOD)%MOD;
    res = res*inv[c+1]%MOD;
    return res;
}

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> r1 >> c1 >> r2 >> c2;
    Cinit();
    int ans = f(r2, c2);
    ans = (ans-f(r1-1, c2)+MOD)%MOD;
    ans = (ans-f(r2, c1-1)+MOD)%MOD;
    ans = (ans+f(r1-1, c1-1))%MOD;
    cout << ans << endl;
}

Measured memory_bytes: 47104
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		
		if (x == 2) {
			System.out.println(2);
			return;
		}
		
		int idx = 0;
		int[] p = new int[100010];
		p[idx++] = 2;
		p[idx++] = 3;
		
		for (int n = 3; n <= 100009; n += 2) {
			boolean flg = false;
			for (int i = 1; p[i] * p[i] <= n; i++) {
				if (n % p[i] == 0) {
					flg = true;
					break;
				}
			}
			
			if (!flg) {
				p[idx++] = n;
				if (n >= x) {
					System.out.println(n);
					return;
				}
			}
		}
	}
}


Measured memory_bytes: 23124
import sys
input = lambda: sys.stdin.readline().rstrip()
 
x=int(input())
a=1
while True:
    for b in range(a + 1):
        if a**5+b**5==x:
            print(a,-b)
            sys.exit()
        elif a**5-b**5==x:
            print(a,b)
            sys.exit()
    else:
        a+=1



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

int main()
{
  long long int MOD = 1000000007;
  long long int N, M;
  cin >> N >> M;
  if (N - M >= 2 or M - N >= 2)
  {
    cout << 0 << endl;
  }
  else
  {
    if (N - M == 1 or M - N == 1)
    {
      long long int tmp1 = 1, tmp2 = 1;
      for (int i = 1; i <= N; i++)
      {
        tmp1 *= i;
        tmp1 %= MOD;
      }
      for (int i = 1; i <= M; i++)
      {
        tmp2 *= i;
        tmp2 %= MOD;
      }
      long long int ans = tmp1 * tmp2 % MOD;
      cout << ans << endl;
    }
    else
    {
      long long int tmp = 1;
      for (int i = 1; i <= N; i++)
      {
        tmp *= i;
        tmp %= MOD;
      }
      long long int ans = tmp * tmp % MOD;
      ans *= 2;
      ans %= MOD;
      cout << ans << endl;
    }
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()

void Calc();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr); cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/
template<class A>void OutContainer(A b, A e, const char *between = " ") {
  if (b != e)while (cout << *b, ++b != e) cout << between;
}
template<class T>void Out(const char* b, const T &t) { cout << t; }
template<class T, class... Args>void Out(const char* b, const T& t, const Args&... args) {
  cout << t << b;
  Out(b, args...);
}
template<class T, class... Args>void OutSpace(const T& t, const Args&... args) { Out(" ", t, args...); }



void Calc() {

  int n = in;
  auto p = in.Array(n);

  vector<int> a(n), b(n);
  a[0] = b[0] = 1;
  rep(i, n - 1)a[i + 1] = a[i] + n;
  rep(i, n - 1)b[i + 1] = b[i] + n;
  reverse(all(b));

  int now = a[0] + b[n - 1];
  for (auto& i : p) {
    i--;
    if (now >= a[i] + b[i]) {
      a[i] += now - (a[i] + b[i]) + 1;
    }
    now = a[i] + b[i];
    err(now, a[i]);
  }
  for (auto& i : p) {
    cerr << a[i] + b[i] << endl;
  }
  now = 0;
  for (auto& i : p) {
    int tmp = a[i] + b[i];
    assert(now < tmp);
    now = tmp;
  }

  rep(i, 1, n) {
    assert(0 < a[i] - a[i - 1]);
  }
  rep(i, 1, n) {
    assert(0 < b[i - 1] - b[i]);
  }
  cerr << endl;
  OutContainer(all(a)); cout << endl;
  OutContainer(all(b)); cout << endl;
}


Measured memory_bytes: 896