akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    S = input()
    N = len(S)
    K = int(input())

    places = defaultdict(list)
    for i in range(N):
        places[S[i]].append(i)

    places = sorted(places.items(), key=lambda x: x[0])
    words = set()
    for k, v in places:
        for start in v:
            cnt = 0
            for end in range(start + 1, N + 1):
                words.add(S[start:end])
                cnt += 1

                if cnt == 5:
                    break

        if len(words) >= 5:
            break

    words = sorted(words)
    print(words[K - 1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 3564
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
	int n, x, y;
	cin >> n >> x >> y;
	vector<ll>dist(n - 1);
	for (int i = 1;i < n;++i) {
		for (int j = i + 1;j <= n;++j) {
			ll res = 0;
			res = min({ j - i,abs(j - y) + abs(i - x) + 1,abs(j - x) + abs(i - y) + 1 });
			dist[res - 1]++;
		}
	}
	rep(i, n - 1) {
		cout << dist[i] << endl;
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  cout << "D";
  for(int i = 0; i < tx - sx + 1; i++)cout << "R";
  for(int i = 0; i < ty - sy + 1; i++)cout << "U";
  cout << "L";
  for(int i = 0; i < ty - sy; i++)cout << "D";
  for(int i = 0; i < tx - sx; i++)cout << "L";
  for(int i = 0; i < ty - sy; i++)cout << "U";
  for(int i = 0; i < tx - sx; i++)cout << "R";
  cout << "U";
  for(int i = 0; i < tx - sx + 1; i++)cout << "L";
  for(int i = 0; i < ty - sy + 1; i++)cout << "D";
  cout << "R" << endl;
	return 0;
}


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

using namespace std;

vector < int > L[55];

int st[11] , n , m , ans , q;

void Back(int top)
{
    if(top == (n + 1))
    {
        int s = 0;
        for(int i = 1 ; i <= q ; i++)
            if(st[L[i][1]] - st[L[i][0]] == L[i][2])
                s += L[i][3];
        ans = max(ans , s);
    }
    else for(int i = st[top - 1] ; i <= m ; i++)
    {
        st[top] = i;
        Back(top + 1);
    }
}

int main()
{
    cin >> n >> m >> q;
    for(int i = 1 ; i <= q ; i++)
    {
        int ai, bi, ci, di;
        cin >> ai >> bi >> ci >> di;
        L[i].push_back(ai);
        L[i].push_back(bi);
        L[i].push_back(ci);
        L[i].push_back(di);
    }
    st[0] = 1;
    Back(1);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=100005,INF=1<<30;

ll rui(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}

ll f(ll x){
    return rui(10,18*x);
}

vector<int> G[MAX][3];
int grundy[MAX][3];

ll sum[MAX][3];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    
    for(int q=0;q<3;q++){
        int M;cin>>M;
        for(int i=0;i<M;i++){
            int a,b;cin>>a>>b;
            if(a>b) swap(a,b);
            G[a][q].push_back(b);
        }
        for(int i=N;i>=1;i--){
            set<int> SE;
            for(int to:G[i][q]) SE.insert(grundy[to][q]);
            
            for(int j=0;;j++){
                if(SE.count(j)==0){
                    grundy[i][q]=j;
                    break;
                }
            }
        }
    }
    
    ll ans=0;
    
    for(int j=1;j<=N;j++){
        sum[grundy[j][1]][0]+=f(j);
        sum[grundy[j][1]][0]%=mod;
    }
    for(int j=1;j<=N;j++){
        sum[grundy[j][2]][1]+=f(j);
        sum[grundy[j][2]][1]%=mod;
    }
    
    for(int j=0;j<1024;j++){
        for(int k=0;k<1024;k++){
            sum[j^k][2]+=sum[j][0]*sum[k][1];
            sum[j^k][2]%=mod;
        }
    }
    
    for(int i=1;i<=N;i++){
        ans+=f(i)*sum[grundy[i][0]][2];
        ans%=mod;
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 14208
/*  ***  In The Name of God ... ***  */ 
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int long long
#define all(v) v.begin() , v.end()

template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}


int n , k ; 
bool mark [ 10 ] ;

bool ok ( int x ) {
	while ( x ) {
		if ( mark [ x % 10 ] ) return 0 ;
		x /= 10 ; 
	}
	return 1 ; 
}

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> k ;
	for ( int i = 0 ; i < k ; ++ i ) {
		int p ;
		cin >> p ;
		mark [ p ] = 1 ; 
	}
	while ( n ) {
		if ( ok ( n ) )
			return cout << n << '\n' , 0 ;
		++ n ; 
	}
}


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

int main(){
  int n;
  cin >> n;
  
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a.at(i);
  
  int next = 1;
  for (int i = 1; i <= n; i++) {
    next = a.at(next-1);
    if (next == 2) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	int t[n+1], x[n+1], y[n+1];
	t[0]=0; x[0]=0; y[0]=0;
	for(int i=1; i<=n; i++){
		cin >> t[i] >> x[i] >> y[i];
	}
	for(int i=1; i<=n; i++){
		int td=t[i]-t[i-1];
		int dd=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
		if(td<dd){
			cout << "No" << endl;
			return 0;
		}
		else if(dd==0 && td%2==1){
			cout << "No" << endl;
			return 0;
		}
		else if((td-dd)%2==1){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int C = sc.nextInt();

        int[] B = new int[M];
        for (int i = 0; i < M; i++) {
            B[i]=sc.nextInt();
        }

        int count =0;
        for (int i = 0; i < N; i++) {
            int val = 0;
            for (int j = 0; j < M; j++) {
                val += B[j] * sc.nextInt();
            }
            if(val + C > 0 ) count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <cmath>

/*std::vector<long long> divisors(long long n) {
	std::vector<long long> ret(1, 1);
	long long m = sqrt(n);
	for (long long i = 2; i <= m; i++) {
		if (n % i == 0) ret.push_back(i);
	}
	if (m == sqrt(n)) {
		for (long long i = ret.size() - 2; i >= 0; i--) {
			ret.push_back(n / ret[i]);
		}
	} else {
		for (long long i = ret.size() - 1; i >= 0; i--) {
			ret.push_back(n / ret[i]);
		}
	}
	return ret;
}*/

std::vector<long long> common_divisors(long long a, long long b) {
	auto divisors = [] (long long n) {
		std::vector<long long> ret(1, 1);
		long long m = sqrt(n);
		for (long long i = 2; i <= m; i++) {
			if (n % i == 0) ret.push_back(i);
		}
		if (m == sqrt(n)) {
			for (long long i = ret.size() - 2; i >= 0; i--) {
				ret.push_back(n / ret[i]);
			}
		} else {
			for (long long i = ret.size() - 1; i >= 0; i--) {
				ret.push_back(n / ret[i]);
			}
		}
		return ret;
	};
    if (a > b) std::swap(a, b);
    std::vector<long long> v = divisors(a);
    std::vector<long long> ret(1, 1);
    for (long long i = 1; i < v.size(); i++) {
        if (b % v[i] == 0) ret.push_back(v[i]);
    }
    return ret;
}

bool is_prime(long long n) {
    if (n == 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
	long long m = sqrt(n);
    for (long long i = 3; i <= m; i += 2) {
        if (n % i == 0) return false;
    }
    return true;
}

int main() {
    long long a, b;
    std::cin >> a >> b;
    std::vector<long long> v = common_divisors(a, b);
    long long ans = 1;
    for (auto i : v) {
        if (is_prime(i)) ans++;
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 3728
use std::collections::BTreeSet;
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const IN: usize = 1;
const OUT: usize = 0;

fn main() {
    let n = read::<usize>();
    let q = read::<usize>();
    let mut events = vec![];
    for _i in 0..n {
        let s = read::<i64>();
        let t = read::<i64>();
        let x = read::<i64>();
        events.push((s - x, IN, x));
        events.push((t - x, OUT, x));
    }
    events.sort();
    let mut query = vec![(0, 0); q];
    for i in 0..q {
        query[i].0 = read::<i64>();
        query[i].1 = i;
    }
    query.sort();
    let mut state = BTreeSet::<i64>::new();
    let mut e_index = 0;
    let mut anss = vec![0; q];
    for q_index in 0..q {
        let t = query[q_index].0;
        while e_index < events.len() && events[e_index].0 <= t {
            if events[e_index].1 == IN {
                state.insert(events[e_index].2);
            // println!("in: {:?}", events[e_index]);
            } else {
                state.remove(&events[e_index].2);
                // println!("out: {:?}", events[e_index]);
            }
            e_index += 1;
        }
        // println!("{:?}", state);
        anss[query[q_index].1] = if state.len() == 0 {
            -1
        } else {
            *state.iter().next().unwrap()
        }
    }
    for i in 0..q {
        println!("{}", anss[i]);
    }
}


Measured memory_bytes: 23668
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define c(n) cin>>n
#define c2(n,m) cin>>n>>m
#define c3(n,m,k) cin>>n>>m>>k
#define c4(n,m,k,l) cin>>n>>m>>k>>l
#define co(n) cout<<n<<endl
using namespace std;

int main(){
  long a,b=2,c=0,d=0,e,n,m=0,x;
  string s;
  c2(n,s);
  int a1[26]={},a2[26]={};
  rep(i,1,n-1){
    rep(j,0,i){
      a=s[j];
      a1[a-97]++;
    }
    rep(j,i,n){
      a=s[j];
      a2[a-97]++;
    }
    rep(j,0,26){
      if(a1[j]>0 && a2[j]>0) c++;
    }
    m=max(m,c);
    c=0;
    rep(j,0,26){
      a1[j]=0;
      a2[j]=0;
    }
  }
  co(m);
  
  
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

L = int(input())
A = [0] * L
for i in range(L):
    A[i] = int(input())

dp = [[0 for _ in range(5)] for _ in range(L+1)]
dp[0][0] = 0
for i in range(L):
    if A[i] != 0:
        dp[i+1][0] = dp[i][0] + A[i]
        dp[i+1][1] = min(dp[i][:2]) + A[i] % 2
        dp[i+1][2] = min(dp[i][:3]) + (A[i]+1) % 2
        dp[i+1][3] = min(dp[i][:4]) + A[i] % 2
        dp[i+1][4] = min(dp[i]) + A[i]
    else:
        dp[i + 1][0] = dp[i][0] + A[i]
        dp[i + 1][1] = min(dp[i][:2]) + 2
        dp[i + 1][2] = min(dp[i][:3]) + 1
        dp[i + 1][3] = min(dp[i][:4]) + 2
        dp[i + 1][4] = min(dp[i]) + A[i]
print(min(dp[-1]))


Measured memory_bytes: 80348
#Uses python3
import sys
import threading

# This code is used to avoid stack overflow issues
sys.setrecursionlimit(10**7) # max depth of recursion
threading.stack_size(2**29)  # new thread will get stack of such size

visited = set()

def explore(adj, x, comp, cc):
    visited.add(x)
    if not(cc in comp):
        comp[cc] = []
    comp[cc].append(x)
    for w in adj[x]:
        if not (w in visited):
            explore(adj, w, comp, cc)

def number_of_components(adj, n):
    #visited = [False for _ in range(n)]
    cc = 0
    comp = dict()
    for v in range(n):
        if not(v in visited):
            explore(adj, v, comp, cc)
            cc += 1
    return comp


def main():
    n, m = map(int, input().split())
    adj = [[] for _ in range(n)]
    for _ in range(m):
        a, b = map(int, input().split())
        adj[a - 1].append(b - 1)
        adj[b - 1].append(a - 1)
    res = number_of_components(adj, n)
    max_ = 0
    for value in res.values():
        max_ = max(max_, len(value))
    print(max_)
    #print(n - number_of_components(adj, n) - 1)


threading.Thread(target=main).start()


Measured memory_bytes: 647036
#include <stdio.h>
int main(void)
{
	int m, e, j, n, i;
	while(scanf("%d", &n) != EOF){
		for(i = 0; i < n; i++){
			scanf("%d%d%d", &m, &e, &j);
			if ((m == 100 || e == 100 || j == 100) || (m + e) / 2 >= 90 || (m + e + j) / 3 >= 80) 
				puts("A");
			else if((m + e + j) / 3 >= 70 || ((m + e + j) / 3 >= 50 && (m >= 80 || e >= 80))) 
				puts("B");
			else 
				puts("C");
		}
	}
	return 0;
}


Measured memory_bytes: 2040
#include <stdlib.h>
#include <iostream>
using namespace std;

int main(){
	long n;
	long m;

	cin >> n >> m;

	if(n*2 > m){
		cout << m/2 << endl;
	}else{
		cout << (n + ((m - 2*n)/4)) << endl;
	}
	
	return 0;
}



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

int main(){
    int n;
    cin >> n;
    vector<P> v(n);
    for(int i=0; i<n; i++) cin >> v[i].first >> v[i].second;
    sort(v.rbegin(), v.rend());
    vector<P> u;
    //for(int i=0; i<n-1; i++) u[i] = P{v[i+1].first - v[i].first, v[i+1].second - v[i].second};
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            //if(i != j)cout << "i = " << i << " j = " << j << endl;
            u.push_back(P{v[i].first - v[j].first, v[i].second - v[j].second});
        }
    }
    int cnt = 0;
    sort(u.rbegin(), u.rend());
    for(int i=0; i<u.size(); i++){
        int tmp = i;
        P target = u[i];
        while(u[i] == target){
            i++;
        }
        cnt = max(cnt, i - tmp);
        i--;
    }
    cout << n - cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int e= s.size();
    char s1[100001];
    char s2[100001];
    s1[0]='0';
    for(int i=1;i<e;i++)
    {
        if(i%2==1)
        {
            s1[i]='1';
        }
        else if(i%2==0)
        {
            s1[i]='0';
        }

    }
    s1[e]='\0';
    //cout << s1 << endl;
    s2[0]='1';
    for(int i=1;i<e;i++)
    {
        if(i%2==1)
        {
            s2[i]='0';
        }
        else if(i%2==0)
        {
            s2[i]='1';
        }
    }
    s2[e]='\0';
    //cout << s2 << endl;
    int cnt1=0;

    for(int i=0;i<e;i++)
    {
        if(s[i]!=s1[i])
        {
            cnt1++;
        }
    }
    int cnt2=0;
    for(int i=0;i<e;i++)
    {
        if(s[i]!=s2[i])
        {
            cnt2++;
        }
    }
    int ans= min(cnt1,cnt2);
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 640
#include<iostream>  
 
using namespace std;  
   
char table[100][100];  
int w, h;  
const int dir[4][2] = {{ -1, 0 },  { 1, 0 },  { 0, -1 },  { 0, 1 }};  
   

void Dfs(int x, int y, char cur) {
  table[x][y] = 'X';
  for (int i = 0; i < 4; ++i) {
    int next_x = x + dir[i][0];
    int next_y = y + dir[i][1];
    if (next_x >= 0 && next_x < w
        && next_y >=0 && next_y < h
        && table[next_x][next_y] == cur) {
        Dfs(next_x, next_y, cur);
    }
  }
}

int main()  
{  
   
  while (cin >> h >> w, w > 0)  
  {  
    int res = 0;  
    int x, y;  
    for (y = 0; y < h; ++y)  
    {  
      for (x = 0; x < w; ++x)  
      {  
        cin >> table[x][y];  
      }  
    }  
   
    for (y = 0; y < h; ++y)  
    {  
      for (x = 0; x < w; ++x)  
      {  
        if (table[x][y] != 'X')  
        {  
          Dfs(x, y, table[x][y]);  
          ++res;  
        }  
      }  
    }  
    cout << res << endl;  
  }  
  return 0;  
} 

Measured memory_bytes: 3560
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Set mochi = new HashSet<Integer>();
        for(int n=0;n<N;n++) mochi.add(sc.nextInt());
        System.out.println(mochi.size());
    }
}

Measured memory_bytes: 24020
#include<stdio.h>
int main(void)
{
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if(x-r >= 0 && x+r <= W && y-r >= 0 && y+r <= H)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

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

int hs(bool a){
  if(a) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
  return 0;
}

int main() {
  string s; cin >> s;
  if(s[5] == '1') return hs(0);
  if(s[6] - '0' >= 5) return hs(0);
  else return hs(1);
  
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;


int main(){
    int a,b;
    cin>> a >> b;
    int cnt=0;
    for(int i=a;i<=b;i++){
        int n1=i%10, n2=i/10000 % 10;
        int m1=i/10 % 10, m2=i/1000 % 10;
        if (n1 == n2 && m1 == m2) cnt++;
    }
    cout << cnt <<endl;
}


Measured memory_bytes: 256
x,y = map(int,input().split())
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result
if all([2*y-x >= 0,2*x-y >= 0,(2*y-x)%3==0,(2*x-y)%3==0]):
  m = (2*y-x)//3
  n = (2*x-y)//3
  print((cmb(m+n,n))%(10**9+7))
else:
  print(0)
    
    


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

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

    ll ans = 0;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
        {
            int t = __gcd(i, j);
            for (int k = 1; k <= n; ++k)
                ans += __gcd(t, k);
        }
    cout << ans << endl;
}

Measured memory_bytes: 3536
#include<stdio.h>
int main(void){
    int a=0,b=0,c=0,i,j;
    for(j=0;;j++){
    scanf("%d",&a);
    if(a==0){
    break;
    }
    b=1000-a;
    if(b>=500){
        b=b-500;
        c=c+1;
    }
    for(i=0;;i++){
        if(0<=b&&b<100){
            break;
        }
        b=b-100;
        c=c+1;
    }
    for(i=0;;i++){
        if(0<=b&&b<50){
            break;
        }
        b=b-50;
        c=c+1;
    }
        for(i=0;;i++){
        if(0<=b&&b<10){
            break;
        }
        b=b-10;
        c=c+1;
    }
        for(i=0;;i++){
        if(0<=b&&b<5){
            break;
        }
        b=b-5;
        c=c+1;
    }
        for(i=0;;i++){
        if(0<=b&&b<1){
            break;
        }
        b=b-1;
        c=c+1;
    }
    printf("%d\n",c);
    c=0;
    }
    return 0;
    }

Measured memory_bytes: 600
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

x, y = MAP()

a = [x, -x, x, -x]
b = [y, y, -y, -y]
c = [0, 1, 1, 2]

ans = inf
for i in range(4):
    if a[i] <= b[i]:
       ans = min(ans, b[i]-a[i]+c[i])
print(ans)

Measured memory_bytes: 10240
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
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; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
int main(){
  double a,b,c,x; cin>>a>>b>>x;
  if(2*x <= a*a*b){
    printf("%.7f\n", atan(a*b*b/(2*x))*180/M_PI);
  }else{
    printf("%.7f\n", atan(2*(a*a*b-x)/(a*a*a))*180/M_PI);
  }
  return 0;
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
#include<string.h>
#define pb push_back
#define all(v) v.begin(),v.end()
#define see(x) cout<<#x<<" : "<<x<<endl;
#define ya cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
typedef unsigned long long ll;
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    //freopen("test.txt","r",stdin);
    ll n,i,j,ans=1,ck=0,an=0;
    cin>>n;
    ll a[n];
    bool f=0;
    for(i=0; i<n; i++)
    {
        cin>>a[i];
        if(a[i]==0)f=1;
    }
    ans=1;
    if(f==1)
    {
        cout<<0<<endl;
        return 0;
    }
    f=0;
    for(i=0; i<n; i++)
    {
        if(ans*a[i] < ans || ans*a[i] > 1000000000000000000)
        {
            cout<<-1<<endl;
            return 0;
        }
        ans=ans*a[i];
    }
    cout<<ans<<endl;

    return 0;
}


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

const int MOD = (int)1e9+7;

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

  int n=S.size()-1;
  long long ans=0;
  for(int bit=0;bit<(1<<n);bit++){
    long long x=0;
    for(int i=0;i<S.size();i++){
      x+=S.at(i)-'0';
      if(bit&(1<<i)){
        ans+=x;
        x=0;
      }
      else  x*=10;
    }
    x/=10;
    ans+=x;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# n = gets.chomp.split('')
# n0=n=gets.to_i
# x=0
# (n.to_s.size).times do
#   x+=n%10
#   n/=10
# end
# puts n0%x==0 ? :Yes: :No
n = gets.to_i
f = n.to_s.chars.map(&:to_i).inject(&:+)
puts n%f == 0 ? "Yes" : "No"

Measured memory_bytes: 1788
# Your code here!
str = gets.split
array = gets.split
n, x = str[0].to_i, str[1].to_i

array = array.map{|n| n.to_i}

counter = 1
d = 0
i = 0

while i <= n - 1
d += array[i]
    if d <= x
        i += 1
        counter += 1
    else
        print counter
        break
    end
end

print counter if d <= x


Measured memory_bytes: 1788
#include <stdio.h>

int main(void)
{
    int i,c;
    char s[16];

    scanf("%s",s);
    for(i=0;s[i]!='\0';i++){
    if(s[i]=='x') c++;
}
if(7>=c){
    printf("YES");
}else{
    printf("NO");
}
return 0;
}


Measured memory_bytes: 128
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    character(10):: s
    integer(int32):: i


    read*, s
    i=1
    do while(i <= len_trim(s))
        if (s(i:i) == 'B') then
            s(i:) = s(i+1:) // ' '
            if (i>1) then
                s(i-1:) = s(i:) // ' '
                i=i-1
            end if
        else
            i=i+1
        end if
    end do
    print'(a)', s
end program name

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define x first
#define y second
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
struct lct
{
    static const int maxn = 1000005;
    #define INF (ll)(1e17)
    static const int N = maxn;

    pll tree[maxn << 2];
    void init(){
        for (int i = 0; i < (maxn << 2); i++)tree[i] = pll(0LL, INF);
    }
    inline ll f(pll line, int x) {
        return line.x * x + line.y;
    }
    void update(pll line, int lo = 1, int hi = N, int i = 1) {
        int m = lo + hi >> 1;
        bool left = f(line, lo) < f(tree[i], lo);
        bool mid = f(line, m) < f(tree[i], m);
        if (mid) swap(tree[i], line);
        if (hi > lo) {
            if (left != mid) update(line, lo, m, i << 1);
            else update(line, m + 1, hi, i << 1 | 1);
        }
    }
    ll query(int x, int lo = 1, int hi = N, int i = 1) {
        int m = lo + hi >> 1;
        ll curr = f(tree[i], x);
        if (hi > lo) {
            if (x < m) return min(curr, query(x, lo, m, i << 1));
            else return min(curr, query(x, m + 1, hi, i << 1 | 1));
        } else return curr;
    }
}cht;

ll n, c, h[200010];

int main()
{
    fast;
    cin >> n >> c;
    for (int i = 1; i <= n; i++)cin >> h[i];
    cht.init();
    cht.update({-2LL * h[n], (h[n]*h[n] + c)});
    ll dp;
    for (int i = n - 1; i >= 1; i--) {
        dp = h[i] * h[i] + cht.query(h[i]);
        cht.update({-2LL * h[i], (h[i]*h[i] + c + dp)});
    } cout << dp << endl;
    return 0;
}


Measured memory_bytes: 67760
#include<iostream>
using namespace std;
int main()
{
  int n, v=0;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  int dp[n];
  dp[0]=0;
  dp[1]=abs(a[0]-a[1]);
  for(int i=2;i<n;i++)
  {
    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
              
   }
  cout<<dp[n-1]<<endl;
 }             
              
      

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

int main() {
    int N;
    cin >> N;
    int cnt;
    int ans = N;
    int t;
    for (int i = 0; i <= N; i++) {
        cnt = 0;
        t = i;
        while(t > 0) {
            cnt += t % 6;
            t /= 6;
        }
        t = N - i;
        while(t > 0) {
            cnt += t % 9;
            t /= 9;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}


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

///////////////////////////////////////////
const long long int INF = INT64_MAX;
//const long long int INF = 1000000;
const long long int Mod = 1000000007;
using ll = long long int;
using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<=former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
typedef vector<vector<ll> > matrix;
///////////////////////////////////////////////////////////////////////////////////
ll n,t,a;
ll h[1001]={0};

int main(){
    cin>>n>>t>>a;
    rep(i,n)cin>>h[i];
    //input
    ll ans = 0;
    double best = abs(a-t-h[0]*0.006);
    rep(i,n){
        if(chmin(best,abs(t-h[i]*0.006-a))){
            ans = i;
        }
    }
    cout<<ans+1<<endl;
    return 0;
}

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

using namespace std;

string s;
stack<char> st;

int main(void) {

	cin>>s;
	int n = s.size();
	for(int i = 0; i < n; ++i) {
		if(s[i] == 'S') {
			st.push(s[i]);
		}
		else {
			if(!st.empty() && st.top() == 'S') {
				st.pop();
			}
			else {
				st.push(s[i]);
			}
		}
	}

	cout<<(int)(st.size());

	return 0;
}



Measured memory_bytes: 644
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
int main()
{
    reg int a=read(),b=read();
    cout<<1ll*a/__gcd(a,b)*b<<"\n";
	return 0;
}

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

MAXBIT = (10 ** 12).bit_length()
F = [0] * MAXBIT  # num of bit flag 1 of A's in each digit

for a in A:
    for i in range(MAXBIT):
        F[i] += a >> i & 1

small = False
ans = 0
for i in range(MAXBIT-1, -1, -1):
    if F[i] > N//2:  # X bit is 0
        ans += F[i] * 2 ** i
        if K >> i & 1:
            small = True
    elif F[i] <= N//2:  # X bit is 1
        if small or K >> i & 1:
            ans += (N - F[i]) * 2 ** i
        else:
            ans += F[i] * 2 ** i

print(ans)


Measured memory_bytes: 15144
#include<cstdio>
#define MAX_SET_SIZE 10000
int main() {
  int S[MAX_SET_SIZE];
  int size_s, size_t;

  scanf("%d", &size_s);
  for(int i = 0; i < size_s; i++) {
    scanf("%d", &S[i]);
  }

  scanf("%d", &size_t);
  int t_elem;
  int included_count = 0;
  for(int i = 0; i < size_t; i++) {
    scanf("%d", &t_elem);

    for(int j = 0; j < size_s; j++) {
      if(t_elem == S[j]) {
        included_count++;
        break;
      }
    }
  }

  printf("%d\n", included_count);
}



Measured memory_bytes: 2756
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll dp[4000][4000][4];
int val[4000][4000];
int r,c,k;
ll recur(int x,int y,int tot)
{
   // cout<<x<<" "<<y<<endl;
    if(x>=r || y>=c)
        return 0;
    ll &ret=dp[x][y][tot];
    if(~ret)
      return ret;
    ret=0;
    if(tot!=3)
        ret=recur(x,y+1,tot+1)+val[x][y];
    if(tot!=3)
        ret=max(ret,recur(x+1,y,0)+val[x][y]);
    ret=max(ret,recur(x+1,y,0));
    ret=max(ret,recur(x,y+1,tot));
    return ret;
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    memset(dp,-1,sizeof(dp));

    cin>>r>>c>>k;
    while(k--)
    {
        int x,y,v;
        cin>>x>>y>>v;
        val[x-1][y-1]=v;
    }
    cout<<recur(0,0,0)<<endl;

    return 0;
}


Measured memory_bytes: 550320
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  int N;
  cin >>N;
vector<int> B(N-1);
   rep(i,N-1) {
cin >>B.at(i);
   }

  
  vector<int> A(N);
  A.at(0)=B.at(0);
  A.at(N-1)=B.at(N-2);
  
  repl(i,1, N-1) {
A.at(i)=min(B.at(i-1),B.at(i));
  }
  int sum=0;
rep(i,N) {
sum +=A.at(i);
}
  cout<<sum<<endl;
  
}


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

int W, Q;
int wall[101];

void sleep(int id , map<int,int> cat ){
	bool sleepFlag = false;
	
	for(int i=0 ; i <= W-cat[id] ; i++ ){
		bool flag = true;
		
		if( wall[i] == -1 ){
			for(int j=i ; j < i+cat[id] ; j++ ){
				if( wall[j] != -1 ){
					flag = false;
				}
			}
			if( flag ){
				sleepFlag = true;
				cout << i << endl;
				for(int j=0 ; j < cat[id] ; j++ ){
					wall[i+j] = id;
				}
				break;
			}
		}
	}
	if( sleepFlag == false ){
		cout << "impossible" << endl;
	}
}

void wakeup(int id , map<int,int> cat ){
	for(int i=0 ; i < W ; i++ ){
		if( wall[i] == id ){
			wall[i] = -1;
		}
	}
}

int main(){
	int id, w;
	
	while( cin >> W >> Q , W||Q ){
		map<int,int> cat;
		for(int i=0 ; i < 101 ; i++ )
			wall[i] = -1;
		
		for(int i=0 ; i < Q ; i++ ){
			char c;
			cin >> c;
			if( c == 's' ){
				cin >> id >> w;
				cat[id] = w;
				sleep( id , cat );
			}else if( c == 'w' ){
				cin >> id;
				wakeup( id , cat );
			}
		}
		cout << "END" << endl;
	}
}

Measured memory_bytes: 0
N = int(input())
xy = [map(int, input().split()) for _ in range(N)]
x, y = [list(i) for i in zip(*xy)]

def M():
  count = 0
  for j in range(N):
    if x[j] == y[j]:
      if j+2 < N:
        if x[j+1] == y[j+1]:
          if x[j+2] == y[j+2]:
            print('Yes')
            return
  print('No')

M()

Measured memory_bytes: 9184
N=int(input())
S=input()
# N=int(Input[0][0])
# S=Input[1][0]
import math
count=0
counter={'R':0,'G':0,'B':0}
for i in S:
    counter[i]+=1
s=counter['R']*counter['G']*counter['B']
for i in range(1,N-1):
    for j in range(i+1,N):
        k=2*j-i
        if k<=N and (S[i-1]!=S[j-1] and S[i-1]!=S[k-1] and S[j-1]!=S[k-1]):
                count+=1
print(s-count)        

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

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

	char c;
	for(int i=0;i<N;i++){
		cin >> c;
		if(c == 'Y'){
			cout << "Four\n";
			break;
		}
		if(i == N-1) cout << "Three\n";
	}

	return 0;
}

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

using namespace std;

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


typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define rep2(i, n) for(int i = 1; i <= (n); i++)
#define all(a) begin(a),end(a)
#define endl '\n'




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


const int MOD = 1000000007;
const long double PI = (acos(-1));
const int MAX = 1000001;
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;
   }
}

inline void init(vector<int>& uf) {

    iota(all(uf), 0);
}

inline int root(vector<int>& uf, int x) {

    if(uf[x] == x) {

        return x;
    }
    else {

        return uf[x] = root(uf, uf[x]);
    }
}

inline bool same(vector<int>& uf, int x, int y) {

    return root(uf, x) == root(uf, y);
}

inline void unite(vector<int>& uf, int x, int y) {

    x = root(uf, x);
    y = root(uf, y);

    if(x == y) return;

    uf[x] = y;
}

int n;
int c[505];
int s[505];
int f[505];
void Input() {

    cin >> n;
}



void Solve() {


    for(int i = 0; i < n-1; i++) {

        cin >> c[i] >> s[i] >> f[i];
    }


    for(int j = 0; j < n-1; j++) {


        int com_sum = c[j] + max(s[j], f[j]);
        for(int i = j+1; i < n-1; i++) {



            if(com_sum < s[i]) {

                com_sum += s[i] - com_sum;
                if(com_sum % f[i] != 0) {

                    com_sum += f[i] - (com_sum % f[i]);
                }
            }
            else {

                if(com_sum % f[i] != 0) {

                     com_sum += f[i] - (com_sum % f[i]);
                }
            }

            com_sum += c[i];
        }
        cout << com_sum << endl;
    }

    cout << 0 << endl;


}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);
  Input();
  Solve();


  return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % mod;
    } else {
        return modpow(m, n - 1) * m % mod;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

long long nCkmod(long long n, long long k) {
    long long denomi = 1;
    REP(i, n) {
        denomi *= (i + 1);
        denomi %= mod;
    }
    long long numera = 1;
    for (int i = n - k; i > 0; i--) {
        numera *= i;
        numera %= mod;
    }
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}

vector<int> h, memo;

// int dp(int n) {
//     if (memo[n] != -1) {
//         return memo[n];
//     }
//     if (n == 0) {
//         return 0;
//     }
//     if (n == 1) {
//         return abs(h[1] - h[0]);
//     }
//     memo[n] = min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
//     return min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
// }
signed main() {
    int n, m;
    cin >> n >> m;
    vector<int> as(n);
    REP(i, n) { cin >> as[i]; }
    sort(as.begin(), as.end());
    vector<int> bs(n);
    vector<pair<int, int>> cb(m);
    REP(i, m) {
        cin >> cb[i].second;
        cin >> cb[i].first;
    }
    sort(cb.rbegin(), cb.rend());
    long long sum = 0, now = 0;
    REP(i, m) {
        REP(j, cb[i].second) {
            if (cb[i].first > as[now]) {
                sum += cb[i].first;
            } else {
                sum += as[now];
            }
            now++;
            if (now == n) {
                cout << sum << endl;
                return 0;
            }
        }
    }
    for (int i = now; i < n; i++) {
        sum += as[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define INS(x) x.begin(),x.end()
#define debug(x) cout<<x;
    

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

    cout<<x/500*1000+x%500/5*5<<'\n';
    return 0;
}

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

int main(){
    int N,L;
    vector<string> a;
    cin >> N >> L;
    for(int i=0; i<N; i++){
        string s;
        cin >> s;
        a.push_back(s);
    }
    sort(a.begin(),a.end());
    string s = "";
    for(int i=0; i<N; i++){
        s += a[i];
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	S := sc.nextStr()
	str := S[0:4] + S[5:7] + S[8:len(S)-1]
	if str <= "20190430" {
		fmt.Println("Heisei")
	} else {
		fmt.Println("TBD")
	}
}


Measured memory_bytes: 640
<?php
$str = trim(fgets(STDIN));
$l = strlen($str);
$min = 10**10;
$max = -10**10;
for($i = 0; $i < $l; $i++){
    if($str[$i] == "A" && $min == 10**10)$min = $i;
    if($str[$i] == "Z")$max = $i;
}
echo $max - $min + 1;


Measured memory_bytes: 4856
object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  show
  def show = {
    val (n, pair) = (2 to 40).map { whole ⇒ (whole, maxPairCount(whole)) }.maxBy { it ⇒ estimated(it._2, it._1 - it._2) }
    println(n)

    for (from ← 0 until n) {
      if (from < pair) {
        println((0 until n).map { to ⇒
          if (to < pair) 'N'
          else 'Y'
        }.mkString)
      } else {
        println((0 until n).map { to ⇒
          if (from == to) 'N'
          else 'Y'
        }.mkString)
      }
    }
  }

  def estimated(pair: Int, nonPair: Int): Double = {
    pair - pair.toDouble / (nonPair + 1) - nonPair.toDouble / (pair + nonPair)
  }
  def maxPairCount(wholeNode: Int): Int = {
    (1 until wholeNode).maxBy{pair ⇒ estimated(pair, wholeNode - pair)}
  }
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    string s;cin >> s;
    deque<char> res;
    rep(i,s.size()){
        if(s[i] == 'B'){
            if(!res.empty())res.pop_back();
        }
        else res.push_back(s[i]);
    }
    while(!res.empty()){
        cout << res.front();
        res.pop_front();
    }
    cout << endl;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;
  cin >> s;
  
  string t;
  t = s;
  reverse(t.begin(), t.end());
  
  int ans = 0;
  for(int i = 0; i < (s.size() + 1) / 2; i++){
    if(s.at(i) != t.at(i)) ans++;
  }
  
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
#define mp make_pair
#define all(a) a.begin(), a.end()
#define pub push_back
#define ll long long
					  
using namespace std;

ll lcm(ll a, ll b){
	ll ans = a / __gcd(a, b);
	return ans * b;
}

int main(){
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//freopen("seating.in", "r", stdin);
	//freopen("seating.out", "w", stdout);
	int n;
	ll a[111];
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	ll ans = a[0];
	for (int i = 1; i < n; i++) ans = lcm(ans, a[i]);
	cout << ans;
}

Measured memory_bytes: 256
from collections import deque

N,M,S = map(int,input().split())
city = [[]for i in range(N)]
for i in range(M):
    u,v,a,b = map(int,input().split())
    city[u-1].append([v-1,a,b])
    city[v-1].append([u-1,a,b])
ex = [[] for i in range(N)]
for i in range(N):
    c,d = map(int,input().split())
    ex[i] = [c,d]

MCOIN = 5000

cost = [[float('inf')]*(MCOIN+500) for i in range(N)]
cost[0][min(MCOIN,S)] = 0

queue = deque([[0,min(MCOIN,S)]])
while queue:
    p,m = queue.popleft()
    if m < MCOIN and cost[p][m+ex[p][0]] > cost[p][m] + ex[p][1]:
        queue.append([p,m+ex[p][0]])
        cost[p][m+ex[p][0]] = cost[p][m] + ex[p][1]
    for v,a,b in city[p]:
        if m >= a  and cost[v][m-a] > cost[p][m] + b:
            queue.append([v,m-a])
            cost[v][m-a] = cost[p][m] + b

for i in cost[1:]:
    print(min(i))

Measured memory_bytes: 176584