akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; #[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug { 
    ($($a: expr),*) => { 
        println!(concat!($(stringify!($a)," = {:?}, "),*), $($a),*);
    } 
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

fn solve() {
    let (n, k) = get!(usize, usize);
    let mut sum = 0usize;
    for b in 1..n+1 {
        let p = n/b;
        let r = n%b;
        sum += p*(max!(b,k)-k);
        sum += max!(r+1,k)-k;
    }
    if k == 0 {
        sum -= n;
    }
    println!("{}", sum);
}


Measured memory_bytes: 8572
#include<stdio.h>
#include<string.h>

int main(void)
{
        char bl[3] = {'a','a','a'};
        int  num = 0;
        int counta = 0;
        int countb = 0;
        int countab = 0;
        int counto = 0;

        while(scanf("%d,%s",&num,bl) != EOF)
        {

                if(strcmp(bl,"A") == 0)
                {
                        counta++;
                }
                else if(strcmp(bl,"B") == 0)
                {
                        countb++;
                }
                else if(strcmp(bl,"AB") == 0)
                {
                        countab++;
                }
                else if(strcmp(bl,"O") == 0)
                {
                        counto++;
                }
        }

        printf("%d\n", counta);
        printf("%d\n", countb);
        printf("%d\n", countab);
        printf("%d\n", counto);

        return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		String[] a = new String[N];

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

		int cnt = 0;
		int divCnt = 0;

		boolean continueFlg = true;

	while(continueFlg) {
			for (int i = 0; i < N; i++) {
				if(Integer.parseInt(a[i]) % 2 == 0 ) {
					a[i] = String.valueOf(Integer.parseInt(a[i]) / 2);
					divCnt ++;
				}
			}
			if(divCnt == N) {
				divCnt = 0;
				cnt++;
			} else {
				continueFlg = false;
			}
		}
	System.out.println(cnt);
	}
}



Measured memory_bytes: 21588
#include<bits/stdc++.h>
 
#define    pi          acos(-1) 
#define    all(x)      (x).begin(),(x).end()
#define    fill(x,y)   memset(x, y, sizeof(x))
#define    gcd(x,y)    __gcd(x,y)
#define    lcm(x,y)    (x*(y/gcd(x,y))
#define    trace(x)    cout << #x << " = " << x << endl
#define    bug         cout << "Bug check" << endl
#define    endl        '\n'
 
using namespace std; 

int main(){
	//freopen("in.txt","r", stdin);
	//freopen("out.txt","w", stdout);
 
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	int arr[3][3];
	bool chk[3][3];
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			chk[i][j]=0;
		}
	}
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin >> arr[i][j];
		}
	}
	int n; cin >> n;
	int c=0;
	while(n--){
		int x; cin >> x;
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				if(arr[i][j]==x){
					chk[i][j]=1;
					break;
				}
			}
		}
	}
	bool flg=0;
	for(int i=0;i<3;i++){
		if(chk[i][0]==1 && chk[i][1]==1 && chk[i][2]==1){
			flg=1;
			break;
		}
	}
	for(int j=0;j<3 && flg==0;j++){
		if(chk[0][j]==1 && chk[1][j]==1 && chk[2][j]==1){
			flg=1;
			break;
		}
	}
	if(chk[0][0]==1 && chk[1][1]==1 && chk[2][2]==1){
		flg=1;
	}
	if(chk[0][2]==1 && chk[1][1]==1 && chk[2][0]==1){
		flg=1;
	} 
	puts(flg? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <cstdio>
#include <cmath>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using P1 = pair<int, P>;
#define FOR(t, a, b) for (int t = (a); t < (b); ++t)
#define REP(t, n) FOR(t, 0, n)

int main()
{
    ll d, n;
    cin >> d >> n;
    if (d == 0)
    {
        if (n != 100)
            cout << n << endl;
        else
            cout << n + 1 << endl;
    }
    else if (d == 1)
    {
        if (n != 100)
            cout << 100 * n << endl;
        else
            cout << 100 * (n + 1) << endl;
    }
    else if (d == 2)
    {
        if (n != 100)
            cout << 10000 * n << endl;
        else
            cout << 10000 * (n + 1) << endl;
    }

    return 0;
}


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

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int main() {
	int h, w; cin >> h >> w;
	char s[h+2][w+2];
	for(int i = 0; i < w+2; i++) s[0][i] = '.';
	for (int i = 1; i <= h; i++)
	{
		s[i][0] = '.';
		for (int j = 1; j <= w; j++)
		{
			cin >> s[i][j];
		}
		s[i][h+1] = '.';
	}
	for(int i = 0; i < w+2; i++) s[h+1][i] = '.';

	bool res = true;
	for (int i = 1; i <= h; i++)
	{
		for (int j = 1; j <= w; j++)
		{
			if(s[i][j] == '.') continue;
			bool tmp = false;
			for (int k = 0; k < 4; k++)
			{
				if(s[i+dx[k]][j+dy[k]] == '#')
					tmp = true;
			}
			if(!tmp) res = false;
		}
	}

	if(res) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3680
#include<cstdio>
#include<cstring>
#include<iostream>

#define nn 200010
using namespace std;

int f[nn],l[nn],n,tot;
struct Edge{int to,old;}e[nn*2];
inline void Lnk(int x,int y){e[++tot].to=y,e[tot].old=l[x],l[x]=tot;}
inline void Dfs(int x,int y){
	for (int i=l[x];i;i=e[i].old)if(e[i].to!=y){
		Dfs(e[i].to,x);
		f[x]^=(f[e[i].to]+1);
	}
}

int main()
{

	scanf("%d",&n);
	for (int i=1;i<n;i++){
		int u,v;scanf("%d%d",&u,&v);
		Lnk(u,v),Lnk(v,u);
	}
	
	Dfs(1,0);
	
	if (f[1]) puts("Alice");else puts("Bob");
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define rep(i , n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
int main() {
    string s;
    cin >> s;
    if(s[s.size() - 1] == 's'){
        cout << s << "es" << endl;
    }
    else{
        cout << s << 's' << endl;
    }
}


Measured memory_bytes: 3628
// g++ -I ~/Documents/programming/cppLib -std=gnu++14 -o test ~/Documents/programming/cppLib/test.cpp && ./test && rm test
#include <bits/stdc++.h>
using namespace std;
template <typename T> using vector2 = vector <vector  <T>>;
template <typename T> using vector3 = vector <vector2 <T>>;
template <typename T> using vector4 = vector <vector3 <T>>;
using lint = long long;
#define FOR( i, a, b ) for( lint i=(a) ; i < (b) ; ++i )
#define REP( i, n )    for( lint i= 0  ; i < (n) ; ++i )
#define ALL( v )       (v).begin(), (v).end()

int bitCount(int bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}



int main() {
    int N, M;
    cin >> N >> M;

    vector<int> S(M,0);
    REP(i, M) {
        int K;
        cin >> K;
        REP(j, K) {
            int I;
            cin >> I;
            S[i] |= (1<< (I-1));
        }
        //cout << "S:" << bitset<10>(S[i] )<< endl;
    }


    vector<int> P(M);
    REP(i, M) {
        cin >> P[i];
    }

    int count = 0;
    REP(i, (1 <<N) ) { // 1024
        //cout << "i:" << bitset<10>(i) << endl;
        bool allTentou = true;
        REP( j, M ) {
            if ( bitCount( i & S[j] ) %2 != P[j] ) {
                allTentou = false;
                break;
            }
        }
        if( allTentou ) {
            count ++;
        }
    }

    cout << count << endl;
}


Measured memory_bytes: 256
class Dice
  attr_reader :labels

  def initialize(args)
    @labels = args
  end

  def top
    @labels[0]
  end

  def move(a,b,c,d)
    arr = [@labels[a], @labels[b], @labels[c], @labels[d]]
    t = arr.shift
    arr << t
    @labels[a], @labels[b], @labels[c], @labels[d] = arr
  end

  def move_n
    move(0,1,5,4)
  end

  def move_e
    move(0,3,5,2)
  end

  def move_s
    move(4,5,1,0)
  end

  def move_w
    move(2,5,3,0)
  end

  def move_to_input(ch)
    case ch
    when 'E'
      move_e
    when 'N'
      move_n
    when 'S'
      move_s
    when 'W'
      move_w
    end
  end
end

input = gets.split.map(&:to_i)
dice = Dice.new(input)
n = gets.to_i

n.times do
  q = gets.split.map(&:to_i)
  loop do
    dice.move_to_input('ENSW'.chars.sample)
    if dice.labels[0] == q[0] && dice.labels[1] == q[1]
      puts dice.labels[2]
      break
    end
  end
end

Measured memory_bytes: 6124
#include <iostream>
#include <map>
#include <bitset>
#include <string>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define INF 1100000000
#define LLINF 1100000000000000000
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair

using namespace std;
typedef long long ll;

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

  int cnt = 1;
  REP(i, S.size() - 1) {
    if (S[i] != S[i + 1]) cnt++;
  }
  cout << (cnt - 1) << endl;

  return 0;
}

Measured memory_bytes: 512
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

static class P
{
    static void Main()
    {
        Console.WriteLine(Console.ReadLine().PadLeft(15, 'o').Count(x => x == 'o') >= 8 ? "YES" : "NO");
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 100001;
static const ll MOD = 1000000007;

namespace Printer{
    void print(vector<int> v){
        rep(i, v.size()){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    void print(vector<vector<int> > vv){
        rep(i, vv.size()){
            rep(j, vv[i].size()){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }
};

//--global--//



//----------//

ll calc(ll n, vector<vector<ll> > vv, vector<vector<ll> > p, string out){
    if(out.find("1") == string::npos) return -LLINF;
    ll sum = 0;
    vector<ll> correctRate(n);
    rep(i, out.size()){
        int k = out[i] - '0';
        if(k == 1){
            rep(j, n){
                if(vv[j][i] == 1){
                    correctRate[j]++;
                }
            }
        }
    }
    rep(i, n){
        sum += p[i][correctRate[i]];
    }
    //cout << out << ":" << sum << endl;
    return sum;
}

ll solve(ll n, vector<vector<ll> > vv, vector<vector<ll> > p, string out){
    if(out.size() == 10){
        return calc(n, vv, p, out);
    }
    ll res = -LLINF;
    res = max(res, solve(n, vv, p, out + "00"));
    res = max(res, solve(n, vv, p, out + "01"));
    res = max(res, solve(n, vv, p, out + "10"));
    res = max(res, solve(n, vv, p, out + "11"));

    return res;
}

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//

    ll n;
    cin >> n;
    vector<vector<ll> > vv(n, vector<ll>(10));
    vector<vector<ll> > p(n, vector<ll>(10));
    rep(i, n){
        rep(j, 10){
            cin >> vv[i][j];
        }
    }
    rep(i, n){
        rep(j, 11){
            cin >> p[i][j];
        }
    }

    string tmp;
    cout << solve(n, vv, p, tmp) << endl;
    
    
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> t(n);
    vector<string> s(n);
    string x;
    int rep = 0;

    for (int i = 0;i < n;i++) {
        cin >> s[i] >> t[i];
        rep += t[i];
    }

    cin >> x;

    int cnt = 0,sum = 0;

    for (int i = 0; i < n;i++){
        if (s[i] == x) {
            sum += t[i];
            break;
        }

        sum += t[i];
    }
    int ans = rep - sum;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n,temp;

    cin >> n;

        for(int i=1;i<=n;i++){
            temp = i;
            if(temp%3==0){
                cout<<" "<<i;
            }
            else{
                while(temp>0){
                    if(temp%10==3){
                        cout << " "<<i;
                        break;
                    }
                    else{
                        temp = temp / 10;
                    }
                }

            }
        }
            
        cout << endl;

    return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <set>
#include <numeric> 
#include <vector> 
#include <algorithm>
#include <cstring>
#include <map>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int sz = 2e5 + 10;
int x, y, a, b, c;
int r[sz], g[sz], l[sz];

int main() {

    while (cin >> x >> y >> a >> b >> c) {
       for (int i = 0; i < a; i++) {
           cin >> r[i];
       }
       for (int i = 0; i < b; i++) {
           cin >> g[i];
       }
       for (int i = 0; i < c; i++) {
           cin >> l[i];
       }
        sort(r, r + a, greater <int> ());
        sort(g, g + b, greater <int> ());
        sort(l, l + c, greater <int> ());
        vector <int> ans;
        for (int i = 0; i < a && i < x; i++) {
            ans.push_back(r[i]);
        }
        for (int i = 0; i < b && i < y; i++) {
            ans.push_back(g[i]);
        }
        for (int i = 0; i < c; i++) {
            ans.push_back(l[i]);
        }
        sort(ans.begin(), ans.end(), greater <int> ());
        ans.resize(x + y);
        ll pr = 0;
        for (int x: ans) {
            pr += x;
        }
        cout << pr << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const long long N = 3e6 + 17;
ll a[N], b[N], cnt, ans, lnt, n, m, r1, r0, l1, l0, sum, mx, h, c[N], t[N], mn = N, x, y, k;
pair<ll,ll>pr[N];
vector<ll>v,v2;
map<ll,ll>mp;
bool used[N];
char ch[N];
ll prime[N] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s;
    cin >> s;
    for(ll i = 0; i < s.size(); i ++)
    {
        if(s[i] == '+')
        {
            cnt ++;
        }
        if(s[i] == '-')
        {
            cnt --;
        }
    }
    cout << cnt;
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int N, M, Q;
pii T[200000];
int sum[501][501];

int main() {
    cin >> N >> M >> Q;
    int l, r;
    REP(i, M) {
        cin >> l >> r;
        T[i] = {l, r};
    }
    sort(T, T + M, [](const pii& a, const pii&b){ return a.second < b.second; });

    int t = 0;
    FOR(i, 1, N + 1) {
        REP(j, N + 1) sum[i][j] = sum[i - 1][j];
        while (t < M && T[t].second <= i) {
            FOR(k, T[t].first, N + 1) sum[i][k]++;
            t++;
        }
    }
    int p, q;
    REP(i, Q) {
        cin >> p >> q;
        cout << sum[q][q] - sum[q][p - 1] << endl;
    }

    return 0;
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    REP(i, n) cin >> a[i];

    int rem = (n - 1) % (k - 1);
    int div = (n - 1) / (k - 1);

    if (rem) cout << div + 1 << '\n';
    else cout << div << '\n';
    return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    static long[] fact;
    static long[] revFact;
    static long mod = (long) Math.pow(10, 9) + 7;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        // 素因数分解
        HashMap<Integer, Integer> map = new HashMap<>();

        for (int i = 2; i < Math.sqrt(M) + 2; i++) {
            while (M % i == 0) {
                if (map.containsKey(i)) {
                    map.put(i, map.get(i) + 1);
                } else {
                    map.put(i, 1);
                }

                M /= i;
            }
        }

        if (M > 1) {
            map.put(M, 1);
        }

        // 階乗とその逆元を求める
        fact = new long[(int) Math.pow(10, 7)];
        revFact = new long[(int) Math.pow(10, 7)];
        setFact();

        // answer
        long ret = 1;
        for (int b : map.values()) {
            ret *= select(N - 1 + b, b);
            ret %= mod;
        }

        System.out.println(ret);
    }

    static long select(int a, int b) {
        return (((fact[a] * revFact[b]) % mod) * revFact[a - b]) % mod;
    }

    static void setFact() {
        fact[0] = 1;
        for (int i = 1; i < (long) Math.pow(10, 7); i++) {
            fact[i] = fact[i - 1] * i;
            fact[i] %= mod;
        }

        revFact[(int) Math.pow(10, 7) - 1] = powmod(fact[(int) Math.pow(10, 7) - 1], mod - 2);
        for (int i = (int) Math.pow(10, 7) - 2; i >= 0; i--) {
            revFact[i] = revFact[i + 1] * (i + 1);
            revFact[i] %= mod;
        }
    }

    static long powmod(long a, long p) {
        long ans = 1;
        long mul = a;

        for (; p > 0; p >>= 1, mul = (mul * mul) % mod) {
            if ((p & 1) == 1) ans = (ans * mul) % mod;
        }

        return ans;
    }
}

Measured memory_bytes: 181588
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define loop(i, l, r) for(int i = l; i < r; i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vec_i;

const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int INF = 1e9;
const int MOD = 1e9+7;

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

	vec_i dp(3, 0);
	rep(i, n){
		int a,b,c;
		cin >> a >> b >> c;

		int prev_a = dp[0], prev_b = dp[1], prev_c = dp[2];
		dp[0] = max(prev_b + a, prev_c + a);
		dp[1] = max(prev_a + b, prev_c + b);
		dp[2] = max(prev_a + c, prev_b + c);
	}
	cout << max(dp[0], max(dp[1], dp[2])) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N;string S;cin>>N>>S;
	int white[N],black[N];
	int a=0,b=0;
	for(int i=0;i<N;i++){
		if(S.at(i)=='.'){
			a++;
		}else{
			b++;
		}white[i]=a;
		black[i]=b;
	}int ans=200000;
	for(int i=0;i<N;i++){
		ans=min(ans,black[i]+white[N-1]-white[i]);
	}cout<<min(ans,white[N-1])<<endl;
}

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

#define HASH 1000003

typedef struct List {
	struct List *next;
	char *s;
	int l;
} list;

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int hash_string(char* s)
{
	int i, x = 0;
	for (i = 0; s[i] != 0; i++) x = ((x << 5) + s[i] - 'a') % HASH;
	return x;
}

int lex_smaller(char* s1, char* s2)
{
	int i;
	for (i = 0; s1[i] != 0 && s2[i] != 0; i++) {
		if (s1[i] < s2[i]) return 1;
		else if (s1[i] > s2[i]) return -1;
	}
	if (s1[i] == s2[i]) return 0;
	else if (s1[i] == 0) return 1;
	else return -1;
}

int main()
{
	int i, j, l[200001], N;
	char *S[200001], T[1000001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%s", T);
		for (l[i] = 0; T[l[i]] != 0; l[i]++);
		S[i] = (char*)malloc(sizeof(char) * (l[i] + 1));
		for (j = 0; j <= l[i]; j++) S[i][j] = T[j];
	}
	
	int h[200001];
	list *p, *hash[HASH], d[200001];
	for (i = 1; i <= N; i++) {
		h[i] = hash_string(S[i]);
		d[i].s = S[i];
		d[i].l = l[i];
		d[i].next = hash[h[i]];
		hash[h[i]] = &(d[i]);
	}
	
	int k, m, dp[2][26];
	long long ans = 0, tmp, pow[32];
	const long long inv = div_mod(1, 32, HASH);
	for (k = 1, pow[0] = 32; k < 32; k++) pow[k] = pow[k-1] * pow[k-1] % HASH;
	for (i = 1; i <= N; i++) {
		if (l[i] <= 1) continue;
		for (j = 0; j <= l[i]; j++) T[j] = S[i][j];
		for (j = l[i] - 1, k = 0, tmp = 1; j > 0; j >>= 1, k++) if ((j & 1) == 1) tmp = tmp * pow[k] % HASH;
		h[i] = (h[i] - tmp * (T[0] - 'a') % HASH + HASH) % HASH;
		tmp = tmp * inv % HASH;
		h[i] = (h[i] - tmp * (T[1] - 'a') % HASH + HASH) % HASH;
		for (j = 0; j < 26; j++) dp[0][j] = 0;
		dp[0][S[i][0] - 'a'] = 1;
		dp[1][0] = S[i][0] - 'a';
		for (j = 1, m = 1; j < l[i]; j++) {
			if (dp[0][S[i][j] - 'a'] == 0) {
				dp[0][S[i][j] - 'a'] = 1;
				dp[1][m++] = S[i][j] - 'a';
			}
			for (k = 0; k < m; k++) {
				T[j] = 'a' + dp[1][k];
				h[0] = (tmp * dp[1][k] + h[i]) % HASH;
				for (p = hash[h[0]]; p != NULL; p = p->next) if (lex_smaller(p->s, &(T[j])) == 0) break;
				if (p != NULL) ans++;
			}
			tmp = tmp * inv % HASH;
			h[i] = (h[i] - tmp * (S[i][j+1] - 'a') % HASH + HASH) % HASH;
		}
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 23520
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int N;
    String S;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        N = sc.nextInt();
        S = sc.next();
    }
    
    //解答処理
    private int solve() {
    	int max = 0;
        
    	for (int i=1; i<N; i++) {
    		int count = 0;
    		boolean[] a1 = new boolean[26];	//左用
        	boolean[] a2 = new boolean[26];	//右用
        	String leftS = S.substring(0,i);
        	String rigthS = S.substring(i,N);
        	
        	//対応する要素番号の要素をtrueにする
        	for (int j=0; j<leftS.length(); j++) {
        		a1[leftS.charAt(j)-'a'] = true;
        	}
        	for (int j=0; j<rigthS.length(); j++) {
        		a2[rigthS.charAt(j)-'a'] = true;
        	}
        	
        	for (int j=0;j<26;j++){
                if (a1[j] && a2[j]){
                  count++;	//両方に存在していればカウント
                }
            }
        	max = Math.max(max,count);
    	}
        return max;
    }
    
    //出力
    public void show(int answer) {
        System.out.println(answer);
    }

}


Measured memory_bytes: 35796
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

struct UF
{
	vector<int> par; // 親のインデックスを記憶する配列
	vector<int> sz; // サイズを記憶する。
	vector<int> rank;
	// 初期化
	UF(int n):par(n),sz(n),rank(n){
		for(int i = 0; i < n; i++){
			par[i] = i;sz[i] = 1;rank[i] = 0;
		}
	}
	// 親を求める
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	// xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if(rank[x] < rank[y]){
			par[x] = y;
			sz[y] += sz[x];
		}
		else{
			par[y] = x;
			sz[x] += sz[y];
			if(rank[x] == rank[y])rank[x]++;
		}
	}
	// xとyが同じ集合ならtrue
	bool same(int x, int y) { return find(x) == find(y); }
	// 素の集合のサイズを求める
	int size(int n){return sz[find(n)];}
};

vector<vector<ll> > ff(111111);
vector<vector<ll> > block(111111);


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

  ll n, m, k;cin >> n >> m >> k;
  UF uf(n);

  REP(i, m){
    ll a, b;cin >> a >> b;
    a--;b--;
    ff[a].PB(b);
    ff[b].PB(a);
    uf.unite(a, b);
  }

  REP(i, k){
    ll a, b;cin >> a >> b;
    a--;b--;
    block[a].PB(b);
    block[b].PB(a);
  }

  REP(i, n){
    set<ll> s;
    REP(j, ff[i].size())s.insert(ff[i][j]);
    ll ans = uf.size(i) - (1 + s.size());
    REP(j, block[i].size()){
      if(uf.same(block[i][j], i) && s.find(block[i][j]) == s.end())ans--;
    }
    cout << ans << " ";
  }
  cout << endl;

	return 0;
}


Measured memory_bytes: 19316
from collections import deque
class csr:
    def __init__(self,N,edges):
        self.start = [0]*(N+1)
        self.elist = [0]*len(edges)
        for e in edges:
            self.start[e[0]+1] += 1
        for i in range(1,N+1):
            self.start[i] += self.start[i-1] 
        counter = self.start[:]
        for e in edges:
            self.elist[counter[e[0]]] = e[1]
            counter[e[0]] += 1

class scc_graph:
    def __init__(self,N):
        self.N = N
        self.edges = []
    
    def add_edge(self,v,w):
        self.edges.append((v,w))

    def scc_ids(self):
        N = self.N
        g = csr(self.N,self.edges)
        now_ord = group_num = 0
        visited = deque()
        low = [0]*N
        order = [-1]*N
        ids = [0]*N
        parent = [-1]*N
        stack = deque()
        for i in range(N):
            if order[i] == -1:
                stack.append(i)
                stack.append(i)
                while stack:
                    v = stack.pop()
                    if order[v] == -1:
                        low[v] = order[v] = now_ord
                        now_ord += 1
                        visited.append(v)
                        for i in range(g.start[v],g.start[v+1]):
                            to = g.elist[i]
                            if order[to] == -1:
                                stack.append(to)
                                stack.append(to)
                                parent[to] = v
                            else:
                                low[v] = min(low[v],order[to])
                    else:
                        if low[v] == order[v]:
                            while True:
                                u = visited.pop()
                                order[u] = N
                                ids[u] = group_num
                                if u == v:
                                    break
                            group_num += 1
                        if parent[v] != -1:
                            low[parent[v]] = min(low[parent[v]],low[v])
        for i,x in enumerate(ids):
            ids[i] = group_num-1-x

        return group_num,ids
    
    def scc(self):
        group_num,ids = self.scc_ids()
        groups = [[] for _ in range(group_num)]
        for i,x in enumerate(ids):
            groups[x].append(i)
        return groups
    
import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
N,M = map(int,readline().split())
ab = list(map(int,read().split()))
sg = scc_graph(N)

it = iter(ab)
for a,b in zip(it,it):
    sg.add_edge(a,b)

scc = sg.scc()
print(len(scc))
for group in scc:
    print(str(len(group))+' '+' '.join(map(str,group)))


Measured memory_bytes: 214272
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    vector<int> a(3);
    rep(i,3) cin >> a.at(i);
    sort(a.begin(), a.end());


    if(a.at(0)+a.at(1)==a.at(2)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3572
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  vector<int> N(4);
  rep(i, 4) cin >> N[i];
  sort(N.begin(), N.end());
  if (N[0] == 1 && N[1] == 4 && N[2] == 7 && N[3] == 9)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 3612
#pragma region _head

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

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define ei else if
#define all(a) a.begin(),a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define int_INF 1<<29
#define ll_INF 1LL<<60
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using mll = map<LL, LL>;
using mcl = map<char, LL>;
using vpi = vector<pi>;

#pragma endregion

void y_n(bool p) {
	p ? _y() : _n();
}

void Y_N(bool p) {
	p ? _Y() : _N();
}

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

//素数判定
bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		ret %= MOD;
	}
	return ret;
}

#pragma endregion 




/*****************************************************************************/
int n, m;
vvi g;
vi dp;

int rec(int v) {
	if (dp[v] != -1)return dp[v];

	int res = 0;
	for(auto v2:g[v]) {
		res = max(res, rec(v2) + 1);
	}
	return dp[v] = res;
}

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

	cin >> n >> m;
	g.assign(n, vi());
	f(i, 0, m) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		g[x].push_back(y);
	}
	dp.resize(n);
	f(i, 0, n) {
		dp[i] = -1;
	}
	int ans = 0;
	f(v, 0, n) {
		ans = max(ans, rec(v));
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <string>
#include <vector>

using namespace std;

unsigned long euclidean_gcd(unsigned long a, unsigned long b);
int main()
{
  unsigned a,b;
  cin >> a >> b;
  unsigned long c = euclidean_gcd(a,b);
  unsigned long ans = a * (b / c);
  cout <<  ans;
  
  return 0;
}

unsigned long euclidean_gcd(unsigned long a, unsigned long b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned long r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

void solve() {
	int n;
	cin >> n;
	vi a(n), b(n), c(n);
	for(int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
	
	vector<vi> dp(n + 1, vi(3, 0));
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	for(int i = 1; i <= n; i++) {
		dp[i][0] = max(dp[i][0], max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i]));
		dp[i][1] = max(dp[i][1], max(dp[i - 1][0] + b[i], dp[i - 1][2] + b[i]));
		dp[i][2] = max(dp[i][2], max(dp[i - 1][0] + c[i], dp[i - 1][1] + c[i]));
	}
	
	cout << max(max(dp[n][0], dp[n][1]), dp[n][2]) << endl;
}

int main(){
#define MULTITEST 0
#if MULTITEST   
 
    CASET {
        solve();
    }
    
#else

    solve();
    
#endif

    return 0;
}

Measured memory_bytes: 9800
#include <iostream>
using namespace std;
int d[12][12]={},n;
void cal(int X,int Y,int num,int R){
	if(num<=n*n){
		d[X][Y]=num;
		num++;
		int RR;
		if(R==1){
			X++;
			if(Y==1)RR=2;
			else RR=3;
		}
		else if(R==2){
			X--,Y++;
			if(X==1 && Y==n)RR=1;
			else if(X==1)RR=4;
			else if(Y==n)RR=1;
			else RR=2;
		}
		else if(R==3){
			X++,Y--;
			if(Y==1 && X==n)RR=4;
			else if(Y==1)RR=1;
			else if(X==n)RR=4;
			else RR=3;
		}
		else if(R==4){
			Y++;
			if(X==1)RR=3;
			else RR=2;
		}
		cal(X,Y,num,RR);
	}
}
int main(){
	int Case=1;
	while(cin>>n,n){
		cout<<"Case "<<Case<<":"<<endl;
		cal(1,1,1,1);
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if(d[j][i]>99)cout<<d[j][i];
				else if(d[j][i]>9)cout<<" "<<d[j][i];
				else cout<<"  "<<d[j][i];
			}
			cout<<endl;
		}
		Case++;
	}
	return 0;
}


Measured memory_bytes: 1160
# 3重ループでテスト

from functools import reduce

k = int(input())

def gcd(a, b):
    # 最大公約数
    while b:
        a, b = b, a % b
    return a

def gcds(*nums):
	return reduce(gcd, nums)

res = 0
for a in range(1, k + 1):
	for b in range(1, k + 1):
		for c in range(1, k + 1):
			res += gcds(a, b, c)

print(res)

Measured memory_bytes: 75856
n=int(input())
p=list(map(int,input().split()))
ok=True
for i in range(1,n):
  if p[i]-p[i-1]>0:
    continue
  ok=False
if ok:
  print("YES")
  exit(0)

for i in range(n):
  for j in range(n):
    if i==j:continue
    t=p[:]
    taihi=t[i]
    t[i]=t[j]
    t[j]=taihi
    ok=True
    for k in range(1,n):
      if t[k]-t[k-1]>0:
        continue
      ok=False
    if ok:
      print("YES")
      exit(0)
print("NO")



Measured memory_bytes: 9220
#include <cstdio>
#include <iostream>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

int vs[110];

int main(void) {
  int n;
  cin >> n;
  REP(i, n) {
    cin >> vs[i];
  }
  sort(vs, vs + n);
  printf("%d\n", vs[n-1] - vs[0]);
  return 0;
}


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

int main()
{
	int n, m; cin >> n >> m;
	int total = 0;
	vector<int>v(n);
	for (int i = 0; i < n; i++){
		cin >> v[i];
		total += v[i];
	}
	double q = ((double)total / (double)(4 * m));
	int c = 0;
	for (int i = 0; i < n; i++)
	{
		if (v[i] >=q )
			c += 1;
	}

	if (c >= m)
		cout << "Yes";
	else
		cout << "No";

}

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

using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<double>;
using VVI = vector<VI>;
using VVL = vector<VL>;
using PI = pair<int, int>;
using PL = pair<ll, ll>;
using VPI = vector<PI>;
using VPL = vector<PL>;
using VS = vector<string>;

#define ln '\n'
#define REP(t, n) for (int t = 0; t < (n); ++t)
#define FOR(t, a, b) for (int t = (a); t <= (b); ++t)
#define FORR(t, a, b) for (int t = (a); t >= (b); --t)
#define ALL(c) (c).begin(), (c).end()

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int left, right;
    cin >> left >> right;
    bool ok = true;
    REP(i, m - 1) {
        int l, r;
        cin >> l >> r;
        if (!ok) continue;
        if (r < left)
            ok = false;
        else if (l <= left && left <= r && r <= right)
            right = r;
        else if (left <= l && r <= right)
            left = l, right = r;
        else if (left <= l && l <= right && right <= r)
            left = l;
        else if (right < l)
            ok = false;
    }
    // cerr << left << " " << right << ln;
    if (!ok)
        cout << 0 << ln;
    else {
        int num = right - left + 1;
        if (num > n)
            cout << n << ln;
        else
            cout << num << ln;
    }
    return 0;
}


Measured memory_bytes: 256
const lines=readlines()
state=0
input()=lines[global state+=1]
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
floatSub(s::SubString{String})=parse(Float64,s)
intLine()=map(intSub,split(input()))
function main()
    s=input()
    println(minimum(abs(753-int(s[i:i+2])) for i=1:length(s)-2))
end
main()

Measured memory_bytes: 117152
import sys
from collections import Counter
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
odds, evens = A[0::2], A[1::2]
if N % 2 == 0:
    evens = evens[::-1]
    print(' '.join(str(x) for x in evens+odds))
else:
    odds = odds[::-1]
    print(' '.join(str(x) for x in odds+evens))

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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    string s;
    ll k;
    cin >> s >> k;
    int ans;
    REP(i,s.size()){
        if(s[i] == '1'){
        if(i+1==k){
            ans = 1;
            break;
        }
        }
        else{
            if(s[i]=='2') ans = 2;
            if(s[i]=='3') ans = 3;
            if(s[i]=='4') ans = 4;
            if(s[i]=='5') ans = 5;
            if(s[i]=='6') ans = 6;
            if(s[i]=='7') ans = 7;
            if(s[i]=='8') ans = 8;
            if(s[i]=='9') ans = 9;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

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

	res := 0
	for i:= 0; i < 2; i++ {
		if a > b {
			res += a
			a--
		} else {
			res += b
			b--
		}
	}

	fmt.Println(res)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
namespace mp = boost::multiprecision;// 任意長整数型
using bint = mp::cpp_int;// 仮数部長が32の浮動小数点数型
using real32 = mp::number<mp::cpp_dec_float<32>>;// 仮数部長が1024の浮動小数点数型
using real1024 = mp::number<mp::cpp_dec_float<1024>>;// ついでに有理数型
using rat = boost::rational<bint>;
*/
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
int main(){ //srand((unsigned)time(NULL));
  while(1){
    ll H,W;
    cin >> H >> W;
    if(H == 0 && W == 0)break;
    for (int i = 0; i < H; i++) {
      for (int l = 0; l < W; l++) {
        if(l%2 == 0){
          cout << (i%2 == 0 ? '#':'.');
        }else{
          cout << (i%2 == 0 ? '.':'#');
        }
      }
      cout << endl;
    }cout << endl;
  }
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    int a, b;
    cin >> a >> b;
    cout << a * (a - 1) / 2 + b * (b - 1) / 2 << endl;

    return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include<algorithm>
using lint=long long;
using namespace std;

int main()
{
	int N;
	int A[110]={};
	int cnt=1;
	int ans=0;
	
	cin >> N;
	cin >> A[0];
	for(int i=1;i<N;i++)
	{
		cin >> A[i];
		if(A[i]==A[i-1])cnt++;
		else
		{
			ans+=cnt/2;
			cnt=1;
		}
		
	}
	ans+=cnt/2;
	
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

vector<vector<int>> g;
vector<long long> a;
vector<bool> used;
bool ans;
int loot;

long long requirePairNumber(vector<long long> v){
	sort(all(v), greater<long long>());

	long long sum = 0;
	sum += v[1];
	v[0] -= v[1];

	long long remainder = 0;
	range(i,2,v.size()){
		sum += v[i] / 2;
		if(v[i] % 2){
			if(v[0] > 0){
				v[0]--;
				sum++;
			}else{
				remainder++;
			}
		}
	}

	sum += remainder / 2;
	return sum;
}

long long dfs(int cur){
	used[cur] = true;

	vector<long long> v;
	for(auto to : g[cur]){
		if(used[to]) continue;
		v.emplace_back(dfs(to));
	}

	//show(cur) for(auto i : v){ cout << i << ' ' ; } cout << endl;

	if(v.empty()){
		//cout << "return " << a[cur] << endl;
		return a[cur];
	}else{
		long long childSum = accumulate(all(v), 0);
		if(childSum < a[cur]){ //どのようにしても石が取りきれない
			ans = false;
			return 0;
		}

		long long maximumPair = min(childSum - *max_element(all(v)), childSum / 2);
		//show(maximumPair)
		if(loot == cur and maximumPair != a[cur]){
			ans = false;
			return 0;
		}

		long long needPair = childSum - a[cur];
		if(maximumPair >= needPair){
			return a[cur] - needPair;
		}else{
			ans = false;
		}

		return 0;
	}
}

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

	a = vector<long long>(n);
	rep(i,n){
		cin >> a[i];
	}

	g = vector<vector<int>>(n);
	rep(i,n - 1){
		int a, b;
		cin >> a >> b;
		a--; b--;

		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}

	if(n == 2){
		ans = a[0] == a[1];
	}else{
		loot = 0;
		while(g[loot].size() == 1) loot++; //葉ではない頂点を探す

		used = vector<bool>(n,0);
		ans = true;
		dfs(loot);
	}

	cout << (ans ? "YES" : "NO") << endl;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	string s;
	cin>>s;

	lli left=0,right=s.size()-1;
	lli cnt=0;
	while(left<right){
		if(s.at(left)==s.at(right)){
			left++;
			right--;
			continue;
		}
		if(s.at(left)=='x'){
			left++;
			cnt++;
			continue;
		}
		if(s.at(right)=='x'){
			right--;
			cnt++;
			continue;
		}
		cout<<-1<<endl;
		return 0;
	}
	cout<<cnt<<endl;

	return 0;
}

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

long long int N, M, a, b, d, e;
vector<pair<long long, long long>> s, c;

long long mht(pair<long long, long long> a, pair<long long, long long> b){
    return abs(a.first - b.first) + abs(a.second - b.second);
}

int main(){
    scanf("%lld%lld", &N, &M);
    for(int i = 0; i < N; ++i){
        scanf("%lld%lld", &a, &b);
        s.emplace_back(a, b);
    }
    for(int i = 0; i < M; ++i){
        scanf("%lld%lld", &a, &b);
        c.emplace_back(a, b);
    }
    for(auto i : s){
        a = 1245987519240975012;
        b = -1;
        e = 0;
        for(auto j : c){
            ++e;
            d = mht(i, j);
            if(a > d){
                a = d;
                b = e;
            }
        }
        cout << b << endl;
    }
    return 0;
}

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

using namespace std;

int main(void){
    string b;

    cin >> b;

    if(b=="A")cout << "T" << endl;
    else if(b=="C")cout << "G" << endl;
    else if(b=="G")cout << "C" << endl;
    else if(b=="T")cout << "A" << endl;

    return 0;
}

Measured memory_bytes: 256