akhauriyash/Code-Regression huggingface dataset:
from collections import deque
MAX = float('inf')
S = input()
points = [MAX] * (len(S) + 1)
idxs = []
comp = [[] for _ in range(len(S) + 1)]
if S[0] == '<':
    points[0] = 0
    idxs.append(0)
if S[-1] == '>':
    points[-1] = 0
    idxs.append(len(S))
for idx, s in enumerate(S):
    if s == '<': comp[idx].append(idx + 1)
    else: comp[idx + 1].append(idx)
    if idx == 0 or idx == len(S): continue
    if S[idx - 1] == '>' and s == '<':
        points[idx] = 0
        idxs.append(idx)
stack = deque(idxs)
while stack:
    idx = stack.pop()
    for i in comp[idx]:
        points[i] = max(points[i], points[idx] + 1) if points[i] != MAX else points[idx] + 1
        stack.append(i)
print(sum(points))

Measured memory_bytes: 122084
def F(S):
    if len(S) ==1:
        return S[0]
    else:
        S1 = [(10*S[0]+S[1])]+S[2:]
        S2 = S[1:]
        return F(S1)+F(S2)+S[0]*(2**(len(S)-2))

s = input()
x = [int(s[i]) for i in range(len(s))]
print(F(x))


Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cmath>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

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



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

int divisable(int acc, int N) {
  if (N % 2 != 0) {
    return acc;
  }
  divisable(acc + 1, N / 2); 
}

int main() {
  int N;
  cin >> N;
  
  int count = 0;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (i == 0) {
      count = divisable(0, x);
    } else {
      count = min(count, divisable(0, x));
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        d: i64,
        xys: [(i64,i64);n]
    }
    let mut cnt = 0;
    for (x,y) in xys {
        let b = x.pow(2) + y.pow(2);
        if b <= d.pow(2) {
            cnt += 1;
        }
    }
    println!("{}", cnt);
}


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

#define times(n, i)      uptil(0, n, i)
#define rtimes(n, i)     downto((n) - 1, 0, i)
#define upto(f, t, i)    for(int _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(int _##i = (t), i = (f); i <  _##i; i++)
#define downto(f, t, i)  for(int _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(int _##i = (t), i = (f); i >  _##i; i--)
typedef long double ld;
#define long long long

#if defined(EBUG) && !defined(ONLINE_JUDGE)
    #define debug true
    #define ln << endl
#else
    #define debug false
    #define ln << '\n'
#endif
#define tb << '\t'
#define sp << ' '

const long MOD = 1e9 + 7;

long X[100000], Y[100000];

signed main() { // long: 64bit
    if(!debug) {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }

    int N, M;
    scanf("%d%d",&N,&M);

    times(N, i) scanf("%lld", X+i);
    times(M, j) scanf("%lld", Y+j);

    long x = 0, y = 0;

    uptil(1, N, i) {
        x += (X[i] - X[i-1]) * i % MOD * (N - i) % MOD;
        if(debug) cout << (X[i] - X[i-1]) * i * (N - i) ln;
        x %= MOD;
    }
    uptil(1, M, j) {
        y += (Y[j] - Y[j-1]) * j % MOD * (M - j) % MOD;
        if(debug) cout << (Y[j] - Y[j-1]) * j * (M - j) ln;
        y %= MOD;
    }

    cout << x * y % MOD ln;

    return 0;
}


Measured memory_bytes: 1792
c,d,t,u;
long s;
char x[18];
main()
{
	c=getchar_unlocked();
	while(c!=10)
	{
		t+=1;
		d=getchar_unlocked();
		if(c!=d)
		{
			s+=(long)t*(t+1)/2;
			if(c=='>')s-=t<u?t:u;
			u=t;
			t=0;
			c=d;
		}
	}
	t=17;
	do{
		x[--t]=s%10+'0';
		s/=10;
	}while(s);
	write(1,x+t,17-t);
}

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

int main()
{
    string a,b;
    cin>>a;
    for(int s=1;s<a.size();s++)
    {
        if(a[s]==a[s-1])
        {
            cout<<s<<" "<<s+1<<endl;
            return 0;
        }
    }
    for(int s=2;s<a.size();s++)
    {
        if(a[s]==a[s-2])
        {
            cout<<s-1<<" "<<s+1<<endl;
            return 0;
        }
    }
    cout<<-1<<" "<<-1<<endl;
    return 0;
}

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

int main(void) {
    int N;
    cin >> N;
    string S;
    cin >> S;
    if (N % 2 != 0) {
        printf("No\n");
    } else {
        bool flag = true;
        for (int i = 0; i < N / 2; ++i) {
            if (S[i] != S[i + (N / 2)]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            printf("Yes\n");
        } else {
            printf("No\n");
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main(void){
    int n, q, head = 0, ima = 0 ;
    cin >> n >> q;
    int tail = n - 1;
    string name;
    int time;
    string na[1000000];
    int ti[1000000];
    for(int i = 0; i < n; i++){
        cin >> name >> time;
        na[i] = name;
        ti[i] = time;
        
    }
    
    /*
    for(int i = 0; i < n; i++){
        cout << na[i] << " " << ti[i] << endl;
    }
    */
    while(ti[head] != 0){
        if(1 <= ti[head] and ti[head] <= q){
            ima += ti[head];
            cout << na[head] << " " << ima << endl;
            head++;
        } else {
            tail++;
            ima += q;
            na[tail] = na[head];
            ti[tail] = ti[head] - q;
            head++;
        }
    }
    
    return 0;
}



Measured memory_bytes: 14044
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());


int main() {
    string S;
    cin >> S;

    int N = S.size();

    string WB;
    string BW;

    rep(i, N) {
        WB.push_back('0');
        WB.push_back('1');
        BW.push_back('1');
        BW.push_back('0');
    }

    int cou1 = 0, cou2 = 0;
    rep(i, N) {
        if (S[i] == WB[i])cou1++;
        if (S[i] == BW[i])cou2++;
    }
    int ans = N - max(cou1, cou2);
    cout << ans << endl;
}

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

typedef pair<int,int> P;

int n, m;
int a[14], b[14];
P dp[1 << 14];

void dfs(int idx, int bit, int rem, int sum, int now){
  if(idx == n){
    rem += sum;
    if(dp[now].first + 1 < dp[bit].first ||
       dp[now].first + 1 == dp[bit].first && dp[bit].second < rem){
      dp[bit] = P(dp[now].first + 1, rem);
    }
    return;
  }

  dfs(idx + 1, bit, rem, sum, now);

  if(!(bit & (1 << idx)) && b[idx] <= rem){
    dfs(idx + 1, bit | (1 << idx), rem - b[idx], sum + a[idx], now);
  }
}

void solve(){
  int to = 1 << n;

  for(int i = 0; i < to; i++){
    dp[i] = P(INT_MAX, INT_MAX);
  }

  dp[0] = P(0, m);

  for(int i = 0; i < to; i++){
    if(dp[i] == P(INT_MAX, INT_MAX)) continue;
    dfs(0, i, dp[i].second, 0, i);
  }

  int ans = dp[to - 1].first;

  if(ans == INT_MAX){
    cout << "Impossible\n";
  }
  else{
    cout << ans << endl;
  }
}

int main(){
  while(cin >> n >> m, n || m){
    for(int i = 0; i < n; i++){
      cin >> a[i] >> b[i];
    }
    solve();
  }
}

Measured memory_bytes: 996
#include <stdio.h>

int main(){
  int n,i,j,min,tmp,num,a[100];
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  for(i=0;i<n-1;i++){
    for(j=n-1;j>0;j--){
      if(a[j]<a[j-1]){
	tmp=a[j-1];
	a[j-1]=a[j];
	a[j]=tmp;
	num++;
      }
    }
  }

  for(i=0;i<n;i++){
    if(i<n-1) printf("%d ",a[i]);
    else printf("%d\n",a[i]);
  }

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

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define cyes cout << "YES" << endl
#define cno cout << "NO" << endl
#define f(i, a, n) for(int i = a; i < n; i++)
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mod 1000000007
int gcd(int a, int b) { if (!b) return a; return gcd(b, a % b); }  
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
using namespace std;

int32_t main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

  int n;cin >> n;
  if(n%1000!=0)
    cout << 1000 - n%1000;
  else
    cout << 0;

}

Measured memory_bytes: 3620
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            line.pop();
            line
        }
    )
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let iter = line.split_whitespace();
            iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    )
}


fn solve(aa: Vec<i64>) -> usize {
    use std::collections::HashMap;

    let mut hm = HashMap::new();
    let mut acc = 0;
    for a in aa {
        acc += a;
        let el = hm.entry(acc).or_insert(0);
        *el += 1;
    }

    let mut cnt = 0;
    for (k,v) in hm {
        cnt += (v * (v-1)) / 2;
        if k == 0 {
            cnt += v;
        }
    }

    cnt
}

fn main() {
    read_line!();

    println!("{}", solve(parse_vec!(i64)));
}

#[test]
fn solve_test() {
    assert_eq!(solve(vec![1,3,-4,2,2,-2]), 3);
    assert_eq!(solve(vec![1,-1,1,-1,1,-1,1]), 12);
    assert_eq!(solve(vec![1,-2,3,-4,5]), 0);
}


Measured memory_bytes: 18064
package main

import "fmt"

func main() {
	var h, w int
	for {
		fmt.Scanln(&h, &w)
		if h == 0 && w == 0 {
			break
		}
		for i := 1; i <= h; i++ {
			for j := 1; j <= w; j++ {
				fmt.Print("#")
			}
			fmt.Println("")
		}
		fmt.Println("")
	}
}


Measured memory_bytes: 1124
#include <stdio.h>
int main(){
    int x[3000],y[3000],i;
    for (i=0;i<3000;i++){
        scanf("%d%d", &x[i], &y[i]);
        if (x[i] == 0 && y[i] == 0){
            break;
        }
    }
    for (i=0;i<3000;i++){
        if (x[i] == 0 && y[i] == 0){
            break;
        }
        else {
            (x[i]<y[i])? printf("%d %d\n", x[i], y[i]):printf("%d %d\n", y[i], x[i]);
        }
    }
}

Measured memory_bytes: 620
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))

if sum(A)<sum(B):
	print(-1)
	exit(0)


C_less=[]
C_more=[]

for i in range(N):
	if A[i]==B[i]:
		continue
	else:
		if A[i]<B[i]:
			C_less.append(abs(A[i]-B[i]))
		if A[i]>B[i]:
			C_more.append(abs(A[i]-B[i]))

C_more2=list(sorted(C_more, reverse=True))
# print(C_less)
# print(C_more2)
ans=len(C_less)
s=sum(C_less)
if s==0:
	print(0)
	exit(0)
# print(s)
s_m=0
for i in range(len(C_more2)):
	s_m+=C_more2[i]
	# print(i,s_m)
	if s_m>=s:
		d=i+1
		break
print(ans+d)
		



Measured memory_bytes: 18356
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define MAX 101000
#define MOD 1000000007
void add(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int s[50];
int n;char ch[MAX];
int main()
{
	scanf("%d",&n);scanf("%s",ch+1);
	for(int i=1;i<=n;++i)s[ch[i]-97]+=1;
	int ans=1;
	for(int i=0;i<26;++i)ans=1ll*ans*(s[i]+1)%MOD;;
	add(ans,MOD-1);
	printf("%d\n",ans);
	return 0;
}


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

int main() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    
    int sum_min=0;
    
    if(a<b) sum_min +=a;
    else    sum_min +=b;

    if(c<d) sum_min +=c;
    else    sum_min +=d;
    
    cout<<sum_min<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int MAXN = 100008;
long long a[MAXN];
struct BC
{
    long long b, c;
};
BC bc[MAXN];

int n, m;
long long sum=0;

bool cmp(BC x, BC y)
{
    return x.c > y.c;
}

int main()
{
    //freopen("1.in", "r", stdin);
    //freopen("1.out", "w", stdout);
    
    scanf("%d%d", &n, &m);
    int i, j, cnt;
    for(i = 1; i <= n; i++)
        scanf("%lld", &a[i]);
        
    for(i = 1; i <= m; i++)
        scanf("%lld%lld", &bc[i].b, &bc[i].c);
    
    sort(a+1, a+n+1); //small to big
    sort(bc+1, bc+m+1, cmp);
    
    i = n;
    j = 1;
    cnt = 0;
    
    while(cnt < n)
    {
        if(i >= 1 && j <= m)
        {
            if(a[i] >= bc[j].c)
            {
                sum = sum + a[i];
                i--;
                cnt++;
            }
            else
            {
                if(n - cnt >= bc[j].b)
                {
                    sum = sum + bc[j].c * bc[j].b;
                    cnt = cnt + bc[j].b;
                    j++;
                }
                else
                {
                    sum = sum + bc[j].c * (n - cnt);
                    bc[j].b = bc[j].b - (n - cnt);
                    cnt = n;
                }
            }
        }
        else
        {
            while(cnt < n)
            {
                sum = sum + a[i];
                i--;
                cnt++;
            }
        }
    }

    cout << sum;

    return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		
		int h = S / 3600;
		int m = S % 3600 / 60;
		int s = S % 3600 % 60;
		
		
		System.out.println(h + ":" + m + ":" + s);
	}
}


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

int main(){
        long long n,i,tmp;
        cin >> n;
        vector<long long> a(n);
        for(i=0;i<n;++i){
                cin >> tmp;
                a.at(tmp-1) = i+1;
        }
        for(i=0;i<n;++i) cout << a.at(i) << " ";
        cout << endl;
        return 0;
}

Measured memory_bytes: 3988
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int maxCnt = 0;
		int maxNum = 1;
		for (int i = 1; i <= n; i++) {
			int cnt = 0;
			int num = i;
			while (num % 2 == 0) {
				cnt++;
				num /= 2;
			}
			
			if (cnt > maxCnt) {
				maxCnt = cnt;
				maxNum = i;
			}
		}
		
		System.out.println(maxNum);
		
		sc.close();
	}
}




Measured memory_bytes: 27068
#include <cstdio>

int main()
{
  int n;
  scanf("%d", &n);
  int ans = 1e9;
  for (int i = 0; i <= n; ++i)
  {
    int c = 0;
    for (int j = i; j > 0; j /= 6)
    {
      c += j % 6;
    }
    for (int j = n - i; j > 0; j /= 9)
    {
      c+= j % 9;
    }
    if (c < ans) ans = c;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#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 RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> fri(100003,0);
  int first,end,max_friend=0;
  REP(i,n){
    cin >> first >> end;
    fri[first]++;
    fri[end+1]--;
  }

  for(int i = 1;i<100003;i++){
    fri[i] +=fri[i-1];
    if(fri[i]  >= i-1)
      max_friend = max(i-1,max_friend);
  }
  cout << max_friend << endl;
  
  return 0;
}

Measured memory_bytes: 3096
#include <stdio.h>

int main(void) {
    int i, c1, c2, c3, yes, no, point;
    while(scanf("%d",&c1) != EOF ) {
        scanf("%d %d",&c2,&c3);
        point = c1 + c2;
        yes = 0; no = 0;
        for(i = 1; i < 11; i++ ) {
            if(i == c1 || i == c2 || i == c3 ) {
                continue;
            }
            if(point + i > 20) {
                no++;
            } else {
                yes++;
            }
        }
        if(yes > no) {
            puts("YES");
        } else {
            puts("NO");
        }
    }
    return 0;
}

Measured memory_bytes: 580
#include<stdio.h>
#include<stdlib.h>
 
 
long long X[ 100 ][ 2 ] ,x[ 100 ] ;
long long Y[ 100 ][ 2 ] ,y[ 100 ] ;
long long Z[ 100 ][ 2 ] ,z[ 100 ] ;
 
int i ,j ,k ,l ;
 
inline void sort( long long *a ,int size )
{
    qsort( a ,size ,sizeof( long long ) ,[]( const void *a ,const void *b ){ return *( int* )a - *( int* )b ; } ) ;
}
 
int check()
{
    if(
            X[ l ][ 0 ] > x[ i ] || X[ l ][ 1 ] < x[ i + 1 ] ||
            Y[ l ][ 0 ] > y[ j ] || Y[ l ][ 1 ] < y[ j + 1 ] ||
            Z[ l ][ 0 ] > z[ k ] || Z[ l ][ 1 ] < z[ k + 1 ]
    )
    {
        return 1 ;
    }
 
    return 0 ;
}
 
int main( void )
{
    int N ,K ;
    scanf( "%d %d" ,&N ,&K ) ;
 
    N *= 2 ;
 
    --K ;
 
    int n = N - 1 ;
 
    for( i = 0 ; i < N ; ++i )
    {
        scanf( "%lld %lld %lld" ,x + i ,y + i ,z + i ) ;
 
        X[ i / 2 ][ i % 2 ] = x[ i ] ;
        Y[ i / 2 ][ i % 2 ] = y[ i ] ;
        Z[ i / 2 ][ i % 2 ] = z[ i ] ;
    }
 
    sort( x ,N ) ;
    sort( y ,N ) ;
    sort( z ,N ) ;

	N /= 2 ;
 
    long long ans = 0 ;
    for( i = 0 ; i < n ; ++i )
    {
        for( j = 0 ; j < n ; ++j )
        {
            for( k = 0 ; k < n ; ++k )
            {
                int cnt = 0 ;
 
                for( l = 0 ; l < N ; ++l )
                {
                    if( check() == 0 )
                    {
                        ++cnt ;
                    }
                }
 
                if( cnt > K )
                {
                    ans += ( x[ i + 1 ] - x[ i ] ) * ( y[ j + 1 ] - y[ j ] ) * ( z[ k + 1 ] - z[ k ] ) ;
                }
            }
        }
    }
 
 
    printf( "%lld\n" ,ans ) ;
 
    return 0 ;
}


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

using namespace std;

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

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

ll H, W, N;
map<pii,ll> mp;
ll ans[10] = {};

void solve() {
    cin >> H >> W >> N;
    rep(i,N) {
        int a, b;
        cin >> a >> b;
        for (int j = a-1; j <= a+1; j++) {
            for (int k = b-1; k <= b+1; k++) {
                mp[pii(j, k)]++;
                //cout << mp[pii(j, k)] << endl;
            }
        }
    }
    ll sum = 0;
    for (auto p : mp) {
        int y = p.first.first;
        int x = p.first.second;
        int c = p.second;
        if (y >= 2 && y <= H-1 && x >= 2 && x <= W-1) {
            ans[c]++;
            sum++;
        }
    }
    ans[0] = (H-2) * (W-2) - sum;
    rep(i,10) cout << ans[i] << endl;
}

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


Measured memory_bytes: 56576
#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node { int p, l, r;};

Node T[MAX];
int n, D[MAX];

void print(int u) {
  int i,c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";

  if( T[u].p == NIL ) cout << "root, ";
  else if( T[u].l == NIL ) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";

  for(i=0, c=T[u].l; c!=NIL; i++,c=T[c].r) {
    if(i) cout <<", ";
    cout << c;
  }
  cout << "]" << endl;
}

void rec(int u, int p) {
  D[u] = p;
  if(T[u].r != NIL) rec(T[u].r,p);
  if(T[u].l != NIL) rec(T[u].l,p+1);
}

int main(void) {
  int i,j,d,v,c,l,r;
  cin >> n;
  for(i=0;i<n;i++) T[i].p = T[i].l = T[i].r = NIL;
  for(i=0;i<n;i++) {
    cin >> v >> d;
    for(j=0;j<d;j++) {
      cin >> c;
      if(j==0) T[v].l=c;
      else T[l].r =c;
      l = c;
      T[c].p = v;
    }
  }
  for(i=0;i<n;i++) {
    if(T[i].p == NIL) r = i;
  }
  
  rec(r,0);
  
  for(i=0;i<n;i++) print(i);
  
  return 0;
}


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

#define endl            "\n"
#define ll              long long
#define ld              long double 
#define ull             unsigned long long int
#define MOD             (ll)(1e9 + 7)
#define vll             vector<ll>
#define pll             pair<ll,ll>
#define mll             map<ll,ll>
#define vpll            vector<pair<ll,ll>>
#define mpll            map<pair<ll,ll>,ll>
#define len(x)          x.length()
#define all(x)          x.begin(),x.end()
#define deb1(x)         cout<<#x<<" "<<x<<endl;
#define deb2(x,y)       cout<<#x<<" "<<x<<"\t"<<#y<<" "<<y<<endl;
#define deb3(x,y,z)     cout<<#x<<" "<<x<<"\t"<<#y<<" "<<y<<"\t"<<#z<<" "<<z<<endl;
#define fr(a,b,c)       for(auto a=b;a<c;a++)
#define frc(a,b,c)      for(auto a=b;a!=c;a++)
#define pb(x)           push_back(x)
#define lb(v,x)         lower_bound(v.begin(), v.end(), x)
#define ub(v,x)         upper_bound(v.begin(), v.end(), x)
#define GR              (double)(1 + sqrt(5)) / 2
#define fib(n)          (ll)round(pow(GR,n) / sqrt(5))
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define out1(x)         cout<<x<<" "<<endl
#define out2(x,y)       cout<<x<<" "<<y<<endl
#define ARRAY(a,n)      vll a; fr(i,0,n) { ll temp; cin>>temp; a.pb(temp); }  
#define PRINT(a)        for(auto x:a)cout<<x<<" ";cout<<endl
#define MAX             100005
template<typename T>
void output_vector(const vector<T> &v, bool add_one = false, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = int(v.size());
 
    for (int i = start; i < end; i++)
        cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}


void solve(){
    int n,k;cin>>n;
    int a[n+1];int dp[n+1]={0};
    fr(i,1,n+1)cin>>a[i];
    dp[1]=0;
    dp[2]=abs(a[2]-a[1]);
    for(int i=3;i<=n;i++)
        dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
    cout<<dp[n]<<" ";
}

int main()
{   
    // #ifndef ONLINE_JUDGE 
    //     freopen("input.txt", "r", stdin); 
    //     freopen("output.txt", "w", stdout); 
    // #endif 
    // FIO;
    // ll test;cin>>test;
    // while(test--)
    solve();
    return 0;
}


Measured memory_bytes: 1024
#Atcoder ABC 122 C
n,q=gets.split.map{|u| u.to_i}
s=gets.chomp
lr=[]
q.times{
    l,r=gets.split.map{|u| u.to_i}
    lr.push([l-1,r-1])
}
data=[0]*(n+1)
if s[0..1]=="AC"
    data[0]=1
end
for i in 1...n-1
    if s[i..i+1]=="AC"
        data[i]+=1
    end
    data[i]+=data[i-1]
end
lr.each do |l,r|
    puts data[r-1]-data[l-1]
end

Measured memory_bytes: 11132
package main

import (
	"fmt"
)

func main() {
	var a, b, c, d, e int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)
	fmt.Scan(&e)

	ms := [5]int{a, b, c, d, e}
	mi, mm := 0, 10
	for i, m := range ms {
		k := m % 10
		if k == 0 {
			continue
		}
		if k < mm {
			mm = k
			mi = i
		}
	}
	for i := 0; i < 5; i++ {
		if i == mi || ms[i]%10 == 0 {
			continue
		}
		ms[i] = 10 * int((ms[i]+9)/10)
	}
	fmt.Println(ms[0] + ms[1] + ms[2] + ms[3] + ms[4])
}


Measured memory_bytes: 512
s=input()
t=input()
ans="UNRESTORABLE"
for i in range(len(s)-len(t)+1):
  flag=True
  for j in range(len(t)):
    if s[i+j]==t[j] or s[i+j]=="?":
      continue
    else:
      flag=False
  if flag:
    ans=s[:i]+t+s[i+len(t):]
    ans=ans.replace("?","a")
print(ans)



Measured memory_bytes: 3060
#include <iostream>
#include <cstdlib>
#include <math.h>
#include <algorithm>

int main()
{
    char a;
    char s[10];
    int x = 0, i = 0;
    while (std::cin >> a) {
        x += a-48;
        s[i++] = a;
    }
    if (std::stoi(s) % x == 0) std::cout << "Yes" << std::endl;
    else std::cout << "No" << std::endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define rep(i, n) for(int i = 0; i < n; i++)
#define repx(i, a, n) for(int i = a; i < n; i++) 
#define loop while(1)
#define lli long long int
#define aryout(ary) rep(i, ary.size()) cout << ary[i] << (i < ary.size() - 1 ? " " : "\n");
#define arysort(v) sort(v.begin(), v.end()) 
#define aryreverse(v) reverse(v.begin(),v.end())
#define arysum(v) accumulate(v.begin(), v.end(), 0)

#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <utility>
#include <set>

using namespace std;

int main() {

  int n;
  cin >> n;

  string str;
  cin >> str;

  rep(i, str.size()) {
    str[i] += n;
    if (str[i] > 'Z') str[i] -= 26;
  }

  cout << str << endl;
  return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>

using namespace std;

int a[21];
int n;

int solve(int p, int s, int t)
{
  if(p == n) return abs(s-t);
  return min(solve(p+1, s+a[p], t), solve(p+1, s, t+a[p]));
}

int main()
{
  while(scanf("%d", &n)!=EOF && n != 0){
    for(int i = 0; i < n; ++i) scanf("%d", &a[i]);
    printf("%d\n", solve(0, 0, 0));
  }

  return 0;
}

Measured memory_bytes: 764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();
        long[] bb = sc.LongArray();

        List<long> bList = bb.ToList();
        List<long> answers = new List<long>();

        while (answers.Count != n)
        {
            long tmpAnswer = 0;
            for (int i = 0; i < bList.Count(); i++)
            {
                if (i + 1 == bList[i])
                {
                    tmpAnswer = Math.Max(i + 1, tmpAnswer);
                }
            }
            if (tmpAnswer == 0)
            {
                Console.WriteLine(-1);
                return;
            }
            answers.Add(tmpAnswer);
            bList.RemoveAt((int)(tmpAnswer - 1));
        }

        answers.Reverse();
        foreach (var answer in answers)
        {
            Console.WriteLine(answer);
        }
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

#pragma GCC optimize("O3")
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,n,N) for(ll i=n;i<=N;++i)
#define rap(i,n,N) for(ll i=n;i>=N;--i)
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define lc (id<<1)
#define rc ((id<<1)|1)
#define db(x) cout << ">>>>>> " << #x << " -> " << x << endl;
#define all(x) x.begin(),x.end()
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define piii pair<int,pii>
#define piiii pair<pii,pii>
#define psi pair<string,int>
#define endl "\n"
const int MAX = 3e5+5;
const ll MAX2 = 11;
const ll MOD = 1000000007;
const ll INF = 2e18;
const int dr[]={1,0,-1,0,1,1,-1,-1,0};
const int dc[]={0,1,0,-1,1,-1,1,-1,0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 450;

int n,k,cnt[128],ans,z;
priority_queue<int> pq;
stack<int> st;
string s;
set<string> cek;

int main(){
//	cout<<fixed<<setprecision(15);
//    freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n>>k;
    while(n--){
    	cin>>s;
    	auto it = cek.find(s);
    	if(it==cek.end()){
    		cek.insert(s);
    		cnt[s[0]]++;
		}
	}
	rep(i,'A','Z')if(cnt[i])pq.push(cnt[i]);
	while(pq.size()>=k){
		++ans;
		rep(i,1,k){
			z = pq.top(); pq.pop();
			z--;
			if(z)st.push(z);
		}
		while(!st.empty())pq.push(st.top()), st.pop();
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

struct Union_Find {
	vector<int> rank, par, size;
	int independent_tree;
	int N;

	Union_Find() = default;

	Union_Find(int n) {
		N = n;
		for (int i = 0; i < N; i++)rank.push_back(1), par.push_back(i), size.push_back(1);
		independent_tree = N;
	}

	void setsize(int n) {
		N = n;
		for (int i = 0; i < N; i++)rank.push_back(1), par.push_back(i);
		independent_tree = N;
	}

	int getroot(int X) {
		if (par[X] == X)return X;
		return par[X] = getroot(par[X]);
	}

	bool issame(int A, int B) {
		return getroot(A) == getroot(B);
	}

	void unite(int A, int B) {
		A = getroot(A), B = getroot(B);
		if (A == B)return;
		independent_tree--;
		if (rank[A] > rank[B]) {
			par[B] = A;
			size[A] += size[B];
		}
		else if (rank[A] == rank[B]) {
			par[B] = A;
			rank[A]++;
			size[A] += size[B];
		}
		else {
			par[A] = B;
			size[B] += size[A];
		}
	}

};

int n, m, k;
vector<vector<int>> E;

int main() {
	cin >> n >> m >> k;
	Union_Find uf(n);
	E.resize(n);
	for (int i = 0; i < m; i++) {
		int s, t;
		cin >> s >> t;
		s--, t--;
		E[s].push_back(t);
		E[t].push_back(s);
		if (!uf.issame(s, t))uf.unite(s, t);
	}

	vector<int> ans(n, 0);
	for (int i = 0; i < k; i++) {
		int s, t;
		cin >> s >> t;
		s--, t--;
		if (uf.issame(s, t))ans[s]--, ans[t]--;
	}
	for (int i = 0; i < n; i++) {
		ans[i] += uf.size[uf.getroot(i)];
		ans[i] -= E[i].size();
		ans[i]--;
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 8300
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define DEBUG2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << "\n"
#define DEBUG3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair<int, int>
#define ld long double
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int 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(10);
  int N;
  cin >> N;
  vec<int> a(N);
  vec<int> b(N);
  REP(i, N) {
    cin >> a[i];
    a[i]--;
    b[a[i]] = i;
  }
  set<int> q0;
  set<int, greater<int>> q1;
  q0.insert(-1);
  q0.insert(N);
  q1.insert(-1);
  q1.insert(N);

  int ans = 0;
  REP(i, N) {
    int pos = b[i];
    int val0 = *q0.upper_bound(pos);
    int val1 = *q1.upper_bound(pos);
    q0.insert(pos);
    q1.insert(pos);
    ans += (i + 1) * (val0 - pos) * (pos - val1);
  }
  print(ans);
}
/*
まだまだ書き慣れていないことが分かったことが収穫。
まず、2つの配列を用意するのはいいのだが、
その後のマイナスの値を代入するところでバグが発生した。
はじめにinsertするのは、-1とNで直感的ではない。
greaterをつけることで解決するので利用することにした。
*/

Measured memory_bytes: 22144
// IOI 2021
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
 
////////////////////////////////////////////////////////////////////
 
const int N = 1e5 + 5;

int X[N];

int main() {
 
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	mt19937 Rnd(time(0));

	int n, k; cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> X[i];
	int ans = INF;
	for (int l = 0; l + k <= n; l++)  {
		int r = l + k - 1;
		ans = min(ans, abs(X[l]- X[r]) + min(abs(X[l]), abs(X[r])));
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4000
#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;
bool isPrime(int);
int main(void){
    int n;
    cin>>n;
    int isPriNum=0;
    int num[10000];
    for(int i=0;i<n;++i){
        cin>>num[i];
        if(isPrime(num[i])) isPriNum++;
    }
    cout<<isPriNum<<endl;
    return 0;
}

bool isPrime(int n) {
    int i;
    for(i = 2; i <= sqrt(n); i++) {
        if((n % i) == 0) // 如果能被除了1和它本身的数整除，就不是素数
             return false;
    }
    return true; // 是素数
}




Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main(){
    int h, w, n;
    cin >> h >> w >> n;

    if(h>=w){
        dunk((h+n-1)/h);
    }
    if(h<w){
        dunk((w+n-1)/w);
    }
}

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

using namespace std;
const int maxn=2e5+5;
char s[maxn];
int n,a,b,c,d;
int flag,flag2,flag3,flag4;
int main()
{
    scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
    scanf("%s",s+1);
    for(int i=a; i<=max(c,d); i++)
    {
        if(s[i]=='#'&&s[i-1]=='#')
        {
            printf("No\n");
            return 0;
        }
    }
    if(d<c)
        flag=1;
    if(flag)
    {
        for(int i=b; i<=min(c,d); i++)
        {
            if(s[i]=='.'&&s[i-1]=='.')
            {
                if(i+1<=n)
                {
                    if(s[i+1]=='.')
                        flag2=1;
                }
                else
                    flag2=1;
            }
        }
        if(flag2)
            printf("Yes\n");
        else
            printf("No\n");

    }
    else
    {
        printf("Yes\n");
    }
    return 0;
}



Measured memory_bytes: 384
import sys

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))


last = [n-1 for i in range(n)]

a,b = 0,0

l = [i+1 for i in range(n)]
if l == p:
	a = 1
if l == q:
	b = 1

if a == b == 1:
	print(0)
	sys.exit()
cnt = 1
while True:
	cnt += 1
	for i in range(n-1,-1,-1):
		if l[i] < l[i-1]:
			continue
		else:
			obj = l[i-1]
			tmp = sorted(l[i-1:])
			switch = tmp.pop(tmp.index(obj)+1)
			l = l[:i-1] + [switch] + sorted(tmp)

			#print(l)

			break
	
	if l == p:
		a = cnt
	if l == q:
		b = cnt

	if a != 0 and b != 0:
		break

print(abs(a-b))



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n,a[100];
double ans;
int main()
{
	scanf("%d",&n);
	for(register int i=1,x;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	ans=a[1];
	for(register int i=2;i<=n;i++)
		ans=(ans+a[i])*1./2;
	printf("%.6lf",ans);
	return 0;
}

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

int main() {
	long long x, y;
	cin >> x >> y;
	long long count = 1;
	long long num = x;
	while (true) {
		x = x * 2;
		if (x < y) {
			++count;
		} else {
			if (x == y) {
				++count;
			}
			break;
		}
	}
	cout << count;
	return 0;
}

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

x = 0
d = 0
for i in range(N):
	if S[i:i+1]=='(':
		d += 1
	elif S[i:i+1]==')':
		d -= 1
	x = min(x, d)

print('('*(-x) + S + ')'*(d-x))

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int>A(n);
    for (int i = 0; i < n; i++){
        cin >> A[i];
    }
    int total = 0;
    for (int i = 0; i < n; i++){
        total += A[i];
    }
    sort(A.begin(), A.end(), greater<int>());
    if(total % m == 0){
        if(total/(4*m) > A[m-1]){
            cout << "No" << "\n";
        }else{
            cout << "Yes" << "\n";
        }
    }else{
        if(total/(4*m) >= A[m-1]){
            cout << "No" << "\n";
        }else{
            cout << "Yes" << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    s = input()
    Q = int(input())
    t = [input().split() for _ in range(Q)]

    d = [0] * n + [1 << ord(c) - 97 for c in s]
    for i in range(n - 1, 0, -1):
        d[i] = d[i + i] | d[i - ~i]
    for q, a, b in t:
        i, s = int(a) + n - 1, 0
        if q < "2":
            d[i] = 1 << ord(b) - 97
            while i > 1:
                i //= 2
                d[i] = d[i + i] | d[i - ~i]
        else:
            j = int(b) + n
            while i < j:
                if i & 1:
                    s |= d[i]
                    i += 1
                if j & 1:
                    j -= 1
                    s |= d[j]
                i //= 2
                j //= 2
            print(bin(s).count("1"))


main()


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

int main(){
  string s; cin >> s;
  deque<char> q;
  for(char c : s) q.push_back(c);
  bool flip = false;
  int Q; cin >> Q;
  rep(qi,Q){
    int ty; cin >> ty;
    if (ty == 1){
      flip = !flip;
    }else{
      int f; char c; cin >> f >> c;
      if (flip) f = 3-f;
      if (f == 1){
	q.push_front(c);
      }else{
	q.push_back(c);
      }}
  }
  if (flip)  reverse(q.begin(), q.end());
  string ans;
  for (char c : q) ans += c;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1412
def f(L):
	for i in range(0,len(L)-2):
		if(L[i][0]==L[i][1] and L[i+1][0]==L[i+1][1] and L[i+2][0]==L[i+2][1]):
			return "Yes"
	return "No"

n=int(input())
L=[]
for i in range(0,n):
	x=input().split()
	L.append(x)
print(f(L))

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

using namespace std;

const int MOD=1000000007;
int N, M;
int A[100001];
vector<int> adj[100001];
bool seen[100001];
bool use[100001];
bool cycle[100001];
int B[100001];
int fact[100001];
int ifact[100001];
int dp[100001];
int cnt[100001];

int powmod(int a, int b)
{
    int ret=1;
    for(; b>0; b/=2)
    {
        if(b&1)
            ret=1LL*ret*a%MOD;
        a=1LL*a*a%MOD;
    }
    return ret;
}

int C(int n, int k)
{
    return 1LL*fact[n]*ifact[n-k]%MOD*ifact[k]%MOD;
}

void dfs(int u, int i)
{
    M=max(M, i);
    if(!cycle[u])
        B[i]++;
    seen[u]=true;
    int ch=0;
    for(auto& v: adj[u]) if(!seen[v])
    {
        if(cycle[v])
            dfs(v, i+1);
        else
        {
            dfs(v, i);
            ch++;
        }
    }
    if(ch>1)
    {
        printf("0\n");
        exit(0);
    }
}

int brute()
{
    static int P[100];
    for(int i=1; i<=N; i++)
        P[i]=i;
    int ans=0;
    do
    {
        int x=0;
        for(int i=1; i<=N; i++) if(P[i]==A[i] || P[P[i]]==A[i])
            x++;
        if(x==N)
            ans++;
    }
    while(next_permutation(P+1, P+1+N));
    return ans;
}

int main()
{
    scanf("%d", &N);
    for(int i=1; i<=N; i++)
        scanf("%d", A+i);
    fact[0]=ifact[0]=1;
    for(int i=1; i<=N; i++)
    {
        fact[i]=1LL*fact[i-1]*i%MOD;
        ifact[i]=powmod(fact[i], MOD-2);
    }
    for(int i=1; i<=N; i++)
        adj[A[i]].push_back(i);
    int ans=1;
    for(int i=1; i<=N; i++) if(!seen[i])
    {
        int u=i;
        while(!use[u])
        {
            use[u]=true;
            u=A[u];
        }
        int v=u;
        do
        {
            cycle[v]=true;
            v=A[v];
        }
        while(v!=u);
        M=0;
        dfs(u, 0);
        M++;
        int sum=0;
        for(int j=0; j<M; j++)
            sum+=B[j];
        if(sum>M)
        {
            printf("0\n");
            return 0;
        }
        if(sum==0)
            cnt[M]++;
        for(int j=0; j<M; j++) if(B[j]>0)
        {
            bool zero=true;
            for(int k=1; k<B[j]; k++)
                zero&=(B[(j+k)%M]==0);
            if(!zero)
            {
                printf("0\n");
                return 0;
            }
            if(B[(j+B[j])%M]==0)
                ans=2LL*ans%MOD;
        }
        for(int j=0; j<M; j++)
            B[j]=0;
    }
    dp[0]=1;
    for(int i=2; i<=N; i++)
        dp[i]=1LL*dp[i-2]*(i-1)%MOD;
    for(int j=1; j<=N; j++)
    {
        int mult=0;
        if(j>1 && j%2==1)
        {
            for(int i=0; i*2<=cnt[j]; i++)
                mult=(mult+1LL*C(cnt[j], i*2)*dp[i*2]%MOD*powmod(j, i)%MOD*powmod(2, cnt[j]-i*2))%MOD;
        }
        else
        {
            for(int i=0; i*2<=cnt[j]; i++)
                mult=(mult+1LL*C(cnt[j], i*2)*dp[i*2]%MOD*powmod(j, i))%MOD;
        }
        ans=1LL*ans*mult%MOD;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 12672
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)*}
    };
}

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

fn main() {
    input! {
        s: String,
    }
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        if let 'B' = c {
            v.pop();
        } else {
            v.push(c);
        }
    }
    println!("{}", v.into_iter().collect::<String>());
}


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

using namespace std;

#define ll long long

void solve() {
	string s;
	cin >> s;
	int a = s[0] - '0';
	int b = s[1] - '0';
	int c = s[2] - '0';
	int d = s[3] - '0';
	if (a+b+c+d == 7) cout << a << "+" << b << "+" << c << "+" << d << "=7";	
	else if (a+b+c-d == 7) cout << a << "+" << b << "+" << c << "-" << d << "=7";
	else if (a+b-c-d == 7) cout << a << "+" << b << "-" << c << "-" << d << "=7";
	else if (a-b-c-d == 7) cout << a << "-" << b << "-" << c << "-" << d << "=7";
	else if (a+b-c+d == 7) cout << a << "+" << b << "-" << c << "+" << d << "=7";
	else if (a-b-c+d == 7) cout << a << "-" << b << "-" << c << "+" << d << "=7";
	else if (a-b+c+d == 7) cout << a << "-" << b << "+" << c << "+" << d << "=7";
	else if (a-b+c-d == 7) cout << a << "-" << b << "+" << c << "-" << d << "=7";
}

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

	int t = 1, i = 1;
	//cin >> t;
	while(t--) {
		//cout << "Case #" << i << ": ";
		solve();
		//i++;
	}
	return 0;
}



Measured memory_bytes: 3628
from collections import deque

def solve(W, H, field):
    dire = [(1,0), (0,1), (-1,0), (0,-1)]
    for i in range(H):
        for j in range(W):
            if (field[i][j]=="@"):
                s = (i,j)
    check = [[0]*W for i in range(H)]
    q = deque()
    q.append(s)
    check[s[0]][s[1]] = 1
    ret = 1
    while q:
        y, x = q.popleft()
        for dy, dx in dire:
            if (y+dy<H) and (y+dy>=0) and (x+dx<W) and (x+dx>=0):
                if (field[y+dy][x+dx] == ".") and (not check[y+dy][x+dx]):
                    q.append((y+dy, x+dx))
                    check[y+dy][x+dx] = 1
                    ret += 1
    return ret

def main():
    ans = []
    while True:
        W, H = list(map(int, input().split()))
        if (not W) and (not H):
            break
        field = [input() for i in range(H)]
        ans.append(solve(W, H, field))
    for i in ans:
        print(i)
    
main()


Measured memory_bytes: 6076
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000

int main(){
  char buf[1024];
  int A, B, C;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d %d %d", &A, &B, &C);

  int ans=B/A;

  if(ans>=C){
    printf("%d\n", C);
  }
  else{
    printf("%d\n", ans);
  }

  return 0;


}


Measured memory_bytes: 128
n,m=map(int,input().split())
arr1=set()
arrn=set()
for _ in range(m):
    a,b=map(int,input().split())
    if a==1 and b==n or a==n and b==1:
        print("POSSIBLE")
        exit(0)
    else:
        if a==1:
            arr1.add(b)
        elif a==n:
            arrn.add(b)
        elif b==1:
            arr1.add(a)
        elif b==n:
            arrn.add(a)
if len(arr1.intersection(arrn))>0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 19012
#include<stdio.h>

int main(){
	int x[5];
	int i;
	for(i = 0; i < 5; i++){
		scanf("%d",&x[i]);
	}
	for(i = 0; i < 5;i++){
		if(x[i] == 0){
			printf("%d",i + 1);
			break;
		}
	}
}


Measured memory_bytes: 1732