akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lsb(x) (x & (-x))

using namespace std;



int main() {
#ifdef HOME
	ifstream cin("C.in");
	ofstream cout("C.out");
#endif
	int i, na, nb, m;
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> na >> nb >> m;
	vector <int> a(na), b(nb);
	int mna = 2e9, mnb = 2e9;
	for(i = 0; i < na; i++) {
		cin >> a[i];
		mna = min(mna, a[i]);
	}
	for(i = 0; i < nb; i++) {
		cin >> b[i];
		mnb = min(mnb, b[i]);
	}
	int ans = mna + mnb;
	while(m--) {
		int x, y, z; cin >> x >> y >> z;
		x--, y--;
		ans = min(ans, a[x] + b[y] - z);
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#define max 26
#define NIL -1

typedef struct{
    int parent,left,right;
}NODE;

NODE T[max];
int Max(int a,int b){
    if(a>b)return a;
    else return b;
}
int depth(int i){
    int d=0;
    while(T[i].parent!=NIL){
        i=T[i].parent;
        d++;
    }
    return d;
}
int height(int i){
    int h1=0,h2=0;
    if(T[i].left!=NIL){
        h1=height(T[i].left)+1;
    }
    if(T[i].right!=NIL){
        h2=height(T[i].right)+1;
    }
    return Max(h1,h2);
}

int main(){
    int n,i;
    scanf("%d",&n);
    for(i=0;i<=n-1;i++){
        T[i].parent=NIL;
    }
    for(i=0;i<=n-1;i++){
        int id,l,r;
        scanf("%d %d %d",&id,&l,&r);
        T[id].left=l,T[id].right=r;
        if(l!=NIL)T[l].parent=id;
        if(r!=NIL)T[r].parent=id;
    }
    
    for(i=0;i<=n-1;i++){
        printf("node %d: parent = %d, sibling = ",i,T[i].parent);
        if(T[i].parent==NIL)printf("-1");
        else if(T[T[i].parent].left==i)printf("%d",T[T[i].parent].right);
        else printf("%d",T[T[i].parent].left);
        printf(", degree = ");
        if(T[i].left==NIL && T[i].right==NIL)printf("0");
        else if (T[i].left!=NIL && T[i].right!=NIL)printf("2");
        else printf("1");
        printf(", depth = %d, height = %d, ",depth(i),height(i));
        if(T[i].parent==NIL)printf("root\n");
        else if(T[i].left==NIL && T[i].right==NIL) printf("leaf\n");
        else printf("internal node\n");
    }
    
    
    return 0;
}

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

int main() {
    int n, pred, min;
    cin >> n;
    cin >> pred;
    min = pred;
    bool y = true;
    for (int i=0; i<n-1; i++)
    {
        int curr;
        cin >> curr;
        if (curr > pred)
            min = curr - 1;
        if (pred - 1 > curr)
            y = false;
        if (curr < min)
            y = false;
        pred = curr;
    }
    cout << (y?"Yes":"No");
    return 0;
}

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

typedef long long ll;
const int mod = 1000000007;

int main()
{
	ios_base::sync_with_stdio(false);
	string s;
	cin>>s;
	int n = s.size();
	ll dp[n][13];
	memset(dp,0,sizeof(dp));
	if(s[0]=='?')
	{
		for(int i=0;i<10;i++)
			dp[0][i]=1;
	}
	else
		dp[0][s[0]-'0']=1;
	
	for(int i=1;i<n;i++)
	{
		ll temp = s[i]-'0';
		if(s[i]=='?')
		{
			for(int j=0;j<10;j++)
			{
				temp=j;
				for(int k=0;k<13;k++)
				{
					dp[i][(k*10 + temp)%13]+=dp[i-1][k];
					dp[i][(k*10 + temp)%13]%=mod;
				}
			}
		}
		else
		{
			for(int j=0;j<13;j++)
			{
				dp[i][(j*10 + temp)%13]+=dp[i-1][j];
				dp[i][(j*10 + temp)%13]%=mod;
			}
		}
	}
	cout<<dp[n-1][5]<<"\n";
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define PN 6700417 

int main(){
    int i;
    //入力
    long long n;
    cin>>n;
    //処理
    if(n%2==1){
        cout<<0<<endl;
        exit;
    }else{
    
    long long ans=0;
    do{
        n=n/5;
        ans+=n/2;
    }while(n>5);
    //出力
    cout<<ans<<endl;
    }
}

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

int main(){
  int i,a,b,c,count;
  count = 0;
  cin >> a >> b >> c;

  for(i=a;i<=b;i++){
    if(c%i==0){
      count++;
    }
  }
  cout << count	<< endl;

  return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int  main()
{
	int n, d; cin >>  n >> d;
	int range = d *2 + 1;
	if (n % range == 0)
		cout << n / range << endl;
	else 
		cout << (n / range) + 1 << endl;
	return (0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

int main(){
	int a, b;
	scanf("%d%d", &a, &b);
	printf("%s\n", a * b % 2 == 1 ? "Yes" : "No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define vin vector<int>
#define vcn vector<char>
#define ver pair<int,int>
#define pb push_back
#define ld long double
#define x first
#define y second
#define blush fflush(stdout);fflush(stdin);
#define $(a) (int)a.size()
#define scanf ;
#define printf ;
using namespace std;
void i_love_misaka_mikoto();
int32_t main(){
    #ifdef RNS
        freopen("input.txt","r",stdin);
        #ifndef DBG
            freopen("output.txt","w",stdout);
        #endif
    #else
        ios_base::sync_with_stdio(false);
    #endif
    i_love_misaka_mikoto();
    #ifdef RNS
        cout<<'\n'<<(ld)clock()/CLOCKS_PER_SEC<<'\n';
    #endif
    return 0;
}

void i_love_misaka_mikoto(){
    int n, k;
    cin>>n>>k; 
    vin in(n);
    for(int&i:in)cin>>i;
    vin sp(n,1e10);
    sp[0]=0;
    for(int i=1;i<n;i++){
        for(int j=i-1;j>=max(i-k,0LL);j--)sp[i]=min(sp[i],sp[j]+abs(in[j]-in[i]));
    }
    cout<<sp[n-1];
}

Measured memory_bytes: 1792
def search(N, M, adj):
    reachable = [[set() for i in range(N)] for _ in range(N)]
    reachable[0] = adj
    start = -1
    for m in range(1, N):
        prev = reachable[m-1]
        cur = reachable[m]
        #        for i in range(N):
        #            cur[i] = set(prev[i])
        for i in range(N):
            for nxt in adj[i]:
                for p in prev[nxt]:
                    cur[i].add(p)
                if i in prev[nxt]:
                    return (i, reachable, m+1)
    return None


def main():
    N, M = map(int, input().split())
    adj = [set() for _ in range(N)]
    for _ in range(M):
        A, B = map(int, input().split())
        adj[A-1].add(B-1)
    result = search(N, M, adj)
    if not result:
        print(-1)
        return
    start, reachable, cnt = result
    ans = [-1] * cnt
    x = start
    for i in range(cnt):
        ans[i] = x+1
        for nxt in adj[x]:
            if start in reachable[cnt-i-2][nxt]:
                x = nxt
                break
    print(len(ans))
    for a in ans:
        print(a)


if __name__ == "__main__":
    main()


Measured memory_bytes: 240860
using System;
using System.Linq;
using System.Numerics;
using System.Collections;
using System.Collections.Generic;

public class Program {
    static long ncm(int n, int m) {
        long r = 1;
        for (int i = 1; i < m+1; ++i, --n) {
            r *= n;
            r /= i;
        }
        return r;
    }
    
    static void Main(string[] args) {
        int N, A, B;
        string[] s = Console.ReadLine().Split(' ');
        N = int.Parse(s[0]);
        A = int.Parse(s[1]);
        B = int.Parse(s[2]);
        List<long> v = new List<long>();
        foreach (var i in Console.ReadLine().Split()) { v.Add(long.Parse(i)); }
        v.Sort();
        v.Reverse();
        decimal d = (decimal)v.GetRange(0, A).Sum() / A;
        long cnt = 0;
        for (int i=A; i<B+1 && d == (decimal)v.GetRange(0, i).Sum() / i; ++i) {
            long a = 1;
            List<long> l = v.GetRange(0, i);
            foreach (var j in new HashSet<long>(l)) {
                int n = v.Where(x => x == j).Count();
                int m = l.Where(x => x == j).Count();
                a *= ncm(n, m);
            }
            cnt += a;
        }
        Console.WriteLine(d);
        Console.WriteLine(cnt);
    }
}

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

int main(){
  int H,W;
  cin >> H >> W;
  vector<vector<char>> a(H,vector<char> (W));
  int i,j = 0;
  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      cin >>a.at(i).at(j);
    }
  }
  
  vector<bool> row(H,false);
  vector<bool> col(W,false);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(a.at(i).at(j)=='#'){
        row.at(i)=true;
        col.at(j)=true;
      }
    }
  }
  for(int i=0;i<H;i++){
    if(row.at(i)){
      for(int j=0;j<W;j++){
        if(col.at(j)==true)
          cout << a.at(i).at(j);
      }
    }
    cout << endl;
  }
  
  
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 80
#define M 320
#define LL long long
#define INF 1e18
#define Gmax(x,y) (x<(y)&&(x=(y)))
#define Gmin(x,y) (x>(y)&&(x=(y)))
using namespace std;
int n,m,L[N+5],R[N+5],U[N+5],D[N+5];
struct Jewel {int x,y;LL v;}s[N+5];struct Data {char op;int x,y;}p[M+5];
template<int PS,int ES> class MinCostMaxlow
{
	private:
		#define E(x) ((((x)-1)^1)+1)
		#define S (4*n+1)
		#define T (4*n+2)
		int ee,lnk[PS+5];struct edge {int to,nxt,F;LL C;}e[2*ES+5];
		int p[PS+5],IQ[PS+5],F[PS+5];LL C[PS+5];queue<int> q;
		I bool SPFA()
		{
			RI i,k;for(i=0;i<=4*n+2;++i) F[i]=1e9,C[i]=-INF;q.push(S),C[S]=0;
			W(!q.empty()) for(i=lnk[k=q.front()],q.pop(),IQ[k]=0;i;i=e[i].nxt)
			{
				if(!e[i].F||C[k]+e[i].C<=C[e[i].to]) continue;
				C[e[i].to]=C[k]+e[p[e[i].to]=i].C,F[e[i].to]=min(F[k],e[i].F),
				!IQ[e[i].to]&&(q.push(e[i].to),IQ[e[i].to]=1);
			}return F[T]!=1e9;
		}
	public:
		I void Clear() {ee=0,memset(lnk,0,sizeof(lnk));}
		I void Add(CI x,CI y,CI f,Con LL& c)
		{
			e[++ee].nxt=lnk[x],e[lnk[x]=ee].to=y,e[ee].F=f,e[ee].C=c,
			e[++ee].nxt=lnk[y],e[lnk[y]=ee].to=x,e[ee].F=0,e[ee].C=-c;
		}
		I LL MCMF(RI k)
		{
			RI x;LL t=0;W(SPFA())
			{
				k-=F[T],t+=C[T]*F[T],x=T;
				W(x^S) e[p[x]].F-=F[T],e[E(p[x])].F+=F[T],x=e[E(p[x])].to;
			}return k?0:t;
		}
};MinCostMaxlow<4*N+2,3*N+2*N*N> F;
int main()
{
	RI i,j,k;for(scanf("%d",&n),i=1;i<=n;++i) scanf("%d%d%lld",&s[i].x,&s[i].y,&s[i].v);
	for(scanf("%d",&m),i=1;i<=m;++i) cin>>p[i].op,scanf("%d%d",&p[i].x,&p[i].y);
	LL ans=0;for(i=1;i<=n;++i)
	{
		for(j=1;j<=i;++j) L[j]=D[j]=0,R[j]=U[j]=100;for(j=1;j<=m;++j) switch(p[j].op)
		{
			case 'L':p[j].y<i&&Gmax(L[p[j].y+1],p[j].x+1);break;
			case 'R':p[j].y<i&&Gmin(R[i-p[j].y],p[j].x-1);break;
			case 'D':p[j].y<i&&Gmax(D[p[j].y+1],p[j].x+1);break;
			case 'U':p[j].y<i&&Gmin(U[i-p[j].y],p[j].x-1);break;
		}
		for(j=2;j<=i;++j) Gmax(L[j],L[j-1]),Gmax(D[j],D[j-1]);
		for(j=i-1;j;--j) Gmin(R[j],R[j+1]),Gmin(U[j],U[j+1]);F.Clear();
		for(j=1;j<=n;++j) F.Add(j,n+j,1,s[j].v);for(j=1;j<=i;++j) F.Add(S,2*n+j,1,0),F.Add(3*n+j,T,1,0);
		for(j=1;j<=i;++j) for(k=1;k<=n;++k) L[j]<=s[k].x&&s[k].x<=R[j]&&(F.Add(2*n+j,k,1,0),0);
		for(j=1;j<=i;++j) for(k=1;k<=n;++k) D[j]<=s[k].y&&s[k].y<=U[j]&&(F.Add(n+k,3*n+j,1,0),0);
		ans=max(ans,F.MCMF(i));
	}return printf("%lld\n",ans),0;
}

Measured memory_bytes: 4160
//IOI 2021

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

#define pb push_back
#define ff first
#define ss second

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

int n;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= 9; i++)
		if (n % i == 0 && n / i < 10)
			return cout << "Yes" << endl, 0;
	cout << "No" << endl;
	return 0;
}


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

using namespace std;

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

#define INF (1e9)

int main() {

  int N; cin >> N;
  vector<vector<int>> v(N, vector<int>(N));
  rep(i, N) rep(j, N) {
    cin >> v[i][j];
  }
  
  vector<int> V(N);
  iota(V.begin(), V.end(), 0);
  
  priority_queue<pair<int, vector<int>>,
		 vector<pair<int, vector<int>>>,
		 greater<pair<int, vector<int>>>> q;
  map<vector<int>, int> mp;
  mp[V] = 0;
  q.emplace(0, V);
  while(!q.empty()) {
    int co; vector<int> V; tie(co, V) = q.top(); q.pop();
    
    rep(i, N) REP(j, i+1, N) {
      swap(V[i], V[j]);
      if(mp.find(V) != mp.end() && mp[V] <= co + v[V[i]][V[j]]) {
	swap(V[i], V[j]);
	continue;
      }

      mp[V] = co + v[V[i]][V[j]];
      q.emplace(co + v[V[i]][V[j]], V);
      swap(V[i], V[j]);
    }
  }
  
  int ans = 0;
  
  for(auto && e: mp) {
    ans = max(ans, e.second);
  }

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

Measured memory_bytes: 12440
#include <iostream>
#include <limits>

int main() {
	std::int16_t A, B, C, D;

	std::cin >> A >> B >> C >> D;

	std::int16_t start = std::max(A, C);
	std::int16_t end   = std::min(B, D);
	std::cout << (end - start < 0 ? 0 : end - start) << std::endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            for(int i = 3; i <= N; i++)
            {
                bool a = false;
                string str = i.ToString();
                for(int j = 0; j < str.Length; j++)
                {
                    if (str[j] == '3')
                    {
                        Console.Write(" " + i);
                        a = true;
                        break;
                    }
                }
                if (i % 3 == 0 && a == false)
                {
                    Console.Write(" " + i);
                }
            }
            Console.WriteLine();
        }
    }
}

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

const int maxn=1e5+5;
char s[10];
int main()
{
    scanf("%s",s);
    if(s[0]=='S')
        printf("Cloudy");
    else if(s[0]=='C')
        printf("Rainy");
    else if(s[0]=='R')
    printf("Sunny");
    return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
p = [int(i) for i in input().split()]
xy = []

for _ in range(M):
    xy.append(list(map(int,input().split())))

class UnionFind:
    def __init__(self,N):
        self.parent = [i for i in range(N)]
        self.rank = [0] * N
    def root(self,a):
        if self.parent[a] == a:
            return a
        else:
            self.parent[a] = self.root(self.parent[a])
            return self.parent[a]
    def is_same(self,a,b):
        return self.root(a) == self.root(b)
    def unite(self,a,b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb: return
        if self.rank[ra] < self.rank[rb]:
            self.parent[ra] = rb
        else:
            self.parent[rb] = ra
            if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1

uf = UnionFind(N+1)
for x,y in xy:
    uf.unite(x,y)
count = 0
for i in p:
    if uf.is_same(i,p[i-1]):
        count += 1
print(count)

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

using namespace std;

#define ll long long

#define all(x) x.begin(), x.end()

const int mod = 998244353;

int main(){

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

	#ifdef Cyborg101
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int n, m;
	cin >> n;
	map<int, int> mp;
	for(int i = 0, x; i < n; ++i){
		cin >> x;
		mp[x]++;
	}

	cin >> m;
	for(int i = 0, x; i < m; ++i){
		cin >> x;
		if(!mp[x]){
			puts("NO");
			return 0;
		}
		mp[x]--;
	}

	puts("YES");
}

Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

int main(){
	int N,M;
	cin>>N>>M;
	vector<int> X(M);
	vector<int> dis(M-1);
	for(int i=0;i<M;i++){
		cin>>X[i];
	}
	sort(X.begin(),X.end());
	for(int i=0;i<M-1;i++){
		dis[i]=X[i+1]-X[i];
	}
	sort(dis.begin(),dis.end());
	long long cnt=0;
	for(int i=0;i<M-N;i++){
		cnt+=dis[i];
	}
	cout<<cnt<<endl;
	
	return 0;
}


Measured memory_bytes: 1024
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        s: Chars,
    }

    let mut zero_count = 0;
    let mut one_count = 0;
    for c in s {
        match c {
            '0' => {
                zero_count += 1;
            },
            '1' => {
                one_count += 1;
            },
            _ => {},
        }
    }

    let ans = std::cmp::min(zero_count, one_count) * 2;
    
    println!("{}", ans);
}

Measured memory_bytes: 2484
#include <iostream>
#include <algorithm>
#define MAX_N 100000

typedef long long ll;
using namespace std;

int n;
ll a[MAX_N + 1], b[MAX_N];

void solve()
{
    ll res = 0, tmp = 0;
    for (int i = 0; i < n; i++)
    {
        // i番目の勇者が余力を残さないとき
        if (a[i] >= (b[i] + tmp))
        {
            res += b[i] + tmp;
            tmp = 0; // i+1番目に助太刀できない
        }
        else
        {
            res += a[i];
            tmp = min(b[i], min(a[i + 1], b[i] + tmp - a[i]));
        }
    }
    // n+1番目の街はn番目の勇者の余力で倒す
    res += tmp;

    cout << res << endl;
}

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

    solve();
}


Measured memory_bytes: 1792
w,h,n = map(int,input().split())
x=[]
for i in range(n):
    x.append(list(map(int,input().split())))
#x軸の最小を求める(a=1のときの最大のxと同義）
Xmin = 0
for xi in range(n):
    if x[xi][2] == 1:
        Xmin =max(Xmin,x[xi][0])
#x軸の最大を求める(a=2のときの最小のxと同義）
Xmax = w
for xj in range(n):
    if x[xj][2]==2:
        Xmax =min(Xmax,x[xj][0])
#y軸の最小を求める(a=3のときの最大のyと同義）
Ymin = 0
for yi in range(n):
    if x[yi][2] == 3:
        Ymin =max(Ymin,x[yi][1])
#y軸の最大を求める(a=4のときの最小のyと同義）
Ymax = h
for yj in range(n):
    if x[yj][2]==4:
        Ymax =min(Ymax,x[yj][1])
S=print((Xmax-Xmin)*(Ymax-Ymin)*(Xmax>Xmin)*(Ymax>Ymin))

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>

using ll = long long;
using p = std::pair<ll, ll>;
ll n, m;


int main(){
    std::cin >> n >> m;
    std::vector<p> H(n);
    std::vector<ll> originH(n);
    for(int i = 0; i < n; i++){
        std::cin >> H[i].first;
        originH[i] = H[i].first;
        H[i].second = i;
    }
    
    std::vector<std::vector<ll>> adj(n);
    for(int i = 0; i < m; i++){
        ll a, b;
        std::cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    std::sort(H.begin(), H.end(), std::greater<p>());

    std::vector<bool> isGood(n, true);
    for(int i = 0; i < n; i++){
        ll h = H[i].first;
        ll k = H[i].second;
        if(!isGood[k]) continue;
        bool flag = true;
        for(int j = 0; j < adj[k].size(); j++){
            ll next = adj[k][j];
            ll nextH = originH[next];
            if(h > nextH){
                isGood[next] = false;
            }else{
                flag = false;
            }
        }

        if(!flag){
            isGood[k] = false;
        }
    }

    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(isGood[i]) cnt++;
    }

    std::cout << cnt << std::endl;
    return 0;
}


Measured memory_bytes: 11444
#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);
    }

    vector<int> A_diff(N);
    A_diff.at(0) = (K - A.at(N - 1)) + A.at(0);
    for (int i = 0; i < N - 1; i++)
    {
        A_diff.at(i + 1) = A.at(i + 1) - A.at(i);
    }
    sort(A_diff.begin(), A_diff.end());
    cout << K - A_diff.at(N - 1) << endl;
}


Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		char[] s = sc.next().toCharArray(), t = sc.next().toCharArray();
		Arrays.sort(s);
		Arrays.sort(t);
		ArrayUtils.reverse(t);
		int compared = String.valueOf(s).compareTo(String.valueOf(t));
		System.out.println(compared < 0 ? "Yes" : "No");
	}

	static class ArrayUtils {
		static void reverse(char[] array) {
			for (int i = 0; i < array.length / 2; i++) {
				char tmp = array[i];
				array[i] = array[array.length - i - 1];
				array[array.length - i - 1] = tmp;
			}
		}
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int h, w ;
 cin >> h >> w;
  vector<vector<char>> data(h,vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> data.at(i).at(j);
    }
  }
   for (int i = 0; i <2*h; i++) {
     int x =i/2;
    for (int j = 0; j < w; j++) {
     cout << data.at(x).at(j);
    }
     cout <<endl;
  }
  
 
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if (n == 1) {
			System.out.println("Hello World");
		} else {
			int A = sc.nextInt();
			int B = sc.nextInt();
			System.out.println(A + B);
		}
	}
}


Measured memory_bytes: 22996
s = int(input())
a = [s]
for i in range(2, 10000000):
    if a[i-2]%2 == 1:
        tmp = 3 * a[i-2] + 1
        if tmp in a:
            ans = i
            break
        else:
            a.append(tmp)
    else:
        tmp = a[i-2] // 2
        if tmp in a:
            ans = i
            break
        else:
            a.append(tmp)
print(ans)

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

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

    vector<int64_t> a(n);
    vector<int64_t> num_list(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        num_list[a[i] - 1]++;
    }

    int64_t ans_total = 0;
    for(int i = 0; i < n; i++) {
        ans_total += num_list[i]*(num_list[i] - 1)/2;
    }

    for(int i = 0; i < n; i++) {
        cout << ans_total - num_list[a[i] - 1] + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vi vector <ll> 
#define qu queue <ll>
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

double pi = 3.14159265359;
const ll INF = 1e9;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


void solve()
{
    ll h, n; cin >> h >> n;
    vector <pair<ll,ll>> v;
    for (ll i=0; i<n; i++) {
        ll a1,b; cin >> a1 >> b;
        v.pb(mp(a1,b));
    }
    vector <ll> dp(h+5,INF);
    dp[0]=0;
    for (ll i=1; i<=h; i++) {
        for (ll j=0; j<n; j++) {
            if (v[j].first>=i) dp[i] = min(dp[i],v[j].second);
            else dp[i] = min(dp[i],dp[i-v[j].first]+v[j].second);
        }
    }
    nout(dp[h]);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d,e,f,g;
  cin>>a>>b>>c>>d>>e;
  if(b%d)f=b/d+1;
  else f=b/d;
  if(c%e)g=c/e+1;
  else g=c/e;
  cout<<a-max(f,g)<<endl;
}

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

using namespace std;


#define MAXN 200001
vector<int> g[MAXN];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  set<int> s1(g[1].begin(), g[1].end());
  set<int> s2(g[n].begin(), g[n].end());
  int da = 0;
  for (auto u : s1) {
    da |= s2.count(u);
  }
  if (da) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 21360
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n;
  long long int k;
  cin>>n>>k;
  long long int m=1000000007;
  long long int sum=0;
  for(int i=k;i<=n+1;i++)
  {
    sum=(sum%m + (n%m*i%m)%m - (i%m*i%m)%m + i%m + 1)%m;
  }
  cout<<sum%m;
}

Measured memory_bytes: 3632
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner scan = new Scanner(System.in);

		String s = scan.next();

		if(s.equals("ABC")) {
			System.out.println("ARC");

		}else if(s.equals("ARC")) {

			System.out.println("ABC");
		}

	}

}


Measured memory_bytes: 26912
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

int main(){
    int m;

    vector<int> X;
    long long int ans=(1e18)+1;

    int C;
    int i;
    cin >> m ;
    long long int sum=0;

    X.resize(m);

    for(i=0;i<m;i++){
        cin >> X.at(i);
    }

    sort(X.begin(),X.end());

    int a=X.front(); //最初を格納
    int b=X.back(); //最後を格納

    for (C=a;C<=b;C++) { //話を計算
        sum = 0;
        for(i=0;i<X.size();i++){
            sum+=pow(X[i]-C,2);
        }
        ans = min(sum,ans);
    }
    cout << ans << endl;


}


Measured memory_bytes: 256
x = True
s_list = []
while x == True:
    s_list.append(input().split())
    if s_list[-1][1] == '?':
        x = False

a_list = []
for i in range(len(s_list)-1):
    if s_list[i][1] == '+':
        ans = int(s_list[i][0]) + int((s_list[i][2]))
        a_list.append(ans)
    elif s_list[i][1] == '-':
        ans = int(s_list[i][0]) - int((s_list[i][2]))
        a_list.append(ans)
    elif s_list[i][1] == '*':
        ans = int(s_list[i][0]) * int((s_list[i][2]))
        a_list.append(ans)
    elif s_list[i][1] == '/':
        ans = int(s_list[i][0]) // int((s_list[i][2]))
        a_list.append(ans)

for a in a_list:
    print(a)


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

int main(){
    string N;
    cin >> N;
    char fin = N[N.size() -1];
    if(fin == '3') cout <<"bon"<<endl;
    else if(fin == '0' or fin == '1' or fin == '6' or fin == '8') cout << "pon"<<endl;
    else cout<<"hon"<< endl;
}

Measured memory_bytes: 3552
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 200005;
const int MM = 1000000007;

map<vector<ll>, vector<pll>> X;
int N;
ll K;

bool update(vector<pll> &L, pll c){
	for(pll e : L) if( e.first <= c.first && c.second <= e.second ) return false;
	vector<pll> X;
	L.push_back(c);
	sort(L.begin(), L.end());
	for(pll e : L){
		ll lst = 0;
		while(X.size() && e.first <= X.back().second+1 ){
			e.second = max(e.second, X.back().second);
			e.first = X.back().first;
			X.pop_back();
		}
		X.push_back(e);
	}
	swap(X, L);
	return true;
}

void dfs(vector<ll> &P, ll K){
	vector<ll> Q;
	for(int i = 0; i+1 < P.size(); i++) Q.push_back(P[i+1] - P[i]);

	ll mn = P[0];
	for(ll c : P) mn = min(mn, c);
	if( !update(X[Q], pll(max(0ll, mn-K),mn)) ) return;

	if( K < 1) return;
	vector<ll> R;
	for(ll c : P) R.push_back(c/2);
	dfs(R, K-1);
	
	if( K < 2) return;
	for(int i = 0; i < N; i++){
		if( P[i] <= 0 ) return;
		R[i] = (P[i]-1)/2;
	}
	dfs(R, K-2);
}

int main()
{
	scanf("%d%lld", &N, &K);
	vector<ll> P;
	for(int i = 1; i <= N; i++){
		ll a;
		scanf("%lld", &a);
		P.push_back(a);
	}
	dfs(P, K);
	ll ans = 0;
	for(auto e : X){
		for(pll c : e.second){
			ans = (ans + c.second - c.first + 1) % MM;
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 17920
#include<iostream>
#include<vector>
#include<map>
using namespace std;
long long n,a[100100],ans;
vector<long long> v;
map<long long,long long> m;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		m[a[i]]=i;
	}
	v.push_back(-1);
	v.push_back(-1);
	v.push_back(n);
	v.push_back(n);
	for(int i=n;i>=1;i--)
	{
		long long l=0,r=v.size(),w;
		while(r-l!=1)
		{
			w=(l+r)/2;
			if(v[w]>m[i])
				r=w;
			else
				l=w;	
		}
		w=(l+r)/2;
		ans+=((v[w+2]-v[w+1])*(m[i]-v[w])+(v[w]-v[w-1])*(v[w+1]-m[i]))*i;
		v.insert(v.begin()+w+1,m[i]);
	}	
	cout<<ans<<endl;
}
/*
141
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
141
*/

Measured memory_bytes: 8444
#include<stdio.h>
#include<math.h>
int main()
{
long long int a,b,ans,mod,i,modp[200001];
  scanf("%lld %lld",&a,&b);
  mod=pow(10,9)+7;
  modp[0]=1;
  for(i=1;i<200001;++i)
  {
  modp[i]=(modp[i-1]*i)%mod;
  }
  ans=(modp[a]*modp[b])%mod;
  if(llabs(a-b)>1) printf("0");
  else if(a==b) printf("%lld",(ans*2)%mod);
  else printf("%lld",ans);
return 0;}

Measured memory_bytes: 3268
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
using namespace std;

int main() {
	ll t;
	//cin>>t;
	t=1;
	while(t--){
	    ll n,k;
	    cin>>n>>k;
 
        cout<<n*k<<endl;
	}
    
}

Measured memory_bytes: 3636
fun main(args: Array<String>) {
  var (N, K) = readLine()!!.split(" ").map { it.toLong() }
  val A = readLine()!!.split(" ").map { it.toLong() }.sorted()
  val F = readLine()!!.split(" ").map { it.toLong() }.sortedDescending()

  var min = -1L
  var max = 1000000000000L
  while (min + 1 < max) {
    val mid = (min + max) / 2
    var sum = 0L
    for (i in 0 until N.toInt()) {
      if (A[i] * F[i] > mid) sum += (A[i] - mid / F[i])
    }
    if (sum <= K) max = mid else min = mid
  }
  println(max)
}


Measured memory_bytes: 114592
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int Z = sc.nextInt();
		int count =0;
		for (int i=Y+2*Z;i<=X;i+=Y+Z) {
			count ++;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 35832
N, M, Q = map(int, input().split())
X = []
for _ in range(Q):
    a, b, c, d = map(int, input().split())
    X.append((a, b, c, d))

def calc(L):
    s = 0
    for a, b, c, d in X:
        if L[b] - L[a] == c: s += d
    return s

def rec(L):
    if len(L) == N + 1:
        return calc(L)
    ma = 0
    for i in range(L[-1], M+1):
        ma = max(ma, rec(L + [i]))
    return ma

print(rec([1]))

Measured memory_bytes: 78488
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

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

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    print(p.first, p.second);
}


int main(){
    ll h,w,k; cin >> h >> w >> k;
    string s[h];
    rep(i,h)cin >> s[i];
    vector<vector<ll>> sum(h+1, vector<ll>(w+1));
    rep(i,h)rep(j,w){
        sum[i+1][j+1] = sum[i][j+1] + sum[i+1][j] - sum[i][j] + (s[i][j] - '0');
    }
    auto f = [&](int sx, int sy, int gx, int gy){
        return sum[gx][gy] - sum[gx][sy] - sum[sx][gy] + sum[sx][sy];
    };

    // print(sum);

    ll ans = INF;
    rep(i,(1LL << (h-1))){
        ll sy = 0;
        ll sx = 0, gx = 1;
        ll temp = 0;
        bool ok = true;
        reps(gy, w){
            rep(j,h-1){
                if((i >> j) & 1){
                    gx = j+1;
                    if(f(sx,sy,gx,gy) > k){
                        if(sy == gy-1)ok = false;
                        temp++;
                        sy = gy-1;
                        // debug(i);debug(gy);
                    }
                    sx = gx;
                }
            }
            if(f(sx,sy,h,gy) > k){
                if(sy == gy-1)ok = false;
                sy = gy-1;
                temp++;
                // debug(i);debug(gy);
            }
            sx = 0;
        }
        
        if(ok){
            // debug(i);debug(temp);
            chmin(ans, __builtin_popcountll(i) + temp);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define fill(a,val) memset(a, (val), sizeof a)
#define pb push_back
#define lli long long int
#define scantype int
#define endl "\n"
#define unique(x) x.erase(unique(x.begin(),x.end()), x.end())
#define debug(x) cerr << #x " = " << (x) << '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
 
lli MOD  = 1000000007;
lli inf = 1e15;
 
void scan(scantype &x);

lli powermod(lli _a,lli _b,lli _m){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
lli string_to_number(string s){lli x=0; stringstream convert(s); convert>>x; return x;}
lli add(lli a,lli b){lli x = (a+b)%MOD; return x; }
lli mul(lli a,lli b){lli x = (a*b)%MOD; return x; }
lli sub(lli a,lli b){lli x = (a-b+MOD)%MOD; return x; }
lli div(lli a,lli b){lli x = a;lli y = powermod(b,MOD-2,MOD);lli res = (x*y)%MOD;return res;}

bool isprime(long long int n)
{
    if(n ==1 )
        return false;
    if(n == 2)
        return true;
    for(long long int i =2;i<=n/i;i++)
    {
        if(n%i == 0)
            return false;
    }
    return true;
}
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    int t;
    t = 1;
    while(t--)
    {
        string s;
        int n;
        cin>>n;
        int c = 0;
        int o = 0;

        cin>>s;
        for(auto i :s)
        {
            if(i == '(')
            {
                o++;
            }
            else
            {
                if( o > 0)
                    o--;
                else
                    c++;
            }
        }
        while(c--)
            cout<<"(";
        cout<<s;
        while(o--)
            cout<<")";
    }    


    
    return 0;    
}
 

void scan(scantype &x)
{
    register int c = getchar(); //for negative/positive
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = getchar());
    if(c=='-') {neg=1;c=getchar();}
    for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}


Measured memory_bytes: 256
// AOJ 1287: Stopped Watches
// 2017.10.28 bal4u@uu

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

typedef struct { int t, id; } T;
T tbl[10000]; int sz;
int min, max;
int a[12][60];
int c[6][3] = {{0,1,2},{0,2,1},{1,0,2},{1,2,0},{2,0,1},{2,1,0}};

void check(int id, int *t)
{
	int i, j, h, m, s, hh;

	for (j = 0; j < 60; j++) for (i = 0; i < 6; i++) {
		h = (t[c[i][0]] + j) % 60, hh = h/5;
		m = (t[c[i][1]] + j) % 60;
		s = (t[c[i][2]] + j) % 60;
		if (a[hh][m] == h) tbl[sz].t = ((hh*60)+m)*60+s, tbl[sz++].id = id;
	}
}

int cmp(T *a, T *b) { return a->t - b->t; }
int main()
{
	int n, i, j, k, d;
	int t[3];
	char f[11];

	for (i = 0; i < 12; i++) for (j = 0; j < 60; j++) a[i][j] = (60*i + j)/12;
	while (scanf("%d", &n) && n > 0) {
		sz = 0;
		for (i = 0; i < n; i++) {
			scanf("%d%d%d", t, t+1, t+2);
			check(i, t);
		}
		qsort(tbl, sz, sizeof(T), cmp);
		d = 0x7fffffff;
		for (i = 0; i < sz; i++) {
			memset(f, 0, sizeof(f)), k = 0;
			for (j = i; j < sz; j++) {
				if (f[tbl[j].id]) continue;
				f[tbl[j].id] = 1;
				if (++k == n) {
					if ((tbl[j].t - tbl[i].t) < d) {
						d = tbl[j].t - tbl[i].t, min = tbl[i].t, max = tbl[j].t;
					}
					break;
				}
			}
		}
		printf("%02d:%02d:%02d %02d:%02d:%02d\n",
		   min/3600, (min/60)%60, min%60, max/3600, (max/60)%60, max%60);
	}
	return 0;
}

Measured memory_bytes: 1844
#include <iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    long long x, y, i;
    cin >> x >> y;

    int ans = 1;
    for (i = x; i * 2 <= y; i *= 2) {
        ans+= 1;
    }
    cout << ans << '\n';
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  string n;
  cin>>n;
  int cnt=0;
  for(auto& x : n){
    cnt+=(x-'0');
    cnt%=9;
  }
  cout<<(cnt%9==0 ? "Yes" : "No")<<'\n';
  return 0;
}


Measured memory_bytes: 3672
<?php
$cards = [];

$n = trim(fgets(STDIN));
for ($i = 0; $i < $n; $i++) {
    $s = trim(fgets(STDIN));

    if (isset($cards[$s])) {
        $cards[$s]++;
    } else {
        $cards[$s] = 1;
    }
}

$n = trim(fgets(STDIN));
for ($i = 0; $i < $n; $i++) {
    $s = trim(fgets(STDIN));

    if (isset($cards[$s])) {
        $cards[$s]--;
    } else {
        $cards[$s] = -1;
    }
}

$max = max($cards);
if ($max > 0) {
    echo $max . PHP_EOL;
} else {
    echo 0 . PHP_EOL;
}

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

void solve () {
    int n;
    cin >> n;
    vector<int> v;
    v.clear();
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if (x % 2 == 0) {
            v.push_back(x);
        }
    }
    for (int i = 0; i < (int)v.size(); ++i) {
        if (v[i] % 3 != 0 && v[i] % 5 != 0) {
            cout << "DENIED\n";
            return;
        }
    }
    cout << "APPROVED\n";
}

int main() {
    solve();
    return 0;
}


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

int main(void) {
  long N, M;
  cin >> N >> M;
  long ans, totyuu;
  if (2*N >= M) {cout << (long)M/2 << endl;}
  else {
    totyuu = (M - 2*N)/4;
    ans = totyuu+N;
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 256
{-#LANGUAGE BangPatterns#-}
module Main where

import Data.Functor
import Control.Monad
import Data.List

main::IO ()
main=do
   (m:n:_)<- map read . words <$> getLine::IO [Int]
   unless (m==0 && n==0) $
     do
       input<-replicateM m (map read . words <$> getLine)::IO [[Int]]
       let input'=zip [1..] (map (length . filter (==1)) $ cross input n)::[(Int,Int)]
           out=unwords . map (show . fst) $ sortBy func input'
       putStrLn out
       main
  where
    func (_,a) (_,b)=case compare a b of
      LT->GT
      EQ->EQ
      GT->LT

cross::[[a]]->Int->[[a]]
cross list n=reverse $ cross' [] list n
  where
    cross'::[[a]]->[[a]]->Int->[[a]]
    cross' v l 0=v
    cross' v l !m=
      let (xs,xss)=(map head l,map tail l) in
      cross' (xs:v) xss (m-1)

Measured memory_bytes: 18404
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

struct aa {
	int x;
	int y;
	int time;

	const bool operator<(const aa&a)const  {
		return time>a.time;
	}
};

int main() {
	int R,C;cin>>R>>C;
	vector<vector<int>>field(R,vector<int>(C,-1));

	int sx,sy,gx,gy;
	for (int i = 0; i < R; ++i) {
		string st;cin>>st;
		for (int j = 0; j < C; ++j) {
			char ch(st[j]);
			switch (ch) {
			case 'S':
				field[i][j] = 2;
				sx = j, sy = i;
				break;
			case 'G':
				field[i][j] = 2;
				gx = j, gy = i;
				break;
			case 'o':
				field[i][j] = 1;
				break;
			case '#':
				field[i][j] = 10000;
				break;
			case '.':
				field[i][j] = 2;
				break;
			case 'x':
				field[i][j] = 100;
				break;
			}
		}
	}
	vector<vector<int>>dp(R,vector<int>(C,10000));
	dp[sy][sx]=0;

	priority_queue<aa,vector<aa>>que;
	que.push(aa{ sx,sy,0 });

	int dx[4] = { -1,0,1,0 };
	int dy[4] = { 0,1,0,-1 };
	while (!que.empty()) {
		auto atop(que.top());
		que.pop();

		int nx=atop.x;
		int ny=atop.y;
		int ntime=atop.time;

		for (int way = 0; way < 4; ++way) {

			bool flag=false;

			int need_time=0;
			for (int dis = 1; dis <= 3; ++dis) {
				int next_x=nx+dx[way]*dis;
				int next_y=ny+dy[way]*dis;
				if (next_x < 0 || next_x >= C || next_y < 0 || next_y >= R) {
					break;
				}
				if(field[next_y][next_x]==10000)break;
				else {
					need_time+=field[next_y][next_x];
				}

				int next_time=ntime+min(need_time,dis+2);

				if (next_time < dp[next_y][next_x]) {
					dp[next_y][next_x]=next_time;
					que.push(aa{ next_x,next_y,next_time });
				}
				
			}
		}

	}

	cout<<dp[gy][gx]<<endl;
	return 0;
}


Measured memory_bytes: 3208
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
 
#define int long long int
#define pb push_back
#define mp make_pair
#define loop(i,x,n) for(int i=x;i<=n;i++)
#define rloop(i,x,n) for(int i=x;i>=n;i--)
#define ff first
#define ss second
#define N4RUTO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 
typedef tree<int, null_type, less<int>, rb_tree_tag,  
tree_order_statistics_node_update>
ordered_set;
 
int32_t main(){
    N4RUTO;
    string s;
    cin>>s;
    deque<char> dq;
    loop(i,0,s.length()-1) dq.push_back(s[i]);
    bool rev = false;
    int t;
    cin>>t;
    while(t--){
        int a;
        cin>>a;
        if(a==1) rev = !rev;
        else{
            int b;
            char c;
            cin>>b>>c;
            if(rev){
                if(b==1) b=2;
                else b=1;
            }
            if(b==1) dq.push_front(c);
            else dq.push_back(c);
        }
    }
    string ans = "";
    if(!rev){
        for(auto it:dq) ans+=it;
    }else{
        for(auto it=dq.rbegin(); it!=dq.rend(); it++) ans+=*it;
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 1368
def yakusuu(n):
    ANS=0
    for i in range(1,n//2+1):
        if n%i==0:
            ANS+=1

    if ANS==7:
        return 1
    else:
        return 0

N=int(input())

ANS=0

for i in range(1,N+1,2):
    if yakusuu(i)==1:
        ANS+=1

print(ANS)


Measured memory_bytes: 2940
N = int(input())
ary = list(map(int, input().split()))
  
sorted_ary = sorted(ary)
d = [a - s for a, s in zip(ary, sorted_ary)]
n = sum([1 for x in d if x != 0])
if n <= 2:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

vector<pair<string, string>> rules;
string s;
string g;
map<string, int> mp;

string getReplacedString(string t, pair<string, string> p) {
    string a, b;
    tie(a, b) = p;

    int i = 0;
    while (i <= (int)t.size() - (int)a.size()) {
        if (t.substr(i, a.size()) == a) {
            t.replace(i, a.size(), b);
            i += b.size();
        } else {
            i++;
        }
    }

    return t;
}

int bfs() {
    mp.clear();
    queue<pair<string, int>> que;
    que.push(make_pair(s, 0));

    while (!que.empty()) {
        string t;
        int c;
        tie(t, c) = que.front(); que.pop();
        if (t == g) break;

        for (const auto &p : rules) {
            string nt = getReplacedString(t, p);
            if (!mp.count(nt) && nt.size() <= g.size()) {
                mp[nt] = c + 1;
                que.push(make_pair(nt, c + 1));
            }
        }
    }

    return (mp.count(g) ? mp[g] : -1);
}

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

    int n;
    int t = 0;
    while (cin >> n, n) {
        rules.clear();
        rep(i, n) {
            string a, b;
            cin >> a >> b;
            rules.emplace_back(a, b);
        }
        cin >> s;
        cin >> g;

        cout << bfs() << endl;
    }
}

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

int main() {
	int n,k; cin >> n >> k;
	int a[200000];
	rep(i,n) cin >> a[i];
	//double hh[200010] = {0};
	//rep(i,k) hh[k] *= double(a[i]) / k;
	for(int i=k; i < n; i++) {
		if (a[i-k] < a[i]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}


}

Measured memory_bytes: 4372
#include<stdio.h>
#define MAX 500000
#define S 2000000000

int L[MAX/2+2],R[MAX/2+2],count;

void merge(int A[],int n, int left,int mid,int right){
 int n1 = mid - left;
  int n2 = right - mid;
  int i,j=0,k;
  // L[0...n1], R[0...n2] を生成                                                
  for(i = 0 ;i<n1;i++)L[i] = A[left + i];
  for (i = 0;i<n2;i++)R[i] = A[mid + i];

  L[n1] = S;
  R[n2] = S;
  i=0;
  for(k = left;k<right;k++){
    count++;
    if(L[i] <= R[j]){
      A[k] = L[i++];

        }
    else {
      A[k] = R[j++];

        }
      }
}

void mergeSort(int A[],int n,int left,int right){
  int mid;
  if(left+1 < right){
    mid = (left + right)/2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);

  }
}

int main(){
  int A[MAX],n,i;
  count=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  mergeSort(A, n, 0, n);


  for(i=0;i<n;i++){
    if(i!=0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",count);

  return 0;

}






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

int main()
{
  std::string r, g, b;
  std::cin >> r >> g >> b;
  int num = std::stoi(r + g + b);
  if ( num % 4 == 0 ) std::cout << "YES\n";
  else std::cout << "NO\n";

  return 0;
}


Measured memory_bytes: 256