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

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

int main(){
    int x;
    cin>>x;
    int count=1;
    int dig=x;
    while(dig){
        dig+=x;
        dig%=360;
        count++;
    }
    cout<<count<<endl;

    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<functional>

using namespace std;
#define LL long long
#define LLBIG 1999999999999999999
#define INTBIG 1111111111
#define PI pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>

LL N, OI = 0, JO = 0, J[100002] = {}, I[100002] = {}, JOI = 0, ans;
string S;

int main() {
	cin >> N >> S;
	//JO,J
	J[0] = (S[0] == 'J' ? 1 : 0);
	for (int i = 1; i < N; i++) {
		J[i] = J[i - 1];
		if (S[i] == 'J') J[i]++;
		if (S[i] == 'O') JO += J[i];
	}
	//JOI,OI,I
	I[N - 1] = (S[N - 1] == 'I' ? 1 : 0);
	for (int i = N - 2; i >= 0; i--) {
		I[i] = I[i + 1];
		if (S[i] == 'I') I[i]++;
		if (S[i] == 'O') OI += I[i];
		if (S[i] == 'J') JOI += OI;
	}
	
	ans = max(JOI + JO, JOI + OI);//I,Jをつけたとき

	for (int i = 0; i < N - 1; i++) 
		ans = max(ans, JOI + J[i] * I[i + 1]);
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 4876
using System;

namespace question2
{
    class Program
    {
        static void Main(string[] args)
        {

            int N = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            int[] a = new int[N];
            for (int i = 0; i < N; i++)
            {
                a[i] = int.Parse(str[i]);
            }

            int count = 0;
            for (int i = 0; i < N; i++)
            {
                if (a[i] != (i+1)) count++;
            }
            if (count == 0) Console.WriteLine("YES");
            else if (count == 2) Console.WriteLine("YES");
            else Console.WriteLine("NO");

        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<stdio.h>

#define MAX_N 100000
int N;
int a[MAX_N]; //??¶???
int p[MAX_N]; //?????????, a[i] = a[i + 1]??????i???????´?
int p_tail; //p????????????????´?

int main()
{
  scanf("%d", &N);
  p[0] = -1;
  p_tail = 0;
  for (int i = 0; i < N; i++) {
    scanf("%d", &a[i]);
    if(i > 0 && a[i] == a[i - 1]) {
      p[p_tail + 1] = i - 1;
      p_tail++;
    }
  }
  p[p_tail + 1] = N - 1;
  p_tail++;
  //a[i + 3] - a[i]????????§????????§?????????????????¢???
  if(p_tail <= 2) {
    printf("%d\n", N);
  }
  else {
    int ans = 0;
    for(int i = 0; i <= p_tail - 3; i++) {
      if(ans < p[i + 3] - p[i]) {
        ans = p[i + 3] - p[i];
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
  

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

int main(){
  int n; cin >> n;
  bool ok = false;
  for(int i = 1; i < 10; i++){
    for(int j = 1; j < 10; j++){
      if(n == i * j){
        ok = true;
        break;
      }
    }
  }
  if(ok){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

long long X, Y;

int main() {
  scanf("%lld%lld", &X, &Y);
  long long r = Y / X;
  int res = 1;
  while(r >= 2) { r /= 2; ++res; }
  printf("%d\n", res);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <string>
#include <set>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <ctime>
//#include<bits/stdc++.h>
using namespace std;
#define maxn 107
#define maxm 444
#define modn 998244353
#define scan(a) scanf("%d",&a)
#define scanl(a) scanf("%lld",&a)
#define scans(a) scanf("%s",a)
#define scand(a) scanf("%lf",&a)
#define scan2(a,b) scanf("%d%d",&a,&b)
#define scand2(a,b) scanf("%lf%lf",&a,&b)
#define scan3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define mp      make_pair	
#define pb      push_back
#define eb      emplace_back
#define mm(a,b) memset(a,b,sizeof a)
typedef long long ll;
typedef unsigned long long ull;
const ll base = 100000;
const int inf = 0x3f3f3f3f;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef map <char, int> mci;
typedef map <char, char> mcc;
typedef pair <char, int> pci;
typedef unsigned long long ull;

const double eps = 1e-11;
const double PI = 2 * acos(0.0);
const double sqrt2 = sqrt(2);

int main() {
	int w, h;
	queue<pii> q;
	int vis[maxn][maxn];
	char g[maxn][maxn];
	int d[4][2] = { -1,0,1,0,0,-1,0,1 };
	while (cin >> h >> w && w) {
		for (int i = 0; i < h; i++)
			scans(g[i]);
		memset(vis, 0, sizeof vis);
		char now;
		int res = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (vis[i][j])continue;
				now = g[i][j];
				q.push(make_pair(i, j));
				vis[i][j] = 1;
				res++;
				while (!q.empty()) {
					int x = q.front().first, y = q.front().second;
					q.pop();
					int nx, ny;
					for (int i = 0; i < 4; i++) {
						nx = x + d[i][0], ny = y + d[i][1];
						if (nx < h && nx >= 0 && ny < w && ny >= 0 && g[nx][ny] == now && !vis[nx][ny]) {
							q.push(make_pair(nx, ny));
							vis[nx][ny] = 1;
						}
					}
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}


Measured memory_bytes: 3284
# -*- coding: utf-8 -*-
#mitsui e
import sys
import math
import collections
#sys.setrecursionlimit(100000)

n=int(input())

tmp = input().split()
s = list(map(lambda a: int(a), tmp))

a=-1
b=-1
c=-1

ans=1

for i in range(0,n):
	tmp=0
#	print(s[i])
	if(s[i]-1==a):
		tmp+=1
	if(s[i]-1==b):
		tmp+=1
	if(s[i]-1==c):
		tmp+=1
	ans*=tmp
	if(s[i]-1==a):
		a+=1
	elif(s[i]-1==b):
		b+=1
	elif(s[i]-1==c):
		c+=1
print(ans%1000000007)

Measured memory_bytes: 14908
import sys
input = sys.stdin.buffer.readline

n, m, q = map(int, input().split())

class TwoDimSum():
    def __init__(self, h, w):
        self.h = h
        self.w = w
        self.counts = [[0 for _ in range(w+1)] for _ in range(h+1)]
        self.s = [[0 for _ in range(w+1)] for _ in range(h+1)]

    def add_count(self, x, y):
        # 1-indexed
        self.counts[y][x] += 1

    def build(self):
        for i in range(self.h):
            for j in range(self.w):
                self.s[i+1][j+1] = self.s[i][j+1] + self.s[i+1][j] - self.s[i][j] + self.counts[i+1][j+1]

    def solve(self, x1, y1, x2, y2):
        # 1-indexed
        # (x1, y1): left up
        # (x2, y2): right down
        return self.s[x2][y2] - self.s[x1-1][y2] - self.s[x2][y1-1] + self.s[x1-1][y1-1]

counts = TwoDimSum(n, n)
for _ in range(m):
    l, r = map(int, input().split())
    counts.add_count(l, r)
counts.build()

ans = []
for i in range(q):
    x, y = map(int, input().split())
    ans.append(str(counts.solve(x, x, y, y)))
print("\n".join(ans))

Measured memory_bytes: 59484
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto x = readln.chomp.split.to!(int[]);
  auto a = new int[](3);
  a[0] = x[0] * x[1];
  a[1] = x[0] + x[1];
  a[2] = x[0] - x[1];
  writeln(max(a[2],max(a[0], a[1])));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int x,y,z;
  cin>>x>>y>>z;
  cout<<x<<" "<<y<<" "<<3*z-x-y <<" "<<endl;
  cout<<4*z-2*x-y<<" "<<z<<" "<<2*x+y-2*z<<" "<<endl;
  cout<<x+y-z<<" "<<2*z-y<<" "<<2*z-x<<" "<<endl;
  return 0 ;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int n;string s;
    int count  = 0;
    cin>>n>>s;
    REP(i,n-2){
        if(s[i]=='A' and s[i+1]=='B' and s[i+2]=='C') count++;

    }
    cout << count;
}

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

ll H, N;
const int MAX = 1.0e5 + 100;
ll A[MAX];

int main() {
    cin >> H >> N;
    for (int i = 0; i < N; i++) cin >>  A[i];

    ll cnt = 0;
    for (int i = 0; i < N; i++) {
        cnt += A[i];
    }

    if (cnt >= H) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>

using namespace std;

int N,X[1001],P,maxn,f[1001][5001],g[1001];
vector<int> point[1001];

void dfs(int u){
	for(int v:point[u])dfs(v);
	bool c=false;
	memset(f[0],0x3f,sizeof(f[0]));
	f[0][0]=0;
	for(int v:point[u]){
		c=!c;
		memset(f[c],0x3f,sizeof(f[0]));
		for(int j=0;j<=X[u];++j){
			if(j>=X[v])f[c][j]=min(f[c][j],f[!c][j-X[v]]+g[v]);
			if(j>=g[v])f[c][j]=min(f[c][j],f[!c][j-g[v]]+X[v]);
		}
	}
	for(int i=0;i<=X[u];++i)g[u]=min(g[u],f[c][i]);
}

int main(){
	scanf("%d",&N);
	for(int i=2;i<=N;++i)scanf("%d",&P),point[P].push_back(i);
	for(int i=1;i<=N;++i)scanf("%d",X+i);
	memset(g,0x3f,sizeof(g));
	dfs(1);if(g[1]<0x3f3f3f3f)puts("POSSIBLE");else puts("IMPOSSIBLE");
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define dbg(x) cout<<(#x)<<"="<<x<<endl
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, a, b) for(int i=(a); i<=(b); i++)
#define DOWN(i, a, b) for(int i=(a); i>=(b); i--) 

using namespace std;

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

const double eps=1e-8;
const int INF=0x3f3f3f3f;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int N=1e6+10;

int main() {
	int n;
	cin>>n;
	if (n<1200) cout<<"ABC"<<endl;
	else if (n<2800) cout<<"ARC"<<endl;
	else cout<<"AGC"<<endl;
//	cout<<1.0*clock()<<"ms"<<endl;
	return 0;
} 

Measured memory_bytes: 256
N, K = map(int, input().split())
sunuke = [0] * N
for i in range(K):
    di = int(input())
    Ai = map(int, input().split())
    for a in Ai:
        sunuke[a - 1] += 1
answer = 0
for s in sunuke:
    if s == 0:
        answer += 1
print(answer)

Measured memory_bytes: 9116
#include<stdio.h>
struct Card{char suit;int value; };
int main()
{
  struct Card a[101],b[101];
  int n,i,j,k,mini,m,sum=0; 
  char ch;
  scanf("%d%c",&n,&ch);
  for(i=0;i<n;i++){ 
    scanf("%c%d%c",&a[i].suit,&a[i].value,&ch);
  }
  for(i=0;i<n+1;i++){
    b[i]=a[i];
  }
  
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(a[j].value<a[j-1].value){
	m=a[j].value;
	a[j].value=a[j-1].value;
 	a[j-1].value=m;
	ch=a[j].suit;
        a[j].suit=a[j-1].suit;
        a[j-1].suit=ch;
      }
    }
  }  
  for(i=0;i<n-1;i++){
    mini=i; 
    m=b[i].value;
    for(j=i;j<n;j++){
      if(b[j].value<m){
	m=b[j].value;
	mini=j;
      }
    }
    if(m!=b[i].value){
      k=b[i].value;
      b[i].value=b[mini].value;
      b[mini].value=k;
      ch=b[i].suit;
      b[i].suit=b[mini].suit;
      b[mini].suit=ch;
    }
  }  for(i=0;i<n;i++){
    if(a[i].suit==b[i].suit && a[i].value==b[i].value){
    sum++;
    }
  }
  for(i=0;i<n-1;i++){
    printf("%c%d ",a[i].suit,a[i].value);
  }
  printf("%c%d",a[i].suit,a[i].value);
  printf("\nStable\n");

  for(i=0;i<n-1;i++){
    printf("%c%d ",b[i].suit,b[i].value);
  }
  printf("%c%d",b[i].suit,b[i].value);
  if(sum==n)printf("\nStable\n");
  else printf("\nNot stable\n");

  return 0;
}



Measured memory_bytes: 2112
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a[4]={},n,b=0;
    
    for(int i=0;i<6;i++){
        cin>>n;
        a[n-1]++;
    }
    
    for(int i=0;i<6;i++){
        if(a[i]==3) b++;
    }
    if(b>=1) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    
    return 0;
}


Measured memory_bytes: 256
import sys
#import numpy as np

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, A, B, C, D = i2nn()
    S = i2s()

    s1 = S[A:C-1]
    s2 = S[B:D-1]
    if s1.find('##') >= 0 or s2.find('##') >= 0:
        print('No')
        return

    if C < D:
        print('Yes')
        return
    else:
        s3 = S[B-2:D+1]
        if s3.find('...') >= 0:
            print('Yes')
            return
        print('No')
        return

main()


Measured memory_bytes: 41072
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
using ll = long long;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define rep(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int main(){
    int n,k,r,s,p;
    cin>>n>>k>>r>>s>>p;
    string t;
    cin>>t;
    map<char,int>mp;
    mp['r']=p;
    mp['s']=r;
    mp['p']=s;
    int ans =0;
    rep(i,n){
        if(i<k)ans+=mp[t[i]];
        else if(t[i]==t[i-k])t[i]='a';
        else ans+=mp[t[i]];
        //cout<<ans<<endl;   
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define acc(v) accumulate(v.begin(), v.end(), 0)

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;

int B[1000100];
int main()
{
    ll n, k;
    cin >> n >> k;
    vector<int> A(n);
    rep(i, n){
        cin >> A[i];
        A[i]--;
    }
    ll count = 0;
    int now = 0;
    int roop = 0;
    rep(i,n){
        B[i] = -1;
    }
    while (true)
    {
        if(B[now]!=-1){
            roop = now;
            break;
        }
        B[now] = count;
        count++;
        now = A[now];
        if(count==k){
            cout << now+1 << endl;
            return 0;
        }
    }
    int roop_count = count - B[roop];
    k -= count - roop_count;
    ll d = k % roop_count;
    while (d > 0)
    {
        now = A[now];
        d--;
    }
    cout << now+1 << endl;
    return 0;
}


Measured memory_bytes: 4840
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n;
int p;
int a[55];
ll even = 0;
ll odd = 0;
ll c[55][55];

//ll c(ll n, ll m)
//{
//	ll res = 1;
//	for (ll i = n - m + 1;i <= n;i++) {
//		res *= i;
//	}
//	for (ll i = 1;i <= m;i++) {
//		res /= i;
//	}
//	return res;
//}

ll pow2(ll n)
{
	ll res = 1;
	while (n) {
		res *= 2;
		n--;
	}
	return res;
}

int main()
{
	cin >> n >> p;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		if (a[i] % 2) {
			odd++;
		}
		else {
			even++;
		}
	}

	ll ans = 0;

	if (p == 1 && odd == 0) {
		cout << ans << endl;
		return 0;
	}

	c[0][0] = 1;
	for (int i = 1;i < 55;i++)
		for (int j = 0;j <= i;j++) {
			if (i == 0) {
				c[i][j] = 0;
				continue;
			}

			if (j == 0) {
				c[i][j] = 1;
			}
			else {
				c[i][j] = c[i -1][j] + c[i - 1][j - 1];
			}
		}

//	cout << c[10][2] << endl;


	if (p == 0) {
		ll temp = pow2(even);

		for (ll i = 0;i <= odd;i += 2) {
			ans += (temp * c[odd][i]);
		}
	}
	else {
		ll temp = pow2(even);

		for (ll i = 1;i <= odd;i += 2) {
			ans += (temp * c[odd][i]);
		}
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main()
{
  string a;
  cin >> a;
  if (a >= "A" && a<= "Z") {
    cout << "A" << endl;
  } else {
    cout << "a" << endl;
  }
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n; cin>>n;
	vector<int> a(n + 1), b(n + 1);
	for(int i = 1; i <= n; i++){
		cin>>a[i];
	}
	for(int i = n; i >= 1; i--){
		int cnt = 0;
		for(int j = i*2; j <= n; j += i){
			cnt ^= b[j];
		}
		b[i] = cnt^a[i];
	}
	int m = accumulate(b.begin(), b.end(), 0);
	cout<<m<<'\n';
	for(int i = 1; i <= n; i++){
		if(b[i])cout<<i<<" ";
	}

	return 0;
}

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

int main() {
  int N, n_1, n_2, n_3, n_4;
  cin >> N;
  n_1 = N / 1000;
  n_2 = N / 100 % 10;
  n_3 = N / 10 % 100 % 10;
  n_4 = N % 1000 % 100 % 10;
  
  if ((n_1 == n_2 && n_2 == n_3) || (n_2 == n_3 && n_3 == n_4)) {
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

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

	ll n, a, b, c, d;cin >> n >> a >> b >> c >> d;
	a--;b--;c--;d--;
	string str;cin >> str;

	bool ac = true;
	bool bd = true;
	bool bd3 = false;
	for(int i = min(a, c);i < max(a, c);i++){
		if(str[i] == '#' && str[i+1] == '#')ac = false;
	}
	for(int i = min(b, d);i <= max(b, d);i++){
		if(i < d && str[i] == '#' && str[i+1] == '#')bd = false;
		if(i < n - 1 && str[i-1] == '.' && str[i] == '.' && str[i+1] == '.')bd3 = true;
	}

	if(d < c){
		if(!bd3)ac = false;
	}

	if(ac && bd){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 592
#include <stdio.h>

int main(int argc, char const *argv[]) {

    int a,b;

    scanf("%d%d",&a,&b);

    if(a < b){
        printf("a < b\n");
    }else if(a > b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }

    return 0;
}



Measured memory_bytes: 2040
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int min(int a,int b)
{
    if(a<b)
        return a;
    else
        return b;
}
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int b[n];
    b[0]=0;
    b[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
        b[i]=min(b[i-1]+abs(a[i]-a[i-1]),b[i-2]+abs(a[i]-a[i-2]));
    }
    //for(int i=0;i<n;i++)
    cout<<b[n-1];
}


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

const int MAX_N = 20, MAX_Q = 200;

int n, q, A[MAX_N], m[MAX_Q];

bool solve(int i, int m) {
  if (m == 0) return true;
  if (i >= n) return false;
  return (solve(i + 1, m) || solve(i + 1, m - A[i]));
}

int main() {
  cin >> n;
  REP(i, n) cin >> A[i];
  cin >> q;
  REP(i, q) cin >> m[i];

  REP(i, q) {
    if (solve(0, m[i])) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
  return 0;
}

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

signed main(){
    int n; cin >> n;
    vector<int> vec(n);
    for (int i = 2; i <= n; i++) cin >> vec[i-1];
    vector<int> buka(n);
    for (int i = 2; i <= n; i++){
        buka[vec[i-1]-1]++;
    }
    for (int i = 0; i < n; i++){
        cout << buka[i] << endl;
    }
    return 0;
}


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

using namespace std;
using ll=long long;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;
int dp[3100][3100] = {0};

int main() {

string s,t,ans="";
cin >> s >> t;
int ss,st;
ss=(int)s.size();st=(int)t.size();


for (int i = 0; i < ss; ++i)
{
   for (int j = 0; j < st; ++j)
   {
       if(s[i]==t[j]) chmax(dp[i+1][j+1],dp[i][j]+1);
       chmax(dp[i+1][j+1],dp[i+1][j]);
       chmax(dp[i+1][j+1],dp[i][j+1]);
   }
}
int x=st,y=ss;
while (x>0&&y>0)
{   
    if(dp[y][x]==dp[y][x-1]) x--;
    
    else if(dp[y][x]==dp[y-1][x]) y--;
       
    else{ ans = t[x-1] + ans; x--;y--;}
    
}
cout << ans;
return 0;
}




Measured memory_bytes: 37120
#include<bits/stdc++.h>
#include<map>
#include<iostream>

using namespace std;

int main(){
    int K;
    int A,B;
    cin >> K;
    cin >> A >> B;
    bool x = false;
    for(int i = A; i <= B; i++){
        if(i % K == 0){
            x = true;
            break;
        }
    }
    cout << (x ? "OK" : "NG") << endl;
    
}

Measured memory_bytes: 3676
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n;
main()
{
	while(cin>>n,n)
	{
		int sumr=0,sumw=0;
		vector<pair<int,int> >a;
		for(int i=0;i<n;i++)
		{
			int x,y;cin>>x>>y;
			a.push_back(make_pair(x,y));
			sumr+=x,sumw+=y;
		}
		sort(a.begin(),a.end());
		if(sumr>=a[n-1].first*2)cout<<sumr+sumw<<endl;
		else
		{
			bool dp[1001]={};
			dp[0]=1;
			int ret=0;
			for(int i=0;i<n-1;i++)
			{
				for(int j=a[n-1].first*2-sumr;j>=a[i].second;j--)
				{
					dp[j]|=dp[j-a[i].second];
					if(dp[j])ret=max(ret,j);
				}
			}
			cout<<sumr+sumw+a[n-1].first*2-sumr-ret<<endl;
		}
	}
}



Measured memory_bytes: 3108
using System;
using System.Text;

namespace ALDS1_8_A {
    class Node {
        public int Key { get; set; }
        public Node Parent { get; set; }
        public Node Left { get; set; }
        public Node Right { get; set; }

        public Node(int key = default(int)) {
            Key = key;
        }
    }

    class Problem {
        private Node _root;
        private StringBuilder _sb;

        public void Run() {
            _sb = new StringBuilder();
            int n = int.Parse(Console.ReadLine());
            SetRoot();
            for (int i = 1; i < n; i++) {
                string[] input = Console.ReadLine().Split(' ');

                switch (input[0]) {
                    case "insert":
                        Insert(int.Parse(input[1]));
                        break;
                    case "print":
                        Inorder(_root);
                        _sb.AppendLine();
                        Preorder(_root);
                        _sb.AppendLine();
                        break;
                }
            }
            Console.Write(_sb);
        }

        private void SetRoot() {
            string[] input = Console.ReadLine().Split(' ');
            _root = new Node(int.Parse(input[1]));
        }

        private void Insert(int key) {
            Node x = _root;
            Node y = null;
            Node z = new Node(key);

            while (x != null) {
                y = x;
                x = z.Key < x.Key ? x.Left : x.Right;
            }

            z.Parent = y;

            if (z.Key < y.Key)
                y.Left = z;
            else
                y.Right = z;
        }

        private void Inorder(Node node) {
            if (node == null)
                return;
            Inorder(node.Left);
            _sb.Append(" " + node.Key);
            Inorder(node.Right);
        }

        private void Preorder(Node node) {
            if (node == null)
                return;
            _sb.Append(" " + node.Key);
            Preorder(node.Left);
            Preorder(node.Right);
        }
    }

    class Program {
        static void Main(string[] args) {
            Problem p = new Problem();
            p.Run();
        }
    }
}

Measured memory_bytes: 91824
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll H, W, N;
    cin >> H >> W >> N;
    vec obstacles(H, inf);
    Rep (i, N) {
        ll X, Y;
        cin >> X >> Y;
        X--; Y--;
        chmin(obstacles[X], Y);
   }

//    Rep (i, H) {
//        cout << obstacles[i] << " \n"[i==H-1];
//    }

    ll now = 0;
    Rep (i, H-1) {
        // cout << now << " " << obstacles[i] << "\n";
        if (obstacles[i+1] <= now) {
            cout << i+1 << "\n";
            return 0;
        }
        now++;
        if (obstacles[i+1] == now) now--;
    }

    cout << H << "\n";
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <stack>
#include <queue>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

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

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

  std::sort(l.begin(), l.end(), std::greater<int>());

  int res = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n - 1; ++j) {

      // 二分探索
      // l[i] < l[j] + l[k] であれば OK

      // すでに NG
      if (l[i] >= l[j] + l[j + 1])
        continue;

      // すべて OK
      if (l[i] < l[j] + l[n - 1]) {
        res += n - j - 1;
        continue;
      }

      int ok = j + 1;
      int ng = n - 1;
      while (std::abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (l[i] < l[j] + l[mid])
          ok = mid;
        else
          ng = mid;
      }

      res += ok - j;

      // std::cout << res << std::endl;
    }
  }

  std::cout << res << std::endl;

  return 0;
}


Measured memory_bytes: 256
n,d = map(int, input().split())

ab = [list(map(int, input().split())) for _ in range(n)]

dd = d*d

res = 0
for i in range(n):
    r = ab[i][0]**2+ab[i][1]**2
    if r <= dd:
        res +=1
        
print(res)

Measured memory_bytes: 45456
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a + b >= c ? "Yes" : "No") << endl;
}


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

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}

int main(){
	int x, a, b;
	string s;
	while(scanf("%d", &x), x){
		if(x % 1111 == 0){
			puts("NA");
		}
		else{
			int ans;
			for(ans = 0; x != 6174; ++ans){
				convert(x, s);
				s.resize(4, '0');
				sort(s.begin(), s.end());
				convert(s, a);
				reverse(s.begin(), s.end());
				convert(s, b);
				x = b - a;
			}
			printf("%d\n", ans);
		}
	}
}

Measured memory_bytes: 1292
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,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(int i=0;i<x;i++)
#define repn(i,x) for(int 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(){
  string s;cin>>s;
  ll N = s.size();
  vector<ll> a(N),b(N);
  ll i,j,k;

  ll tmp1 = 1;
  rep(i,N-1){
    if(s[i] == 'R' and s[i+1] == 'R') tmp1++;
    else if(s[i] == 'R' and s[i+1] == 'L'){
      a[i] = tmp1++;
      tmp1 = 1;
    }
    else tmp1 = 1;
  }

  ll tmp2 = 1;
  for(i=N-1;i>=1;i--){
    if(s[i] == 'L' and s[i-1] == 'L') tmp2++;
    else if(s[i] == 'L' and s[i-1] == 'R'){
      b[i] = tmp2;
      tmp2 = 1;
    }
    else tmp2 = 1;
  }


  vector<ll> ans(N);
  rep(i,N){
    if(a[i] == 0 and b[i]==0) ans[i] = 0;
    else if(a[i]==1 and b[i+1]==1) ans[i] = 1;
    else{
      ans[i] += a[i]/2;
      ans[i+1] += a[i]/2;
      if(a[i]%=2) ans[i]++;

      ans[i-1] += b[i]/2;
      ans[i] += b[i]/2;
      if(b[i]%=2) ans[i]++;
    }
  }

  rep(i,N){
    cout<<ans[i]<<" ";
  }
  cout<<endl;

}


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

typedef long long ll;
const int N = 1e6;

ll n, ans, a[N], cnt[N];
string s;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> s;
	n = s.length();
	for (int i = n - 1; ~i; i--)
		if (s[i] == '>')
			cnt[i] = cnt[i + 1] + 1;
	ans += (a[0] = cnt[0]);
	for (int i = 0; i < n; i++) {
		if (s[i] == '<')
			a[i + 1] = max(a[i] + 1, cnt[i + 1]);
		else
			a[i + 1] = cnt[i + 1];
		ans += a[i + 1];
	}
	cout << ans;
}


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

int main() {
    vector<string> A = {"Sunny", "Cloudy", "Rainy"};
    string S;
    cin >> S;
    if(S == A[0]) cout << A[1] << endl;
    else if(S == A[1]) cout << A[2] << endl;
    else cout << A[0] << endl;
}

Measured memory_bytes: 256
x = int(input())
ans = ''
if 400 <= x < 600:
    ans = '8'
elif x < 800:
    ans = '7'
elif x < 1000:
    ans = '6'
elif x < 1200:
    ans = '5'
elif x < 1400:
    ans = '4'
elif x < 1600:
    ans = '3'
elif x < 1800:
    ans = '2'
elif x < 2000:
    ans = '1'
print(ans)


Measured memory_bytes: 8984
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#define pr(x) cerr<<#x<<"="<<x<<endl
#define pri(x,lo) {cerr<<#x<<"={";for (int ol=0;ol<=lo;ol++)cerr<<x[ol]<<",";cerr<<"}"<<endl;}
#define N 1000
ll a,b;
int main()
{
	cin>>a>>b;
	ll ans=1;
	ll i=a;
	while (i*2ll<=b&&i*2ll>=a) i=i*2ll,ans++;
	cout<<ans;
}

Measured memory_bytes: 256
h, w, n = gets.chomp!.split(" ").map!(&:to_i)
s_r, s_c = gets.chomp!.split(" ").map!(&:to_i)
s_r -= 1
s_c -= 1
s = gets.chomp!.chars
t = gets.chomp!.chars

memo = {
  'L' => s_c,
  'R' => s_c,
  'U' => s_r,
  'D' => s_r,
}

inverse = {
  'L' => 'R',
  'R' => 'L',
  'U' => 'D',
  'D' => 'U',
}

is_no = false

n.times do |i|
  case s[i]
  when 'R'
    memo[s[i]] += 1
    if memo[s[i]] >= w
      is_no = true
      break
    end
  when 'D'
    memo[s[i]] += 1
    if memo[s[i]] >= h
      is_no = true
      break
    end
  when 'L', 'U'
    memo[s[i]] -= 1
    if memo[s[i]] < 0
      is_no = true
      break
    end
  end

  case t[i]
  when 'L', 'U'
    memo[inverse[t[i]]] = memo[inverse[t[i]]] > 0 ? memo[inverse[t[i]]] - 1 : 0
  when 'R'
    memo[inverse[t[i]]] = memo[inverse[t[i]]] + 1 < w ? memo[inverse[t[i]]] + 1 : memo[inverse[t[i]]]
  when 'D'
    memo[inverse[t[i]]] = memo[inverse[t[i]]] + 1 < h ? memo[inverse[t[i]]] + 1 : memo[inverse[t[i]]]
  end
end

puts is_no ? "NO" : "YES"


Measured memory_bytes: 22396
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int n,x,y;
vvi g[2];
vi d[2],p,a;

void In(int I){
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		g[I][u].push_back(v);
		g[I][v].push_back(u);
	}
}

void dfs(int v,int v_,int D,int I){
	d[I][v]=D;
	if(I==1) p[v]=v_;
	for(auto u:g[I][v]) if(u!=v_) dfs(u,v,D+1,I);
}

int DFS(int v,int v_){
	if(d[0][v]>=d[1][v]) return 0;
	if(a[v]) return inf;
	int t=0;
	for(auto u:g[0][v]) if(u!=v_) t=max(t,DFS(u,v));
	return max(t,2*d[1][v]);
}

int main(){
	cin>>n>>x>>y;
	x--;y--;
	g[0]=g[1]=vvi(n);
	d[0]=d[1]=a=vi(n);
	p=vi(n+1);
	p[n]=n;
	In(0);In(1);
	dfs(x,n,0,0);dfs(y,n,0,1);
	for(int v=0;v<n;v++) for(auto u:g[0][v]){
		if(p[u]!=v&&p[v]!=u&&p[p[v]]!=u&&p[p[u]]!=v&&p[u]!=p[v]) a[u]=a[v]=1;
	}
	int res=DFS(x,n);
	cout<<(res==inf?-1:res)<<endl;
}

Measured memory_bytes: 36604
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
//typedef pair<long long,long long> P;
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int k,t;
  cin>>k>>t;
  int a[t];
  int ma=0;
  REP(i,t){
    cin>>a[i];
    ma = max(ma,a[i]);
  }
  int ans;
  ans = max((ma-1)-(k-ma),0);
  cout<<ans<<endl;
  return 0; 
}


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

int main() {
	int a,b;
	char s[15];
	int counter = 0;
	
	scanf ("%d %d", &a, &b);
	scanf ("%s", &s);
	
	for (int i=0; s[i] != '\0'; i++){
        if (s[a] != '-') {
            printf ("No\n");
            return 0;
        }
        if (s[i] >= '0' && s[i] <= '9'){
            counter++;
        }
    }
    if (counter == a+b) {
        printf ("Yes\n");
    }
    else{
        printf ("No\n");
    }
    
    
	return 0;
}

Measured memory_bytes: 1628
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define TRACE(x) cerr << #x << " = " << x << endl
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define _ << " " <<

typedef long long ll;
typedef pair<int, int> P;
#define X first
#define Y second

const int MAX = 1<<19, LOG = 20, A = 26;

char s[MAX];
int skok[MAX][LOG];
int dp[MAX][A+2];
int n;

int main()
{
  scanf("%s", s);
  n = (int) strlen(s);

  REP(i, MAX) REP(j, LOG) skok[i][j] = n + 2;

  memset(dp, -1, sizeof dp);
  dp[n][A] = n;

  for (int i=n-1; i>=0; i--) {
    int c = s[i] - 'a';
    dp[i][c] = i+1;
    for (; c<A; c++) {
      dp[i][c+1] = dp[dp[i][c]][c];
      if (dp[i][c+1] == -1) break;
    }
    
    if (dp[i][A] != -1) {
      c = s[i] - 'a';
      REP(j, c)
	dp[i][j] = dp[dp[i][A]][j];
    }

    skok[i][0] = (dp[i][A] == -1 ? (n + 2) : dp[i][A]);
  }

  FOR(i, 1, LOG)
    REP(j, MAX)
    skok[j][i] = skok[skok[j][i-1]][i-1];

  int q;
  scanf("%d", &q);
  
  for (; q--; ) {
    int l, r;
    scanf("%d%d", &l, &r); l--;
    
    for (int i=LOG-1; i>=0; i--)
      if (skok[l][i] <= r)
	l = skok[l][i];
    
    printf("%s\n", l == r ? "Yes" : "No");
  }

  return 0;
}


Measured memory_bytes: 99456
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,a=0;
	cin>>n;
	int b[n][2];
	for(int i=0;i<n;i++){ 
		for(int j=0;j<2;j++) cin>>b[i][j];
    }
	for(int k=0;k<n;k++) a=a+(b[k][1]-b[k][0]+1);
	cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

constexpr ll MOD = 1000000007;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

int main() {
  int n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  // s - 1,
  ll g = gcd(n, m);
  ll l = n / g * m;

  // s の a文字目 == tのb文字目
  // それ以上の値はあるか？

  bool ok = true;
  rep(i, 0, g) if (s[n / g * i] != t[m / g * i]) ok = false;

  if (ok)
    cout << l;
  else
    cout << -1;
  cout << endl;

#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[10005];

class Prime {
public:
    Prime(ll n) {
        mPrimeTbl.clear();
        vector<bool> u(n, false);
        for (ll i = 2; i <= n; ++i) {
            if (u[i])
                continue;
            mPrimeTbl.push_back(i);
            for (ll p = i; p <= n; p += i)
                u[p] = true;
        }
    }

    ~Prime() {}

    ll num() {
        return static_cast<ll>(mPrimeTbl.size());
    }

    ll get(ll index) {
        return mPrimeTbl[index];
    }

private:
    vector<ll> mPrimeTbl;
};

ll modpow(ll n, ll p) {
    ll ret = 1;
    ll t = n;
    for (ll i = 1; i <= p; i <<= 1) {

        if (p & i)
            ret = (t * ret) % MOD;
        t = (t * t) % MOD;
    }
    return ret;
}

ll S[1000005];

int main() {
    ll N;
    cin >> N;
    ll max = 0;
    REP(i, N) {
        cin >> A[i];
        max = std::max(A[i], max);
    }
    memset(S, 0, sizeof(S));
    Prime prime(1005);
    map<ll, ll> map;

    REP(a, N) {
        ll n = A[a];

        REP(i, prime.num()) {
            ll p = prime.get(i);
            ll m = 0;
            while (n % p == 0) {
                n /= p;
                m++;
            }
            S[p] = std::max(S[p], m);
            if (n == 1)
                break;
        }

        if (n > 1) {
            S[n] = 1;
        }
    }

    ll pw = 1;
    REP(i, max + 1) {
        pw = (pw * modpow(i, S[i])) % MOD;
    }
    ll ans = 0;
    REP(i, N) {
        ll n = A[i];
        ll t = pw;
        REP(i, prime.num()) {
            ll p = prime.get(i);
            ll m = 0;
            while (n % p == 0) {
                n /= p;
                m++;
            }
            t = t * modpow(p, MOD - 1 - m) % MOD;
            if (n == 1)
                break;
        }

        if (n > 1) {
            t = t * modpow(n, MOD - 2) % MOD;
        }
        ans += t;
    }
    cout << ans % MOD << endl;
    return 0;
}

Measured memory_bytes: 8192
// God put a smile upon your face <3

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

#define slld(longvalue) scanf("%d", &longvalue)

#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 958585860497

#define base 2001487

using namespace std;


vector < int > g[100005];
int hill[100005];

int main()
{
    int i, j, k, l, m, n, o, r, q;
    int testcase;
    int input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    while(cin >> n >> m)
    {
		for(i = 1; i <= n; i++) g[i].clear();

		for(i = 1; i <= n; i++) slld(hill[i]);

		for(i = 1; i <= m; i++)
		{
			int u, v;

			slld(u);
			slld(v);

			g[u].pb(v);
			g[v].pb(u);
		}

		ans = 0;

		for(i = 1; i <= n; i++)
		{
			bool on = 1;

			for(auto it: g[i])
			{
				if(hill[it] >= hill[i])
				{
					on = 0;
					break;
				}
			}

			if(on) ans++;
		}

		printf("%d\n", ans);
    }

}





Measured memory_bytes: 9284
def max_profit(A, n):
    minv = A[0]
    for j in range(1, n):
        if j == 1:
            maxv = A[j] - A[j-1]
        if maxv < A[j] - minv:
            maxv = A[j] - minv
        if minv > A[j]:
            minv = A[j]
    print(maxv)

n=int(input())
A=[int(input()) for i in range(n)]

max_profit(A, n)


Measured memory_bytes: 13600
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }
        static void MainStream()
        {
            Scan sc = new Scan();
            write wr = new write();

            int[] nx = sc.intarr;
            int n = nx[0];
            int x = nx[1];

            int[] ls = sc.intarr;

            int grid = 0;
            int count = 1;

            for(int i=0; i<n; i++)
            {
                grid += ls[i];
                if(grid > x)
                {
                    wr.wri(count);
                    return;
                }
                else
                {
                    count++;
                }
            }
            wr.wri(count);
        }


    }

    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


    }



    class write
    {
        public void wri<Type>(Type x)
        {
            Console.WriteLine(x);
        }
    }

    class Method
    {
        static public int max(params int[] nums)
        {

            int maxx = nums[0];
            for (int i = 1; i < nums.Length; i++)
            {
                maxx = Math.Max(maxx, nums[i]);
            }
            return maxx;
        }
    }
}


Measured memory_bytes: 13268
def dfs(s):
    for t in G[s]:
        if not used[t]:
            used[t] = 1
            dfs(t)
    res.append(s)
def rdfs(s, l):
    for t in RG[s]:
        if label[t] is None:
            label[t] = l
            rdfs(t, l)

while 1:
    n = int(input())
    if n == 0:
        break
    G = [[] for i in range(n)]
    RG = [[] for i in range(n)]
    P = []
    for i in range(n):
        p, m, *A = input().split()
        P.append(float(p))
        for t in map(int, A):
            G[i].append(t-1)
            RG[t-1].append(i)
    used = [0]*n
    res = []
    for i in range(n):
        if not used[i]:
            used[i] = 1
            dfs(i)
    label = [None]*n; k = 0
    for i in reversed(res):
        if label[i] is None:
            label[i] = k
            rdfs(i, k)
            k += 1
    GP = [1.]*k; GF = [0]*k
    for s in range(n):
        l = label[s]
        GP[l] *= P[s]
        for t in G[s]:
            if label[s] != label[t]:
                GF[label[t]] += 1
    ans = 1.
    for i in range(k):
        if GF[i] == 0:
            ans *= 1.-GP[i]
    print("%.9f" % (ans))

Measured memory_bytes: 7952
n,x = gets.chomp.split(' ').map(&:to_i)
arr = gets.chomp.split(' ').map(&:to_i).sort
ans = 0
arr.each do |num|
  x -= num
  if x < 0
    break
  end
  ans += 1
end
if x > 0
  ans -= 1
end
puts ans


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

int main() {
string S;
  cin >> S ;
int a=S.size();  
int  count=0;
  for (int i=0;i<a/2;i++){
  if (S.at(i)!=S.at(a-1-i)) count ++;
  }  
  cout << count<< endl;  
}


Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
value = 1000
current = 0
stocks = 0
for i in range(N-1):
    if A[i] < A[i+1] :
        h = value//A[i]
        stocks+=h
        value = value - h*A[i]
    if A[i]==max(A[i:]) :
        value = value + stocks*A[i]
        stocks = 0
    elif A[i] > A[i+1]:
        value = value + stocks*A[i]
        stocks = 0
value = value + stocks*A[N-1]
print(value)
        

Measured memory_bytes: 9052
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>

using namespace std;


int main(void) {
	int a,b;
	cin >> a >> b;
	
	int diff = b - a - 1;

	int base = (diff * diff - diff) / 2 + diff;

	cout << base - a;
}

Measured memory_bytes: 256