akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

def Warshall_Floyd(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])
    return d
h, w = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
n = 10
Warshall_Floyd(c)

A =[list(map(int, input().split())) for _ in range(h)]
S = []
S_append = S.append
for a in A:
    for i in a:
      if i != -1 and i != 1:
        S_append(i)
ans = 0
for s in S:
  ans += c[s][1]
print(ans)

Measured memory_bytes: 3836
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define llong long long
#define pb(a) push_back(a)
#define INF 9999999

using namespace std;

typedef pair<int,int> P;

int dy[4]={0,0,1,-1};
int dx[4]={1,-1,0,0};
int main(){
	string s;
	cin>>s;
	VSORT(s);
	if(s=="abc")cout<<"Yes";
	else cout<<"No";
}


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

main(){
  int i, n, *a,c[10001], *b, j;

  scanf("%d", &n);

  a = malloc(sizeof(int)*n+1);
  b = malloc(sizeof(int)*n+1);

  for(j = 0;j < 10001;j++) c[j] = 0;

  for(i = 0;i < n;i++){ 
    scanf("%d", &a[i+1]);
    c[a[i+1]]++;
  }
  
  for(j = 1;j <= 10001;j++) c[j] = c[j] + c[j - 1];
  
  for(j = 1;j <= n;j++){
    b[c[a[j]]] = a[j];
    c[a[j]]--;
  }
  
  for(i = 1;i < n;i++)  printf("%d ", b[i]);
  printf("%d\n", b[i]);
  return 0;
}

Measured memory_bytes: 16272
#include <stdio.h>
int main(){
  long long int k,i,n=0;
  scanf("%lld",&k);
  
  for(i=1; i<=150000000;i++){
    n=10*n+7;
    n=n%k;
    if(n==0){
      printf("%lld",i);
      return 0;
    }
  }
  printf("-1");
  return 0;
}


Measured memory_bytes: 1716
a = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
e = '#' * 20
n = int(input())
for i in range(n):
    b,f,r,v = [int(i) for i in input().split()]
    a[b - 1][f - 1][r - 1] += v
for i in range(4):
        for j in range(3):
            print(' ' + ' '.join(map(str,a[i][j])))
        if(i != 3):
            print(e)

Measured memory_bytes: 7720
s = input()
n = len(s)
ans = [0] *n 

left = 0
i = 0

while(left<n-1):
  while s[i]=="R":
    i+=1
  right=i
  while s[right]=="L":
    if right==n-1:
      right += 1
      break        
    right +=1

  for k in range(left, right):
    if (i-k) % 2==0:
      ans[i] += 1
    else:
      ans[i-1] += 1

  left = right
  i = left
    
print(*ans)




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

unsigned GetDigit(unsigned num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

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

    int  ans = 0;

    for(int i = 1; i <= n; i++){
        if(GetDigit(i) % 2 == 1){
            ans ++;
        }
    }
    std::printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;


int main() {
    int E,x,y,z,m;
    while (cin >> E && E>0) {
       m = 1000000;
       for (int i = 0 ; i <= 100 ; i++) {
           for (int j = 0 ; j <= 1000 ; j++){
               x = E - i*i*i - j*j;
               if (x+j+i<=m && x>=0) m = x+j+i;
           }
       }
       cout << m <<endl;
    }
}



Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  ll a, b, x;
  cin >> a >> b >> x;

  ll da = a / x;
  ll ra = a % x;
  ll db = b / x;
  ll rb = b % x;

  if (ra > 0) da++;
  ll ans = max(0LL, db - da + 1);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define mod 998244353
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int r[8010];
int b[8010];
int ar[8010];
int ab[8010];
ll dp[4010][4010];
int main(){
    string s;
    cin >> s;
    int n = s.size();
    
    rep(i,n){
        if(s[i]=='0'){
            ar[i] = 2;
        }else if(s[i]=='1'){
            ar[i] = 1;
            ab[i] = 1;
        }else{
            ab[i] = 2;
        }
    }
    if(s[0]=='0'){
        r[0] = 1;
    }else if(s[0]=='1'){
        r[0] = 1;
        b[0] = 1;
    }else{
        b[0] = 1;
    }
    for(int i=1;i<=8005;i++){
        r[i] = r[i-1];
        b[i] = b[i-1];
        if(ar[i]>=1){
            r[i]++;
        }
        if(ar[i-1]>=2){
            r[i]++;
        }
        if(ab[i]>=1){
            b[i]++;
        }
        if(ab[i-1]>=2){
            b[i]++;
        }
        // if(i<=4){
        //     cerr << r[i] << " " << b[i] << endl;
        // }
    }
    dp[0][0] = 1;
    for(int i=0;i<=2*n;i++){
        for(int j=0;j<=2*n;j++){
            if(i==0&&j==0)continue;
            if(r[i+j-1]<i||b[i+j-1]<j)continue;
            //cerr << i << " "<< j << endl;
            if(i!=0){
                dp[i][j] += dp[i-1][j];
                dp[i][j] %= mod;
            }
            if(j!=0){
                dp[i][j] += dp[i][j-1];
                dp[i][j] %= mod;
            }
        }
    }
    //cerr << r[4010] << " " << b[4010] << endl;
    cout << dp[r[4010]][b[4010]] << endl;
    return 0;
}

Measured memory_bytes: 123520
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vb = vector<bool>;
using vs = vector<string>;
using pint = pair<int, int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
    int a, b;
    cin >> a >> b;
    string s, t;
    rep(i, b) {
        s += to_string(a);
    }
    rep(i, a) {
        t += to_string(b);
    }
    if(s <= t) {
        cout << s << endl;
    } else {
        cout << t << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <cstdio>
using namespace std;
const int N = 1e5 + 12;
int head[N],dt,dep[N],mx,rt,n,sz[N],fa[N],num[N],que[N],tot,ans[2][N];
struct Edge{int to,nex;}edge[N <<1];bool vis[N];
void AddEdge(int u,int v){edge[++dt] = (Edge){v,head[u]};head[u] = dt;}
void dfs(int u)
{
	if(dep[u] > dep[mx])mx = u;sz[u] = 1;
	for(int i = head[u];i;i = edge[i].nex)if(edge[i].to != fa[u])
	{
		dep[edge[i].to] = dep[u] + 1;
		fa[edge[i].to] = u;
		dfs(edge[i].to);
		sz[u] += sz[edge[i].to];
	}
}
int main()
{
  int x,y;scanf("%d",&n);
  for(int i = 1;i < n;i++)scanf("%d %d",&x,&y),AddEdge(x,y),AddEdge(y,x);
  dfs(1);dep[rt = mx] = fa[rt] = 0;dfs(rt);x = mx;
  while(x)vis[x] = true,que[++tot] = x,x = fa[x];
  for(int i = 1;i <= n;i++)if(!vis[i] && sz[i] != 1){puts("-1");return 0;}
  else num[fa[i]] += !vis[i];
  for(int i = 1,p = 0,t = 0;i <= tot;i++,t++)
  {
  	ans[0][t + num[que[i]] + 1] = ++p;
  	for(int j = 1;j <= num[que[i]];j++)
  	ans[0][++t] = ++p;
  } 
  for(int i = tot,p = 0,t = 0;i >= 1;i--,t++)
  {
  	ans[1][t + num[que[i]] + 1] = ++p;
  	for(int j = 1;j <= num[que[i]];j++)
  	ans[1][++t] = ++p;
  } 
  int cur = -1;
  for(int i = 1;i <= n && cur == -1;i++)
  {
  	if(ans[0][i] < ans[1][i])cur = 0;
  	if(ans[0][i] > ans[1][i])cur = 1;
  }
  if(cur == -1)cur = 0;
  printf("%d",ans[cur][1]);
  for(int i = 2;i <= n;i++)printf(" %d",ans[cur][i]);
}

Measured memory_bytes: 8704
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4") // wonderful

#include <bits/stdc++.h>
using namespace std;

#define forn(i, a, n) for (int i = (a); i < (int)n; i++)
#define trav(x, arr) for (auto &x : arr)
#define sz(x) (int)x.size()
#define Matrix(m, h, w) = std::vector<vector<int>> m(h, vector<int> (w)); 
using ll = long long;

#define vi vector<int>
#define vl vector<long>
#define vll vector<ll>

// benq
const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 100001;


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


    int x, n, p; cin >> x >> n;

    if (n == 0) {
    	cout << x;
    	return 0;
    } 


    unordered_set<int> set {};

    forn(i, 0, n) {
    	int a; cin >> a;
    	set.insert(a);
    }

    if (set.find(x) == set.end()) {
    	cout << x;
    	return 0;
    }

    int b = 1;

    while(true) {



    	if (set.find(abs(x - b)) == set.end()) {
    		cout << x-b;
    		break;
    	}
   		else if (set.find(abs(x+b)) == set.end()) {
   			cout << x+b;
   			break;
   		}
   		b++;
    }

	


    return 0;
}

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

int main() {
  string S;
  cin>>S;
  int A=0;
  int B=0;
  int C=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='a') A++;
    else if(S.at(i)=='b') B++;
    else if(S.at(i)=='c') C++;
  }
  vector<int> vec(3);
  vec.at(0)=A;
  vec.at(1)=B;
  vec.at(2)=C;
  
  sort(vec.begin(),vec.end());
  if(vec.at(0)==0){
    if(vec.at(1)==1&&vec.at(2)==1) cout<<"YES"<<endl;
    else if(vec.at(1)==0&&vec.at(2)==1) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  else{
    if(vec.at(2)-vec.at(0)<=1) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }

      
}

Measured memory_bytes: 3732
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n+1];
        int[] b = new int[n];
        for(int i = 0; i<n+1; i++) {
            a[i] = sc.nextInt();
        }

        for(int i = 0; i<n; i++) {
            b[i] = sc.nextInt();
        }
        long monsters = 0;
        for(int i = 0; i<n; i++) {

            if(a[i]>=b[i]) {
                monsters += b[i];
                //System.out.println(monsters + " " + a[i+1]);
                continue;
            }
            //System.out.println(b[i]);
            monsters += a[i];
            b[i] = b[i]-a[i];
            //System.out.println(b[i]);
            //System.out.println("monsters" + monsters);
            monsters += Math.min(a[i+1],b[i]);
            a[i+1] = Math.max(0,a[i+1]-b[i]);
            //System.out.println(monsters + " " + a[i+1]);
        }
        System.out.println(monsters);
    }
}

Measured memory_bytes: 65360
#include<bits/stdc++.h>
#define ll long long
#define N 100005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
main()
{
    int n;
    cin>>n;
    map<int,int>mp;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        mp[a[i]]=i;
    }
    sort(a,a+n);
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        int dif=mp[a[i]]-i;
        dif=abs(dif);
        ans+=dif%2;
    }
    cout<<ans/2;
}


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

int main(){
  int A, B, X;
  cin >> A >> B >> X;
  
  if(A > X){
    cout << "NO" << endl;
  }
  else if((A+B) < X){
    cout << "NO" << endl;
  }
  else{
    cout << "YES" << endl;
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[4];
  cin >> a[0] >> a[1] >> a[2] >> a[3];
  sort(a,a+4);
  if(a[0] == a[1] && a[2] == a[3]) cout << "yes" << endl;
  else cout << "no" << endl;
  return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll A, B, C;
    cin >> A >> B >> C;

    if (B+C > A) {
        cout << B+C-A << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
int Y[100];
int main() {
    int N,A,B,C,X;
    while(scanf("%d %d %d %d %d",&N,&A,&B,&C,&X),N) {
        for(int i=0;i<N;i++) {
            scanf("%d",&Y[i]);
        }
        int idx=0;
        bool OK=0;
        for(int i=0;i<=10000;i++) {
            if(X==Y[idx]) idx++;
            if(idx==N) {
                printf("%d\n",i);
                OK=1;
                break;
            }
            X=(A*X+B)%C;
        }
        if(!OK) printf("-1\n");
    }
}

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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010;
const double eps = 1e-6;

int n, m;
int a[N];

void init(int l, int r)
{
    a[l]++, a[r + 1]--;
}

int main()
{
    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        init(l, r);
    }

    int res = 0;
    for(int i = 1; i <= n; i++)
    {
        a[i] += a[i - 1];
        if(a[i] == m) res++;
    }

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


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll               long long
#define mod              1000000007
#define endl              "\n"
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb                push_back
#define all(v)             v.begin(),v.end()
#define inp(V,n)      for(int i=0;i<n;i++){cin >> V[i];}
#define oup(V,n)     {for(int i=0;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
using namespace std;
ll factorial(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll gcd(ll a, ll b)
{
    if (a == 0)
      return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
   return (a*b)/gcd(a, b);
}
bool sortByVal(const pair<ll,ll> &a,
               const pair<ll,ll> &b)
{
    return (a.second > b.second);
}
ll Powb(ll b,ll n)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2);
    if(n%2==0){return (temp*temp)%mod;}
    else{return (b*((temp*temp)%mod))%mod;}
}
int main()
{
     fast;
     ll x,y,z,i,j,c=0,d=0,e=0,f=0,g=0,h=0,n,sum=0;
     cin>>x>>y>>z;
     swap(x,y);
     swap(x,z);
     cout<<x<<" "<<y<<" "<<z;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  string s;
  cin>>s;
  if(s=="Sunny"){
      cout<<"Cloudy"<<endl;
  }
  else if(s=="Cloudy"){
      cout<<"Rainy"<<endl;
  }
  else if(s=="Rainy"){
      cout<<"Sunny"<<endl;
  }
}

Measured memory_bytes: 256
import itertools
n, k = map(int, input().split())
p = list(map(int, input().split()))
ki = [0]*1001
for i in range(1, 1001):
    ki[i] = ki[i-1]+i

pp = []
for pa in p:
    pp.append(ki[pa]/pa)

# print(pp)
ppp = [0] + list(itertools.accumulate(pp))
# print(ppp)
ans = 0
for i in range(n-k+1):
    # print(ppp[i+k]-ppp[i])
    ans = max(ans, ppp[i+k]-ppp[i])

print("{0:.12f}".format(ans))


Measured memory_bytes: 82184
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, islice
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')

s = input()
t = input()

dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]
for i in range(len(s)):
	for j in range(len(t)):
		if s[i] == t[j]:
			dp[i+1][j+1] = dp[i][j] + 1
		else:
			dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])

ans = ""
i, j = len(s), len(t)
while dp[i][j]:
	if s[i-1] == t[j-1]:
		ans += s[i-1]
		i -= 1
		j -= 1
	else:
		if dp[i][j] == dp[i-1][j]:
			i -= 1
		else:
			j -= 1
print(ans[::-1])


Measured memory_bytes: 132568
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n=int(input())\n"
"a=1\n"
"for i in range(1,n+1):\n"
"  a=a*i%1000000007\n"
"print(a)\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 8384
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
#define YMAX 250001
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int digitsum(int n){
	int sum=0;
	while(n){
		sum+=n%10;
		n/=10;
	}
	return sum;
}
int main(){
	int N;
	scan(N);
	int ketawa[100001];
	for(int i=1;i<=N-1;i++){
		ketawa[i]=digitsum(i);
	}
	int ketawamin=INF;
	for(int i=1;i<=N/2;i++){
		ketawamin=min(ketawamin,ketawa[i]+ketawa[N-i]);
	}
	prin(ketawamin);
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;

int n,q;
int f[100001],dep[100001],d[100001],p[100001];
bool cmp(int i,int j){return dep[i]>dep[j];}

int h[100001],nxt[200001],to[200001],tot;
void ins(int x,int y){nxt[++tot]=h[x];to[tot]=y;h[x]=tot;}

int v[100001];

void DFS(int u,int fa){
	f[u]=fa; dep[u]=dep[fa]+1; ++d[fa];
	for(int i=h[u];i;i=nxt[i]) if(to[i]!=fa) DFS(to[i],u);
}

int main(){
	int x,y;
	scanf("%d",&n);
	F(i,2,n) scanf("%d%d",&x,&y), ins(x,y), ins(y,x);
	DFS(1,0);
	F(i,1,n) p[i]=i;
	sort(p+1,p+n+1,cmp);
	F(I,1,n){
		int i=p[I];
		if(v[i]) continue;
		if(i==1) {puts("First"); return 0;}
		v[i]=1;
		if(--d[f[i]]) {puts("First"); return 0;}
		else v[f[i]]=1, --d[f[f[i]]];
	} puts("Second");
	return 0;
}

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

using namespace std;

#define SEGTREE_MAX_N (1<<17)

class SegmentTree {
private:
  
  int size;
  vector<int> dat;
  
  int query(int a, int b, int k, int l, int r) {
    if(r<=a||b<=l) return INT_MAX;
    
    if(a<=l&&r<=b) return dat[k];
    int vl = query(a, b, k*2+1, l, (l+r)/2);
    int vr = query(a, b, k*2+2, (l+r)/2, r);
    
    return min(vl, vr);
  }
  
public:
  
  SegmentTree(int n_) {
    size = 1;
    while(size < n_) size *= 2;
    dat.resize(2*size-1, INT_MAX);
  }
  
  void update(int k, int a) {
    k += size-1;
    dat[k] = a;
    while(k>0) {
      k = (k-1) / 2;
      dat[k] = min(dat[k*2+1], dat[k*2+2]);
    }
  }
  
  int rangeMinimumQuery(int a, int b) {
    return query(a, b, 0, 0, size);
  }
};

int main() {
    
  int nn, q;
  int c, x, y;
  cin >> nn >> q;
  
  SegmentTree s(nn);
  
  for(int i=0; i<q; i++) {
    cin >> c >> x >> y;
      
    if(c) {
      cout << s.rangeMinimumQuery(x, y+1) << endl;
    }
    else {
      s.update(x, y);
    }
  }
  
  return 0;
}

Measured memory_bytes: 2060
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>
using namespace std;

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

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

int n;
vector<int> t[100000];
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
bool used[100000];
int color[100000];

bool dfs(int idx,int c){
  //cout<<idx<<","<<c<<endl;

  color[idx] = c;
  used[idx] = true;

  rep(i,t[idx].size()){
    int next = t[idx][i];

    if(color[next] == -1){
      if(idx + n == next || idx - n == next){
        bool res = dfs(next,!c);
        if(!res) return false;
      }
      else{
        bool res = dfs(next,c);
        if(!res) return false;
      }
    }
    else{
      if((idx + n == next || idx - n == next) && color[next] == color[idx]) return false;
      if(!(idx + n == next || idx - n == next) && color[next] != color[idx]) return false;
    }
  }

  return true;
}

bool solve(){
  memset(used,0,sizeof(used));

  REP(i,1,n+1){
    if(!used[i]){
      memset(color,-1,sizeof(color));
      bool flg = dfs(i,0);
      if(!flg) return false;
    }
  }

  return true;
}

int main(){
  while(scanf("%d",&n),n){
    rep(i,100000) t[i].clear();

    map<P,int> m;

    REP(i,1,n+1){
      int x[2],y[2];
      char buff[10];

      scanf("%d%d%s",&x[0],&y[0],buff);

      if(buff[0] == 'x'){
        x[1] = x[0] + 1;
        y[1] = y[0];
      }
      else{
        x[1] = x[0];
        y[1] = y[0] + 1;
      }

      rep(k,2){
        rep(j,4){
          int nx = x[k] + dx[j];
          int ny = y[k] + dy[j];
          int tmp = m[P(nx,ny)];
          if(tmp != 0){
            t[i+k*n].push_back(tmp);
            t[tmp].push_back(i+k*n);
          }
        }
      }

      rep(j,2){
        m[P(x[j],y[j])] = i + j * n;
      }
      t[i].push_back(i+n);
      t[i+n].push_back(i);
    }

    bool res = solve();
    printf("%s\n",res ? "Yes" : "No");
  }
}

Measured memory_bytes: 9444
# DFS用の関数.
def f(n, x):
    if n==0:
        return 0 if x<=0 else 1
    elif x <= 1+a[n-1]:
        return f(n-1,x-1)
    else:
        return p[n-1]+1+f(n-1,x-2-a[n-1])

n, x = map(int, input().split())
# n=0のとき、a,pを初期化.
a, p = [1], [1]
# 1<=n<=nのときの、a,pを逐次的に求める.
for i in range(n):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)

print(f(n,x))

Measured memory_bytes: 61920
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>

using ll = long long;
using namespace std;
const int limit = 100010;
using edge = struct{int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

// 深さ優先探索(現在の頂点v, vの親p, 現在の距離d)
void dfs(int v, int p, ll d){
    depth[v] = d;
    for(auto &e : tree[v]){
        if(e.to == p){
            continue;
        }
        dfs(e.to, v, d+e.cost);
    }
}

int main(){
    int N;
    cin >> N;
    int a,b;
    long long c;
    for(int i = 0; i < N-1; i++){
        cin >> a >> b >> c;
        a--, b--;
        tree[a].push_back({b, c});
        tree[b].push_back({a, c});
    }

    int Q,K;
    cin >> Q >> K;
    K--;

    //先にkからの全ノードの最短経路を深さ優先探索で求めておく
    dfs(K, -1, 0);

    for(int i = 0; i < Q; i++){
        int x, y;
        cin >> x >> y;
        x--, y--;
        cout << depth[x] + depth[y] << endl;
    }

    return 0;
}


Measured memory_bytes: 14336
using System;

namespace AtCoderBeginnerContest143
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ab = Console.ReadLine().Split(' ');
            int a = int.Parse(ab[0]);
            int b = int.Parse(ab[1]);

            int c = a - 2 * b;
            if(c > 0)
            {
                Console.WriteLine(c);
            }
            else
            {
                Console.WriteLine(0);
            }

            //Console.ReadKey();

        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define ll long long int
#define __ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi acos(-1)
#define N 100005
#define mod 1000000007 
#define bitscount 32

using namespace std;


int  main()
{

int n,h,ans=0;

cin >> n >> h;

for(int v,i=0;i<n;i++){
cin >> v;

if(v>=h) ans ++ ;
}

cout << ans << endl;

return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int x,a,b;
  scanf("%d %d %d",&x,&a,&b);
  
  if(a>=b){
    printf("delicious");
  } else if(a<b && (b-a)<=x){
    printf("safe");
  } else {
    printf("dangerous");
  }
}
         


Measured memory_bytes: 128
N, K = map(int, input().split())
X = list(map(int, input().split()))

if 0 in X:
    i = X.index(0)
    del X[i]
    N -= 1
    K -= 1

C=N
for i, x in enumerate(X):
    if x >= 0:
        C = i
        break

A = []

if K == 0:
    print(0)
else:
    if C>=K:
        A.append(-X[C-K])
        # print(-X[C-K])
    if N-C>=K:
        A.append(X[C+K-1])
        # print(X[C+K-1])
    for k in range(max(C+K-N, 1), min(C+1, K)):
        A.append(-2*X[C-k] + X[C-k-1+K])
        # print(X[C-k], X[C-k-1+K], -2*X[C-k] + X[C-k-1+K])
    for k in range(max(K-C, 1), min(N-C+1,K)):
        A.append(2*X[C+k-1] - X[C+k-K])
        # print(X[C+k-1], X[C+k-K], 2*X[C+k-1] - X[C+k-K])
    print(min(A))

Measured memory_bytes: 14480
n = int(input())
m=list(map(int,input().split()))
m.sort(reverse=True)
k=0
for i in range((n+1)//2-1):
    k+=m[i]

for i in range(1,(n+1)//2):
    k+=m[i]

if n%2==0:
    k+=m[(n+1)//2-1]
print(k)

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

void fnInput(string& rsStr)
{
  cin >> rsStr;
}

string fnOddString(string sStr)
{
  string sOddStr = "";
  for (int i = 0; i < sStr.size(); i++)
    if (i % 2 == 0) sOddStr += sStr[i];

  return sOddStr;
}

int main()
{
  string sStr;

  fnInput(sStr);
  cout << fnOddString(sStr) << endl;

  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

long int M = 1e+9+7;
int main(void){
    string s;
    cin >> s;
    if(s == "ABC"){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <iostream>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
template <class T>
void setmax(T &a, T const &b) {
    if (a < b) a = b;
}

template <class T>
void setmin(T &a, T const &b) {
    if (a > b) a = b;
}

template <typename T, typename X>
auto vectors(T a, X x) { return vector<T>(x, a); }

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
    auto cont = vectors(a, y, zs...);
    return vector<decltype(cont)>(x, cont);
}

int main() {
    long long X, K, D;
    cin >> X >> K >> D;
    if (X < 0) X *= -1LL;
    long long K1 = K - X / D;
    if (K1 < 0) {
        cout << X - K * D << endl;
        return 0;
    }
    X %= D;
    if (K1 % 2 == 0) {
        cout << X << endl;
    } else {
        cout << abs(X - D) << endl;
    }
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int n,m,x;
int main()
{
	cin>>n>>m;
	while(m--)
	{
		cin>>x;
		n-=x;
	}
	if(n<0)cout<<"-1\n";
	else cout<<n<<"\n";
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

s64 update_score(const set<int>& last, int day, int prev, int c, int max_d)
{
    s64 ret = 0;
    auto itr = last.upper_bound(day);
    int l, r;
    if (itr == last.end())
    {
        r = max_d + 1;
        l = *--itr;
    }
    else
    {
        r = *itr;
        l = *--itr;
    }
    ret -= (s64)((day - prev) + (r - 1 - prev)) * (r - day) / 2;
    ret += (s64)((day - l) + (r - 1 - l)) * (r - day) / 2;

    return c * ret;
}

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

    const int DAY = 365;
    const int NUM = 26;
    int d;
    cin >> d;
    int c[NUM];
    rep (i, NUM)
    {
        cin >> c[i];
        c[i] = -c[i];
    }

    int s[DAY][NUM];
    rep (i, d) rep (j, NUM) cin >> s[i][j];

    set<int> last[NUM];
    rep (i, NUM) last[i].insert(0);

    int t[DAY];
    rep (i, d)
    {
        cin >> t[i];
        --t[i];
    }

    s64 v = 0;
    rep (i, d)
    {
        v += s[i][t[i]];
        last[t[i]].insert(i + 1);
        rep (j, NUM)
        {
            v += c[j] * ((i + 1) - *last[j].rbegin());
        }
    }

    int m;
    cin >> m;

    s64 ans[m];
    rep (ii, m)
    {
        int dd, q;
        cin >> dd >> q;
        --q;
        int p = t[dd - 1];
        t[dd - 1] = q;
        v += s[dd - 1][q] - s[dd - 1][p];

        last[p].erase(dd);
        last[q].insert(dd);
        auto itr = last[q].lower_bound(dd);
        int prevq = *--itr;

        v += update_score(last[p], dd, dd, c[p], d);
        v += update_score(last[q], dd, prevq, c[q], d);
        ans[ii] = v;
    }

    rep (i, m)
    {
        cout << ans[i] << "\n";
    }

    return 0;
}



Measured memory_bytes: 4372
#include <iostream>
#include <algorithm>
#include <cmath>

int main(void){
    int A, B, C, X, Y, min_p, d, ans=0;
    std::cin >> A >> B >> C >> X >> Y;

    min_p = std::min(X, Y);
    d = X - Y;

    if (A + B > 2 * C){
        ans += C * min_p * 2;
    } else {
        ans += (A + B) * min_p;
    }

    if (d > 0){
        if (A > 2 * C){
            ans += 2 * C * d;
        } else {
            ans += A * d;
        }
    } else if (d < 0){
        if (B > 2 * C){
            ans += 2 * C * -d;
        } else {
            ans += B * -d;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3592
d = '2 7 4'
d = input()
d = input()
d = [int(i) for i in d.split()]
d.sort()
s1 = 0
s2 = 0
i = len(d)-1
while(i>=0):
    s1 = s1 + d[i]
    if((i-1)>=0):
        s2 = s2 + d[i-1]
    i = i-2
print(s1-s2)




Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<functional>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll a,b,ans=0;
    cin>>a>>b;
    ans=min(a,b/2);
    b-=a*2;
    if(b>0) ans+=b/4;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
//AUTHOR - NAVEEN KUMAR(@naveen19991124)
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#inlcude<boost/multiprecision/cpp_dec_float.hpp>
#define ll long long
#define pb push_back
#define f(a) for(ll i = 0;i<a;i++)
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define rrep(i,a,b) for(ll i = a;i>b;i--)
#define v vector<ll>
#define mp make_pair
#define fir first
#define sec second
#define _fast_ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
//using boost :: multiprecision :: cpp_int;
//using boost :: multiprecision :: cpp_dec_float_50;
//using boost :: multiprecision :: cpp_dec_float_100;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}

ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1;
a *= a; a %= mod;} return p % mod;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
int main()
{
    _fast_
    ll t = 1;
  //  cin>>t;
    while(t--){
    string s;
    cin>>s;
    if(s[0] == 'A')
    {
        if(s[1] == 'B' || s[2] == 'B')
        {
            cout<<"Yes\n";
        }
        else
        {
            {cout<<"No\n";}
        }
        
    }
    else if(s[1] == 'A')
    {
        if(s[0] == 'B' || s[2] == 'B')
        {
            cout<<"Yes\n";
        }
        else
        {
            cout<<"No\n";
        }
        
    }
    else if(s[2] == 'A')
    {
        if(s[0] == 'B' ||s[1] == 'B')
        {
            cout<<"Yes\n";
        }
        else
        {
            cout<<"No\n";
        }
        
    }
    else
    {
        cout<<"No\n";
    }
    
    }
    return 0;
}

Measured memory_bytes: 256
from sys import stdin

L, R = [int(x) for x in stdin.readline().rstrip().split()]

A = [(L + x) % 2019 for x in range(min(2019, R - L + 1))]
A.sort()

ans = 10 ** 8
for l in range(len(A) - 1):
    for m in range(l + 1, len(A)):
        if (A[l] * A[m]) % 2019 < ans:
            ans = (A[l] * A[m]) % 2019

print(ans)


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

typedef long long int lli;
#define int lli
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<lli> vli;
typedef vector<pii> vii;

const int MOD   = 1e9 + 7;
const double PI = acos(-1.0);
const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};
const int INF   = 1e18;

#define fastio            ios_base::sync_with_stdio(false);cin.tie(0)
#define sz(a) int((a).size())
#define rsz resize
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define f first
#define s second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define endl "\n"
#define spc " "
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }

void solve(){

    int n, x;
    cin >> x >> n;
    vi a(n);
    rep(i, n){
        cin >> a[i];
    }
    set<int> s(all(a));
    int ans = 0;
    rep(num, 200){
        if(!present(s, num)){
            if(abs(num - x) < abs(ans - x)){
                ans = num;
            }

        }
    }
    cout << ans << endl;


}

signed main(){
    fastio;

    solve();

    return 0;
}


Measured memory_bytes: 3584
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	try {
    		final int N = sc.nextInt();
    		String [] A = new String[N];
    		for (int i=0; i<N; i++) {
    			A[i] = sc.next();
    		}

    		HashMap<String, Integer> map = new HashMap<>();

    		for (int i=0; i<N; i++) {
    			if (map.containsKey(A[i])) {
    				int count = map.get(A[i]);
    				count++;
    				map.put(A[i], count);
    			} else {
    				map.put(A[i], 1);
    			}
    		}

    		int maxCount = 0;
    		ArrayList<String> list = new ArrayList<>();
    		Iterator<String> it = map.keySet().iterator();
    		while (it.hasNext()) {
    			String s = it.next();
    			int count = map.get(s);
    			if (maxCount < count) {
    				list.clear();
    				list.add(s);
    				maxCount = count;
    			} else if (maxCount == count) {
    				list.add(s);
    			}
    		}

    		Collections.sort(list);
    		for(String s: list) {
    			System.out.println(s);
    		}

    	} finally {
    		sc.close();
    	}
    }
}


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

public class Hello{
    public static void Main(){
        var num = int.Parse(Console.ReadLine());
        var a = ReadList();
        var b = ReadList();
        var c = ReadList();
        
        c.Add(0);
        
        int satisfy = 0;
        int before = 10000;
        for(int i = 0; i < num; i++){
            satisfy += b[a[i] - 1];
            
            if(before == a[i] -1){
                satisfy += c[a[i] - 2];
            }
            
            before = a[i];
        }
        
        Console.WriteLine(satisfy);
    }
    
    public static List<int> ReadList(){
        var a_text = Console.ReadLine().Split(' ');
        return a_text.Select(x => int.Parse(x)).ToList(); 
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main()
{
    int q, l, r;
    cin >> q;
    lli s[100015] = {};
    bool p[100015] = {};
    p[2] = false;
    p[1] = true;
    for (int i = 2; i < 100005; i++) {
        if (!p[i])
            for (int j = 2 * i; j < 100005; j += i) {
                p[j] = true;
            }
    }
    int sum = 0;

    rep(i, 100010)
    {
        if (i & 1 and !p[i] and !p[(i + 1) / 2]) {
            sum++;
        }
        s[i] = sum;
    }
    rep(i, q)
    {
        cin >> l >> r;
        cout << s[r] - s[l - 1] << endl;
    }
}


Measured memory_bytes: 1536
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const ll INF = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}
ll ar[40];
int memo[1001][1001];
int revm[1001];
int rev(int x) {


	int &res = revm[x];
	if (~res) return res;
	res = 0;
	while (x > 0)
	{
		res *= 10;
		res += x % 10;
		x /= 10;
	}
	return res;
}
int rec(int n, int m) {

	int &res = memo[n][m];
	if (~res) return res;
	if (n == 0 || m == 0) return 0;
	memo[n][m] = 1;
	int nex = n;
	int ney = m;
	if (nex < ney) {
		nex = rev(nex);
	}
	else ney = rev(ney);

	if (nex < ney) {
		ney -= nex;
	}
	else nex -= ney;
	return res = rec(nex, ney);
}
int ok[301][301];
bool use[301][301];
void solv() {
	ll n;
	cin >> n;
	string tb[301];
	for (size_t i = 0; i < n; i++)
	{
		for (size_t j = 0; j < n; j++)
		{
			ok[i][j] = 1;
		}
	}
	for (size_t i = 0; i < n; i++)
	{
		cin >> tb[i];
	}

	int res = n * n;
	for (size_t i = 0; i < n; i++)
	{
		for (size_t j = 0; j < n; j++)
		{
			for (size_t k = 1; k + i < n; k++)
			{
				int nx = i + k;
				int ny = ((j + n) - k) % n;
				if (tb[i][j] != tb[nx][ny]) {

					for (size_t t = 0; t < n; t++)
					{
						int ndy = (k + t) % n;
						int dx = ((t + n) - i) % n;
						int dy = ((ndy + n) - j) % n;
						if (dx == 0 && dy == 1) {
							cout << endl;
						}
						if (!ok[dx][dy]) break;
						ok[dx][dy] = false;
						res--;
					}
				}
			}
		}
	}

	cout << res << endl;
}




int main() {
	solv();

	return 0;
}


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

typedef long long ll;

int main()
{
	ll n;
	scanf("%lld",&n);
	int ans;
	if(n!=2){
		ans = 2;
	}
	else{
		ans = 1;
	}
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			ll cur = n;
			while(cur%i==0){
				cur /= i;
			}
			if((cur-1)%i==0){
				ans++;
			}
			if(n/i!=i){
				cur = n;
				ll div = n/i;
				while(cur%div==0){
					cur /= div;
				}
				if((cur-1)%div==0){
					ans++;
				}
			}
		}
	}
	//printf("%d\n",ans);
	for(ll i=2;i*i<=n-1;i++){
		if((n-1)%i==0){
			ans++;
			if((n-1)/i!=i){
				ans++;
			}
		}
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 3756
N = int(input())
As = [int(s) for s in input().split(' ')]
count_minus = len([a for a in As if a < 0])
As2 = [abs(a) for a in As]
As2.sort()
ret = sum(As2)

if count_minus % 2 == 1:
    ret -= As2[0] * 2

print(ret)


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

int main() {
 int A,B,C,K;
 cin >>A>>B>>C>>K;
  
  if(A > K){
    cout << K << endl;
  }  
  else if(A+B >= K){
    cout << A <<endl;
  }
  else{
    cout << A -(K-A-B) << endl;
  }
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef unsigned long long ll;

int main()
{
	ll a, b, c, x, y;
	ll ans = 0;
	cin >> a >> b >> c >> x >> y;
	if (a + b > 2 * c) {
		ll temp = min(x, y);
		x -= temp; y -= temp;
		ans += (temp*c * 2);
		if (a > 2 * c) {
			ans += (x * 2 * c);
		}
		else
			ans += (x*a);
		if (b > 2 * c) {
			ans += (y * 2 * c);
		}
		else
			ans += (b*y);
	}
	else {
		ans += (a*x + b*y);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define FASTIO() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int n;
string s;

bool Is_Pali(const string& p) {
  string r = p;
  reverse(begin(r), end(r));
  return r == p;
}

bool Solve() {
  if (!Is_Pali(s))
    return 0;
  if (!Is_Pali(s.substr(0, s.length() / 2)))
    return 0;
  if (!Is_Pali(s.substr(s.length() / 2 + 1)))
    return 0;

  return 1;
}

void Process() {
  if (Solve())
    cout << "Yes\n";
  else
    cout << "No\n";
}

int main() {
  FASTIO();

  while (cin >> s) {
    Process();

    if (cin.eof())
      break;
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n,p,box,turn;
		int[] stone;
		
		
		while(true){
			n=sc.nextInt(); //????£??????°
			p=sc.nextInt(); //?°????????????°
			if(n==0&&p==0){break;}
			stone= new int[n];
			for(int i=0;i<n;i++){stone[i]=0;}
			box=p;
			turn=0;
			
			while(true){
				if(turn==n){turn=0;}
				if(box==0){
					box=stone[turn];
					stone[turn]=0;
				}else{
					stone[turn]++;
					box--;
				}
				if(stone[turn]==p){break;}
				turn++;
			}
			System.out.println(turn);
		}
	}
}

Measured memory_bytes: 20404
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::cmp::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    }
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
macro_rules! chmax {
    ($x:expr, $e:expr) => {
        $x = max($x, $e);
    };
}
macro_rules! chmin {
    ($x:expr, $e:expr) => {
        $x = min($x, $e);
    };
}

const INF: i64 = 1 << 60;

fn main() {
    input!{
        N: usize,
        M: usize,
        xy: [(usize, usize); M],
    }
    let mut graph = vec![Vec::new(); N + 10];
    let mut deg = vec![0; N + 10];
    for i in 0..M {
        let (x, y) = xy[i];
        graph[x].push(y);
        deg[y] += 1;
    }
    let mut stack = Vec::new();
    for i in 1..(N+1) {
        if deg[i] == 0 {
            stack.push(i);
        }
    }
    let mut sorted_nodes = Vec::new();
    while let Some(i) = stack.pop() {
        sorted_nodes.push(i);
        for &j in &graph[i] {
            deg[j] -= 1;
            if deg[j] == 0 {
                stack.push(j);
            }
        }
    }
    let mut dp = vec![0; N+10];
    for &i in &sorted_nodes {
        for &ni in &graph[i] {
            chmax!(dp[ni], dp[i] + 1);
        }
    }
    let mut ans = 0;
    for i in 1..(N+1) {
        chmax!(ans, dp[i]);
    }
    println!("{}", ans);
}


Measured memory_bytes: 16636
#include <stdio.h>
#include <string.h>
int main(){
    char s[11], t[1001];
    int cnt=0;
    scanf("%s", s);
    do{
        scanf("%s", t);
        if(strcmp(t, "END_OF_TEXT")!=0){
            for (int i = 0; i < strlen(t); i++)
            {
                if(t[i]>='A'&&t[i]<='Z'){
                    t[i]+=32;
                }
            }
            // printf("%s\n", t);
            if(strcmp(s, t)==0)cnt++;
        }
    }while(strcmp(t, "END_OF_TEXT")!=0);
    printf("%d\n", cnt);
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))




int main(){
	
	ll a;
	string s;
	cin >> a >> s;
	if(a>=3200){
		cout << s << endl;
	}else{
		cout << "red" << endl;
	}
}


Measured memory_bytes: 256