akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
#define ip(arr, n) for(int i=0; i<n; i++) cin>>arr[i];
#define op(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define fstIO ios_base::sync_with_stdio(false); cin.tie(NULL);

void stringEquivalence(int n, int i, string out, char max_char){
    if(i==n){
        cout<<out<<endl;
        return;
    }

    for(char c='a'; c<=max_char; c++){
        out += c;
        if(c == max_char){
            stringEquivalence(n, i+1, out, max_char+1);
        }
        else stringEquivalence(n, i+1, out, max_char);
        out.pop_back();
    }
}
int main(){
    int n;
    cin>>n;
    stringEquivalence(n, 0, "", 'a');
    return 0;
}

Measured memory_bytes: 1536
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int w = sc.nextInt(), h = sc.nextInt(), n = sc.nextInt();

		int lx = 0, rx = w;
		int ly = 0, ry = h;

		for(int i=0;i<n;i++){
			int x = sc.nextInt(), y = sc.nextInt(), a = sc.nextInt();
			if(a==1)
				lx = Math.max(x, lx);
			else if(a==2)
				rx = Math.min(rx, x);
			else if(a==3)
				ly = Math.max(ly, y);
			else
				ry = Math.min(ry, y);
		}
		sc.close();

		if(ry<=ly || rx<=lx)
			System.out.println(0);
		else
			System.out.println((rx-lx) * (ry-ly));
		}
}

Measured memory_bytes: 22228
from bisect import bisect_left
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

cumA=[0]*(N+1)
cumB=[0]*(M+1)

for i in range(N):
    cumA[i+1]=cumA[i]+A[i]
for i in range(M):
    cumB[i+1]=cumB[i]+B[i]

ans=0
for i in range(N+1):
    r=K-cumA[i]
    if r<0:
        break
    b=bisect_left(cumB,r)
    if b==M+1:
        ans=max(ans,i+M)
    else:
        if cumB[b]!=r:
            b-=1
        ans=max(ans,i+b)
print(ans)

Measured memory_bytes: 110836
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)

a,b,k = map(int,input().split())

def cd(a,k):
    for i in reversed(range(1,a+1)):
        if a%i == 0:
            k = k-1
            if k==0:
                return i
    return -1

print(cd(gcd(a,b),k))


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

int main() {
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i%3 == 0 || i%5 == 0) {
      continue;
    }
    ans += i;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a;string b;cin>>a>>b;b.erase(b.begin()+1);
  ll c=stoll(b);
  print(a*c/100);
  return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#pragma region Macros
#define ios\
    ios::sync_with_stdio(false);\
    cin.tie(nullptr);
#define VEC(type, name, size)\
    V<type> name(size);\
    IN(name)
#define VVEC(type, name, h, w)\
    VV<type> name(h, V<type>(w));\
    IN(name)
#define INT(...)\
    int __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LL(...)\
    ll __VA_ARGS__;\
    IN(__VA_ARGS__)
#define STR(...)\
    string __VA_ARGS__;\
    IN(__VA_ARGS__)
#define CHAR(...)\
    char __VA_ARGS__;\
    IN(__VA_ARGS__)
#define DOUBLE(...)\
    DOUBLE __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LD(...)\
    LD __VA_ARGS__;\
    IN(__VA_ARGS__)
template <class T> void scan(T &a) { cin >> a; }
template <class T> void scan(vector<T> &a) { for(auto &i : a) scan(i); }
template <class T, class L> void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) { scan(head); IN(tail...); }
template <class T> inline void print(T x){ cout << x << '\n';}
#define ll long long
#define ld long double
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
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; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
template <typename T> T pow(T a, long long n, T e = 1) {T ret = e; while (n) {if (n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
const ll INF = 1e18;
#pragma endregion

string res, ok, prefix;

int main(){
    ios;
    INT(n, k);
    STR(s);
    string t = s;
    reverse(all(t));
    s += t;
    char mini = 'z';
    REP(i, 2 * n) chmin(mini, s[i]);
    int max_len = 0, cnt = 0;
    REP(i, 2 * n){
        if(s[i] == mini) cnt++;
        else cnt = 0;
        chmax(max_len, cnt);
    }
    if(k > 13 or max_len * pow(2, k - 1) >= n){
        REP(i, n) cout << mini;
        cout << endl;
        return 0;
    }
    REP(i, n) res += 'z';
    REP(i, max_len) ok += mini;
    REP(i, pow(2, k - 1)) prefix += ok;
    REP(i, n + 1){
        if(s.substr(i + n - max_len, max_len) != ok) continue;
        string d = s.substr(i + max_len * (pow(2, k - 1) - 1), n - max_len * pow(2, k - 1));
        reverse(all(d));
        chmin(res, prefix + d);
    }
    print(res);
}

Measured memory_bytes: 4096
fn main() {
    let s = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    };

    let (n, m) = {
        let mut ws = s.split_whitespace();
        let n: i32 = ws.next().unwrap().parse().unwrap();
        let m: i32 = ws.next().unwrap().parse().unwrap();
        (n, m)
    };

    let res = n - m*2;
    if res > 0 {
        println!("{}", res);
    } else {
        println!("{}", 0);
    }
}


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

using namespace std;

char a[2][3];

int main()
{
    for (int i = 1; i <= 2; i++)
        for (int j = 1; j <= 3; j++)
            cin >> a[i][j];
    if (a[1][1] == a[2][3] && a[1][2] == a[2][2] && a[1][3] == a[2][1]) cout << "YES";
    else cout << "NO";
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define endl "\n"
#define all(v) v.begin(),v.end()
#define sz(v)  v.size()


void fast() {

    cin.tie(0);
    cin.sync_with_stdio(0);
}



int main() {
    fast();
    ll n,h;cin>>n>>h;
    ll A[n],B[n];
    for (int i = 0; i <n ; ++i) {
        cin>>A[i]>>B[i];
    }
    sort(A,A+n,greater<int>());
    sort(B,B+n,greater<int>());
    bool done =false;
    ll ans=0;
    for (int j = 0; j <n ; ++j) {
        if(B[j]>=A[0])ans++,h-=B[j];
        else break;
        if(h<=0){
            done= true;
            break;
        }
    }
    if(!done)ans+=(h/A[0])+(h%A[0]!=0);
    cout<<ans;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int K,S;
  cin >> K >> S;
  int count, A;
  count = 0;
  for(int i = 0;i <= K;i++){
    for(int j = 0;j <= K;j++){
      A = S - i - j;
      if(A >= 0 && A <= K) count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int sum(int A[],int a, int key)
{
    int i=0;
    A[a]=key;
    while(A[i]!=key)i++;
    return i!=a;
}

int main()
{
    int a,b,A[10000+1],c,key,tum=0;
    
    scanf("%d",&b);
    for(a=0;a<b;a++)
    {
        scanf("%d",&A[a]);
    }
    scanf("%d",&c);
    for(a=0;a<c;a++)
    {
        scanf("%d",&key);
        if(sum(A,b,key))
        tum++;
        
    }
    printf("%d\n",tum);
    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
using vs = vector<string>;
using ll = long long;

void solve(long long N, std::vector<std::string> s){
  bool A = false;
  ll ans = 0;
  ll B_A = 0;
  ll B_ = 0;
  ll _A = 0;
  for(auto& str : s){
    if(str.at(0) == 'B' && *(str.end() - 1) == 'A'){
      ++B_A;
    } else if(str.at(0) == 'B'){
      ++B_;
    } else if(*(str.end() - 1) == 'A'){
      ++_A;
    }
    A = false;
    for(auto& c : str){
      if(c == 'A'){
        A = true;
      } else {
        if(c == 'B' && A == true){
          ++ans;
        }
        A = false;
      }
    }
  }

  //cout << B_A << ' ' << B_ << ' ' << _A << ' ' << ans << endl;

  // B_Aを全部結合
  if(B_A > 1){
    ans += B_A - 1;
    B_A = 1;
  }

  // 結合したB_Aを消費
  if(B_A == 1 && (_A > 0 || B_ > 0)){
    ++ans;
  }

  //_AとB_を結合
  ans += min(_A, B_);

  cout << ans << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> s(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> s[i];
    }
    solve(N, std::move(s));
    return 0;
}


Measured memory_bytes: 768
#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

void solve(std::vector<ll> H, std::vector<ll> M, ll K) {
  ll H1 = H.at(0);
  ll H2 = H.at(1);
  ll M1 = M.at(0);
  ll M2 = M.at(1);

  ll dh = H2 - H1;
  ll dm = M2 - M1;

  ll m = dh * 60 + dm;

  cout << m - K << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  std::vector<ll> H(2);
  std::vector<ll> M(2);
  for (int i = 0; i < 2; i++) {
    scanf("%lld", &H[i]);
    scanf("%lld", &M[i]);
  }
  ll K;
  scanf("%lld", &K);
  solve(std::move(H), std::move(M), K);
  return 0;
}


Measured memory_bytes: 3724
import java.io.PrintWriter

fun main(args: Array<String>) {
    val pw = PrintWriter(System.out)
    val n = readLine()!!.toInt()
    val tree = mutableMapOf<Int, MutableList<Pair<Int, Long>>>()
    repeat(n - 1) {
        val s = readLine()!!.split(' ')
        val a = s[0].toInt()
        val b = s[1].toInt()
        val c = s[2].toLong()

        tree.getOrPut(a) { mutableListOf() }.add(b to c)
        tree.getOrPut(b) { mutableListOf() }.add(a to c)
    }

    val visited = BooleanArray(n + 1) { false }
    val costs = LongArray(n + 1) { 0L }

    fun dfs(v: Int, cost: Long) {
        visited[v] = true
        costs[v] = cost
        for ((u, c) in tree.getOrElse(v) { emptyList<Pair<Int, Long>>() }) {
            if (visited[u]) {
                continue
            }
            dfs(u, cost + c)
        }
    }

    val (q, k) = readLine()!!.split(' ').map { it.toInt() }

    dfs(k, 0)

    repeat(q) {
        val (x, y) = readLine()!!.split(' ').map { it.toInt() }
        pw.println(costs[x] + costs[y])
    }

    pw.flush()
}


Measured memory_bytes: 140184
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
const int N = 1e5 + 5;
queue<int> q;
int n, head[N], tot, deg[N], is[N], f[N], sum, mn;
char s[N];
struct node{int to, nex;}a[N << 1];
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
void add(int x, int y) {a[++ tot].to = y; a[tot].nex = head[x]; head[x] = tot; deg[x] ++;}
void topsort()
{
	for(int i = 1; i <= n; i ++) if(deg[i] == 1 && s[i] == 'B') q.push(i);
	while(!q.empty())
	{
		int x = q.front(); q.pop(); is[x] = 1;
		for(int i = head[x]; i; i = a[i].nex)
		{
			int y = a[i].to; deg[y] --;
			if(deg[y] == 1 && !is[y] && s[y] == 'B') q.push(y);
		}
	}
}
int v(int x) {return (deg[x] & 1) ^ (s[x] == 'W');}
int val(int x) {return (v(x) == 1) ? -2 : 0;}
void dfs(int x, int fa)
{
	f[x] = val(x); sum += (v(x) == 1) + 2;
	for(int i = head[x]; i; i = a[i].nex)
	{
		int y = a[i].to; if(y == fa || is[y]) continue;
		dfs(y, x);
		if(mn > f[x] + f[y]) mn = f[x] + f[y];
		f[x] = min(f[x], f[y] + val(x));
	}
}
int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read();
	for(int i = 1, x, y; i <= n - 1; i ++)
	{
		x = read(); y = read();
		add(x, y); add(y, x);
	}
	scanf("%s", s + 1); topsort(); int x;
	for(x = 1; x <= n; x ++) if(!is[x]) break;
	if(x > n) {puts("0"); return 0;}
	dfs(x, 0); sum -= 2; printf("%d\n", sum + mn);
	fclose(stdin);
	fclose(stdout);
	return 0;
}


Measured memory_bytes: 8704
#include<stdio.h>
char p[1000020]={1,1};
int main(){
  long long n,i,j,s=1,d[100010],c,M=1000010;
  for(i=0;i*i<M;i++){
    if(p[i])continue;
    for(j=i*i;j<M;j+=i)p[j]=1;
  }
  for(i=c=0;i<M;i++){
    if(p[i]==0)d[c++]=i;
  }//printf("%lld %lld\n",M*M,c);
  //for(i=0;s*d[i]<1e12;i++)s*=d[i];printf("%lld\n",s);
  while(scanf("%lld",&n),n){
    s=1;
    for(i=0;n-1&&i<c;i++){
      for(j=0;n%d[i]==0;j++)n/=d[i];//,printf("%lld %lld\n",n%d[i],j);
      s*=j+j+1;
    }
    if(n-1)s*=3;
    printf("%lld\n",s/2+1);
  }
  return 0;
}

Measured memory_bytes: 2196
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Output
template<class T, class S> std::ostream& operator <<(std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator <<(std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec; }
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H&& head){ std::cout << head << std::endl; }
template<typename H, typename... T> void print(H&& head, T&&... tail){
  std::cout << head << " ", print(std::forward<T>(tail)...);
}

// FAIL
void fail(){ print(-1); std::exit(0); }

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

  ll N, M;
  std::cin >> N >> M;

  std::vector< int > vc(N, -1);

  for (ll i = 0; i < M; i++) {
    int s, c;
    std::cin >> s >> c;
    s--;
    if (vc[s] != c && vc[s] != -1) fail();
    vc[s] = c;
  }

  if (vc[0] == 0) {
    if (N != 1) fail();
  }
  if (N == 1) {
    if (vc[0] == -1) vc[0] = 0;
  }

  if (vc[0] == -1) vc[0] = 1;
  std::cout << vc[0];

  for (ll i = 1; i < N; i++) {
    if (vc[i] == -1) vc[i] = 0;
    std::cout << vc[i];
  }
  print();

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String akihabara = "AKIHABARA";
		String kihbr = "KIHBR";
		String s = scanner.nextLine();

		int i;
		int j = 0;
		int k = 0;
		for(i = 0; i < s.length(); i++){
			if(
				j+1 < akihabara.length() &&
				akihabara.charAt(j) == 'A' &&
				akihabara.charAt(j) != s.charAt(i)
			) {
				j++;
			}

			if(j >= akihabara.length() || akihabara.charAt(j) != s.charAt(i)) {
				System.out.println("NO");
				return;
			}
			if(s.charAt(i)!='A') {
				if(s.charAt(i) == kihbr.charAt(k)) {
					k++;
				} else {
					System.out.println("NO");
					return;
				}
			}
			
			j++;
		}
		if(k == kihbr.length()) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


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

int main() {
	long long n, a, b, c, d, e;
	cin >> n >> a >> b >> c >> d >> e;
	long long minV = min({a, b, c, d, e});
	long long ans = (n + minV - 1) / minV + 4;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import Data.Function
import Data.List

main :: IO ()
main = do
  _n <- readLn :: IO Int
  hs <- map read.words <$> getLine
  print $ solve hs

solve :: [Int] -> Int
solve hs
    | maximum hs == 0 = 0
    | otherwise = foldl' (+) m . map solve
        . groupBy ((==) `on` compare 0)
        $ map (subtract m) hs
  where
    m = minimum hs

Measured memory_bytes: 1148
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n, k, a[200100], i, nowplace=0, loop[200100], cnt=0, ans=0, pla=0, lcnt=0, f=0;
    map<long long, long long> mp;
    cin >> n >> k;
    for(i=0;i<n;i++){
        cin >> a[i];
        a[i]--;
    }
    for(i=0;i<k;i++){
        mp[nowplace]++;
        if(mp[nowplace]>1){
            f=1;
            break;
        }
        nowplace=a[nowplace];
        cnt++;
    }
    if(f==0){
        cout << nowplace+1 <<endl;
        return 0;
    }
    pla=nowplace;
    for(i=0;i<k;i++){
        if(mp[pla]>2) break;
        loop[i]=pla;
        pla=a[pla];
        mp[pla]++;
        lcnt++;
    }
    k-=cnt;
    ans=loop[(k%lcnt)]+1;
    cout << ans <<endl;
    return 0;
}

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

int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
   	int l,d,r,count=0;
   	cin>>l>>d>>r;
   	for(int i=l; i<=d; i++){
   		if(i%r==0){
   			count++;
   		}
   	}
   	cout<<count<<"\n";
    return 0;
}

Measured memory_bytes: 3604
#ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var) \
  cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<vector<pair<int, int>>> edges(n, vector<pair<int, int>>());
  for (int i = 0; i < n; ++i) {
    int u, k;
    cin >> u >> k;
    for (int j = 0; j < k; ++j) {
      int v, c;
      cin >> v >> c;
      edges[i].push_back(make_pair(v, c));
    }
  }
  int count = 1;
  constexpr auto not_yet = numeric_limits<int>::max();
  vector<int> costs(n, not_yet);
  costs[0] = 0;
  auto cmp = [](const pair<int, int>& lhs, const pair<int, int>& rhs) {
    return lhs.second > rhs.second;
  };
  priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(cmp)> q(cmp);
  for (auto&& edge : edges[0]) {
    q.push(edge);
  }
  while (true) {
    auto state = q.top();
    q.pop();
    if (costs[state.first] > state.second) {
      assert(costs[state.first] == not_yet);
      for (auto&& edge : edges[state.first]) {
        q.push(make_pair(edge.first, edge.second + state.second));
      }
      costs[state.first] = state.second;
      if (++count == n) {
        break;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << i << " " << costs[i] << endl;
  }
}

Measured memory_bytes: 3208
# 全探索で行う
N, M, Q = map(int, input().split())
query = [list(map(int, input().split())) for _ in range(Q)]
A = [1]

def dfs(now):
    if len(now) == N:
        global ans
        tmp_ans = 0
        for a, b, c, d in query:
            a -= 1
            b -= 1
            if now[b] - now[a] == c:
                tmp_ans += d
        ans = max(ans, tmp_ans)
    else:
        for i in range(now[-1], M+1):
            tmp = now.copy()
            tmp.append(i)
            dfs(tmp)


ans = 0
dfs(A)
print(ans)


Measured memory_bytes: 9100
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Integer n = sc.nextInt();
		Integer a = sc.nextInt();
		Integer rem = n%500;
		if(rem <= a){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

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

int ctoi(char c) {
    int n = c - '0';
    return n;
}

int pow_int(int x, int n) {//x^n
    if (n == 0) {
        return 1;
    }else {
        int y = x;
        for (int i = 0; i < n; i++) {
            x *= y;
        }
        return x;
    }
}

long long pow_ll(int x, int n) {//x^n
    if (n == 0) {
        return 1;
    }else {
        long long ans = 1;
        for (int i = 0; i < n; i++) {
            ans *= x;
        }
        return ans;
    }
}


int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    sort(p.begin(), p.end());
    int ans = 0;
    rep(i, k) ans += p[i];
    cout << ans << endl;
}

Measured memory_bytes: 3564
def main():
    from collections import defaultdict
    import sys
    sys.setrecursionlimit(10 ** 9)
    
    H, W = list(map(int, raw_input().split()))
    G = [list(raw_input()) for i in range(H)]
    
    Visited = [[0] * W for i in range(H)]
    direction = [[0, 1], [0, -1], [1, 0], [-1, 0]]
    
    
    def dfs(ny, nx, color):
        for dy, dx in direction:
            if not ((0 <= ny + dy < H) and (0 <= nx + dx < W)):
                continue
    
            if G[ny + dy][nx + dx] == G[ny][nx]:
                continue
    
            if Visited[ny + dy][nx + dx] != 0:
                continue
    
            if G[ny + dy][nx + dx] == '#':
                Visited[ny + dy][nx + dx] = color
            else:
                Visited[ny + dy][nx + dx] = -color
    
            dfs(ny + dy, nx + dx, color)
    
    
    Color = 1
    for y in range(H):
        for x in range(W):
            if Visited[y][x] == 0:
                if G[y][x] == '#':
                    Visited[y][x] = Color
                else:
                    Visited[y][x] = -Color
                dfs(y, x, Color)
                Color += 1
    
    D = defaultdict(int)
    for i in range(1, Color + 1):
        D[i] = 0
        D[-i] = 0
    
    for row in Visited:
        for data in row:
            D[data] += 1
    
    ans = 0
    for key in D.keys():
        ans += D[key] * D[-key]
    
    print(ans // 2)
    
main()


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

int lower_bound(int *A, int N, int key) {
  int left = 0;
  int right = N;

  while (left < right) {
    int mid = (left + right) / 2;
    if (key <= A[mid]) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  return left;
}

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

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

  int Q;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    int k;
    cin >> k;
    int ans = lower_bound(A, N, k);
    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 3480
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sort(a) sort(all(a))
using P = pair<int, int>;
using ll = long long;
using ld = long double;
typedef vector<int> vi;
int dx[4] = { 0, 1, 0,-1 };
int dy[4] = { 1, 0,-1, 0 };
const ll MOD = 1000000007;

signed main() {
  int n;cin >>n;
  cout << n*n*n << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long int ll;

int main() {
  ll N, L, max, sum;

  max = 0;
  sum = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> L;
    if (max < L) {
      max = L;
    }
    sum += L;
  }
  if (max < sum - max) {
    cout << "Yes";
  }else{
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
void swap(int *,int *);
int sum=0;
int main(){
  int n,i,retu[100],mini,j;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&retu[i]);
  
  for(i=0;i<n;i++){
    mini=i;
    for(j=i;j<n;j++){
      if(retu[j] < retu[mini]){
	mini = j;
      }
    }
    if(i!=mini)swap(&retu[i],&retu[mini]);
  }
  for(i=0;i<n-1;i++)printf("%d ",retu[i]);
  printf("%d",retu[n-1]);
  printf("\n%d\n",sum);
  return 0;
}

void swap(int *a,int *b){
  int temp;
  temp = *a;
  *a = *b;
  *b = temp;
  sum++;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <set>
#define F first
#define S second
using namespace std;
int n, ans;
pair<int, int> a[205];
set<int> st;
int main() {
	int i;
	set<int>::iterator it;
	cin>>n;
	for(i=0; i<n; i++) {
		cin>>a[i].F>>a[i].S;
		a[i].F = a[i].F*10 + 1;
	}
	for(i=0; i<n; i++) {
		cin>>a[n+i].F>>a[n+i].S;
		a[n+i].F = a[n+i].F*10;
	}
	sort(a, a+2*n);
	for(i=0; i<2*n; i++) {
		if(a[i].F%2) st.insert(a[i].S);
		else {
			it = st.lower_bound(a[i].S);
			if(it!=st.begin()) {
				--it;
				st.erase(it);
				ans++;
			}
		}
	}
	cout<<ans;
	return 0;
}

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

typedef long long ll ;
#define rep (i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int N;
	
	cin >> N;

	int tmp = N;

	int count = 0;
	while (tmp)
	{
		if (tmp % 10 == 2)
		{
			count++;
		}

		tmp = tmp / 10;
	}

	cout << count << endl;

	
	return 0;
}

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

#define MAX_N 50

int main() {
    int N;
    char S[MAX_N + 1];
    cin >> N >> S;
    int count = 0;
    for (int i = 0; i+2 < N; i++) {
        if (S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C') {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())

S = []
for i in range(N):
  S.append(str(input()))

M = int(input())

T = []
for i in range(M):
  T.append(str(input()))

money = [0]

for i in S:
  cc = S.count(i)-T.count(i)
  money.append(cc)

print(max(money))

Measured memory_bytes: 3064
import copy
import heapq
import math

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printrow(a):
    for i in a:
        print(i)

n = ip()
a =input().split()
f = []
for i in range(n):
    f.append(a[0][i])
    f.append(a[1][i])
print(''.join(f))

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  
  int a,b,k;
  cin >> a>>b>>k;
  int count=0,ans;
  int c;
  if(a>b) {
    c=a; a=b; b=c;
  }
  
  for(int i=a; i>0; i--){
  	if(a%i==0 && b%i==0) count++;
    if(count==k){
      ans=i; break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, e) for(int i = (int)(s); i < (int)(e); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPR(i, s, e) for(int i = (int)(s-1); i >= (int)(e); --i)
#define repr(i, n) REPR(i, n, 0)
#define pb push_back
using namespace std;

struct P {
  int x, y;
  P() = default;
  P(int x, int y) : x(x), y(y){}
  bool operator < (const P& p) const {
    if(x != p.x) return x < p.x;
    return y < p.y;
  }
  bool operator == (const P& p) const {
    return !((*this < p) || (p < *this)); 
  }
};

P rot(const P& p) {
  return P{-p.y, p.x};
}

vector<P> rotL(const vector<P>& l) {
  vector<P> ret;
  rep(i, l.size()) {
    ret.push_back(rot(l[i]));
  }
  return ret;
}

vector<vector<P>> makeLine(vector<P> l) {
  vector<vector<P>> ret;
  int m = l.size();
  repr(i, m) {
    l[i].x -= l[0].x;
    l[i].y -= l[0].y;
  }
  ret.push_back(l);
  rep(i, 3) {
    ret.push_back(rotL(ret[i]));
  }
  return ret;
}

vector<vector<P>> makeLine2() {
  int m;
  cin >> m;
  vector<P> l;
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    l.emplace_back(x, y);
  }
  vector<vector<P>> ret;
  auto tmp = makeLine(l);
  for(const auto l : tmp) ret.pb(l);
  reverse(l.begin(), l.end());
  auto tmp_rev = makeLine(l);
  for(const auto l : tmp_rev) ret.pb(l);
  return ret;
}

int main() {
  int n;
  while(cin >> n) {
    if(n == 0) break;
    auto A = makeLine2();
    rep(i, n) {
      auto B = makeLine2();
      bool f = false;
      for(const auto& a : A) for(const auto& b : B) f |= (a == b);
      if(f) cout << i+1 << endl;
    }
    cout << "+++++" << endl;
  }
  return 0;
}



Measured memory_bytes: 3144
import java.util.*;
import java.lang.Math;

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

  		int a = sc.nextInt(); 
      	int b = sc.nextInt(); 
      	int c = sc.nextInt(); 
      	int d = sc.nextInt(); 
      	String str = "No";
      	
      	if((Math.abs(a-b) <= d && Math.abs(b-c) <= d) || Math.abs(c-a) <= d) str = "Yes";
      	
      	
      	System.out.println(str);
        
	}
}


Measured memory_bytes: 35632
#(34)フレームの描画
while True:
    H,W = [int(x) for x in input().split()]
    
    if (H,W)==(0,0): 
        break
    for i in range(H):
        if i==0 or i==H-1:
            print("#"*W)
        else:
            print("#" + "."*(W-2) + "#")
            
    print("")


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

#define endl '\n'
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

typedef long long llong;
typedef pair<int, int> pii;

void solve() {

	int n;
	cin >> n;

	multiset<char> curr_set, new_set;

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

		string str;
		cin >> str;

		if (i == 0) {

			for (char c : str) {
				curr_set.insert(c);
			}

		} else {

			for (char c : str) {

				auto it = curr_set.find(c);

				if (it != curr_set.end()) {

					new_set.insert(c);
					curr_set.erase(it);

				}

			}

			curr_set = move(new_set);

		}

	}

	for (char c : curr_set) {
		cout << c;
	}

}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	#ifdef LOCAL
		ifstream in("in");
		cin.rdbuf(in.rdbuf());
	#endif

	solve();

	return 0;

}

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

int main(){
int a, b, c;
cin >> a >> b >> c;
if(a != b && a != c && b != c){
cout << "No";
}
else if(a != b || a != c || b != c){
cout << "Yes";
}
else{
cout << "No";
}
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define MAX 50
using namespace std;
typedef long long ll;
typedef pair<double, ll> P;
typedef tuple<ll, ll, ll> T;

ll N, A, B;

ll a[MAX + 1][MAX + 1] = {{0}};
ll nCr(ll n, ll r){
    for(int i = 0; i <= MAX; i++){
        for(int j = 0; j <= i; j++){
		    if(j == 0) a[i][j] = 1;
		    else a[i][j] = (a[i - 1][j] + a[i - 1][j - 1]);
        }
	}
	return a[n][r];
}

int main(void){
    
    scanf("%lld %lld %lld", &N, &A, &B);
    map<double, ll> mp;
    for(int i = 0; i < N; ++i){ double v; scanf("%lf", &v); ++mp[v]; }
    
    vector<P> v;
    for(auto m : mp) v.push_back(m);
    sort(v.begin(), v.end(), greater<P>());
    
    int cnt = 0, idx = 0;
    for(int i = 0; i < v.size(); ++i){
        cnt += v[i].second;
        if(A <= cnt){ idx = i; break; }
    }
    
    if(idx == 0){
        ll combi = 0;
        for(int i = A; i <= B; ++i) combi += nCr(v[idx].second, i);
        printf("%f\n%lld\n", v[idx].first, combi);
    }
    else{
        double average = 0;
        ll cnt = 0, combi = 0;
        for(int i = 0; i <= idx; ++i) for(int j = 0; j < v[i].second && cnt < A; ++j) average += v[i].first, ++cnt;
        cnt = 0;
        for(int i = 0; i <= idx - 1; ++i) cnt += v[i].second;
        combi = nCr(v[idx].second, A - cnt);
        printf("%f\n%lld\n", average / A, combi);
    }
    
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (h1, m1, h2, m2, k) = readLine()!!.split(' ').map { it.toInt() }


    val e = h2* 60 + m2
    val s = h1 * 60 + m1
    val l = e-s

    println(l-k)
}


Measured memory_bytes: 36260
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int h, w, n;
  cin >> w >> h >> n;
  int l = 0, r = w, u = h, d = 0;
  for(int i = 0; i < n; i++) {
    int a, x, y;
    cin >> x >> y >> a;
    if(a == 1){
      l = max(l, x);
    }else if(a == 2){
      r = min(r, x);
    }else if(a == 3){
      d = max(d, y);
    }else{
      u = min(u, y);
    }
  }
  //cout << l << " " << r << " " << u << " " << d << endl;
  if(u < d || r < l) {
    cout << 0 << endl;
  } else {
    cout << (r - l) * (u - d) << endl;
  }
    return 0;
}

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

int main(){
int n;cin>>n;
vector<bool> seat(100000,false);
vector<pair<int,int>> v(n);
for(int i=0;i<n;i++){
    cin>>v[i].first;
    cin>>v[i].second;
}
for(int i=0;i<n;i++){
    for(int x=v[i].first-1;x<v[i].second;x++)seat[x]=true;
}
int ans=0;
for(int i=0;i<100000;i++){
    ans+=seat[i];
}
cout<<ans;
}

Measured memory_bytes: 256
loop{

a, op, b = STDIN.gets.split(' ')
a = a.to_i
b = b.to_i

  case op
  when '+' then
    ans = a + b
    puts ans
  when '-' then
    ans = a - b
    puts ans
  when '*' then
    ans = a * b
    puts ans
  when '/' then
    ans = a / b
    puts ans
  else
    break
  end
}

Measured memory_bytes: 8652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e2+7;
const ll mod = 1e9+7;
int n,m;

int arr[maxn][maxn];
int main()
{
    scanf("%d%d", &n, &m);
    int ans=0;
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)scanf("%d", arr[i]+j);
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            ll ins=0;
            for(int k=1;k<=m;k++){
                ins += (arr[i][k] - arr[j][k])*(arr[i][k] - arr[j][k]);
            }
            ll nn = sqrt(ins);
            ans += (nn*nn==ins);
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#define endl "\n"
using namespace std;

const int C = 2600, maks = 2600;
long long x, v, dp[10*C], n;

int main()
{
	ios_base::sync_with_stdio( 0 );
	cin.tie( 0 );
	cin>>n>>v;
	dp[0+C] = 1;
	for( int a = 1; a <= n; a++ )
	{
		cin>>x;
		x -= v;
		if( x >= 0 )
		{
			for( int b = maks; b >= -maks; b-- )
			{
				if( dp[b+C] )dp[b+x+C] += dp[b+C];
			}
		}
		if( x < 0 )
		{
//			cout<<"tu"<<" "<<x<<endl;
			for( int b = -maks; b <= maks; b++ )
			{
				if( dp[b+C] )dp[b+x+C] += dp[b+C];
			}
		}
//		for( int b = C-2; b <= C+2; b++ )cout<<dp[b]<<" ";
//		cout<<endl;
	}
	cout<<dp[C]-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define M 1000000007
#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define what_is(x)  cout << #x << " is " << x << endl;
#define U 1000000007
#define N 100005
using namespace std;
signed main()
{
  ios_base::sync_with_stdio(false);
  int n,k;
  cin>>n>>k;
  int a[n];
  rep(i,0,n) cin>>a[i];
  int dp[n];
  dp[0]=0;
  //dp[1]=abs(a[1]-a[0]);
  rep(i,1,n)
  { 
    int mn=INT_MAX;
    rep(j,1,min(k+1,i+1)) mn=min(dp[i-j]+abs(a[i]-a[i-j]),mn);
    dp[i]=mn;
  }
  //rep(i,0,n) cout<<dp[i]<<" ";
  cout<<dp[n-1];



}

Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

//Spider Jin
public class Main{

	static double[] d;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int[] id = new int[n];
			int[][] p = new int[n][2];
			Map<Integer, Integer> ref = new HashMap<Integer, Integer>();
			for(int i=0;i<n;i++){
				id[i] = sc.nextInt();
				p[i][0] = sc.nextInt();
				p[i][1] = sc.nextInt();
				ref.put(id[i], i);
			}
			double[][] cost = new double[n][n];
			for(int i=0;i<n;i++){
				for(int j=i+1;j<n;j++){
					double r = Math.hypot(p[i][0]-p[j][0], p[i][1]-p[j][1]);
					if(r<=50) cost[i][j] = cost[j][i] = r;
					else cost[i][j] = cost[j][i] = Integer.MAX_VALUE;
				}
			}
			int m = sc.nextInt();
			while(m--!=0){
				int s = ref.get(sc.nextInt());
				int g = ref.get(sc.nextInt());
				int[] pre = new int[1001];
				d = new double[n];
				Arrays.fill(d, Integer.MAX_VALUE);
				d[s] = 0;
				pre[s] = -1;
				PriorityQueue<Integer> q = new PriorityQueue<Integer>(n, new Comparator<Integer>() {
					public int compare(Integer o1, Integer o2) {
						return d[o1]-d[o2]<0?-1:d[o1]-d[o2]>0?1:0;
					}
				});
				q.add(s);
				String ans = "NA";
				while(!q.isEmpty()){
					int v = q.poll();
					if(v==g){
						int ID = v;
						ans = "";
						while(ID!=s){
							ans = " "+id[ID]+ans;
							ID = ref.get(pre[id[ID]]);
						}
						ans = id[s]+ans;
						break;
					}
					for(int i=0;i<n;i++){
						if(cost[v][i]!=Integer.MAX_VALUE){
							double c = d[v] + cost[v][i];
							if(c < d[i]){
								d[i] = c;
								pre[id[i]] = id[v];
								q.add(i);
							}
						}
					}
				}
				System.out.println(ans);
			}
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> min(M);
  vector<int> max(M);
  
  for(int i = 0; i < M; i++){
    cin >> min.at(i);
    cin >> max.at(i);
   }
  
  int Minmax = 0;
  int Maxmin = 1000000;
  
  for(int i = 0; i < M; i++){
    if(min.at(i) - Minmax > 0){
      Minmax = min.at(i);
    }
    
    if(Maxmin - max.at(i) > 0){
      Maxmin = max.at(i);
    }    
   }
  if(Maxmin - Minmax < 0){
    cout << 0 << endl;
  }
  
  else{
  cout << Maxmin - Minmax + 1 << endl;
  }
}

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

int a[10000];
int main() {
  int n;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
 

  
  int min = a[0];
  for(int i=0; i<n; i++){
    if(min>a[i]) {
      min = a[i];
    }
  }
  cout << min << " ";

  int max = a[0];
  for(int i=0; i<n; i++){
    if(max<a[i]){
      max = a[i];
    }
  }
  cout << max << " ";

  long long sum = 0;
    for(int i=0; i<n; i++){
      sum += a[i];
    }
  cout << sum << endl;


}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
typedef long long ll;
int n, k;
int p[maxn], c[maxn];
int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
    for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
    ll ans = -1e18;
    for (int i = 1; i <= n; i++) {
        int t = i;
        vector<int> v;
        ll sum = 0;
//        printf("i = %d : ", i);
        while (1) {
//            printf("%d ", c[p[t]]);
            v.push_back(c[p[t]]), sum += c[p[t]], t = p[t];
            if(t == i) break;
        }
        int tn = v.size();
        if(k <= tn || sum <= 0) {
            ll tmp = 0;
            for (int j = 0, z = 1; z <= k && j < tn; z++, j++)
                tmp += v[j], ans = max(tmp, ans);
        }
        else {
            ll tmp = 0;
            for (int j = 0; j < tn; j++) {
                tmp += v[j];
                ll r = (k - (j + 1)) / tn;
                ans = max(ans, tmp + r * sum);
//                printf("tmp = %lld  r *sum = %lld\n", tmp, r * sum);
            }
        }
//        printf("\n");
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 3880
# ABC116
# C
import numpy as np
N = int(input())
h_list = list(map(int, input().split()))

def shorten(idx_list, current_h):
    for idx in idx_list:
        current_h[idx] -= 1
    return current_h

def get_highest_idx(current_h):
    max_h = np.max(current_h)
    max_flower_idx = []
    for idx, h in enumerate(current_h):
        if h == max_h:
            max_flower_idx.append(idx)
    return max_flower_idx

ans = 0
while(np.max(h_list) > 0):
    highest_idx_list = get_highest_idx(h_list)
    mizunuki_idx = []
    
    for i, idx in enumerate(highest_idx_list):
        hight = h_list[idx]
        if i==len(highest_idx_list)-1:
            break
        else:
            if idx+1 == highest_idx_list[i+1]:
                j = 0
                while(True):
                    try:
                        if idx+j == highest_idx_list[i+j]:
                            j += 1
                        else:
                            break
                    except:
                        break

                mizunuki = np.array(highest_idx_list)[np.arange(i, i+j,1)]
                mizunuki_idx.append(mizunuki)
    if len(mizunuki_idx) == 0:
        mizunuki_ = [highest_idx_list[0]]
    else:
        mizunuki_ = mizunuki_idx[0]
    
    new_h = shorten(mizunuki_, h_list)
    h_list = new_h
    ans += 1
    
print(ans)
    
                    
    


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

int main(){
  int n,j=0;
  cin >> n;
  string s,t;
  cin >> s >> t;
  for(int i=0;i<2*n;i++){
  	if(i%2==0){
      cout << s[j]; 
    } else{
      cout << t[j];
      j++;
    }
  }
 
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

using namespace std;

int f (int x) {
  return x * x;
}


int main() {
  int d;
  while(scanf("%d", &d) != EOF) {
    long long sum = 0;
    for(int i = 1; i*d <= 600 - d; i++) {
      sum = sum + f(i*d) * d;
    }
    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 3168
fn kth_term() -> Result<i32, & 'static str> {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input)
        .map_err(|_| "input error")?;
    let k = input.trim_right().parse::<usize>().unwrap();
    let list = [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];

    Ok(list[k -1])
}

fn main() {
    println!("{}", kth_term().unwrap());
}

Measured memory_bytes: 4352
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
typedef double d;
typedef int i;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    char a , b;
    cin >> a >> b;
    int c , d;
    if ( a == 'D' ) c = -1;
    else c = 1;
    if ( b == 'D' ) d = -1;
    else d = 1;
    if ( c * d == 1 ) cout << 'H';
    else cout << 'D';
}

Measured memory_bytes: 256
while True:
   a, op, b = input().split()
   a = int(a)
   b = int(b)
   if op == "+":
	   print(a + b)
   elif op == "-":
	   print(a - b)
   elif op == "*":
	   print(a * b)
   elif op == "/":
	   print(a // b)
   elif op == "?":
   	   break

Measured memory_bytes: 7648
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void) {
	int N;
	cin >> N;
	string str;
	cin >> str;
	int res = 0;
	for (int i = 1; i < str.length(); ++i){
		string ss1 = str.substr(0,i);
		string ss2 = str.substr(i,str.length()-i);
		vector<bool> alpha1('z'-'a',false);
		vector<bool> alpha2('z'-'a',false);
		for (int j = 0; j < ss1.length(); ++j) {
			alpha1[ss1[j]-'a'] = true;
		}
		for (int j = 0; j < ss2.length(); ++j) {
			alpha2[ss2[j]-'a'] = true;
		}
		int now = 0;
		for (int j = 0; j < 'z'-'a'+1; ++j) {
			if (alpha1[j] && alpha2[j]) {
				++now;
			}
		}
		res = max(res,now);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
deque<int> deq;
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

#define MOD 1000000007

char cl[5] = {'x','A','C','G','T'};

int n;
int dp[5][5][5][101];

int f(char c, char a, char b, int d){
	if(d==n)return 1;
	if(dp[c][a][b][d]!=-1)return dp[c][a][b][d];
	int sum = 0;
	for(int i = 1;i < 5;i++){
		if(cl[a] == 'A' && cl[b] == 'G' && cl[i] == 'C')continue;
		if(cl[a] == 'A' && cl[b] == 'C' && cl[i] == 'G')continue;
		if(cl[a] == 'G' && cl[b] == 'A' && cl[i] == 'C')continue;
		if(cl[c] == 'A' && cl[a] == 'G' && cl[b] == 'G' && cl[i] == 'C')continue;
		if(cl[c] == 'A' && cl[a] == 'T' && cl[b] == 'G' && cl[i] == 'C')continue;
		if(cl[c] == 'A' && cl[a] == 'G' && cl[b] == 'T' && cl[i] == 'C')continue;
		sum += f(a, b, i, d+1);
		sum %= MOD;
	}
	return dp[c][a][b][d] = sum;
}

int main(){
	cin >> n;
	fill_n(***dp,5*5*5*101,-1);//初期化
	cout << f(0, 0, 0, 0) << endl;

	return 0;
}


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


int main(){
  ll n,k;
  cin>>n>>k;
  vector<ll>a(n);
  rep(i,n)cin>>a[i];
  sort(a.begin(),a.end());
  ll l=-INF,r=INF;
  while(l+1<r){
    ll x=(l+r)/2;
    bool ok=[&]{
      ll tot=0;
      rep(i,n){
	if(a[i]<0){
	  int l=-1,r=n;
	  while(l+1<r){
	    int c=(l+r)/2;
	    if(a[c]*a[i]<x)r=c;else l=c;
	  }
	  tot+=n-r;
	}else{
	  int l=-1,r=n;
	  while(1+l<r){
	    int c=(l+r)/2;
	    if(a[c]*a[i]<x)l=c;else r=c;
	  }
	  tot+=r;
	}
	if(a[i]*a[i]<x)tot--;
      }tot/=2;
      return tot<k;
    }();
    if(ok)l=x;else r=x;
  }
  cout << l << endl;

  return 0;
}


Measured memory_bytes: 1792
// -*- mode:c++; coding:utf-8; indent-tabs-mode:nil; -*-
// ALDS1_3-D: Areas on the Cross-Section Diagram

#include <algorithm>
#include <iostream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef unsigned int uint;

struct area {
  uint from_;
  uint area_;
  area(const uint from, const uint to) : from_(from), area_(to-from) {}
};
                     
static stack<area> prepare_areas(const string str) {
  stack<area> areas;
  stack<uint> s;
  for (auto i = 0u; i < str.size(); ++i) {
    auto c = str[i];
    if (c == '\\') {
      s.push(i);
    } else if (c == '/') {
      if (!s.empty()) {
        areas.push(area(s.top(), i));
        s.pop();
      }
    } else {
      // nop
    }
  }
  return move(areas);
}

static pair<uint, vector<uint>> accumulate_areas(stack<area> areas) {
  uint sum = 0u;
  vector<uint> accs;
  while (!areas.empty()) {
    auto p = areas.top();
    areas.pop();
    auto acc = p.area_;
    while (!areas.empty() && p.from_ < areas.top().from_) {
      acc += areas.top().area_;
      areas.pop();
    }
    sum += acc;
    accs.push_back(acc);
  }
  reverse(accs.begin(), accs.end());
  return move(make_pair(sum, accs));
}

int main(void) {
  string str;
  getline(cin, str);
  auto areas = prepare_areas(move(str));

  auto sum_accs = accumulate_areas(move(areas));
  auto sum = sum_accs.first;
  auto accs = sum_accs.second;

  cout << sum << endl;
  cout << accs.size();
  for (auto acc : accs) {
    cout << " " << acc;
  }
  cout << endl;

  return 0;
}
// end

Measured memory_bytes: 3284