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

struct job {
  ll len, dead;
  const bool operator<(const job &j) const {
    if (dead != j.dead)
      return dead < j.dead;
    return len < j.len;
  }
};

vector<job> jobs;

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

  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    jobs.push_back((job){a, b});
  }
  sort(jobs.begin(), jobs.end());
  ll ctime = 0;
  for (job &j : jobs) {
    ctime += j.len;
    if (ctime > j.dead) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 6256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
#define out(S) cout<<(S)<<endl;
#define REP(i,b) for(size_t i=0;i<(b);i++)
#define rREP(i,b) for(int i=(b)-1;i>=0;i--)
#define FOR(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFOR(i,a,b) for(int i=(b)-1;i>=0;i--)
#define Foreach(item,collection) for(auto item:collection)
#define mod(i) ((i) % (ll)(1e9 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9 + 5))))
#define Yes out("Yes")
#define No out("No")
#define NO out("NO")
#define YES out("YES")
#define INF 1e10;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define IfOut(condition,text) if((condition)){out(text);return 0;}
#define IfeOut(condition,itext,etext) if(condition){out(itext);return 0;}else{out(etext);return 0;}
#define Select(collection,condition,result) Foreach(i,collection){result+=condition;}
#define GetAuto(_N,vect) {cin>>N;vect.resize(N);REP(i,_N){cin>>vect[i];}}
void removeAt(string& s, int index) { s.erase(index, 1); }
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
ll manhattanDistance(ll x1, ll y1, ll x2, ll y2) { return (abs(x2 - x1) + abs(y2 - y1)); }
#define beginend(vec) (vec).begin(),(vec).end()
vector<ll> sieveOfEratosthenes(int max) {ll prime;double sqrtmax = sqrt(max);vector<ll> primeVec, searchVec;FOR(i, 2, max + 1) searchVec.push_back(i);do{prime = searchVec[0];primeVec.push_back(prime);auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; });searchVec.erase(itr, searchVec.end());} while (prime < sqrtmax);primeVec.reserve(primeVec.size() + searchVec.size());primeVec.insert(primeVec.end(), beginend(searchVec));return primeVec;}


int main() {
	ll nn;
	map<ll, ll> ans;
	map<ll, bool> box;
	vector<ll> input, output;
	while (cin >> nn)
	{
		input.push_back(nn);
		box[nn] = false;
	}
	box[1] = true;
	ans[1] = 0;
	Foreach(n, input) {

		if (box[n]) {
			output.push_back(ans[n]);
			continue;
		}
		int prime;
		double sqrtmax = sqrt(n);
		vector<ll> primeVec, searchVec;
		FOR(i, 2, n + 1) searchVec.push_back(i);
		do
		{
			prime = searchVec[0];
			primeVec.push_back(prime);
			auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; });
			searchVec.erase(itr, searchVec.end());
		} while (prime < sqrtmax);
		ans[n] = (primeVec.size() + searchVec.size());
		output.push_back(ans[n]);
		box[n] = true;
	}

	ShowAll(output);
	return 0;
}

Measured memory_bytes: 15124
from fractions import gcd
from functools import reduce

N, M = map(int, input().split())
A = list(map(int, input().split()))

count = 0
tmp = A[0]
while tmp % 2 == 0:
    count += 1
    tmp //= 2
for a in A[1:]:
    tmp = a
    tmp_count = 0
    while tmp % 2 == 0:
        tmp_count += 1
        tmp //= 2
    if count != tmp_count:
        print (0)
        exit()

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

tmp = lcm(*A) // 2
# print (tmp)
ans = M // tmp

ans = (ans + 1) // 2

print (ans)

Measured memory_bytes: 16348
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define int int64_t
#define watch(x) cout << (#x) << " is " << (x) << endl

const int32_t MAX=1e9+7;
typedef vector<int> vi;
typedef vector<int64_t> vll;

vi f((int)1e7+1,1);
int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
	int n;
	cin >> n;
	int ans{0};
	for(int i=2;i<=n;i++){
		for(int j=i;j<=n;j+=i){
			f[j]++;
		}
	}
	
	for(int i=1;i<=n;i++){
		ans += i*f[i];
	}
	cout << ans;
    return 0;
}



Measured memory_bytes: 81240
#include<bits/stdc++.h>
using namespace std;
int main()
{



    long long a,b,st=0,c,d;
    cin>>a;
    for(long long i=0;i<a;i++)
    {
       cin>>c>>d;
       st=st+(d-c)+1;

    }
    cout<<st;
}


Measured memory_bytes: 256
/**
 *      ABC 77 A
 *      author  : kyomukyomupurin
 *      created : 2018-09-03 02:04:47
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string c1, c2; cin >> c1 >> c2;
    if ((c1[0] == c2[2] && c2[0] == c1[2]) && c1[1] == c2[1]){
        cout << "YES"; return 0;
    }
    else {
        cout << "NO"; return 0;
    }
}



Measured memory_bytes: 256
//Code by ASIM FOIZE AIMON
//CSE'19;CUET
//avoid copy paste//Hit the frined button
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise cout.precision(10); cout << fixed;
#define endl "\n"
#define int int64_t
#define ll long long
#define yes printf("Yes\n")
#define no printf("No\n")

int32_t main()
{
    /*#ifndef ONLINE_JUDGE
        freopen("/media/AIMON/SSDVol/Progs/CodeForces/input.txt", "r", stdin);
        freopen("/media/AIMON/SSDVol/Progs/CodeForces/output.txt", "w", stdout);
    #endif*/
    int a,b,c=0,d=0,e,f,m,n,p,x,y,z,t,i,j,k;
    vector<int>v;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a>>b;
        if(a==b)
            c++;
        else
            c=0;
        v.push_back(c);
    }
    for(i=0;i<v.size();i++)
    {
        if(v[i]>=3)
        {
            yes;
            d=1;
            break;
        }
    }
    if(d==0)
        no;
    v.clear();
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    int a[m];
    rep(i, m) {
        cin >> a[i];
        a[i];
    }

    ll  l  =  0, r = 0;
    
    rep(i, m){
        if (a[i] <  x) l += 1;
        if (a[i] >  x) r += 1;
    }
    cout  << min(l, r) << endl;
    return 0;
}

Measured memory_bytes: 256
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List ((\\))

main :: IO ()
main = do
  [n, k] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  ass <- sequence . replicate k $ T.getLine >> (map unsafeTextToInt . T.words <$> T.getLine) :: IO [[Int]]
  print . length $ [1..n] \\ concat ass

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


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

int main()
{
    int a,b,w;
    cin>>w>>a>>b;
    int ans=0;
    if(b>a+w)
    {
        ans=b-a-w;
    }
    if(a>b+w)
    {
        ans=a-b-w;
    }
    cout<< ans << endl;
    return 0;
}


Measured memory_bytes: 256
fun main(args : Array<String>) {
    var n = readLine()!!.toLong()

    if (n % 2L == 1L) {
        println(0)
        return
    }

    var cnt5 = 0L
    n /= 2
    while (n > 0L) {
        cnt5 += n/5L
        n /= 5L
    }

    println(cnt5)
}

Measured memory_bytes: 34520
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    int x = a*n;
    if(x>b){
      System.out.println(b);
    }else{
      System.out.println(x);
    }
  }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  getline(cin, s);
  for (int i = 0; i < s.size(); i++){
    char c = s[i];
    if (islower(c)){
      cout << (char)toupper(c);
    } else {
      cout << (char)tolower(c);
    }
  }
  cout << endl;
}


Measured memory_bytes: 3200
n,m,k = map(int, input().split())
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
p = 998244353
N = n  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

ans = 0
for i in range(k+1):
  a = m*pow(m-1,n-i-1,p)
  a *= cmb(n-1, i, p)%p
  ans += a
print(ans%p)


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<tuple<long, long, long>> V(N);
  for (auto &[x, y, z] : V) cin >> x >> y >> z;
  long mx = 0;
  for (int bit = 0; bit < 1 << 3; bit++) {
    vector tmp(N, 0L);
    for (int i = 0; i < N; i++) {
      auto [x, y, z] = V.at(i);
      if (bit >> 0 & 1) x = -x;
      if (bit >> 1 & 1) y = -y;
      if (bit >> 2 & 1) z = -z;
      tmp.at(i) = x + y + z;
    }
    sort(tmp.rbegin(), tmp.rend());
    mx = max(mx, accumulate(tmp.begin(), tmp.begin() + M, 0L));
  }
  cout << mx << "\n";
}

Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

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

int main()
{
  int N, M, R;
  cin >> N >> M >> R;
  vector<int> r(R);
  REP(i, R)
  {
    cin >> r[i];
    r[i]--;
  }
  sort(ALL(r));
  vector<int> A(M), B(M), C(M);
  REP(i, M)
  {
    cin >> A[i] >> B[i] >> C[i];
    A[i]--, B[i]--;
  }
  ll INF = 1e9;
  ll dist[N][N]; // iからjまでの最短距離
  REP(i, N)
  REP(j, N)
  {
    dist[i][j] = INF;
    if (i == j)
      dist[i][j] = 0;
  }
  REP(i, M)
  {
    dist[A[i]][B[i]] = C[i];
    dist[B[i]][A[i]] = C[i];
  }
  REP(k, N)
  REP(i, N)
  REP(j, N)
  dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); // ワーシャルフロイド法
  ll ans = INF;
  do
  {
    ll tmp = 0;
    REP(i, r.size() - 1)
    tmp += dist[r[i]][r[i + 1]];
    ans = min(ans, tmp);
  } while (next_permutation(ALL(r)));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 768
#include<stdio.h>
void swap(int *,int *);

int main(){
  int N;
  int A[100];
  int flag;
  int i,j,count=0;

scanf("%d",&N);
for(i=0;i<N;i++){
  scanf("%d",&A[i]);
}
flag = 1;
while(flag){
  flag = 0;
  for(j=N-1;j>=1;j--){
    if(A[j]<A[j-1]){
      swap(&A[j],&A[j-1]);
      flag=1;
      count++;
    }
  }
}
for(j=0;j<N-1;j++){
printf("%d ",A[j]);
}
printf("%d\n",A[N-1]);
printf("%d\n",count);
  return 0;
}
void swap(int *x,int *y){
  int m;
  m = *x;
  *x=*y;
  *y = m;
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int dx[] = {1, 0};
int dy[] = {0, 1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;cin>>h>>w;
    const int HWM = 501;
    int a[HWM][HWM];
    rep(i,h){
        rep(j,w){
            cin>>a[i+1][j+1];
        }
    }
    // rep(i,h){
    //     rep(j,w){
    vector<string> ans;
    int cnt = 0;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(a[i][j]%2==1){
                rep(k, 2){
                    if(i+dy[k]>h || j+dx[k]>w) continue;
                    cnt++;
                    string aa = to_string(i)+" "+to_string(j)+" "+to_string(i+dy[k])+" "+to_string(j+dx[k]);
                    ans.push_back(aa);
                    a[i][j]--;
                    a[i+dy[k]][j+dx[k]]++;
                    break;
                }
            }
        }
    }
    cout<<cnt<<endl;
    for(auto au : ans){
        cout<<au<<endl;
    }
}

Measured memory_bytes: 11892
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::iter::FromIterator;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<usize>();
    let m = scan.read::<usize>();
    let mut edges = vec![];
    for _ in 0..m {
        let a = scan.read::<usize>()-1;
        let b = scan.read::<usize>()-1;
        let c = scan.read::<i64>();
        edges.push((a, b, -c));
    }
    if let Some(d) = bellman_ford(n, &edges, 0, n-1) {
        println!("{}", -d);
    } else {
        println!("inf");
    }
}

#[allow(dead_code)]
fn bellman_ford(n: usize, edges: &Vec<(usize, usize, i64)>, s: usize, t: usize) -> Option<i64> {
    let mut d = vec![1i64<<60;n];
    let mut p = 0;
    d[s] = 0;
    for i in 0..2*n {
        for &(from, to, cost) in edges {
            if d[from] != 1i64<<60 && d[to] > d[from] + cost {
                d[to] = d[from] + cost;
            }
        }
        if i == n-1 {p = d[t]}
    }
    if p == d[t] {Some(p)} else {None}
}

#[allow(dead_code)]
fn find_negative_loop(n: usize, edges: &Vec<(usize, usize, i64)>) -> bool {
    let mut d = vec![0; n];
    for i in 0..n {for &(from, to, cost) in edges {
        if d[to] > d[from] + cost {
            d[to] = d[from] + cost;
            if i == n-1 {return true;}
        }
    }}
    return false;
}


// region template
#[allow(dead_code)]
fn iu(i: isize) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> isize { i as isize }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

#[allow(dead_code)]
fn alt<S, T>(v: Vec<S>) -> T where T: FromIterator<S> {
    v.into_iter().collect::<T>()
}

#[allow(dead_code)]
fn dup<S, T>(v: &[S]) -> T where T: FromIterator<S>, S: Clone {
    v.iter().cloned().collect::<T>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

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

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

	for (ll i = 1; i < s.length(); i++) {
		if ((s.length() - i) % 2 != 0) continue;
		bool flg = true;
		for (ll j = 0; j < (s.length() - i) / 2; j++) {
			if (s[j] != s[(s.length()-i) / 2 + j]) {
				flg = false;
			}
		}
		if (flg) {
			cout << s.length() - i << endl;
			return 0;
		}
	}
	return 0;
}


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

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


int main(){
      ll m,n,ans;
      while(cin >>m >>n){
            ans = pow_ans(m,n);
            cout << ans << endl;
      }
}


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

ll N, K;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> N >> K;
    N--;
    K--;
    if (N % K == 0) {
        cout << N / K << "\n";
    }
    else {
        cout << N / K + 1 << "\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
std::vector<bool> IsPrime;

void sieve(size_t max) {
  if (max + 1 > IsPrime.size()) {  // resizeで要素数が減らないように
    IsPrime.resize(max + 1, true);  // IsPrimeに必要な要素数を確保
  }
  IsPrime[0] = false;  // 0は素数ではない
  IsPrime[1] = false;  // 1は素数ではない

  for (size_t i = 2; i * i <= max; ++i)      // 0からsqrt(max)まで調べる
    if (IsPrime[i])                          // iが素数ならば
      for (size_t j = 2; i * j <= max; ++j)  // (max以下の)iの倍数は
        IsPrime[i * j] = false;              // 素数ではない
}

int main() {
  sieve(1000009);
  ll N;
  cin >> N;
  vector<ll> A(N);
  unordered_map<int, int> mp{};
  REP(i, N) {
    cin >> A[i];
    mp[A[i]]++;
  }
  sort(A.begin(), A.end());
  A.erase(unique(A.begin(), A.end()), A.end());
  if (A[0] == 1) {
    if (mp[1] == 1) {
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
    return 0;
  }
  ll ans = 0;
  REP(i, A.size()) {
    if (1 < mp[A[i]]) continue;
    if (IsPrime[A[i]] == true) {
      ans++;
      continue;
    }
    bool ok = true;
    /*for (int j = 0; j < i; j++) {
      if (A[i] % A[j] == 0) {
        ok = false;
        break;
      }
    }*/
    for (ll j = 2; j * j <= A[i]; j++) {
      if (A[i] % j != 0) continue;
      if (mp[j] != 0 || mp[A[i] / j] != 0) {
        ok = false;
        break;
      }
    }
    if (ok) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 33272
object Main extends App {
  val in = scala.io.Source.stdin.getLines.toSeq
  val ls = in(0).split(' ').map(_.toInt)
  val X = ls(0)
  val tbl = (0 to 200001).map(_ => false).toArray
  //tbl(2) = false
  //tbl(3) = true
  //tbl(5) = true
  
  var i = 2
  val End = X*2
  while(i<End){
    var j = i*2
    while(j<End){
      tbl(j) = true
      j += i
    }
    i += 1
  }
  
  //(0 to X*2).foreach{i => println(i, tbl(i)) }
  
  var k = X
  var found = false
  do{
    if(!tbl(k))
      found = true
    else k += 1
  }while(!found)
  println(k)
}


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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	ll int dp[21][101] = {0};
	int num[101];
	int n;
	cin >> n;
	REP(i,n) cin >> num[i];
	dp[num[0]][1] = 1;
	FOR(i,1,n-1){
		REP(j,21){
			int tmp = j + num[i];
			if(0 <= tmp && tmp <= 20) dp[tmp][i+1] += dp[j][i];
			tmp = j - num[i];
			if(0 <= tmp && tmp <= 20) dp[tmp][i+1] += dp[j][i];
		}
	}
	cout << dp[num[n-1]][n-1] << endl;
}

Measured memory_bytes: 1180
A, B, C = map(int, input().split())
K = int(input())


def combinations(k):
    result = []
    for b in range(k + 1):
        for c in range(k + 1 - b):
            result.append([b, c])

    return result


def magic(A, B, C, K):
    if A < B < C:
        return True

    for b_count, c_count in combinations(K):
        a, b, c = A, B, C
        if b_count > 0:
            b *= 2 ** b_count
        if c_count > 0:
            c *= 2 ** c_count

        if a < b < c:
            return True

    return False


if (magic(A, B, C, K)):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9132
h = {}
while True:
	try:
		a = int(input())
		if a in h:
			h[a] += 1
		else:
			h[a] = 1
	except EOFError:
		break
#print(h)
l = [(mode, 10000 - num) for num, mode in h.items()]
l.sort(reverse=True)
max_mode, num = l[0]
print(10000 - num)
for i in range(1,1000):
	if l[i][0] != max_mode: break
	mode, num = l[i]
	print(10000-num)

Measured memory_bytes: 7692
#include <bits/stdc++.h>
using namespace std;
using lint = long long;

const int MAXN = 200005;

int N;
long long A[MAXN];
long long Answer[MAXN];

void Read() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
}

bool used[MAXN];
long long pref[MAXN][2]; // (even, odd) only

void Solve() {
  priority_queue<pair<long long, pair<int, int>>> pq;
  set<int> unused;

  for (int i = 1; i <= N; i++) {
    pq.push({A[i], {i, i + 1}});
  }

  for (int i = 0; i <= N + 2; i++) {
    unused.emplace(i);
  }

  for (int i = 1; i <= N + 2; i++) {
    pref[i][0] = pref[i - 1][0];
    pref[i][1] = pref[i - 1][1];
    pref[i][i & 1] += A[i];
  }

  int num = 0;
  long long ans = 0;

  while (!pq.empty()) {
    long long w = pq.top().first;
    int u = pq.top().second.first;
    int v = pq.top().second.second;
    pq.pop();
    if (used[u] || used[v]) continue;

    used[u] = true, used[v] = true;
    unused.erase(u);
    unused.erase(v);

    Answer[++num] = (ans += w);

    int L = *prev(unused.lower_bound(u));
    int R = *unused.lower_bound(v);

    if (1 <= L && R <= N + 1) {
      long long NotTakeUV = (pref[R - 1][L & 1] - pref[L - 1][L & 1]);
      long long TakeUV = (pref[R - 1][(L & 1) ^ 1] - pref[L - 1][(L & 1) ^ 1]);
      pq.push({NotTakeUV - TakeUV, {L, R}});
    }
  }
}

void Write() {
 cout << Answer[N/2];
}

int main() {
  Read();
  Solve();
  Write();
  return 0;
}


Measured memory_bytes: 21412
#include<bits/stdc++.h> 
using namespace std;
vector <vector <int> > A(4);
int main () {
	int a1, b1, a2, b2, a3, b3;
	cin >> a1 >> b1 >> a2 >> b2 >> a3 >> b3;
	A[a1 - 1].push_back(b1 - 1);
	A[b1 - 1].push_back(a1 - 1);
	A[a2 - 1].push_back(b2 - 1);
	A[b2 - 1].push_back(a2 - 1);
	A[a3 - 1].push_back(b3 - 1);
	A[b3 - 1].push_back(a3 - 1);
	int count1 = 0, count2 = 0;
	for(int i = 0; i < 4; i++)
	{
		if(A[i].size() == 2)
		{
			count1++;
		}
		else if(A[i].size() == 1)
		{
			count2++;
		}
	}
	if(count2 == 2 && count1 == 2)
	{
		cout << "YES";
	}
	else
	{
		cout << "NO";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template <class T> bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template <class T> bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct { template <typename T> operator T() { T x; cin >> x; return x; } } IN;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n=IN;
    vector<vector<int>> a(n-1);
    REP(i,n-1) {
        int c,s,f;
        cin>>c>>s>>f;
        a[i]={c,s,f};
    }
    REP(i,n) {
        int t=0;
        REPF(j,i,n-1) {
            int f=a[j][2];
            t=max((t+f-1)/f*f,a[j][1])+a[j][0];
        }
        cout<<t<<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++)

int main(){
    int N,i,j,flag;
    flag = 0;

    cin >> N;
    vector<vector<int>> cube(N,vector<int>(2));

    rep(i,N){
        cin >> cube.at(i).at(0);
        cin >> cube.at(i).at(1);        
    }
    rep(i,N-2){
        if(cube.at(i).at(0) == cube.at(i).at(1)){
            if(cube.at(i+1).at(0) == cube.at(i+1).at(1)){
                if(cube.at(i+2).at(0) == cube.at(i+2).at(1)){
                flag = 1;
                }
            }
        }
    }
    if(flag == 1){
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    
}

Measured memory_bytes: 3604
L=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())
print(L[K-1])

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

using namespace std;

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> a(n);
	vector<pair<int, int>> c(m);
	for (int i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
	}
	for (int i = 0; i < m; i++) {
		cin >> c[i].first >> c[i].second;
	}
	for (int i = 0; i < n; i++) {
		int best = 1e9;
		int besti = m;
		for (int j = 0; j < m; j++) {
			int cur = abs(c[j].first - a[i].first)
				+ abs(c[j].second - a[i].second);
			if (cur < best) {
				best = cur;
				besti = j + 1;
			}
		}
		cout << besti << '\n';
	}

	return 0;
}



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

const int N = 1e5 + 5, mod = 1e9 + 7;

int n, k, suma = 0, a[N], dp[101][N], sum[101][N];

int add(int a, int b) {
	return (a % mod + b % mod) % mod;
}

int sub(int a, int b) {
	return (a % mod - b % mod + mod * mod) % mod;
}

signed main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	memset(sum, 0, sizeof sum);
	for (int i = 0; i <= k; i++) {
		sum[0][i] = 1;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= k; j++) {
			if (j > a[i]) dp[i][j] = sub(sum[i - 1][j], sum[i - 1][j - a[i] - 1]);
			else dp[i][j] = sum[i - 1][j];
			sum[i][j] = add((j ? sum[i][j - 1] : 0), dp[i][j]);
		}
		suma += a[i];
	}
	cout << dp[n][k];
}

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

// dp[i][j] = 表がi回、裏がj回出る確率
long double dp[3001][3001];

int main() {
    int n;
    cin >> n;
    vector<long double> p(n+1);
    for(int i = 1; i <= n; i++) cin >> p[i];
    long double res = 0.0;
    dp[0][0] = 1.0;
    for(int k = 1; k <= n; k++) {
        int i = 0, j = k;
        while (j >= 0) {
            if (i == 0 || j == 0) {
                if (i == 0) dp[i][j] = dp[i][j-1] * (1.0 - p[k]);
                if (j == 0) dp[i][j] = dp[i-1][j] * p[k];
            } else dp[i][j] = dp[i-1][j] * p[k] + dp[i][j-1] * (1.0 - p[k]);
            if (k == n && i > j) {
                res += dp[i][j];
            }
            i++;
            j--;
        }
    }
    cout << fixed << setprecision(10);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 139648
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.immutable._
import scala.io.StdIn.readLine

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}

object Main {
  def solve(sc: => Scanner): Unit = {
    val N, A, B, C, D = sc.nextInt
    println(math.min(((N - 1) / A + 1) * B, ((N - 1) / C + 1) * D))
  }

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}


Measured memory_bytes: 45032
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

int N, D[55];
int A[13];

int Get(int X[]) {
	rep(i, 24) if(X[i] >= 2) return 0;
	int res = 1e9;
	rep(i, 24) if(X[i]) for(int j=i+1;j<24;j++) if(X[j]) res = min(res, min(j-i, 24-(j-i)));
	return res;
}

void solve() {
	scanf("%d", &N);
	rep(i, N) scanf("%d", D+i);
	rep(i, N) A[ D[i] ]++;
	if(A[0] > 0) puts("0");
	else {
		for(int i=1;i<=12;i++) if(A[i] > 2) { puts("0"); return; }
		vector <int> v;
		int X[24] = {};
		for(int i=1;i<=12;i++) {
			if(A[i] == 1) v.pb(i);
			else if(A[i] == 2) X[i]++, X[24-i]++;
		}
		X[0]++;
		int ans = 0;
		rep(i, 1<<(szz(v))){
			
			rep(j, szz(v)) {
				if(1<<j & i) X[v[j]]++;
				else X[24-v[j]]++;
			}
			ans = max(ans, Get(X));
			
			rep(j, szz(v)) {
				if(1<<j & i) X[v[j]]--;
				else X[24-v[j]]--;
			}
		}
		printf("%d\n", ans);
	}
}

int main(){
	int Tc = 1; // scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}


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

int main() {
	int	N, Q;
	cin >> N >> Q;
	vector<stack<int>> vec(N);
	rep(i, Q)
	{
		int a, b;
		cin >> a >> b;
		if (a == 0)
		{
			int	c;
			cin >> c;
			vec.at(b).push(c);
		}
		else if (!vec.at(b).empty())
		{
			if (a == 1)
				cout << vec.at(b).top() << endl;
			else if (a == 2)
				vec.at(b).pop();

		}
	}
}



Measured memory_bytes: 4288
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

S,T=LS()
print(T+S)


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

int64_t msb(int64_t v){
  v = v | (v >>  1);
  v = v | (v >>  2);
  v = v | (v >>  4);
  v = v | (v >>  8);
  v = v | (v >> 16);
  v = v | (v >> 32);
  return v ^ (v >> 1);
}

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int main(){
    int N;
    cin >> N;
    int cnt[60] = {0};
    vector<int64_t> V(N);
    vector<int64_t> A;
    for(int i=0; i<N; i++){
        cin >> V[i];
        for(int k=0; k<60; k++) cnt[k] += nth_bit(V[i], k);
    }
    for(int k=0; k<60; k++) if(cnt[k]%2) for(int i=0; i<N; i++) if(nth_bit(V[i], k)) V[i] -= 1LL<<k;
    for(int64_t v : V){
        for(int64_t a : A) if(msb(a) & v) v ^= a;
        if(v > 0){
            A.push_back(v);
            sort(A.rbegin(), A.rend());
        }
    }

    int64_t ans = 0, v = 0, use = 0;
    for(int k=59; k>=0; k--){
        if(cnt[k]%2){
            ans += 1LL<<k;
        }else{
            int64_t v2 = use | (1LL<<k);
            for(auto a : A) if(((v^a)&v2) == v2) v ^= a;
            if((v&v2) == v2){
                ans += 2LL<<k;
                use |= 1LL<<k;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <set>
#include <algorithm>

using namespace std;

int main()
{

	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;

		set<string> a;

		int len = s.size();
		for (int i = 1; i < len; i++) {
			// 2個に分割する
			string f = s.substr(0, i);
			string b = s.substr(i, len - i);

			// 逆順の文字列を求める
			string bf = f;
			string bb = b;
	//		reverse(begin(bf), end(bf));	// 逆順にする
	//		reverse(begin(bb), end(bb));	// 逆順にする


			std::reverse(bf.begin(), bf.end());	// 逆順にする
			std::reverse(bb.begin(), bb.end());	// 逆順にする


			// 連結する
			a.insert(f + b);
			a.insert(b + f);
			a.insert(bf + b);
			a.insert(b + bf);
			a.insert(f + bb);
			a.insert(bb + f);
			a.insert(bf + bb);
			a.insert(bb + bf);
		}
		cout << a.size() << endl;
	}
	return 0;
}



Measured memory_bytes: 3260
n = int(input())
a = input()
b = input()
c = input()
ans = 0
for i in range(n):
    s = set()
    s.add(a[i])
    s.add(b[i])
    s.add(c[i])
    if len(s) == 2:
        ans += 1
    elif len(s) == 3:
        ans += 2
print(ans)

Measured memory_bytes: 9096
loop {
    a = gets.split.map(&:to_i)
    break if a[0] == 0

    x, y = a.sort[0..1]
    min = Math.sqrt(x*x + y*y)

    n = gets.to_i
    n.times{
        r = gets.to_i
        puts min < 2 * r ? "OK" : "NA"
    }
}

Measured memory_bytes: 6116
n, a, b = map(int, input().split())
if a>b:
  a, b = b, a;
r = b-a
if r%2==0:
  print(r//2)
else:
  r = (b-a-1)//2
  res = min(a-1, n-b) + r+1
  print(res)
  

Measured memory_bytes: 38384
import sys

s = sys.stdin.readline().strip()
t = sys.stdin.readline().strip()

s_len = len(s)
t_len = len(t)
dp = [[0 for x in range(t_len + 1)] for y in range(s_len + 1)]


for i in range(1, s_len+1):
    for j in range(1, t_len+1):
        if t[j-1] == s[i-1]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])

ans = ''
i = s_len
j = t_len

while i > 0 and j > 0:
    if dp[i][j] == dp[i - 1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j - 1]:
        j -= 1
    else:
        ans += s[i - 1]
        i -= 1
        j -= 1

print(ans[::-1])

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

ll a,b,c,d,n,m,k;
ll ans=100000000000;

string s;

int main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll card[3];
  int v[3] = {1,0,-1};
  cin>>card[0]>>card[1]>>card[2]>>k;
  ll sum=0;
  rep(i,3){
    if(card[i]>=k){
      sum+=v[i]*k;
      k-=k;
    }else{
      k-=card[i];
      sum+=v[i]*card[i];
    }
    if(k<=0)break;
  }
  cout<<sum;
  
  
  



  

  return 0;
}



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

int main() {
  int N, K;
  cin >> N >> K;
  int sum = 0;
  int i = 0;
  for (; i < N;) {
    int x;
    cin >> x;
    if (K-x <= x) 
      sum+=2*(K-x);
    else
      sum+=2*x;
    i++;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int main(){

            int a,b;
            scanf("%d %d",&a,&b);
            if(a==3 && b==1){
          printf("2");
                }
            if(a==1 && b==3){
                printf("2");
                }
                 if(a==2 && b==1){
                printf("3");
                }
                if(a==1 && b==2){
                printf("3");
                }
                 if(a==2 && b==3){
                printf("1");
                }
                 if(a==3 && b==2){
                printf("1");
                }
return 0;

}




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

int main() {
  vector<int> plate(3);
  for (int i = 0; i < 3; i++) {
    cin >> plate.at(i);
  }
  sort(plate.begin(), plate.end());
  cout << plate.at(0) + plate.at(1) + plate.at(2) * 10 << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    int N,M,L,K,A,H;
    int[] d;
    List<Edge>[] adj;
    int INF = 1000000000;
    List<String> f;

    public static void main(String[] args){
	new Main().solve();
    }

    class Edge{
	int t, c;
	public Edge(int t, int c) {
	    this.t = t;
	    this.c = c;
	}
    }

    @SuppressWarnings("unchecked")
    void solve(){
	Scanner sc = new Scanner(System.in);
	N = sc.nextInt();
	while(N!=0){
	    M = sc.nextInt();
	    L = sc.nextInt();
	    K = sc.nextInt();
	    A = sc.nextInt();
	    H = sc.nextInt();
	    f = new ArrayList<String>();
	    for(int i=0; i<L; i++){
		f.add(sc.nextInt()+"");
	    }
	    f.add(A+"");
	    f.add(H+"");
	    
	    adj = new List[N];
	    for(int i=0; i<N; i++)adj[i] = new ArrayList<Edge>();
	    for(int i=0; i<K; i++){
		int x = sc.nextInt();
		int y = sc.nextInt();
		int t = sc.nextInt();
		adj[x].add(new Edge(y,t));
		adj[y].add(new Edge(x,t));
	    }

	    d = new int[N*(M+1)];

	    dijkstra(A);

	    if(d[H*(M+1)+M]==INF){
		System.out.println("Help!");
	    }else{
		System.out.println(d[H*(M+1)+M]+Math.max(0,d[H*(M+1)+M]-M));
	    }

	    N = sc.nextInt();
	}
    }

    void dijkstra(int s){
	Arrays.fill(d,INF);
	d[s*(M+1)+M] = 0;
	PriorityQueue<Integer> q = new PriorityQueue<Integer>(N, new Comparator<Integer>() {
		public int compare(Integer o1, Integer o2) {
		    return d[o1]-d[o2];
		}
	    });

	q.add(s*(M+1)+M);
	while(!q.isEmpty()){
	    int v = q.poll();
	    int town = v/(M+1);
	    int left = v%(M+1);
	    for(Edge e:adj[town]){
		if(left-e.c<0)continue;
		if(f.contains(e.t+"")){
		    int w = d[town*(M+1)+left]+e.c;
		    if(w<d[e.t*(M+1)+M]){
			q.remove(e.t*(M+1)+M); 
			d[e.t*(M+1)+M] = w; 
			q.add(e.t*(M+1)+M);
		    }
		}else{
		    int w = d[town*(M+1)+left]+e.c;
		    if(w<d[e.t*(M+1)+left-e.c]){
			q.remove(e.t*(M+1)+left-e.c); 
			d[e.t*(M+1)+left-e.c] = w; 
			q.add(e.t*(M+1)+left-e.c);
		    }
		}
	    }
	}
    }
}

Measured memory_bytes: 14000
#include<iostream>
#include<string>
#include<array>
#include<algorithm>
#include<deque>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<list>

int main(void) {
	using namespace std;
	/*int N, A,res;
	cin >> N >> A;
	res = N * N - A;
	cout << res << endl;*/

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

	/*int A, B, a, b, c;
	cin >> A >> B;
	a = A + B;
	b = A - B;
	c = A * B;
	if (a >= b && a >= c) {
		cout << a << endl;
	}
	else if (b >= a && b >= c) {
		cout << b << endl;
	}
	else if (c >= a && c >= b) {
		cout << c << endl;
	}*/

	/*int K, S,res = 0;
	cin >> K >> S;
	for (int X = 0; X <= K;X++) {
		for (int Y = 0; Y <= K; Y++) {
			for (int Z = 0; Z <= K; Z++) {
				if (X + Y + Z == S) {
					res += 1;
				}

			}
		}
	}
	cout << res << endl;*/

	/*int N,a;
	cin >> N;
	set<int>s;
	for (int i = 0; i < N;i++) {
		cin >> a;
		s.insert(a);
	}
	cout << s.size() << endl;*/

	int N, a, res;
	vector<int>vec;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a;
		vec.push_back(a);
	}
	sort(vec.begin(), vec.end());
	res = vec[vec.size() - 1] - vec[0];
	cout << res << endl;

	/*int Alice = 0, Bob = 0,a,N;
	deque<int>dec;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a;
		dec.push_back(a);
	}
	sort(dec.rbegin(), dec.rend());
	for (int i = 0; i < N;i++) {
		if (i % 2 == 0) {
			Alice += dec[0];
			dec.pop_front();
		}
		else if (i % 2 == 1) {
			Bob += dec[0];
			dec.pop_front();
		}
	}
	cout << Alice - Bob << endl;*/
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* snukeくんの解説動画最後10分弱くらい */

#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 INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;

int main(){
    ll n; cin >> n;
    ll ans = 0;

    REPN(i, 1, sqrt(n) + 1) {
        if(n % i == 0) {
            ans = i;
        }
    }

    cout << ans + (n/ans) - 2 << endl;
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// 再帰関数で解いてみた
// 3^10=59049なので、3, 5, 7を含む数をすべて列挙していく
// 3, 5, 7すべて1回以上登場し、かつ、N以下であればsftにpushし、sftのサイズを出力する
ll N;
vector<ll> sft;

void func(string s){
  if(s.size() == 12) return;
  if(stoll(s) <= N){
    bool flag3 = false, flag5 = false, flag7 = false;
    REP(i, s.size()){
      if(s[i] == '3') flag3 = true;
      if(s[i] == '5') flag5 = true;
      if(s[i] == '7') flag7 = true;
    }
    if(flag3 && flag5 && flag7) sft.push_back(stoll(s));
  }
  func(s + '3');
  func(s + '5');
  func(s + '7');
  return;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  string s = "0";
  func(s);
  cout << sft.size() << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
	char c;
  	int ans=0;
  	for(int i=0; i<4; i++){
		cin >> c;
      	if(c=='-'){
			ans--;
        }else{
			ans++;
        }
    }
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
sx,sy,tx,ty=map(int,input().split())

ans=""
y=ty-sy
x=tx-sx

#1往復目
ans +="U"*y
ans +="R"*x
ans +="D"*y
ans +="L"*x
#2往復目(+1は1往復目との重複を避けるために1ずらしている。)
ans +="L"
ans +="U"*(y+1)
ans +="R"*(x+1)
ans +="D"
ans +="R"
ans +="D"*(y+1)
ans +="L"*(x+1)
ans +="U"

print(ans)

Measured memory_bytes: 3064
/*
Kaushal Jalan
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define r0 return 0;
#define f(k,i,n,j) for(ll k=i;k<=n;k=k+j)
#define cin(a) cin>>a;
#define loop int t;cin>>t;while(t--)
#define vi vector<int>
#define vii vector<long long int>
#define SORT(v) sort(v.begin(),v.end());
#define mod 1000000007
#define crap ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
int min(int a,int b){
    return (a<b)?a:b;
}
int max(int a,int b){
    return (a>b)?a:b;
}
int fp(int a,int b){
    if(b==0) return 1;
    int x=fp(a,b/2);
    x=(x*x)%mod;
    if(b&1) x=(x*a)%mod;
    return x;
}
void c_p_c()
{
    crap;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
signed main()
{
    //c_p_c();
    int n;
    cin>>n;
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        
        if(i%3==0)
        continue;
        if(i%5==0)
        continue;
        sum+=i;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3636
n = int(input())
blue =[]
red = []
result = 0

for i in range (n):
  word = input()
  blue.append(word)
  
m = int(input())

for i in range (m):
  word = input()
  red.append(word)

for word in blue:
  temp = blue.count(word) - red.count(word)
  
  if temp > result:
    result = temp
    
print (result)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<bitset>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)   
typedef long long ll;
const ll mod = 1e9+7;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6+5;
const ll N = 1e3+5;
const double pi = acos(-1.0);
const double eps=1e-9;
using namespace std;

ll a[maxn];
int main(){
    me(a);
    ll n;
    cin>>n;
    for(int i=1;i<n;i++){
        ll x;
        cin>>x;
        a[x]++;
    }
    for(int i=1;i<=n;i++){
        cout<<a[i]<<endl;
    }
}


Measured memory_bytes: 11432
#include<bits/stdc++.h>
#ifndef LOCAL_PROJECT
#define cerr if(0)cerr
#endif
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef __int128 lll;
const lll ONE=1;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int mn=2e5+10;
const ll inf=0x3f3f3f3f3f3f3f3f;
const ll mod=1e9+7;
int main(){
#ifdef LOCAL_PROJECT
    freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
#else
    cin.tie(0);
    cin.sync_with_stdio(0);
#endif
    ll n;
    cin>>n;
    ll ans=n*(n+1)*(n+2)/6;
    for(int i=0;i<n-1;i++){
        ll a,b;
        cin>>a>>b;
        if(a>b)swap(a,b);
        ans-=a*(n-b+1);
    }
    printf("%lld",ans);
}

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

int main(void) {

	int a,b,d,r;
	double f;

	scanf("%d%d",&a,&b);

	d=a/b;
	r=a%b;
	f=(double)a/b;

	printf("%d %d %f\n",d,r,f);

	return 0;
}

Measured memory_bytes: 636
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    s = list(SS())
    K = I()

    # 左からaにしていって、余ったKを一番右に突っ込む
    for i in range(len(s) - 1):
        diff = (ord('a') - ord(s[i])) % 26
        if K >= diff:
            K -= diff
            s[i] = 'a'

    if K > 0:
        s[-1] = chr((ord(s[-1]) - ord('a') + K) % 26 + ord('a'))
    
    print(''.join(s))

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10936