akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>


int main()
{
    std::size_t N, M;
    std::cin >> N >> M;

    std::vector<std::size_t> H(N);
    for(auto& h : H)
    {
        std::cin >> h;
    }

    std::vector<std::vector<std::size_t>> pathes(N, std::vector<std::size_t>{});
    for(std::size_t i=0; i<M; ++i)
    {
        std::size_t A, B;
        std::cin >> A >> B;
        A -= 1;
        B -= 1;

        pathes.at(A).push_back(B);
        pathes.at(B).push_back(A);
    }

    std::size_t answer = 0;
    for(std::size_t i=0; i<N; ++i)
    {
        const auto Hi = H.at(i);
        bool good = true;
        for(const auto& accessible : pathes.at(i))
        {
            if(Hi <= H.at(accessible))
            {
                good = false;
                break;
            }
        }
        if(good)
        {
            answer += 1;
        }
    }
    std::cout << answer << std::endl;



    return 0;
}


Measured memory_bytes: 9856
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n;
cin >> n;
int l[n];
int l_max=0;
int sum=0;
REP(i,n) {
  cin >> l[i];
  sum+=l[i];
  l_max = max(l_max,l[i]);
}
if(l_max*2<sum) {
  cout << "Yes" << endl;
} else {
  cout << "No" << endl;
}
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;cin>>n>>m;
  vector<int> b(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--;
      b[a]++;}}
  int ans=0;
  for(int i=0;i<m;i++){
    if(b[i]==n)ans++;}
  cout<<ans;}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        var xx = ConsoleUtil.StrArrayReadLine();
        Console.WriteLine(string.Join(" ", xx));
    }
}








static class ConsoleUtil
{
    public static string[] StrArrayReadLine(char sepalator)
    {
        string str = Console.ReadLine();
        return str.Split(sepalator).ToArray();
    }
    public static string[] StrArrayReadLine()
    {
        string str = Console.ReadLine();
        if (str.Contains(','))
        {
            return str.Split(',').ToArray();
        }
        {
            return str.Split(' ').ToArray();
        }
    }
    
    public static int[] IntArrayReadLine()
    {
        return StrArrayReadLine().Select(s => int.Parse(s)).ToArray();
    }
    public static int[] IntArrayReadLine(char sepalator)
    {
        return StrArrayReadLine(sepalator).Select(s => int.Parse(s)).ToArray();
    }

    public static int IntReadLine() => int.Parse(Console.ReadLine());
}




Measured memory_bytes: 13268
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main(){
	map<char,int> m;
	string s[4]={"One","Two","Three","Four"};
	int n;
	cin>>n;
	while(n--){
		char ch;
		cin>>ch;
		m[ch]++;
	}
	int num=m.size();
	cout<<s[num-1]<<endl;
}

Measured memory_bytes: 256
def lcs():
  x = raw_input()
  y = raw_input()
  x_len = len(x)
  y_len = len(y)
  z2 = [0 for i in range(y_len+1)]

  for i in range(x_len):
    z1 = z2 + []
    ele = x[i]
    for k in range(y_len):
      if ele == y[k]:
        z2[k+1] = z1[k] + 1
      elif z2[k+1] < z2[k]:
        z2[k+1] = z2[k]

  return z2[-1]

num = input()
for j in range(num):
  print lcs()

Measured memory_bytes: 6456
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
inline void read(rel &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  x=f?x:-x;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int mod=1e9+7,yuzu=2e5;
ll jic[yuzu|10]={1},inv[yuzu|10]={1};

ll kasumi(ll a,ll b=mod-2){
ll s=1;
for (;b;b>>=1,a=a*a%mod) if (b&1) s=s*a%mod;
return s;
}

ll cal(ll a,ll b){
return jic[a]*inv[b]%mod*inv[a-b]%mod;
}

int main(){
re0 i,j;
for (i=1;i<=yuzu;++i) jic[i]=jic[i-1]*i%mod;
for (i=yuzu;i;--i) inv[i]=kasumi(jic[i]);
int n=read(),m=read(),a=n-read()+1,b=read();
ll ans=0;
for (i=1;i<a;++i){
  ans=(ans+cal(b+i-2,i-1)*cal(n-i+m-b-1,m-b-1)%mod)%mod;
  } 
write(ans);
}

Measured memory_bytes: 3328
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const int MOD = 1e9 + 7;
const int INF = INT_MAX;

signed main() {
    Fast();

    int n, a, b;
    cin >> n;

    switch(n){
        case 1:
            cout << "Hello World" << endl;
            break;
        default:
            cin >> a >> b;
            cout << a + b << endl;
    }

    return 0;
}


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

using namespace std;






string s;
long long int dp[10001][2][101];
int d;
long long int MOD = 1000000007;
long long int solve(int i,int pode,int resto){
	if(i == s.size() && resto == 0){
		return 1;
	}
	if(i == s.size()){
		return 0;
	}
	if(dp[i][pode][resto] != -1){
		return dp[i][pode][resto];
	}
	int num = s[i] - '0';
	if(pode == 1){
		num = 9;
	}
	int aux = pode;
	long long int  ans = 0;
	for(int j = num; j>= 0 ;j--){
		if(s[i] - '0' > j){
			aux = 1;
		}
		ans = (ans + solve(i+1,aux,(resto + j)%d))%MOD;
	}
	return dp[i][pode][resto] = ans ;
}

int main(){
	cin.tie();
	ios_base::sync_with_stdio(0);
	cin >> s;
	cin >> d;
	memset(dp,-1,sizeof dp);
	cout << (solve(0,0,0) - 1LL + MOD)%MOD<< endl;
	return 0;
}


Measured memory_bytes: 16896
// Created by nachiketbhuta
// I don't give a damn about ratings!!!!!!!!!!
// Write the solution on your own, don't copy......


#include <bits/stdc++.h>

using namespace std;

#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define ll long long
#define lli long long int
#define PI 3.1415926535897932384626
#define MOD1 1000000007
#define MOD9 998244353
#define precision(x, y) cout<<fixed<<setprecision(y)<<x<<endl
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define deb4(x, y, z, w) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << ", " << #w << "=" << w << endl

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

    int ans = 0;
    for (int i = 1; i <= 10000; ++i)
    {
        if (i * 1000 > n && n % 1000 != 0) {
            ans = i * 1000 - n;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int mod = (int)1e9 + 7;
using namespace std;
#define ONLINE_JUDGE 1
#if ONLINE_JUDGE
#define tr(...)
#define endl '\n'
#else
#include "../../tr.h"
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 2*(int)1e5 + 10;

int n, a[N];
vector<long long> v;
map<long long, int> M;

int check(int idx){
   for(auto it: v){
      if(M.count(it-idx) == 0)continue;
      if(M[it-idx] > 0){
         assert(it-idx <= idx);
         M[it-idx]--;
         return it-idx;
      }
   }
   return -1;
}

int32_t main(){_

   cin>>n;
   for (int i = 0; i < n; ++i)
   {
      cin>>a[i];
      M[a[i]]++;
   }
   
   v.pb(1);
   while(1){
      v.pb(v.back()*2LL);
      if(v.back() > 1e12*1LL)break;
   }

   // cout<<v<<endl;

   int ans = 0;
   sort(a, a+n);
   reverse(a, a+n);

   for (int i = 0; i < n; ++i)
   {
      if(M[a[i]] == 0)continue;
      M[a[i]]--;
      int vals = check(a[i]);
      if(vals == -1)continue;
      ans++;
   }

   cout<<ans;
   #warning make sure N size is correct!
   return 0;
}

Measured memory_bytes: 14336
#pragma comment (linker, "/STACK:256000000")

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_NONSTDC_NO_DEPRECATE
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <memory.h>
#include <sstream>
#include <cassert>
#include <ctime>
#include <complex>
#include <random>
#include <bitset>

using namespace std;

typedef unsigned int uint32;
typedef long long int64;
typedef unsigned long long uint64;
typedef long double ldouble;
typedef pair<int, int> pii;
typedef pair<int64, int64> pll;
typedef pair<uint64, uint64> puu;
typedef pair<pii, pii> piiii;

#define pb push_back
#define sq(x) ((x)*(x))
#define tmin(x,y,z) (min(min((x),(y)),(z)))
#define rand32() (((unsigned int)(rand()) << 16) | (unsigned int)(rand()))
#define rand64() (((unsigned int64)(rand32()) << 16) | (unsigned int64)(rand32()))
#define bit(mask, b) ((mask >> b) & 1)
#define biton(mask, bit) (mask | (((uint32)(1)) << bit))
#define bitoff(mask, bit) (mask & (~(((uint32)(1)) << bit)))
#define bitputon(mask, bit) (mask |= (((uint32)(1)) << bit))
#define bitputoff(mask, bit) (mask &= (~(((uint32)(1)) << bit)))
#define FAIL() (*((int*)(0)))++
#define INF ((int)(1e9) + 1337)
#define LINF ((int64)(1e18))
#define EPS 1e-13
#define PI (3.1415926535897932384626433832795)
#define y1 yy1
#define y0 yy0
#define j0 jj0
//#define MOD 1000000007LL
#define HMOD 1234567913LL
#define HMOD2 1000000007LL
#define HBASE 1000003
#define REV2 500000004


//#ifdef _MY_DEBUG
//    #define HMOD 1000000007
//    #define HBASE (1000003LL)
//#else
//    #define HMOD ((int64)(1e18) + 3LL)
//    #define HBASE (1000037LL)
//#endif
#define MAX 2000000000
mt19937 ggen;

int64 a, b, c;

void solve()
{
    cin >> a >> b >> c;
    int64 diff = min({a * b, a * c, b * c});
    if ((a & 1) == 0 || (b & 1) == 0 || (c & 1) == 0)
        cout << 0;
    else
        cout << diff;
}

#define TASK "substr"
int main()
{
    //testgen(100000, 100000);// return 0;
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _MY_DEBUG
    freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
#else
    //freopen(TASK ".in", "rt", stdin); freopen(TASK ".out", "wt", stdout);
#endif
    //stresstest(5, 7, 100); return 0;
    ggen = mt19937(13);

    //int start = clock();
    solve();

    return 0;
}

Measured memory_bytes: 256
while True:
    string = input()
    exp = string.split(' ')
    if exp[1] == '?':
        break
    elif exp[1] == '+':
        print(int(exp[0]) + int(exp[2]))
    elif exp[1] == '-':
        print(int(exp[0]) - int(exp[2]))
    elif exp[1] == '*':
        print(int(exp[0]) * int(exp[2]))
    else:
        print(int(exp[0]) // int(exp[2]))


Measured memory_bytes: 5600
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1LL << 60;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  int H,A;
  cin >> H >> A;
  cout << (H+A-1)/A << endl;
  return 0;
}


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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	while(true){
		int h, w = 5;
		cin >> h;
		if(h == 0){ break; }
		vector<vector<int>> field(h, vector<int>(w));
		for(int i = 0; i < h; ++i){
			for(int j = 0; j < w; ++j){ cin >> field[i][j]; }
		}
		int score = 0;
		while(true){
			bool modified = false;
			for(int i = 0; i < h; ++i){
				for(int j = 0; j < w; ++j){
					if(field[i][j] < 0){ continue; }
					int k = j;
					while(k < w && field[i][j] == field[i][k]){ ++k; }
					if(k - j < 3){ continue; }
					for(--k; k >= j; --k){
						score += field[i][k];
						field[i][k] = -1;
						modified = true;
					}
				}
			}
			if(!modified){ break; }
			for(int j = 0; j < w; ++j){
				int k = h - 1;
				for(int i = h - 1; i >= 0; --i){
					if(field[i][j] >= 0){ field[k--][j] = field[i][j]; }
				}
				for(; k >= 0; --k){ field[k][j] = -1; }
			}
		}
		cout << score << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
// https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main()
{
    char s;
    cin >> s;
    for (int i = 0; i < 26; ++i)
    {
        if (s == 'A' + i)
        {
            cout << "A" << endl;
            return 0;
        }
        else if (s == 'a' + i)
        {
            cout << "a" << endl;
            return 0;
        }
    }
    return 0;
}


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

int main() {
  std::string x(1, ' ');
  scanf("%s", &x[0], x.size());
  switch (x[0]) {
    case 'A':
      printf("T");
      break;
    case 'C':
      printf("G");
      break;
    case 'G':
      printf("C");
      break;
    case 'T':
      printf("A");
      break;
  }
}


Measured memory_bytes: 256
from collections import deque

N = int(input())

colors = [-1 for _ in range(N)]
tree = [{} for _ in range(N)]
for _ in range(N - 1):
  u, v, w = map(int, input().split())
  is_even = (w % 2 == 0)
  tree[u-1][v-1] = is_even
  tree[v-1][u-1] = is_even

visiting = deque([0])
colors[0] = 0
while len(visiting) > 0:
  n = visiting.popleft()
  neighbors = tree[n]
  for m in neighbors:
    if colors[m] < 0:
      colors[m] = colors[n] if neighbors[m] else 1 - colors[n]
      visiting.append(m)

for color in colors:
  print(color)


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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=20,inf=0x3f3f3f3f;
int dp[1<<15][16],n,m,sum[1<<15];
int ans,G[maxn][maxn];
int main(){
	n=read(),m=read();
	REP(i,1,n) REP(j,1,n) G[i][j]=-inf;
	while(m--){
		int x=read(),y=read(),z=read();
		G[x][y]=G[y][x]=z;
		ans+=z;
	}
	int All=(1<<n)-1;
	REP(i,1,All){
		int u;
		REP(j,1,n) if(i&(1<<(j-1))) u=j;
		sum[i]=sum[i^(1<<(u-1))];
		int flag=0;
		REP(j,1,n) if(i&(1<<(j-1))) if(G[j][u]!=-inf) sum[i]+=G[j][u],flag=1;
	//	cout<<i<<' '<<sum[i]<<endl;
//		if(!flag) sum[i]=-inf;
	}
	REP(i,1,All) REP(j,1,n) dp[i][j]=-inf;
	dp[1][1]=0;
	REP(i,1,All) REP(j,1,n) if(dp[i][j]!=-inf){
		REP(k,1,n) if((i&(1<<(k-1)))==0 && G[j][k]!=-inf) chkmax(dp[i|(1<<(k-1))][k],dp[i][j]+G[j][k]);
		for(int u=((i+1)|i);u<=All;u=((u+1)|i)){
			int x=((i^u)|(1<<(j-1)));
			if(sum[x]!=-inf) chkmax(dp[u][j],dp[i][j]+sum[x]);
		}
	}
	printf("%d\n",ans-dp[All][n]);
	return 0;
}

Measured memory_bytes: 2432
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

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

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    int N;
    int ans=0;

    cin >> N;
    vector<int>C(N);
    vector<long long>S(N);
    vector<int>F(N);

    rep(i,N-1){
        cin >> C[i] >> S[i] >> F[i];
    }

    for(int i=0; i<N; i++) {
        ans = 0;
        for(int j=i; j<N-1; j++) {
            if (S[j] > ans) {
                ans += (S[j] - ans) + C[j];
            } else if (ans % F[j]) {
                ans += (F[j] - ans % F[j]) + C[j];
            } else {
                ans += C[j];
            }
        }
        cout << ans << endl;
    }

    return 0;
}



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

using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<int>> a(h, vector<int>(w, 0));
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++)
			cin >> a[i][j];

	int x = 0, y = 0;
	int counter = 0;
	vector<vector<int>> result;
	vector<int> yx(4, 0);
	while(x != w) {
		if(a[y][x] % 2 == 1) {
			a[y][x] -= 1;
			if(x % 2 == 0 && y != h-1) {
				a[y + 1][x] += 1;
				yx[0] = y; yx[1] = x; yx[2] = y+1; yx[3] = x;
				result.push_back(yx);
				counter += 1;
			}
			else if(((x % 2 == 0 && y == h-1) || (x % 2 == 1 && y == 0)) && x + 1 != w) {
				a[y][x + 1] += 1;
				yx[0] = y; yx[1] = x; yx[2] = y; yx[3] = x + 1;
				result.push_back(yx);
				counter += 1;
			}
			else if(x % 2 == 1 && y != 0) {
				a[y - 1][x] += 1;
				yx[0] = y; yx[1] = x; yx[2] = y-1; yx[3] = x;
				result.push_back(yx);
				counter += 1;
			}
		}

		if(x % 2 == 0 && y != h-1)
			y += 1;
		else if((x % 2 == 0 && y == h-1) || (x % 2 == 1 && y == 0))
			x += 1;
		else if(x % 2 == 1 && y != 0)
			y -= 1;
	}

	cout << counter << endl;
	for(int i = 0; i < counter; i++)
		cout << result[i][0] + 1 << " " << result[i][1] + 1 << " " << result[i][2] + 1 << " " << result[i][3] + 1 << endl;

	return 0;
}

Measured memory_bytes: 9904
#include <stdio.h>
int main(){
  long long n,i,a,b,min=1000000,max=-1000000,sum,tem,t;
  scanf("%lld",&n);
  sum = 0;
  for(i=0;i<n;i++){
    scanf("%lld",&a);
    sum = sum + a;
    if(a<min){
      min=a;
    }
    if(a>max){
      max=a;
  }
  }
  printf("%lld ",min);
  printf("%lld ",max);
  printf("%lld\n",sum);
  return 0;
}
    
    



Measured memory_bytes: 2112
S = input()

answer = 'Yes'
for i, s in enumerate(S):
    nth = i + 1
    is_odd = nth % 2 == 1
    is_even = not is_odd
    if (
        (is_odd and s in 'RUD') or
        (is_even and s in 'LUD')
    ): continue
    answer = 'No'

print(answer)


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

#define rep(i,n) for( (i)=0;(i)<(n);++(i) )
#define repr(i,n) for( (i)=(n);(i)>0;==(i) )
#define FOR(i,j,n) for( (i)=(j);(i)<(n);++(i) )
#define forr(i,j,n) for( (i)=(j);(i)>(n);--(i) )
#define debg(a) cout<<(a)<<endl;
#define INF 9999999
#define Int long long 
int i,j,k;
int dx,dy;
int a,b,c;
string s,t;

int main(){ 
  string a;
  cin>>s>>a>>t;
  cout<<"A"<<a[0]<<"C"<<endl;


  return 0;
}


Measured memory_bytes: 764
n,k=map(int,input().split())
sushi=[]
for i in range(n):
    sushi.append([])
for i in range(n):
    t,d=map(int,input().split())
    sushi[t-1].append(d)
Max=[]
Rest=[]
v=0
for i in sushi:
    if not i==[]:
        Max.append(max(i))
        i.remove(max(i))
        for j in i:
            Rest.append(j)
        v=v+1
Max.sort(reverse=True)
Rest.sort(reverse=True)
Max_s=[]
Rest_s=[0]
Sum=0
for i in Max:
    Sum=Sum+i
    Max_s.append(Sum)
Sum=0
l_r=0
for i in Rest:
    Sum=Sum+i
    Rest_s.append(Sum)
    l_r=l_r+1
ans=0
for i in range(1,min(k,v)+1):
    if k-i<=l_r:
        temp=Max_s[i-1]+Rest_s[k-i]+i**2
        if ans<temp:
            ans=temp
print(ans)


Measured memory_bytes: 65056
using System;

namespace B___Varied
{
    class Program
    {
        static void Main(string[] args)
        {
            string ans = "yes";
            string line = Console.ReadLine();
            for (int i = 0; i < line.Length; i++)
            {
                for (int j = 0; j < line.Length; j++)
                {
                    if (line[i] == line[j] && i != j)
                    {
                        ans = "no";
                        break;
                    }
                }
            }
            Console.WriteLine(ans);
        }
    }
}


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

bool check(vector<P> s) {
  int h = 0;
  for (P p : s) {
    int b = h + p.first;
    if (b < 0) return false;
    h += p.second;
  }
  return true;
} 


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

  vector<P> ls, rs;
  int total = 0;
  string s;
  rep(i, N) {
    cin >> s;
    int h = 0, b = 0;
    for (char c : s) {
      if (c == '(') h++; else h--;
      b = min(b, h);
    }
    if (h > 0) ls.emplace_back(b, h); 
    else rs.emplace_back(b - h, -h);
    total += h;
  }
  sort(ls.rbegin(), ls.rend());
  sort(rs.rbegin(), rs.rend());

  if (check(ls) && check(rs) && total == 0) {
    cout << "Yes" << endl;
  } else {
     cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 18812
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;

int n;
int a[210000];

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

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

    long long ans = 1000000000000000000LL;
    long long curt = 0;
    for (int i = 0; i < n-1; i++) {
        curt += a[i];
        ans = min(ans, abs( tot-2*curt ));
    }

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

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

using ll = long long;

int main(){

  ll oni,kid;
  ll oniGo,kidGo;
  ll time;
  cin >> oni >> oniGo;
  cin >> kid >> kidGo;
  cin >> time;

  if(oniGo<=kidGo){
    cout << "NO" << endl;
    return 0;
  }

  ll distance = abs(oni-kid);
  ll go = abs(oniGo-kidGo);

  if(go*time>=distance){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

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

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

    if(S.size()<T.size()){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    for(int i=0; i<S.size()-T.size()+1; i++){
        bool flg=false;
        for(int j=0; j<T.size(); j++){
            if(S[i+j]!=T[j] and S[i+j]!='?') flg=true;
        }

        if(flg) continue;
        ans="";
        for(int j=0; j<S.size(); j++) ans+=S[j];
        for(int j=0; j<T.size(); j++){
            ans[i+j]=T[j];
        }

        for(int j=0; j<ans.size(); j++) if(ans[j]=='?') ans[j]='a';
    }

    if(ans=="") cout << "UNRESTORABLE" << endl;
    else cout << ans << endl;
}

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

int main(){
  ll n, m;
  cin >> n >> m;
  ll day = 0;
  rep(i,m){
    ll a;
    cin >> a;
    day += a;
  }
  if(day>n){
    cout << -1 << endl;
  }
  else{
    cout << n - day << endl;
  }
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n; cin >> n;
	int num = 0;
	long long a;
	long long ans = 0, mini = 10000000000;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		if (a < 0) {
			a = -a;
			num++;
		}
		ans += a;
		mini = min(mini, a);
	}
	if (num % 2 == 1) ans -= 2 * mini;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int r,g,b;cin >> r >> g >> b;
  YESNO((g*10+b)%4 == 0);
  return 0;
}


Measured memory_bytes: 256
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra

n,x,y=map(int,input().split())

fr,to,w=[],[],[]

for i in range(n-1):
  fr.append(i)
  to.append(i+1)
  w.append(1)

fr.append(x-1)
to.append(y-1)
w.append(1)

g=csr_matrix((w, (fr, to)), shape=(n, n))

ans_l=[]

'''for i in range(n):
  d=dijkstra(g,indices=i,directed=False)
  ans_l+=list(d)'''

d=dijkstra(g,directed=False).astype(int)
ans_l=np.bincount(d.ravel(), minlength=n)//2

print(*ans_l[1:], sep='\n')

'''
for i in ans_l[1:]:
  print(i)
'''

Measured memory_bytes: 76512
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 2e5 + 17;

int n;
int a[maxn], pos[maxn];
llong F[maxn];

bool read()
{
	if (scanf("%d", &n) != 1)
		return false;

	forn (i, n + 1)
		scanf("%d", a + i);

	return true;
}

llong binpow(llong a, llong b)
{
	llong res = 1ll;

	for (; b > 0; b >>= 1, a = a * a % inf)
		if (b & 1)
			res = res * a % inf;

	return res;
}

llong binomial(int n, int k)
{
	if (k > n) return 0;
	return F[n] * binpow(F[k], inf - 2) % inf * binpow(F[n - k], inf - 2) % inf;
}

void solve()
{
	F[0] = 1;

	for (int i = 1; i <= n + 1; ++i)
		F[i] = F[i - 1] * i % inf;

	int i1, i2;
	fill(pos + 1, pos + n + 1, -1);

	forn (i, n + 1)
		if (pos[a[i]] == -1)
			pos[a[i]] = i;
		else
		{
			i1 = pos[a[i]];
			i2 = i;
		}

	for (int k = 1; k <= n + 1; ++k)
	{
		llong res = binomial(n + 1, k);
		res -= binomial(i1 + n - i2, k - 1);
		if (res < 0) res += inf;
		printf("%lld\n", res);
	}
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


Measured memory_bytes: 2816
/*
	f(v, d, d1):- d = d + w(P[v], v), d1

*/
#include <bits/stdc++.h>

using namespace std;
const int maxv = 100001;
vector< pair<int, int> > A[maxv], T[maxv];
int P[maxv], solve;
int a, b, c, N, root;


void tree_build( int v, int parent ){

	vector< pair<int, int> >::iterator x = A[v].begin();

	for( ; x != A[v].end(); ++x ){
	    if( x->first == parent )
	    	continue;
		T[v].push_back( *x ),
		tree_build( x->first, v );
	}
}

void sol( int v, int &len ){

    vector< pair<int, int> >::iterator x = T[v].begin();

    int tplen = 0;
    int ch1 = 0;
    int ch2 = 0;
    for( ; x != T[v].end(); ++x ){
		tplen = x->second;
		sol( x->first, tplen );
		if( ch1 <= tplen ){
			ch2 = ch1;
			ch1 = tplen;
		}else
		if( ch2 < tplen )
			ch2 = tplen;
	}

	solve = max( solve, ch1 + ch2 );
	len += ch1;
}

int main( void ){

	//freopen("input.in", "r", stdin);
	scanf( "%d", &N );

	for( int i = 1; i < N; ++i )
		scanf( "%d%d%d", &a, &b, &c ), 
		++a, 
		++b,
		P[b] = a,
		T[a].push_back( make_pair( b, c ) ),
		A[b].push_back( make_pair( a, c ) );


	for( int i = 1; i <=N && !root; ++i )
		root = ( !P[i] )?i:root;	

	tree_build( root, 0 );
	int len = 0;
	sol( root, len );

	printf("%d\n", solve);

	return 0;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int N;
	cin >> N;

	vector<int> V( N ), C( N );
	for( auto& v: V ) { cin >> v; }
	for( auto& v: C ) { cin >> v; }

	int result = 0;
	for( int i = 0; i < N; ++i ) {
		result += max( V[i] - C[i], 0 );
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;

typedef pair<int,int> pii;

int main(){
	int n, m, k, u;
	scanf("%d%d%d", &n, &m, &k);

	vector<int> a(m), b(m), L(m);
	vector<vector<pii> > G(n + 1);
	for(int i = 0; i < m; ++i){
		scanf("%d%d%d", &a[i], &b[i], &L[i]);
		G[a[i]].push_back(pii(L[i], b[i]));
		G[b[i]].push_back(pii(L[i], a[i]));
	}

	priority_queue<pii,vector<pii>,greater<pii> > pq;
	vector<int> d(n + 1, 500000000);
	for(int i = 0; i < k; ++i){
		scanf("%d", &u);
		d[u] = 0;
		pq.push(pii(0, u));
	}

	while(!pq.empty()){
		int e = pq.top().first;
		u = pq.top().second;
		pq.pop();
		if(d[u] != e){ continue; }
		for(size_t i = 0; i < G[u].size(); ++i){
			int v = G[u][i].second;
			int f = e + G[u][i].first;
			if(d[v] > f){
				d[v] = f;
				pq.push(pii(f, v));
			}
		}
	}

	int ans = 0;
	for(int i = 0; i < m; ++i){
		int e = d[a[i]];
		int f = d[b[i]];
		int r = max(max(e, f), e + (f - e + L[i] + 1) / 2);
		ans = max(ans, r);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 5188
// Aizu 0235: Sergeant Rian
// 2017.9.11 bal4u@uu

#include <stdio.h>
#include <string.h>

typedef struct { char f; int len, to[22], t[22]; } T;
T tbl[22];
int n;

int mostfar(int k)
{
	int i, j, max, s;

	if (tbl[k].f) return 0;
	tbl[k].f = 1;
	for (max = 0, i = 0; i < tbl[k].len; i++) {
		if ((j = tbl[k].to[i]) >= 0 && tbl[j].f == 0) {
			s = tbl[k].t[i] + mostfar(j);
			if (s > max) max = s;
		}
	}
	return max;
}

int main()
{
	int i, j, a, b, t, ans;
	T *p;

	while (scanf("%d", &n) && n) {
		memset(tbl, 0, sizeof(tbl));
		for (ans = 0, i = 1; i < n; i++) {
			scanf("%d%d%d", &a, &b, &t), a--, b--;
			p = tbl + a, p->to[p->len] = b, p->t[p->len++] = t;
			p = tbl + b, p->to[p->len] = a, p->t[p->len++] = t;
			ans += t;
		}
		for (i = 1; i < n; i++) if (tbl[i].len == 1) {
			p = tbl + tbl[i].to[0];
			for (j = 0; j < p->len; j++) 
				if (p->to[j] == i) { ans -= p->t[j], p->to[j] = -1; break; }
		}
		printf("%d\n", 2*ans - mostfar(0));
	}
	return 0;
}

Measured memory_bytes: 1732
#include <iostream>

using namespace std;

int main()
{



    int n;
    cin>>n;
    int arr[n];

    for(int i = 0 ; i<n ; i++)cin>>arr[i];


    int tot = 0 ;
    for(int i = 1; i<n-1 ; i++)
    {
        if(arr[i-1]<arr[i] && arr[i]<arr[i+1] || arr[i-1]>arr[i] && arr[i]>arr[i+1])tot++;
    }

    cout<<tot<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef complex<double> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define X real()
#define Y imag()
#define EQ(a,b) (abs((a)-(b))<EPS)
short f[5001][5001];
int n;
int ans=0;
vector<P> v;
int main()
{
	while(1)
	{
		ans=0;
		memset(f,0,sizeof(f));
		cin >> n;
		if(n==0)break;
		for(int i=0;i<n;i++)
		{
			int p,q;
			cin >> p >> q;
			f[p][q]++;
			v.pb(P(p,q));
		}
		for(int i=0;i<v.size()-1;i++)
		{
			for(int j=i+1;j<v.size();j++)
			{
				P k=v[i]-v[j];
				P n=k*P(0,1);
				P c=v[i]+n;
				P d=v[j]+n;
				if(c.X-(int)c.X!=0||c.Y-(int)c.Y!=0||
				   d.X-(int)d.X!=0||d.Y-(int)d.Y!=0||
				   c.X<0||c.Y<0||c.X>5000||c.Y>5000||
				   d.X<0||d.Y<0||d.X>5000||d.Y>5000)
				{
					continue;
				}
				if(f[(int)c.X][(int)c.Y]&&f[(int)d.X][(int)d.Y])
				{
					P e=d-v[j];
					int sq=((int)k.X)*((int)e.Y)-((int)k.Y)*((int)e.X);
					if(sq<0)sq=-sq;
					ans=max(ans,sq);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 50312
while True:
    m, f, r = map(int, raw_input().split())
    if(m == -1 and f == -1 and r == -1):
        break
    if(m == -1 or f == -1 or m + f < 30):
        print("F")
    elif(m + f >= 80):
        print("A")
    elif(m + f >= 65):
        print("B")
    elif(m + f >= 50):
        print("C")
    elif(m + f >= 30):
        if(r >= 50):
            print("C")
        else:
            print("D")

Measured memory_bytes: 4220
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#pragma GCC optimize("unroll-loops")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define DB double
#define ST string
#define BS bitset
#define VE vector
#define VL vector<LL>
#define VP vector<pair<LL,LL>>
#define VVL vector<vector<LL>>
#define PQ priority_queue
#define PQS priority_queue<LL,vector<LL>,greater<LL>>
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define EB emplace_back
#define MP make_pair
#define TS to_string
#define TU to_ullong
#define FOR(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define UB(a,n) *upper_bound(ALL(a),n)
#define LB(a,n) *lower_bound(ALL(a),n)
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000001
//#define ERR 0.00000000000001
#define NUM 200010
#define FAST cin.tie(0);ios::sync_with_stdio(false)

void Yn(LL a){if(a)printf("Yes\n");else printf("No\n");}
void YN(LL a){if(a)printf("YES\n");else printf("NO\n");}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL GCD(LL a,LL b){LL c=1,tmp=max(a,b);b=min(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int lcmpr(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int ccmpr(const void* a,const void* b){return *(char*)b-*(char*)a;}
int scmp(const void* a,const void* b){return strcmp((char*)a,(char*)b);}
int scmpr(const void* a,const void* b){return strcmp((char*)b,(char*)a);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(m,d);x-=k*y;swap(x,y);}return mod(a*mod(x,MOD),MOD);}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}
bool cmps(pair<LL,LL> a,pair<LL,LL> b){if(a.second!=b.second)return a.second<b.second;return a.first<b.first;}

void prfc(LL n,VL &p){LL i=2;while(n>1&&i*i<=n){if(n%i==0){n/=i;p.EB(i);}else i++;}if(n>1)p.EB(n);}
void alfc(LL n,VL &a){for(LL i=1;i*i<=n;i++){if(n%i==0){a.EB(i);if(i*i!=n)a.EB(n/i);}}SORT(a);}

int main(){
  FAST;
  LL ans=0,N,n;
  cin>>N;
  VL vn,v;
  alfc(N,vn);alfc(N-1,v);
  ans+=v.size()-1;
  for(LL i:vn){
    n=N;
    if(i==1)continue;
    while(n%i==0)n/=i;
    if(n%i==1)ans++;
  }
  cout<<ans<<endl;
}


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

int main(){

  long long int n,m,a,b,c;

  while(cin >> n >> m, n, m){
    a = b = c = 0;
    m -= n;

    while(m - 1000 >= 0){
      c++;
      m -= 1000;
    }

    while(m - 500 >= 0){
      b++;
      m -= 500;
    }

    while(m - 100 >= 0){
      a++;
      m -= 100;
    }

    cout << a << " " << b << " " << c << endl;

  }
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[1000005];
string s;
int  main(void)
{
	cin>>s;
	for(ll i=0;i<s.size();i++)
	{
		a[i+1]=s[i]-'0';
	}
	ll cnt=0,f=0;
	a[0]=0;
	for(ll i=s.size();i>0;i--)
	{
		a[i]=a[i]+f;
		cnt+=min(a[i],10-a[i]);
		if(a[i]>5||a[i]==5&&a[i-1]>=5)
		{
			f=1;
		}
		else
		{
			f=0;
		}
	}
	printf("%lld",cnt+f);
}

Measured memory_bytes: 9220
#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"

using namespace std;

//const long long int MOD = 1000000007;
const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R

class UnionFind {
	vector<int>parent;
	vector<int>rank;
public:
	UnionFind(int num) {
		num++;
		parent.resize(num);
		rank.resize(num);
		sz.resize(num, 1);
		for (int i = 0; i < num; i++) {
			parent[i] = i;
			rank[i] = 0;
		}
	}
	int Find(int node) {
		if (parent[node] == node)return node;
		else return parent[node] = Find(parent[node]);
	}
	void Unite(int u, int v) {
		u = Find(u);
		v = Find(v);
		if (u == v)return;
		if (rank[u] < rank[v]) {
			parent[u] = v;
			sz[v] += sz[u];
		}
		else {
			parent[v] = u;
			sz[u] += sz[v];
			if (rank[u] == rank[v])rank[u]++;
		}
	}
	bool Check_Same(int u, int v) {
		return Find(u) == Find(v);
	}
	vector<long long int>sz;
};

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

	cin >> N >> M;
	vector<pair<int, int>>edge(M);
	for (auto &i : edge)cin >> i.first >> i.second;
	reverse(edge.begin(), edge.end());
	vector<long long int>ans;
	ans.push_back(N*(N - 1) / 2);
	UnionFind uf(N);
	K = N * (N - 1) / 2;
	for (auto i : edge) {
		int a = i.first;
		int b = i.second;
		if (uf.Check_Same(a, b)) {
			ans.push_back(K);
			continue;
		}
		K -= uf.sz[uf.Find(a)] * uf.sz[uf.Find(b)];
		ans.push_back(K);
		uf.Unite(a, b);
	}
	ans.pop_back();
	reverse(ans.begin(), ans.end());
	for (auto i : ans)cout << i << endl;

	return 0;
}


Measured memory_bytes: 4596
N,M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()



def gcd(a,b):
    x = max([a,b])
    y = min([a,b])
    while y:
        x, y = y, x % y
    return x

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

# 全体の最大公約数, 最小で2
num = A[0]
for i in range(1,N):
    num = gcd(num, A[i])

# それぞれをnumで割った時の偶奇が異なれば、NG
odd = 0
even = 0
for i in range(N):
    if (A[i] / num)  % 2 == 0:
        even += 1
    else:
        odd += 1

if odd > 0 and even > 0:
    print(0)
else:
    # 半最小公倍数
    h = A[0] // 2
    # 最小公倍数
    n = A[0]
    for i in range(1,N):
        h = lcm(h, A[i]//2)
        n = lcm(n, A[i])
    if h == A[-1]:
        h *= 1.5

    if M < h:
        print(0)
    else:
        ans = 1
        M -= h
        ans += M // n
        print(ans)
    


Measured memory_bytes: 14400
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
int main(){
	string A;
	cin>>A;
	if(A=="abc"||A=="acb"||A=="bac"||A=="bca"||A=="cab"||A=="cba"){
		cout<<"Yes"<<endl;}
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int x=0;
  int y=0;
  int i=0;
  char s[100001];
  
  scanf("%s",s);
  
  while(1){
        if(s[i]=='\0')
          break;
    
        if(s[i]=='0' && i%2==0)
           x++;
    
        else if(s[i]=='1' && i%2==1)
         x++;
         i++;
    
        if(s[i]=='\0')
          break;
  }
i=0;
    while(1){
          if(s[i]=='\0')
           break;
          if(s[i]=='1' && i%2==0)
           y++;
          else if(s[i]=='0' && i%2==1)
           y++;
           i++;
  }
  if(y<x)
    x=y;
  
  printf("%d\n",x);
  return 0;
}

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

def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    inf = 10**10
    dp = [inf for _ in range(N)]
    dp[0] = 0
    for i in range(0,N-1):
        for k in range(1,min(K+1,N-i)):
            dp[i+k] = min(dp[i]+abs(h[i+k]-h[i]),dp[i+k])
    print(dp[-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 56572
#include<bits/stdc++.h>
#pragma GCC optimize("02")
#define ll long long
#define _inline __inline__ __attribute__((always_inline))
using namespace std;
struct ios{
    inline char gc(){
        static const int IN_LEN=1<<18|1;
        static char buf[IN_LEN],*s,*t;
        return (s==t)&&(t=(s=buf)+fread(buf,1,IN_LEN,stdin)),s==t?-1:*s++;
    }
    template <typename _Tp> _inline ios & operator >> (_Tp &x){
        static char ch,sgn; ch=gc(),sgn=0;
        for(;!isdigit(ch);ch=gc()){if(ch==-1)return *this;sgn|=ch=='-';}
        for(x=0;isdigit(ch);ch=gc())x=x*10+(ch^'0');
        sgn&&(x=-x); return *this;
    }
}inc;
string a,b;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>a>>b;
	sort(a.begin(),a.end());
	sort(b.begin(),b.end(),greater<char>());
	puts(a<b?"Yes":"No");
	return 0;
}


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

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

  int ans = 0;

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

    for(int  c='a'; c<='z'; c++){
      bool left = false, right = false;

      for(int j=0; j<i; j++){
        if(s[j] == c) left = true;
      }
      for(int j=i; j<n; j++){
        if(s[j] == c) right = true;
      }

      if(right && left) cnt++;
    }
    if(cnt > ans) ans = cnt;
  }

  cout << ans << endl;
}



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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll K; cin >> K;
  if (K%2==0||K%5==0) { cout << -1 << endl; return 0; }

  ll result = 1, now = 7 % K;
  while (now) { now = (now*10+7) % K; result++; }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3640
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

const ld eps = 1e-9, pi = acos(-1.0);

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

    int a, b;
    char c;
    while (cin >> a >> c >> b, c != '?')
    {
        int res = 0;
        if (c == '+')
            res = a + b;
        else if (c == '-')
            res = a - b;
        else if (c == '*')
            res = a * b;
        else
            res = a / b;
        cout << res << endl;
    }
}



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

using namespace std;

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

  int ans = 0;
  for (int i = 1; i < n - 1; i++) {
    if (a[i - 1] < a[i] && a[i] < a[i + 1]) ans++;
    if (a[i - 1] > a[i] && a[i] > a[i + 1]) ans++;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256