akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <utility>
#include <array>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	array<int, 5> H;
	for (;;) {
		array<int, 3> m = {}, r = {3, 3, 3};
		for (int &h: H) {
			if (!(h = in()))
				return 0;
			m[--h]++;
		}
		for (int i = 0; i < 3; i++)
			if (m[i] == 5)
				break;
			else if (m[i] && m[i] + m[(i + 1) % 3] == 5) {
				r[i] = 1, r[++i % 3] = 2;
				break;
			}
		for (int h: H)
			outl(r[h]);
	}
}


Measured memory_bytes: 2524
#include <iostream>
#include <string>
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	//删除最后一个字符的方法
	//1.substr
	//b=b.substr(0,b.size()-1);
	//2.erase函数
	b.erase(b.end()-1); 
	cout<<(a==b?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
using namespace std;

int N;
vector<int> A, T;
typedef pair<int, int> pii;
vector<pii> range;

pii cap(pii a, pii b) {
	if (a == pii(0, -1) || b == pii(0, -1))return pii(0, -1);
	pii c = pii(max(a.first, b.first), min(a.second, b.second));
	if (c.first > c.second)return pii(0, -1);
	else return c;
}

int main() {
	cin >> N;
	for (int n = 0; n < N; n++) {
		int a;
		cin >> a;
		T.push_back(a);
	}
	for (int n = 0; n < N; n++) {
		int a;
		cin >> a;
		A.push_back(a);
	}
	range.resize(N, pii(1, 1e9));
	range[0] = pii(T[0], T[0]);
	for (int n = 1; n < N; n++) {
		if (T[n - 1] != T[n]) {
			range[n] = cap(range[n], pii(T[n], T[n]));
		}
		else {
			range[n] = cap(range[n], pii(1, T[n]));
		}
	}
	range[N - 1] = cap(range[N - 1], pii(A[N - 1], A[N - 1]));
	for (int n = N - 2; n >= 0; n--) {
		if (A[n + 1] != A[n]) {
			range[n] = cap(range[n], pii(A[n], A[n]));
		}
		else {
			range[n] = cap(range[n], pii(1, A[n]));
		}
	}
	long long ans = 1;
	int MOD = 1e9 + 7;
	for (int n = 0; n < N; n++) {
		ans *= (range[n].second - range[n].first + 1);
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1912
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  cin >> n;
  vector<pll> a(n+1);
  for(ll i=0;i<n;i++) cin >> a[i].first,a[i].second=i;
  vec ans(n);
  sort(a.rbegin(),a.rend());
  ll id=inf;
  for(ll i=0;i<n;i++) {
    id=min(id,a[i].second);
    ans[id]+=(i+1)*(a[i].first-a[i+1].first);
  }
  for(ll i=0;i<n;i++) {
    cout << ans[i] << endl;
  }
}

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

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        if (scanner.hasNextLine()) {
            String[] array = scanner.nextLine().split(" ");
            int N = Integer.parseInt(array[0]);

            String[] Xs = scanner.nextLine().split(" ");
            int[] intArray = new int[N];
            int[] intArray2 = new int[N];
            for (int i = 0; i < N; ++i) {
                int w = Integer.parseInt(Xs[i]);
                intArray[i] = w;
                intArray2[i] = w;
            }
            Xs = null;
            Arrays.sort(intArray2);
            int half = intArray2[N / 2 - 1];
            int halfNext =  intArray2[N / 2];
            for (int i = 0; i < N; ++i) {
                if (intArray[i] <= half) {
                    System.out.println(halfNext);
                } else {
                    System.out.println(half);
                }
            }
        }
    }
}

Measured memory_bytes: 78496
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define lla(s) s.rbegin(),s.rend()
#define pcnt(b) __builtin_popcount(b)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int,int>>
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m=0;
    cin>>n;
    vi a(n+1),b(n+1,0),ans;
    rep(i,1,n+1){cin>>a[i];}
    rrep(i,n+1,1){
        int tmp = 0;
        for(int j = i;j <= n;j+=i){
            tmp += b[j];
        }
        if((tmp%2)!=a[i]){b[i]=1;m++;ans.push_back(i);}
    }
    cout<<m<<'\n';
    rep(i,0,m){
        cout<<ans[i];
        if(i!=m-1)cout<<' ';
    }
}

Measured memory_bytes: 5108
import java.util.Scanner;

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

    void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println((b % a == 0 ? a + b : b - a));
    }
}


Measured memory_bytes: 22868
#include <iostream>
using namespace std;
const int N = 100;

int main()
{
	int M[N][N];	// 0 0起点的邻接矩阵
	int n, u, k, v;
	
	cin >> n;
	for(int i = 0; i < n; ++ i)
	{
		for(int j = 0; j < n; ++ j)
		{
			M[i][j] = 0;
		}
	} 
	
	for(int i = 0; i < n; ++ i)
	{
		cin >> u >> k;
		u --;	// 转换为0起点 
		for(int j = 0; j < k; ++ j)
		{
			cin >> v;
			v --;	// 转换为0起点 
			M[u][v] = 1;	// 在u和v之间画出一条边 
		}
	}
	
	for(int i = 0; i < n; ++ i)
	{
		for(int j = 0; j < n; ++ j)
		{
			if(j)	cout << " ";
			cout << M[i][j];
		}
		cout << endl;
	}
	
	return 0;
} 


Measured memory_bytes: 3116
use std::io;


fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();

    buf.split(' ')
        .map(|s| s.trim().parse().unwrap())
        .collect()
}


fn main() {
    let (mut x, y) = {
        let v = read::<i64>();
        (v[0], v[1])
    };

    let mut cnt = 0;
    while x <= y {
        x *= 2;
        cnt += 1;
    }

    println!("{}", cnt);
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

pair<ll, ll> m[200010];

int main() {
	int N;
	ll D, A;
	cin >> N >> D >> A;
	for(int i=0; i<N; ++i){
		ll X, H;
		cin >> X >> H;
		m[i]=make_pair(X, H);
	}
	sort(m, m+N);
	vector<int> num{-1};
	vector<ll> s{0};
	int cnt=1, now=0;
	ll sum=0, ans=0;
	for(int i=0; i<N; ++i){
		int ok=0, ng=cnt;
		while(ok+1<ng){
			int mid=(ok+ng)/2;
			if(num[mid]<=i) ok=mid;
			else ng=mid;
		}
		m[i].second -= sum-s[ok];
		if(m[i].second<=0) continue;
		while(now<N){
			if(m[now].first>m[i].first+D*2) break;
			else ++now;
		}
		ll t=(m[i].second+A-1)/A;
		ans += t;
		num.emplace_back(now);
		s.emplace_back(s[cnt-1]+t*A);
		sum += t*A;
		++cnt;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6124
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>

using namespace std;

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

char C[] = "RYGB";
char A[505][505];

int main()
{
	int H, W, D;
	scanf("%d%d%d", &H, &W, &D);
	if( D%2 == 1 ){
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				printf("%c", C[i%2*2 + j%2]);
			}
			printf("\n");
		}
	}
	else{
		for(int i = -D/2*4; i < H+D/2*10; i += D/2){
			for(int j = -D/2*4; j < W+D/2*10; j += D/2){
				if( (i/(D/2) + j/(D/2) + 20000)%2 == 1 ) continue;
				int v = (i/(D/2) + j/(D/2) + 20000)%4;
				if( i%D ) v |= 1; 
				for(int k = 0; k < D-1; k++){
					for(int l = 0; l < D; l++){
						if( k+l < D/2-1 || k-l < -D/2 || k-l >= D/2 || k+l >= D/2*3-1) continue;
						if( 0 <= i+k && i+k < H && j+l < W && 0 <= j+l ) A[i+k][j+l] = C[v];
					}
				}
			}
		}
		for(int i = 0; i < H; i++) printf("%s\n", A[i]);
	}
	return 0;
}


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

int main() {
  string s,t;
  cin>>s;
  cin>>t;
  int op = 0;
  for(int i = 0; i < s.length(); i++) {
    if(s[i] != t[i])
      op++;
  }
  cout<<op<<endl;
}

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

using namespace std;

int main()
{
	int t;
	t=1;
	while(t--)
	{
	  long long int n,i,j,q;
	  
	  cin>>n;
	  
	  long long int a[100001] {0},b[100001] {0};
	  long long int sum=0;
	  for(i=0;i<n;i++)
	  {
	  	cin>>a[i];
	  	sum=sum+a[i];
	  	b[a[i]]=b[a[i]]+1;
	  	
	  }
   
   
     cin>>q;
     
     long long int x,y;
     for(i=1;i<=q;i++)
     {
      cin>>x>>y;
	  
	  if(b[x]!=0)
	  {
	  sum=sum-b[x]*x+y*b[x];    	
     	
     		b[y]=b[y]+b[x];
     	b[x]=0;
     
     
    }
     	
     	cout<<sum<<endl;
     	
     	
	 }
   
   
   }



}


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


int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int train = min(a, b);
	int bus = min(c, d);
	int ans = train + bus;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> g[205];
char f[205];
int du[205];
int lev[205];
bool vis[205];
int main() {
        int n;
        scanf("%d", &n);
        for (int i = 1; i <= n; i++) {
                scanf("%s", f + 1);
                for (int j = i + 1; j <= n; j++) {
                        if (f[j] == '1') {
                                g[i].push_back(j);
                                g[j].push_back(i);
                                du[i]++, du[j]++;
                        }
                }
        }
        queue<int> que;
        bool flag = 1;
        int ans = -1;
        for (int i = 1; i <= n; i++) {
                //cout << "do " << i << endl;
                fill_n(lev, n + 2, 0);
                fill_n(vis, n + 2, 0);
                flag = 1;
                int ansnow = -1;
                while (que.size()) {
                        que.pop();
                }
                que.push(i);
                lev[i] = 1;
                while (que.size() && flag) {
                        int x = que.front();
                        //cout << x << " " << lev[x] << endl;
                        que.pop();
                        vis[x] = 1;
                        for (int v : g[x]) {
                                if (lev[v] == 0) {
                                        lev[v] = lev[x] + 1;
                                        ansnow = max(ansnow, lev[v]);
                                        que.push(v);
                                } else if (lev[v] == lev[x] || abs(lev[v] - lev[x]) >= 2) {
                                        flag = 0;
                                        break;
                                } else if (abs(lev[v] - lev[x]) == 1) {
                                        if (lev[v] < lev[x] && !vis[v]) {
                                                flag = 0;
                                                break;
                                        }
                                        if (lev[v] > lev[x] && vis[v]) {
                                                flag = 0;
                                                break;
                                        }
                                }
                        }
                }
                if (flag) {
                        ans = max(ans, ansnow);
                }
        }
        cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

int main()
{
	int A = inputValue();
	int B = inputValue();
	int C = inputValue();
	
	int val1 = C - (A - B);
	
	if(val1 < 0){
	    val1 = 0;
	}
	
	cout << val1 << endl;
}


Measured memory_bytes: 256
import queue
n,q=int(input()),queue.Queue()
s=[set() for i in range(n+1)]
for i in range(2*n-2):
	u,v=map(int,input().split())
	if v in s[u]:
		q.put((u,v))
	else:
		s[u].add(v)
		s[v].add(u)
f=[i for i in range(n+1)]
def find(x):
	if f[x]==x:
		return x
	else:
		f[x]=find(f[x])
		return f[x]
while not q.empty():
	u,v=map(find,q.get())
	if u==v:
		continue
	if len(s[u])<len(s[v]):
		u,v=v,u
	s[u].remove(v)
	s[v].remove(u)
	for x in s[v]:
		s[x].remove(v)
		if u in s[x]:
			q.put((u,x))
		else:
			s[u].add(x)
			s[x].add(u)
	s[v],f[v]=[],u
root=find(1)
for i in range(2,n+1):
	if find(i)!=root:
		print("NO")
		break
else:
	print("YES")

Measured memory_bytes: 116508
#2005_c
"""
n = int(input())
k = list("mcxi")
for i in range(n):
    d = {"m":0,"c":0,"x":0,"i":0}
    a,b  = input().split()
    a = list(a)
    b = list(b)
    a.insert(0,1)
    b.insert(0,1)
    for j in range(1,len(a)):
        if a[j] in k:
            if a[j-1] in k:
                d[a[j]] += 1
            else:
                d[a[j]] += int(a[j-1])
    for j in range(1,len(b))[::-1]:
        if b[j] in k:
            if b[j-1] in k:
                d[b[j]] += 1
            else:
                d[b[j]] += int(b[j-1])
            if d[b[j]] >= 10:
                l = b[j]
                while d[l] >= 10:
                    d[l] -= 10
                    l = k[k.index(l)-1]
                    d[l] += 1
    for j in k:
        if d[j]:
            if d[j] == 1:
                print(j,end = "")
            else:
                print(str(d[j])+j,end = "")
    print()
"""

#2017_c
"""
while 1:
    h, w = map(int, input().split())
    if h == w == 0:
        break
    s = [list(map(int, input().split())) for i in range(h)]

    ans = 0
    for u in range(h):
        for d in range(u+2,h):
            for l in range(w):
                for r in range(l+2,w):
                    m = float("inf")
                    for i in range(u,d+1):
                        m = min(m,s[i][l],s[i][r])
                    for i in range(l,r+1):
                        m = min(m,s[u][i],s[d][i])
                    f = 1
                    su = 0
                    for i in range(u+1,d):
                        for j in range(l+1,r):
                            su += (m-s[i][j])
                            if s[i][j] >= m:
                                f = 0
                                break
                        if not f:
                            break
                    if f:
                        ans = max(ans,su)
    print(ans)
"""

#2016_c
"""
while 1:
    m,n = map(int, input().split())
    if m == n == 0:
        break
    d = {}
    ma = 7368791
    for i in range(m,ma+1):
        d[i] = 1
    z = m
    for i in range(n):
        for j in range(z,ma+1):
            if d[j]:
                z = j
                break
        j = 1
        while z*j <= ma:
            d[z*j] = 0
            j += 1
    for j in range(z,ma+1):
        if d[j]:
            print(j)
            break
"""

#2018_c
def factorize(n):
    if n < 4:
        return [1,n]
    i = 2
    l = [1]
    while i**2 <= n:
        if n%i == 0:
            l.append(i)
            if n//i != i:
                l.append(n//i)
        i += 1
    l.append(n)
    l.sort()
    return l
while 1:
    b = int(input())
    if b == 0:
        break
    f = factorize(2*b)
    for n in f[::-1]:
        a = 1-n+(2*b)//n
        if a >= 1 and a%2 == 0:
            print(a//2,n)
            break



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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  //idiots dont even know how coordinates are settled just to make us wronh noobs
  string ans = (abs(c-a) <= d || (abs(b-a) <= d && abs(c-b) <= d)) ? "Yes" : "No";
  cout << ans << endl;
  return 0;
  
}

Measured memory_bytes: 256
#include <iostream>
#define ll long long int
#define N 55
using namespace std;
char s[N][N];
int dir[4][2]={0,1,1,0,0,-1,-1,0};
int a,b; 
bool search(int x,int y){
    for(int i=0;i<4;i++){
         int xx = x+dir[i][0];
         int yy = y+dir[i][1];
         if(xx>=0&&xx<a&&y>=0&&y<b){
             if(s[xx][yy]=='#')
                 return true;
        }
     }
     return false;
 }
 int main(){
     cin>>a>>b;
     for(int i=0;i<a;i++)
         for(int j=0;j<b;j++)
             cin>>s[i][j];
    for(int i=0;i<a;i++){
         for(int j=0;j<b;j++){
            if(s[i][j]=='#'){
                 bool prime = search(i,j);
                 if(!prime){
                     return 0*printf("No\n");
                 }
            }
         }
    }
     printf("Yes\n");
     return 0;
 }

Measured memory_bytes: 3632
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.*;

public class Main {
    public static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }


    }

    public static void main(String[] args) {
        FastReader s = new FastReader();
        Main obj = new Main();

        int n = s.nextInt();
        int k = s.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
        }
        Arrays.sort(arr);
        if (k >= n)
            System.out.println(0);
        else {
            for (int i = n - 1; i > n - k - 1; i--)
                arr[i] = 0;
            long sum = 0;
            for (int i = 0; i < n; i++) {
                sum += arr[i];
            }
            System.out.println(sum);

        }
    }






}

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

int main (void) {
    char s[11] = {'\0'};
    scanf("%s", s);

    int i, atgc_len = 0, max_len = 0;
    for (i = 0; i < strlen(s); i++) {
        if ( s[i] == 'A' || s[i] == 'T' ||
             s[i] == 'G' || s[i] == 'C' ) {
            atgc_len++;
        }
        else {
            if ( atgc_len > max_len ) {
                max_len = atgc_len;
            }
            atgc_len = 0;
        }
    }
    if ( atgc_len > max_len ) {
        max_len = atgc_len;
    }


    printf("%d\n", max_len);
    return 0;
}

Measured memory_bytes: 128
n = int(input())
dic = {}

for i in range(n):
    s = input()
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1

dic = sorted(dic.items())
dic = sorted(dic, key=lambda x: -x[1])
dic.append(('_', 0))
for i in range(n):
    if dic[i][1] == dic[i + 1][1]:
        print(dic[i][0])
    else:
        print(dic[i][0])
        break

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

using namespace std;

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

    int s, t, u, v, cnt = 0;
    for (int i = a; i <= b; i++) {
        s = i % 10;
        t = i / 10000 % 10;
        u = i / 10 % 10;
        v = i / 1000 % 10;

        if (s == t && u == v) cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 2010
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#pragma GCC optimize(2)
#define ll long long
#define makefa(n) for(int i=1;i<=(n);i++)f[i]=i;
#define hh puts("");
#define eps 1e-10
#define db double
#define AC 2333
#define REP(i,n) for((i)=0;(i)<(n);(i)++)
bool ab[maxn+20000],ac[maxn+20000],bc[maxn+20000];
bool match(char c,char d){return c==d||c=='?'||d=='?';}
int main(){
   IOS
   string a,b,c;
   cin>>a>>b>>c;
   int i,j;
   int la=a.size(),lb=b.size(),lc=c.size();
   REP(i,la)REP(j,lb)if(!match(a[i],b[j]))ab[i-j+10000]=true;
    REP(i,la)REP(j,lc)if(!match(a[i],c[j]))ac[i-j+10000]=true;
    REP(i,lb)REP(j,lc)if(!match(b[i],c[j]))bc[i-j+10000]=true;
    int ans=3*maxn;
    for (i = -2*maxn; i <=2*maxn ; ++i) {
        for (j = -2*maxn;  j<=2*maxn ; j++) {
            if(!ab[i+10000] && !ac[j+10000] && !bc[j-i+10000]){
                int l=min(0,min(i,j));
                int r=max(la,max(lb+i,j+lc));
                ans=min(ans,r-l);
            }
        }
    }
    cout<<ans;
    return 0;
}


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


bool eq(vector<int>& a, vector<int>& b) {
	if (a.size() != b.size()) {
		return false;
	}

	for (int i = 0; i < a.size(); ++i) {
		if (a[i] != b[i]) {
			return false;
		}
	}

	return true;
}

vector<int> curr;
vector<bool> u;
int j = 0;
int pos(int n, vector<int>& p, int k = 0) {
	if (k == n) {
		++j;
		if (eq(curr, p)) {
			return j;
		}

		return -1;
	}

	for (int i = 1; i <= n; ++i) {
		if (u[i]) {
			continue;
		}

		curr[k] = i;
		u[i] = true;
		int ans = pos(n, p, k + 1);
		u[i] = false;
		if (ans > -1) {
			return ans;
		}
	}

	return -1;
}

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

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

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

	curr = vector<int>(n, 0);
	u = vector<bool>(n, false);
	j = 0;

	int px = -1;
	for (int i = 1; i <= n; ++i) {
		u[i] = true;
		curr[0] = i;
		px = max(px, pos(n, p, 1));
		u[i] = false;
	}

	curr = vector<int>(n, 0);
	u = vector<bool>(n, false);
	j = 0;

	int qx = -1;
	for (int i = 1; i <= n; ++i) {
		u[i] = true;
		curr[0] = i;
		qx = max(qx, pos(n, q, 1));
		u[i] = false;
	}

	cout << abs(px - qx);
	
	return 0;
}
	

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

using namespace std;  

int main(){
  int N;
  int max_times = 0;
  int max_value = 1;
  cin >> N;
  for (int i = 1; i <= N; i++){
    int times = 0;
    int x = i;
    while (true){
      if(x % 2 != 0){
        if (times > max_times)
        {
          max_value = i;
          max_times = times;
        }
        
        break;
      } 
      ++times;
      x = x/2;
    }
    
  }
  cout << max_value << endl;
  
}

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

int main(){
    string s ,t;
    cin >> s >> t;
    //sを昇順、tを降順に並べて比較すれば良い
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>());
//    cout << s << endl;
//    cout << t << endl;
    if(s < t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}                                                                                                                                                                               

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

int main() {
    int n; cin >> n;
    int cnt = 0;
    for (int i=0; i<n; ++i) {
        int a; cin >> a;
        while (a%2 == 0) {
            cnt++;
            a /= 2;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,temp;
    cin >> n >> x;
    temp=n*500;
    if(temp>=x)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;

}


Measured memory_bytes: 384
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

//同じコードでそんなにばらつくんですか

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzll((tmp & ma0) ^ ma0) : 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	return tmp;
}

bool NG[100001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint(), M = getint();
	int H[100001];
	rep1(i, N) H[i] = getint();
	rep(i, M) {
		int a = getint(), b = getint();
		if (H[a] >= H[b]) NG[b] = 1;
		if (H[a] <= H[b]) NG[a] = 1;
	}
	int kotae = N;
	rep1(i, N) kotae -= NG[i];

	printf("%d", kotae);

	Would you please return 0;
}

Measured memory_bytes: 2172
#include<iostream>
using namespace std;
const int N=100;

void output(int *A,int num){
  int i=0;
  for(;i<num-1;i++){
    cout<<A[i]<<' ';
  }
  cout<<A[i];
  cout<<"\n";
}

void Sort(int *A,int num){
  int v;
  for(int i=1;i<num;i++){
    v=A[i];
    int j=i-1;
    for(;j>=0&&A[j]>v;j--){
      A[j+1]=A[j];
    }
    A[j+1]=v;

    output(A,num);
  }
}

int main(){
  int A[N];
  int num;

  cin>>num;

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

  output(A,num);
  Sort(A,num);

  return 0;
}

  
  
      
  
	





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

int main() {
	int A,B,C,check=0;
	cin >> A >> B >> C;

	if(A==5 && B==5 && C==7) {
		check=1;
	}
	if(A==5 && B==7 && C==5) {
		check=1;
	}
	if(A==7 && B==5 && C==5) {
		check=1;
	}
	if(check==1) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

void trace(int A[], int N){
    int i;
    for(i=0;i<N;i++){
        if(i>0) printf(" ");
        printf("%d", A[i]);
        
    }
    printf("\n");
}

void insertionSort(int A[], int N){
    int j,i,v;
    for(i = 1; i<N;i++){
        v = A[i];
        j = i-1;
        while (j>=0&&A[j]>v){
            A[j+1]=A[j];
            j--;
        }
        A[j+1]=v;
        trace(A,N);
    }
}

int main(){
    int N, i,j;
    int A[100];
    scanf("%d", &N);
    for(i=0;i<N;i++) scanf("%d", &A[i]);
    
    trace(A, N);
    insertionSort(A,N);
    
    return 0;
}


Measured memory_bytes: 2752
#include <bits/stdc++.h> 
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define vbi vector<bool> 
#define mod 1000000007
#define INF 1000000000
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define ms(x,v) memset(x,v,sizeof x)
#define endl '\n'
#define cnl cout<<endl;
#define frr(i,b) for(ll i=0; i<b;i++)
#define fb(i,b) for(ll i=b-1; i>=0; i--)
#define pi  3.141592653589793238
ll i,j,k;
void solve()
{
  ll n; cin>>n;
  bool flag=false;
  for(i=1;i<=9;i++){
    ll x=n/i;
    if(n%i==0 and x<=9){
      flag=true;
      break;
    }
  }
  if(flag==false) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
 
}
signed main(){
   
    solve();

  return 0;
}



Measured memory_bytes: 256
n = int(input())
a = 0
for j in range(n):
  j += 1
  if j % 2 != 0:
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= j:
      if j % i == 0:
        lower_divisors.append(i)
        if i != j // i:
          upper_divisors.append(j//i)
      i += 1
    if len(lower_divisors + upper_divisors[::-1]) == 8:
      a += 1
    lower_divisors.clear
    upper_divisors.clear
print(a)

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

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;



signed main() {
	double a, b, c, d, e, f;
	while (cin >> a >> b >> c >> d >> e >> f) {
		double x = (c - f / e * b) / (a - d / e * b);
		double y = (c - f / d * a) / (b - e / d * a);
		if (e == 0) {
			x = f/d;
			y = (c - a * x) / b;
		}
		if (d == 0) {
			y = f / e;
			x = (c - b * y) / a;
		}
		cout << fixed << setprecision(3) << x << " " << setprecision(3) << y << endl;
	}
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define PI acos(-1.0)

typedef long long ll;
const int maxn=1e5+10;

ll gcd(ll x,ll y)
{
    return x%y==0?y:gcd(y,x%y);
}

ll lcm(ll x,ll y)
{
    return x/gcd(x,y)*y;
}

int main()
{
    int n;
    cin >> n;
    ll sum=1;
    for(int i=0;i<n;i++)
    {
        ll m;
        cin >> m;
        sum=lcm(sum,m);
    }
    cout << sum << endl;
    return 0;
}


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

int main(){
    string s,tmp,s1,s2;
    cin>>s;
    tmp=s;
    reverse(tmp.begin(),tmp.end());
    if(s!=tmp){
        cout<<"No"<<endl;
        return 0;
    }

    s1=s.substr(0,s.size()/2);
    tmp=s1;
    reverse(tmp.begin(),tmp.end());
    if(s1!=tmp){
        cout<<"No"<<endl;
        return 0;
    }

    s2=s.substr(s.size()/+1,s.size()/2);
    tmp=s2;
    reverse(tmp.begin(),tmp.end());
    if(s2!=tmp){
        cout<<"No"<<endl;
        return 0;
    }

    cout<<"Yes"<<endl;

    return 0;
}

Measured memory_bytes: 256
N, x = map(int, input().split())
A = list(map(int, input().split()))

def solve(N,x,A):
    ans = max(A[0]-x,0)
    A[0] -= ans
    for i in range(1,N):
        p = max(A[i]-(x-A[i-1]),0)
        A[i] -= p
        ans += p
    return ans
print(solve(N,x,A))

Measured memory_bytes: 14540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int H, W, K; cin >> H >> W >> K;
    ll mod = 1000000007;
    vector<vector<ll>> dp(H+5, vector<ll>(W+5, 0));
    dp[1][0] = 1;

    //もらうDPで書いてみます
    for(int i=2; i<=H+1; i++){
        for(int j=0; j<W; j++){

            for(int bit=0; bit<1<<(W-1); bit++){
                bool flg = true;
                for(int k=0; k<W-2; k++) if((bit&1<<k) && bit&1<<(k+1)) flg = false;
                if(flg == false) continue;

                if(0<j && bit&1<<(j-1)) dp[i][j] += dp[i-1][j-1]; // 左から来る時
                else if(j<W-1 && bit&1<<j) dp[i][j] += dp[i-1][j+1]; // 右から来る時
                else if((bit&1<<(j-1)) == 0 && (bit&1<<j) == 0) dp[i][j] += dp[i-1][j]; // 真上から来る時

                dp[i][j] %= mod;
            }
        }
    }


    cout << dp[H+1][K-1] << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Arrays;
import java.util.Comparator;
public class Main {    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();        
		int a = sc.nextInt();
        int [] s = new int [n];
        for(int i=0;i<n;i++){s[i]=sc.nextInt();}
        Arrays.sort(s);
        long ans = 0;       
        Data [] d = new Data [a];
        for(int i=0;i<a;i++){int B = sc.nextInt();
                             int C = sc.nextInt();
                             d[i] = new Data(B,C);                            
                            }
        Arrays.sort(d, new Comparator<Data>() {
            public int compare(Data d1, Data d2) {
                return d1.getB() - d2.getB();
            }
        }); 
        int b = a-1;
        int count = 0;
        for(int i=0;i<n;i++){if(b>=0 && d[b].getB()>s[i]){s[i]=d[b].getB();
                                                          count++;                                                 
                                                          if(count==d[b].getA())
                                                          {b--;count=0;}
                                                         }else{break;}
                  }        
		for(int i=0;i<n;i++){ans+=s[i];}
        System.out.println(ans);
	}
}
class Data{
    private int a;
    private int b;
    public Data(int a, int b) {
        this.a = a;
        this.b = b;
    }
    public int getA() {
        return a;
    }
    public int getB() {
        return b;
    }
}

Measured memory_bytes: 91256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

ll a[100010];
int main(){
	ll n;
	scanf("%lld",&n);
	rep(i,0,n+1)scanf("%lld",a+i+1);
	ll ans=0,crr=1;
	while(crr!=2&&crr!=-1){
		ll temp=a[crr];
		a[crr]=-1;
		crr=temp;
		ans++;
	}
	printf("%lld",crr==2?ans:-1);
}

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

#define fastIO() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'

int main()
{
 fastIO();
 long long A,B,C,chose,ans, res ;
 cin>>A>>B>>C>>chose;
 //lin.
 if(A>=chose)
 {
 	cout<<chose<<endl;
 }
 else if((A+B)>=chose)
 {
 	cout<<A<<endl;
 }
 else
 {
 	ans = A-(chose-A-B);
 	cout<<ans <<endl;
 }

return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include <cstdlib>
#include <stdlib.h>
#define FasterIO     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define all(a) a.begin(),a.end()
#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define f0(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<n;i++)
#define f1n(i,n) for(i=1;i<=n;i++)
#define szf sizeof()
#define sz size()
#define ln length()
#define MOD 1000000007
using namespace std;
using ll=long long;
int cnt,element;
int main()
{
    ll a,b,n,rafi=0,fl;
    cin>>a>>b>>n;
    fl=b-1;
    if(fl>n)
    {
        fl=n;
    }
    rafi=floor(((a*fl)/b)-(a*(fl/b)));
    cout<<rafi<<endl;
    return 0;
}


Measured memory_bytes: 3576
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <utility>
#include <map>
#include <set>
#include <ios>
#include <iomanip>
#include <functional>

using namespace std;

int main(){
    vector<vector<int>> v(3);
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            int x;
            cin >> x;
            v[i].push_back(x);
        }
    }
    int b1 = 0;
    int b2 = 0;
    int b3 = 0;
    bool ch = false;
    for(int i = 0; i < 100; i++){
        b1 = v[0][0] - i;
        b2 = v[0][1] - i;
        b3 = v[0][2] - i;
        for(int j = 0; j < 2; j++){
            int a1 = v[j + 1][0] - b1;
            int a2 = v[j + 1][1] - b2;
            int a3 = v[j + 1][2] - b3;
            if(a1 == a2 && a2 == a3){
                ch = true;
            }else{
                ch = false;
                break;
            }
        }
        if(ch == true){
            break;
        }
    }
    if(ch){
        cout << "Yes";
    }else{
        cout << "No";
    }
    
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

h,w = map(int,input().split())
#1 -> ?±????????????????, 0 -> ?¶????????????????
c = [list(map(int,input().split())) for j in range(h)]
dp = [[0 for i in range(w)] for j in range(h)]

for j in range(h):
    for i in range(w):
        dp[j][i] = c[j][i]

#0 -> ?±????????????????, 1 -> ?¶????????????????
for j in range(h):
    for i in range(w):
        dp[j][i] = c[j][i] ^ 1

for j in range(1,h):
    for i in range(1,w):
        if dp[j][i]:
            dp[j][i] = 1 + min(dp[j-1][i-1], dp[j-1][i], dp[j][i-1])
print(max(y for x in dp for y in x)**2)

Measured memory_bytes: 57880
#include <stdio.h>
#include <stdlib.h>

int int_compar(const int* a, const int* b)
{
    if (*a > *b) {
        return -1;
    } else if (*a < *b) {
        return 1;
    } else {
        return 0;
    }
}

int main(void)
{
    int n;
    scanf("%d", &n);
    int* arr = calloc(n, sizeof(int));

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

    int* sorted = calloc(n, sizeof(int));

    for (int i = 0; i < n; i++) {
        sorted[i] = arr[i];
    }
    qsort(sorted, n, sizeof(int), (int (*)(const void*, const void*))(*int_compar));

    int max = sorted[0];
    int second_max = sorted[1];

    for (int i = 0; i < n; i++) {
        if (arr[i] == max) {
            printf("%d\n", second_max);
        } else {
            printf("%d\n", max);
        }
    }
    return 0;
}


Measured memory_bytes: 3120
#整数nを入力
n = int(input())

x = 1
y = n
#整数nの約数で、平方根以下の最も大きい約数を求める
for i in reversed(range(1, int(n**0.5)+1)):
    if n % i == 0:
        x = i
        y = n / i
        break

#約数＋約数 - 2で答えを求める
print(int(x+y) - 2)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	while(n)
	{
		if(n%10==7)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
		n/=10;
	}
	cout<<"No"<<endl;
} 

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long
#define PINT pair<int,int>
#define f1 first
#define s2 second
const int INF = 1e9 + 7;

using namespace std;

#define MAX_N 100000
int prime[MAX_N];   //i番目の素数
bool is_prime[MAX_N+1]; //falseは素数でない

//n以下の素数を返す
int sieve(int n){
    int p = 0;
    REP(i,n+1) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    FOR(i,2,n+1){
        if(is_prime[i]){
            prime[p++] = i;
            for(int j=2*i;j<=n;j+=i) is_prime[j] = false;
        }
    }
    return p;
}

int main(){
    cin.tie(0), ios::sync_with_stdio(false);
    int q,maxlr=0;
    cin >> q;
    vector<int> l(q),r(q);
    REP(i,q) cin >> l[i] >> r[i];
    maxlr = max(*max_element(l.begin(),l.end()),*max_element(r.begin(),r.end()));
    sieve(maxlr);
    vector<int> is2017((maxlr-5)/4+1);
    int sum=1;
    REP(i,(maxlr-5)/4+1){
        if(is_prime[i*4+5] && is_prime[i*2+3]) is2017[i] = ++sum;
        else is2017[i] = sum;
    }
    REP(i,q){
        if(l[i]>5){
            cout << is2017[(r[i]-5)/4] - is2017[(l[i]-6)/4] << "\n";
        }else if(r[i] < 3){
            cout << "0\n";
        }else if(r[i] < 5){
            cout << "1\n";
        }else if(l[i] <= 3){
            cout << is2017[(r[i]-5)/4] << "\n";
        }else{
            cout << is2017[(r[i]-5)/4] - 1 << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 1664
N,K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
dp = [0]*(N)
dp[1] = abs(h[0] - h[1])
for i in range(0,N-2):
    dp[i+2] = min([dp[i+2-j]+abs(h[i+2-j]-h[i+2]) for j in range(1,min(K+1, i+3))])
print(dp[-1])

Measured memory_bytes: 52448
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

using namespace std;

bool v[100005];

void dfs(int now,vector<vector<ll>> &to,vector<vector<ll>> &cost,vector<ll> &pos){
	if(v[now]==0){
		v[now] = 1;
		pos[now] = 0;
	}
	for(int i=0;i<to[now].size();i++){
		int next = to[now][i];
		int dis  = cost[now][i];
		if(v[next]==0){
			v[next] = 1;
			pos[next] = pos[now] + dis;
			dfs(next,to,cost,pos);
		}
	}
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,M;
	cin >> N >> M;
	vector<ll> pos(N,-inf);
	vector<vector<ll>> to(N),cost(N);
	vector<int> l(M),r(M),D(M);
	rep(i,M){
		int a,b,c;
		cin >> a >> b >> c;
		a--;b--;
		l[i] = a;
		r[i] = b;
		D[i] = c;
		to[a].push_back(b);
		cost[a].push_back(c);
		to[b].push_back(a);
		cost[b].push_back(-c);
	}
	rep(i,N)dfs(i,to,cost,pos);
	rep(i,M){
		if(pos[l[i]]+D[i] != pos[r[i]]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 24192
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
a = LIST()
b = Counter(a)
c = list(set(a))
c.sort()
ans = 0
for i in range(len(c)):
    tmp = b[c[i]]
    if i > 0 and c[i - 1] == c[i] - 1:
        tmp += b[c[i - 1]]
    if i < len(c) - 1 and c[i + 1] == c[i] + 1:
        tmp += b[c[i + 1]]
    ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 80360
// #pragma GCC optimize("O3")
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace ::std;
// clang-format off
template<typename T> T nxt() {T res; cin >> res; return res;}
#define tests() for (int _ = nxt<int>(); _ > 0; _--)
#define nxt1(t,n) t (n); cin >> n
#define nxt2(t,n,m) t (n),(m); cin >> n >> m
#define nxt3(t,n,m,k) t (n),(m),(k); cin >> n >> m >> k
#define rep(i, A) for (int i = 0 ; i < A ; i++)
#define ll long long
typedef pair<int,int> pii;typedef pair<ll, ll> pll;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<ll> vl;typedef vector<vl> vvl;
#define dbg(vari) cerr<<#vari<<" = "<<(vari)<<endl;
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){for(T ti : t)s<<ti<<" ";return s; }
#define all(x) (x).begin(), (x).end()
#define last(vec) vec[vec.size()-1]
#define has(c,x) ((c).find(x) != (c).end())
// clang-format on

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

    int N = nxt<int>();

    ll res = 1ll, tmp1 = 1ll, tmp2 = 1ll;
    ll mod = 1000000007ll;

    for (int i = 0; i < N; i++) {
        res = (res * 10ll) % mod;
        tmp1 = (tmp1 * 9ll) % mod;
        tmp2 = (tmp2 * 8ll) % mod;
    }

    ll mid = (2ll * tmp1) % mod;

    cout << (((res + tmp2) % mod) + mod - mid) % mod << endl;

    return 0;
}


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


int main(){
    int n; cin >> n;
    int ans=0;
    int back=0;
    for(int i=1;i<=n;i++){
        back=ans;
        int top=i/pow(10.0,(int)log10(i));
        int end=i%10;
        if(top==0 || end==0) continue;
        if(top==end){
            //(1) Bが一桁の整数
            ans++;
        }
        //(2) Bが(end)(top)で表される
        if(end*10+top<=n) ans++;
        //(3) Bが(end)[1桁以上の整数](top)で表される
        int d=1; //中央の桁数
        int endn=end*100;
        int endnp=(end+1)*100;
        while(d<=log10(n)-1){
            if(d==int(log10(n)-1)){
                if(n>=endnp){
                    ans+=pow(10.0,d);
                }else if(n>=endn){
                    int mid=(n-endn)/10;
                    ans+=mid;
                    if(n%10>=top) ans++;
                }
            }else{
                ans+=pow(10.0,d);
            }
            d++;
            endn*=10;
            endnp*=10;
        }
        //if(back!=ans) cout << i << " " << ans-back << endl;
    }
    cout << ans << endl;
    return 0;
}

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

#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
  int x, y;
  char op;
  while(cin >> x >> op >> y) {
    if(op == '?') break;
    if(op == '+') cout << x+y << endl;
    if(op == '-') cout << x-y << endl;
    if(op == '*') cout << x*y << endl;
    if(op == '/' && y != 0) cout << x/y << endl;
  }

}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
const int N=3005,inf=0x3f3f3f3f;
const ld PI=3.1415926535897932384626;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,L,a[N];
ld b[N],ansx,ansy;
int main(){
//	freopen("balance.in","r",stdin);
//	freopen("balance.out","w",stdout);
	n=read();L=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=1;i<=n;i++)
	for (int j=i+1;j<=n;j++){
		ansx+=(n+i*2-j*2)*cos(PI*(a[i]+a[j])/L);
		ansy+=(n+i*2-j*2)*sin(PI*(a[i]+a[j])/L);
	}
	ll s=(ll)n*(n-1)*(n-2)/6;
	ansx/=s;ansy/=s;
	printf("%.16lf %.16lf\n",ansx,ansy);
	return 0;
}

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

int index(int numToFind, std::vector<int> vectorToFindIn) {int len = vectorToFindIn.size();for (int i = 0; i < len; i++){if (vectorToFindIn[i] == numToFind){return i;}}return -1;}

int main()
{
  ios_base::sync_with_stdio(0); cin.tie(0);
  int n,d,ans;
  cin>>n>>d;
  d=(2*d)+1;
  if (n<=d)
  {
  	ans=1;
  }
  else if (n%d==0)
  {
  	ans=n/d;
  }
  else
  {
  	ans=n/d;
  	++ans;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256