akhauriyash/Code-Regression huggingface dataset:
extern crate core;

use std::fmt;
use std::cmp::{Ordering, min, max};
use std::fmt::{Display, Error, Formatter};
use std::ops::{Index, IndexMut, Add, AddAssign, Sub, SubAssign, Mul, MulAssign};
use std::collections::VecDeque;
use std::f32::MAX;

fn show<T: Display>(vec: &Vec<T>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        print!("[{}", vec[0]);
        for i in 1 .. vec.len() {
            print!(", {}", vec[i]);
        }
        println!("]");
    }
}
macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (' ') => {
        read_line!(delimiter: ' ')
    };
    ($delimiter:expr) => {
        read_line!(delimiter: $delimiter)
    };
    (' '; $ty:ty) => {
        read_line!().split_whitespace().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
    ($delimiter:expr; $ty:ty) => {
        read_line!($delimiter).into_iter().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
}
macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}


fn main() {
    loop {
        let_all!(n: usize, w: usize);
        if n == 0 && w == 0 {
            return
        }
        let mut appear = vec![0; (99 + w) / w + 1];
        let mut max_v = 0;
        for _ in 0 .. n {
            let_all!(v: usize);
            if max_v < v / w {
                max_v = v / w;
            }
            appear[v / w] += 1;
        }
        let mut max = 0;
        for &i in &appear {
            if max < i {
                max = i;
            }
        }
        let max = max as f64;
        let diff = 1_f64 / max_v as f64;
        let mut result = 0.01_f64;
        for i in 0 .. max_v + 1 {
            result += appear[i] as f64 / max * (max_v - i) as f64 * diff;
        }
        println!("{:.*}", 10, result);
    }
}


Measured memory_bytes: 5056
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int H=scan.nextInt();
		int W=scan.nextInt();

		String[][] result = new String[H+2][W+2];

		for(int i=0;i<H+2;i++){
			for(int j=0;j<W+2;j++){

				result[i][j]="#";


			}
		}


		String[] sub = new String[H];
		for(int i=0;i<H;i++){
			sub[i]=scan.next();
			for(int j=0;j<W;j++){
				result[i+1][j+1]=sub[i].substring(j, j+1);
			}


		}

		for(int i=0;i<H+2;i++){
			for(int j=0;j<W+2;j++){

				System.out.print(result[i][j]);


			}
			System.out.println();
		}
	}

}


Measured memory_bytes: 24252
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        long X = long.Parse(Console.ReadLine());
        double t = (Math.Sqrt(X * 8 + 1) - 1) / 2;
        Console.WriteLine((int)Math.Ceiling(t));
    }
}


Measured memory_bytes: 13140
#include<cstdio>
#include<cstring>
#include<algorithm>
int n;
char s[210];
template<class T>
inline void read(T&a){
	char c=getchar();
	for(a=0;c<'0'||c>'9';c=getchar());
	for(;c>='0'&&c<='9';c=getchar())a=a*10+c-'0';
}
int main(){
	scanf("%s",s+1),n=strlen(s+1);
	for(int i=(n>>1)-(!(n&1));i;i--){
		bool f=1;
		for(int j=1;j<=i;j++)
			if(s[j]!=s[j+i]){f=0;break;}
		if(f){printf("%d\n",i<<1);return 0;}
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using lint = long long;
using namespace std;

const int MOD = 1000000007;
const lint INF = 1LL << 60;

const double PI = acos(-1);
const double Rad2Deg = 180.0 / PI;
const double Deg2Rad = PI / 180.0;

int main() {
    int N;
    cin >> N;
    vector<lint> L(N);
    rep(i, N) cin >> L[i];

    int ans = 0;
    sort(L.begin(), L.end());

    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            int right = lower_bound(L.begin(), L.end(), L[i] + L[j]) - L.begin();
            ans += max(0, right - j - 1);
        }
    }

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


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
 
 
const ll INF = 1e18;
const ll N =(1e4+5); // TODO : change value as per problem
const ll MOD = 1e9+7;
void solve(){
    string s;
    cin >>s;
    ll ans =0;
    string t = "CODEFESTIVAL2016";
    for(int i =0;i<16;i++){
        if(s[i] != t[i])ans++;
    }    
    cout<<ans<<endl;
}

signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    

 
     ll tt=1;   
    while(tt--){    
        solve();
    }    
}

Measured memory_bytes: 3652
#include <stdio.h>
int main(){
	int h,w,i,j;
	while(1){
		scanf("%d %d\n",&h,&w);
		if(h==0 && w==0)	break;
		for(i=1;i<=h;i++){
			for(j=1;j<=w;j++){
				if(i==1 || i==h ||j==1 || j==w){
					printf("#");
				}else{
					
						printf(".");
				}

			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2032
import java.util.*;
public class Main {

	static int N;
	static long K, INF = 1_000_000_000_000_000_001L;
	static long[] A;
	
	static boolean ok(long X) {
		long c = 0;
		for(int i = 0; i < N; i++) {
			int lb = -1, ub = N, mid;
			while(lb + 1 < ub) {
				mid = (lb + ub) / 2;
				if(A[i] * A[mid] < X) {
					if(A[i] < 0)
						ub = mid;
					else
						lb = mid;
				}
				else {
					if(A[i] < 0)
						lb = mid;
					else
						ub =  mid;
				}
			}
			if(A[i] < 0)
				c += N - ub;
			else
				c += ub;
			if(A[i] * A[i] < X)
				c--;
		}
		return c / 2 < K;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		K = sc.nextLong();
		A = new long[N];
		Arrays.setAll(A, i -> sc.nextInt());
		Arrays.sort(A);
		long lb = -INF, ub = INF, mid;
		while(lb + 1 < ub){
			mid = (lb + ub) / 2;
			if(ok(mid))
				lb = mid;
			else
				ub = mid;
		}
		System.out.println(lb);
	}

}

Measured memory_bytes: 92292
import sys
from itertools import combinations

def main():
    input = sys.stdin.readline
    N = int(input())
    cord = set()
    for _ in range(N):
        x, y = map(int, input().split())
        cord.add((x, y))

    if N <= 2:
        return 1

    ans = 50
    for a in combinations(cord, 2):
        x1, y1 = a[0]
        x2, y2 = a[1]

        p = x2 - x1
        q = y2 - y1

        cnt1 = 0
        cnt2 = 0

        if p == q == 0:
            continue

        A = set()
        B = set()
        for x, y in cord:
            A.add((x-p, y-q))
            B.add((x+p, y+q))

        ans = min(ans, len(A - cord), len(B - cord))

    return ans


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3064
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int A = sc.nextInt();
		int B = sc.nextInt();
		if (A >= 13)
			System.out.println(B);
		else if (A >= 6)
			System.out.println(B / 2);
		else
			System.out.println(0);

	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 21972
#include<stdio.h>
#define MAX 100005
#define NIL -1
  
struct Node{ int p, l, r;};
struct Node T[MAX];
int n, H, D[MAX];
int getDepth(int);
void print(int);


  
int main(){
  int i, j, d, v, c,l,r;
    
  scanf("%d",&n);
    
  for ( i = 0; i < n; i++ ) {
    T[i].p = T[i].l = T[i].r = NIL;
  }
    
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &v, &d);
    for ( j = 0; j < d; j++ ){
      scanf("%d", &c);
      T[c].p = v;
        
      if(j == 0) T[v].l = c;
        
      else if (j >= 1)
	T[r].r = c;
      r = c;
    }
  }
    
  
  for ( i = 0; i < n; i++ ){
    D[i] = getDepth(i);
  }
  
  for ( i = 0; i < n; i++ ) print(i);
  return 0;
}


int getDepth(int u){
  int d = 0;
  
  while(T[u].p >= 0){
    u = T[u].p; 
    d++;
  }
  
  return d;
}
  
void print(int u){
  if(T[u].p == NIL)
    printf("node %d: parent = %d, depth = %d, root, ",u,T[u].p,D[u]);
    
  else if(T[u].l == NIL)
    printf("node %d: parent = %d, depth = %d, leaf, ",u,T[u].p,D[u]);
    
    
  else printf("node %d: parent = %d, depth = %d, internal node, ",u,T[u].p,D[u]);
    
    
  printf("[");
  int t; 
  t = u;
  if(T[t].l  != NIL){
    printf("%d",T[t].l);
    if(T[T[t].l].r == NIL)
      printf("]\n");
    else printf(",");
    t =T[t].l;
    while(T[t].r != NIL){
      printf(" %d",T[t].r);
  
      if(T[T[t].r].r == NIL)
	printf("]\n");
      else printf(",");
      t =T[t].r;
    }
  }
  else  printf("]\n");
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long ;
int main(){
    bool ok = false;
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) ok =true;
    if(ok) cout << "Yes" << endl;
    else cout << "No" <<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
typedef long long ll;

int main(){
	int n;
	cin >> n;
	vector<ll> a(n+1);
	vector<ll> b(n);
	rep(i,n+1) cin >> a[i];
	rep(i,n) cin >> b[i];
	ll taosu = 0;
	rep(i,n){
		ll ltaosu = min(a[i],b[i]);
		ll rtaosu = min(a[i+1],b[i]-ltaosu);
		a[i] -= ltaosu;
		a[i+1] -= rtaosu;
		taosu += ltaosu + rtaosu;
	}
	cout << taosu;

}

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int ans=0, cnt=1, A, B;
	cin>>A>>B;
	for(;cnt<B;ans++) cnt+=A-1;
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
const long long mod=1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define rep2(i,x,n) for(int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first 
#define S second
#define PB push_back 
#define MP make_pair
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
using vl=vector<long long>;
using vvl = vector<vl>;
using vp =vector<pair<int,int>>;

typedef pair<int,int> P;
string s;
int k; 
ll INF = 10000000000000000;



int main(){
    int K;
    cin >>K;
    string S;
    cin >>S;
    int n =S.size();
    if(n>K){
        cout <<S.substr(0,K)+"..."<<endl;
    }
    else cout <<S<<endl;
}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		long n = Long.parseLong(br.readLine());

		ArrayList<Long> list = divisor(n);
		long sum = 0;
		for (long l : list) {
			long m = n / l - 1;
			if (m == 0)
				continue;

			if (n / m == n % m) {
				sum += m;
			}
		}

		System.out.println(sum);
	}

	public static final ArrayList<Long> divisor(final long n) {
		final ArrayList<Long> list = new ArrayList<>();

		for (long i = 1; i * i <= n; i++) { // √n
			if (n % i == 0) {
				list.add(i); // a x b
				if (i != n / i) {
					list.add(n / i); // b x a (逆向き)
				}
			}
		}
		return list;
	}
}

Measured memory_bytes: 33304
import java.io.*;
import java.util.StringTokenizer;

public class Main {
		
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		long a,b;
		
		while ((str =br.readLine()) != null) {
			
			a = Long.parseLong(str.substring(0,str.indexOf(" ")));
			b = Long.parseLong(str.substring(str.indexOf(" ")+1, str.length()));
			
			System.out.println(gcd(a,b) + " " + lcm(a,b));
		}
	}
	
	static long gcd(long a,long b){
		return b == 0 ? a : gcd(b,a%b);
	}
	
	static long lcm(long a,long b){
		return b*a/gcd(a, b);
	}
	
}

Measured memory_bytes: 24088
n = int(input())

d = dict()
for i in range(n):
  s = "".join(sorted(list(input())))
  d[s] = d.get(s, 0) + 1
  
ans = 0
for key in d:
  ans += d[key] * (d[key]-1) // 2
  
print(ans)

Measured memory_bytes: 17808
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin >> n;
    cin >> k;
    vector<int> x(n);
    for(int i=0; i<n; i++){
        cin >> x[i];
    }
    int ans = 0;
    for(int i = 0; i < n; ++i){
        int tmp = min(x[i], k - x[i]);
        ans += tmp; 
    }
    cout << ans*2 << endl;
    return 0;
}




Measured memory_bytes: 256
import sys
import math
input = sys.stdin.readline
N=int(input())
xys = []
for _ in range(N):
    xys.append(list(map(int, input().split())))

def z(mx,my):
    rx, ry = 0,0
    for x, y in xys:
        if x*mx + y*my > 0:
            rx, ry = (rx + x), (ry + y)
    return pow(pow(rx, 2) + pow(ry, 2), 1/2)

M = 1000
r = 0
for i in range(M):
    k = 2*(i/M)*math.pi
    r = max(r, z(math.cos(k), math.sin(k)))
print(r)



Measured memory_bytes: 40816
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// 読み込み
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		
		String result = str.replace("hi", "");
		if(result.length() > 0)
			System.out.println("No");
		else
			System.out.println("Yes");
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <climits>

using namespace std;

int main(){
    vector<int> vc;
    vector<pair<int,int>> vp;
    int i,j;
    cin >> i;
    while(i--){
        cin >> j;
        vc.push_back(j);
    }

    int max_id = 0;
    int min_id = 0;
    int maxv = INT_MIN;
    int minv = INT_MAX;
    for(size_t i = 0;i<vc.size();i++){
        if(vc[i] > maxv){
            max_id = i;
            maxv = vc[i];
        }
        if(vc[i] < minv){
            min_id = i;
            minv = vc[i];
        }
    }

    if(abs(maxv) > abs(minv)){
        for(size_t i = 0; i < vc.size();i++){
            if(vc[i] < 0){
                vp.push_back(make_pair(i+1,max_id+1));
            }
        }

        for(size_t i = 0; i < vc.size()-1;i++){
            vp.push_back(make_pair(i+2,i+1));
        }
    }
    else{
        for(size_t i = 0; i < vc.size();i++){
            if(vc[i] > 0){
                vp.push_back(make_pair(i+1,min_id+1));
            }
        }
        for(i = vc.size()-1; i > 0 ;i--){
            vp.push_back(make_pair(i,i+1));
        }
    }

    cout << vp.size()<<endl;
    for(auto a:vp){
        cout<<a.second<<" "<<a.first<<endl;
    }
}


Measured memory_bytes: 256
#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>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,A,B;

signed main(){
	cin>>N>>A>>B;
	if(abs(A-B)%2==0){
		cout<<abs(A-B)/2<<endl;
	}
	else{
		int ans1=A+(B-A-1)/2;
		ans1=max(0,ans1);
		int ans2=(N-A+1)+(N-(B+N-A+1))/2;
		ans2=max(0,ans2);
		cout<<min(ans1,ans2)<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define ll long long
using namespace std;
int main()
{

    ll n;
    cin>>n;
    if(n>=400&&n<=599)
        cout<<8<<endl;
    else if(n>=600&&n<=799)
        cout<<7<<endl;
            else if(n>=800&&n<=999)
        cout<<6<<endl;
            else if(n>=1000&&n<=1199)
        cout<<5<<endl;
            else if(n>=1200&&n<=1399)
        cout<<4<<endl;
            else if(n>=1400&&n<=1599)
        cout<<3<<endl;
            else if(n>=1600&&n<=1799)
        cout<<2<<endl;
        else if(n>=1800&&n<=1999)
        cout<<1<<endl;
}


Measured memory_bytes: 3632
a,b,c,d = gets.chomp.chars.map(&:to_i)
ans_i = 199
op = [nil, nil, nil]
8.times do |i|
    ans = a
    if i/4 == 0
        ans += b
        op[0] = "+"
    else
        ans -= b
        op[0] = "-"
    end
    
    if (i/2)%2 == 0
        ans += c
        op[1] = "+"
    else
        ans -= c
        op[1] = "-"
    end
    
    if i%2 == 0
        ans += d
        op[2] = "+"
    else
        ans -= d
        op[2] = "-"
    end
    
    if ans == 7
        ans_i = i 
        break
    end
end

puts "#{a}#{op[0]}#{b}#{op[1]}#{c}#{op[2]}#{d}=7"


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int n;
  cin>>n;
  int f;
  int p[20010];
  repi(i,1,n+1){
    cin>>f;
    p[f]=i;
  }
  int a[20010],b[20010];
  int brank=0;
  rep(i,20010) a[i]=b[i]=0;
  a[1]=1;b[1]=p[1]+n-1;
  repi(i,2,n+1){
    a[i]=a[i-1]+1;
    b[i]=b[i-1]-1;
    while(a[i]+b[i]>p[i]+n){
      b[i]--;
      brank++;
    }
    
    while(a[i]+b[i]<p[i]+n){
      a[i]++;
    }
  }
  rep(i,n){
    cout<<a[i+1]<<" ";
  }
  cout<<endl;
  rep(i,n){
    cout<<b[i+1]+brank<<" ";
  }
  cout<<endl;
  return 0;
}












Measured memory_bytes: 768
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
ll dp[3001][3001];
string str;
int nex[3001];
int cnt[3001];

int main(void){
	scanf("%d%d",&n,&m);
	cin >> str;
	for(int i=0;i<n;i++){
		cnt[i+1]+=cnt[i];
		if(str[i]=='1')cnt[i+1]++;
	}
	memset(nex,-1,sizeof(nex));
	for(int i=0;i<m;i++){
		int l,r;
		scanf("%d%d",&l,&r);
		l--;
		nex[l]=max(nex[l],r);
	}
	dp[0][0]=1;
	int r=-1;
	for(int i=0;i<n;i++){
		r=max(nex[i],r);
		for(int j=0;j<=i;j++){
			if(r<=i){
				if(str[i]=='0'){
					dp[i+1][j]=(dp[i+1][j]+dp[i][j])%MOD;
				}else{
					dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j])%MOD;
				}
			}else{
				if(j<cnt[r]){
					dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j])%MOD;
				}
				if(i-j<r-cnt[r]){
					dp[i+1][j]=(dp[i+1][j]+dp[i][j])%MOD;
				}
			}
		}
	}
	printf("%lld\n",dp[n][cnt[n]]);
	return 0;
}


Measured memory_bytes: 68992
# Fast IO (only use in integer input)

import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

R,C,K = map(int,input().split())
Gift = []
for i in range(R):
    Gift.append([])
    for _ in range(C):
        Gift[i].append(0)
for _ in range(K):
    r,c,v = map(int,input().split())
    Gift[r-1][c-1] = v

for i in range(R):
    DPi = [None] * C
    for j in range(C):
        DPi[j] = [0,0,0,0]
        DPij = DPi[j]
        DPijs1 = DPi[j-1]
        if i != 0 and j != 0:
            DPij[0] = max(DPLast[j][0],DPLast[j][1],DPLast[j][2],DPLast[j][3],DPijs1[0])
            DPij[1] = DPijs1[1]
            DPij[2] = DPijs1[2]
            DPij[3] = DPijs1[3]
            if Gift[i][j]:
                DPij[3] = max(DPij[3],DPij[2] + Gift[i][j])
                DPij[2] = max(DPij[2],DPij[1] + Gift[i][j])
                DPij[1] = max(DPij[1],DPij[0] + Gift[i][j])
        elif i == 0 and j != 0:
            DPij[0] = DPijs1[0]
            DPij[1] = DPijs1[1]
            DPij[2] = DPijs1[2]
            DPij[3] = DPijs1[3]
            if Gift[i][j]:
                DPij[3] = max(DPij[3],DPij[2] + Gift[i][j])
                DPij[2] = max(DPij[2],DPij[1] + Gift[i][j])
                DPij[1] = max(DPij[1],DPij[0] + Gift[i][j])
        elif j == 0 and i != 0:
            DPij[0] = max(DPLast[j][0],DPLast[j][1],DPLast[j][2],DPLast[j][3])
            if Gift[i][j]:
                DPij[3] = max(DPij[3],DPij[2] + Gift[i][j])
                DPij[2] = max(DPij[2],DPij[1] + Gift[i][j])
                DPij[1] = max(DPij[1],DPij[0] + Gift[i][j])
        else:
            DPij[1] = Gift[i][j]
    DPLast = DPi

print(max(DPi[C-1]))

Measured memory_bytes: 184240
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int k = scan.nextInt();

		int max = a;
		String str = "a";
		if (max < b) {
			max = b;
			str = "b";
		}
		if (max < c) {
			max = c;
			str = "c";
		}

		for (int i = 0; i < k; i++) {
			max = max * 2;
		}

		if (str.equals("a")) {
			System.out.print(max + b + c);
		} else if (str.equals("b")) {
			System.out.print(a + max + c);
		} else {
			System.out.print(a + b + max);
		}

	}

}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{   
    fast;
    char c;
    cin>>c;
    if((int)c<96)
    {
        cout<<'A';
    }
    else
    {
        cout<<'a';
    }
    
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cmath>

using namespace std;

int main(){
	int n, num;
	int notpr;

	cin >> n;

	notpr = 0;
	for (int i = 0; i < n; i++){
		cin >> num;
		for (int j = 2; j <= sqrt(num); j++){
			if (num % j == 0){
				notpr++;
				break;
			}
		}
	}
	cout << n - notpr << endl;
}

Measured memory_bytes: 3060
import itertools

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

for idx, i in enumerate(itertools.permutations([i+1 for i in range(n)])):
    if i == p:
        a = idx
    
    if i == q:
        b = idx

print(abs(a - b))

Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
//        int a = 3;
        int a = sc.nextInt();
        int[] b = new int[a];

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

        int cnt = 0;
        while (foobaa(b)) {
            cnt += 1;
        }

        System.out.println(cnt);

    }

    static boolean foobaa(int[] aaa) {

        for (int i = 0; i < aaa.length; i++) {
            if (aaa[i] % 2 == 0) {
                aaa[i] = aaa[i] / 2;
            } else {
                return false;
            }
        }
        return true;
    }
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h.at(i);
    }
    int count = 0;
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        if (h.at(i) >= h.at(i + 1)) {
            count++;
        } else {
            ans = max(ans, count);
            count = 0;
        }
    }
    ans = max(ans, count);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3788
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int[] s = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int K = sc.nextInt();
	System.out.print(s[K-1]);
	
    }
}


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

using ll = long long;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int x, y, z, k;
ll a[1005], b[1005], c[1005];
ll sum[10000005];
int num;
std::set<std::tuple<ll, ll, ll>> s;
int main()
{
	std::cin >> x >> y >> z >> k;
	for (int i = 0; i < x; ++i)
		std::cin >> a[i];
	for (int i = 0; i < y; ++i)
		std::cin >> b[i];
	for (int i = 0; i < z; i++)
		std::cin >> c[i];
	std::sort(a, a + x);
	std::sort(b, b + y);
	std::sort(c, c + z);

	ll ans = a[x - 1] + b[y - 1] + c[z - 1];
	s.insert(std::make_tuple(x - 1, y - 1, z - 1));
	std::priority_queue<std::pair<ll, std::tuple<ll, ll, ll>>> q;
	q.push(std::make_pair(ans, std::make_tuple(x - 1, y - 1, z - 1)));

	for (int time = 0; time < k; ++time) {
		auto buf = q.top(); q.pop();
		auto index = buf.second;
		ll xi = std::get<0>(index);
		ll yi = std::get<1>(index);
		ll zi = std::get<2>(index);
		std::cout << buf.first << std::endl;
		if (xi > 0 && s.find(std::make_tuple(xi - 1, yi, zi)) == s.end()) {
			q.push(std::make_pair(a[xi - 1] + b[yi] + c[zi], std::make_tuple(xi - 1, yi, zi)));
			s.insert(std::make_tuple(xi - 1, yi, zi));
		}
		if (yi > 0 && s.find(std::make_tuple(xi, yi - 1, zi)) == s.end()) {
			q.push(std::make_pair(a[xi] + b[yi - 1] + c[zi], std::make_tuple(xi, yi - 1, zi)));
			s.insert(std::make_tuple(xi, yi - 1, zi));
		}
		if (zi > 0 && s.find(std::make_tuple(xi, yi, zi - 1)) == s.end()) {
			q.push(std::make_pair(a[xi] + b[yi] + c[zi - 1], std::make_tuple(xi, yi, zi - 1)));
			s.insert(std::make_tuple(xi, yi, zi - 1));
		}
	}
	return 0;
}


Measured memory_bytes: 896
N=int(input())
V=[int(i) for i in input().split()]
K=list(set(V))
if len(K)==1:
    print(N//2)
    exit()

cnt={}
cnt[-1]=0
for k in K:
    cnt[k]=0
for i in range(0,N,2):
    cnt[V[i]]+=1
ev_MAX=0
sec_ev_MAX=0
ev=-1
ev_cnt=[(cnt[k],k) for k in K]
ev_cnt.sort(key=lambda x: x[0],reverse=True)
ev=ev_cnt[0][1]
ev_MAX=ev_cnt[0][0]
sec_ev_MAX=0 if len(ev_cnt)<2 else ev_cnt[1][0]
# print(ev_cnt)
cnt={}
cnt[-1]=0
for k in K:
    cnt[k]=0
for i in range(1,N,2):
    cnt[V[i]]+=1
od_MAX=0
sec_od_MAX=0
od=-1
od_cnt=[(cnt[k],k) for k in K]
od_cnt.sort(key=lambda x: x[0],reverse=True)
od=od_cnt[0][1]
od_MAX=od_cnt[0][0]
sec_od_MAX=0 if len(od_cnt)<2 else od_cnt[1][0]

ans=0
if od!=ev:
    # print('#',1)
    ans+=N//2-ev_MAX
    ans+=N//2-od_MAX
else:
    # print(sec_ev_MAX,od_MAX,sec_od_MAX,ev_MAX)
    ans+=min(N//2-sec_ev_MAX+N//2-od_MAX,N//2-sec_od_MAX+N//2-ev_MAX)
print(ans)

Measured memory_bytes: 33564
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace AtcoderExpress
{


    class Program2
    {
        static long[] A;
        static void Main(string[] args)
        {
            var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var N = NM[0];
            var M = NM[1];
            var flg = true;
            A= Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();

            var Div2Count = 0;
            var CopyA1 = A[0];
            while (CopyA1 % 2 == 0)
            {
                CopyA1 /= 2;
                Div2Count++;
            }

            for (int i = 0; i < N; i++)
            {
                var Count  = 0;
                var CopyAi = A[i];
                while(CopyAi%2 == 0)
                {
                    CopyAi /= 2;
                    Count++;
                }

                if(Count != Div2Count)
                {
                    flg = false;
                    break;
                }
            }

            for (int i = 0; i < A.Length; i++)
            {
                A[i] /= 2;
            }

            var LCM = A[0];
            for (int i = 1; i < N; i++)
            {
                LCM = lcm(LCM,A[i]);
            }
            //Console.WriteLine( LCM);
            if (flg)
            {
                Console.WriteLine((M/LCM+1)/2);
            }
            else
            {
                Console.WriteLine(0);
            }
        }

        static long lcm(long a,long b)
        {
            return (a * b / gcd(a, b));
        }
        

        static long gcd(long a, long b)
        {
            if (a < b) return gcd(b, a);
            if( b > 0)
            {
                return gcd(b, a%b);
            }
            else
            {
                return a;
            }
        }
    }
}


Measured memory_bytes: 29404
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		boolean b = false;
		for (int i=0;i<S.length();i++) {
			boolean tempB = true;
			for (int j=0;j<S.length();j++) {
				if (S.charAt((i+j)%S.length())!=T.charAt(j)) {
					tempB =false;
					break;
				}
			}
			if (tempB == true) {
				b=true;
				break;
			}
		}
		if (b==true) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll n,W;
ll w[100005],v[100005];
ll dp[100005],ans;
int main(){
	memset(dp,0x3f,sizeof(dp));
	cin>>n>>W;
	for(int i=1;i<=n;++i){
		cin>>w[i]>>v[i]; 
	} 
	dp[0]=0;
	for(int i=1;i<=n;++i){
		for(ll j=1e5;j>=v[i];--j){
				dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
				if(dp[j]<=W){
					ans=max(j,ans);
				}
		}
	}
	cout<<ans<<'\n';
	return 0; 
} 

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/

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

	int n;
	cin >> n;
	vector<int> h(n);
	rep(i, n) cin >> h[i];

	vector<int> dp(n + 1, inf);
	dp[0] = 0;

	rep(i, n) {
		if (i - 1 >= 0) dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
		if( i - 2 >= 0) dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
	}

	cout << dp[n - 1] << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
    // Here your code !
    int N,Ki,Pi,i;
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d %d",&Ki,&Pi);
        if(Ki%Pi == 0)printf("%d\n",Pi);
        else printf("%d\n",Ki%Pi);
    }
    return 0;
}

Measured memory_bytes: 596
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int &x : a){
        cin >> x;
    }
    int ans = INT_MAX;
    for(int i = -100; i <= 100; i++){
        int yo = i;
        int cur = 0;
        for(auto &x : a){
            cur += (x - yo) * (x - yo);
        }
        ans = min(ans, cur);
    }
    cout << ans;
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

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

from fractions import gcd
# return gcd(x, y)

d = {}

def f(x, y, z):
    # print(d)
    if d.get((x,y)):
        s = d[(x,y)]
    else:
        s = gcd(x, y)
        d[(x,y)] = s

    if d.get((s,z)):
        t = d[(s,z)]
    else:
        t = gcd(s,z)
        d[(s,z)] = t

    return t

ans = 0
for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            if i == j == k:
                ans += f(i, j, k)
            elif i == j or j == k:
                ans += 3 * f(i, j, k)
            else:
                ans += 6 * f(i, j, k)

print(ans)

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

int main() {
	int H, W; cin >> H >> W;
	string A;
	int count=0;
	for(int i=0; i<H; ++i){
	    cin >> A;
	    for(int j=0; j<W; ++j){
	        if(A[j]=='#') ++count;
	    }
	}
	if(count==H+W-1) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}


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

int main(){
  int K;
  string S;
  cin >> K >> S;
  int t = S.size(); // Kの文字列の長さ//
  if(t <= K)
    cout << S << endl;
  else{
    for(int i = 0; i < K; i++){
      cout << S.at(i);
    }
    cout << "..." << endl;

  }
  
}

Measured memory_bytes: 3628
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INF = 1e20;
const ll MOD = 1e9 + 7;

void solve(long long N, long long K, std::vector<long long> x,
           std::vector<long long> y) {
  ll ans = INF;
  rep(xl, 0, N) {
    rep(xr, 0, N) {
      rep(yu, 0, N) {
        rep(yd, 0, N) {
          ll xld = x[xl];
          ll yld = y[yd];
          ll xru = x[xr];
          ll yru = y[yu];

          if (xld > xru) {
            continue;
          }

          if (yld > yru) {
            continue;
          }

          ll cnt = 0;
          rep(i, 0, N) {
            if (xld <= x[i] && x[i] <= xru && yld <= y[i] && y[i] <= yru) {
              cnt++;
            }
          }

          if (cnt >= K) {
            ans = min(ans, (xld - xru) * (yld - yru));
          }
        }
      }
    }
  }
  print(ans);
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> x(N);
  std::vector<long long> y(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &x[i]);
    scanf("%lld", &y[i]);
  }
  solve(N, K, std::move(x), std::move(y));
  return 0;
}


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

using namespace std;

const int N = 100000;

int n, m, pos[N], in, p, ans;

main(){
  while(cin >> n >> m && (n|m)){
    pos[0] = 0;
    for(int i=1;i<n;i++){
      cin >> in;
      pos[i] = pos[i-1] + in;
    }
    ans = p = 0;
    for(int i=0;i<m;i++){
      cin >> in;
      ans += abs(pos[p] - pos[p+in]);
      p += in;
      ans %= N;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using Graph = vector<vector<LL>>;

long long gcd(long long a, long long b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
long long chmax(long long a,long long b){
  a = max(a,b);
}
long long chmin(long long a, long long b){
  a = min(a,b);
}
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true;

    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v);
    }
}



int main() {
  LL n,k=-1,sum=0,a=0,b=0,c=0,d=0,ans=0;
  LL MOD = 1000000007;
  LL INF = 1LL << 60;
  string S="",T="",U="";
  cin >> S >> T >> a >> b >>U;
  if(S==U) cout <<a -1 << endl << b << endl;
  else cout << a << endl << b-1 << endl;
  //cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
 
#define AMAX 20
#define MMAX 200

int gA[AMAX+1],gM[MMAX+1];
int gn;

int solve( int p, int t )
{
	if( 0 == t ) { return 1; }
	if( gn < p ) { return 0; }
	
	int res = solve( p+1, t-gA[p] ) || solve( p+1, t ) ;
	
	return res;
}

int main( void ) 
{

    int i;
    int q;
    
    scanf( "%d", &gn );  
	for( i=0; i<gn; i++ ) {
	    scanf( "%d", &gA[i] );
	}   
    scanf( "%d", &q );  
    for( i=0; i<q; i++ ) {
        scanf( "%d", &gM[i] );
    	if( solve( 0, gM[i] ) ) {
    		printf( "yes\n" );    	
    	} else {
    		printf( "no\n" );
    	}
    }
 
    return 0;
}

Measured memory_bytes: 580
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(int i=(a);i<(b);++i)

#define huge 1000000007
typedef long long ll;
ll gcd(ll a, ll b);

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;
	ll M = 0;
	//ll M = 0;
	ll a[200] = {};
	ll b[200] = {};
	ll v[3] = {};
	//ll *a, *b, *x;
	string S,T,U[52];
	ll count = 0;
	ll sum = 0;
	ll min = 100000;
	ll max = 0;
	int flag = 0;
	char temp,head;
	//int is = 0;
	
	vector<int> c(3);
	//char p;
	cin >> A >> B;

	rep(i, 0, A) {
		cin >> U[i];
	}

	rep(j, 0, A) {
		rep(i, 0, B) {

			if (U[j][i] == '.') {

				rep(y, j - 1, j + 2) {
					rep(x, i - 1, i + 2) {
						if(y>=0&&x>=0)
						if (U[y][x] == '#') {
							count++;
						}

					}
				}
				cout << count;
			}
			else {
				cout << "#";
			}
			
			count = 0;
		}
		cout << endl;
	}


	rep(i, 0, A) {
		//cout << U[i] << endl;;
	}

	//cin >> S;
	
	//a = (ll *)malloc(M * sizeof(ll));
	//b = (ll *)malloc(M * sizeof(ll));
	//vector<pair<int,int>> ch(N+1);
	//vector<bool> flag(N);
	
	//count--;
	//	cout << X << endl;
	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(c.begin(), c.end());
	
	//cout << c[2] - c[1] << endl;



	/*A = N / 1000;
	N %= 1000;
	B = N / 100;
	N %= 100;
	C = N / 10;
	N %= 10;
	D = N;*/

	
	

	return 0;

}

ll gcd(ll a, ll b) {
	ll c;
	c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}

	return b;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
#define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

map<ll, ll> prime;
void factorize(int n) {
    for(int i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            prime[i]++;
            n /= i;
        }
    }
    if(n != 1) {
        prime[n] = 1;
    }
}

int main() {

    int n;
    cin>>n;
    factorize(n);
    cout<<n<<":";
    irep(i,prime){
        rep(j,i->second){
            cout<<" "<<(i->first);
        }
    }
    cout<<endl;
}




Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define EPS (1e-14)
#define _PA(x,N) rep(i,N){cout<<x[i]<<" ";}cout<<endl;
#define _PA2(x,H,W) rep(i,(H)){rep(j,(W)){cout<<x[i][j]<<" ";}cout<<endl;}

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef complex<double> Complex;
typedef vector< vector<int> > Mat;

ll ans;
const ll INF = 1e+9 + 7;
int N;
int a[50], b[50], c[50];
int Ma, Mb;

ll dp[50][405][405];

void solve() {
	for (int i = 0; i < 50; i++) {
		for (int j = 0; j < 405; j++) {
			for (int k = 0; k < 405; k++) {
				dp[i][j][k] = INF;
			}
		}
	}
	dp[0][0][0] = 0;

	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= 400; j++) {
			for (int  k = 0; k <= 400; k++) {
				dp[i+1][j][k] = dp[i][j][k];
				if (j - a[i] >= 0 && k - b[i] >= 0) {
					dp[i+1][j][k] = min(dp[i][j][k], dp[i][j-a[i]][k-b[i]] + c[i]);
				}
			}
		}
	}
#if 0
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j < 10; j++) {
			for (int k = 0; k < 10; k++) {
				cout << dp[i][j][k] << " ";
			}
			cout << endl;
		}
		cout << endl;
	}
#endif

	ans = INF;
	for (int i = 1; max(Ma, Mb) * i <= 400; i++) {
		int p = Ma * i;
		int q = Mb * i;
		ans = min(ans, dp[N][p][q]);
	}
	
	if (ans == INF) {
		ans = -1;
	}

	cout << ans << endl;
}

int main() {
	cin >> N >> Ma >> Mb;
	rep(i, N) {
		cin >> a[i] >> b[i] >> c[i];
	}
	solve();
	return 0;
}




Measured memory_bytes: 64256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
    int N;
    cin >> N;
    long long int ans = 0;
    string s;
    int cnt1 = 0, cnt2 = 0, cnt3 = 0;
    for(int i = 0; i < N; i++){
        cin >> s;
        for(int j = 0; j < s.size() - 1; j++){
            if(s[j] == 'A' && s[j + 1] == 'B'){
                ans += 1;
            }
        }
        if(s[0] == 'B' && s[s.size() - 1] != 'A'){
            cnt1 += 1;
        }
        if(s[0] != 'B' && s[s.size() - 1] == 'A'){
            cnt2 += 1;
        }
        if(s[s.size() - 1] == 'A' && s[0] == 'B'){
            cnt3 += 1;
        }
    }
    ans += min(cnt1, cnt2);
    if(cnt1 > 0 || cnt2 > 0){
        ans += cnt3;
    }else{
        ans += max(cnt3 - 1, 0);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256