akhauriyash/Code-Regression huggingface dataset:
N = int(input())
ABC = []
for i in range(N):
    a,b,c = map(int, input().split())
    ABC.append((a,b,c))

dpA = [0 for _ in range(N)]
dpB = [0 for _ in range(N)]
dpC = [0 for _ in range(N)]

for i in range(N):
    if i == 0:
        dpA[0] = ABC[i][0]
        dpB[0] = ABC[i][1]
        dpC[0] = ABC[i][2]
    else:
        dpA[i] =  max(dpB[i-1], dpC[i-1]) + ABC[i][0]
        dpB[i] =  max(dpA[i-1], dpC[i-1]) + ABC[i][1]
        dpC[i] =  max(dpA[i-1], dpB[i-1]) + ABC[i][2]

print(max(dpA[-1],dpB[-1],dpC[-1]))


Measured memory_bytes: 69336
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]

ok = False
for i in range(N - 2):
    ok |= ((X[i][0] == X[i][1]) and ((X[i + 1][0] == X[i + 1][1]))
           and (X[i + 2][0] == X[i + 2][1]))

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


Measured memory_bytes: 62712
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using static System.Console;

namespace AtCoder
{
    class AtCoderrrrrr
    {
        static void Main(string[] args)
        {
            string s = ReadLine();
            int w = int.Parse(ReadLine());
            string ans = "";
            for (int i = 0; i < s.Length; i++)
            {
                if (i % w == 0)
                {
                    ans += s[i].ToString();
                }
            }
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
h, w = map(int, input().split())

def clear_maze(sx, sy, maze):
    INF = -1
    field_x_length = len(maze[0])
    field_y_length = len(maze)
    distance = [[INF for i in range(field_x_length)]
                for j in range(field_y_length)]
    for i in range(field_y_length):
        for j in range(field_x_length):
            if maze[i][j] == '#':
                distance[i][j] = -100

    def bfs():
        queue = []
        queue.insert(0, (sx, sy))
        distance[sy][sx] = 0

        while len(queue):
            x, y = queue.pop()
            for i in range(0, 4):
                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]
                if (0 <= nx and nx < field_x_length and 0 <= ny and ny < field_y_length and maze[ny][nx] != '#' and distance[ny][nx] == INF):
                    queue.insert(0, (nx, ny))
                    distance[ny][nx] = distance[y][x] + 1
        
        return distance
    return bfs()


S = [list(input()) for _ in range(h)]
ans = 0
cnt = 1
for i in range(h):
    for j in range(w):
        start = S[i][j]
        if start == '#':
            continue
            
        num = clear_maze(j, i, S)
        # print(num,cnt,j,i,S[i][j])
        cnt += 1
        for k in range(h):
            ans = max(ans, max(num[k]))
print(ans)


Measured memory_bytes: 48476
import sys
input = sys.stdin.readline


def read():
    N = int(input().strip())
    return N,


def solve(N):
    L = [0 for i in range(N+1)]
    L[0] = 2
    L[1] = 1
    for i in range(2, N+1):
        L[i] = L[i-1] + L[i-2]
    return L[N]


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 9196
#!/usr/bin/env python

def main():
    x = sorted(list(map(int, input().split())))
    count = 0

    while True:
        if x[0] == x[1] == x[2]:
            break
        elif x[2] > x[1] and x[2] > x[0]:
            x[1] += 1
            x[0] += 1
        else:
            x[0] += 2
        x = sorted(x)
        count += 1

    print(count)

if __name__=='__main__':
    main()


Measured memory_bytes: 3060
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! {
        n: usize,
        m: usize,
        xx: [i64;m]
    }
    let mut xx = xx;
    xx.sort();
    let mut v = Vec::new();
    for i in 0..m-1 {
        v.push(xx[i+1] - xx[i]);
    }
    v.sort();
    let p = std::cmp::max(m as i64 - n as i64, 0) as usize;
    println!("{}", v.iter().take(p).sum::<i64>());
}


Measured memory_bytes: 8444
// https://atcoder.jp/contests/abc069/tasks/abc069_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    cout << s.front() << s.length() - 2 << s.back() << endl;
    return 0;
}


Measured memory_bytes: 256
import math
def isPrime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False

    m = math.floor(math.sqrt(n)) + 1
    for p in range(3, m, 2):
        if n % p == 0:
            return False
    return True
ans = n = int(input())
while not isPrime(ans):
    ans += 1
print(ans)

Measured memory_bytes: 3064
/* Filename: ARC063C.java
 * Author: Mushiyo
 */

import java.util.Scanner;

public class Main{

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

		while (input.hasNext()) {
			String S = input.next();
			
			int countDiff = 0;
			for(int i = 1; i < S.length(); ++i){
				if(S.charAt(i) != S.charAt(i - 1)){
					++countDiff;
				}
			}
			
			System.out.println(countDiff);
		}
	}

}


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

using namespace std;

struct Position {
    int h, w, H, W;
    void next() {
        if (h%2 == 1 && w < W) w++;
        else if (h%2 == 0 && w > 1) w--;
        else if (h%2 == 1 && w == W) h++;
        else if (h%2 == 0 && w == 1) h++;
    }
};

int main() {
    Position pos;
    pos.h = 1; pos.w = 1;
    cin >> pos.H >> pos.W;

    int N; // 色の種類
    cin >> N;

    vector<int> a(N); // それぞれの色の個数
    for (int i = 0; i < N; i++) cin >> a[i];

    vector<vector<int>> ans(pos.H + 1, vector<int>(pos.W + 1)); // 1-indexed

    int cpos = 0; // 現在の色
    while (cpos < N) {
        ans[pos.h][pos.w] = cpos + 1;
        a[cpos]--;
        if (a[cpos] == 0) cpos++;
        pos.next();
    }

    for (int i = 1; i <= pos.H; i++) {
        for (int j = 1; j <= pos.W - 1; j++) {
            cout << ans[i][j] << ' ';
        }
        cout << ans[i][pos.W] << endl;
    }

    return 0;
}

Measured memory_bytes: 384
N = int(input())
l = [int(input()) for _ in range(N)]
largest = max(l)
largest_index = l.index(max(l))
second_largest = sorted(l)[-2]
second_largest_index = l.index(second_largest)

for idx, n in enumerate(l):
  if idx == largest_index:
    print(second_largest)
  else:
    print(largest)
  

Measured memory_bytes: 18944
using System;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(null).Select(s => int.Parse(s)).ToArray();
            UnionFind uni = new UnionFind(line[0]);
            var pro = Console.ReadLine().Split(null).Select(s => int.Parse(s)).ToArray();

            for (var i = 0; i < line[1]; i++)
            {
                var xy = Console.ReadLine().Split(null).Select(s => int.Parse(s)).ToArray();
                uni.Unite(xy[0] - 1, xy[1] - 1);
            }

            var ans = 0;

            for(var i = 0; i < line[0]; i++)
            {
                if (uni.Same(i, pro[i] - 1)) ans++;
            }

            Console.WriteLine(ans);
        }
    }

    public class UnionFind
    {
        private int[] par;
        private int[] rank;

        public UnionFind(int n)
        {
            par = new int[n];
            rank = new int[n];
            for(var i = 0; i < n; i++)
            {
                par[i] = i;
                rank[i] = 0;
            }
        }

        public int Root(int x)
        {
            return par[x] == x ? x : par[x] = Root(par[x]);
        }

        public bool Same(int x,int y)
        {
            return Root(x) == Root(y);
        }

        public void Unite(int x,int y)
        {
            x = Root(x);
            y = Root(y);
            if (x == y) return;

            if (rank[x] < rank[y])
            {
                par[x] = y;
            }
            else
            {
                par[y] = x;
                if (rank[x] == rank[y]) rank[x]++;
            }
        }
    }
}

Measured memory_bytes: 28128
n =int(input())
l = [list(map(int,input().split())) for i in range(n)]

dp = [[0 for i in range(3)] for j in range(n)]

for i in range(n):
  if i==0:
    dp[0]=l[0]
  else:
    dp[i][0]=max(dp[i][0],dp[i-1][1]+l[i][0],dp[i-1][2]+l[i][0])
    dp[i][1]=max(dp[i][1],dp[i-1][0]+l[i][1],dp[i-1][2]+l[i][1])
    dp[i][2]=max(dp[i][2],dp[i-1][0]+l[i][2],dp[i-1][1]+l[i][2])
print(max(dp[n-1]))

Measured memory_bytes: 103000
#include<cstdio>
#include<algorithm>
 
using namespace std;
 
const int MAX_N = 100000;
const int MAX_Q = 100000;
const long long UB = 1000000000;
 
long long A[MAX_N];
int N;
 
long long eSum[MAX_N], oSum[MAX_N];
long long sum[MAX_N];
 
bool lt(int x, int a, int b){
	if(b < 0 || b >= N) return true;
	if(a < 0 || a >= N) return false;
	long long d1 = abs(x - A[a]);
	long long d2 = abs(x - A[b]);
	if(d1 < d2) return true;
	if(d1 == d2) return a < b;
	return false;
}
 
long long calc(int r, int d){
	if(r < 0) return 0;
	if(d == 0) return eSum[r];
	else if(d == 1) return oSum[r];
	else return sum[r];
}
 
long long calc(int l, int r, int d){
	if(l > r) return 0;
	return calc(r, d) - calc(l - 1, d);
}
 
long long query(int x){
	int lb = 1, ub = N + 1;
	while(ub - lb > 1){
		int mid = (lb + ub) / 2;
		int a = mid / 2;
		int b = mid / 2;
		if(a + b < mid) a++;
		int l = N - mid;
		int r = N - a - 1;
		// take [l, r]
		if(lt(x, r + 1, l)) ub = mid;
		else lb = mid;
	}
	// lb cards: no conflict
	int a = (lb + 1) / 2;
	int d = N % 2;
	long long ans = calc(0, N - lb - 1, d) + calc(N - lb, N - a - 1, -1);
	return sum[N - 1] - ans;
}
 
int main(){
	int Q;
	scanf("%d%d", &N, &Q);
	for(int i = 0; i < N; ++i) scanf("%lld", A + i);
	sum[0] = A[0];
	for(int i = 1; i < N; ++i) sum[i] = sum[i - 1] + A[i];
	eSum[0] = A[0];
	for(int i = 1; i < N; ++i) eSum[i] = eSum[i - 1] + (i % 2 == 0 ? A[i] : 0);
	oSum[0] = 0;
	for(int i = 1; i < N; ++i) oSum[i] = oSum[i - 1] + (i % 2 == 1 ? A[i] : 0);
	for(int i = 0; i < Q; ++i){
		long long x;
		scanf("%lld", &x);
		long long ans = query(x);
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 4948
N, Q = map(int, input().split())
S=list(input())
Snum=list()
Snum.append(0)
Snum.append(0)
for i in range(1,N):
  if S[i]=="C" and S[i-1]=="A":
    Snum.append(Snum[i]+1)
  else:
    Snum.append(Snum[i])
for i in range(Q):
  L,R=map(int, input().split())
  print(Snum[R]-Snum[L])

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

#define INF 1000000007

int main(void){
  vector<int> v;
  int n,q,b,e;
  
  cin >> n;
  for (int i=0; i<n; i++){
    int t; cin >> t;
    v.push_back(t);
  }
  cin >> q;
  for (int i=0; i<q; i++){
    cin >> b >> e;
    reverse(v.begin()+b, v.begin()+e);
  }
  cout << v[0];
  for (int i=1; i<v.size(); i++){
    cout << " " << v[i];
  } cout << endl;
  return 0;
}
  
  



Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n[6];
  for(int i=0; i<6; i++)
    cin>>n[i];
  sort(n,n+6);
  if(n[1]==n[2] && n[3]==n[4])
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
  return 0;
}
	

Measured memory_bytes: 256
#%%
a,b = input().split()

def alphabet(x):
  if x == 'A':
    return 10
  elif x == 'B':
    return 11
  elif x == 'C':
    return 12
  elif x == 'D':
    return 13
  elif x == 'E':
    return 14
  else:
    return 15

a = alphabet(a)
b = alphabet(b)

if a>b:
  print('>')
elif a<b:
  print('<')
else :
  print('=')

Measured memory_bytes: 3064
import java.util.*
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }
fun main(args:Array<String>){
  var n = nextInt()
  var a = listOfInt()
  var deq = ArrayDeque<Int>()
  for(i in 0..n-1){
    if(i%2==0) deq.addFirst(a[i])
    else deq.addLast(a[i])
  }
  for(i in 0..n-1){
    var tmp = 0
    if(n%2==0){
      tmp = deq.removeLast()
    }else{
      tmp = deq.removeFirst()
    }
    print(tmp.toString()+" ")
  }
  println()
}


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

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

    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    for (int i = 0; i < N; i++)
    {
        cin >> L[i];
    }

    int ans = 1;
    int now = 0;
    for (int i = 0; i < N; i++)
    {
        now += L[i];
        if (now <= X)
        {
            ans++;
        }
        else
        {
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<fstream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

    // input
    string s;
    cin >> s;

    ll max_count = 0;
    ll count = 0;
    for(char c : s){
        if(c=='A' || c=='G' || c=='C' || c=='T'){
            count++;
        }else{
            max_count = max(max_count, count);
            count = 0;
        }
    }
    max_count = max(max_count, count);

    p(max_count);

    return 0;
}

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

using namespace std;typedef long long ll;
#define DRP(t,a,b) for(register int t=(a),edd=(b);t>=edd;--t)
#define RP(t,a,b)  for(register int t=(a),edd=(b);t<=edd;++t)
#define ERP(t,a)   for(register int t=head[a];t;t=e[t].nx)
#define midd register int mid=(l+r)>>1
#define TMP template < class ccf >
#define lef l,mid,pos<<1
#define rgt mid+1,r,pos<<1|1
#define pushup(pos) (seg[pos]=seg[pos<<1]+seg[pos<<1|1])
TMP inline ccf qr(ccf b){
    register char c=getchar();register int q=1;register ccf x=0;
    while(c<48||c>57)q=c==45?-1:q,c=getchar();
    while(c>=48&&c<=57)x=x*10+c-48,c=getchar();
    return q==-1?-x:x;}
TMP inline ccf Max(ccf a,ccf b){return a<b?b:a;}
TMP inline ccf Min(ccf a,ccf b){return a<b?a:b;}
TMP inline ccf Max(ccf a,ccf b,ccf c){return Max(a,Max(b,c));}
TMP inline ccf Min(ccf a,ccf b,ccf c){return Min(a,Min(b,c));}
TMP inline ccf READ(ccf* _arr,int _n){RP(t,1,_n)_arr[t]=qr((ccf)1);}
//----------------------template&IO---------------------------
const int maxn=3e3+15;
const ll mod=1e9+7;
ll dp[maxn][maxn][2];
ll ans;
#define md(x) ((x)%mod)
#define add(x,y) ((x)=md((x)+(y)))

int n,m;
inline void wk(){
    dp[1][0][1]=dp[1][1][1]=1;
    RP(t,1,n) dp[1][t][0]=2;
    RP(t,1,m){
	RP(i,0,n){
	    //取两个白
	    if(i<n){
		if(i){
		    dp[t+1][i+1][0]=md(dp[t+1][i+1][0]+dp[t][i][0]);
		    dp[t+1][i+1][1]=md(dp[t+1][i+1][1]+dp[t][i][1]);
		}
		else dp[t+1][i+1][1]=md(dp[t+1][i+1][1]+dp[t][i][0]+dp[t][i][1]);
	    }
	    //取两个黑色
	    if(i){
		if(i-1){
		    dp[t+1][i-1][0]=md(dp[t+1][i-1][0]+dp[t][i][0]);
		    dp[t+1][i-1][1]=md(dp[t+1][i-1][1]+dp[t][i][1]);
		}
		else dp[t+1][i-1][1]=md(dp[t+1][i-1][1]+dp[t][i][0]+dp[t][i][1]);
	    }
	    //一黑一白
	    if(i){
		dp[t+1][i][0]=md(dp[t+1][i][0]+(dp[t][i][0]<<1));
		dp[t+1][i][1]=md(dp[t+1][i][1]+(dp[t][i][1]<<1));
	    }
	    else dp[t+1][i][1]=md(dp[t+1][i][1]+dp[t][i][0]);
	}
    }
}

inline void wk2(){
    
    dp[1][0][1]=1;
    RP(t,1,n) dp[1][t][0]=1;
    RP(t,1,m){
	RP(i,0,n){
	    if(i){
		add(dp[t+1][i-1][1],dp[t][i][1]);
		add(dp[t+1][i][1],dp[t][i][1]);
		if(i==1) add(dp[t+1][i-1][1],dp[t][i][0]),add(dp[t+1][i][1],dp[t][i][0]);
		else add(dp[t+1][i-1][0],dp[t][i][0]),add(dp[t+1][i][0],dp[t][i][0]);
		
	    }
	    if(i<n){
		add(dp[t+1][i+1][0],dp[t][i][0]);
		add(dp[t+1][i+1][1],dp[t][i][1]);
		
		add(dp[t+1][i][0],dp[t][i][0]);
		add(dp[t+1][i][1],dp[t][i][1]);
	    }
	}
    }
}

int main(){
    
    n=qr(1);m=qr(1);
    wk2();    
    RP(t,0,n) ans=md(ans+dp[m+1][t][1]);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 141568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long c_max = 1000003;
const long long mod = 1e9+7;
long long fac[c_max], finv[c_max], inv[c_max];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long long i = 2; i < c_max; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
// 二項係数計算
long long COM(long long comn, long long comk){
    if (comn < comk) return 0;
    if (comn < 0 || comk < 0) return 0;
    return fac[comn] * (finv[comk] * finv[comn - comk] % mod) % mod;
}
int main() {
    COMinit();
    // your code goes here
    ll n,k,i,j,a[100005],ans1=0,ans2=0,m;
    cin >> n >> k;
    for(i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a,a+n);
    for(i=0;i<n;i++){
        m=COM(n-i-1,k-1);
        m=(m*a[i])%mod;
        ans1=(ans1+m)%mod;
    }
    for(i=0;i<n;i++){
        m=COM(i,k-1);
        m=(m*a[i])%mod;
        ans2=(ans2+m)%mod;
    }
    cout << (ans2-ans1+2*mod)%mod << endl;
    return 0;
}

Measured memory_bytes: 24448
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int h,w;
    cin>>h>>w;
    string s[h];
    for(int i=0;i<h;i++)
    {
        cin>>s[i];
    }
    int c=w+2;
    for(int i=0;i<c;i++)
    {
        cout<<"#";
    }
    cout<<endl;
    for(int i=0;i<h;i++)
    {
        cout<<"#"<<s[i]<<"#"<<endl;
    }
    for(int i=0;i<c;i++)
    {
        cout<<"#";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
import numpy as np
def main():
    N,M = map(int, input().split())
    Aij = [list(map(int, input().split())) for i in range(N)]
    
    Aij.sort()
    
    Ai = [ Aij[i][0] for i in range(N)]
    Aj = [ Aij[i][1] for i in range(N)]
    
    a = np.cumsum(Aj)
    num = 0
    dif = 0
    for i in range(N):
        if a[i] >= M:
            num = i
            if i == 0:
                dif = M
                break
            dif = M - a[i-1]
            break

    i = 0
    gokei = 0
    for i in range(num+1):
        if i == num:
            #print(Ai[i],5555)
            gokei = gokei + Ai[i]*dif
            break
        gokei = gokei + Ai[i]*Aj[i]
        
    print(gokei)
    
    
main()

Measured memory_bytes: 40016
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second

void solve(){ 
	int ans1=0,ans2=0; 
	string s;
	cin>>s;
	rep(i,0,sz(s)){
		if(i%2){
			if(s[i]=='0')
				++ans1;
			else ++ans2;
		}
		else{
			if(s[i]=='1'){
				++ans1;
			}
			else ++ans2;
		}
	}
	cout<<min(ans1,ans2)<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int main(){
	int k, s, qnt = 0;
	scanf("%d%d", &k, &s);
	for(int x = 0; x <= k; ++x){
		for(int y = 0; y <= k; ++y){
			int z = s - x - y;
			//printf("%d %d %d\n", x, y, z);
			if(z >=0 && z <= k)qnt++;
		}
	}
	printf("%d\n", qnt);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

int extgcd(int a, int b, int &x, int &y){
    int d = a;
    if(b != 0){
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else{
        x = 1;
        y = 0;
    }
    return d;
}

signed main(){

    int A, B, C, D; cin >> A >> B >> C >> D;
    A = llabs(A - C);
    B = llabs(B - D);
    if(A == 0 || B == 0){
        cout << 0 << endl;
        return 0;
    }

    int x, y;
    int g = extgcd(A, B, x, y);
    A /= g;
    B /= g;
    int ans = g * (A + B - 1);
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;

typedef pair<int,int> P;

signed main(){
	int n,p,q,c[500000],sum = 0,ma;
	vector<P> vec;
	cin >> n >> p >> q;
	for(int i = 0;i < n;i++){
		cin >> c[i];
		sum += c[i];
		vec.push_back(P(p * (q - i) - c[i],i));
	}
	ma = sum;
	sort(vec.begin(),vec.end(),greater<P>());
	for(int i = 1;i <= n;i++){
		sum += vec[i - 1].first;
		ma = max(ma,sum + p * i * (i - 1));
	}
	cout << ma << endl;
	return 0;
}

Measured memory_bytes: 14796
s = list(input())
n = len(s)
a = s[0]
b = s[1]

ans = 0
i = 1
while i < n:
    j = 0
    while i+j < n: 
        if b == a:
            j += 1
            if i+j < n:
                b += s[i+j]
            else:
                i = n
                break
        else:
            if i+j < n:
                i += j+1
                a = b
                if i < n:
                    b = s[i]
                ans += 1
            break
print(ans+1)

Measured memory_bytes: 62960
def f(S, K):
    if K == 0: return 0
    cnt = 0
    p = ''
    for i, s in enumerate(S):
        if p == s:
            cnt += 1
            p = ''
        else:
            p = s
    cnt *= K
    if p == S[0]:
        cnt += K - 1
    return cnt


if __name__ == '__main__':
    S = input()
    K = int(input())
    cnt1 = 0
    cnt2 = 0

    if len(S) % 2 == 1 and K > 1:
        S2 = S * 2
        K2 = K // 2
        cnt1 = f(S2, K2)

        S2 = S[::-1] * 2
        cnt2 = f(S2, K2)

        K = K % 2
    cnt1 += f(S, K)
    cnt2 += f(S[::-1], K)

    print(min(cnt1, cnt2))

Measured memory_bytes: 3064
N=int(input())
s=[input() for _ in range(N)]
cnt=0

A_count=0
B_count=0
BA_count=0
for u in s:
    cnt+=u.count("AB")
    if u[0]=="B":
        B_count+=1
    if u[-1]=="A":
        A_count+=1
    if u[0]=="B" and u[-1]=="A":
        BA_count+=1
if A_count==B_count==BA_count:
    if A_count==0:
        print(cnt)
    else:
        print(cnt+A_count-1)
else:
    print(cnt+min(A_count,B_count))

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    string s;
    cin>>s;
    int flg1 = (s[0]=='A');
    int flg2 = (count(s.begin()+2,s.end()-1,'C')==1);
    int cnt = 0;
    for(int i=0;i<s.size();++i)
        if(isupper(s[i]))
            cnt++;
    int flg3 = (cnt==2);
 
    (flg1 && flg2 && flg3 )?cout<<"AC":cout<<"WA";
    return 0;
}   

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

int main() {
  long long h;
  cin >> h;
  
  long long i = 0, ans = 0;
  while (h > 0) {
    h /= 2;
    ans += pow(2, i);
    i++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#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)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
template<class T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*(._.)*/
int main(){
	ll N,K;
	cin >> N >> K;
	vector<ll> A(N);
	ll purec = 0;
	ll rcount = 0;
	ll ncount = 0;

	REP(i,N){
	    cin >> A[i];
	}
	REP(i,N){
	    REP(j,N){
	        if (i >= j) continue;
	        if (A[i] > A[j]) purec++;
	        purec = purec % MOD;
	    }
	    //cout << purec << endl;
	}

	REP(i,N){
		REP(j,N){
			if (A[i] > A[j]) ncount++;
			ncount = ncount % MOD;
		}
	}


	REP(i,N){
		FORq(j,i+1,2*N-1){
			if (A[i] > A[j%N]) rcount++;
			rcount = rcount % MOD;
		}
	}

	ll ans = 0;
	ans = (K * purec) % MOD + ((ncount % MOD) * (((K * (K-1)) / 2) % MOD)) % MOD;
	ans = ans % MOD;
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
vector<lint> v;
int a[100100],b[100100];
int main()
{
	int n;lint sum=0,s2=0;
	cin>>n;
	rep(i,n) cin>>a[i];
	rep(i,n) cin>>b[i];
	rep(i,n){
		if(a[i]>=b[i]) v.pb(a[i]-b[i]);
		sum+=a[i]-b[i];
	}
	sort(All(v));
	if(sum<0){
		cout<<-1<<endl;return 0;
	}
	int out=0;
	rep(i,v.size()){
		s2+=v[i];
		if(s2<=sum) out=max(out,i+1);
	}
	cout<<n-out<<endl;
}


Measured memory_bytes: 2168
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"c=[list(map(int,input().split()))for _ in range(3)]\n"
"for i in range(c[0][0]+1):\n"
"    b=[c[0][0]-i,c[0][1]-i,c[0][2]-i]\n"
"    a=[i,c[1][0]-b[0],c[2][0]-b[0]]\n"
"    t=1\n"
"    for j in range(3):\n"
"        for k in range(3):\n"
"            if c[j][k]!=a[j]+b[k]:\n"
"                t=0\n"
"                break\n"
"    if t:\n"
"        print('Yes')\n"
"        exit()\n"
"print('No')\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 3280
N = int(input())
a = [int(input()) for _ in range(N)]
hist = [0] * N
bottun = a[0]
cnt = 1
hist[0] = 1

while True:
    # print(hist)
    # print(bottun)
    if hist[bottun-1] == 1:
        print(-1)
        exit()
    
    if bottun == 2:
        print(cnt)
        exit()
    
    hist[bottun-1] = 1
    bottun = a[bottun-1]
    cnt += 1


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

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

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())
#define END cout<<"\n"

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)    for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 200;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//


signed main(){
    CIN(N,M);
    vector<bool> broken(N+1,false);
    rep(i,M){
        CIN(a);
        broken[a]=true;
    }
    vector<ll> dp(N+1);
    dp[0]=1;
    rep(i,N){
        RepS(j,i+1,min(N,i+2)){
            if(!broken[j]){
                dp[j]+=dp[i];
                dp[j]%=MOD;
            }
        }
    }
    printf("%lld\n",dp[N]);    

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main {

    static int n = 0;
    static int q = 0;
    static int[] A;
    static int[] w;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        A = new int[n];
        for(int i = 0; i < n; i++) {
            A[i] = sc.nextInt();
        }

        q = sc.nextInt();
        w = new int[q];
        for(int i = 0; i < q; i++) {
            w[i] = sc.nextInt();
        }

        for(int i = 0; i < q; i++) {
            if(ExhaustiveSearch(A, w[i], n))
                System.out.println("yes");
            else
                System.out.println("no");
        }
    }

    public static int[] InsertionSort(int[] input, int length) {
		for(int i = 1; i <= length - 1; i++) {
			int key = input[i];
			int j = i - 1;

			while(j >= 0 && input[j] > key) {
				input[j + 1] = input[j];
				j--;
			}
			input[j + 1] = key;
		}
		return input;
	}

    public static boolean ExhaustiveSearch(int[] A, int w, int q) {
        for(int i = 1; i < Math.pow(2, q+1); i++) {
            int tmp = 0;
            for(int j = 0; j < q; j++) {
                int buf = A[j] * ((i & (1 << j)) >> j);
                tmp += buf;
            }
            if(tmp == w) return true;
        }
        return false;
    }
}



Measured memory_bytes: 26864
# coding: utf-8

Node = list()
n = int(input())

def insertKey(k):
    idx = len(Node)
    Node.append([k, -1, -1])
    if idx > 0:
        pPrv = -1
        pTmp = 0
        while pTmp != -1:
            pPrv = pTmp
            if k < Node[pTmp][0]:
                pTmp = Node[pTmp][1]
            else:
                pTmp = Node[pTmp][2]
        if Node[-1][0] < Node[pPrv][0]:
            Node[pPrv][1] = idx
        else:
            Node[pPrv][2] = idx

def inOrder(num):
    if num == -1:
        return
    inOrder(Node[num][1])
    print(' {}'.format(Node[num][0]), end = '')
    inOrder(Node[num][2])

def preOrder(num):
    if num == -1:
        return
    print(' {}'.format(Node[num][0]), end = '')
    preOrder(Node[num][1])
    preOrder(Node[num][2])

for i in range(n):
    temp = input().strip()
    if temp[:6] == 'insert':
        insertKey(int(temp[7:]))
    else:
        inOrder(0)
        print('')
        preOrder(0)
        print('')


Measured memory_bytes: 85244
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
using tiii = tuple<int, int, int>;
using pii = pair<int, int>;

int main()
{
    int n, q;
    cin >> n >> q;

    vector<tiii> events;
    rep(i, 0, n)
    {
        int s, t, x;
        cin >> s >> t >> x;
        events.emplace_back(x, s - x, t - x);
    }
    sort(events.begin(), events.end());
    
    set<pii, less<pii>> starts;
    rep(i, 0, q)
    {
        int d;
        cin >> d;
        starts.insert(make_pair(d, i));
    }

    vector<int> ans(q, -1);
    for (auto event: events)
    {
        int x, s, t;
        tie(x, s, t) = event;

        set<pii>::iterator it = starts.lower_bound(make_pair(s, 0));
        while (it != starts.end())
        {
            int d, i;
            tie(d, i) = *it;
            // cout << "**" << endl;
            if (d >= t) break;

            ans[i] = x;
            starts.erase(it++);
        }
    }
    rep(i, 0, q)
        cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 15088
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;
 
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
 
const double EPS = 1e-10;
 
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
    int n,m,x; cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n,vector<int>(m));
    rep(i,n){
        cin >> c[i];
        rep(j,m){
            cin >> a[i][j];
        }
    }
    int ans = INF;
    rep(i,1<<n){
        vector<int> now(m);
        int nowans = 0;
        rep(j,n){
            if(i>>j&1){
                nowans += c[j];
                rep(k,m){
                    now[k] += a[j][k];
                }
            }
        }
        bool ok = true;
        rep(j,m){
            if(now[j] < x){
                ok = false;
            }
        }
        if(ok) ans = min(ans,nowans);
    }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 3636
A, B, C, D = map(int, input().split())

MOD = 998244353

dp0 = [[0] * (D + 1) for _ in range(C + 1)]
dp1 = [[0] * (D + 1) for _ in range(C + 1)]


dp0[A][B] = 1

for x in range(A, C + 1):
    for y in range(B, D + 1):
        if x == A and y == B:
            continue
        dp0[x][y] = (dp0[x][y - 1] * x + dp1[x][y - 1] * 1) % MOD
        dp1[x][y] = (dp0[x - 1][y] * y + dp1[x - 1][y] * y) % MOD

# print (dp0)
# print (dp1)        

ans = (dp0[C][D] + dp1[C][D]) % MOD
print (ans)

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

typedef long long ll;
typedef long double ld;
// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// use merge(all(vec1), all(vec2), vec3.begin()) to merge 2 vectors, use vec3.resize(vec1.size() + vec2.size()) first
// ll pos = partition_point(all(vec), pred) - vec.begin(); bool pred(ll a){return a<3};
// print number in binary -> cout << bitset<20>(n);

int res,ch[6],cw[6];
char f[6][10];
int main(){
	int h,w,k;cin>>h>>w>>k;
	for(int i=0;i<h;++i)cin>>f[i];
	for(int i=0;i<(1<<h+w);++i){
		memset(ch,0,sizeof(ch));
		memset(cw,0,sizeof(cw));
		for(int j=0;j<h;++j)
			if(i&(1<<j))ch[j]=true;
		for(int j=0;j<w;++j)
			if(i&(1<<j+h))cw[j]=true;
		int cnt=0;
		for(int j=0;j<h;++j)
			for(int kk=0;kk<w;++kk)
				if(!ch[j]&&!cw[kk]&&f[j][kk]=='#')++cnt;
		if(cnt==k)++res;
	}
	cout<<res<<endl;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n;
map<int, int> mp;

int ask(int p) {
	if(mp.count(p) == 1) { return mp[p]; }
	
	cout << p << endl;
	string s;
	cin >> s;
	if(s[0] == 'V') { exit(0); }
	if(s[0] == 'M') { mp[p] = 1; }
	if(s[0] == 'F') { mp[p] = 0; }
	return mp[p];
}

int main() {
	cin >> n;
	
	int l = 0;
	int h = n - 1;
	while(true) {
		int m = (l + h) / 2;
		int ll = ask(l);
		int hh = ask(h);
		int mm = ask(m);
		assert((h - l) % 2 != (hh + ll) % 2);
		((m - l) % 2 == (mm + ll) % 2 ? l : h) = m;
	}
	
	return 0;
}


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

int main()
{
int N;cin>>N;
string S;cin>>S;
  int count=0;
  for(int i=0;i<N-2;i++)
  {
   if(S.substr(i,3)=="ABC")
   {
    count++;
   }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 764
#include <stdio.h>

int main(void){
    long ans[98] = {61,230,865,3247,12185,45719,171531,643550,2414454,9058467,33985227,127504505,478366600,794717734,733354121,261943303,776803305,580025381,51688048,44657419,737209731,604119499,159693437,858533109,639056669,549054109,996291083,531294469,23314687,783022045,855462856,649970414,68697295,409213624,604356692,88638656,978442997,534833116,763737161,785892908,123883652,639213333,181836645,998121103,124885216,501575626,39816123,113468411,799008836,775465589,256852905,664630886,971550783,751629411,51018086,702530485,725438992,696683714,792638194,221791721,149602322,414054379,986519078,981760191,305799096,515140586,406959393,975058685,245601370,324759692,673385295,191483611,570246669,427196161,781042769,569725155,842176273,25328739,847501730,206282374,353770801,323137024,371653459,940737264,123820509,915711339,847205021,252858375,718889563,866398347,738390145,133009077,333099663,170591295,329869205,616680192,597534442,388130742};
    int n;
    scanf("%d",&n);
    printf("%d\n",ans[n - 3]);
    return 0;
}

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

const ll INF = -1e16+7;

struct edge{
    int from;
    int to;
    int c;
};

bool bellman_ford(const ll &s,const ll &V,const ll &E,const vector<edge> &ed, vector<ll> &d){

    // s=スタート, Vが頂点数，Eが辺の数, ed=どのようなパスを持つか, 
    //d=答えを保持するvector．今は１つの経路が欲しいので参照して書き換えているが全ての経路について必要になった場合にはdをreturnするように改造する

    // 初期化
    for(ll i = 0; i < V+1; i++){
        d[i] = INF;
    }

    d[s] = 0;
    ll num = 0;
    while(true){
        if(num>=V){
            return false;
        }
        //updateが更新されなくなるまでこの操作を繰り返す
        bool update = false;
        for(ll i = 0; i < E; i ++){
            edge e = ed[i];
            if(d[e.from]!=INF && d[e.to]<d[e.from]+ e.c){  // 更新条件を変更
                if(e.to==V && d[V]!=INF){
                    return true;
                }
                d[e.to] = d[e.from]+ e.c;
                update = true;
            }
        }
        if(!update){
            break;
        }

        num ++;
    }
    return false;
}


int main(){

    ll V,E; cin >> V >> E;
    vector<edge> ed(E);
    rep(i,E){
        cin >> ed[i].from >> ed[i].to >> ed[i].c;
    }
    vector<ll> d(V+5); // スタートの頂点番号を0ではなく１としたいので余分に作ってd[0]は使わない
    bool loop = bellman_ford(1, V, E, ed, d);

    if(loop){
        cout << "inf" << endl;
    }else{
        cout << d[V] << endl;
    }

    return 0;
}

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

int main () {
    int n;
    
    scanf("%d", &n);
    
    printf("%d", n * 800 - 200 * (n / 15));
    
}

Measured memory_bytes: 128
import java.util.*;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		ln(sc.nextLine().toUpperCase());
	}

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

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
import unittest


def solve(n):
    used = set()
    total = 0
    for i in range(1, int(n ** 0.5)+1):
        if n % i > 0:
            continue
        d = n // i
        cand = [i-1, d-1]
        for c in cand:
            if c not in used and c > 0 and n % c == n // c:
                total += c
                used.add(c)

    return total


def main():
    n = int(input())
    result = solve(n)
    print(result)


if __name__ == "__main__":
    main()


class Test(unittest.TestCase):
    def test_solve_1(self):
        n = 8
        actual = solve(n)
        expected = 10
        self.assertEqual(actual, expected)

    def test_solve_2(self):
        n = 1000000000000
        actual = solve(n)
        expected = 2499686339916
        self.assertEqual(actual, expected)


Measured memory_bytes: 5880
#include <iostream>
#include <array>
#include <vector>
#include <map>
#include <utility>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <string>
#include <limits.h>

using namespace std;

//
//int mid(int a,int b, int c ){
//    if ((a <= b && b <= c) || (a >= b && b >= c)) {
//        return b;
//    }
//    if ((b <= c && c <= a) || (b >= c && c >= a)) {
//        return c;
//    }
//    if ((b <= a && a <= c) || (b >= a && a >= c)) {
//        return a;
//    }
//    return 0;
//    
//}
//
//int main(){
//    
//    static const int N = 4;
//    vector<int> ini;
//    for (int i = 1; i <= 2*N-1; i++) {
//        ini.emplace_back(i);
//    }
//    
//    while (true) {
//        random_shuffle(ini.begin(), ini.end());
//        
//        vector<int> at= ini;
//        while (at.size()  > 1) {
//            vector<int> ne;
//            for (int i = 0; i < at.size()-2; i++) {
//                ne.push_back(mid(at[i], at[i+1], at[i+2]));
//            }
//            at = ne;
//        }
//        
//        cout << at[0] <<endl;
//        
//        
//    }
//    
//    return 0;
//}



int main(){
    int N, x;
    cin >> N>>x;
    
    if (N==x) {
        cout<<"Yes"<<endl;
        for (int i = 0; i < 2*N-1; i++) {
            cout<<i+1 << endl;
        }
    }else if(x == 2*N-2){
        cout<<"Yes"<<endl;
        //半分
        for (int i = 0; i < N - 1; i++) {
            cout << i + 1 <<endl;
        }
        for (int i = 2*N-1; i >= N ; i--) {
            cout << i  <<endl;
        }
    }else if(x > N && x != 2*N-1){
        cout<<"Yes"<<endl;
        //半分
        for (int i = 0; i < N - 1; i++) {
            cout << i + 1 <<endl;
        }
        cout << x<< endl;
        
        for (int i = 2*N-1; i >= N ; i--) {
            if (i!= x) {
                cout << i  <<endl;
            }
        }
    }else if(x == 2){
        cout<<"Yes"<<endl;
        //半分
        for (int i = 2*N-1; i >N; i--) {
            cout << i <<endl;
        }
        for (int i = 1; i <= N ; i++) {
            cout << i  <<endl;
            
        }
    }else if(x < N && x!= 1){
        cout<<"Yes"<<endl;
        //半分
        for (int i = 2*N-1; i >N; i--) {
            cout << i  <<endl;
        }
        cout << x << endl;
        
        for (int i = 1; i <= N ; i++) {
            if (i!= x) {
                cout << i  <<endl;
            }
        }
    }else{
        cout<< "No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 1664