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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

const ll MOD = (ll)1e9+7; //change it for other mods

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}

void solve(ll testnum)
{
    ll n;
    cin >> n;
    vpll d(n);
    for(ll i=0;i<n;i++) {
    	cin >> d[i].ff >> d[i].ss;
    }
    ll check = 0;
    for(ll i = 0; i < n-2; i++) {
    	if(d[i].ff == d[i].ss && d[i+1].ff == d[i+1].ss && d[i+2].ff == d[i+2].ss) {
    		check = 1;
    		break;
    	}
    }
    if(check) {
    	cout << "Yes\n";
    } else {
    	cout << "No\n";
    }
}

int main()
{
    FAST_IO;
    #ifdef STIO 
      freopen("input.txt" , "r", stdin);
      freopen("output.txt" , "w", stdout);
    #endif
    ll t = 1;
    // cin >> t;
    for (ll i = 1; i <= t; i++) {
        // cout << "Case #" << i << ": ";
        solve(i);
    }
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int sum=0;
int a[n];
for(int i=0;i<n;i++)
{
	cin>>a[i];
	sum+=a[i];
}
double o=double(sum)/(4*m);
int count=0;
sort(a,a+n);
reverse(a,a+n);
for(int i=0;i<n;i++)
{
  if(a[i]>=o)
     count++;
	 if(count==m)
	 {
	 	cout<<"Yes"<<endl;
	 	return 0;
		 }	
}
cout<<"No"<<endl;
return 0;
}

Measured memory_bytes: 3620
N,K=map(int,input().split())
L=[1]
P=[1]
BG=[0]
for i in range(1,N+1):
  L.append(L[i-1]*2+3)
  P.append(P[i-1]*2+1)
def f(x,y):
  if x==0:
    if y==0:
      return 0
    if y==1:
      return 1
  elif y<=1:
    return 0
  elif 1<y<=L[x-1]+1:
    return f(x-1,y-1)
  elif L[x-1]+1<y<L[x]:
    return P[x-1]+1+f(x-1,y-2-L[x-1])
  elif y==L[x]:
    return P[x]
print(f(N,K))

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


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

    vector<int> v(n+1, 0);
    for(int i = 1; i <= n; i ++){
        int w; cin >> w;
        v[i] = v[i-1] + w;
    }
    int ans = 100000;
    for(int t = 1; t < n; t++){
        int s1 = v[t];
        int s2 = v[n] - v[t];
        int diff = abs(s1 - s2);
        if(ans > diff)
            ans = diff;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
pair = [[] for i in range(N)]

for _ in range(N):
  pair[_] = list(map(int,input().split()))
  a = pair[_][0]
  b = pair[_][1]

ans = 0
diff = 0

for i in range(N - 1,-1,-1):
  A = pair[i][0]
  a = pair[i][0] + ans
  b = pair[i][1]
  diff = b - a + b * (a // b)

  if a % b != 0:
    ans += diff
  
print(ans)

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 A, B, V, W, T;
	cin >> A >> V >> B >> W >> T;
	int64 dis = abs(A - B);
	int64 sa = V - W;
	if (V <= W || (dis + sa - 1) / sa > T) {
	  cout << "NO" << endl;
	} else {
	  cout << "YES" << endl;
	}
}


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

int main(){
    ll A,B,K;
    cin >> A >> B >> K;
    for (ll i = 1; i <= K; i++){
        if (i % 2 == 1){
            if (A % 2 == 1) A--;
            B += A / 2;
            A /= 2;
        }
        else{
            if (B % 2 == 1) B--;
            A += B / 2;
            B /= 2;
        }
    }
    cout << A << " " << B << endl;
}


Measured memory_bytes: 3636
import heapq

n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr,reverse=True)
ans=0
q=[]
heapq.heappush(q,-arr[0])
for i in range(1,n):
  ans+=-heapq.heappop(q)
  heapq.heappush(q,-arr[i])
  heapq.heappush(q,-arr[i])
print(ans)

Measured memory_bytes: 31792
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1e18;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
    //a^tを求める
    //例：d[i] = mint(k/i).pow(n);
    //mint(2).pow(n); 2^n
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}



int main() {
  ll h,w;
  cin>>h>>w;
  vector<string> g(h);
  rep(i,h)cin>>g[i];
  mint dp[h+5][w+5];

  rep(i,h+5)rep(j,w+5)dp[i][j]=0;
  dp[1][1]=1;

  rep(i,h)rep(j,w){
    if (g[i][j]=='#')continue;
    if (i==0 and j==0)continue;
    dp[i+1][j+1]=dp[i][j+1]+dp[i+1][j];

  }

cout<<dp[h][w].x;

}


Measured memory_bytes: 13380
while True:
	n = int(input())
	if n == 0:
		break
	cheapest = float('inf')
	for bagsA in range(n // 200 + 1):
		for bagsB in range(n // 300 + 1):
			for bagsC in range(n // 500 + 1):
				if 200 * bagsA + 300 * bagsB + 500 * bagsC == n:
					price = 1520 * (bagsA // 5) + 380 * (bagsA % 5) + 1870 * (bagsB // 4) + 550 * (bagsB % 4) + 2244 * (bagsC // 3) + 850 * (bagsC % 3)
					cheapest = min(cheapest, price)
	print(cheapest)

Measured memory_bytes: 7668
fun main (args : Array<String>) {
	val n = readLine()
	val N : Int = n!!.toInt()
	var list : MutableList<Int> = mutableListOf()
	var result : Int = 0
	for (i in 0..N - 1) {
		val p = readLine()
		list.add(p!!.toInt())
	}
	list.sort()
	list[N - 1] = list[N - 1] / 2
	for (i in 0..N - 1) {
		result += list[i]
	}
	println("${result}")
}

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  vector<int> t(n);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i) >> t.at(i);
  }
  string x;
  cin >> x;
  bool sleep = false;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (sleep) ans += t.at(i);
    if (s.at(i) == x) sleep = true;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int maxn = 1e5+100;

int n,m;
int a[maxn];
int b[maxn];
// double ans;
int main(int argc, char const *argv[])
{
	cin>>n>>m;
	rep(i,0,m)
	{
		cin>>a[i];
	}
	sort(a,a+m);
	int sum = 0;
	rep(i,0,m-1)
	{
		b[i] = a[i+1] - a[i];
		sum += b[i];
	}
	sort(b,b+m);
	if(n >= m)
	{
		cout<<0<<endl;
	}
	else
	{
		per(i,m-n+1,m)
		{
			sum -= b[i];
		}
		cout<<sum<<endl;
	}
	return 0;
}

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

int m[1010],n[1010];
int main(){
	int N,M,nw,cnt;
	while(1){
		cin>>N>>M;
		if(N==0&&M==0) break;
		for(int i=0;i<N;i++){
			cin>>n[i];
		}
		for(int i=0;i<M;i++){
			cin>>m[i];
		}
		nw=cnt=0;
		while(1){
			nw+=m[cnt];
			if(nw<=N-1)nw+=n[nw];
			cnt++;
			if(nw>=N-1){
				break;
			}
		}
		cout<<cnt<<endl;
	}
}

Measured memory_bytes: 1168
import itertools

n,m=map(int,input().split())
linelist=[list(map(int,input().split())) for i in range(m)]

numlist=[i for i in range(1,n+1)]

plist=list(itertools.permutations(numlist))

sum=0

for challenger in plist:
	if challenger[0] != 1:
		pass
	else:
		needlist=[]
		for i in range(n-1):
			tmp=[]
			tmp.extend([challenger[i],challenger[i+1]])
			tmp.sort()
			needlist.append(tmp)
		addflag=True
		for need in needlist:
			if not need in linelist:
				addflag = False
		
		if addflag:
			sum+=1

print(sum)


Measured memory_bytes: 8052
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 100000+5
#define MOD 20190823
#define eps 1e-8
#define mp make_pair
#define INF 1000000000+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline void read(ll &f){
	f=0;
    ll x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
int ans=0;
int main(){
	string s;
	int n;
	cin>>n;
	cin>>s;
	for(ll i=0;i<s.size();i++){
		if(s.substr(i,3)=="ABC"){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    int N,M,Q; cin >> N >> M >> Q;
    int cnt[N+2][N+2]={};
    for(int i=0;i<M;i++){
        int l,r; cin >> l >> r;
        cnt[l][r]++;
    }
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            cnt[i][j]+=cnt[i][j-1];
        }
    }
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            cnt[i][j]+=cnt[i-1][j];
        }
    }
    while(Q--){
        int p,q; cin >> p >> q;
        cout << cnt[q][q]+cnt[p-1][p-1]-cnt[p-1][q]-cnt[q][p-1] << endl;
    }
}

Measured memory_bytes: 1920
// https://atcoder.jp/contests/abc141/tasks/abc141_e
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using I = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (I i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    I N;
    string S;
    cin >> N >> S;
    I len = S.length(), maxv = 0;
    REP(d, len) {
        I cnt = 0;
        REP(i, len - d) {
            if (S[i] == S[i + d]) {
                cnt++;
            } else {
                cnt = 0;
            }
            maxv = max(maxv, min(cnt, d));
        }
    }
    cout << maxv << endl;

    return 0;
}

Measured memory_bytes: 384
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int a = stdIn.nextInt();
			int b = stdIn.nextInt();
			System.out.println(a + b);
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int ans=0;
  int m = 0;
  for(int i = 0;i<n; i++){
    int p;
    cin >> p;
    m = max(p,m);
    ans += p;
  }
  cout << ans - (m /2); 
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
long mod=1e6+3;
long fac[1<<20];
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
main()
{
	fac[0]=1;
	for(int i=1;i<mod;i++)fac[i]=fac[i-1]*i%mod;
	int Q;cin>>Q;
	for(;Q--;)
	{
		long x,d,n;cin>>x>>d>>n;
		if(d==0)
		{
			cout<<power(x,n)%mod<<endl;
			continue;
		}
		x=x*power(d,mod-2)%mod;
		if(x+n-1>=mod)cout<<0<<endl;
		else cout<<fac[x+n-1]*power(fac[x-1],mod-2)%mod*power(d,n)%mod<<endl;
	}
}


Measured memory_bytes: 9088
#include<stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,G[100][100];
int color[100],d[100],f[100],tt;

void DFS_visit(int v){
  int i;
  color[v]=GRAY;
  d[v]=++tt;
  for(i=0;i<n;i++){
    if(G[v][i]==0)continue;
    if(color[i]==WHITE){
      DFS_visit(i);
    }
  }
  color[v]=BLACK;
  f[v]=++tt;
}

void DFS(){
  int i;
  //初期化
  for(i=0;i<n;i++){
    color[i]=WHITE;
  }
  tt=0;
  for(i=0;i<n;i++){
    if(color[i]==WHITE){
      DFS_visit(i);
    }
  }
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
}
  



int main(){
  int i,j,u,k,v;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      G[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      G[u][v]=1;
    }
  }

  DFS();

  return 0;
}

      



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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s, t;
	cin >> s >> t;
	int ans = 0;
	for (int i=0; i<s.size(); i++) if (s[i] != t[i]) ans++;
	cout << ans;
	return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();

int div(lli n) {
    int count=0;
    for(int i=1;i*i<=n;++i) {
        if(n%i==0) {
            if(n/i==i) {
                ++count;
            }
            else {
                count+=2;
            }
        }
    }
    // cout<<count<<endl;

    return count;
}
int main() {

    int a[5];
    f1(i,5) {
        cin>>a[i];
    }
    int x;
    f1(i,5) {
        if(a[i]==0)
         {
            x=i;
         }
    }
    cout<<x+1<<endl;
    return 0;
}

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

vector<vector<ll>> G;
ll dist[210][210];

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll N; cin >> N;
	G.resize(N);
	REP(i, N)REP(j, N)
	{
		char c; cin >> c;
		if (c == '1')
		{
			G[i].push_back(j);
			dist[i][j] = 1;
		}
		else
			dist[i][j] = INF;
	}


	vector<ll> color(N, -1);
	queue<ll> que;
	que.push(0);
	color[0] = 0;
	while (que.size())
	{
		ll now = que.front();
		que.pop();

		for (auto &nv : G[now])
		{
			if (color[nv] != -1)
			{
				if (color[nv] == color[now])
				{
					std::cout << -1 << std::endl;
					return 0;
				}
				continue;
			}
			color[nv] ^= color[now];
			que.push(nv);
		}
	}

	REP(via, N)REP(s, N)REP(t, N)
		dist[s][t] = min(dist[s][t], dist[s][via] + dist[via][t]);

	ll res{0};
	REP(i, N)REP(j, N)
	{
		if (i == j) continue;
		if (dist[i][j] != INF)
		{
			res = max(res, dist[i][j]);
		}
	}

	std::cout << res + 1<< std::endl;
	
	return 0;
}


Measured memory_bytes: 4344
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0207

"""
import sys
from sys import stdin
from collections import deque
input = stdin.readline


def solve(w, h, xs, ys, xg, yg, blocks):
    # ????????????????????±????????°???????????????l
    field = [[0] * (w+1) for _ in range(h+1)]
    for c, d, x, y in blocks:
        field[y][x] = c
        field[y][x+1] = c
        field[y+1][x] = c
        field[y+1][x+1] = c

        if d == 0:              #  ?¨????
            field[y][x+2] = c
            field[y][x+3] = c
            field[y+1][x+2] = c
            field[y+1][x+3] = c
        else:                   #  ??????
            field[y+2][x] = c
            field[y+3][x] = c
            field[y+2][x+1] = c
            field[y+3][x+1] = c

    # ????????????????§????????????´????????§?¨??????????
    dy = [-1, 1, 0, 0]
    dx = [0, 0, -1, 1]

    # ??????????????°???(S)??¨??´????????°???(G)?????????

    d = [[float('inf')] * (w+1) for _ in range(h+1)] #  ??????????????°?????????????????¢???INF??§?????????
    Q = deque()
    Q.append((xs, ys))
    d[ys][xs] = 0
    color = field[ys][xs]

    while Q:
        xc, yc = Q.popleft()        #  ?????¨??°?????§?¨?
        if xc == xg and yc == yg:
            return 'OK'
        for i in range(len(dx)):
            xn = xc + dx[i]
            yn = yc + dy[i]
            #  ?§????????????§???????????? ?????? ??¢?????¢?´¢?????§???????????°??????????????§?????¢?´¢????¶???????
            if 0 < xn <= w and 0 < yn <= h and d[yn][xn] == float('inf') and field[yn][xn] == color:
                Q.append((xn, yn))
                d[yn][xn] = d[yc][xc] + 1
    return 'NG'


def main(args):
    while True:
        w, h = map(int, input().split())
        if w == 0 and h == 0:
            break
        xs, ys = map(int, input().split())
        xg, yg = map(int, input().split())
        n = int(input())
        blocks = [list(map(int, input().split())) for _ in range(n)]

        result = solve(w, h, xs, ys, xg, yg, blocks)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 8116
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
	Scanner scanner = new Scanner(System.in);
	int a = scanner.nextInt();
	int b = scanner.nextInt();
	int c = scanner.nextInt();
	int d = scanner.nextInt();
	
	if (Math.abs(a - c) <= d) {
	    System.out.println("Yes");
	} else if ( Math.abs(a - b) <= d && Math.abs(b - c) <= d) {
	    System.out.println("Yes");
	} else {
	    System.out.println("No");
	}
    }
}

Measured memory_bytes: 22356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    if(S.substr(0, 4) == "YAKI") cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int N, X, x, ans;
	cin >> N >> X;
	rep(i, N) {
		cin >> x;
		if (!i)ans = abs(X - x);
		else ans = gcd(ans, abs(X - x));
	}
	cout << ans;
}


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

const int mod = 1'000'000'007;
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint dp[10010010];
bool fl[10010010];
int m[21][21];
int n;
int p2[22];
int num(int man, int index) {
  int ind = index;
  rep(i, n) {
    if (!(ind & 1) && (m[man][i] == 1)) {
      if (man == n-1) {dp[index] = 1; return 0;}
      if (!fl[index + p2[i]]) num(man + 1, index + p2[i]);
      dp[index] += dp[index + p2[i]];
    }
    ind = ind >> 1;
  }
  fl[index] = true;
  return 0;
}

int main() {
  cin >> n;
  p2[0] = 1;
  rep(i, n) p2[i+1] = p2[i] * 2;
  rep(i, p2[n]) {dp[i] = 0; fl[i] = false;}
  rep(i, n)rep(j, n) cin >> m[i][j];
  num(0, 0);
  cout << dp[0].x << endl;
}
    
    

Measured memory_bytes: 84224
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//int n = sc.nextInt();
		//String[][] array = new String[100][500];
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		List<Integer> list=new ArrayList<Integer>();

		double n = sc.nextInt();
		double bunbo =1;

		for(int i=0; n>i;i++) {
			int a = sc.nextInt();
			bunbo=bunbo*a;
			list.add(a);
		}

		double bunsi=bunbo/list.get(0);

		for(int i=1;n>i;i++) {
			bunsi=bunsi+bunbo/list.get(i);
		}

		double answer=bunbo/bunsi;

		System.out.println(answer);


		}

}

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

vector<int64_t> calc_score(vector<vector<int>>& s, vector<int>& c, vector<int>& t) {
    vector<int> last(c.size(), 0);
    vector<int64_t> ret(t.size(), 0);
    for (auto i = 0; i < (int)t.size(); i++) {
        if(i != 0) ret[i] = ret[i - 1];
        ret[i] += s[i][t[i] - 1];
        last[t[i] - 1] = i + 1;
        for (auto j = 0; j < 26; j++) {
            ret[i] -= c[j] * (i + 1 - last[j]);
        }
    }
    return ret;
}

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

    vector<int> c(26);
    for (auto i = 0; i < 26; i++) cin >> c[i];

    vector<vector<int>> s(d, vector<int>(26));
    for (auto i = 0; i < d; i++) {
        for (auto j = 0; j < 26; j++) cin >> s[i][j];
    }

    vector<int> t(d);
    for (auto i = 0; i < d; i++) cin >> t[i];
    auto score = calc_score(s, c, t);
    for(auto & elm : score) cout << elm << endl;

    return 0;
}

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

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

typedef long long ll;

const char nl = '\n' ;
const ll MOD = 1e9 + 7;
int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);
   string s; cin >> s;
   int a[300] = {};
   for(int i =0; i < s.size(); i++)
   {
      a[s[i]]++;
      if(a[s[i]] == 2)
      {
         cout << "no" << nl;
         return 0;
      }
   }
   cout << "yes" << nl;
   return 0;

}


Measured memory_bytes: 3624
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

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

    int x, y, z, K;
    cin >> x >> y >> z >> K;
    vector<ll> a(x), b(y), c(z);
    REP(i, x) { cin >> a[i]; }
    REP(i, y) { cin >> b[i]; }
    REP(i, z) { cin >> c[i]; }

    RSORT(a);
    RSORT(b);
    RSORT(c);

    vector<ll> ans;

    REP(i, x) {
        REP(j, y) {
            REP(k, z) {
                if ((i + 1) * (j + 1) * (k + 1) <= K)
                    ans.push_back(a[i] + b[j] + c[k]);
                else
                    break;
            }
        }
    }

    RSORT(ans);
    REP(i, K) cout << ans[i] << '\n';

    return 0;
}

Measured memory_bytes: 1404
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
const long long INF = 1LL << 60;


const int K = 43;
//dp[何桁目(0-42くらい)][繰り上がりあるか(0 or 1)][今までの範囲がA以下かどうか(0or1)] = 最大値
long long dp[K][2][2];

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

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

    long long X =0;
    for(int i=2; i<N; ++i){
        X ^= A[i];
    }
    //１つ目をa２つ目をｂ，全体をSにする
    long long a = A[0];
    long long b = A[1];
    long long S = a + b;


    //init,その状態にイケナイに初期化
    for(int i=0; i<K; ++i){
        for(int j=0; j<2; ++j){
            for(int k=0; k<2; ++k){
                dp[i][j][k] = -1;
            }
        }
    }
    //最初は0桁、繰り上がりなし、今の所A以下
    dp[0][0][0] = 0;
    //
    long long v = 1;

    for(int i=0; i<K-1; ++i){
        //今の桁をわかりやすく表現
        int cx = X&1;
        int cs = S&1;
        int ca = a&1;

        //4通りの状態
        for(int j=0; j<2; ++j){
            for(int k=0; k<2; ++k){
                //遷移を考える
                for(int na = 0; na<2; ++na){
                    for(int nb=0; nb <2; ++nb){
                        //今がもし行けない場所だったら何もできない
                        if( dp[i][j][k] == -1 ) continue;
                        //桁1つ増やす
                        int ni = i+1;
                        
                        int nj = 0;
                        
                        int nk = k;
                        
                        //今のくらいと一致してなかったらだめ
                        if((na^nb) != cx) continue;
                        //jは繰り上がり分
                        int ns = na + nb +j;
                        //sは普遍なので一致してないとだめ
                        if(ns % 2 != cs) continue;

                        //ここまでを満たせば遷移できる
                        //和が２以上なら繰り上がりが起きる
                        if(ns >= 2) nj = 1;
                        
                        // nkはaの桁とa'のけたを比較して
                        if(ca < na) {
                            //大きくなるなら１
                            nk = 1;
                        }else if (ca == na){
                            //一致ならkが変わらない
                            nk = k;
                        }else{
                            //小さいなら0
                            nk = 0;
                        }
                        //末尾にnaを追加したもの,vは桁が増えるごとに位置増える
                        dp[ni][nj][nk] = max(dp[ni][nj][nk], dp[i][j][k]|(v*na));

                    }
                }
            }
        }
        X >>= 1;
        S >>= 1;
        a >>= 1;
        v <<= 1;

    }

    //答え
    a = dp[K-1][0][0];
    if( a == -1 || a == 0){
        cout << -1 << endl;
        return 0;
    }

    long long ans = A[0] - a;
    cout << ans << endl;
    return 0;

    // //O(N)　解法
    // bool skip = false;
    // if(A[0] == 1) skip = true;

    // if(!skip){
    //     for(long long i=0; i<=A[0]; ++i){
    //         long long tmp = h ^ (A[0] -i) ^ (A[1] +i);
    //         if(tmp == 0){
    //             ans = i;
    //             break;
    //         }
    //     }        
    // }

    // cout << ans << endl;
}

Measured memory_bytes: 3584
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Akash
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ATenki solver = new ATenki();
        solver.solve(1, in, out);
        out.close();
    }

    static class ATenki {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String a = in.nextLine();
            String b = in.nextLine();
            int ans = 0;
            for (int i = 0; i < 3; i++) {
                if (a.charAt(i) == b.charAt(i))
                    ans++;
            }
            out.println(ans);
        }

    }
}



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

typedef pair<int,int> pii;

int N;
vector<int> V;
vector<pii> W;

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)
    {
        int a;
        scanf("%d",&a);
        V.push_back(a);
    }
    sort(V.begin(),V.end());
    for(int i = 0; i < V.size(); i++)
    {
        if(i == 0 || W[W.size() - 1].first != V[i])
        {
            W.push_back(make_pair(V[i],1));
        }
        else
        {
            W[W.size() - 1].second++;
        }
    }
    if(W.size() > 2)
    {
        printf("No\n");
        return 0;
    }
    if(W.size() == 1)
    {
        if(N == W[0].first + 1 || W[0].first * 2 <= N)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
        return 0;
    }
    if(W[0].first >= W[0].second && (W[1].first - W[0].second) * 2 <= W[1].second && W[0].second <= W[1].first)
    {
        printf("Yes\n");
        return 0;
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        string s, t;
        in >> s;
        in >> t;
        bool ok = true;
        for (int i = 0; i < 3; i++) {
            ok &= t[3 - i - 1] == s[i];
        }
        out << (ok ? "YES" : "NO") << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <numeric>
using namespace std;

template <typename T>
void readVec(vector<T>& v, int n)
{
	for(int i = 0; i < n; ++i)
			cin >> v[i];
}

template <typename T>
void printVec(vector<T>& v, int n)
{
	for(int i = 0; i < n; ++i)
			cout << v[i] << " ";
}


int main()
{		
		int n, m; cin >> n >> m;
		vector<int> v(n); readVec(v, n);
		vector<int> good(n+1, 2);
		vector<int> reached(n+1, 0);
		int a, b;
		for(int i = 0; i < m; ++i)
		{
			cin >> a >> b;
			--a; --b;
			reached[a] = 1;
			reached[b] = 1;
			if(v[a] < v[b])
			{
				good[a] = 0;
			}
			if(v[b] < v[a])
			{
				good[b] = 0;
			}
			if(v[b] == v[a])
			{
				good[a] = 0;
				good[b] = 0;
			}
		}
		
		int ans = 0;
		for(int i = 0; i <n; ++i)
		{
			if(good[i])
					++ans;
		}

		cout << ans;
		return 0;
}


Measured memory_bytes: 4224
import java.util.Scanner;


public class Main{

	static int[][] result;
	static boolean[] stillVisited;

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int cnt = Integer.parseInt(s.nextLine());
		int[][] list = new int[cnt][cnt];
		stillVisited = new boolean[cnt];
		result = new int[cnt][2];
		for(int i=0 ; i<cnt ; i++) {
			String[] tmp = s.nextLine().split(" ");
			stillVisited[i] = false;
			for(int j=0 ; j<tmp.length-2 ; j++) {
				list[Integer.parseInt(tmp[0])-1][j] = Integer.parseInt(tmp[j+2]);
			}
		}
		int c = 1;
		for(int i=0 ; i<cnt ; i++){
			c = dfs(list, i, c);
			c += 1;
		}
		for(int i=0 ; i<result.length ; i++) {
			System.out.println((i+1) + " " + result[i][0] + " " + result[i][1]);
		}
	}

	public static int dfs(int[][] list, int current, int cnt) {
		if(stillVisited[current]) {
			return cnt-1;
		}
		stillVisited[current] = true;
//		if(list[current][0]==0)
//			return cnt;
		//?????????????????????
		result[current][0] = cnt;
		for(int i=0 ; 0!=list[current][i] ; i++) {
			cnt = dfs(list, list[current][i]-1, cnt+1);
		}
		int returnV = cnt + 1;
		//?????????????????????
		result[current][1] = returnV;
		return returnV;
	}
}

Measured memory_bytes: 19616
import java.util.Scanner;

public class Main {

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

		Scanner sc1 = new Scanner(System.in);

		int time = sc1.nextInt();

		int hh = time / 3600;
		time = time % 3600;
		int mm = time / 60;
		int ss = time % 60;

		System.out.println(hh + ":" + mm + ":" + ss);

		sc1.close();

	}

}


Measured memory_bytes: 26256
from collections import Counter
n = int(input())
dd = list(map(int,input().split()))
dic_c = Counter(dd)

zero_flag = False
if dic_c[0]!= 1 or dd[0]!=0 :
  zero_flag = True

for i in range(max(dd)):
  if dic_c[i] == 0 :
    zero_flag = True

if zero_flag:
  print(0)  
else:
  ans = 1
  for i in range(1,max(dd)):
    ans *= dic_c[i]**dic_c[i+1]
  print(ans % 998244353)    

Measured memory_bytes: 19936
<?php

ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_WARNING);
ini_set('display_errors', 'Off');

// define('DEBUG', true);
define('DEBUG', false);

fscanf(STDIN, "%d %d", $H, $W);
fscanf(STDIN, "%d", $N);
$a = explode(" ", trim(fgets(STDIN)));
array_unshift($a, 0);
// var_dump($a);

$x = 0;
$y = 0;
$dx = 1;
$dy = 0;
$ans = array(array());
$cursor = 1;

while(true) {
    if (DEBUG) echo "x:{$x} y:{$y} c:{$cursor}\n";
    $a[$cursor]--;
    $color = $cursor;
    if ($a[$cursor] == 0) {
        $cursor++;
    }
    $ans[$x][$y] = $color;
    if ($cursor > $N) {
        break;
    }
    $x += $dx;
    $y += $dy;
    if ($x == $W) {
        $x--;
        $y++;
        $dx = 0;
        $dy = 1;
    }
    if ($y == $H) {
        $y--;
        $x--;
        $dx = -1;
        $dy = 0;
    }
    if ($x < 0) {
        $x++;
        $y--;
        $dx = 0;
        $dy = -1;
    }
    if ($y < 0) {
        $x++;
        $y++;
        $dx = 1;
        $dy = 0;
    }
    if (isset($ans[$x][$y])) {
        if (DEBUG) echo "XX:{$x} YY:{$y} {$dx} {$dy}\n";
        if ($dx == 1 && $dy == 0) {
            if (DEBUG) echo "case A\n";
            $x--;
            $y++;
            $dx = 0;
            $dy = 1;
        } elseif ($dx == -1 && $dy == 0) {
            if (DEBUG) echo "case B\n";
            $x++;
            $y--;
            $dx = 0;
            $dy = -1;
        } elseif ($dx == 0 && $dy == 1) {
            if (DEBUG) echo "case C\n";
            $y--;
            $x--;
            $dx = -1;
            $dy = 0;
        } elseif ($dx == 0 && $dy == -1) {
            if (DEBUG) echo "XXXX\n";
            $x++;
            $y++;
            $dx = 1;
            $dy = 0;
        }
    }
}

for ($y = 0; $y < $H; $y++) {
    $arrTmp = array();
    for ($x = 0; $x < $W; $x++) {
        $arrTmp[] = $ans[$x][$y];
    }
    echo implode(" ", $arrTmp) . PHP_EOL;
}



Measured memory_bytes: 6776
n, k, q = gets.chomp.split.map(&:to_i)
corrects = Array.new(n, 0)
q.times do
  correct = gets.chomp.to_i
  corrects[correct - 1] += 1
end

corrects.each do |count|
  puts k - q + count > 0 ? 'Yes' : 'No'
end

Measured memory_bytes: 5116
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
  
def main():
  n = int(input())
  A = list(map(int,input().split()))
  B = list(map(int,input().split()))
  C = list(map(int,input().split()))
  ans = 0
  last = A[0]-1
  for i in range(n):
    ans += B[A[i]-1]
    #print(i,last,ans)
    if A[i]-1 == last + 1:
      #print(i,last)
      #print('come?')
      ans += C[last]
      last = A[i]-1
    else:
      last = A[i]-1
  print(ans)
if __name__ == '__main__':
  main()

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

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		String s=scan.next();
		String t=scan.next();
		scan.close();

		char[] cs =s.toCharArray();
		char[] ct =t.toCharArray();
		for(int i=0;i<n;i++) {
			String x=String.valueOf(cs[i])+String.valueOf(ct[i]);
			System.out.print(x);
		}
		System.out.println();
	}

}

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

Int gcd(Int a, Int b) { return b ? gcd(b, a%b) : a;}
Int lcm(Int a, Int b) { return a/gcd(a,b) * b; }

int main() {
    Int a, b, c, d; cin >> a >> b >> c >> d;
    Int C = b/c - (a-1)/c;
    Int D = b/d - (a-1)/d;

    Int lcm_v = b/lcm(c,d) - (a-1)/lcm(c,d);
    Int ans = (b - a+1) - C-D+lcm_v;
    cout << ans << endl;
}

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

int main() {
  ll n;
  cin >> n;
  double sum=0,a[n],b[n];
  r(i,n)cin >> a[i] >>b[i];
  r(i,n){
    for(int j=i+1;j<n;j++){
      sum+=sqrt((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]));
    }
  }
  printf("%.10lf\n",sum*2/n);
}

Measured memory_bytes: 256
N=int(input())
S=[input() for i in range(N)]
X=[50]*26
for i in range(N):
  Y=[0]*26
  for j in range(len(S[i])):
    Y[ord(S[i][j])-ord('a')]+=1
  for j in range(26):
    X[j]=min(X[j],Y[j])
for i in range(26):
  for j in range(X[i]):
    print(chr(i+ord('a')),end="")
print()

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_SIZE=2000000;
ll segMin[MAX_SIZE - 1],segMax[MAX_SIZE - 1], segAdd[MAX_SIZE - 1];
int n,N=1;

//??????[a, b)??????x???????????????.
void add(int a, int b, int x, int k = 0, int l = 0, int r = N)
{
	if (r <= a || b <= l) return;
	if (a <= l && r <= b){
		segAdd[k] += x;
		while (k){
			k = (k - 1) / 2;
			segMin[k] = min(segMin[k * 2 + 1] + segAdd[k * 2 + 1], segMin[k * 2 + 2] + segAdd[k * 2 + 2]);
			segMax[k] = max(segMax[k * 2 + 1] + segAdd[k * 2 + 1], segMax[k * 2 + 2] + segAdd[k * 2 + 2]);
		}
		return;
	}
	
	add(a, b, x, k * 2 + 1, l, (l + r) / 2);
	add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}

ll getMin(int a, int b, int k = 0, int l = 0, int r = N)
{
	if (r <= a || b <= l) return (LLONG_MAX);
	if (a <= l && r <= b) return (segMin[k] + segAdd[k]);
	ll left = getMin(a, b, k * 2 + 1, l, (l + r) / 2);
	ll right = getMin(a, b, k * 2 + 2, (l + r) / 2, r);
	return (min(left, right) + segAdd[k]);
}
ll getMax(int a, int b, int k = 0, int l = 0, int r = N)
{
	if (r <= a || b <= l) return (-LLONG_MAX);
	if (a <= l && r <= b) return (segMax[k] + segAdd[k]);
	ll left = getMax(a, b, k * 2 + 1, l, (l + r) / 2);
	ll right = getMax(a, b, k * 2 + 2, (l + r) / 2, r);
	return (max(left, right) + segAdd[k]);
}
void dump() {
  for(int i=0;i<n/2;i++) {
    cout<<i<<": "<<getMin(i,i+1)<<", "<<getMax(i,i+1)<<endl;
  }
}
int main() {
  cin >> n;
  while(N<n) N<<=1;
  ll a[n];
  for(int i=0; i<n; i++) cin >> a[i];
  for(int i=0; i<n/2; i++) add(i,i+1,a[i]-a[n-1-i]);
  int m;
  cin >> m;
  while(m--) {
    int x,y,z;
    cin >> x >> y >> z;
    x--,y--;
    if(y<n/2) add(x,y+1,z);
    else if(n/2<=x) {
      x=n-x-1;
      y=n-y-1;
      add(y,x+1,-z);
    } else {
      y=n-y-1;
      //cout<<__LINE__<<": "<<x<<", "<<y<<endl;
      add(x,n/2+1,z);
      add(y,n/2+1,-z);
    }
    //dump();
    ll mi=getMin(0,n/2+1);
    ll ma=getMax(0,n/2+1);
    if(!mi&&!ma) cout << 1 << endl;
    else cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 26568
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

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

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

  int n; cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  a.erase(unique(a.begin(), a.end()), a.end());
  int N = a.size();

  ll ans = 0;
  int i  = 1, flag = 0;
  while(i < N) {
    if(a[i-1] < a[i]) {
      if(flag == 0) {
        flag = 1;
        i++;
      } else if(flag == 1) {
        i++;
      } else {
        flag = 0;
        i++;
        ans++;
      }
    } else {
      if(flag == 0) {
        flag = -1;
        i++;
      } else if(flag == -1) {
        i++;
      } else {
        flag = 0;
        i++;
        ans++;
      }
    }
  }

  cout << ans+1 << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  
  cin >> a >> b;
  
  if ( a >= 13){
    cout << b << endl;
  }
  
  else if (a>= 6 and a<13){
    cout << b/2 << endl;
  }
  
  else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
k, n = map(int, input().split())
a = list(map(int, input().split()))
d_list = [] * n
for i in range(1, n):
    d_list.append(a[i] - a[i - 1])
d_list.append(k - a[n - 1] + a[0])
ans = sum(d_list) - max(d_list)
print(ans)


Measured memory_bytes: 26420
import collections
import itertools

def dfs(used:set, newi:int, i:int):
    global D, N, iters
    new1 = newi
    new2 = (24-newi) * (newi!=0)
    if new1 not in used:
        used.add(new1)
        if i+1 == N:
            iters.append(list(used))
        else:
            dfs(used, D[i+1], i+1)
        used.remove(new1)
    if new2 not in used:
        used.add(new2)
        if i+1 == N:
            iters.append(list(used))
        else:
            dfs(used, D[i+1], i+1)
        used.remove(new2)

def main():
    global D, N, iters
    N = int(input())
    D = list(map(int, input().split()))
    D.sort()
    iters = []
    used = set([0])
    dfs(used, D[0], 0)
    if len(iters) == 0:
        print(0)
        return
    maxd = 0
    for tmp in iters:
        pairs = itertools.combinations(tmp, 2)
        mind = 25
        for x, y in pairs:
            mind = min(mind, min(abs(x-y), 24-abs(x-y)))
        maxd = max(maxd, mind)
    print(maxd)

if __name__ == "__main__":
    main()


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

using namespace std;

void Solve(){
	int n;
	long long k;
	cin>>n>>k;
	vector<int> v(n + 1);
	for(int i = 1; i <= n; i++)
		cin>>v[i];
	vector<bool> vst(n + 1);
	vector<int> res;
	int i = 1;
	res.push_back(i);
	int c = 1;
	while(!vst[i]){
		vst[i] = true;
		i = v[i];
		if(vst[i]){
			c = i;
			break;
		}
		res.push_back(i);
	}
	int num = 0;
	for(int i = 0; i < res.size(); i++){
		if(res[i] == c){
			num = i;
			c = res.size() - i;
			break;
		}
	}
	
	if(k < res.size()){
		cout<<res[k]<<'\n';
		return;
	}
	k -= (res.size() - c);
	k = k % c;
	cout<<res[num + k]<<'\n';
	return;

}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int T = 1;
	//cin>>T;
	while(T--){
		Solve();
	}
}

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

int i;

int main()
{
    string s;
    int count = 0;

    cin >> s;

    for (i = 0; i < 3; i++)
    {
        if (s[i] == '7')
        {
            count++;
        }
    }

    if (count != 0)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}

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

using namespace std;

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i =0;i<t;i++)
#define bs(a,x) binary_search(a.begin(),a.end(),x)
#define ll long long int
#define ul unsigned long int
#define ld long double
#define umpi unordered_map<int,int> 
#define umpl unordered_map<ll,ll> 
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mod 1000000007 
#define N 10000000
#define all(a) a.begin(),a.end()
#define point pair<int,int>
const int inf = 1000000007;
const ll linf = 1ll * inf * inf;

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

string to_string(char x)
{
	string s(1,x);
	return s;
}

ll dp[100005];

ll longest_path(vector<vector<ll>> &graph,ll v)
{
	if(dp[v]!=-1)return dp[v];
	else if(graph[v].size()==0)return 0;
	else
	{
		ll ans=0;
		for(ll i=0;i<graph[v].size();i++)
		{
			ans=max(ans,1+longest_path(graph,graph[v][i]));
		}
		return dp[v]=ans;
	}
}

int main()
{
	
	fio;
	ll t;t=1;
	while(t--)
	{
		ll n,m;cin>>n>>m;
		vector<vector<ll>> graph(n);
		f(m)
		{
			ll x,y;cin>>x>>y;x--;y--;
			graph[x].pb(y);
		}
		ll ans=0;
		memset(dp,-1,sizeof(dp));
		f(n)
		{
			ll temp=longest_path(graph,i);
			ans=max(ans,temp);
		}
		cout<<ans<<"\n";
	}
}


Measured memory_bytes: 8576
import java.util.*;

public class Main {
    public static void main(String args[]) {
    Scanner read = new Scanner(System.in);
    int n = read.nextInt();
    int d[] = new int[n];
    d[0] = read.nextInt()-1;
    boolean ban=true;
    for(int i=1; i<n; i++){
        d[i]=read.nextInt();
        if(d[i-1] > d[i]){
            ban=false;
            break;
        }
        if(d[i-1] < d[i])
            --d[i];
    }
    
        if(ban)
           System.out.println("Yes");
        else
           System.out.println("No");
    
    
    
   
    }
}

Measured memory_bytes: 51136