akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
    int n, m, l, a[100][100], b[100][100];

    cin >> n >> m >> l;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < l; j++) {
            cin >> b[i][j];
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            long long c = 0;
            for (int k = 0; k < m; k++) {
                c += (long long)a[i][k] * b[k][j];
            }
            if (j > 0) cout << " ";
            cout << c;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=1000000000000000000,mod=1000000007,BS,k;

int main(){
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
        char ch;
        cin>>ch;
        if(isupper(ch))
        cout<<"A";
        else
        cout<<"a";

}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*

*/
vector<int> prime(0, 0);
vector<int> cnt(10001001, 2);

void eratos(int n){
  for(int i=2; i<=n; i++){
    ll j = 2;
    while (i*j <= n){
      cnt[i*j]++;
      j++;
    }
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  ll N, ans = 0; cin >> N;
  eratos(10001000);//nまでの素数を抽出
  cnt[1] = 1;
  for(ll i=1; i<=N; i++)
    ans += i * cnt[i];
//  rep(i, 100)
//    cout<<"i:"<<i+1<<" cnt:"<<cnt[i+1]<<endl;
  cout << ans << endl;
}


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

int main() {
  int n, c, k;
  cin >> n >> c >> k;
  vector<int> t(n);
  rep(i, n) {
    cin >> t.at(i);
  }
  sort(t.begin(), t.end());
  int count = 1;
  int num = 1;
  int first = t.at(0);
  for (int i = 1; i < n; i++) {
    if (t.at(i) > first + k || num == c) {
      first = t.at(i);
      num = 1;
      count++;
    }
    else {
      num++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main() {
  // input
  int A, B, C, X;
  cin >> A >> B >> C >> X;

  // solve
  int res = 0;
  for (int a = 0; a <= A; a++){
    for (int b = 0; b <= B; b++){
      for (int c = 0; c <= C; c++){
        int total = 500*a + 100*b + 50*c;
        if (total == X) ++res; // 合計金額がXに一致したらインクリメント
      }
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif
#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }
void rsorta_d32(void *base, const int count, const int size, const int index){
	typedef int32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	for(int k=0; k<4; k++){
		memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(k<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(k<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	}
	free(b);
}

int m[3001][3001];
long d[3001][3001][4];
int main(void){
	int w=nextint();
	int h=nextint();
	int k=nextint();
	for(int i=0; i<k; i++){
		int x=nextint();
		int y=nextint();
		int v=nextint();
		m[x][y]=v;
	}
	for(int x=1; x<=w; x++){
		for(int y=1; y<=h; y++){
			d[x][y][0]=d[x][y-1][0];
			if(d[x][y][0]<d[x-1][y][0]) d[x][y][0]=d[x-1][y][0];
			if(d[x][y][0]<d[x-1][y][1]) d[x][y][0]=d[x-1][y][1];
			if(d[x][y][0]<d[x-1][y][2]) d[x][y][0]=d[x-1][y][2];
			if(d[x][y][0]<d[x-1][y][3]) d[x][y][0]=d[x-1][y][3];
			d[x][y][1]=d[x][y-1][1];
			d[x][y][2]=d[x][y-1][2];
			d[x][y][3]=d[x][y-1][3];
			if(m[x][y]>0){
				if(d[x][y][1]<d[x-1][y][0]+m[x][y]) d[x][y][1]=d[x-1][y][0]+m[x][y];
				if(d[x][y][1]<d[x-1][y][1]+m[x][y]) d[x][y][1]=d[x-1][y][1]+m[x][y];
				if(d[x][y][1]<d[x-1][y][2]+m[x][y]) d[x][y][1]=d[x-1][y][2]+m[x][y];
				if(d[x][y][1]<d[x-1][y][3]+m[x][y]) d[x][y][1]=d[x-1][y][3]+m[x][y];
				if(d[x][y][1]<d[x][y-1][0]+m[x][y]) d[x][y][1]=d[x][y-1][0]+m[x][y];
				if(d[x][y][2]<d[x][y-1][1]+m[x][y]) d[x][y][2]=d[x][y-1][1]+m[x][y];
				if(d[x][y][3]<d[x][y-1][2]+m[x][y]) d[x][y][3]=d[x][y-1][2]+m[x][y];
			}
			//printf("%d %d %ld %ld %ld %ld\n", x, y, d[x][y][0], d[x][y][1], d[x][y][2], d[x][y][3]);
		}
	}
	long ans=d[w][h][0];
	if(ans<d[w][h][1]) ans=d[w][h][1];
	if(ans<d[w][h][2]) ans=d[w][h][2];
	if(ans<d[w][h][3]) ans=d[w][h][3];
	printf("%ld\n", ans);
}


Measured memory_bytes: 318024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    int N;
    cin >> N;
    vl T(N),A(N);
    rep(i,N) cin >> T[i] >> A[i];
    ll t = 1,a = 1;
    
    rep(i,N){
        ll t1 = (t+T[i]-1)/T[i]*T[i];
        ll a1 = t1/T[i]*A[i];
        if(t1 < t || a1 < a) t1 = 1e18, a1 = 111;
            
        ll a2 = (a+A[i]-1)/A[i]*A[i];
        ll t2 = a2/A[i]*T[i];
        if(t2 < t || a2 < a) t2 = 1e18, a2 = 111;
        
        if(t1+a1 < a2+t2) a = a1, t = t1;
        else a = a2, t = t2;
       
    }
        

    cout << t+a << endl;
    
    
    
    

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 int main()
{
     long long int n,a,b;
     cin>>n;
     vector<pair<long long int,long long int> >v;
     for (long long int i=0;i<n;i++){
        cin>>a>>b;
        v.push_back(make_pair(b,a));
     }
     sort(v.begin(),v.end());
     int flag=0,s=0;
     for(long long int i=0;i<n;i++){
        s+=v[i].second;
        if(s>v[i].first){
            flag++;
        }
     }
     if(flag==0){
        cout<<"Yes"<<endl;
     }
     else{
        cout<<"No"<<endl;
     }
}

Measured memory_bytes: 5744
package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
func main() {
	S := ReadString()

	var cnt int
	for i := 0; i < 3; i++ {
		if S[i] == 'R' {
			cnt++
		}
	}

	switch cnt {
	case 3:
		fmt.Println(3)
		return
	case 2:
		if S[1] != 'R' {
			fmt.Println(1)
			return
		}
		fmt.Println(2)
		return
	default:
		fmt.Println(cnt)
		return
	}

}


Measured memory_bytes: 1840
S = list(input())

if S[0] != 'A':
    print('WA')
elif S[2:-1].count('C') != 1:
    print('WA')
else:
    S = list(S[1:])
    S.remove('C')
    S = ''.join(S)
    if S.islower():
        print('AC')
    else:
        print('WA')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  if(n%10==3){
    cout << "bon";
  }
  else if(n%10==0||n%10==1||n%10 == 6||n%10==8){
    cout << "pon";
  }
  else
    cout << "hon";
  return 0;
}


Measured memory_bytes: 3652
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

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

    int N; cin >> N; int ans = 0;
    FOR(i, 1, N+1) {
        int count = 0;
        int cur = i;
        while (cur > 0) {
            cur /= 10;
            count++;
        }
        if (count % 2 == 1) ans++;
    }
    cout << ans << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343
// license: https://github.com/bqi343/USACO/blob/master/LICENSE

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
# from collections import defaultdict, deque
# from math import sqrt, gcd, factorial, tan, pi, sin, cos
def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline()[:-1]


def solve():
    n, m = [int(x) for x in input().split()]
    dp = [[float('inf') for _ in range(m)] for _ in range(n)]
    s = []
    for i in range(n):
        s.append(input())
        
    for i in range(n):
        for j in range(m):
            c = int(s[i][j] != '.')
            if i == 0 and j == 0:
                dp[i][j] = c
            if i:
                dp[i][j] = min(dp[i][j], dp[i-1][j] + c * (s[i-1][j] != s[i][j]))
            if j:
                dp[i][j] = min(dp[i][j], dp[i][j-1] + c * (s[i][j-1] != s[i][j]))
    # for r in dp:
    #     print(*r)
    print(dp[n-1][m-1])
        




t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()



"""
1 -> (1, 2) -> (2 ** 3, 3) -> (3, 1)

"""



Measured memory_bytes: 3316
#include <bits/stdc++.h> 
using namespace std;
#define int long long
#define ld double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD =1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1LL;}return res%p;}
const int N=1e6+2,M=1e6+2;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	// freopen("out10.txt","w",stdout);
	#endif
	int n,k;
	cin>>n>>k;
	n%=k;
	cout<<min({abs(n-k),n,n+k});
}
// Don't be afraid to fail. Be afraid not to try.
// "Become grindian instead of greendian" - aryanc403
// When you want to succeed as bad as you want to breathe, only then you’ll Be Successful!
// No Matter,How Fast You Are Driving If You Are Driving in a Wrong Direction You Will Never Reach Your Destination
// When failures hit you, you hit the failures back with Bounce Back!
// When you face failures, Don’t change your goal, Change your strategy!

Measured memory_bytes: 256
import java.util.*;

public class Main {

	int w, h, m, n;
	boolean[][] field;

	class Pos{
		int x, y, cnt;
		Pos(int x, int y, int cnt){
			this.x = x;
			this.y = y;
			this.cnt = cnt;
		}
	}

	void Search(){
		Queue<Pos> Q = new LinkedList<Pos>();
		Q.offer(new Pos(0,0,1));
		while(!Q.isEmpty()){
			Pos now = Q.poll();
			if(m-1==now.x&&n-1==now.y){
				System.out.println(now.cnt);
				return;
			}
			if(now.x+2<m&&field[now.x+1][now.y]){
				Q.offer(new Pos(now.x+2,now.y,now.cnt+1));
				field[now.x+1][now.y] = false; 
			}
			if(now.y+2<n&&field[now.x][now.y+1]){
				Q.offer(new Pos(now.x,now.y+2,now.cnt+1));
				field[now.x][now.y+1] = false;
			}
			if(now.x-2>=0&&field[now.x-1][now.y]){
				Q.offer(new Pos(now.x-2,now.y,now.cnt+1));
				field[now.x-1][now.y] = false;
			}
			if(now.y-2>=0&&field[now.x][now.y-1]){
				Q.offer(new Pos(now.x,now.y-2,now.cnt+1));
				field[now.x][now.y-1] = false;
			}
		}
		System.out.println("0");
	}

	void run(){
		Scanner stdIn = new Scanner(System.in);
		while(true){
			w = stdIn.nextInt();
			h = stdIn.nextInt();
			if(w==0&&h==0){
				return;
			}
			m = h*2-1;
			n = w*2-1;
			field = new boolean[m][n];
			for(int i=0;i<m;i++){
				for(int j=0;j<n;j++){
					if((i+j)%2==0){
						continue;
					}
					if(stdIn.nextInt()==0){
						field[i][j] = true;
					}
				}	
			}
			Search();
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#pragma GCC optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
#define LSOne(S) (S & (-S))
#define ll long long
#define two pair<int,int>
#define four pair<two,two>
#define pb push_back
#define mk make_pair
#define INF 1000000000000000000
#define P 1000000007
#define lmax 1000000000
ll a[100003];
ll b[100004];
ll n,ans;
int main(){std::ios::sync_with_stdio(false);
cin>>n;
for(int i=0;i<n;i++){
	cin>>a[i]>>b[i];
	ans-=b[i];
	b[i]+=a[i];
	b[i]=-b[i];
}
sort(b,b+n);
//cout<<ans<<endl;
for(int i=1;i<=n;i++){
	if(i&1)ans-=b[i-1];
}
cout<<ans<<endl;
}
/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
                 *   *   * *   *
                  *   *   *   *
                   *   * *   *
                     *  *   *
					   *  *


*/





Measured memory_bytes: 1792
n, m = [int(v) for v in input().split()]
a_s = [[int(v) - 1 for v in input().split()] for _ in range(m)] #0起点に変換

ls = [[1, 0] for _ in range(n)]
ls[0][1] = 1

for a in a_s:
  x, y = a
  #玉移動
  #print(ls, x, y)
  ls[x][0] -= 1
  ls[y][0] += 1
  #移動元が赤箱なら先も赤箱にする
  if ls[x][1] == 1:
    ls[y][1] = 1
  #移動元が空になったら白箱にする
  if ls[x][0] == 0:
    ls[x][1] = 0
    
print(sum([e[1] for e in ls]))


Measured memory_bytes: 32248
def main():
    # n = int(input())
    # h, w, k = map(int, input().split())
    # a = list(map(int, input().split()))
    # s = input()
    a, v = map(int, input().split())
    b, w = map(int, input().split())
    t = int(input())
    if b < a:
        b = a + a - b
    if (b+w*t) - (a+v*t) <= 0:
        print("YES")
    else:
        print("NO")



if __name__ == '__main__':
    main()


Measured memory_bytes: 80264
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define  SIZE 3000
#define max(a,b) ((a>b) ? (a) : (b))

typedef long long unsigned int int64;

int value[SIZE+10][SIZE+10]={0};
int64 dp[SIZE+10][SIZE+10][4]={0};

int main()
{
    int r,c,k;
    int n, i, j;
    int rn,cn;
    int v;
    int64 ans=0;


    scanf("%d %d %d", &r,&c,&k);

    for(i=0;i<k;i++)
    {
        scanf("%d %d %d",&rn,&cn,&v);
        value[rn][cn]=v;
    }

    for(i=0;i<=r;i++)
    {
        for(j=0;j<=c;j++)
        {
            for(n=2;n>=0;n--)//拾う場合の遷移
            {
                dp[i][j][n+1]=max(dp[i][j][n+1],dp[i][j][n]+(int64)value[i][j]);
            }
            for(n=0;n<4;n++)
            {
                dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][n]);
                dp[i][j+1][n]=max(dp[i][j+1][n],dp[i][j][n]);
            }
        }
    }
    for(n=0;n<4;n++)
    {
        if(ans<dp[r][c][n])ans=dp[r][c][n];
    }

    printf("%lld",ans);
}



Measured memory_bytes: 319312
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val d = sc.nextInt()
    val c = (0 until 26).map { sc.next().toInt() }
    val s = (0 until d).map {
        (0 until 26).map { sc.next().toInt() }
    }
    println(problemintroduction_to_heuristics_contest(d, c, s))
}

fun problemintroduction_to_heuristics_contest(
    D: Int,
    c: List<Int>,
    s: List<List<Int>>
): String {
    val last = LongArray(26) { 0 }
    val satisfactions = LongArray(26) { 0 }
    val ans = IntArray(D) { 1 }
    for (d in 0 until D) {
        var max = -Long.MAX_VALUE
        var maxIndex = 0
        for (select in 0 until 26) {
            val plus = s[d][select].toLong()
            var minus = 0L
            for (other in 0 until 26) {
                if (select == other) {
                    continue
                }
                minus += c[other] * ((d + 1) - last[other])
            }
            max = Math.max(max, plus - minus)
            if (max <= plus - minus) maxIndex = select
        }
        val selected = maxIndex
        ans[d] = selected + 1
        satisfactions[selected] += s[d][selected].toLong()
        last[selected] = d + 1L
        for (j in 0 until 26) {
            satisfactions[j] -= c[j] * ((d + 1) - last[j])
        }
    }
//    debugLog(satisfactions.sum())
    return ans.joinToString("\n")
}

Measured memory_bytes: 48180
#include<bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
using namespace std;
const int nx=2e5+5;
const int inf=1e18+7;
const int mod=1e9+7;
vector<int>adj[nx];


signed main(){
	int n,k;
	cin>>n>>k;
	int cnt=0;
	while(n){
		cnt++;
		n /= k;
	}
	cout<<cnt<<endl;
	return 0;
}



Measured memory_bytes: 4992
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;

  cin >> s;
  int cand1 = 0;
  int cand2 = 0;
  int len = s.length();
  // cand1 for 1.....
  // cand2 for 0.....
  // now for cand1
  for(int i=0;i<len;i++){
    if(i%2 == 0){
      if(s[i] != '1'){
        cand1++;
      }
    }
    else{
      if(s[i] != '0'){
        cand1++;
      }
    }
  }
  for(int i=0;i<len;i++){
    if(i%2 == 0){
      if(s[i] != '0'){
        cand2++;
      }
    }
    else{
      if(s[i] != '1'){
        cand2++;
      }
    }
  }

  if(cand1 <= cand2){
    cout << cand1 << endl;
  }
  else{
    cout << cand2 << endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;

signed main(){
    
    int k,s,ans=0;
    cin>>k>>s;
    int z;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            z=(s-i-j);
            if(0<=z && z<=k)ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2005,mod=1000000007;
int n,dp[N][N],s[N][N],ans;
int main()
{
	scanf("%d",&n);
	for(int j=0;j<=n;j++)
		s[0][j]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=3;j<=n;j++)
		{
			dp[i][j]=s[i-1][j-3];
			s[i][j]=(s[i][j-1]+dp[i][j])%mod;
		}
		ans=(ans+dp[i][n])%mod;
	}
	printf("%d\n",ans);
	return 0;
}

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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

int n;
int a[100005];
long long leftt = 2, rightt = 2;

void compute(int cmd){
	// look for multiples of cmd in [left, right]
	long long lo = (leftt + cmd - 1) / cmd;
	long long hi = rightt / cmd;
	// now lo * cmd to (hi + 1) * cmd - 1 are possible
	leftt = lo * cmd;
	rightt = (hi + 1) * cmd - 1;
	return;
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
	}
	for(int i = n; i >= 1; i--){
		compute(a[i]);
	//	printf("%lld %lld\n", leftt, rightt);
		if(leftt > rightt){
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld %lld\n", leftt, rightt);
}

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

using namespace std;


int main()
{
    int n = 0, a = 0, b = 0, cnt = 0;

    cin >> n;
    while (n--) {
        cin >> a >> b;
        if (a == b) {
            cnt += 1;
            if (cnt == 3) {
                cout << "Yes";
                return 0;

            }
        }
        else {
            cnt = 0;
        }
    }
    cout << "No";
}

Measured memory_bytes: 3620
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	for (int i = 0; i < n.length(); i++) {
		if (n[i] == '1') {
			cout << 9;
		}
		else if (n[i] == '9') {
			cout << 1;
		}else{
			cout << n[i];
		}
	}
	cout << endl;
	
	
}


Measured memory_bytes: 3580
#include<cstdio>
using namespace std;
int main()
{
	int A1,A2,B1,B2,a=0;
	scanf("%d%d%d%d",&A1,&A2,&B1,&B2);
	if(A2<=B1||B2<=A1)
    	a=0;
	else if(A1>=B1)
	{
		a=B2-A1;
		if(A2<B2)
			a=A2-A1;
	}
	else if(B1>=A1)
	{
		a=A2-B1;
		if(B2<A2)
			a=B2-B1;
	}
	printf("%d",a);
	return 0;
}

Measured memory_bytes: 128
n,y = map(int, input().split())
a,b,c = -1,-1,-1
for i in range(n+1):
    for j in range(n+1):
        total = 10000*i + 5000*j + 1000*(n-i-j)
        if(total == y and (n-i-j)>=0):
            a,b,c = i,j,(n-i-j)
print(a,b,c)


Measured memory_bytes: 9132
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#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)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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 (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
  string s;
  cin >> s;
  if(s=="RRR"){
    cout << 3 << endl;
  }else if(s=="RRS"||s=="SRR"){
    cout << 2 << endl;
  }else{
    int res = 0;
    rep(i,3)if(s[i]=='R')res = 1;
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 3608
import re

S = input()
flag = True
while(flag):
    if(len(S)==0):
        flag = False
    if(S[-5:]=='dream' or S[-5:]=='erase'):
        S=S[:-5]
    elif(S[-6:]=='eraser'):
        S=S[:-6]
    elif(S[-7:]=='dreamer'):
        S=S[:-7]
    else:
        break
if(flag):
    print('NO')
else:
    print('YES')

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#include <iomanip>
#define ll long long int
#define ld long double
#define IOS cin.tie(NULL);cout.tie(NULL)
#define f first
#define inf 100000000000000000
#define ii pair<ll,ll>
#define vi vector<ll>
#define vii vector<ii>
#define MS0(x) memset(x,0,sizeof(x))
#define MS1(x) memset(x,-1,sizeof(x))
#define sc(i) scanf("%lld",&i);
#define s second
#define pb push_back
#define forn(i,n) for(int i=0;i<(int)n;i++)
using namespace std;
ll const mod=1000000007;
 
// ll arr1[10000009];
// vector<ll> sieve;
// void sievefun(ll n){
//     for(ll i=2;i<=n;i++){
//         if(arr1[i]==0){
//             for(ll j=i*i;j<=n;j+=i){
//                 arr1[j]=1;
//             }
//         }
//     }
//     for(int i=2;i<=n;i++){
//     	if(arr1[i]==0)sieve.pb(i);
//     }
// }
 
ll countDivisors(ll n)
{
    ll cnt = 0;
    for (ll i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            // If divisors are equal,
            // count only one
            if (n / i == i)
                cnt++;
 
            else // Otherwise count both
                cnt = cnt + 2;
        }
    }
    return cnt;
}
ll power(ll x, ll y) {
	ll temp;
	if( y == 0)
		return 1;
	temp = power(x, y/2);
	if (y%2 == 0)
		return ((temp)*(temp));
	else
		return (((x))*((temp*temp)));
}
ll gcd1(ll a, ll b){
if (a == 0)
    return b;
return gcd1(b % a, a);
}
ll lcm(ll a, ll b)
{
return (a*b)/gcd1(a, b);
}
ll dp[1<<22];
ll arr[22][22];
int main()
{	//sievefun(10000007);
	//ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll n;
	cin>>n;
	forn(i,n){
		forn(j,n){
			cin>>arr[i][j];
		}
	}
	dp[0]=1;
	ll mask;
	ll count;
	for(int i=1;i<(1<<n);i++){
		count=0;
		forn(j,21){
			if((i>>j)&1)count++;
		}
		forn(j,21){
			if((i>>j)&1){
				mask=i;
				if(!arr[count-1][j])continue;
				mask^=(1<<j);
				dp[i]+=dp[mask];
				dp[i]%=mod;
			}
		}
	}
	//forn(i,12)cout<<dp[i]<<" ";
	//cout<<endl;
	cout<<dp[(1<<n)-1];
}

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

#define fi  first
#define se  second
#define mp  make_pair
#define pb  push_back

typedef long long ll;
typedef queue <int> qi;
typedef vector <int> vi;
typedef vector <char> vc;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef map <char, int> mci;
typedef map <char, char> mcc;
typedef map <string, int> msi;
typedef pair <string, int> psi;
typedef map <string, string> mss;
typedef unsigned long long ull;

const ll mod = 10e9+7;
const double eps = 1e-11;
const double PI = 2 * acos(0.0);

/*
string ToString(int n) { // Integer -> String
    stringstream convert;
    convert << n;
    return convert.str();
}

int ToInt(string s) { // String -> Integer
    istringstream sin(s);
    int x = 0;
    sin >> x;
    return x;
}

ll BigMod(ll b, ll p, ll m) {
    if (p == 0) return 1;
    ll r = bigmod(b, p / 2, m);
    r = (r * r) % m;
    if (p & 1) r = (r * b) % m;
    return r;
}
*/

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    a += b;
    if (c <= a) puts("Yes");
    else puts("No");
}


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

int digitsum(int a){
  int ret = 0;
  while(a != 0) {
    ret += a % 10;
    a /= 10;
  }
  return ret;
}

int main(){
  int n; cin >> n;
  int m = 1e9;
  for (int i = 1; i < n; i++) {
    m = min(m, digitsum(i) + digitsum(n-i));
  }
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    string s;
    cin >> s;
    rep(i, len(s)) {
        if (s[i] == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3640
import math
import heapq as hp
import sys
input = sys.stdin.readline

sx, sy, tx, ty = map(int, input().split())
N = int(input())
XYR = [list(map(int, input().split())) for _ in range(N)]
INF = 10**14

graph = [[] for _ in range(N+2)]
for i in range(N-1):
    for j in range(1, N):
        x1, y1, r1 = XYR[i]
        x2, y2, r2 = XYR[j]
        d = max(0, math.sqrt((x1-x2)**2+(y1-y2)**2)-r1-r2)
        graph[i].append((d, j))
        graph[j].append((d, i))

for i in range(N):
    x, y, r = XYR[i]
    graph[N].append((max(0, math.sqrt((x-sx)**2+(y-sy)**2)-r), i))
    graph[i].append((max(0, math.sqrt((x-tx)**2+(y-ty)**2)-r), N+1))

graph[N].append((math.sqrt((tx-sx)**2+(ty-sy)**2), N+1))

D = [INF for _ in range(N+2)] # 頂点iへの最短距離がD[i]
D[N] = 0 
q = [] # しまっていく優先度付きキュー
hp.heappush(q, (0, N))

while q:
    nd, np = hp.heappop(q) # 一番距離が近いものを取ってくる
    if D[np] < nd: # 追加した後の残骸は見ない
        continue
    for d, p in graph[np]:
        if D[p] > D[np] + d: # 隣接するやつの中で今よりも近くなれるなら更新
            D[p] = D[np] + d
            hp.heappush(q, (D[p], p))

print(D[N+1])

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

int main(void) {
    int N, K;
    cin >> N >> K;
 
    int a[N];
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

   int SIZE = N + 1;
    int b[SIZE] = {0};
    for (int i = 0; i < N; i++) {
        b[a[i]]++;
    }
    sort(b, b + SIZE, greater<>());

#if 0
    cout << "sort :"; 
    for (int i  = 0; i < SIZE; i++) {
        cout << b[i];
    }
    cout << endl;
#endif

    int sum = 0;
    for (int i = K; i < SIZE; i++) {
        sum += b[i];
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<bitset>
#include<cstdlib>
#include<set>
#include<unordered_map>
#define l(x) (x<<1)
#define r(x) ((x<<1)|1)
#define low(x) (x&(-x))
#define IL inline
#define reg register
#define LL long long
#define N 500010
#define MOD 998244353
#define MO 1000000007
#define INF 0x3f3f3f3f
using namespace std;

int T,n,i,j,k,x,y,z;
int a[N],b[N];
char c[N];

struct Data{
	int x,y;
}d[N];

IL int Abs(int x){return (x<0)?-x:x;}
IL void Swap(int &a,int &b){a^=b^=a^=b;}
IL int Min(int a,int b){return (a<b)?a:b;}
IL int Max(int a,int b){return (a>b)?a:b;}
IL bool cmp(const Data a,const Data b){return a.x<b.x;}

IL LL Mi(LL x,LL y){
	LL p=x,t=1,Res=1;
	for (;t<=y;(t&y)?Res=(Res*p)%MOD:0,p=(p*p)%MOD,t<<=1);
	return Res;
}

IL int read(){
	int p=0,f=1;	char	c=getchar();
	while (c<48||c>57)	{if (c=='-')	f=-1;	c=getchar();}
	while (c>=48&&c<=57)	p=(p<<1)+(p<<3)+c-48,c=getchar();
	return p*f;
}

int main(){
	#ifdef __Marvolo
	freopen("zht.in","r",stdin);
	freopen("zht.out","w",stdout);
	#endif
	n=read();
	if (n<=599)	puts("8");
	else 	if (n<=799)	puts("7");
	else 
		if (n<=999)	puts("6");
	else 
		if (n<=1199)	puts("5");
	else 
		if (n<=1399)	puts("4");
	else 
		if (n<=1599)	puts("3");
	else 	if (n<=1799)	puts("2");
	else 
		if (n<=1999)	puts("1");
	return 0;
}

Measured memory_bytes: 3624
H, W = map(int, input().split())
S = [''] * H
M = [[0 for w in range(W)] for h in range(H)]
for i in range(H):
  S[i] = input()
  n = H * W
  for j in range(W):
    if S[i][j] == '#':
      M[i][j] = 0
      n = 0
    else:
      n += 1
      M[i][j] = n
  n = H * W
  for j in range(W - 1, -1, -1):
    if S[i][j] == '#':
      n = 0
    else:
      n = min(n + 1, M[i][j])
      M[i][j] = n
for j in range(W):
  n = H * W
  for i in range(H):
    if S[i][j] == '#':
      n = 0
    else:
      n = min(n + 1, M[i][j])
      M[i][j] = n
  n = H * W
  for i in range(H - 1, -1, -1):
    if S[i][j] == '#':
      n = 0
    else:
      n = min(n + 1, M[i][j])
      M[i][j] = n
print(max([max(m) for m in M]))

Measured memory_bytes: 58332
import java.util.Scanner;

// ABC134 A - Dodecagon

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int r = Integer.parseInt(sc.nextLine());
		
		
		// Output
		int ans = (int)(3 * Math.pow(r, 2));
		System.out.println(ans);
	}
}


Measured memory_bytes: 21972
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N (1<<17)
class RAQxRMQ{
private:
    ll dat[N*2],laz[N*2];
    void eval(int k){
	dat[k]+=laz[k];
	if(k<N-1){
	    laz[k*2+1]+=laz[k];
	    laz[k*2+2]+=laz[k];
	}
	laz[k]=0;
    }
    ll dfs(int l,int r,int a,int b,int k){
	eval(k);
	if(l<=a&&b<=r)return dat[k];
	if(b<=l||r<=a)return (ll)mod*(ll)mod;
	ll vl=dfs(l,r,a,(a+b)/2,k*2+1);
	ll vr=dfs(l,r,(a+b)/2,b,k*2+2);
	return min(vl,vr);
    }
    void ufs(int l,int r,int a,int b,int k,ll x){
	eval(k);
	if(l<=a&&b<=r){laz[k]+=x;eval(k);return;}
	if(b<=l||r<=a){return;}
	ufs(l,r,a,(a+b)/2,k*2+1,x);
	ufs(l,r,(a+b)/2,b,k*2+2,x);
	dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
public:
    void Init(){
	lol(i,2*N)dat[i]=laz[i]=0;
    }
    void Add(int l,int r,ll x){
	ufs(l,r+1,0,N,0,x);
    }
    ll Min(int l,int r){
	return dfs(l,r+1,0,N,0);
    }
};
int main(){
    int n,q;cin>>n>>q;
    RAQxRMQ seg;seg.Init();
    while(q--){
	ll z,a,b,c;
	cin>>z;
	if(z==0){
	    cin>>a>>b>>c;
	    seg.Add(a,b,c);
	}
	if(z==1){
	    cin>>a>>b;
	    cout<<seg.Min(a,b)<<endl;
	}
    }
    return 0;
}



Measured memory_bytes: 7196
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s;
    int x, y;
    cin >> s;
    cin >> x >> y;
    
    int n = 0, a[5000], b[5000], strt = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'F') strt++;
        else {
            if (n % 2 == 0) a[n / 2] = strt;
            else b[n / 2] = strt;
            n++;
            strt = 0;
        }
    }
    if (s[s.size() - 1] == 'F') {
        if (n % 2 == 0) a[n / 2] = strt;
        else b[n / 2] = strt;
        n++;
    }
    
    bool ap[16000], app[16000];
    int apmin = a[0] + 8000, apmax = a[0] + 8000, appmin, appmax;
    ap[a[0] + 8000] = true;
    for (int i = 1; i <= n / 2; i++) {
        for (int j = apmin; j <= apmax; j++) {
            if (ap[j]) {
                app[j - a[i]] = true;
                app[j + a[i]] = true;
            }
            if (j == apmin) appmin = j - a[i];
            if (j == apmax) appmax = j + a[i];
        }
        apmin = appmin;  apmax = appmax;
        for (int j = apmin; j <= apmax; j++) {
            ap[j] = app[j];
            app[j] = false;
        }
    }
    if (!ap[x + 8000]) {
        cout << "No" << endl;
        return 0;
    }
    
    bool bp[16000], bpp[16000];
    int bpmin = 8000, bpmax = 8000, bppmin, bppmax;
    bp[8000] = true;
    for (int i = 0; i <= (n - 1) / 2; i++) {
        for (int j = bpmin; j <= bpmax; j++) {
            if (bp[j]) {
                bpp[j - b[i]] = true;
                bpp[j + b[i]] = true;
            }
            if (j == bpmin) bppmin = j - b[i];
            if (j == bpmax) bppmax = j + b[i];
        }
        bpmin = bppmin;  bpmax = bppmax;
        for (int j = bpmin; j <= bpmax; j++) {
            bp[j] = bpp[j];
            bpp[j] = false;
        }
    }
    if (!bp[y + 8000]) {
        cout << "No" << endl;
        return 0;
    }
    
    cout << "Yes" << endl;
}


Measured memory_bytes: 384
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n):
    b[i]=a[i]-i-1
b.sort()

chuoh=0
count=0
count2=0
if n%2==1:
    chuoh=b[int(n/2)]
    for i in range(n):
        count+=abs(a[i]-chuoh-i-1)
else:
    chuoh=b[int(n/2)]
    for i in range(n):
        count+=abs(a[i]-chuoh-i-1)
    chuoh=b[int(n/2)-1]
    for i in range(n):
        count2+=abs(a[i]-chuoh-i-1)
    count=min(count, count2)

print(count)

Measured memory_bytes: 88404
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] l = new int[n];
        int max = 0;
        int acc = 0;

        for (int i=0; i<n; i++) {
            l[i] = scanner.nextInt();
            acc += l[i];
            max = Math.max(max,l[i]);
        }

        int left = max;
        int right = acc;

        while (left < right) {
            int p = (left+right)/2;
            int id = 0;
            int sum = 0;
            for (int i=0; i<n; i++) {
                if (sum + l[i] > p) {
                    sum = l[i];
                    id++;
                }else {
                    sum += l[i];
                }
                if (id == k)
                    break;
            }
            if (id == k)
                left = p+1;
            else
                right = p;
        }
        System.out.println(left);

    }
}



Measured memory_bytes: 70408
#include <iostream>

using namespace std;
typedef long long ll;
ll c,d;
ll gcd(ll x, ll y){
	if(x<y) swap(x,y);
	if(y==0) return x;
	else return gcd(x%y,y);
}
ll lcm(ll x, ll y){
	return x*y/(gcd(x,y));
}

ll solve(ll a){
	return a - (a/c + a/d - a/(lcm(c,d)));
}

int main(){
	ll a,b;
	cin >> a >> b >> c >> d;
	cout << solve(b) - solve(a - 1) << endl;
}

Measured memory_bytes: 256
x = list(map(int, input().split()))
x0 = [x[0], x[1]]
y0 = [x[2], x[3]]
results = [(x0[0]*y0[0]), (x0[1]*y0[0]), (x0[0]*y0[1]), (x0[1]*y0[1])]
print(max(results))

Measured memory_bytes: 9104
N = int(input())
H = list(map(int,input().split()))
flag = True
num = 0
for i in range(N-1):
  if H[i] - 1 == H[i+1] and H[i+1] >= num: 
    num = H[i+1]
  elif H[i] - 1 == H[i+1] and H[i+1] < num:
    flag = False
    break
  elif H[i] -1 > H[i+1]:
    flag = False
    break
if flag == True:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 14396
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;

const ll INF = 10000000000000000;

struct Graph
{
    int n;
    vector<vector<int>> g;
    
    Graph(int n) : n(n){
        g.resize(n);
    }
    
    void init(int n_){
        n = n_;
        g.resize(n_);
    }
    
    void add_edge(int from, int to){
        g[from].push_back(to);
    }
};

struct Tree	//create tree(directed) from graph(undirected)
{
    int n;
    int root;
    int root2;
    vector<vector<int>> t;
    vector<int> par;
    vector<int> dpt;
    
    void init(Graph &g, int root_, int root2_ = -1){
        n = g.n;
        root = root_;
        root2 = root2_;
        t.resize(n);
        par.resize(n);
        dpt.resize(n);
        fill(dpt.begin(), dpt.end(), -1);
        queue<int> que;
        par[root] = -1;
        dpt[root] = 0;
        que.push(root);
        if(root2 != -1){
            par[root2] = -1;
            dpt[root2] = 0;
            que.push(root2);
        }
        while(que.size()){
            int pa = que.front();
            que.pop();
            for(int ch : g.g[pa]){
                if(dpt[ch] == -1){
                    t[pa].push_back(ch);
                    par[ch] = pa;
                    dpt[ch] = dpt[pa] + 1;
                    que.push(ch);
                }
            }
        }
    }

    Tree(){}
    
    Tree(Graph &g, int root_, int root2_ = -1){
        init(g, root_, root2_);
    }
};

int main()
{
    int n;
    cin >> n;
    Graph g(n);
    int a[102], b[102];
    for(int i = 0; i < n - 1; i++){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        g.add_edge(a[i], b[i]);
        g.add_edge(b[i], a[i]);
    }
    ll ans = INF;
    ll l = INF;
    for(int i = 0; i < n; i++){
        if((int)g.g[i].size() == 1) continue;
        Tree t(g, i);
        queue<int> que[2];
        que[0].push(i);
        int d = 0;
        ll s = 1;
        while(true){
            ll r = 0;
            while(que[d % 2].size()){
                int u = que[d % 2].front();
                que[d % 2].pop();
                r = max(r, (ll)t.t[u].size());
                for(int v : t.t[u]) que[(d + 1) % 2].push(v);
            }
            d++;
            if(r == 0) break;
            s *= r;
        }
        if(d == ans) l = min(l, s);
        if(d < ans) ans = d, l = s;
    }
    for(int i = 0; i < n - 1; i++){
        Tree t(g, a[i], b[i]);
        queue<int> que[2];
        que[0].push(a[i]);
        que[0].push(b[i]);
        int d = 0;
        ll s = 2;
        while(true){
            ll r = 0;
            while(que[d % 2].size()){
                int u = que[d % 2].front();
                que[d % 2].pop();
                r = max(r, (ll)t.t[u].size());
                for(int v : t.t[u]) que[(d + 1) % 2].push(v);
            }
            d++;
            if(r == 0) break;
            s *= r;
        }
        if(d == ans) l = min(l, s);
        if(d < ans) ans = d, l = s;
    }
    cout << ans << " " << l << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll ans = 0;
ll N;
vector<l_l> v;
ll Rmin[100050];
ll LLeft[100050], RLeft[100050], LRight[100050], RRight[100050];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    v.resize(N);
    for(int i = 0; i < N; i++) {
        cin >> v[i].first >> v[i].second;
        //chmax(ans, v[i].second - v[i].first + 1);
        //v[i].second *= -1;
    }
    LLeft[0] = v[0].first;
    RLeft[0] = v[0].second;
    for(int i = 1; i <= N - 1; i++) {
        LLeft[i] = max(LLeft[i-1], v[i].first);
        RLeft[i] = min(RLeft[i-1], v[i].second);
    }
    LRight[N] = 0;
    RRight[N] = 2e9;
    for(int i = N - 1; i >= 0; i--) {
        LRight[i] = max(LRight[i+1], v[i].first);
        RRight[i] = min(RRight[i+1], v[i].second);
    }
    for(int i = 0; i <= N - 1; i++) {
        ll nowans = v[i].second - v[i].first + 1;
        ll Rmin = 2e9;
        ll Lmax = 0;
        if(i > 0) {
            chmin(Rmin, RLeft[i-1]);
            chmax(Lmax, LLeft[i-1]);
        }
        if(i < N - 1) {
            chmin(Rmin, RRight[i+1]);
            chmax(Lmax, LRight[i+1]);
        }
        nowans += max(Rmin - Lmax + 1, 0LL);
        chmax(ans, nowans);
    }
    for(int i = 0; i < N; i++) {
        v[i].second *= -1;
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < N; i++) {
        v[i].second *= -1;
    }
    Rmin[N] = 1e9;
    for(int i = N - 1; i >= 0; i--) {
        Rmin[i] = min(Rmin[i+1], v[i].second);
    }
    set<ll> st;
    st.insert(2e9);
    for(int i = 0; i < N - 1; i++) {
        //cerr << "---" << i << "---" << endl;
        st.insert(v[i].second);
        /*
        for(auto val : st) cerr << val << " ";
        cerr << endl;
        cerr << "----------" << endl;
        */
        auto itr = st.lower_bound(v[i+1].first);
        if(*itr == 2e9) itr--;
        //cerr << *itr << " " << v[i+1].first << endl;
        //cerr << Rmin[i+1] << endl;
        //if(itr != st.begin()) itr--;
        ll nowans = max(*itr - v[i].first + 1, 0LL);
        ll subans = 0;
        subans = Rmin[i+1];
        if(itr != st.begin()) {
            itr--;
            if(itr != st.end()) {
                chmin(subans, *itr);
            }
        }
        //cerr << subans << endl;
        //cerr << nowans << " " << subans << endl;
        subans -= v.back().first;
        subans++;
        chmax(subans, 0LL);
        //cerr << nowans << " " << subans << endl;
        chmax(ans, nowans + subans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 13480
n = int(input())
bara=list(map(int,input().split()))
number=list(range(1,n+1))

count = 0
    
for i in range (0,n):
    if bara[i] != number[i]:
        count += 1

if count==2 or count==0:
    print("YES")
else:
    print("NO")



Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>

using namespace std;

int st[10001];
int fn[10001];

int main()
{
    int n;

    while (cin >> n, n) {
        int h, m, s;
        char ch;
        int ans = 0;

        for (int i = 0; i < n; i++) {
            cin >> h >> ch >> m >> ch >> s;
            st[i] = (h * 60 + m) * 60 + s;
            cin >> h >> ch >> m >> ch >> s;
            fn[i] = (h * 60 + m) * 60 + s;
        }

        sort(st, st + n);
        sort(fn, fn + n);

        int i_s, i_f, tmp;
        i_s = i_f = tmp = 0;
        while (i_s < n && i_f < n) {
            if (st[i_s] < fn[i_f]) {
                i_s++;
                tmp++;
                ans = max(ans, tmp);
            }
            else {
                i_f++;
                tmp--;
            }
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    ll N, A, B;  cin >> N >> A >> B;
    
    ll ans = (ll)(N/(A+B))*A + ((A < N%(A+B)) ? A : N%(A+B));

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

Measured memory_bytes: 256
import numpy as np
N = int(input())
a, b, c = [0] * N, [0] * N, [0] * N
for i in range(N):
	a[i], b[i], c[i] = map(int, input().split())
DP_list = [[0] * 3 for _ in range(N)]
#print(dp)
DP_list[0] = [a[0], b[0], c[0]]

base = np.array([a,b,c]).T
for i in range(1,N):
  DP_list[i][0] = base[i][0] + max(DP_list[i-1][1], DP_list[i-1][2])
  DP_list[i][1] = base[i][1] + max(DP_list[i-1][0], DP_list[i-1][2])
  DP_list[i][2] = base[i][2] + max(DP_list[i-1][1], DP_list[i-1][0])

print(int(max(DP_list[-1])))

Measured memory_bytes: 45820
#include<bits/stdc++.h>
#define ll long long
#define REP(i, n) for (int i=0; i<n; ++i)
#define print(x) cout << x << endl;

using namespace std;

void solve() {
    int H, W;
    cin >> H >> W;
    vector<vector<char> > a(H, vector<char>(W));
    REP(i, H) {
        REP(j, W) {
            cin >> a[i][j];
        }
    }
    
    vector<int> newH, newW;
    REP(i, H) {
        bool flag = false;
        REP(j, W) {
            if (a[i][j] == '#') {
                flag = true;
                break;
            }
        }
        if (flag) {
            newH.push_back(i);
        }
    }
    REP(i, W) {
        bool flag = false;
        REP(j, H) {
            if (a[j][i] == '#') {
                flag = true;
                break;
            }
        }
        if (flag) {
            newW.push_back(i);
        }
    }

    for (int h = 0; h < newH.size(); h++) {
        for (int w = 0; w < newW.size(); w++) {
            cout << a[newH[h]][newW[w]];
        }
        cout << endl;
    }
}

int main() {

    solve();
    return 0;
}


Measured memory_bytes: 256