akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long

using namespace std;
const int INF = 2e17;
const int MB = 20;
const int MOD = 1e9 + 7;

void solve() {
	int n, m;
	cin >> n >> m;
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	x1--; y1--; x2--; y2--;

	vector<string> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	vector<vector<int>> d(n, vector<int>(m, INF));
	vector<vector<bool>> used(n, vector<bool>(m));
	deque<pair<int, int>> q;
	q.push_back({ x1, y1 });
	d[x1][y1] = 0;

	while (!q.empty()) {
		auto p = q.front();
		q.pop_front();
		if (used[p.first][p.second]) continue;
		used[p.first][p.second] = true;
		for (int i = p.first - 2; i <= p.first + 2; i++) {
			for (int j = p.second - 2; j <= p.second + 2; j++) {
				int w = abs(i - p.first) + abs(j - p.second) > 1;
				if (i < 0 || j < 0 || i >= n || j >= m || a[i][j] == '#' || d[i][j] <= d[p.first][p.second] + w) continue;
				d[i][j] = d[p.first][p.second] + w;
				if (w) q.push_back({ i, j });
				else q.push_front({ i, j });
			}
		}
	}

	cout << (d[x2][y2] == INF ? -1 : d[x2][y2]);
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	//srand(time(0));
	int t = 1;
	//int t;
	//cin >> t;
	while (t--) solve();
}

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

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

	if (c >= b && b >= a)
		cout << a << " " << b << " " << c << endl;
	
	else if (c >= a && a >= b)
		cout << b << " " << a << " " << c << endl;
	
	else if (b >= c && c >= a)
		cout << a << " " << c << " " << b << endl;
	
	else if (b >= a && a >= c)
		cout << c << " " << a << " " << b << endl;
	
	else if (a >= c && c >= b)
		cout << b << " " << c << " " << a << endl;

	else if (a >= b && b >= c)
		cout << c << " " << b << " " << a << endl;
	

	return 0;
}


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

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

	int N,K;
	int i,j;
	int tmp;
	int answer=0;
	int counter=0;
	double ave;
	vector<int> given;

	cin >> N >> K;

	for(i=0;i<N;i++){
		cin >> tmp;
		given.push_back(tmp);
	}

	sort(given.begin(),given.end());
	
	if(given[N/2]<K){
		//half x
		for(i=N/2;i<N;i++){
			if(given[i]>=K){
				answer=N-i;
				break;
			}
		}
	}else{
		//half o
		for(i=0;i<N;i++){
			if(given[i]>=K){
				answer=N-i;
				break;
			}
		}
	}

	cout << answer << endl;

	return 0;
}



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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_A 100'000
#define MAX_B 100'000
#define MAX_C 100'000
i64 X, Y, A, B, C;
i64 p[MAX_A], q[MAX_B], r[MAX_C];

int main() {
    cin >> X >> Y >> A >> B >> C;
    REP(i, A) cin >> p[i];
    REP(i, B) cin >> q[i];
    REP(i, C) cin >> r[i];

    sort(p, p + A, greater<i64>());
    sort(q, q + B, greater<i64>());
    sort(r, r + C, greater<i64>());

    priority_queue<i64, vector<i64>, greater<i64>> pq;
    REP(i, X) pq.push(p[i]);
    REP(i, Y) pq.push(q[i]);

    i64 x;
    REP(i, C) {
        x = pq.top(); pq.pop();
        if (x > r[i]) {
            pq.push(x);
            break;
        }
        pq.push(r[i]);
    }

    i64 ans = 0;
    while (!pq.empty()) {
        ans += pq.top(); pq.pop();
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4852
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	string S;
	cin >> S;
	int res = S.size();
	int a = S.size();
	for (int i = 1;i < S.size();i++) {
		if (S[i] != S[i - 1])
			res = min(res, max(i, a - i));
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;


ll dfs(ll now){
  if(now==1) return 1;
  return dfs(now/2) * 2;
}
int main(int argc, char const *argv[]) {
  ll h;std::cin >> h;
  std::cout << dfs(h)*2 - 1 << '\n';
}


Measured memory_bytes: 888
import math

class UnionFind():
    def __init__(self, N):
        # negative value: represents the root of a tree; its absolute value is the size of the tree
        # positive value: the parent's index
        self.vertices = [-1 for _ in range(N+1)]
        
    def find(self, v):
        if self.vertices[v] < 0:
            return v
        else:
            # path compression
            self.vertices[v] = self.find(self.vertices[v])
            return self.vertices[v]
        
    def union(self, a, b):
        s1 = self.find(a)
        s2 = self.find(b)
        if s1 == s2: # a and b is in the same tree
            return False
        else:
            if self.vertices[s1] <= self.vertices[s2]: # the tree including a is bigger
                self.vertices[s1] += self.vertices[s2] # update the size of the bigger tree
                self.vertices[s2] = s1
            elif self.vertices[s1] > self.vertices[s2]: # the tree including b is bigger
                self.vertices[s2] += self.vertices[s1] # update the size of the bigger tree
                self.vertices[s1] = s2
            return True
        
    def is_connected(self, x, y):
        return self.find(x) == self.find(y)

N, M = map(int, input().split())
E = []
for _ in range(M):
    a, b = map(int, input().split())
    E.append((a, b))
uf = UnionFind(N)
inconv = [N*(N-1)//2]

while E:
    e = E.pop()
    if uf.is_connected(e[0], e[1]):
        inconv.append(inconv[-1])
    else:
        comp1 = abs(uf.vertices[uf.find(e[0])])
        comp2 = abs(uf.vertices[uf.find(e[1])])
        uf.union(e[0], e[1])
        temp = inconv[-1] - comp1*comp2
        inconv.append(temp)
inconv.pop()
inconv = list(reversed(inconv))
print(*inconv, sep='\n')

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

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

	if((S.at(6)>'4')||(S.at(5) == '1'))
		cout<<"TBD";
	else
		cout<<"Heisei";
	cout<<endl;

	return 0;
}


Measured memory_bytes: 256
MN = 10000
tp = []
op = -5
mem = [False * 2] + [True] * MN
for i in range(2, MN):
  if not mem[i]:
    continue
  if i - op == 2:
    tp.append((op, i))
  op = i
  for j in range(i + i, MN, i):
    mem[j] = False
tp.append((MN + 1, MN + 1))
while True:
  N = input()
  if not N:
    break
  for i, p in enumerate(tp):
    if p[1] > N:
      print('%d %d' % (tp[i - 1][0], tp[i - 1][1]))
      break

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a[101]={0};
	int n, x, s=0;
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		cin >> x;
		a[x]=1;
	}
	for(int i=1;i<=100;i++)
	{
		if(a[i]==1)
		{
			s++;
		}
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main
{
  public static void main(String[] args)
  {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int m = in.nextInt();
    int[] l = new int[m];
    int[] r = new int[m];
    for (int i = m-1; i >= 0; i--)
    {
      l[i] = in.nextInt()-1;
      r[i] = in.nextInt()-1;
    }
    
    int[] size = new int[n];
    Arrays.fill(size, 1);
    long[] ans = new long[m];
    DSU d = new DSU(n);
    for (int i = 0; i < m; i++)
    	if (d.find(l[i]) != d.find(r[i]))
        {
          int a = size[d.find(l[i])];
          int b = size[d.find(r[i])];
          ans[m-1-i] = a*b;
          d.union(l[i], r[i]);
          size[d.find(l[i])] = a+b;
        }
    System.out.println(ans[0]);
    for (int i = 1; i < m; i++)
    {
      ans[i] += ans[i-1];
      System.out.println(ans[i]);
    }
    
    in.close();
  }
  
  public static class DSU
    {
        int[] set;
        
        DSU(int n)
        {
            Arrays.fill(set = new int[n], -1);
        }
        
        int find(int i)
        {
            return set[i] < 0 ? i : (set[i] = find(set[i]));
        }
        
        boolean union(int a, int b)
        {
            if ((a = find(a)) == (b = find(b))) return false;
            if (set[a] == set[b]) set[a]--;
            if (set[a] <= set[b]) set[b] = a; else set[a] = b;
            return true;
        }
    }
}

Measured memory_bytes: 99272
def main():
  n = int(input())
  name = input()
  length = len(name)
  def check(ss):
    ind = 0
    end = len(ss)
    while ind < end:
      while ind < end and ss[ind] != name[0]:
        ind += 1
      
      for i in range(100):
        j1 = ind
        j2 = 0
        while j1 < end and j2 < length and ss[j1] == name[j2]:
          j1 += i
          j2 += 1
        if j2 == length:
          return True
      ind += 1
    return False
  
  print(sum([check(input()) for _ in range(n)]))
main()


Measured memory_bytes: 5616
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int n,k,x,y;
	cin>>n>>k>>x>>y;
	if(n<=k){
		cout<<n*x<<endl;
	}else{
		cout<<x*k+(n-k)*y<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>

using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

LL gcd(LL a, LL b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}



int main(){
    int N;
    cin >> N;
    int A[N+2];
    int sum=0;
    A[0]=0;
    A[N+1]=0;
    for(int i=1;i<=N;++i){
        cin >> A[i];
    }
    for(int i=0;i<=N;++i){
        sum+=abs(A[i]-A[i+1]);        
    }
    int pos=0;
    int ans[N+2]={0};
    int res=0;
    for(int i=1;i<=N;++i){
        ans[i]=sum+abs(A[i-1]-A[i+1])-(abs(A[i-1]-A[i])+abs(A[i]-A[i+1]));
    }
    for(int i=1;i<=N;++i){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 2048
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
//long long num[100000];
int main(){
	char x,y;
	cin>>x>>y;
	if(x>y) cout<<">"<<endl;
	else if(x<y)cout<<"<"<<endl;
  	else cout<<"="<<endl;
	return 0;
}

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

string fizzbuzz(int i)
{
	stringstream sst;
	sst << i;
	if(i%15==0)
		return "FizzBuzz";
	else if(i%5==0)
		return "Buzz";
	else if(i%3==0)
		return "Fizz";
	else
		return sst.str();
}

int main()
{
	int m,n;
	while(cin >> m >> n){
		if(m == 0 && n == 0)
			break;
		string str;
		bool *player = new bool[m];
		int check = m;
		for(int i=0;i<m;i++){
			player[i] = true;
		}

		int pos = 0;
		for(int i=0;i<n;i++){
			cin >> str;
			if(check != 1 && str != fizzbuzz(i+1)){
				player[pos] = false;
				check--;
			}
			pos++;
			pos%=m;
			if(check != 1){
				while(player[pos] != true){pos++;pos%=m;}
			}
		}

		bool flag = false;
		for(int i=0;i<m;i++){
			if(player[i] == true){
				if(flag == true)
					cout << " ";
				cout << i+1;
				flag = true;
			}
		}
		cout << endl;
		delete[] player;
	}
	return 0;
}

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

int main(){
  int sec;
  cin >> sec;
  int h,m,s;
  h = sec / 3600;
  sec = sec % 3600;
  m = sec / 60;
  s = sec % 60;
  cout << h << ":" << m << ":" << s << endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<char> c(N);
    for(int i=0; i<N; i++) cin >> c.at(i);
    int RW=0, Wcnt=0, Rcnt=0;
    for(int i=0; i<N; i++){
        if(c.at(i) == 'W') Wcnt++;
        else Rcnt++;
    }

    for(int i=0; i<Rcnt; i++){
        if(c.at(i) == 'W') RW++;
    }

    if(RW < Wcnt && RW < Rcnt) cout << RW << endl;
    else if(Wcnt < Rcnt) cout << Wcnt << endl;
    else cout << Rcnt << endl;

}

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

int main()
{
    long long int n,i,d=1;
    long long int a[100050];
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    int c=0;
    for(i=0; i<n; i++)
    {
        if(a[i]==0)
        {
            c++;
        }
        if(c>0)
        {
            cout<<"0"<<endl;
            return 0;
        }
    }
    for(i=0; i<n; i++)
    {
        if(a[i]<=1000000000000000000/d)
        {
            d*=a[i];
        }
        else
        {
            cout<<"-1"<<endl;
            return 0;
        }
    }
    cout<<d<<endl;
    return 0;
}


Measured memory_bytes: 4416
use std::io::*;
use std::str::FromStr;

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

use std::cmp::min;

fn main() {
    let a: usize = read();
    let b: usize = read();
    let c: usize = read();
    let d: usize = read();

    println!("{}", min(a, b) + min(c, d));
}


Measured memory_bytes: 4352
def judge(n,l):
    for i in range(n):
        s = 0
        for j in range(n):
            if(j!=i):
                s += l[j]
        if(s<=l[i]):
            print('No')
            return
    print('Yes')
    return

n = int(input())
l = list(map(int,input().split()))
judge(n,l)

Measured memory_bytes: 3060
n, m = map(int, input().split())

a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]
ans = False
for h in range(n-m+1):
  for w in range(n-m+1):
    flag = 1
    for i in range(m):
      for j in range(m):
        if a[h+i][w+j] != b[i][j]:
          flag = 0
          break
    if flag == 1:
      ans = True
      break
print("Yes" if ans else "No")

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

int main(){
  int n, m, c, b[21];

  cin >> n >> m >> c;

  for(int i=0; i<m; ++i) cin >> b[i];

  int ax, ans = 0;
  for(int ix=0; ix<n; ++ix){
    long long x = 0;
    for(int i=0; i<m; ++i){
      cin >> ax;
      x += ax*b[i];
    }
    if(x + c > 0) ++ans;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;

int main(){
    ll A;
    cin >> A;
    ll B;
    cin >> B;
    A--;B--;

    vector<vector<char>> ans(100, vector<char>(100, '#'));
    for(ll i=50;i<100;i++){
     for(ll j=0;j<100;j++){
         ans[i][j]='.'
     ;}
    ;}
    ll s=0; ll t=0;
    while(A){
        ans[s][t]='.';
        A--;t+=2;
        if(t>=100){
            t=0;s+=2;
        }
    }
    s=51; t=0;
    while(B){
        ans[s][t]='#';
        B--;t+=2;
        if(t>=100){
            t=0;s+=2;
        }
    }
    cout<<"100 100"<<endl;
    for(ll i=0;i<100;i++){
     for(ll j=0;j<100;j++){
         cout<<ans[i][j]
     ;}cout<<endl;
    ;}
    
    return 0;
}


Measured memory_bytes: 256
n=int(input())
mod=10**9+7
ans=1
from math import factorial
f=factorial(n)
p=[2]
for i in range(2,1001):
    flag=0
    for j in p:
        if i%j==0:
            flag=1
            break
    if flag==1:
        continue
    p.append(i)
for i in p:
    k=0
    while f%i**k==0:
        k+=1
    ans=ans*k
print(ans%mod)

Measured memory_bytes: 39280
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

vector<Int> dist;
vector<vector<pair<Int,Int>>> G;

bool dfs(Int v) {
	
	for (auto e : G[v]) {
		if (dist[e.first] == INF) {//行き先が見探索の場合
			dist[e.first] = dist[v] + e.second;
			//return dfs(e.first);
			if(!dfs(e.first))return false;
		}
		else if (dist[v] + e.second != dist[e.first])return false;//矛盾しない場合
		//else return false;//矛盾する場合
	}

	return true;
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, M;
	cin >> N >> M;

	dist.resize(N, INF);
	G.resize(N);

	Int L, R, D;
	for (Int i = 0; i < M; i++) {
		cin >> L >> R >> D;
		L--;
		R--;
		G[L].push_back(make_pair(R, D));
		G[R].push_back(make_pair(L, -D));
	}

	for (Int i = 0; i < N; i++) {
		if (dist[i] == INF) {
			dist[i] = 0;
			if (!dfs(i)) {
				cout << "No" << "\n";
				return 0;
			}
		}
	}

	cout << "Yes" << "\n";
}


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

int main(){
    int N, X;
    cin >> N >> X;
    int m[N];
    int min = 10000;
    int sum = 0;
    for (int i=0; i<N; ++i){
        cin >> m[i];
        sum += m[i];
        if (m[i] < min) min = m[i];
    }
    int ans = (X-sum)/min + N;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  vector<int> black(N + 1, 0), white(N + 1, 0);
  rep(i, N) { black[i + 1] = black[i] + (s[i] == '#' ? 1 : 0); }
  rrep(i, N) { white[i] = white[i + 1] + (s[i] == '.' ? 1 : 0); }

  int result = N;
  irep(i, N) { result = min(result, black[i] + white[i]); }
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 2180
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //  repマクロ
#define leng(n) (int)(log10(n)+1)  //  桁数leng
#define INF 9223372036854775807 //  巨大数INF
using namespace std;

signed main() {
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(a, b) << ' ' << max(0ll, -n+a+b) << endl;
}


Measured memory_bytes: 256
N=int(input())
H=list(map(int,input().split()))
if N>1:
    for i in range(N-1):
        if H[i]<=H[i+1]-1:
            H[i+1]-=1
        if H[i]>H[i+1]:
            print('No')
            exit()
    print('Yes')
else:
    print('Yes')

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

int main() {
  int x;
  int y;
  cin >> x >> y;

  if ((2 * x <= y) && (y <= 4 * x) && (y % 2 == 0)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3640
N,M = list(map(int,input().split()))

x = ["a"]*N

data = [[0,0] for _ in range(M)]
for m in range(M):
	data[m] = list(map(int,input().split()))

for m in range(M):
	s,c = data[m]
	s = int(s)
	if x[s-1] == "a":
		x[s-1] = str(c)
	elif int(x[s-1]) != c:
		print("-1")
		exit()

if N == 1:
	if x[0] == "a":
		print("0")
	else:
		print(x[0])
	exit()
	
if N == 2:
	if x[0] == "a":
		x[0] = "1"
	if x[1] == "a":
		x[1] = "0"
	if x[0] == "0":
		print("-1")
		exit()

if N == 3:
	if x[0] == "a":
		x[0] = "1"
		if x[1] == "a":
			x[1] = "0"
		if x[2] == "a":
			x[2] = "0"
	elif x[0] == "0":
		print("-1")
		exit()
	else:
		if x[1] == "a":
			x[1] = "0"
		if x[2] == "a":
			x[2] = "0"

for i in range(N):
	print(x[i],end = "")



Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define eps 1e-9
#define MOD 1000000007
#define INV_10 299473306
#define INF 1000000000
using namespace std;
vector<int>v;
int a[50], b[50], c[50], d[50];
int n, m, q;
int ma=0;
int check()
{
	int cu=0;
	for(int i = 0; i < q; i++)
		if(v[b[i]]-v[a[i]] == c[i])
			cu+=d[i];
	return cu;
}
void make_sequence(int step)
{
	if(step==n)
	{
		ma=max(ma, check());
		return;
	}
	for(int i = v[step-1]; i <= m; i++)
	{
		v.push_back(i);
		make_sequence(step+1);
		v.pop_back();
	}
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> m >> q;
	for(int i = 0; i < q; i++)
	{
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--;
		b[i]--;
	}
	v.push_back(1);
	make_sequence(1);
	cout << ma << '\n';
}

Measured memory_bytes: 3644
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

using namespace std;

int main (){
	int n=0,b[101],sum=0;
	cin>>n;
	b[0]=100000;
	for(int i=1;i<n;i++){
		cin>>b[i];		
	}
	for(int i=n-1; i>0;i--){
		if(b[i-1]>b[i]){
			sum+=b[i];
		}
		else {
			sum+=b[i-1];
		}
	}
	sum+=b[n-1];
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
N,H = map(int,input().split())

A = []
B = []
for i in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

A.sort(reverse=True)
B.sort(reverse=True)

ans = 0
cnt = 0
while(1):
    if H<=0:
        print(ans)
        exit()
    if cnt==len(B):
        break
    if A[0]>=B[cnt]:
        break
    H-=B[cnt]
    cnt+=1
    ans+=1

if H%A[0]==0:
    res = H//A[0]
else:
    res = H//A[0]
    res += 1

print(ans+res)

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

int main(){
    int A, B;
    char op;
    cin >> A >> op >> B;
    if (op == '+'){
        cout << A + B << endl;
    } else {
        cout << A - B << endl;
    }
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

#define MAX_N 100100

ll GCD(ll a, ll b) {
    if (a <= 0 || b <= 0) {
        return -1;
    }
    if (a > b) {
        if (a % b == 0) {
            return b;
        } else {
            GCD(b, a % b);
        }
    } else if (a < b) {
        if (b % a == 0) {
            return a;
        } else {
            GCD(a, b % a);
        }
    } else {
        return a;
    }
}

bool IsPrime(int n) {
    for (ll i = 2; i*i <= n; i++) {
        if (n%i == 0) {
            return false;
        }
    }
    return n != 1;
}

ll prime[MAX_N];
bool is_prime[MAX_N+1];
ll sieve(ll n) {
    ll p = 0;
    rep (i, n+1) {
        is_prime[i] = true;
    }
    is_prime[0] = is_prime[1] = false;
    for (ll i = 2; i <= n; i++) {
        if (is_prime[i]) {
            prime[p++] = i;
            for (ll j = 2*i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
    return p;
}

vector<ll> Divisor(ll n) {
    vector<ll> res;
    for (ll i = 1; i*i <= n; i++) {
        if (n%i == 0) {
            res.push_back(i);
            if (i != n/i) {
                res.push_back(n/i);
            }
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    vector<ll> div = Divisor(N);
    /*
    rep (i, div.size()) {
        cout << div[i] << " ";
    }
    cout << endl;
    */

    ll ans = 10000000000000;
    if (div.size()%2 == 0) {
        rep (i, div.size()/2) {
            ans = min(ans, div[i]+div[div.size()-i-1]-2);
        }
    } else {
        rep (i, div.size()/2+1) {
            ans = min(ans, div[i]+div[div.size()-i-1]-2);
        }
    }

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

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;


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

    priority_queue<ii, vector<ii>, greater<ii> > pf[100009];
    for (int i = 1; i <= M; i++) {
        int P, Y;
        cin >> P >> Y;
        pf[P].push(ii(Y, i));
    }

    ii ans[100009];
    for (int i = 1; i <= N; i++) {
        int j = 1;
        while (!pf[i].empty()) {
            int c = pf[i].top().second;
            pf[i].pop();
            ans[c] = ii(i, j);
            j++;
        }
    }

    for (int i = 1; i <= M; i++) {
        ostringstream sout1;
        ostringstream sout2;
        sout1 << setfill('0') << setw(6) << ans[i].first;
        sout2 << setfill('0') << setw(6) << ans[i].second;
        string s = sout1.str() + sout2.str();
        cout << s << endl;
    }
}


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

int main()
{
  int n,m,k;
  while(scanf("%d%d%d", &n, &m, &k)){
    if(n==0&&m==0&&k==0)break;
    map<int,double> M;
    double res = 0;

    M[0] = 1;
    for(int i = 0; i < n; ++i){
      map<int,double> nM;
      for(int j = 1; j <= m; ++j){
	for(map<int,double>::iterator it = M.begin(); it != M.end(); ++it){
	  //double p = it->second * (1./m);
	  //if( nM.find(it->first+j)==nM.end() ){
	    nM[it->first+j] += it->second * (1./m);
	    //}
	}
      }
      M = nM;
    }

    for(map<int,double>::iterator it = M.begin(); it != M.end(); ++it){
      //cout << it->first << ' ' << it->second << endl;
      res += max(1,it->first-k) * it->second;
    }

    printf("%.12lf\n", res);
    //return 0;
  }
  return 0;
}

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

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

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

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

void cout_mat(vector<vector<double>> &mat){
    for(int i=0; i<mat.size(); i++){
        vector<double> vec = mat[i];
        cout_vec(mat[i]);
    }
}

int main(){
    int N;
    cin >> N;
    vector<double> p(N+1,0.0);
    for(int i=1; i<=N; i++){
        cin >> p[i];
    }

    vector<vector<double> > dp(N+1,vector<double>(N+1,0.0));
    dp[0][0]=1;
    for(int n=1; n<=N; n++){
        for(int i=0; i<=n; i++){
            if(i==0){
                dp[0][n]=(1-p[n])*dp[0][n-1];
                continue;
            }else if(i==n){
                dp[n][0]=p[n]*dp[n-1][0];
                continue;
            }
            dp[i][n-i]=p[n]*dp[i-1][n-i] + (1-p[n])*dp[i][n-i-1];
        }
    }
    double ans=0.0;
    for(int i=N/2+1; i<=N; i++){
        ans+=dp[i][N-i];
    }

    //cout_mat(dp);

    cout << setprecision(10) << ans << endl;
}

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

int main(){
  int n;
  int s[100] = {0};

  cin >> n;
  for(int i=0; i<n; i++){
    char v;
    cin >> v;
    s[v]++;
  }

  int size = 0;
  if(s['P'] > 0) size++;
  
  if(s['W'] > 0) size++;
  
  if(s['Y'] > 0) size++;
  
  if(s['G'] > 0) size++;

  if(size == 3)
    cout << "Three" << endl;
  else
    cout << "Four" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#define rep(i, n) for (int i=0; i<(int)(n); ++i)

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

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

    vector<int> A(N);
    for(int i=0; i<N; ++i) cin >> A.at(i);

    int X = 0;
    for(int i=0; i<(N-1); ++i){
        if(A.at(i+1) - A.at(i) > X) X = A.at(i+1) - A.at(i);
    }

    if(K - A.at(N-1) + A.at(0) > X) X = K - A.at(N-1) + A.at(0);

    cout << K - X << endl;
}

Measured memory_bytes: 1024
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my ($x, $y, $z) = split / /, <STDIN>);
if ($x%2==0 || $y%2==0 || $z%2==0) {
  say 0;
} else {
  my @m = ($x, $y, $z);
  @m = sort { $a <=> $b } @m;
  say $m[0] * $m[1];
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[102];
int main() {
	ll n;
	cin>>n;
	ll ans=0,ans2=INF;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		ans+=x;
		if(x%10!=0){
			ans2=min(ans2,x);
		}
	}
	if(ans%10!=0){
		cout << ans;
	}
	else if(ans2!=INF){
		cout << ans-ans2;
	}
	else{
		cout << 0;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
     int A,B,s,m,n;
    scanf("%d%d",&A,&B);
    s=A+B;
    m=A-B;
    n=A*B;
    if(s>=m && s>=n)
        printf("%d\n",s);
    else if(m>=s && m>=n)
        printf("%d\n",m);
    else if(n>=s && n>=m)
        printf("%d\n",n);
    else if(A==0 && B==0)
        printf("%d\n",A);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int rate_to_col(int rate){
  if (rate <=0) return -1;
  if (rate <=399) return 0;
  if (rate <=799) return 1;
  if (rate <=1199) return 2;
  if (rate <=1599) return 3;
  if (rate <=1999) return 4;
  if (rate <=2399) return 5;
  if (rate <=2799) return 6;
  if (rate <=3199) return 7;
  return 8;
}


int truncated_max(int num, int t_max){
  if (num > t_max) return t_max;
  else return num;
}

int truncated_min(int num, int t_min){
  if (num < t_min) return t_min;
  else return num;
}

int main()
{
  int N, a, n_max = 0, c_index;
  bool col[9] = {false};
  cin >> N;
  for (int i = 0; i < N; i++){
    cin >> a;
    c_index = rate_to_col(a);
    col[c_index] = true;
    if (c_index == 8) n_max++;
  }
  int count = 0;
  for (int i = 0; i < 8; i++){
    if (col[i]) count++;
  }
  if (col[8]) cout << truncated_min(count, 1) << " " << count + n_max << endl;
  else cout << count << " " << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int A,B,C; cin >> A >> B >> C;
    int X,Y; cin >> X >> Y;
    int D,E,F;
    D=A*X+B*Y; 
    E=(X>Y ? Y*2*C+(X-Y)*A : (Y-X)*B+X*2*C);
    F=(X>Y ? X*2*C : Y*2*C);
    cout << min({D,E,F}) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000007
using namespace std;
int dp[114514][18];
int dsafter(int pos, int day){
	if(day == 0){
		return pos;
	}
	else{
		int cnt = 0, cur = day;
		while( cur/2 > 0){
			cnt++;
			cur /= 2;
		}
		return dsafter( dp[pos][cnt], day-(1<<cnt) );
	}
}
int solve(int a,int b,int n){
	if(a>b)return solve(b,a,n);
	int lef = 0, rig = n;
	while(rig - lef > 1){
		int mid = (lef+rig)/2;
		int plac = dsafter(a,mid);
		//cout<<a<<" "<<mid<<" "<<plac<<endl;
		if( plac >= b){
			rig = mid;
		}
		else{
			lef = mid;
		}
	}
	return rig;
}
int main(){
	int n;
	cin>>n;
	vector<ll> x;
	set<ll> sx;
	map<int,int> mp;
	for(int i=0;i<n;i++){
		ll tx;
		cin>>tx;
		x.pb(tx);
		sx.insert(tx);
		mp[tx]=i;
	}
	x.pb(2000000009);
	mp[2000000009]=n;
	sx.insert(2000000009);
	int l,q;
	cin>>l>>q;
	for(int i=0;i<n;i++){
		set<ll>::iterator it = sx.upper_bound( x[i]+l );
		dp[i][0] = mp[*it];
		dp[i][0]--;
		//cout<<"dp"<<i<<0<<" "<<dp[i][0]<<endl;
	}
	for(int j=1;j<=17;j++){
		for(int i=0;i<n;i++){
			dp[i][j] = dp[ dp[i][j-1] ][j-1];
		}
	}
	vector<ll> ans;
	for(int i=0;i<q;i++){
		int a,b;
		cin>>a>>b;
		ans.pb(solve(a-1,b-1,n));
	}
	for(int i=0;i<ans.size();i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 18932
#include <stdio.h>

int main(){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if((a>c && b<c) || (a<c && b>c)){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
#define rint register int
#define all(x) (x).begin(), (x).end()
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
const int MOD = 998244353;
vector<int> ary;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int n;
	cin >> n;
	ary.resize(n);
	rep (i, 0, n - 1) {
		cin >> ary[i];
	}
	sort(all(ary));
	lint ans = 1;
	rep (i, 0, n - 1) {
		(ans *= __gcd(ary[i], i)) %= MOD;
	}
	cout << ans << endl;
	return 0;
}

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

long long int Exp(long long int exp_n,long long int exp_e, long long exp_mod);


int main(){
  long long int N, T, B;
  cin >> N;
  long long int A[N], a;
  long long int Bi[40], Ti[40];
  
  for(int i=0;i<40;i++){
    Bi[i] = 0;
    Ti[i] = 0;
  }
  
  
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  
  T = A[0] + A[1];
  
  for(int i=2;i<N;i++){
    a = A[i];
    for(int j=0;j<40;j++){
      if(a>0){
        Bi[j] = Bi[j] + a%2;
        a = a/2;
        if(Bi[j]==2){
          Bi[j] = 0;
        }
      }
    }
  }
  
  //for(int i=0;i<40;i++){
  //  cout << i << ":" << Bi[i] <<endl;
  //}
  
  B=0;
  a=1;
  for(int i=0;i<40;i++){
    B = B + Bi[i]*a;
    a= a*2;
  }
  // cout << B <<endl;
  
  long long int Xi[40], X = T-B;
  if(X>=0 && X%2==0){
    X = X/2;

    if(X<=A[0]){
      a = X;
      for(int j=0;j<40;j++){
        Xi[j] = a%2;
        a = a/2;
        //cout << j << ":" << Xi[j] <<endl;
      }
      for(int j=0;j<40;j++){
        if(Xi[j]==1 && Bi[j]==1){
          cout << -1 <<endl;
          exit(0);
        }
      }
      
      for(long long int k=39;k>=0;k--){
        if(X+Bi[k]*Exp(2,k,999999999999)<A[0]){
          X = X+Bi[k]*Exp(2,k,999999999999);
        }
      }
      //cout << X <<endl;
      if(X != 0){
        cout << A[0]-X <<endl;
      }else{
        cout << -1 <<endl;
      }
    }else{
      cout << -1 <<endl;
    }
  }else{
    cout << -1 <<endl;
  }
  
  return 0;
}


long long int Exp(long long int exp_n,long long int exp_e, long long int exp_mod){
  long long int exp_o = 1;
  long long int exp_x=exp_n;
  long long int exp_tmp;
  
  while(0<exp_e){
    exp_tmp = exp_e/2;
    if(exp_e - exp_tmp*2 == 1){
      exp_o = exp_o*exp_x;
      if(exp_o>exp_mod){
        exp_o=exp_o%exp_mod;
      }
    }
    
    exp_x = exp_x*exp_x;
    if(exp_x>exp_mod){
      exp_x=exp_x%exp_mod;
    }
    exp_e = exp_tmp;
  }
  return exp_o;
}


Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        var num = int.Parse(Console.ReadLine());
        var trains = new Train[num-1];
        for (int i = 0; i < num - 1; i++)
        {
            var line = Console.ReadLine();
            var train = new Train();
            train.arrival = int.Parse(line.Split(' ')[0]);
            train.start = int.Parse(line.Split(' ')[1]);
            train.interval = int.Parse(line.Split(' ')[2]);
            trains[i] = train;
        }

        for (int i = 0; i < num - 1; i++)
        {
            int place = i;
            int timer = 0;
            while (true)
            {
                if (timer >= trains[place].start && timer % trains[place].interval == 0)
                {
                    timer += trains[place].arrival;
                    place++;
                } else
                {
                    timer++;
                }
                if (place >= num-1)
                {
                    Console.WriteLine(timer);
                    break;
                }
            }
        }
        Console.WriteLine("0");
        Console.ReadKey();
    }
}

public class Train
{
    public int arrival;
    public int start;
    public int interval;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
	int A, B;
	cin >> A >> B;

	if ((A+B)%2==0) {

		ce((A+B)/2)
	}
	else {
		ce("IMPOSSIBLE")
	}
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1e9 + 10;//10^9
ll MOD  = 1000000007;
int dy[] = {0,0,1,-1};
int dx[] = {1,-1,0,0};

int main(void){
    string S;
    cin >> S;
    int a = 0, b = 0, c = 0;
    for(int i = 0; i < 3; i++){
        if(S[i] == 'a') a++;
        if(S[i] == 'b') b++;
        if(S[i] == 'c') c++;
    }
    if(a * b * c == 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

int p, q, a, n;
int dfs(int mul, int sum, int k, int prev) {
    // 判定
    if(p * mul == q * sum) return 1;

    if(k == n) return 0;
    int ret = 0;
    for(int x=prev; x*mul<=a; x++) {
        int nmul = x * mul;
        int nsum = sum * x + mul;
        ret += dfs(nmul, nsum, k+1, x);
    }
    return ret;
}

int main() {
    while(cin >> p >> q >> a >> n) {
        if(!p) break;

        int cnt = dfs(1, 0, 0, 1);
        cout << cnt << endl;
    }
}


Measured memory_bytes: 3080
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
    char a[100],s[10]="FESTIVAL";
    cin>>a;
    int len=strlen(a);
    a[len-8]='\0';
    cout<<a;
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<ll> A(n), B(n);
    ll S = 0;
    rep(i, n) cin >> A[i];
    rep(i, n) S += A[i];
    ll S2 = 0;
    for (int i = 1; i <= n - 2; i += 2)
        S2 += A[i];
    B[0] = S - 2 * S2;
    cout << B[0] << " ";
    for (int i = 1; i < n; i++)
    {
        B[i] = 2 * A[i - 1] - B[i - 1];
        cout << B[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll INF = 1LL << 30;
ll min(ll a, ll b){ if(a < b) return a; else return b;}

int N, K;
vector<int> h;
vector<int> dp;

int req(int i){
    if(i == 0) return i;
    if(dp[i] != INF) return dp[i];
    
    ll res = INF;
    for(int k = 1; k <= K; k++){
        if(i - k >= 0) res = min(res, req(i - k) + abs(h[i] - h[i-k]));
    }
    
    return dp[i] = res;
}

int main(void){
    cin >> N >> K;
    h.resize(N); for(int i = 0; i < N; i++) cin >> h[i];
    dp.resize(N+10, INF);
    
    cout << req(N-1) << endl;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n, k;
	cin >> n >> k;
	for(int i=0; i<n; i++){
		int a;
		cin >>a;
	}
	cout << (n+k-3)/(k-1) << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

def dijkstra(graph: 'List[List[int]]', s: int):
    """
    特定の始点から各点への最短距離を求めます。
    重みが非負であることを前提とします。
    ================
    s: 始点
    graph: 隣接リスト
    ----------------
    d: sから各頂点への最短距離
    counter: sから各頂点への最短経路の個数
    """
    import heapq
    INF = 1e18
    d = [INF] * len(graph)
    d[s]  = 0
    counter = [0] * len(graph)
    counter[s] = 1

    q = []
    heapq.heappush(q, (0, s))
    while q:
        (dd, vv) = heapq.heappop(q)
        if d[vv] < dd:
            continue
        for (to, cost) in graph[vv]:
            if d[to] > (d[vv] + cost):
                d[to] = d[vv] + cost
                counter[to] = counter[vv]
                heapq.heappush(q, (d[to], to))
            elif d[to] == (d[vv] + cost):
                counter[to] += counter[vv]
    return d, counter


def solve(N: int, a: "List[int]", b: "List[int]", c: "List[int]", Q: int, K: int, x: "List[int]", y: "List[int]"):
    G = [[] for _ in range(N)]
    for i in range(N-1):
        G[a[i]-1].append((b[i]-1, c[i]))
        G[b[i]-1].append((a[i]-1, c[i]))
    dist, _ = dijkstra(G, K-1)

    for i in range(Q):
        print(dist[x[i]-1] + dist[y[i]-1])

    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N - 1)  # type: "List[int]"
    b = [int()] * (N - 1)  # type: "List[int]"
    c = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    Q = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int()] * (Q)  # type: "List[int]"
    y = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, a, b, c, Q, K, x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 60876
def resolve():
    S = list(map(int, input()))
    a, b, c, d = S[0], S[1], S[2], S[3]
    op = ['+', '-']
    for i in op:
        moji_i = str(a)
        sum_i = a
        sum_i += b if i == '+' else -b
        moji_i += i + str(b)
        for j in op:
            sum_j = sum_i + c if j == '+' else sum_i-c
            moji_j = moji_i + j + str(c)
            for k in op:
                sum = sum_j + d if k == '+' else sum_j-d
                moji = moji_j + k + str(d)
                if sum == 7:
                    moji += '=7'
                    return print(moji)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define ff first
#define ss second
const ll mod =   1e9 +7  ;
ll multiply(ll a, ll b ){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
////////////////////////////////////////////////////////////////



///////////////////////////////////////////////////////////////
void solve(){
   int n ;
   cin >> n ;
   ll sum = 0 ;
   for( int i = 1 ; i <=n ; i++){
    if(i%3!=0 && i%5!=0){
        sum+=i;
    }
   }
   cout << sum ;
}
int main(){
    int t = 1 ;
//    cin >> t ;
//    int cnt = 1 ;
    while(t--){
        //cout << "Case #" << cnt << ": ";
        solve( );
      //  cnt++;
    }
}




Measured memory_bytes: 3620