akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll sum=-1;
const int N=1e5;
ll a[N],b[N],c[N],dp[3][N];
int main()
{
    ll t;
    cin>>t;

    ll answer;
    for(int i=0;i<t;i++){
        cin>>a[i]>>b[i]>>c[i];
        dp[0][i]=a[i];dp[1][i]=b[i];dp[2][i]=c[i];}

    if(t==1)
    {
        cout<<max(max(dp[0][0], dp[1][0]), dp[2][0])<<endl;
        return 0;
    }

    for(int i=1;i<t;i++)
    {
        dp[0][i]=dp[0][i]+max(dp[1][i-1],dp[2][i-1]);
        dp[1][i]=dp[1][i]+max(dp[0][i-1],dp[2][i-1]);
        dp[2][i]=dp[2][i]+max(dp[1][i-1],dp[0][i-1]);
        answer=max(max(dp[0][i], dp[1][i]), dp[2][i]);
    }

    cout<<answer<<endl;


}


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

int main(int argc, char const *argv[])
{
	long long a,b,c;
	cin>>a>>b>>c;
	if (a+b>=c-1)
	{
		cout<<b+c<<endl;
	}
	else
	{
		cout<<a+b+1+b<<endl;
	}
	return 0;
}


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

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

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void) {
	double a, b, C;
	double S, L, h, x;

	scanf("%lf %lf %lf\n", &a, &b, &C);
	if(C == 90.0f || C == -90.0f) {
		h = b;
		x = a;
	} else {
		h = b * sin(C * M_PI / 180.0);
		x = a - b * cos(C * M_PI / 180.0);
	}
	L = sqrt(x*x + h*h);
	S = a * h / 2;
	printf("%.8lf\n", S);
	printf("%.8lf\n", L+a+b);
	printf("%.8lf\n", h);

	return 0;
}

Measured memory_bytes: 656
from operator import itemgetter
N = int(input())
AB = []
sumJ = 0
maxK = 0
for i in range(N):
  a,b = map(int,input().split())
  AB.append([a,b])
AB = sorted(AB, key=itemgetter(1))
for j,k in AB:
  sumJ += j
  maxK = max(k,maxK)
  if sumJ > maxK:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 39744
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<climits>
using namespace std;

int main() {
  int ans=0;

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

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

  cout << p[0] + p[1] << endl;
}


Measured memory_bytes: 256
/*I MAY NOT GET THE SUCCESS IMMEDIATELY BUT I WILL GET IT FOR SURE*/
#include<bits/stdc++.h>
#define opt std::ios_base::sync_with_stdio(false)
#define I int
#define li		int32_t
#define lli		long long
#define ulli unsigned long long
 
#define pn			 printf("\n")
#define nl			 cout<<'\n'
#define sf(N)        scanf("%lld",&N)
#define pf(N)        printf("%lld",N)
#define sf1(N1,N2)    scanf("%lld %lld",&N1,&N2)
#define pf1(N1,N2)    printf("%lld %lld",N1,N2)
#define sf2(N1,N2,N3) scanf("%lld %lld %lld",&N1,&N2,&N3)
#define pf2(N1,N2,N3) printf("%lld %lld %lld",N1,N2,N3)

#define sl          cout<<' '
#define ps          printf(" ")
 
#define rep(i,a,b)	for(i=a;i<b;i++)
#define repr(i,a,b)	for(i=a;i>b;i--)
#define elif		else if
#define mset(a,b)	memset(a,b,sizeof(a))
 
#define pb		push_back
#define pob		pop_back
#define itr		iterator
#define sz()	size()
#define szof    sizeof
#define lb		lower_bound
#define ub		upper_bound
#define mp		make_pair
#define vlli    vector<lli>
#define plli	pair<lli,lli>
#define vplli	vector<plli >
#define F   	first
#define S		second
#define Dup     erase(unique(V.begin(),V.end()),V.end())
 
#define bs      binary_search
#define ub      upper_bound
#define lb      lower_bound

#define ALL(V)  V.begin(),V.end()
 
#define MX1     30001
#define MX2     1000000
#define Inf     1000000000000000
#define mod		1000000007
using namespace std;
 
lli Power(lli a,lli b)
{
    lli result=1;
 
    while(b)
    {
        if(b%2)
        {
            result=(result*a)%mod;
        }
 
        b=b>>1;
        a=(a*a)%mod;
    }
 
 return result;
}
 
int main()
{
    opt;
 
    /*#ifndef ONLINE_JUDGE
    freopen("double_squares.txt","r",stdin);
    freopen("double_squares_out.txt","w",stdout);
    #endif // ONLINE_JUDGE*/
    
    lli N,i;
    cin>>N;
    
    lli Maximum=0,Minimum=1000;
    
    rep(i,0,N)
    {
        lli x;
        cin>>x;
        
        Maximum=max(Maximum,x);
        Minimum=min(Minimum,x);
    }
    
    cout<<Maximum-Minimum;
    
    
    
    
    
    
    
    
    
    
    
    
 
 return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int l[10]={0,0,0,0,0 ,0,0,0,0,0};
	scanf("%d",&l[0]);
	l[0]=0;
	scanf("%d %d %d %d %d %d %d %d %d %d",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9]);
	int max=0,c,sum=0;
	for(c=0;c<10;c++){
		if(max<l[c])max=l[c];
		sum=sum+l[c];
	}
	if(sum-max>max)printf("Yes\n");
	else printf("No\n");

//最大値の判定
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int arr[200005];
int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("input.txt","r",stdin);
// #endif
    int n,k,q;
    cin>>n>>k>>q;
    for(int i = 0 ;i<q;i++)
    {
        int x;
        cin>>x;
        arr[x]++;
    }
    for(int i = 1 ;i<=n;i++)
    {
        int value = q-arr[i];
        int tmp = k - value;
        if(tmp<1)
            cout<<"No"<<endl;
        else
            cout<<"Yes"<<endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

inline ll lcm(ll n, ll m)
{
    return m * n / __gcd(n, m);
}

int main()
{
    int a[3], m[3];

    while (true) {
        int sum = 0;
        for (int i = 0; i < 3; i++) {
            cin >> a[i] >> m[i];
            sum += (a[i] + m[i]);
        }
        if (sum == 0)
            break;

        int x[3] = {1, 1, 1}, cnt = 0;
        ll t[3] = {0};

        for (int i = 0; i < 3; i++) {
            while (true) {
                x[i] = (a[i] * x[i]) % m[i];

                t[i]++;
                if (x[i] == 1)
                    break;
            }
        }

        cout << lcm(lcm(t[0], t[1]), t[2]) << endl;
    }

    return 0;
}

Measured memory_bytes: 1156
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


int main()
{
	int n;
	while (cin >> n, n)
	{
		bool jew[32][32];
		CLEAR(jew, 0);
		rep (i, n)
		{
			int x, y;
			cin >> x >> y;
			jew[y][x] = true;
		}
		
		int m;
		cin >> m;
		int x = 10, y = 10;
		jew[10][10] = false;
		while (m--)
		{
			char c;
			char* d = "NESW";
			int dis;
			cin >> c >> dis;
			int dir = strchr(d, c) - d;
			while (dis--)
			{
				x += dx[dir], y += dy[dir];
				jew[y][x] = false;
			}
		}

		bool res = true;
		for (int i = 0; i <= 20; ++i)
			for (int j = 0; j <= 20; ++j)
				res &= !jew[i][j];

		cout << (res ? "Yes" : "No") << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;

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

typedef pair<int,int> P;
int h,w,s,all,t[32][32];
int i,j;
int rec[32][32][32][32]; //長方形の合計[ly][lx][hy][hx]
P dp[32][32][32][32]; //メモ化

//全ての(lx,ly)〜(hx,hy)の長方形合計を計算
void mkRec(){
  memset(rec,0,sizeof(rec));

  rep(i,h){
    rep(j,w){
      rec[i][j][i][j] = t[i][j];

      for(int y=i-1;y>=0;y--)
        rec[y][j][i][j] = rec[y+1][j][i][j] + t[y][j];

      for(int y=i;y>=0;y--){
        int sum = 0;
        for(int x=j;x>=0;x--){
          sum += rec[y][x][i][x];
          rec[y][x][i][j] = sum;
        }
      }
    }
  }
}

//戻り型 : P. first : 最大グループ数. second : 最大予備力
P dfs(int lx,int ly,int hx,int hy){
  if(dp[ly][lx][hy][hx].first != 0) return dp[ly][lx][hy][hx];

  P res = P(1,s-(all-rec[ly][lx][hy][hx]));

  //水平分割
  for(int i=ly;i<hy;i++){
    if(all - rec[ly][lx][i][hx] > s ||
       all - rec[i+1][lx][hy][hx] > s) continue;
    P a = dfs(lx,ly,hx,i);
    P b = dfs(lx,i+1,hx,hy);
    P cal = P(a.first+b.first,min(a.second,b.second));
    res = max(res,cal);
  }

  //垂直分割
  for(int j=lx;j<hx;j++){
    if(all - rec[ly][lx][hy][j] > s ||
       all - rec[ly][j+1][hy][hx] > s) continue;
    P a = dfs(lx,ly,j,hy);
    P b = dfs(j+1,ly,hx,hy);
    P cal = P(a.first+b.first,min(a.second,b.second));
    res = max(res,cal);
  }

  return dp[ly][lx][hy][hx] = res;
}

int main(void){
  while(scanf("%d%d%d",&h,&w,&s),h||w||s){
    all = 0;
    rep(i,h){
      rep(j,w){
        scanf("%d",&t[i][j]);
        all += t[i][j];
      }
    }

    mkRec();

    memset(dp,0,sizeof(dp));
    P p = dfs(0,0,w-1,h-1);
    printf("%d %d\n",p.first,p.second);
  }
}

Measured memory_bytes: 13496
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main(){
  string s,t;
  cin>>s>>t;
  ll sn=sz(s);
  ll st=sz(t);
  vstr ans(0);
  rep(i,sn-st+1){
    string a=s;
    ll cu=1;
    for(int j=0;j<st;j++){
      if(s[i+j]=='?') continue;
      if(s[i+j]!=t[j]){
        cu=0;
        break;
      }
    }
    if(cu){
      for(int h=i;h<i+st;h++){
        a[h]=t[h-i];
      }
      rep(g,sn){
        if(a[g]=='?'){
          a[g]='a';
        }
      }
      ans.pb(a);
    }
  }
  
  if(sz(ans)==0) COUT("UNRESTORABLE");
  else {
    sort(all(ans));
  COUT(ans[0]);
  }
}

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

signed main () {
	long long n;
	cin >> n;
	if (n & 1)
		cout << "0\n";
	else {
		long long ans = 0LL, five = 5LL;
		int cnt = 1;
		while (true) {
			ans += n / (2LL * five);
			if (cnt == 25)
				break;
			five *= 5LL;
			++cnt;
		}
		cout << ans << '\n';
	}
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] arg) {
        Scanner scan = new Scanner(System.in);
        int h = Integer.parseInt(scan.next());
        int n = Integer.parseInt(scan.next());
        scan.nextLine();
        List<Integer> aList = Arrays.stream(scan.nextLine().split(" ")).map(Integer::parseInt).collect(Collectors.toList());
        for(int a : aList) {
            h-=a;
        }
        if(h > 0) {
            System.out.println("No");
        }
        else {
            System.out.println("Yes");
        }
    }
}







//import java.util.*;
//
//public class Main {
//    public static void main(String[] arg) {
//        Scanner scan = new Scanner(System.in);
//        int h = Integer.parseInt(scan.next());
//        int a = Integer.parseInt(scan.next());
//
//        int count = 0;
//        while(h > 0) {
//            h = h-a;
//            count++;
//        }
//
//        System.out.println(count);
//    }
//}

Measured memory_bytes: 49660
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    n, k = map(int, readline().split())
    ans = 0.
    for i in range(1, n+1):
        cnt = 0
        s = i
        while s<=k-1:
            s *= 2
            cnt += 1
        ans += 1/n * pow(2, -cnt)
    print('{:.12f}'.format(ans))
if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

n, m, d = mi()

if d==0:
    ans = float(m-1) / n
else:
    ans = float(2*(n-d)*(m-1)) / n**2 

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define maxn 100010
#define ms(x,y) memset(x,y,sizeof x)
#define inf 0x3f3f3f3f
#define fir first
#define sec second
#define lb(x) (x&(-x))
const int mod=1e9+7;
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
int n,q,top;ll stk[maxn],t[maxn],a[maxn],s[maxn];
int main(){
	scanf("%d%d",&n,&q);
	stk[++top]=n;ll x;
	for(int i=1;i<=q;i++){
		scanf("%lld",&x);
		while(top&&stk[top]>=x)top--;
		stk[++top]=x;
	}
	q=top;
	for(int i=1;i<=q;i++)a[i]=stk[i];
	t[q]=1;
	for(int i=q;i;i--){
		ll k=a[i];int p=lower_bound(a+1,a+i,k)-a-1;
		while(p){
			t[p]+=k/a[p]*t[i];
			k%=a[p];p=lower_bound(a+1,a+p,k)-a-1;
		}
		s[1]+=t[i];s[k+1]-=t[i];
	}
	ll res=0;
	for(int i=1;i<=n;i++){
		res+=s[i];printf("%lld\n",res);
	}
	return 0;
}


Measured memory_bytes: 4864
S=list(str(input()))
a=0
if len(S)%2==0:
    for i in range((len(S))//2):
        if S[i]!=S[len(S)-i-1]:
            a+=1
if len(S)%2==1:
    for i in range((len(S)-1)//2):
        if S[i]!=S[len(S)-i-1]:
            a+=1
print(a)

Measured memory_bytes: 9024
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N ,M; cin >> N >> M;
  vector<ll> a(N); rep(i,N) cin >> a[i];
  SORT(a);

  // 2分探索で最小値を求める
  ll left = 0 , right = 1e15;
  ll cnt = 0;
  rep(loop, 100){
    // cout << left << " " << right << endl;
    ll m = (left + right) / 2;
    cnt = 0;
    rep(i,N){
      // 足してm以上になる個数を足していく
      cnt += N - POSL(a , m - a[i]);
    }
    if(cnt >= M) left = m;
    else right = m;
  }
  // leftが最小値
  vector<ll> sum(N + 1);
  for(ll i = 0 ; i < N ; i ++){
    sum[i + 1] = sum[i] + a[N - i - 1];
  }
  ll ans = 0;
  ans -= (cnt - M) * left;
  rep(i,N){
    ll tmp = N - POSL(a , left - a[i]);
    ans += tmp * a[i];
    ans += sum[tmp];
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)

signed main(){
    string s;cin>>s;
    char b=' ';
    s[5]=b;
    s[13]=b;
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
const long long INF = 1LL << 60;


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

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

//約数求める //約数
void divisor(ll n,vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	
}
//階乗
long long factorial(long long n, long long mod) {
	long long ret = 1;
	for (long long i = 1; i <= n; i++) {
		ret = (ret * i) % mod;
	}
	return ret;
}
//モジュラ逆数
long long inv_mod(long long n, long long mod) {
	long long a = n % mod, b = mod - 2, ret = 1;
	while (b > 0) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}

long long nPr(long long n, long long r, long long mod) {
	long long ret = 1;
	for (long long i = n; i >= n - r + 1; i--) {
		ret = ret * (i % mod) % mod;
	}
	return ret;
}

long long nCr(long long n, long long r, long long mod) {
	return nPr(n, r, mod) * inv_mod(factorial(r, mod), mod) % mod;
}

ll gcd(ll m, ll n){
	if (n == 0)return m;
	return gcd(n, m%n);
}//gcd

ll dp[100010];

ll lp(vector<vector<ll>> &g,ll n) {
	if (dp[n] != -1)return dp[n];
	ll max = -1;
	for (int i = 0; i < g[n].size(); i++) {
		ll temp = lp(g, g[n][i]);
		if (max < temp)max = temp;
	}
	return dp[n] = max + 1;
}


int main() {
	memset(dp, -1, sizeof dp);
	ll n, m;
	cin >> n >> m;
	vector<vector<ll>> g(n);
	rep(i, m) {
		ll x, y;
		cin >> x >> y;
		g[x - 1].push_back(y - 1);
	}
	ll max = 0;
	rep(i, n) {
		ll temp = lp(g, i);
		if (max < temp)max = temp;
	}
	cout << max;

	return 0;
}


Measured memory_bytes: 8576
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
ll BASE_NUM = 1000000007;

int main()
{
    // 整数の入力
    ll max_diff = 0;
    ll N,K;
    cin >> N >> K;
    cout << min(abs(N % K), K - abs(N % K)) << endl;
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[5];
int main()
{
    int n,m,i,s,c;
    cin >> n >> m;
    for(i=1;i<=n;i++) a[i] = -1;
    for(i=1;i<=m;i++) {
        cin >> s >> c;
        if(a[s]!=-1&&a[s]!=c) { //check if a value has already been input and if new input is equal to original
            cout << -1 << endl;
            return 0;
        } else {
            a[s] = c;
        }
    }
    if(n>1&&a[1]==0) { //check for leading zero
        cout << -1 << endl;
    }
    else if(n==1) {
        if(a[1]==-1) cout << "0" << endl; //check no input, if 1 digit 0 is allowed
        else cout << a[1] << endl;
    }
    else {
        for(int i=1;i<=n;i++) { //fill no inputs with 1 or 0 to make lowest number possible
            if(i==1&&a[i]==-1) cout << "1";
            else if(a[i]==-1) cout << "0";
            else cout << a[i];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

long i,a,b,p,q,r;

while(scanf("%ld",&a)!=EOF){

scanf("%ld",&b);

p=a;
q=b;

for(i=0;i<1000;i++){

r = p%q;
if(r==0) break;

p=q; q=r;

}

printf("%ld %ld\n",q,a*b/q);

}

return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
#define spln(i,n) (i==n?'\n':' ')
using namespace std;
inline void read(int &x)
{
	char c;int f=1;
	while(!isdigit(c=getchar()))if(c=='-')f=-1;
	x=(c&15);while(isdigit(c=getchar()))x=(x<<1)+(x<<3)+(c&15);
	x*=f;
}
int n,m,i,j,k,a[200005],vis[200005],col[200005],wei[200005],c[200005],fa[200005];
vector<pair<int,int> > bi[200005];
bool cmp(int x,int y)
{
	return a[x]<a[y];
}
int fnd(int x)
{
	if(fa[x]==x) return x;
	return fa[x]=fnd(fa[x]); 
}
int main()
{
	read(n);read(m);
	fz1(i,n){
		fa[i]=i;
		fa[i+n]=i+n;
	}
	fz1(i,n)read(a[i]);
	fz1(i,m){
		int x,y;wei[i]=1000000000;
		read(x);read(y);
		bi[x].push_back(make_pair(y,i));
		bi[y].push_back(make_pair(x,i)); 
	}
	fz1(i,n){
		c[i]=i;
	}
	sort(c+1,c+n+1,cmp);
	for(i=1;i<=n;i=j+1){
		j=i;
		while(j<n&&a[c[j+1]]==a[c[i]])j++;
		fz(k,i,j)if(!vis[c[k]]){
			ff(bi[c[k]],it){
				if(vis[it->first]){
					wei[it->second]=a[c[i]];
					fa[fnd(c[k])]=fnd(it->first+n);
					fa[fnd(c[k]+n)]=fnd(it->first);
					vis[c[k]]=1;
					break;
				}
				if(a[it->first]==a[c[i]]){
					wei[it->second]=a[c[i]];
					fa[fnd(c[k])]=fnd(it->first+n);
					fa[fnd(c[k]+n)]=fnd(it->first);
					vis[c[k]]=vis[it->first]=1;
					break;
				}
			}
			if(!vis[c[k]]){
				puts("-1");
				return 0;
			}
		}
	}
	fz1(i,n){
		if(fnd(i)<=n) putchar('B'); else putchar('W');
	}
	puts("");
	fz1(i,m){
		printf("%d\n",wei[i]);
	}
	return 0;
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  ll n; cin >> n;
  ll mi = n-1;
  for(ll i = 2;i*i <= n;++i) {
    if(n % i == 0) {
      mi = min(mi, i + n / i - 2);
    }
  }
  cout << mi << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	long long a[100];
	a[0] = 2;
	a[1] = 1;
	scanf("%d",&n);
	for(int i=2;i<=n;i++){
		a[i] = a[i-1]+a[i-2];
	}
	printf("%lld",a[n]);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define rfo(i,n) for(ll i=n-1;i>=0;i--)
#define rloop(i,a,b) for(ll i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define precision cout<<fixed<<setprecision(10)
#define mem(x,p) memset(x,p,sizeof(x))
#define w(t) ll t;cin>>t;while(t--)
#define kk "\n"
#define setbits(x) __builtin_popcountll(x)
const double pi=3.1415926535897932384626;
//const ll mod = 998244353;
const ll mod=1e9+7;
int main()
{
  IOS
  ll n;
  cin>>n;
  n--;
  ll p=(n*(n+1))/2;
  cout<<p;
  return 0;
}

Measured memory_bytes: 3652
// 整数全体をある数で割った余りで分類
// 余りが同じ整数はすべて同じ(合同≡)とみなす
// 加法、減法、乗法を行っても合同を保つことから
// (1) a + b ≡ 0 mod K
// (2) b + c ≡ 0 mod K
// (3) c + a ≡ 0 mod K
// (1) - (2) + (3) 2a ≡ 0 mod K
// Kが偶数の場合、mod K / 2 もゼロと合同になる
// Kが8の場合、mod 4 もゼロとなるものも対象となる
// Kで割った余りはKより小さい
// Kで割った余りの数が等しくなるものがいくつあるか数え
// a mod Kで全探索する
// 10の5乗を3回かけても15乗はlongの19乗で事足りる
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.Arrays;

@SuppressWarnings("unchecked")
public class Main {
    static final int MAX_N = 200001;
    public static void main(String[] args) throws IOException {
        final String s;

        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            s = reader.readLine();
        }

        final String[] sl = s.split(" ");
        int N = Integer.parseInt(sl[0]);
        int K = Integer.parseInt(sl[1]);

        long[] A = new long[MAX_N];
        Arrays.fill(A, 0L);

        // a b c は 1 から
        for (int i = 1; i <= N; i++) A[i % K]++;

        long ans = 0L;

        // 余りはゼロから
        // a mod K 全探索
        for (int ma = 0; ma < K; ma++) {
            // b と c は a から見て 等価
            int mbmc = (K - ma) % K;

            if (2 * mbmc % K != 0) continue;

            ans += A[ma] * A[mbmc] * A[mbmc];
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 25044
read n d
for i in `seq $n`;do
 read a[i]
done
cnt=0
for i in `seq $n`;do
 for j in `seq $[i+1] $n`;do
  s=(${a[i]})
  t=(${a[j]})
  x=0
  for k in `seq $d`;do
   x=$[x+(s[k-1]-t[k-1])**2]
  done
  c=0
  for k in `seq 130`;do
   if [ $x -eq $[k*k] ];then
    c=1
   fi
  done
  cnt=$[cnt+c]
 done
done
echo $cnt

Measured memory_bytes: 632
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){return (int)s.size();}
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int a,b; cin >> a >> b;
    cout << max(0,a-b*2) << endl;
    return 0;
}


Measured memory_bytes: 256
N = gets.chomp.to_i
sides=Hash.new{|h,k|h[k]={}}
(N-1).times do |i|
  a, b, c = gets.chomp.split(' ').map(&:to_i)
  # sides[a] ||= {}
  # sides[b] ||= {}
  sides[a][b] = c
  sides[b][a] = c
end

qs = []
Q, K = gets.chomp.split(' ').map(&:to_i)
Q.times do
  qs.push gets.chomp.split(' ').map(&:to_i)
end

cost = []
cost[K] = 0

g = [[K, 0]]
while g.length > 0
  node, dis = g.shift
  sides[node].each do |k, v|
    b = k
    c = v
    unless cost[b]
      cost[b] = dis + c
      g.push [b, cost[b]]
    end
  end
end

qs.each do |q|
  print "#{cost[q[0]] + cost[q[1]]}\n"
end

Measured memory_bytes: 62972
import std;

// 累積和による解法
long calc(string s) {
    int n = cast(int)s.length;

    auto acc = new int[][](3, n);
    foreach (i; 0..n) {
        acc[0][i] = (s[i] == 'R') + (i > 0 ? acc[0][i-1] : 0);
        acc[1][i] = (s[i] == 'G') + (i > 0 ? acc[1][i-1] : 0);
        acc[2][i] = (s[i] == 'B') + (i > 0 ? acc[2][i-1] : 0);
    }

    // "RGB" の使っていない文字
    int get(char a, char b) {
        foreach (i, c; "RGB") {
            if (c != a && c != b) return cast(int)i;
        }
        assert(false);
    }

    long ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n - 1; j++) {
            if (s[i] == s[j]) continue;

            int p = get(s[i], s[j]);
            ans += acc[p][$-1] - acc[p][j-1];
            int k = 2*j - i;
            if (k < n && s[k] == "RGB"[p]) ans--;
        }
    }
    return ans;
}

// 全体から j-i == k-j が一致するものを引く
long calc2(string s) {
    int n = cast(int)s.length;

    long r = 0, g = 0, b = 0;
    foreach (c; s) {
        if (c == 'R') r++;
        if (c == 'G') g++;
        if (c == 'B') b++;
    }
    int x = 0;
    foreach (i; 0..n) {
        foreach (j; i+1..n) {
            if (s[i] == s[j]) continue;
            int k = 2*j - i;
            if (k >= n || s[i] == s[k] || s[j] == s[k]) continue;
            x++; // j-i == k-j and i, j, k の文字が全て異なる
        }
    }
    return r * g * b - x;
}

void main() {
    readint;
    string s = read!string;
    writeln(calc2(s));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


Measured memory_bytes: 3640
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
a = a1 + a2 + a3

n = int(input())

b = [int(input()) for _ in range(n)]

l = []
for x in a:
    if x in b:
        l.append('o')
    else:
        l.append('x')

if l[0] == l[1] == l[2] == 'o' or l[3] == l[4] == l[5] == 'o' or l[6] == l[7] == l[8] == 'o' or l[0] == l[3] == l[6] == 'o' or l[1] == l[4] == l[7] == 'o' or l[2] == l[5] == l[8] == 'o' or l[0] == l[4] == l[8] == 'o' or l[2] == l[4] == l[6] == 'o':
    print('Yes')
else:
    print('No')

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

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> xy(n);
    for (auto& e : xy) cin >> e.first >> e.second;

    int m = (abs(xy[0].first) + abs(xy[0].second)) % 2;
    for (int i = 1; i < n; i++) {
        if ((abs(xy[i].first) + abs(xy[i].second)) % 2 != m) {
            cout << -1 << endl;
            return 0;
        }
    }

    vector<int> arms;
    for (int i = 30; i >= 0; i--) arms.push_back(1 << i);
    if (m == 0) arms.push_back(1);

    cout << arms.size() << endl;
    for (auto e : arms) cout << e << " ";
    cout << endl;

    for (auto& e : xy) {
        int u = e.first + e.second, v = e.first - e.second;
        string op = "";
        for (auto& d : arms) {
            if (u > 0 && v > 0) u -= d, v -= d, op += 'R';
            else if (u > 0 && v <= 0) u -= d, v += d, op += 'U';
            else if (u <= 0 && v > 0) u += d, v -= d, op += 'D';
            else u += d, v += d, op += 'L';
        }
        cout << op << endl;
    }
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int k = sc.nextInt();
        if (7 % k == 0) {
            System.out.println(1);
            return;
        }

        int ans = -1;

        long mod = 7 % k;
        for (int i = 1; i <= 1000000; i++) {
            mod = (mod * 10 + 7) % k;

            if (mod == 0) {
                ans = i + 1;
                break;
            }
        }

        System.out.println(ans);

        // out.println("Hello World");
        out.flush();
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 35972
#include<iostream>
using namespace std;
int main(){
    int R;
    cin >> R;
    if(R<1200){
        cout << "ABC" << '\n';
    }else if(R<2800){
        cout << "ARC" << '\n';
    }else{
        cout << "AGC" << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii_ pair<int,int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define show1(a) cout<<#a<<" = "<<a<<endl
#define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl
using namespace std;
const ll INF = 1LL<<60;
const int inf = 1<<30;
const int maxn = 2e5+5;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

int n,a[105];

int main()
{
    fastio();
    cin>>n;
    rep(i,1,n) cin>>a[i];
    rep(i,1,n) a[i] = a[i-1]+a[i];
    int ans = inf;
    rep(i,1,n-1){
        ans = min(ans,abs(a[i]-(a[n]-a[i])));
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
    string s;
    cin >>s;
    int len=s.size();
    rep(i,len/2) {
        if(s[i]!=s[len-i-1]) {
            cout << "No" <<endl;
            return 0;
        }
    }
    rep(i,len/4) {
        if(s[i]!=s[len/2-i-1]||s[len-i-1]!=s[len/2+i+1]) {
            cout << "No" <<endl;
            return 0;
        }
    }
    cout << "Yes" <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int i,n,count=0,sum=0;
  	long long a[100000];
  	cin>>n;
  	for(i=0;i<n;i++){
		cin>>a[i];
      	while(a[i]%2==0){
          	a[i]/=2;
			count++;
        }
      	sum+=count;
			count=0;
    }

  	cout<<sum<<endl;
}


Measured memory_bytes: 384
import bisect
N, Q = map(int, input().split())
S = input()
minians = []
for i in range(N-1):
    if S[i:i + 2] == "AC":
        minians.append(i)
ans = [0]*Q
for i in range(Q):
    left, right = map(int, input().split())
    left -= 1
    right -= 1
    ans[i] = bisect.bisect_left(minians, right) - \
        bisect.bisect_left(minians, left)
print('\n'.join(map(str, ans)))

Measured memory_bytes: 16116
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn enumerate_patterns(n: usize, remain_cities: &mut Vec<usize>, patterns: &mut Vec<Vec<usize>>,
                      cur_path: &mut Vec<usize>){

    if cur_path.len () == n{
        patterns.push(cur_path.clone());
        return;
    }

    for i in 0..remain_cities.len(){
        let mut clone_remain: Vec<usize> = remain_cities.clone();
        let mut clone_path: Vec<usize> = cur_path.clone();

        clone_path.push(clone_remain[i]);
        clone_remain.remove(i);
        enumerate_patterns(n, &mut clone_remain, patterns, &mut clone_path);
    }
}

fn main(){
    let n: usize = read_as_vec()[0];

    let mut cities: Vec<(f64, f64)> = vec![];

    for _ in 0..n{
        let line = read_as_vec::<f64>();
        cities.push((line[0], line[1]));
    }

    //enumerate all patterns
    let mut remain_cities = vec![];
    let mut tmp: Vec<usize> = vec![];
    for i in 0..n{
        remain_cities.push(i);
    }

    let mut patterns: Vec<Vec<usize>> = Vec::new();
    enumerate_patterns(n, &mut remain_cities, &mut patterns, &mut tmp);

    //println!("{:?}", patterns);

    let mut sum_path_length = 0.0;
    for pattern in &patterns{
        let mut path_length = 0.0;
        for i in 1..pattern.len(){
            let path_pow2 = (cities[pattern[i-1]].0 - cities[pattern[i]].0).powi(2) +
                (cities[pattern[i-1]].1 - cities[pattern[i]].1).powi(2);
            path_length += path_pow2.sqrt();

        }
        sum_path_length += path_length;
    }

    println!("{}", sum_path_length/(patterns.len() as f64));
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
long long N, A[1 << 18]; // 262144
int main()
{
  cin >> N;
  long long S = 0;
  for (int i = 1; i <= N; i++)
  {
    cin >> A[i];
    S += A[i];
  }

  long long minx = S, sum = 0;
  for (int i = 1; i <= N; i++)
  {
    sum += A[i];
    minx = min(minx, abs(sum - (S - sum)));  // 累積和
  }
  cout << minx << endl;
  return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
ll n,a,b,c,d;
cin>>n>>a>>b>>c>>d;
if(a>b)swap(a,b);
V<ll> suml1(n+1,0),suml2(n+1,0);
suml1[0]=a,suml2[0]=a;
for(int i=0;i<n-1;i++){
    suml1[i+1]+=suml1[i]+d;
    suml2[i+1]+=suml2[i]-d;
}
V<ll> sumr1(n+1,0),sumr2(n+1,0);
sumr1[n-1]=b;sumr2[n-1]=b;
for(int i=n-1;i>0;i--){
    sumr1[i-1]+=sumr1[i]+d;
    sumr2[i-1]+=sumr2[i]-d;
}
bool ch=false;
for(ll i=0;i<n;i++){
    if(!(suml1[i]<sumr1[i]-(n-1-i)*(d-c)||suml1[i]-i*(d-c)>sumr1[i]))ch=true;
    if(!(suml1[i]<sumr2[i]||suml1[i]-i*(d-c)>sumr2[i]+(n-1-i)*(d-c)))ch=true;
}
if(ch)cout<<"YES"<<"\n";
else cout<<"NO"<<"\n";
}



Measured memory_bytes: 15872
#include <bits/stdc++.h>
#include <iostream>
#define ll long long int
#define ld long double
using namespace std;



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    	int a,n;
	int approve=1;
 
	cin>>n;
 
	while(n--){
		cin>>a;
		if(a%2==0){
			if(a%3!=0&&a%5!=0)
				approve=0;
 
		}
	}
 
	if(approve==0)
		printf("DENIED");
	else
		printf("APPROVED");
	return 0;
}	
    

Measured memory_bytes: 256
n = int(input())


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


fact = factorization(n)
ans = 0
it = []
for x, cnt in fact:
    for _ in range(cnt):
        it.append(x)


def dfs(n, a, b):
    if n == 0:
        return max(map(lambda x: len(str(x)), (a, b)))
    else:
        x1 = dfs(n-1, a*it[n-1], b)
        x2 = dfs(n-1, a, b*it[n-1])
        return min(x1, x2)


print(dfs(len(it), 1, 1))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
using namespace std;

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

struct edge {
	int to, cost;
	edge(int t,int c):to(t),cost(c) {}
};

int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int ddx[]={1,1,1,0,-1,-1,-1,0},ddy[]={1,0,-1,-1,-1,0,1,1};

ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

//-----------------------------------------------------------------------------

ll n,a,b;

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

	cin>>n>>a>>b;
	if(n==1&&a==b) cout<<1<<endl;
	else if((n==1&&a!=b)||a>b) cout<<0<<endl;
	else cout<<max(0LL,(b*(n-1)+a)-(a*(n-1)+b)+1)<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int const MOD = 1000000007;

int dp[1001][1001];

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

    int n; cin>>n; P a[n];
    for (int i = 0; i < n; i++)cin>>a[i].second>>a[i].first;
    sort(a,a+n);
    fill(dp[0],dp[n+1],MOD); dp[0][0]=0;
    for (int i = 0; i < n; i++){
        for (int j = 0; j <= i+1; j++){
            if(!j){dp[i+1][j]=0; continue;}
            if(dp[i][j-1]+a[i].second<=a[i].first)dp[i+1][j]=dp[i][j-1]+a[i].second;
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
        }
    }
    for (int i = n; i >= 0; i--)if(dp[n][i]!=MOD){cout<<i<<'\n'; return 0;}
}


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

int a[100005], d[100005], mi, ma = -1;

int main(void) {
  int N, T, cnt = 0;
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N >> T;
  for(int i = 0; i < N; ++i) cin >> a[i];

  mi = a[0];
  d[0] = 0;
  for(int i = 1; i < N; ++i) {
    if(mi > a[i]) mi = a[i];
    d[i] = a[i] - mi;
    if(ma < d[i]) ma = d[i];
  }
  //for(int i = 0; i < N; i++) cout << d[i] << endl;
  for(int i = 1; i < N; i++) if(d[i] == ma) cnt++;
    cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
/**
*   @Author: MeGaaaaaaaaaa
*   @InitTime: Mon Sep 09 17:56:59 2019
*   @Idea: 
*
*
*
*
* Happy Solving :)
**/
int main(){
#ifndef ONLINE_JUDGE
  //  freopen("in","r",stdin);
 //   freopen("out","w",stdout);
#endif
    int a,b,c;
    cin>>a>>b>>c;
    vector<int>v{a,b,c};
    sort(v.begin(),v.end());
    int cnt=0;
    while(v[0]!=v[1]||v[0]!=v[2]||v[1]!=v[2]){
    	while(v[0]<v[2]&&v[1]<v[2]){
    	  v[0]++;
    	  v[1]++;
    	  cnt++;
    	}
    	while(v[0]<v[2]){
    	  v[0]+=2;
    	  cnt++;
    	}
    	while(v[1]<v[2]){
    	 v[1]+=2;
    	 cnt++;
    	}
    	sort(v.begin(),v.end());
    }
    cout<<cnt<<endl;






}


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

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

  while (1)
  {
    sort(a.begin(), a.end());
    for (ll i = 1; i < a.size(); i++)
    {
      a[i] %= a[0];
      if (a[i] == 0)
      {
        a.erase(a.begin() + i);
      }
    }
    if (a.size() == 1)
    {
      break;
    }
  }
  cout << a[0] << endl;
}


Measured memory_bytes: 4000
// D.

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>

using namespace std;

typedef pair<int, int> II;

int solve(int k) {
	deque<II> q;
	q.push_back(II(1, 1));
	vector<int> vis(k + 1, -1);
	while (!q.empty()) {
		II top = q.front();
		q.pop_front();
		int x = top.first, y = top.second;
		if (vis[x] < 0) {
			vis[x] = y;
			q.push_front(II((x * 10) % k, y));
			q.push_back(II((x + 1) % k, y + 1));
		}
	}
	return vis[0];
}

int main(int argc, char *argv[])
{
	int k;
	cin >> k;
	cout << solve(k) << endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 6060;
int n,dy[N];char s[N];vector<string>a;
inline string geta(int l, int r){
	string a;int lst=l-1;
	rep(i,l,r)if(s[i]=='a'&&i>lst){
		a+="ab";lst=dy[i];
	}
	return a;
}
inline string getb(int l, int r){
	string res;static bool vis[N];
	rep(t,1,(r-l+1)/2){
		rep(i,l,r)vis[i]=0;
		for(int i=r,c=1;i>=l;i--)if(s[i]=='a'&&c<=t){vis[i]=1;c++;}
		for(int i=r,c=1;i>=l;i--)if(s[i]=='b'&&c<=t){vis[i]=1;c++;}
		string a;rep(i,l,r)if(vis[i])a+=s[i];res=max(res,a);
	}
	return res;
}
int main() {
	read(n);scanf("%s",s+1);n*=2;
	Vi u,v;rep(i,1,n)if(s[i]=='a')u.pb(i);else v.pb(i);
	rep(i,0,SZ(u)-1)dy[u[i]]=v[i],dy[v[i]]=u[i];
	for(int i=1,lst=0,now=0;i<=n;i++){
		now+=s[i]=='a'?1:-1;if(!now){
			//lst+1..i
			if(s[lst+1]=='a')a.pb(geta(lst+1,i));else a.pb(getb(lst+1,i));
			lst=i;
		}
	}
	string r;per(i,SZ(a)-1,0)r=max(r,a[i]+r);cout<<r;
	return 0;
}


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

int main(){
  string s;
  cin >> s;
  int sum=0;
  for(int i = 0; i < (int)s.size(); ++i)
    sum+=s[i]-'0';
  sum%9?cout << "No\n":cout << "Yes\n";
  return 0;
}

Measured memory_bytes: 3744
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static long Mod = (long)1e9 + 7;
        static long[] primes = new long[1001];
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var Ai = Sarray();
            var dct = new Dictionary<long, long>();
            foreach(var a in Ai)
            {
                if (!dct.ContainsKey(a)) dct[a] = 0;
                ++dct[a];
            }
            for(var i=1;i<=N;++i)
            {
                var k = Abs(N - 2 * i + 1);
                if(!dct.ContainsKey(k))
                {
                    WriteLine(0);
                    return;
                }
                var num = 2;
                if (0 == k)
                    num = 1;
                if(dct[k]!=num)
                {
                    WriteLine(0);
                    return;
                }
            }
            WriteLine(modpow(2, N / 2, Mod));
            //Out.Flush();
        }
        static long modpow(long a, long n, long mod)
        {
            var res = 1L;
            while (0 < n)
            {
                if (n % 2 != 0) res = res * a % mod;
                a = a * a % mod;
                n >>= 1;
            }
            return res;
        }

    }
}


Measured memory_bytes: 23136