akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

void dfs(int node, int d, vector<int> &dist, vector<vector<int> > &edge){
    if(dist[node]!=MOD){
        return;
    }
    dist[node]=d;

    for(auto x:edge[node]){
        dfs(x,d+1,dist,edge);
    }
}

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

int main(){
    int N;
    cin >> N;
    vector<vector<int> > edge(N,vector<int>(0));
    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        a--;b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    vector<int> dist(N,(int)MOD);

    dfs(0, 0, dist, edge);
    vector<int> odd(0);
    vector<int> even(0);
    for(int i=0; i<N; i++){
        if(dist[i]%2){
            odd.push_back(i);
        }else{
            even.push_back(i);
        }
    }
    if((int)odd.size()<(int)even.size()){
        swap(odd,even);
    }

    vector<int> ans(N,0);

    if((int)odd.size()>2*(N/3)+(N%3>0)){
        int k=3;
        for(auto x:even){
            ans[x]=k;
            k+=3;
        }
        int j=1;
        for(auto y:odd){
            if(k<=N){
                ans[y]=k;
                k+=3;
            }else{
                if(j>N){
                    j=2;
                }
                ans[y]=j;
                j+=3;
            }
        }
    }else{
        int k=1;
        int j=3;
        
        for(auto x:odd){
            if(k<=N){
                ans[x]=k;
                k+=3;
            }else{
                ans[x]=j;
                j+=3;
            }
        }
        k=2;
        for(auto y:even){
            if(k<=N){
                ans[y]=k;
                k+=3;
            }else{
                ans[y]=j;
                j+=3;
            }
        }
    }
    cout_vec(ans);
}

Measured memory_bytes: 18676
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 105;
const int mod = 1000000007;

int x[maxn],y[maxn];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
 int n,m;
 cin>>n>>m;
 for(int i=0;i<m;i++)cin>>x[i]>>y[i];
 for(int i=0;i<1000;i++){
   vector<int>tt;
   if(!i)tt.push_back(0);
   else {
     int tmp = i;
     while(tmp){
       tt.push_back(tmp%10);
       tmp/=10;
     }
   }
   if(tt.size()!=n)continue;
   reverse(tt.begin(), tt.end());
   bool sign = 0;
   for(int j=0;j<m;j++){
     if(tt[x[j]-1]!=y[j]){
       sign=1;
       break;
     }
   }
   if(!sign){
    cout<<i<<endl;
    return 0;
   }
 }
 cout<<-1<<endl;
 return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int a = sc.nextInt();
	        int b = sc.nextInt();
	        System.out.println(gcd(a,b));
		}
	}
	
	public static int gcd(int x, int y) {
		if (y%x == 0) {
			return x;
		}
		return gcd(y%x, x);
		//return (x==0)?y:gcd(y%x,x);
	}

}



Measured memory_bytes: 26188
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    return buf
}

fn main() {
    let line = gets();
    let mut flag = true;
    for (a, b) in line.trim().chars().zip(line.trim().chars().rev()) {
        if a != b {
            flag = false;
            break;
        }
    }
    if flag {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;
 
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int main() {
	int x, a, b;
	cin >> x >> a >> b;
	cout << (x - a) % b << endl;
}


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

int a,b;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>a>>b;
    if(a<10&&b<10){
        cout<<a*b<<endl;
    }else{
        cout<<-1<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
n = int(input())
pn = [int(i) for i in input().split()]
ans = 0

for i in range(1,n-1):
  if pn[i-1] > pn[i] > pn[i+1] or pn[i-1] < pn[i] < pn[i+1]:
    ans += 1

print(ans)

Measured memory_bytes: 3060
V, E, r = map(int, raw_input().split())
es = [map(int, raw_input().split()) for i in xrange(E)]

def solve(V, es, r):
    mins = [(10**18, -1)]*V
    for s, t, w in es:
        mins[t] = min(mins[t], (w, s))
    mins[r] = (-1, -1)

    group = [0]*V
    comp = [0]*V
    cnt = 0

    used = [0]*V
    for v in xrange(V):
        if not used[v]:
            chain = []
            cur = v
            while not used[cur] and cur!=-1:
                chain.append(cur)
                used[cur] = 1
                cur = mins[cur][1]
            if cur!=-1:
                cycle = 0
                for e in chain:
                    group[e] = cnt
                    if e==cur:
                        cycle = 1
                        comp[cnt] = 1
                    if not cycle:
                        cnt += 1
                if cycle:
                    cnt += 1
            else:
                for e in chain:
                    group[e] = cnt
                    cnt += 1


    if cnt == V:
        return sum(map(lambda x:x[0], mins)) + 1

    res = sum(comp[group[v]]*mins[v][0] for v in xrange(V) if v!=r)

    n_es = []
    for s, t, w in es:
        gs = group[s]; gt = group[t]
        if gs == gt:
            continue
        if comp[gt]:
            n_es.append((gs, gt, w - mins[t][0]))
        else:
            n_es.append((gs, gt, w))

    return res + solve(cnt, n_es, group[r])

print solve(V, es, r)

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

int n,k,a[10];
string s,t;

int main() {
  cin >> s;
  cout << (s.substr(0,4)=="YAKI" ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int dp[6005][2005],ans,n,M;
void add(int &x,int y){
    x+=y;if (x>=M)x-=M;
}

int main(){
    cin >> n >> M;
    dp[n*3][0]=1;
    for (int i=n*3;i;i--)
    for (int j=0;j<=n;j++){
        add(dp[i-1][j],dp[i][j]);
        if (i>=2&&j<n) add(dp[i-2][j+1],1ll*dp[i][j]*(i-1)%M);
        if (i>=3&&j<n) add(dp[i-3][j+1],1ll*dp[i][j]*(i-1)*(i-2)%M);
    }
    for (int i=0;i<=n;i++) add(ans,dp[0][i]);
    cout << ans << endl;
}



Measured memory_bytes: 47232
N,A = map(int,input().split())
X = list(map(int,input().split()))

Xp = [0]
Xm = [0]
Xz = 0
for x in X:
    if x-A > 0:
        Xp.append(x-A)
    elif x-A < 0:
        Xm.append(x-A)
    else:
        Xz += 1

DPp = [[0 for j in range(2501)] for i in range(len(Xp))]
DPm = [[0 for j in range(2501)] for i in range(len(Xm))]

DPp[0][0] = 1
DPm[0][0] = 1

for i in range(1,len(DPp)):
    x = Xp[i]
    for j in range(2501):
        if j >= x:
            DPp[i][j] = DPp[i-1][j] + DPp[i-1][j-x]
        else:
            DPp[i][j] = DPp[i-1][j]

for i in range(1,len(DPm)):
    x = -Xm[i]
    for j in range(2501):
        if j >= x:
            DPm[i][j] = DPm[i-1][j] + DPm[i-1][j-x]
        else:
            DPm[i][j] = DPm[i-1][j]

ans = 1

for j in range(1,2501):
    ans += DPp[len(DPp)-1][j]*DPm[len(DPm)-1][j]
ans = ans*pow(2,Xz) - 1
print(ans)


Measured memory_bytes: 41328
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	var odd, even2, even4 int
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
		if a[i]%4 == 0 {
			even4++
		} else if a[i]%2 == 0 {
			even2++
		}
	}
	odd = n - (even4 + even2)
	// fmt.Println("n", n, "e4", even4, "e2", even2, "odd", odd)
	if n-(even4) <= even4+1 || odd == even4 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <boost/math/constants/constants.hpp>

using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)

int main(){
  int N;
  cin >> N;
  int c=0;
  
  rep(i, N+1){
    if((i>=1)&&(i<10)) c++;
    if((i>=100)&&(i<1000)) c++;
    if((i>=10000)&&(i<100000)) c++;
  }
  cout << c << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a, b;
  cin >> a >> b;

  if (a < b)
  {
  	cout << "a < b"<< endl;
  }

  else if (a > b)
  {
  	cout << "a > b" << endl;
  }
  else 
  {
  	cout << "a == b" << endl;
  }

}


Measured memory_bytes: 3136
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	int n;

	cin >> n;

	int minn = 9999999999, maxn = -99999999;

	for (int i = 0; i < n; i++) {
		int num;
		cin >> num;
		minn = min(minn, num);
		maxn = max(maxn, num);
	}

	cout << abs(maxn - minn) << endl;




	return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

#[allow(unused_macros)]
macro_rules ! min {($ a : expr $ (, ) * ) => {{$ a } } ; ($ a : expr , $ b : expr , $ (, ) * ) => {{std :: cmp :: min ($ a , $ b ) } } ; ($ a : expr , $ ($ rest : expr ) ,+ $ (, ) * ) => {{std :: cmp :: min ($ a , min ! ($ ($ rest ) ,+ ) ) } } ; }
#[allow(unused_macros)]
macro_rules ! chmin {($ base : expr , $ ($ cmps : expr ) ,+ $ (, ) * ) => {{let cmp_min = min ! ($ ($ cmps ) ,+ ) ; if $ base > cmp_min {$ base = cmp_min ; true } else {false } } } ; }

fn solve(a: &Vec<Vec<i64>>) -> i64 {
    let n = a.len();

    let mut dist = a.clone();
    for k in 0..n {
        for i in 0..n {
            for j in 0..n {
                chmin!(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    for i in 0..n {
        for j in 0..n {
            if a[i][j] > dist[i][j] {
                return -1;
            }
        }
    }

    let mut ret = 0;
    for i in 0..n {
        for j in i + 1..n {
            let mut dmin = std::i64::MAX;
            for k in 0..n {
                if k == i || k == j {
                    continue;
                }
                chmin!(dmin, a[i][k] + a[k][j]);
            }
            if a[i][j] < dmin {
                ret += a[i][j];
            }
        }
    }
    ret
}

fn main() {
    input! {
        n: usize,
        a: [[i64; n]; n],
    }
    println!("{}", solve(&a));

}


Measured memory_bytes: 3384
from heapq import heapify, heappop, heappush


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

A.sort(reverse=True)

heap = []
heapify(heap)

val = 0
heappush(heap, -A[1])
val += A[0]

for i, a in enumerate(A[2:]):
    n = heappop(heap)
    val += -n

    if i == 0:
        heappush(heap, n)

    heappush(heap, -a)
    heappush(heap, -a)


print(val)



Measured memory_bytes: 31692
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <bitset>
#include <limits>
typedef unsigned long long int ll;
const ll INF = 876543210987654321;
const int MOD = 1000000007;
#define REP(i,n) for(int i=0;i<n;++i)
#define pd(x) cout<<x<<endl

using namespace std;

//vector<vector<int>>(h, vector<int>(w, f));
vector<int> u;
int main() {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	ll n,ans=0,a;
	cin >> n;
	vector<ll>A(n);
	REP(i, n) {
		cin >> a;
		A[i] = a-1;
	}
	ll tmp;
	REP(i, n-1) {
		if (A[i] == i) {
			tmp = A[i];
			A[i] = A[i + 1];
			A[i + 1] = tmp;
			ans++;
		}
	}
	if (A[n - 1] == n - 1)ans++;
	cout << ans;
	cin >> a;
	return 0;


}

Measured memory_bytes: 1024
import sys
import collections
sys.setrecursionlimit(4100000)

n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

ans = sum(b)
for i in range(1,len(a)):
    if a[i] - a[i-1] == 1:
        ans += c[a[i]-2]
print(ans)

Measured memory_bytes: 3564
#include<iostream>
using namespace std;
int main(){
	int a[10],i,j,highest=0,higher=0,higher2=0;
	for(i=0;i<10;i++){
		cin>>a[i];
	}
	for(i=0;i<10;i++){
		if(a[i]>highest){
			highest=a[i];
		}
	}
	cout<<highest<<endl;
	for(j=0;j<10;j++){
		if(highest==a[j]){
			a[j]=0;
			break;
		}
	}
	for(i=0;i<10;i++){
		if(a[i]>higher2){
			higher2=a[i];
		}
	}
	cout<<higher2<<endl;
	for(j=0;j<10;j++){
		if(higher2==a[j]){
			a[j]=0;
			break;
		}
	}
	for(i=0;i<10;i++){
		if(a[i]>higher){
			higher=a[i];
		}
	}
	cout<<higher<<endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n; cin >> n;
    vector<int> v(n*2); cin >> v;
    sort(ALL(v), greater<int>());
    ll ans = 0;
    REP(i, n) {
        ans += min(v[i*2], v[i*2+1]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 998244353;

ll H, N, ans = 10000000000;
vector<ll> A(1010), B(1010);
vector<ll> memo(10010, -1);

ll solve(ll h)
{
    if (memo.at(h) != -1)
    {
        return memo.at(h);
    }
    ll res = 1000000000;
    rep(0, i, N)
    {
        if (h - A.at(i) < 0)
        {
            res = min(res, solve(0) + B.at(i));
        }
        else
        {
            res = min(res, solve(h - A.at(i)) + B.at(i));
        }
    }
    return memo.at(h) = res;
}

int main()
{
    cin >> H >> N;
    rep(0, i, N)
    {
        cin >> A.at(i) >> B.at(i);
    }
    memo.at(0) = 0;
    cout << solve(H) << endl;
}

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

int main() {
	string s;
	cin >> s;
	int ans = 700;
	if (s[0] == 'o') ans += 100;
	if (s[1] == 'o') ans += 100;
	if (s[2] == 'o') ans += 100;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int mo[4][2]={1,0,-1,0,0,1,0,-1};
int vis[1005][1005]={0},vis2[1005][1005]={0},c[1005][1005]={0};
char s[1005][1005];
struct node{
    int x,y;
};
int n,m,s1,e1,s2,e2;
int bfs(){
    queue<node>q1,q2;
    node a,b;
    a.x=s1,a.y=e1;
    vis[a.x][a.y]=1;
    q1.push(a);
    while(!q1.empty()||!q2.empty()){
            //cout<<123<<endl;
        while(!q1.empty()){
            a=q1.front();
            //cout<<a.x<<a.y<<endl;
            q1.pop();
            if(a.x==s2&&a.y==e2){
                return c[a.x][a.y];
            }
            for(int i=0;i<4;i++){
                b.x=a.x+mo[i][0],b.y=a.y+mo[i][1];
                int flag=0;
                if(!vis[b.x][b.y]&&b.x>=0&&b.x<n&&b.y>=0&&b.y<m&&s[b.x][b.y]!='#'){
                    //cout<<b.x<<b.y<<endl;
                    flag=1;
                    vis[b.x][b.y]=1;
                    c[b.x][b.y]=c[a.x][a.y];
                    q1.push(b);
                }
                if(!flag) q2.push(a);
            }
        }
        while(!q2.empty()){
            a=q2.front();
            q2.pop();
            for(int i=-2;i<=2;i++){
                for(int j=-2;j<=2;j++){
                    if(abs(i)+abs(j)>=2){
                        b.x=a.x+i,b.y=a.y+j;
                        if(!vis[b.x][b.y]&&b.x>=0&&b.x<n&&b.y>=0&&b.y<m&&s[b.x][b.y]!='#'){
                            vis[b.x][b.y]=1;
                            c[b.x][b.y]=c[a.x][a.y]+1;
                            //cout<<b.x<<b.y<<endl;
                            q1.push(b);
                        }
                    }
                }
            }
        }
    }
    return -1;
}
int main(){
    cin>>n>>m>>s1>>e1>>s2>>e2;
    s1--,s2--,e1--,e2--;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>s[i][j];
        }
    }
    cout<<bfs();
}
/*
4 4
1 1
4 4
....
..#.
.#..
....
*/


Measured memory_bytes: 12672
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
 
int main() {
  string s,t;
  cin >> s >> t;
  int count = 0;
  if(s[0] == t[0]) count++;
  if(s[1] == t[1]) count++;
  if(s[2] == t[2]) count++;
  cout << count << endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    if(s.endsWith("s")){
      System.out.println(s+"es");
    }
    else{
      System.out.println(s+"s");
    }
  }
}

Measured memory_bytes: 26976
R,G,B,N = map(int,input().split())
ans = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        if N < r*R+g*G:
            continue
        if (N-(r*R+g*G)) % B == 0:
            ans += 1
print(ans)

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

#define IOS cin.tie(0);ios::sync_with_stdio(0)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template <class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?' ':'\n'); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);}//最小公倍数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//void print(){}

//----------------------library------------------------//

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

const int NMAX = 200;
bool flag;

bool comp(int x,int y){
    return abs(0-x)<abs(0-y);
}

signed main(){
//    IOS;
    CIN(N,M);
    map<int,int> mp;
    rep(i,N){
        int k;cin>>k;
        rep(i,k){
            int A;cin>>A;
            mp[A]++;
        }
    }
    int ans=0;
    RepA(mp){
        if(item.second==N) ans++;
    }
    printf("%d\n",ans);
    
    return 0;
}

Measured memory_bytes: 256
Num=int(input())
String=input()
Library=[['A',1],['B',2],['C',3],['D',4],['E',5],['F',6],['G',7],['H',8],['I',9],['J',10],['K',11],['L',12],['M',13],['N',14],['O',15],['P',16],['Q',17],['R',18],['S',19],['T',20],['U',21],['V',22],['W',23],['X',24],['Y',25],['Z',26]]
newstring=''
for i in String:
    for j in range(0,26):
        if i==Library[j][0]:
            oldstring=newstring
            newstring=oldstring+Library[(j+Num)%26][0]
print(newstring)

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

int main() {
	int N, M,ans=0;
	cin >> N >> M;
	vector<int> cnt(M, 0);
	for (int i = 0; i <N; i++) {
		int K;
		cin >> K;
		for (int j = 0; j < K; j++) {
			int A;
			cin >> A;
			A--;
			cnt[A]++;
		}
	}
	for (int i = 0; i <M; i++) {
		if (cnt[i] == N)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
int main(void){
    int N,C;cin>>N>>C;
    int D[C][C],c[3][31];
    rep(i,3)rep(j,31)c[i][j]=0;
    rep(i,C)rep(j,C) cin>>D[i][j];
    rep(i,N)rep(j,N){
        int x;cin>>x;
        c[(i+j)%3][x-1]++;
    }
    int res=1e+9+1;
    rep(i,C)rep(j,C)rep(k,C){
        if(i==j||j==k||i==k)continue;
        int tot=0;
        rep(l,C) tot+=D[l][i]*c[0][l];
        rep(l,C) tot+=D[l][j]*c[1][l];
        rep(l,C) tot+=D[l][k]*c[2][l];
        res=min(res,tot);
    }
    cout<<res<<endl;
} 


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define repi(i,a,b) for(int i = (a); i<= (b); i++)
#define repA(i,n) for(int i=n; i>=0; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (int)(a.size())

typedef long long ll;
typedef long double ld;
const ll mod = 998244353;//1e9+7

vector<int> cnt[201],sp;

void pre() {

}

void solve() {
  int n,k;  cin>>n>>k;
  vector<int> a(n);
  rep(i,n)  cin>>a[i];
  sort(all(a));
  int ans = 0;
  rep(i,k)  ans+=a[i];
  cout<<ans;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  #endif
  int t = 1;
  pre();
  //cin>>t;
  rep(i,t)  {
    solve();
    cout<<'\n';
  }
  return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

const int nmax=40, abmax=10, inf=10000000;
int N,Ma,Mb;
int a[50],b[50],c[50];
int dp[50][1000][1000];

int solve(){
  cin >> N >>Ma>>Mb;
  REP(i,N){ cin >> a[i] >> b[i] >> c[i];}
  
  REP(i,N+1){
    REP(ca,nmax*abmax+1){
      REP(cb, nmax*abmax+1){
        dp[i][ca][cb] = inf;
      }
    }
  }
  
  dp[0][0][0]=0;
  REP(i,N){
    REP(ca,nmax*abmax+1){
      REP(cb, nmax*abmax+1){
        if(dp[i][ca][cb] == inf){continue;}
        dp[i+1][ca][cb] = min( dp[i+1][ca][cb], dp[i][ca][cb] );
        dp[i+1][ca + a[i]][cb + b[i]] = min( dp[i+1][ca + a[i]][cb + b[i]], dp[i][ca][cb] + c[i] );
      }
    }
  }
  
  int ans = inf;
  for(int ca=1; ca<=nmax*abmax; ++ca){
    for(int cb=1; cb<=nmax*abmax; ++cb){
      if(Ma*cb==Mb*ca){ ans = min(ans,dp[N][ca][cb]); }
    }
  }
  if(ans==inf){ ans = -1;}
  return ans;
}

int main(){
  cout << solve() <<"\n";
}

Measured memory_bytes: 151296
import sys
from collections import defaultdict
N, K = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))

T = defaultdict(int)

key_town = 0
count = 0

if K < 3 * (10 ** 5):
    ans = 1
    for k in range(K):
        ans = A[ans]
    print(ans)
    sys.exit(0)


T[1] = 1

now = 1
for i in range(1, len(A)):
    now = A[now]
    if T[now] == 0:
        T[now] = i + 1
    else:
        key_town = now
        count = i - T[now] + 1
        break

if count == 0:
    print(key_town)
    sys.exit(0)

k = (K - T[key_town]+1) % count

ans = key_town
for i in range(k):
    ans = A[ans]
print(ans)


Measured memory_bytes: 107604
#include<stdio.h>
int main()
{
  int i,n,j,min,cnt=0;
  char temp,a[36][3],b[36][3],c[3];
    
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",c);
    a[i][0]=b[i][0]=c[0];
    a[i][1]=b[i][1]=c[1];
  }
  for(i=0;i<n;i++){
    for(j=0;j<n-1-i;j++){
      if(a[j][1]-a[j+1][1]>0){
	temp=a[j][1];
	a[j][1]=a[j+1][1];
	a[j+1][1]=temp;
 
	temp=a[j][0];
	a[j][0]=a[j+1][0];
	a[j+1][0]=temp;
      }
    }
  }
 
  for(i=0;i<n;i++){
    min=i;
    for(j=i;j<n;j++){
      if(b[j][1]-b[min][1]<0){
	min=j;
      }
    }
    temp=b[i][1];
    b[i][1]=b[min][1];
    b[min][1]=temp;
    temp=b[i][0];
    b[i][0]=b[min][0];
    b[min][0]=temp;
  }
 
  for(i=0;i<n;i++){
    if(i!=n-1){
      printf("%c%c ",a[i][0],a[i][1]);
    }
    else
      printf("%c%c\n",a[i][0],a[i][1]);
  }
 
  printf("Stable\n");
 
  for(i=0;i<n;i++){
      if(i!=n-1){
	printf("%c%c ",b[i][0],b[i][1]);
      }
      else
	printf("%c%c\n",b[i][0],b[i][1]);
 
      if(a[i][0]==b[i][0]){
	cnt++;
      }
    }
 
  if(cnt!=n){
    printf("Not stable\n");
  }
  else
    printf("Stable\n");
  return 0;
}

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

int main()
{
  int64_t N, X, ans = 0;
  cin >> N >> X;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  for (int i = 0; i < N - 1; i++)
  {
    if (A.at(i) + A.at(i + 1) > X)
    {
      int64_t diff = A.at(i) + A.at(i + 1) - X;
      ans += diff;
      if (A.at(i + 1) >= diff)
      {
        A.at(i + 1) -= diff;
      }
      else
      {
        A.at(i + 1) = 0;
        A.at(i) -= (diff - A.at(i + 1));
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
N = int(input())
B = list(map(int,input().split()))

ans = []
while N > 0:
  ok = False
  for i in range(N)[::-1]:
    b = B[i]
    if b == (i+1):
      ans.append(b)
      ok = True
      k = i
      break
  
  if not ok:
    break
  else:
    newB = []
    for i in range(N):
      if i != k:
        newB.append(B[i])
    
    B = newB
    N -= 1

if N != 0:
  print(-1)
else:
  print("\n".join(map(str,ans[::-1])))


Measured memory_bytes: 9152
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
typedef long long LL;
const int e[40]={0,1,1,2,2,2,3,3,3,3,4,4,4,4,4,5,5,5,5,5,
               5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8};
const LL UnUseMethod=11e11;
LL count[2]={0};
LL IN(void)
{
  LL x=0;short f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
LL GCD(LL a,LL b){return !b?a:GCD(b,a%b);}
LL Mult(LL x,LL y,LL mod)
{LL temp=x*y-(LL)((long double)x/mod*y+1e-8)*mod;return temp<0?temp+mod:temp;}
LL BinaryModularPower(LL base,LL pow,LL mod)
{
  LL x=1;
  while(pow){if(pow&1){x=Mult(x,base,mod);}base=Mult(base,base,mod);pow>>=1;}
  return x;
}
LL f(LL x,LL mod,LL c){return (Mult(x,x,mod)+c)%x+1;}
void Exp(LL x,LL y){count[1]=0;while(!(x%y)){count[1]++;x/=y;}count[0]=x;return;}
int MillerRabin(const LL a)
{
  if(a==2)return 1;
  if(a%2==0||a==1)return 0;
  static int pr[7]={2,325,9375,28178,450775,9780504,1795265022};
  LL u=a-1,t=0,p=1;
  while(!(u&1)){u>>=1;t++;}
  for(int i=0;i<7;++i)
  {
    p=pr[i]%a;
    if(!p)return 1;
    LL x=BinaryModularPower(p,u,a);
    if(x==1)continue;
    for(int j=0;x!=a-1&&j<t;++j)
    {
      x=Mult(x,x,a);
      if(x==1)return 0;
    }
    if(x==a-1)continue;
    return 0;
  }
  return 1;
}
LL PollardRho(LL n,LL a)
{
  srand((unsigned int)time(NULL));
  LL x=rand()%n,y=x,gcd=1,k=0,i=1;
  while(gcd==1)
  {
    k++;
    x=Mult(x,x,n)+a;if(x>=n)x-=n;
    gcd=GCD(x>y?x-y:y-x,n);
    if(k==i){y=x;i<<=1;}
  }
  if(gcd==n)return PollardRho(n,a+1);
  return gcd;
}
int main(void)
{
  LL a=0,p=1,q=-1,N=IN();
  if(N<=1)return puts("0"),0;
  Exp(N,2);a=e[count[1]];N=count[0];
  Exp(N,3);a+=e[count[1]];N=count[0];
  while(q*q<=UnUseMethod)
  {
    p+=6,q+=6;
    Exp(N,p);a+=e[count[1]];N=count[0];
    Exp(N,q);a+=e[count[1]];N=count[0];
  }
  if(N<=UnUseMethod){if(N>1){a++;}return printf("%lld\n",a),0;}
  if(MillerRabin(N)){a++;return printf("%lld\n",a),0;}
  while(N>=UnUseMethod)
  {
    p=PollardRho(N,0);
    while(!MillerRabin(p))p=PollardRho(p,p);
    Exp(N,p);a+=e[count[1]];N=count[0];
  }
  if(MillerRabin(N)){a++;}return printf("%lld\n",a),0;
}

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

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

    int ans;
    if (a + b <= a + c) {
        if (a + b <= b + c) {
            ans = a + b;
        }
        else {
            ans = b + c;
        }
    }
    else {
        if (a + c <= b + c) {
            ans = a + c;
        }
        else {
            ans = b + c;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 210000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
string str[110];
char in[110];
int p[110];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%s",in);
		int t;scanf("%d",&t);
		str[i]=in;
		p[i]=t;
	}
	scanf("%s",in);
	string tmp=in;
	int ret=0;
	for(int i=0;i<a;i++){
		if(str[i]==tmp){
			for(int j=i+1;j<a;j++){
				ret+=p[j];
			}
		}
	}printf("%d\n",ret);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
  int n;cin >>n;
  ll M=0,m=INF;
  for(int i = 0; i < n; ++i){
    ll a;cin >>a;
    M=max(M,a);
    m=min(m,a);
  }
  cout << M-m<< endl;
}


Measured memory_bytes: 256
#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=1000000007,MAX=505,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,A,B;cin>>N>>A>>B;
    B--;
    int ans=0;
    for(int i=0;i<N;i++){
        int a;cin>>a;
        if(a<A||B<a) ans++;
    }
    cout<<ans<<endl;
}



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

int main()
{
	int A, B, M;

	cin >> A >> B;
	M = A + B;

	if (M < 24)
		cout << M;
	else if (M > 24)
		cout << M - 24;
	else if (M == 24)
		cout << 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef int Int;
typedef pair<Int,Int> pii;
typedef pair<Int,double> pid;
typedef pair<double,double> pdd;
typedef pair<Int,pii> pip;
typedef pair<double,Int> pdp;
#define A first
#define B second
#define pb(x) push_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (x).size()
#define CLR(x) memset(x,0,sizeof x)
#define pdebug() printf("%d\n",__LINE__)
#define Itype(a) typeof(a.begin()) 
#define REP(i,a,b) for(int i = (a);i <= (b);i++)
#define FORO(i,n) REP(i,0,(int)n-1)
#define FORI(i,n) REP(i,1,(int)n)
#define FORIT(i,t) for(Itype(t) i = t.begin();i != t.end();i++)
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define dist(_a,_b) sqrt(sqr(_a.A-_b.A)+sqr(_a.B-_b.B))
#define norm(_a) sqrt(sqr(_a.A)+sqr(_a.B))
template<typename T>void getMin(T &a,T b) { if(a > b) a = b; }
template<typename T>void getMax(T &a,T b) { if(a < b) a = b; }
const int MOD = 1000000007;

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

    int R, G, B, N;
    cin >> R >> G >> B >> N;
    
    int ans = 0;
    for(int r = 0;r * R <= N;r++) {
        for(int g = 0;r * R + g * G <= N;g++) {
            if((N - R * r - g * G) % B == 0) ans++;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define FOR(i, x, n) for(ll i = x; i < n; i++) 
#define pb push_back
#define pf push_front
#define ll long long
#define hii cout << "hii" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
#define int ll
#define mpp make_pair
#define endl '\n'
#define ff first 
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()

const int N = 1e5 + 5;
double arr[N];

int solve()
{
	int n;
	cin >> n;
	n--;
	cout << (n * (n + 1)) / 2;
}

int32_t main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt", "r", stdin);
 //    freopen("output.txt", "w", stdout);
	// #endif
	solve();
	return 0;
}          

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

using namespace std;

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

	bool isOK = true;
	for (int i = 0; i < S.size(); i++){
		if(S[i] != T[i]){
			isOK = false;
		}
	}

	cout << (isOK ? "Yes" : "No") << endl;
	return 0;
}


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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c)  (c).begin(),(c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#define SORT(c) sort((c).begin(),(c).end())

// repetition
// -----------------------------------------------------------------------------
#define FOR(i, a, b) for(ll i= (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
// -----------------------------------------------------------------------------
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x)  cerr << #x << " = " << (x) << endl


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int N; cin >> N;
    int ans = 1;
    while (ans * 2 <= N)
    {
        ans *= 2;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3648
#include <stdio.h>

int main(void) {
	double x[3],y[3],xp,yp;
	double temp;
	double xkeisuu[2],teisuu[2];
	int ok;
	while(!feof(stdin)) {
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf",
			&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&xp,&yp);
		if(feof(stdin))break;
		if(x[0]>x[1]) {
			temp=x[0];x[0]=x[1];x[1]=temp;
			temp=y[0];y[0]=y[1];y[1]=temp;
		}
		if(x[1]>x[2]) {
			temp=x[1];x[1]=x[2];x[2]=temp;
			temp=y[1];y[1]=y[2];y[2]=temp;
		}
		if(x[0]>x[1]) {
			temp=x[0];x[0]=x[1];x[1]=temp;
			temp=y[0];y[0]=y[1];y[1]=temp;
		}
		ok=0;
		if(xp>x[0] && xp<x[2]) {
			if(xp<x[1]) {
				xkeisuu[0]=(y[0]-y[1])/(x[0]-x[1]);
				teisuu[0]=y[0]-x[0]*xkeisuu[0];
				xkeisuu[1]=(y[0]-y[2])/(x[0]-x[2]);
				teisuu[1]=y[0]-x[0]*xkeisuu[1];
				if(xkeisuu[0]>xkeisuu[1]) {
					temp=xkeisuu[0];xkeisuu[0]=xkeisuu[1];xkeisuu[1]=temp;
					temp=teisuu[0];teisuu[0]=teisuu[1];teisuu[1]=temp;
				}
			} else if(xp>=x[1]) {
				xkeisuu[0]=(y[0]-y[2])/(x[0]-x[2]);
				teisuu[0]=y[2]-x[2]*xkeisuu[0];
				xkeisuu[1]=(y[1]-y[2])/(x[1]-x[2]);
				teisuu[1]=y[2]-x[2]*xkeisuu[1];
				if(xkeisuu[0]<xkeisuu[1]) {
					temp=xkeisuu[0];xkeisuu[0]=xkeisuu[1];xkeisuu[1]=temp;
					temp=teisuu[0];teisuu[0]=teisuu[1];teisuu[1]=temp;
				}
			}
			if(yp>xkeisuu[0]*xp+teisuu[0] && yp<xkeisuu[1]*xp+teisuu[1])
				ok=1;
		}
		printf("%s\n",ok?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;	cin >> n;
  map<int,int>	a;
  for(int i=0;i<n;i++){
    int time;	cin >> time;
    a[time]=i+1;
  }
  
  for(auto	stu:a){
    cout << stu.second << " ";
  }
  
}

Measured memory_bytes: 8276
#include<stdio.h>
#include<string.h>

#define N 100


int pop(void);
void push(int);
int pointer=0;
int stack[N];

int main(){
  int x=0;
  int y=0;
  int n;
  char s[N];

  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      x=pop();
      y=pop();
      push(x+y);
    }
    else if (s[0]=='-'){
      x=pop();
      y=pop();
      push(y-x);
    }
    else if(s[0]=='*'){
      x=pop();
      y=pop();
      push(x*y);
    }
    else {
      n=atoi(s);
      push(n);
    }
  }
  printf("%d\n",pop());
  return 0;
}

int pop(){
  pointer--;
  return stack[pointer];
}

void push(int s){
  pointer++;
  stack[pointer-1]=s;
}



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

using namespace std;

vector <long long int> A,B;
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	long long int t;

	cin >> n;

	for(int i=0;i<n+1;i++)
	{
		cin >> t;
		A.push_back(t);
	}

	for(int i=0;i<n;i++)
	{
		cin >> t;
		B.push_back(t);
	}

	long long int res = 0;

	for(int i=0;i<n;i++)
	{
		long long int x = min(A[i],B[i]);
		res += x;
		A[i] -= x;
		B[i] -= x;
		if(B[i] > 0)
		{
			long long int y = min(A[i+1],B[i]);
			res += y;
			A[i+1] -= y;
			B[i] -= y;
		}
	}

	cout << res << '\n';

	return 0;
}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
typedef long double ld;
using namespace std;
ld ans[3005][3005];
ld prob[3005];
int main()
{
int n;
cin >>n;
for(int i=0;i<3005;i++){
    for(int j=0;j<3005;j++){
        ans[i][j]=0;
    }
}
for(int i=0;i<3005;i++){
    prob[i]=0;
}
for(int i=1;i<=n;i++){
    cin >>prob[i];
}
ans[1][0]=1-prob[1];
ans[1][1]=prob[1];
for(int i=2;i<=n;i++){
    for(int j=0;j<=n;j++){
     if(j<=i){
        ans[i][j]=ans[i-1][j]*(1-prob[i]);
        if(j)
            ans[i][j]+=ans[i-1][j-1]*prob[i];
     }
     else{
        ans[i][j]=0;
     }
    }
}
ld finl=0;
for(int i=(n+1)/2;i<=n;i++){
    finl+=ans[n][i];
}
cout <<fixed<<setprecision(12)<<finl;
    return 0;
}


Measured memory_bytes: 141440
n = gets.to_i
edge = Array.new(n+1) {[]}

(n-1).times do
    u, v, w = gets.split.map(&:to_i)
    edge[u] << [v, w]
    edge[v] << [u, w]
end

a = Array.new(n+1)
a[1] = 0
que = [1]

while now = que.shift
    edge[now].each do |v, w|
        next if a[v]
        a[v] = w.odd? ? a[now] ^ 1 : a[now]
        que << v
    end
end

puts a[1..-1]


Measured memory_bytes: 27516
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

int main() {
    ll n, t, a;
    cin >> n >> t >> a;

    vector<ll> h(n);
    rep(i, n) cin >> h[i];

    double temp;
    double diff_min = N;
    int ans;

    rep(i,n){
        temp = t - h[i] * 0.006;
        if(abs(a - temp) < diff_min){
            diff_min = abs(a - temp);
            ans = i + 1;
        }
    }
    print(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
#include <set>

using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
void printVec(std::vector<char> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}

int main() {
    int n;
    cin >> n;
    vector <int> a(n);
    vector <int> b(n);
    rep(i,0,n) {
        cin >> a[i];
        cin >> b[i];
    }
    for(int i=0; i< n-2;i++) {
        if (a[i] == b[i]) {
            if (a[i+1] == b[i+1]) {
                if (a[i+2] == b[i+2]) {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
    return 0;

}

Measured memory_bytes: 3132
#include<iostream>
#include<climits>
#define INF INT_MAX;
void merge(int*, int, int, int);
void mergeSort(int*, int, int);
int cnt=0;
int main(){
  int n;
  std::cin >> n;
  int A[n];
  for(int i=0; i<n; i++) std::cin >> A[i];
  mergeSort(A, 0, n);
  for(int i=0; i<n;i ++) std::cout << A[i] << (i != n-1 ? " " : "\n");
  std::cout << cnt << "\n";
  return 0;
}
void merge(int *A, int l, int m, int r){
  int n1=m-l, n2=r-m, i, j, L[n1+1], R[n2+1];
  for(i=0; i<n1; i++) L[i] = A[l+i];
  for(i=0; i<n2; i++) R[i] = A[m+i];
  i = j = 0, L[n1] = R[n2] = INF;
  for(int k=l;k<r;k++){
    if(L[i] <= R[j]) A[k] = L[i], i++, cnt++;
    else A[k] = R[j], j++, cnt++;
  }
}
void mergeSort(int *A, int l, int r){
  int m;
  if(l+1 < r){
    m = (l + r) / 2;
    mergeSort(A, l, m), mergeSort(A, m, r);
    merge(A, l, m, r);
  }
}

Measured memory_bytes: 6988