akhauriyash/Code-Regression huggingface dataset:
h,w,c,max;
int *_M;
int D(x,y,c,n){
	int r=1;
	_M[x+(w+2)*y]=n;
	if(_M[x-1+(w+2)*y]==c)r+=D(x-1,y,c,n);
	if(_M[x+1+(w+2)*y]==c)r+=D(x+1,y,c,n);
	if(_M[x+(w+2)*(y-1)]==c)r+=D(x,y-1,c,n);
	if(_M[x+(w+2)*(y+1)]==c)r+=D(x,y+1,c,n);
	return r;
}
E(int d,int *M){if(d<4||M[1+w+2]!=c){
	int *m=malloc(4*(w+2)*(h+2));
	if(d==4){
		memcpy(_M=m,M,4*(w+2)*(h+2));
		D(1,1,m[1+w+2],c);
		int k=D(1,1,m[1+w+2],-1,m);
		if(max<k)max=k;
	}else{
		int i=1;
		for(;i<7;i++){
			if(M[1+w+2]==i)continue;
			memcpy(_M=m,M,4*(w+2)*(h+2));
			D(1,1,m[1+w+2],i,m);
			E(d+1,m);
		}
	}
	free(m);
}}
a[100];
main(i,j){for(;scanf("%d%d%d",&h,&w,&c),c;printf("%d\n",max)){
	memset(a,0,4*(w+2)*(h+2));
	for(j=1;j<h+1;j++)for(i=1;i<w+1;i++)scanf("%d",a+i+(w+2)*j);
	E(max=0,a);
}}

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

double third_root(double q) {
	double x = q/2.0;
	while (fabs(x*x*x - q) >= 0.00001*q) {
		x = x - (x*x*x - q)/(3.0*x*x);
	}
	return x;
}

int main() {
	int q;
	while (~scanf("%d",&q) && ~q) {
		printf("%lf\n",third_root((double)q));
	}
	return 0;
}

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

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

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

  int a, b, c, d;
  cin >> a >> b >> c >> d;

  cout << min(a, b) + min(c, d) << endl;
  return 0;
}


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

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

#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__) 
void DBG() { cerr << "]\n";}
template<typename T, typename ...Args> void DBG(T first, Args... args){
cerr << first; if(sizeof...(args))cerr<<", "; DBG(args...); }

#define int ll
#define pb(x) push_back(x)
#define INF (int)1e17
#define PI 3.14159265358979323846
 
int del_x[4] = {-1, 1, 0, 0};
int del_y[4] = {0, 0, 1, -1};
int XX[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int YY[8] = {-1, 0, 1, 1, 1, 0, -1, -1};


void solve(){
	int n,k; cin >> n >> k;
	int p[n], c[n];
	For(i,n)cin >> p[i];
	For(i,n)cin >> c[i];
	vector<int> path;
	int ans = -INF;
	For(i,n){
		int self = p[i];
		int t = self;
		while(true){
			path.pb(c[self-1]);
			if(t==p[self-1])break;
			self = p[self-1];
		}
		int curr_sum=0;
		
		int sz = path.size();
		int r=k%sz, d=k/sz;
		for(int ele : path){
			curr_sum += ele;
		}
		if(curr_sum<0){
			int s=0, mx = -INF;
			for(int j=0;j<sz;j++){
				s+=path[j];
				mx=max(mx,s);
			}
			ans = max(ans,mx);
			
		}
		else{
			if(r!=0){
				int new_sum=curr_sum*d;
				int s=0, mx = -INF;
				for(int j=0;j<r;j++){
					s+=path[j];
					mx=max(mx,s);
				}
				ans = max(ans,new_sum+mx);
			}
			else{
				int new_sum=curr_sum*(d-1);
				int s=0, mx = -INF;
				for(int j=0;j<sz;j++){
					s+=path[j];
					mx=max(mx,s);
				}
				ans = max(ans,new_sum+mx);
			}	
		}
		path.clear();
	}
	cout << ans <<"\n";
}

int32_t main(){ 
	ios_base:: sync_with_stdio(false); 
	cin.tie(0); 
	int t=1;
	//cin >> t;
	for(int tt=1;tt<=t;tt++){
		//cout << "Case #"<<tt<<": ";
		solve();
	}
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
int solve(vector<int> vec, int p1, int p2,int curr){
	
}
int main(){
	int n;
	cin>>n;
	long long arr[n];
	int input;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		
	}
	long long  dp[n][n];
	for(int i=n-1;i>=0;i--){
		for(int j=i;j<n;j++){
			if(i==j){
				dp[i][j]=arr[i];
			}
			else{
				dp[i][j]=max(arr[i]-dp[i+1][j],arr[j]-dp[i][j-1]);
			}
		}
	}
	cout<<dp[0][n-1];
}

Measured memory_bytes: 49724
length = int (input())
line = input().split()
min = int(line[0]);max = int(line[0]);sum = int(line[0]);
for n in range(1,length):
    if int(line[n]) < min:
        min = int(line[n])
    if int(line[n]) > max:
        max = int(line[n])
    sum += int(line[n])
print("{} {} {}".format(min,max,sum))

Measured memory_bytes: 8296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s;
	cin>>s;
	for(ll i=0;i<s.size();i++){
		cout << 'x';
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<string>
using namespace std;
string s;
int c=0;
int main(void){
	cin>>s;
	if(s[0]!='A'){cout<<"WA";return 0;}
	for(int i=1;i<s.size();i++){
		if(s[i]>='a'&&s[i]<='z')continue;
		if(s[i]!='C'||i==1||i==s.size()-1){cout<<"WA";return 0;}
		c++;
	}
	if(c!=1){cout<<"WA";return 0;}
	cout<<"AC";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define bye ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    bye;
    long long n,p=0;
    cin>>n;
    for(long long i=1;i<=n;i++)
    {
        if(i%3==0 || i%5==0)
            p+=i;
    }
    cout<<(n*(n+1)/2)-p;
    return 0;
}


Measured memory_bytes: 3648
#define _CRT_SECURE_NO_DEPRECATE
#include<string>
#include<iostream>
#include<stdio.h>
#include<stack>
using namespace std;


int main()
{
    stack<char>sta;
    char cha;
    while(cin>>cha)
    {
        if (sta.empty())sta.push(cha);
        else
        {
            if (cha == 'S')sta.push(cha);
            else
            {
                if (sta.top() == 'S')sta.pop();
                else sta.push(cha);
            }
        }
    }
    long long number = 0;
    while (!sta.empty())
    {
        number++;
        sta.pop();
    }
    printf("%lld", number);
}



Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

int main()
{
    int a,b;
    cin>>a>>b;
    int ans=1;
    int mous=a;
    if(b==1)
    {
        cout<<0<<endl;
        return 0;
    }
    while(mous<b)
    {
        mous-=1;
        mous+=a;
        ans++;
    }
    cout<<ans;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
using ll = long long;
using namespace std;
int arr[100010];
int odd = 0, even = 0;
int main(void)
{
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i)
    {
        cin >> arr[i];
        if (arr[i] % 2 == 0)
            even++;
        else
            odd++;
    }

    if (even == N)
        cout << "second" << endl;
    else
        cout << "first" << endl;
    return 0;
}

Measured memory_bytes: 640
//============================================================================
// Author       : Sun YaoFeng
//============================================================================

//#pragma 	comment(linker, "/STACK:100240000,100240000")
//#include	<cstdio>
//#include	<cstdlib>
//#include	<cstring>
//#include	<algorithm>

#include	<bits/stdc++.h>

using	namespace	std;

#define DB		double
#define	lf		else if
#define I64		long long
#define	Rd()	(rand()<<15|rand())
#define For(i,a,b)	for(int i=a,lim=b;i<=lim;i++)
#define Rep(i,a,b)	for(int i=a,lim=b;i>=lim;i--)

#define	fi	first
#define se	second
#define MK	make_pair
#define PA	pair<int, int>

//#define	min(a,b)	((a)<(b)?(a):(b))
//#define	max(a,b)	((a)<(b)?(b):(a))

#define	CH	(ch=getchar())
int		IN()	{
		int x= 0, f= 0, ch;
		for	(; CH < '0' || ch > '9';)	f= (ch == '-');
		for	(; ch >= '0' && ch <= '9'; CH)	x= x*10 + ch -'0';
		return	f? -x : x;
}

#define n	1000005

int		N, pre[n], Q[n];

char	A[n], B[n];

int		main(int argc, char* argv[]){
		N= IN();
		scanf("%s%s", A+1, B+1);
		
		int flag= 0;
		For(i, 1, N)	if	(A[i] != B[i])	flag= 1;
		if	(! flag)	return	puts("0"), 0;
		
		for (int i= N, j= N; i; i--)	{
			j= min(j, i);
			for (; j && A[j] != B[i]; j--);
			if	(! j)	return	puts("-1"), 0;
			pre[i]= j;
		}
		
		int	Ans= 1, l= 1, r= 0;
		Rep(i, N, 1)	if	(pre[i] > pre[i-1])	{
			for (; l <= r && Q[l] - (r-l) > i; l++);
			if	(pre[i] < i)	Q[++ r]= pre[i], Ans= max(Ans, r-l+2);
		}
		printf("%d\n", Ans);
		
		return	0;
}

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

int main(){
  int n;
  cin >> n;
  int tmp;
  for ( int i = 0; i < n; i++){
    cin >> tmp;
    if ( tmp % 2 == 0 ){
      if (tmp % 3 != 0 && tmp % 5 != 0){
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }
  cout << "APPROVED" << endl;

  return 0;
}

Measured memory_bytes: 256
N,M=list(map(int,input().split()))
E={i:[] for i in range(1,N+1)}
for i in range(M):
    a,b=list(map(int,input().split()))
    E[a].append(b)
    E[b].append(a)
V={i:0 for i in range(1,N+1)}
W=[1]
while W!=[]:
    S=[]
    for a in W:
        for b in E[a]:
            if V[b]==0:
                V[b]=a
                S.append(b)
    W=S
if -1 in V:
    print('No')
else:
    print('Yes')
    for i in range(2,N+1):
        print(V[i])

Measured memory_bytes: 53564
n, m = map(int, raw_input().split())


def algorithm(k):
    result = 1
    division = 1
    num = n + k - 1
    num2 = 1
    for i in range(min(k, n - 1)):
        result *= num
        num -= 1
        division *= num2
        num2 += 1
    return result / division

if m == 1:
    print 1
else:
    divs = []
    while m != 0:
        flag = 0
        for i in range(2, int(m**0.5)+1):
            if m % i == 0:
                flag = 1
                divs.append(i)
                break
        if flag == 1:
            m = m / i
        else:
            divs.append(m)
            break
    divs.sort()
    divs_num = []
    num = 0
    first = divs[0]
    divs.append(0)
    for i in range(len(divs)):
        if divs[i] == first:
            num += 1
        else:
            divs_num.append(num)
            num = 1
            first = divs[i]

    divs_num = map(algorithm, divs_num)

    result = 1
    for i in divs_num:
        result *= i
    print result % (10**9+7)


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const double INF = 1000000000.0;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

const int MAX_N = 12;
const int MAX_M = 40;
int n, m, p, a, b;
int x, y;
double z;
double dp[1 << MAX_N][MAX_M];
double t[MAX_N];
double d[MAX_M][MAX_M];

int main()
{
  while(cin >> n >> m >> p >> a >> b, n){
    rep(i, m) rep(j, m) d[i][j] = -1;

    rep(i, n) cin >> t[i];
    rep(i, p){
      cin >> x >> y >> z;
      d[x - 1][y - 1] = z;
      d[y - 1][x - 1] = z;
    }

    rep(i, 1 << n) rep(j, m) dp[i][j] = INF;
    dp[0][a - 1] = 0.0;

    rep(S, 1 << n) rep(v, m) rep(i, n) if(!(S & 1 << i)) rep(u, m) if(d[v][u] > 0) minup(dp[S | 1 << i][u], dp[S][v] + d[v][u] / t[i]);

    double res = INF;
    rep(S, 1 << n) minup(res, dp[S][b - 1]);
    if(res < INF) printf("%.15f\n", res);
    else puts("Impossible");
  }

  return 0;
}

Measured memory_bytes: 1344
#include <stdio.h>

int main()
{
  int i;
  int H, A, B;
  int count = 0;
  
  scanf("%d %d %d", &H, &A, &B);

  for (i = A; i <= B; i++) {
    if (!(H % i)) count++;
  }

  printf("%d\n", count);

  return 0;
}
  



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

using namespace std;

typedef long long ll;

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

	int a, b;
	cin >> a >> b;

	int x = b - a;
	cout << x * (x + 1) / 2 - b << endl;
}


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

using namespace std;
#define N 2005
vector<int>a;

int main()
{
    ios::sync_with_stdio(0);
    int n;
    cin>>n;
    a.resize(n);
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    int ma=a[0],j=0;
    for(int i=n-1;i>=0;--i){
        int t;
        if(a[i]*2>a[n-1]){
            t=a[n-1]-a[i];
        }
        else{
            t=a[i];
        }
        if(t>ma){
            ma=t;
            j=i;
        }
    }
    cout<<a[n-1]<<' '<<a[j]<<'\n';
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
int main(){
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<4;i++){
        if(s[i]=='2') ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
constexpr int P = 1E9 + 7;
int power(int base, int exp) {
    int result = 1;
    while (exp > 0) {
        if (exp & 1)
            result = 1LL * result * base % P;
        base = 1LL * base * base % P;
        exp >>= 1;
    }
    return result;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int x, y;
    cin >> x >> y;
    if ((x + y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    tie(x, y) = make_tuple((2 * x - y) / 3, (2 * y - x) / 3);
    if (x < 0 || y < 0) {
        cout << 0 << endl;
        return 0;
    }
    int ans = 1;
    for (int i = x + 1; i <= x + y; ++i)
        ans = 1LL * ans * i % P;
    int tmp = 1;
    for (int i = 1; i <= y; ++i)
        tmp = 1LL * tmp * i % P;
    ans = 1LL * ans * power(tmp, P - 2) % P;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    string s;
    cin >> s;
    ll alp[26];
    ll i;
    for(i=0;i<26;i++){
      alp[i]=0;
    }
    for(i=0;i<s.size();i++){
      if(alp[s[i]-97]==1){
        cout <<"no";
        return 0;
      }else alp[s[i]-97]=1;
    }
    cout << "yes";
    return 0;
}


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

int main () {
  char C ;
  cin >> C ;
  if(C=='A') cout << 'T' << endl ;
  if(C=='C') cout << 'G' << endl ;
  if(C=='G') cout << 'C' << endl ;
  if(C=='T') cout << 'A' << endl ;
}

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

int main(){
    string S,T,U;
    int A,B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;
    if(U == S){
        A--;
    }else{
        B--;
    }
    cout << A << " " << B << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;

int a[10];

int main()
{
   	for(int i=1;i<=4;++i) cin>>a[i];
   	int x=a[1]+a[2];
   	int y=a[3]+a[4];
   	if(x==y) cout<<"Balanced"<<endl;
	else if(x>y) cout<<"Left"<<endl; 
	else cout<<"Right"<<endl;
    return 0;	 
}

Measured memory_bytes: 256
f = True
while f:
    x = raw_input()
    x = int(x)
    l = []
    for i in range(x):
        l.append(int(raw_input()))
    if x == 0:
        f = False
    else:
        print (sum(l) - min(l) - max(l)) / (len(l) - 2)

Measured memory_bytes: 6236
n = int(input())
A = list(map(int,input().split()))
s1 = s2 =  0
#偶数番目までの和を正→ans1、奇数番目までの和を正→ans2
ans1 = ans2 = 0
#ans1について
for i in range(len(A)):
    s1 += A[i]
    if (i+1)%2==0:
        if s1>0:
            continue
        else:
            ans1+= abs(s1) + 1
            s1 = 1
    else:
        if s1<0:
            continue
        else:
            ans1 += abs(s1) +1
            s1 = -1
#ans2について
for i in range(len(A)):
    s2 += A[i]
    if (i+1)%2 == 0:
        if s2 <0:
            continue
        else:
            ans2 += abs(s2) + 1
            s2 = -1
    else:
        if s2 > 0:
            continue
        else:
            ans2 += abs(s2) + 1
            s2 = 1
print(min(ans1,ans2))

Measured memory_bytes: 14468
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int H = in.nextInt();
        int W = in.nextInt();
        char[][] s = new char[H][];
        for (int h = 0; h < H; h++)
            s[h] = in.next().toCharArray();

        int[][] a = new int[H][W];
        if (s[0][0] == '#')
            a[0][0] = 1;
        for (int h = 1; h < H; h++) {
            a[h][0] = a[h-1][0];
            if (s[h-1][0] == '.' && s[h][0] == '#')
                a[h][0]++;
        }
        for (int w = 1; w < W; w++) {
            a[0][w] = a[0][w-1];
            if (s[0][w-1] == '.' && s[0][w] == '#')
                a[0][w]++;
        }
        for (int h = 1; h < H; h++) for (int w = 1; w < W; w++) {
            int a0 = a[h-1][w];
            if (s[h-1][w] == '.' && s[h][w] == '#')
                a0++;
            int a1 = a[h][w-1];
            if (s[h][w-1] == '.' && s[h][w] == '#')
                a1++;
            a[h][w] = Math.min(a0, a1);
        }
        out.println(a[H-1][W-1]);

        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}



Measured memory_bytes: 24660
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	while(true){
		scanf("%d %d",&a,&b);
		if(a == 0 && b == 0) break;
		if(a > b) printf("%d %d\n",b,a);
		else{
			printf("%d %d\n",a,b);
		}
	}
}


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

int main(){
    int H, M, h, m, K;
    cin >> H >> M >>  h >> m >> K;
    int time = h * 60 + m - K - (H*60 + M);
    cout << time << endl;

}

Measured memory_bytes: 3632
fun main() {
    val l = readLine()!!.split(' ').map { it.toInt() }
    val h = readLine()!!.split(' ').map { it.toInt() }
    var list: MutableMap<Int, Int> = mutableMapOf()
    for (i in 0 until l[0]) {
        list[i] = 0
    }

    for (i in 0 until l[1]) {
        val ab = readLine()!!.split(' ').map { it.toInt()-1 }
        if (h[ab[0]] > h[ab[1]]) {
            list[ab[1]] = list[ab[1]]!! + 1
        } else if (h[ab[0]] < h[ab[1]]) {
            list[ab[0]] = list[ab[0]]!! + 1
        } else {
            list[ab[1]] = list[ab[1]]!! + 1
            list[ab[0]] = list[ab[0]]!! + 1
        }
    }

    val res = list.filter { it.value == 0 }.count()
    println(res)
}



Measured memory_bytes: 73580
/*input
46 4 40 5
*/

#include <bits/stdc++.h>

using namespace std;

int A, B, C, D;

int main() {
	cin >> A >> B >> C >> D;
	cout << ((C / B + (C % B != 0) <= A/D + (A % D != 0)) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<fstream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	cout<<(a+b+1)/2<<endl; 
	return 0;
}

Measured memory_bytes: 256
S = int(input())
K = int(input())

lst = [0]*100
while S > 0:
    lst.append(S%10)
    S //= 10 # 必須
lst.reverse()
#print(lst)
j = 0
n = 0
while lst[j] == 1:
    n = j+1
    j += 1
#print('n =',n)
if K <= n:
    print(1)
else:
    print(lst[n])

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

using namespace std;

#define endl "\n"

double dp[3001][3001];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed;
    cout << setprecision(10);
    int t;
    cin >> t;
    vector<double> A(t);
    for (double &i : A) cin >> i;

    dp[0][0] = 1;
    for (int i = 1; i <= t; i++) {
        for (int j = 0; j <= t; j++) {
            if (j == 0) {
                dp[i][j] = (1.0 - A[i - 1]) * dp[i - 1][j];
            } else {
                dp[i][j] = A[i - 1] * dp[i - 1][j - 1] + (1.0 - A[i - 1]) * dp[i - 1][j];
            }
        }
    }

    double sol = 0;
    for (int i = t / 2 + 1; i <= t; i++) {
        sol += dp[t][i];
    }

    cout << sol << endl;
    return 0;
}

Measured memory_bytes: 74172
#include<iostream>
using namespace std;
int num[1000000];
int main(){
	 int n,k;
	 cin>>n>>k;
	 int ans=0;
	 for(int i=0;i<n;i++)
	 {
	 	int x;
	 	cin>>x;
	 	if(x>=k)ans++;
	  } 
	  cout<<ans;
	  
	return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <set>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
int n, m, q;
int a[51], b[51], c[51], d[51];
int v[11];
int ans = 0;
 
 
int main() {
    int N, K;
    cin >> N >> K;
    set<long long> st;
    for (int i= 0;i<K;i++){
        int m;
        cin >> m;
        for (int j= 0;j<m;j++){
            int nn;
            cin >> nn;
            st.insert(nn);
        }
    }
    
    cout <<(N-st.size())<<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    Rep(i, N) {
        cin >> A[i];
    }
    int count = 0;
    for (int i = 0; i < N; ++i) {
        int minj = i;
        for (int j = i; j < N; ++j) {
            if (A[j] < A[minj]) {
                minj = j;
            }
        }
        if (i != minj) {
            swap(A[i], A[minj]);
            count++;
        }
    }
    Rep(i, N) {
        if (i) {
            cout << " ";
        }
        cout << A[i];
    }
    cout << endl;
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  int n,a,b;
  cin>>n>>a>>b;
  int p[n];
  rep(i,n) cin>>p[i];
  int f = 0,s = 0, t = 0;
  rep(i,n) {
    if(p[i] <= a) {
      f++;
    } else if(p[i] >= b + 1) {
      t++;
    } else {
      s++;
    }
  }
  cout << min({f,t,s}) << endl;

  return 0;
}


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

#define ll long long int
#define ull unsigned long long int
#define po2(z) 1<<(ll)z
#define fr(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)
#define rf(i,x,n) for(ll i=(ll)(x);i>=(ll)(n);--i)
#define modinv(x) powah(x,mod-2)
#define ncr(n,r) (((fact[n]*modinv(fact[n-r]))%mod*modinv(fact[r]))%mod)
#define factorial fact.pb(1);sidha(i,1,MAX)fact.pb((fact[i-1]*i)%mod)
#define TC ll test;cin>>test;while(test--)
#define tej ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod (ll)1000000007
#define MAX 100005

int main(){

ll n;
cin>>n;
double dp[n+1][n+1];
memset(dp,0,sizeof(dp));
double ans=0;
double prob[n+1];

fr(i,1,n+1){
	cin>>prob[i];
}


dp[1][0]=1-prob[1];
fr(i,2,n+1){
	dp[i][0]=dp[i-1][0]*(1-prob[i]);
}


dp[1][1]=prob[1];
fr(i,2,n+1){
	dp[i][i]=dp[i-1][i-1]*prob[i];
}


fr(i,1,n+1){
	fr(j,1,i){
		dp[i][j]=dp[i-1][j-1]*prob[i]+dp[i-1][j]*(1-prob[i]);
	}
}

fr(i,n/2+1,n+1){
ans+=dp[n][i];
}
cout<<fixed << setprecision(10) <<ans;

}


Measured memory_bytes: 70528
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const ll inf=998244353;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

ll dp[3300][3300];//(i,j)サイズの通り数

int main(){cout<<fixed<<setprecision(20);
		   //dp
           ll a,b,c,d;
           cin>>a>>b>>c>>d;
           //たて　横　被り
           rep(i,a,c+1){
            rep(j,b,d+1){
             if(i==a&&j==b){
               dp[i][j]=1;
               continue;
             }
              dp[i][j]+=dp[i-1][j]*j%inf;
              dp[i][j]%=inf;
              dp[i][j]+=dp[i][j-1]*i%inf;
              dp[i][j]%=inf;
              dp[i][j]-=(i-1)*(j-1)*dp[i-1][j-1]%inf;
              dp[i][j]+=inf;
              dp[i][j]%=inf;
            }
           }
           cout<<dp[c][d]<<endl;
}



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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)((n)-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int op(int a, int b){
    return max(a, b);
}
int e(){
    return 0;
}
using segtree = atcoder::segtree<int, op, e>;
int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n,k; cin >> n >> k;
    vi a(n);
    rep(i,n) cin >> a[i];

    auto st = segtree(300010);
    rep(i,n){
        int l = max(a[i]-k, 0);
        int r = min(a[i]+k, 300000);
        int mx = st.prod(l, r+1);
        st.set(a[i], mx+1);
    }
    cout << st.all_prod() << endl;
    return 0;
}

Measured memory_bytes: 9772
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} Accelerate_Cin;

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

  vector<int> h(N, 0);
  h[0] = T[0], h[N - 1] = A[N - 1];

  if (T[0] > A[0] || T[N - 1] < A[N - 1]) {
    cout << 0 << endl;
    return 0;
  }

  if (T[N - 1] != A[0]) {
    cout << 0 << endl;
    return 0;
  }

  for (int i = 1; i < N; i++) {
    if (T[i - 1] < T[i]) {
      h[i] = T[i];
    }
  }

  for (int i = N - 2; i - 1 >= 0; i--) {
    if (h[i] != 0) {
      if (h[i] > A[i]) {
        cout << 0 << endl;
        return 0;
      }
    }
    if (A[i] > A[i + 1]) h[i] = A[i];
  }

  int ans = 1;
  for (int i = 0; i < N; i++) {
    if (h[i] == 0) {
      ans *= min(A[i], T[i]);
      ans %= MOD;
    }
  }

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


Measured memory_bytes: 2560
import sys
import numpy as np
from collections import deque
from itertools import combinations
sys.setrecursionlimit(10**9)


def main():
    S,T = input().split()
    A,B = map(int,input().split())
    U = input()

    if S == U:
        print(A-1,B)
    else:
        print(A, B-1)




if __name__ == "__main__":
  main()


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

using namespace std;


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

template <typename T>

void print(T x)
{
	std::cout << x << '\n';
}


signed main(void) {
	int L,R;
	cin >> L >> R ;
	const int mod = 2019;
	int ans = pow(mod, 2);

	if (R - L > mod)print(0);
	else {
		FOR(i,L,min(R+1,L+mod+2)){
			FOR(j, L, min(R+1, L + mod + 2)) {
				if (i != j) {
					ans = min(((i%mod)*(j%mod)) % mod, ans);
				}
			}
		}
		print(ans);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  ll k;
  cin >> k;
  ll s = 7LL;
  ll d = 7LL;
  rep(i,1000000) {
    if(d%k==0) {
      cout << i+1 << endl;
      return 0;
    }
    s *= 10;
    s %= k;
    d += s;
    d %= k;
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000000
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;

ll modpow(ll x, ll n) {
    ll res=1;
    while(n>0) {
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}


int main() {
    ll n, ans=0;
    ll color[8]={0};
    cin >> n;
    ll a[n];
    ll i;
    ll pro=0;
    for(i=0; i<n; i++) {
        cin >> a[i];
        if(a[i]<3200)
            color[a[i]/400]=1;
        else
            pro++;
    }
    
    for(i=0; i<8; i++) {
        ans+=color[i];
    }
    cout << max(1, ans) << " " << ans+pro << endl;
}


Measured memory_bytes: 256
import scala.io.StdIn

object Main extends App {
  StdIn.readLine match {
    case S(a, b, c) => println(s"$a $b $c")
    case _ => throw new Exception("Invalid input.")
  }
}

object S {
  def unapply(s: String): Option[(String, String, String)] = {
    s.split(",") match {
      case Array(a, b, c) => Some(a, b, c)
      case _ => None
    }
  }
}


Measured memory_bytes: 21424
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int n,a; cin>>n>>a;
  if((n%500)<=a)
  cout<<"Yes"<<endl;
  else
  cout<<"No"<<endl;

  return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String args[]){

		Scanner cin = new Scanner(System.in);

		int A = cin.nextInt();
		int B = cin.nextInt();
		cin.close();

		String result = "Draw";

		if(A==B){
		}else{
			if(A==1||B!=1&&A>B){
				result = "Alice";
			}else if(B==1||A!=1&&B>A){
				result = "Bob";
			}
		}

		System.out.println(result);
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int n,a[100005],b[100005];
int main(){
	cin>>n;for(int i=1;i<=n;i++){cin>>a[i]>>b[i];}
  	auto m = max_element(a+1,a+n+1);
  	cout<<(*m)+b[m-a];
}

Measured memory_bytes: 1024
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    N=I()
    a2=input()
    a=[]
    for i in range(len(a2)):
        a.append(int(a2[i]))
    
    def calc(L):
        L1=list(L)
        nL=len(L)
        if nL%2==1 or nL<=5000:
            for i in range(nL-1):
                L1[i]=abs(L[i]-L[i+1])
            L1.pop()
                
            return L1
        else:
            L2=[]
            for i in range(0,nL,2):
                L2.append(abs(L[i]-L[i+1]))
            return L2

    while len(a)!=1:
        a=calc(a)    
    
    print(a[0])
                
        
    
main()


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

int main(){
	int n,l,ans;
	cin >> n >> l;
	int a = l;
	int r = l + n - 1;
	int eat;
	if (r <= 0)eat = r;
	else if (a >= 0)eat = a;
	else eat = 0;
	ans = (r + a)*(r - a + 1) / 2 - eat;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>


int main(void){


	int a, b, c, x, y;

	scanf("%d", &x);
	for (y = 0; y < x; y++){
		scanf("%d %d %d", &a, &b, &c);


		a = a*a;
		b = b*b;
		c = c*c;

		if (a == b + c || b == a + c || c == a + b){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
	}
	return 0;

}

Measured memory_bytes: 580
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format, std.datetime;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N, X, Y;
    scan(N, X, Y);
    X--, Y--;

    if (Y < X)
        swap(X, Y);

    auto ans = new long[](N);
    foreach (i; 0 .. N)
    {
        foreach (j; i .. N)
        {
            long d = () {
                if (i <= X && j <= X)
                    return j - i;
                if (Y <= i && Y <= j)
                    return j - i;
                if (i <= X && Y <= j)
                    return j - i - (Y - X - 1);
                if (i <= X && X <= j && j <= Y)
                    return min(j - i, (Y - j) + (X - i) + 1);
                if (X <= i && i <= Y && Y <= j)
                    return min(j - i, (i - X) + (j - Y) + 1);
                if (X < i && j < Y)
                    return min(j - i, (i - X) + (Y - j) + 1);
                writefln("%s %s", i, j);
                assert(0);
            }();
            ans[d]++;
        }
    }
    foreach (i; 1 .. N)
        writeln(ans[i]);
}


Measured memory_bytes: 256
def main():
    s = list(input())
    t = input()

    flag = 0

    for i in range(len(s)):
        s = list(s)
        b = s[-1]
        for j in reversed(range(len(s))):
            s[j] = s[j-1]
        s[0] = b
        s = ''.join(s)
        if s == t:
            flag = 1
            break


    if flag:
        print("Yes")
    else:
        print("No")
       

if __name__=='__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif


typedef long long ll; 
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
 
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define S second
#define F first
#define PI 3.14159265358979323846

ll sqr(ll n) {
    return n*n;
}

const int MOD = 1e9 + 7;

ll binpow(ll a, ll n) {
    if (n == 0)
        return 1;
    if (n % 2 != 0) return (binpow(a, n-1)*a); else {
        ll b = binpow(a, n/2);
        return (b*b);
    }
}

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;
}

void solve() {
    string s;
    cin >> s;

    int sum = 0;
    for (int i = 0; i < s.size(); i++)
        sum += s[i] - '0';
    if (sum % 9) cout << "No" << endl; else cout << "Yes" << endl;
}

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

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 1005;

int a[MAX_N];
int n,m;
vector<int> v;

int main()
{
	while(1){
		scanf("%d%d",&n,&m);
		if(n==0&&m==0){
			break;
		}
		v.clear();
		rep(i,n){
			scanf("%d",&a[i]);
		}
		a[n] = 0;
		rep(i,n+1){
			for(int j=i;j<=n;j++){
				v.push_back(a[i]+a[j]);
			}
		}
		v.erase(unique(v.begin(),v.end()),v.end());
		sort(v.begin(),v.end());
		int ans = 0;
		rep(i,v.size()){
			if(v[i] == m){
				ans = m;
				break;
			}
			if(v[i] < m){
				vector<int>::iterator it = upper_bound(v.begin(),v.end(),m-v[i]);
				int s = v[i] + *(it-1);
				if(m-ans > m-s){
					ans = s;
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 4996
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef struct dice{
    int face[6];
}dice;

void rotate(dice *d, char dir)
{
    int temp;
    switch(dir) {
    case 'N':
        temp=d->face[0];
        d->face[0]=d->face[1];
        d->face[1]=d->face[5];
        d->face[5]=d->face[4];
        d->face[4]=temp;
        break;
    case 'E':
        temp=d->face[0];
        d->face[0]=d->face[3];
        d->face[3]=d->face[5];
        d->face[5]=d->face[2];
        d->face[2]=temp;
        break;
    case 'W':
        temp=d->face[0];
        d->face[0]=d->face[2];
        d->face[2]=d->face[5];
        d->face[5]=d->face[3];
        d->face[3]=temp;
        break;
    case 'S':
        temp=d->face[0];
        d->face[0]=d->face[4];
        d->face[4]=d->face[5];
        d->face[5]=d->face[1];
        d->face[1]=temp;
        break;
    }
}

int isSame(dice d1, dice d2)
{
    static const char dir[]="NNNESSSWNNNESSSWNNNESSSW";
    int i, j;
    for(i=0; i<24; i++) {
        for(j=0; j<6 && d1.face[j]==d2.face[j]; j++);
        if(j==6) return 1;
        rotate(&d2, dir[i]);
    }
    return 0;
}

int main()
{
    dice d[100];
    int i, j, n;
    scanf("%d", &n);
    for(i=0; i<n; i++) {
        for(j=0; j<6; j++) {
            scanf("%d", &d[i].face[j]);
        }
        for(j=0; j<i; j++) {
            if(isSame(d[i], d[j])) {
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 2112
n=int(input())
alist = list(map(int, input().split()))
gokei=sum(alist)
nokori=gokei

if alist[0]!=0:
    if n==0 and alist[0]==1:
        print(1)
    else:
        print(-1)
else:
    oya=1
    answer=1
    ng=0
    for i in range(n-1):
        #print("choice", oya*2-alist[i+1], nokori-alist[i+1])
        if alist[i+1]>oya*2:
            ng=1
        oya=min(oya*2-alist[i+1], nokori-alist[i+1])
        answer+=oya
        answer+=alist[i+1]
        nokori-=alist[i+1]
        #print(nokori, answer, alist[i+2])
    
    if alist[-1]>oya*2:
        ng=1
        #print(alist[-1], oya)
    answer+=alist[-1]
    
    if ng==1:
        print(-1)
    else:
        print(answer)

Measured memory_bytes: 83424
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>

using namespace std;

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

int main()
{
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  while (true)
  {
    C -= B;
    if (C <= 0)
    {
      cout << "Yes" << endl;
      return 0;
    }
    A -= D;
    if (A <= 0)
    {
      cout << "No" << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3628
import sys

sys.setrecursionlimit(10**6)
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
dx = (0, 0, 1, -1)
dy = (1, -1, 0, 0)
seen = [[False] * w for _ in range(h)]

numb = 0
numw = 0


def dfs(x, y):
    global numb, numw
    seen[x][y] = True
    if s[x][y] == '#':
        numb += 1
    else:
        numw += 1
    for di in range(4):
        nx = x + dx[di]
        ny = y + dy[di]
        if (nx < 0 or nx >= h or ny < 0 or ny >= w):
            continue
        if s[x][y] == s[nx][ny]:
            continue
        if seen[nx][ny]:
            continue
        dfs(nx, ny)


ans = 0
for x in range(h):
    for y in range(w):
        if seen[x][y]:
            continue
        if s[x][y] == '.':
            continue
        numb = 0
        numw = 0
        dfs(x, y)
        ans += numb * numw
print(ans)


Measured memory_bytes: 149492