akhauriyash/Code-Regression huggingface dataset:
using System;

namespace Application
{
    public class MainClass
    {
        public static void Main(string[] args)
        {
            string[] NQ = Console.ReadLine().Split(' ');
            int N = int.Parse(NQ[0]);
            int Q = int.Parse(NQ[1]);
            string S = Console.ReadLine();
            int[] l = new int[Q];
            int[] r = new int[Q];
            for (int i = 0; i < Q; i++)
            {
                string[] ls = Console.ReadLine().Split(' ');
                l[i] = int.Parse(ls[0]);
                r[i] = int.Parse(ls[1]);
            }
            int count = 0;
            int[] binjud = new int[N];
            int[] result = new int[Q];

            for (int i = 0; i < N - 1; i++)
            {
                if ( S[i] == 'A' && S[i + 1] == 'C')
                {
                    count++;
                }
                binjud[i] = count;
            }
            binjud[N - 1] = binjud[N - 2];

            /*累積和配列確認
            foreach (int i in binjud)
            {
                Console.Write("{0}", i);
            }
            Console.WriteLine();
            */           

            //差を確認
            for (int i = 0; i < Q; i++)
            {
                if (l[i] >= 2)
                {
                    result[i] = binjud[r[i] - 2] - binjud[l[i] - 2];
                }
                else
                {
                    result[i] = binjud[r[i] - 2];
                }
            }
            for (int i = 0; i < Q; i++)
            {
                Console.WriteLine(result[i]);
            }
        }
    }
}


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

int c[200005];
int parent[200005];

void reset(int n)
{
	for (int i = 1; i <= n; i++)
		parent[i] = i;
}

int Find(int x)
{
	if (parent[x] == x)
		return x;
	return parent[x] = Find(parent[x]);
}

void Union(int a, int b)
{
	a = Find(a);
	b = Find(b);

	if (a != b)
		parent[b] = a;
}

int main(void)
{
	int n, m;

	scanf("%d %d", &n, &m);

	reset(n);

	while (m--)
	{
		int x, y;

		scanf("%d %d", &x, &y);
		
		Union(x, y);
	}

	for (int i = 1; i <= n; i++)
		c[Find(i)]++;

	printf("%d", *max_element(c + 1, c + n + 1));

	return 0;
}

Measured memory_bytes: 5180
I=lambda:map(int,input().split());F=1e21;r=range;n,m=I();f=[-F,F];X=set([0]+f);Y=set(X);R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):a,b,c=I();R+=[((a,b),c)];Y.add(c);X.add(a);X.add(b)
for i in r(m):a,b,c=I();H+=[(a,(b,c))];X.add(a);Y.add(b);Y.add(c)
s=dict(enumerate(sorted(X)));K=len(s);t=dict(enumerate(sorted(Y)));L=len(t);h=dict(zip(s.values(),s.keys()));w=dict(zip(t.values(),t.keys()));V=[[0]*-~K for i in r(L+1)];U=[i[:]for i in V];v=[i[:]for i in V]
for(a,b),c in R:U[w[c]][h[a]]+=1;U[w[c]][h[b]]+=-1
for i in r(L+1):
 for j in r(K):U[i][j+1]+=U[i][j]
for d,(e,f)in H:V[w[e]][h[d]]+=1;V[w[f]][h[d]]+=-1
for j in r(K+1):
 for i in r(L):V[i+1][j]+=V[i][j]
q=[(h[0],w[0])];v[w[0]][h[0]]=1;a=0
while q:
 x,y=q.pop();a+=(s[x]-s[x+1])*(t[y]-t[y+1])
 for e,f in[(-1,0),(1,0),(0,1),(0,-1)]:
  c=x+e;d=y+f
  if(0<=c<K)*(0<=d<L)*v[d][c]==0:
   if U[-~f//2+y][x]==0if f!=0else V[y][-~e//2+x]==0:q.append((c,d));v[d][c]=1
if a>F:a='INF'
print(a)

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

using namespace std;

const int maxN = 1e5 + 10;

int x[maxN], n, k, res;

int main() {
    cin >> n >> k;
    res = 3e8;
    for (int i = 0; i < n; ++i) cin >> x[i];
    for (int i = 0; i < n - k + 1; ++i) {
        int j = i + k - 1;
        if ((x[i] <= 0) == (x[j] <= 0))
            res = min(res, (int) max(abs(x[i]), abs(x[j])));
        else
            res = min(res, x[j] - x[i] + min(-x[i], x[j]));
    }
    cout << res;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int w = sc.nextInt();
			int h = sc.nextInt();
			if(w == 0 && h == 0) break;
			long dp[][][] = new long[h][w][2];
			dp[0][0][0] = 1;
			dp[0][0][1] = 1;
			int i = 0;
			int j = 0;
			if(i + 1 < h) {
				dp[i+1][j][0] += dp[i][j][0];
			}
			if(j + 1 < w) {
				dp[i][j+1][1] += dp[i][j][1];
			}
			for(i = 0; i < h; i++) {
				for(j = 0; j < w; j++) {
					if(i == 0 && j == 0) continue;
					if(i+2 < h) {
						dp[i+2][j][0] += dp[i][j][1];
						dp[i+2][j][0] %= 100000;
					}
					if(j+2 < w) {
						dp[i][j+2][1] += dp[i][j][0];
						dp[i][j+2][1] %= 100000;
					}
					if(i + 1 < h) {
						dp[i+1][j][0] += dp[i][j][0];
						dp[i+1][j][0] %= 100000;
					}
					if(j + 1 < w) {
						dp[i][j+1][1] += dp[i][j][1];
						dp[i][j+1][1] %= 100000;
					}
				}
			}
			System.out.println((dp[h-1][w-1][0] + dp[h-1][w-1][1] + dp[h-2][w-1][1] + dp[h-1][w-2][0])%100000);
		}
	}
}

Measured memory_bytes: 19204
#include <stdio.h>

#define MAX_SIZE 1000000

int main(void) {
    int s, i, a[MAX_SIZE];
    int f = 0;
    if (scanf("%3d", &s) != EOF) {
        a[0] = s;
        for (i = 1; i < MAX_SIZE; i++) {
            if (a[i-1] % 2 == 0) {
                a[i] = a[i-1]/2;
            } else {
                a[i] = a[i-1]*3+1;
            }
            for (int j = 0; j < i; j++) {
                if (a[j] == a[i]) {
                    f = 1;
                    break;
                }
            }
            if (f) break;
        }
        printf("%d", i+1);
    }
    return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        // code goes here
        String s = br.readLine();
        int ans = 0;
        int count = 0;
        for(int i = 0; i < s.length(); i++){
            if(s.charAt(i) == 'R') count++;
            else {
                ans = Math.max(ans, count);
                count = 0;
            }
        }
        ans = Math.max(ans, count);
        sb.append(ans);
        System.out.print(sb.toString());
    }

    private static int nextInt(BufferedReader br) throws IOException{
        return Integer.parseInt(br.readLine());
    }

    private static int[] nextIntArray(BufferedReader br, int n) throws IOException{
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        return arr;
    }

    static class Pair<A, B>{
        A first;
        B second;
        public Pair(A first, B second){
            this.first = first;
            this.second = second;
        }
    }
}


Measured memory_bytes: 32444
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using ll = long long;
using P  = pair<int, int>;
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
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; }

int main()
{
    string a, b;
    cin >> a >> b;
    string s = a + b;
    int x = stoi(s);
    int y = sqrt(x);
    rep2(i, y, 10000){
        if(i*i == x){
            cout << "Yes" << endl; return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <algorithm>
 
using namespace std;
 
typedef long long ll;
 
const ll N = 100005;
ll n, cnt;
ll a[N], b[N], c[N];
ll d[N], e[N];
 
int main()
{
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    for(ll i = 0; i < n; i++)
    {
        scanf("%d", &b[i]);
    }
    for(ll i = 0; i < n; i++)
    {
        scanf("%d", &c[i]);
    }
    sort(a, a + n, greater<ll>());
    sort(b, b + n, greater<ll>());
    for(ll i = 0, j = 0; i < n; i++)
    {
        for(; j < n; j++)
        {
            if(b[i] > a[j]) {break;}
        }
        d[i] = n - j;
    }
    sort(b, b + n);
    sort(c, c + n);
    for(ll i = 0, j = 0; i < n; i++)
    {
        for(; j < n; j++)
        {
            if(b[i] < c[j]) {break;}
        }
        e[i] = n - j;
        cnt += d[n - i - 1] * e[i];
    }
    printf("%lld", cnt);
    return 0;
}

Measured memory_bytes: 4096
S = input()
T = ""
N = len(S)
flag = 0
for i in range(N):
  if flag == 1:
    flag = 0
    continue
  elif S[i:i+2] == "BC":
    T += "D"
    flag = 1
  else:
    T += S[i]

M = len(T)
count = 0
ans = 0
for i in range(M):
  if T[i] == "A":
    count += 1
  elif T[i] == "D":
    ans += count
  else:
    count = 0
print(ans)

Measured memory_bytes: 3500
#include<bits/stdc++.h>
#include<vector>
#include<math.h>
#include<string.h>
using namespace std;
#define MOD 1000000007
#define MAX 200005
#define PMAX 55
#define PRECISION 0.000001
#define INF 1000000000000000000
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
int P[MAX];
int members[MAX];
int minVal[MAX];
int Find(int x)
{
    if(P[x]==x) return x;
    else
    {
        P[x]=Find(P[x]);
        return P[x];
    }
}
bool Join(int x,int y)
{
    int PoX=Find(x),PoY=Find(y);
    if(PoX==PoY) return false;
    else if(PoX<PoY)
    {
        members[PoX]+=members[PoY];
        minVal[PoX]=min(minVal[PoX],minVal[PoY]);
        P[PoY]=PoX;
    }
    else
    {
        members[PoY]+=members[PoX];
        minVal[PoY]=min(minVal[PoX],minVal[PoY]);
        P[PoX]=PoY;
    }
    return true;
}
pair<int,int> p[MAX];
set<pair<int,int> > S;
set<pair<int,int> >::iterator it;
int ans[MAX];
int main()
{
    int n,i,j,k;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d %d",&j,&k);
        j--;
        k--;
        p[j]=make_pair(k,i);
        P[i]=i;
        members[i]=1;
        minVal[j]=k;
    }
    for(i=0;i<n;i++)
    {
        pair<int,int> r=make_pair(p[i].first,i);
        while(S.size()>0)
        {
            it=S.begin();
            pair<int,int> q=*it;
            if(q.first>p[i].first) break;
            //printf("%d->(%d,%d),(%d,%d)",i,q.second,q.first,r.second,r.first);
            Join(i,q.second);
            r.second=Find(i);
            r.first=minVal[r.second];
            //printf("->(%d,%d)\n",r.second,r.first);
            S.erase(q);
        }
        S.insert(r);
    }
    for(i=0;i<n;i++)
    {
        ans[p[i].second]=members[Find(i)];
    }
    for(i=0;i<n;i++)
    {
        printf("%d\n",ans[i]);
    }
    return 0;
}


Measured memory_bytes: 12672
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    for (int i = b * 10; i < b * 10 + 10; i++) {
        if ((int)(i * 0.08) == a) {
            printf("%d", i);
            return 0;
        }
    }
    printf("-1");
    return 0;
}

Measured memory_bytes: 128
using System.Collections.Generic;
using System;

public class hello
{
    public static void Main()
    {
        var wk = new int[2];
        for (int i = 0; i < 2; i++)
        {
            var wklist = new List<int>();
            for (int j = 0; j < 10; j++)
            {
                var n = int.Parse(Console.ReadLine().Trim());
                wklist.Add(n);
            }
            wklist.Sort();
            wklist.Reverse();
            wk[i] = wklist[0] + wklist[1] + wklist[2];
        }
        Console.WriteLine("{0} {1}", wk[0], wk[1]);
    }
}

Measured memory_bytes: 9296
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
    }
    let mut ans = format!("{}", n).len();
    for a in 1..(n as f64).sqrt() as usize + 1 {
        if n % a != 0 {
            continue;
        }
        let b = n / a;
        let acc = max(format!("{}", a).len(), format!("{}", b).len());
        ans = min(ans, acc);
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll lmax(ll a, ll b){if(a>= b) return a;return b;}
ll lmin(ll a, ll b){if(a>= b) return b;return a;}
static const ll INF = 1e18;

struct Edge {
    int to;     // 辺の行き先
    ll weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};

using Graph = vector<vector<Edge>>;

Graph g;
vector<int> ans;

void dfs(int v){
  for(auto next_v : g[v]){
    if(ans[next_v.to] != -1) continue;
    if(next_v.weight == 1){
      if(ans[v] == 0) ans[next_v.to] = 1;
      else ans[next_v.to] = 0;
    } else {
      if(ans[v]==0) ans[next_v.to] = 0;
      else ans[next_v.to] = 1;
    }
    dfs(next_v.to);
  }
}

int main() {
  int n; cin >> n;
  g.resize(n);
  vector<int> u(n-1), v(n-1);
  rep(i, n-1){
    ll w;
    cin >> u[i] >> v[i] >> w;
    w %= 2;
    --u[i];--v[i];
    g[u[i]].pb(Edge(v[i], w));
    g[v[i]].pb(Edge(u[i], w));
  }

  ans.resize(n);
  rep(i, n) ans[i] = -1;
  ans[0] = 1;

  dfs(0);

  rep(i, n){
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 13156
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N, K;
  cin >> N >> K;
  ll most = (N - 1) * (N - 2) / 2;
  if (K > most) {
    cout << -1 << "\n";
    return 0;
  }
  ll M = N - 1 + most - K;
  cout << M << "\n";
  for (ll i = 1; i < N; ++i) {
    cout << 1 << ' ' << i + 1 << "\n";
  }
  vector<ll> node(N - 1);
  for (ll i = 0; i < N - 1; ++i) {
    node.at(i) = i + 2;
  }
  ll cnt = 0;
  for (ll i = 0; i < N - 2; ++i) {
    for (ll j = i + 1; j < N - 1; ++j) {
      if (cnt == most - K) {
        return 0;
      }
      cout << node.at(i) << ' ' << node.at(j) << "\n";
      cnt += 1;
    }
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
 
const int MAXN = 5e5 + 5;
 
char s[MAXN << 2], t[MAXN];
int lenS, lenT, copyLenS, copyLenT, ans;
int next[MAXN], sum;
int entry[MAXN], res[MAXN], dp[MAXN];
bool find[MAXN << 2];
 
std::vector<int> con[MAXN];
std::queue<int> q;
 
void init() {
    int place = 0;
    next[1] = 0;
    for (int i = 2; i <= lenT; ++i) {
        while (place && t[i] != t[place + 1]) {
            place = next[place];
        }
        if (t[i] == t[place + 1])
            ++place;
        next[i] = place;
    }
}
 
void kmp() {
    init();
    int place = 0;
    for (int i = 1; i <= lenS; ++i) {
        while(place && s[i] != t[place + 1]) {
            place = next[place];
        }
        if (s[i] == t[place + 1])
            ++place;
        if (place == lenT && i - lenT + 1 <= copyLenS) {
            find[i - lenT + 1] = true;
            place = next[place];
            ++sum;
        }
    }
}
 
void ins(int start,int end) {
    con[start].push_back(end);
    ++entry[end];
}
 
bool topSort() {
    int cnt = 0;
    for (int i = 1; i <= copyLenS; ++i) {
        if (find[i] && entry[i] == 0)
            q.push(i);
    }
    while (!q.empty()) {
        int cur = q.front();
        res[++cnt] = cur;
        for (int i = 0; i < con[cur].size(); ++i) {
            if (--entry[con[cur][i]] == 0)
                q.push(con[cur][i]);
        }
        q.pop();
    }
    return cnt == sum;
}
 
int main() {
    scanf("%s%s", s + 1, t + 1);
    copyLenS = lenS = strlen(s + 1);
    copyLenT = lenT = strlen(t + 1);
    while (copyLenT > 0) {
        for (int i = 1; i <= copyLenS; ++i) {
            s[++lenS] = s[i];
        }
        copyLenT -= copyLenS;
    }
    kmp();
    for (int i = 1; i <= copyLenS; ++i) {
        int k = ((i + lenT) % copyLenS == 0) ? copyLenS : ((i + lenT) % copyLenS);
        if (find[i] && find[k])
            ins(i, k);
    }
    if (topSort()) {
        for (int k = 1; k <= sum; ++k) {
            int i = res[k];
            if (dp[i] == 0)
                dp[i] = 1;
            for (int j = 0; j < con[i].size(); ++j) {
                dp[con[i][j]] = std::max(dp[con[i][j]], dp[i] + 1);
            }
        }
        for (int i = 1; i <= sum; ++i) {
            ans = std::max(ans, dp[res[i]]);
        }
    }
    else
        ans = -1;
    printf("%d", ans);
    return 0;
}


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

int main() {
	int a = 0;
	char maze[10][10];
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			maze[i][j] = '0';
		}
	}
	while (cin >> maze[1][1]) {
		for (int i = 2; i < 9; i++) {
			cin >> maze[1][i];
		}
		for (int i = 2; i < 9; i++) {
			for (int j = 1; j < 9; j++) {
				cin >> maze[i][j];
			}
		}
		int ok = 0;
		for (int i = 1; i < 9; i++) {
			for (int j = 1; j < 9; j++) {
				if (maze[i][j] == '1') {
					ok = 1;
					if (maze[i][j + 1] == '1') {
						if (maze[i][j + 2] == '1') {
							cout << "C" << endl;
						}
						else {
							if (maze[i + 1][j] == '1') {
								if (maze[i + 1][j + 1] == '1') {
									cout << "A" << endl;
								}
								else {
									cout << "G" << endl;
								}
							}
							else {
								cout << "E" << endl;
							}
						}
					}
					else {
						if (maze[i + 1][j - 1] == '1') {
							cout << "D" << endl;
						}
						else if (maze[i + 1][j + 1] == '1') {
							cout << "F" << endl;
						}
						else {
							cout << "B" << endl;
						}
					}
				}
				if (ok) break;
			}
			if (ok) break;
		}
		//if (a) cout << endl;
		a++;
	}

}


Measured memory_bytes: 3076
op=0
while op!="?":
    a,op,b=(input().split())
    a=int(a)
    b=int(b)
    if op=="+":
        print(int(a+b))
    elif op=="-":
            print(int(a-b))
    elif op=="*":
        print(int(a*b))
    elif op=="/":
        print(int(a//b))
    else:
        pass


Measured memory_bytes: 5592
H, W, N, *rest = $stdin.read.split.map(&:to_i)
BS = rest.each_slice(2)
SQUAERS = {}

BS.each do |y, x|
  (-2..0).each do |dy|
    (-2..0).each do |dx|
      yy, xx = y+dy, x+dx
      if (1..(H-2)).cover?(yy) && (1..(W-2)).cover?(xx)
        SQUAERS[yy] ||= {}
        SQUAERS[yy][xx] ||= 0
        SQUAERS[yy][xx] += 1
      end
    end
  end
end

ns = SQUAERS.values.flat_map(&:values)
ans = (1..9).map{|i| ns.count(i)}
ans.unshift( (W-2)*(H-2) - ans.inject(:+) )
puts ans


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

int main(void) {
  int N, l, r;
  cin >> N;
  int counter;

  for (int i = 0; i < N; ++i) {
    cin >> l >> r;
    counter += r - l + 1;
  }

  cout << counter << endl;

  return 0;
}

Measured memory_bytes: 256
n = int(input())
ss = [int(input()) for _ in range(n)]
ss = sorted(ss)

ans = sum(ss)
if ans % 10 !=0:
  pass
else:  
  flag = True
  for si in ss:      
    if si % 10 !=0:
      ans -= si
      flag = False
      break
  if flag:
    ans = 0

print(ans)      

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k;
	string s;
	cin>>k;
	cin>>s;
	if(k>=s.size()) cout<<s<<endl;
	else{
		for(int i=0;i<k;i++) cout<<s[i];
		cout<<"..."<<endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
    string a[3];
    for (int i = 0; i < 3; i++)
        cin >> a[i];
    string b;
    b += a[0].at(0);
    b += a[1].at(1);
    b += a[2].at(2);
    cout << b;
    return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
#define per(i , j , n) for(long long i = j ; i >= n ; i--)
const ll N = 123456;

ll a[N];
int big[N];
int small[N];
int ans = 0;
const ll mod = 1e9 + 7;

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

    int n;
    cin >> n;

    rep(i , 1 , n) cin >> a[i];

    ll maxi = INT_MIN;

    rep(i , 1 , n) maxi = max(maxi , a[i]);

    rep(i , 1 , n) {
        big[a[i]]++;
        small[a[i]]++;
    }

    per(i , maxi , 1) {
        big[i] += big[i + 1];
    }

    rep(i , 1 , maxi) {
        small[i] += small[i - 1];
    }

    rep(i , 1 , maxi) {
        if(small[i - 1] == big[i]) {
           // cout << i << " " << big[i] << " " << small[i - 1] << endl;
            ans++;
        }
    }

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


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

using namespace std;

int main()
{
	string w;
	int chars[1000];
	for (int i = 0; i < 1000; i++)
	{
		chars[i] = 0;
	}
	cin >> w;
	for (int i = 0; i < w.length(); i++)
	{
		chars[w[i]]++;
	}
	bool isbeautiful = true;
	for (int i = 0; i < 1000; i++)
	{
		if (chars[i] % 2 == 1)
			isbeautiful = false;
	}
	if (isbeautiful)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    ll n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    for(int i=0;i<n;i++){
	cout<<s[i]<<t[i];
    }
    cout<<endl;
    return 0;
}


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

int main()
{
	int N;
	bool all_even = true;

	std::cin >> N;
	for (int i = 0; i < N; ++i) {
		int a;
		std::cin >> a;
		all_even &= (a % 2 == 0);
	}
	std::cout << (all_even ? "second" : "first") << "\n";
}


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

#define sz(x) static_cast<int>((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using ld = long double;

template<class T> bool cmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool cmx(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector<int> vec(n);
	for(int& x: vec) cin >> x;
	double avg = 0;
	for(int x : vec) avg += x;
	avg /= n;
	int val = (int) round(avg);
	int ans = 0;
	for(int i = 0; i < n; ++i) {
		int go = abs(val - vec[i]);
		ans += go * go;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	N := getStdinInt64()
	Nori := N
	arr := make([]bool, int(math.Sqrt(float64(N)))+1)

	// 初期化
	for i := 2; i < len(arr); i++ {
		arr[i] = true
	}
	// 素数を求める
	arr[0] = false
	arr[1] = false
	for i := 2; i < len(arr); i++ {
		if arr[i] {
			for j := i * 2; j < len(arr); j += i {
				arr[j] = false
			}
		}
	}
	// 割り切れるか判別（素因数分解）
	cnt := 0
	var i int64
	for i = 2; int(i) < len(arr); i++ {
		if arr[i] && (N%i) == 0 {
			mul := i
			pow := 1
			for {
				if N%mul == 0 {
					cnt++
					N /= mul
					pow++
					mul = 1
					for n := 0; n < pow; n++ {
						mul *= i
					}
				} else {
					break
				}
			}
			if N <= 1 {
				break
			}
		}
	}
	// 素因数分解のあまり
	if N > 1 && int(N) > len(arr) {
		cnt++
	}

	if cnt == 0 && (Nori == 0 || Nori == 1) {
		fmt.Printf("%d\n", 0)
	} else if cnt == 0 {
		fmt.Printf("1\n")
	} else {
		fmt.Printf("%d\n", cnt)
	}
}

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func getStdin() string {
	return readLine()
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 2824
if __FILE__ == $0
  while true
    line = gets
    n, s = line.split.map{|i| i.to_i}

    if n == 0 && s == 0
      break
    end

    count = 0
    (0..9).to_a.combination(n) {|arr|
      if arr.inject(:+) == s
        count += 1
      end
    }
    puts count
  end
end

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


def main():
    N, M = map(int, input().split())
    graph = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        graph[a-1].append(b-1)
        graph[b-1].append(a-1)

    if M%2 == 1:
        print(-1)
        return

    q = [0]
    checked = [False]*N
    checked[0] = True
    search_seq = [0]
    while q:
        qq = []
        for p in q:
            for np in graph[p]:
                if not checked[np]:
                    checked[np] = True
                    qq.append(np)
                    search_seq.append(np)
        q = qq
    
    evenOrOdd = []
    for n in range(N):
        evenOrOdd.append(len(graph[n])%2)
    
    searched = [False]*N
    ans = []
    for p in reversed(search_seq):
        evens = []
        odds = []
        for np in graph[p]:
            if not searched[np]:
                if evenOrOdd[np]:
                    odds.append(np)
                else:
                    evens.append(np)
        if not odds and not evens:
            break

        if evenOrOdd[p] == 1:
            if odds:
                np = odds.pop()
                ans.append((np, p))
            else:
                np = evens.pop()
                ans.append((np, p))
        for np in odds:
            ans.append((p, np))
            evenOrOdd[np] = 0
        for np in evens:
            ans.append((p, np))
            evenOrOdd[np] = 1
            
        searched[p] = True
    
    for a1, a2 in ans:
        print(a1+1, a2+1)

    return            

        

if __name__ == "__main__":
    main()

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

using namespace std;

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(){
    int K; cin >> K;
    long long ans = 0;
    
    for (int i = 1; i <= K; i++)
    {
      for (int j = 1; j <= K; j++)
      {
        for (int k = 1; k <= K; k++)
        {
          ans += gcd(gcd(i, j), k);
        }
        
      }
      
    }
    
    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 3624
/*"Success isn't permanent, failure isn't fatal,
                                      it's the courage to continue that counts"*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=54;

struct util
{
	int a,b,c,d;
};

util arr[N];

int n,m,q,ans;

vector<int> v(10,0);

void check()
{
	int here=0;

	rep(i,0,q)
	{
		if(v[arr[i].b-1]-v[arr[i].a-1]==arr[i].c)
		here+=arr[i].d;
	}

	ans=max(ans,here);
}

void solve(int ind)
{
	if(ind==n)
	{
		check(); return;		
	}

	int prev=1;

	if(ind)
	prev=v[ind-1];

	for(int i=prev;i<=m;i++)
	{
		v[ind]=i; 

		solve(ind+1);
	}
}

int main()
{
	scn(n); scn(m); scn(q);

	rep(i,0,q)
	cin>>arr[i].a>>arr[i].b>>arr[i].c>>arr[i].d;

	solve(0);

	pri(ans);

    return 0;
}

Measured memory_bytes: 3832
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#define int long 
using namespace std;

signed main() {
	int N;
	cin >> N;
	cout << 3 * N * N << endl;
}

Measured memory_bytes: 764
#include <cstdio>
int a[100005];
int main(int argc, char const *argv[])
{
    long long n;
    long long suma =0;
    scanf("%lld",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        suma += a[i];
    }
    long long sumy = suma/(((1+n)*n)/2);
    if(sumy * (((1+n)*n)/2) != suma ){
        printf("NO\n");
        return 0;
    }


    for (int i=0;i<n-1;i++){
        long long k = a[i+1]-a[i];
        long long y = (sumy - k)/n;
        if(y<0 || y*n != sumy -k){
            printf("NO\n");
            return 0;
        }

    }
    printf("YES\n");


    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,C;
    cin >> N >> C;
    vector<vector<int>>D(C,vector<int>(C));
    for(int i = 0; i < C; i++) {
        for(int j = 0; j < C; j++) {
            cin >> D[i][j];
        }
    }
    vector<vector<int>>cnt(3,vector<int>(C));
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            int c;
            cin >> c;
            c--;
            cnt[(i+j)%3][c]++;
        }
    }
    int ans = INF;
    for(int i = 0; i < C; i++) {
        for(int j = 0; j < C; j++) {
            for(int k = 0; k < C; k++) {
                if(i == j || j == k || i == k) {
                    continue;
                }
                int sum = 0;
                for(int l = 0; l < C; l++) {
                    sum += D[l][i]*cnt[0][l];
                    sum += D[l][j]*cnt[1][l];
                    sum += D[l][k]*cnt[2][l];
                }
                ans = min(ans,sum);
            }
        }
    }
    cout << ans << endl;
}


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

int main()
{
	int x,y;
	for( ;; ) {
		cin>>x>>y;
		if( 0==x && 0==y ) { break; }
		
		if( x < y ) {
			cout <<x<<" "<<y<<endl;		
		} else {
			cout <<y<<" "<<x<<endl;
		}
	}
	 
    return 0;
}

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

using namespace std;

unsigned long long  runrun(int L, unsigned long long  i)
{
	unsigned long long size = pow(2, L + 1) - 3;
	if (L == 0)
	{
		return 1;
	}
	else if (i == 0)
	{
		return 0;
	}
	else if (i == size +1)
	{
		return runrun(L-1,size-1) + 1;
	}
	else if (i == 2 * size + 2)
	{
		return 2*runrun(L-1,size-1)+1;
	}
	else if (0 < i && i < size +1)
	{
		return  runrun(L - 1, i - 1);
	}
	else if (size + 1 < i && i < 2 * size + 2)
	{
		return  runrun(L - 1, size -1) + 1 + runrun(L - 1, i - size - 2);
	}
}

int main()
{
	int L;
	cin >> L;
	unsigned long long  X;
	cin >> X;
	cout << runrun(L,X-1);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <sstream>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <string>
#include <queue>
#include <vector>
using namespace std;

int main()
{
	string s;
	getline(cin, s);

	for (int i = 0; i < s.length(); i++) {
		if (s[i] >= 'a' && s[i] <= 'z') {
			cout << (char)(s[i] - 0x20);
		}
		else {
			cout << s[i];
		}
	}

	cout << endl;
}


Measured memory_bytes: 3000
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<long long int> c_v(6, 0);
  long long int N, A, B, C, D, E, cnt = 0;
  cin >> N >> A >> B >> C >> D >> E;
  long long int a = N % min({A, B, C, D, E});
  if (a == 0) {
    cnt = (N / min({A, B, C, D, E})) + 4;
  }
  else {
    cnt = (N / min({A, B, C, D, E})) + 5;
        
  }
  cout << cnt << endl;
  // char S[1000000] = {0};
  // vector<int> s_v, s_01v, s_10v;
  // cin >> S;
  // //cout << strlen(S) << endl;
  // for (int i = 0; i < strlen(S); i++) {
  //   s_v.push_back(S[i] - '0');
  //   switch(i%2) {
  //   case 0:
  //     s_01v.push_back(0);
  //     s_10v.push_back(1);
  //     break;
  //   case 1:
  //     s_01v.push_back(1);
  //     s_10v.push_back(0);
  //     break;
  //   }
  // }
  // long long int cnt_01 = 0, cnt_10 = 0;

  // for (int i = 0; i < strlen(S); i++) {
  //   if (s_01v[i] != s_v[i]) cnt_01++;
  //   if (s_10v[i] != s_v[i]) cnt_10++;
  // }
  // if (cnt_01 > cnt_10) {
  //   cout << cnt_10 << endl;
  // }
  // else {
  //   cout << cnt_01 << endl;
  // }
  // for (int i = 0; i < strlen(S); i++) {
  //   printf("%d ", s_v[i]);
  // }
  return 0;
}


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

int main(){
  int n;
  cin>>n;
  int i;
  int sum=0;
  string str_n=to_string(n);
  rep(i, str_n.length()) {
    sum+=(str_n[i]-'0');
  }
  if (n%sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3692
#include <cstdio>

int main()
{
    int n;
    int a, b, c;

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d %d", &a, &b, &c);

        if (a * a + b * b == c * c
            || b * b + c * c == a * a
            || c * c + a * a == b * b)
        {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }

    return 0;
}

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

int main(){
  string S ; 
  cin >> S ; 
  int N = S.size() ; 
  int cnt = 0 ; 

  for(int i = 0 ; i < N ; i++){
    if(S.at(i) == 'R'){
      cnt++ ; 
    }
    
  }
  
  if(cnt >= 2 && S.at(1) == 'S'){
    cout << 1 << endl ;
    return 0 ; 
  }
  
  cout << cnt << endl ; 
  
}

Measured memory_bytes: 3624
#include<iostream>
using namespace std;
#include<stdio.h>

class dice {
        private:
                int temp_t;
                int temp_e;
                int temp_s;
                int temp_b;
                int temp_w;
                int temp_n;
        public:
                int top;
                int east;
                int south;
                int bottom;
                int west;
                int north;

                dice(int _top, int _east, int _south, int _bottom, int _west, int _north);
                void roll(char dir);
                ~dice();
};

dice::dice(int _top, int _east, int _south, int _bottom, int _west, int _north){
        top = _top;
        east = _east;
        south = _south;
        bottom = _bottom;
        west = _west;
        north = _north;
}

void dice::roll(char dir){
        switch (dir){
                case 'N':
                        temp_n = north;
                        temp_t = top;
                        temp_s = south;
                        temp_b = bottom;
                        north = temp_t;
                        bottom = temp_n;
                        south = temp_b;
                        top = temp_s;
                        break;
                case 'S':
                        temp_n = north;
                        temp_t = top;
                        temp_s = south;
                        temp_b = bottom;
                        north = temp_b;
                        bottom = temp_s;
                        south = temp_t;
                        top = temp_n;
                        break;
                case 'E':
                        temp_e = east;
                        temp_t = top;
                        temp_w = west;
                        temp_b = bottom;
                        east = temp_t;
                        bottom = temp_e;
                        west = temp_b;
                        top = temp_w;
                        break;
                case 'W':
                        temp_e = east;
                        temp_t = top;
                        temp_w = west;
                        temp_b = bottom;
                        east = temp_b;
                        bottom = temp_w;
                        west = temp_t;
                        top = temp_e;
                        break;
                default:
                        cout << "Unknown Roll Command. Quit." << endl;
                        break;
        }
}

dice::~dice(){}

int main(){
        char ch;
        int N, T, E, W, B, S;
        cin >> T >> S >> E >> W >> N >> B;
        scanf("%c", &ch);
        dice diceA(T, E, S, B, W, N);
        for(int i = 0; i < 100; i++) {
                scanf("%c", &ch);
                if(ch == '\n') break;
                diceA.roll(ch);
        }
        cout << diceA.top << endl;
}

Measured memory_bytes: 3252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    string S, T;
    cin >> S >> T;
    ll ans = T.size();
    for (int s = 0; s <= S.size() - T.size(); s++) {
        ll diff = 0;
        for (int i = 0; i < T.size(); i++) {
            if (S[s+i] != T[i]) {
                diff++;
            }
        }
        ans = min(ans, diff);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3592
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val xs = new Array[Long](n)
    val ys = new Array[Long](n)
    val hs = new Array[Long](n)
    for (i <- 0 until n) {
      xs(i) = sc.nextLong
      ys(i) = sc.nextLong
      hs(i) = sc.nextLong
    }

    var result = (0, 0, 0L)
    for (x <- 0 to 100) {
      for (y <- 0 to 100) {
        val ret = check(x, y, n, xs, ys, hs)
        if (ret._1) {
          println(x + " " + y + " " + ret._2)
          return
        }
      }
    }

  }

  private def check(x: Int, y: Int, n: Int, xs: Array[Long], ys: Array[Long], hs: Array[Long]): (Boolean, Long) = {
    var index = 0
    val notZeroIndex: Int = hs.indexWhere(h => h != 0L)
    val H = hs(notZeroIndex) + ((x - xs(notZeroIndex)).abs + (y - ys(notZeroIndex)).abs)
    while (index < n) {
      val tmpHeight = math.max((H - (((x - xs(index)).abs + (y - ys(index)).abs))), 0) // ここの条件読み間違えてたかも。。
      if (tmpHeight != hs(index)) {
        return (false, -1)
      }
      index += 1
    }

    (true, H)
  }

}

Measured memory_bytes: 29364
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

const int MAX_N = 100050;

int N;
long long L, a[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N >> L;

    for (int i = 1; i <= N; i++) {
        std::cin >> a[i];
    }

    for (int i = 1; i <= N - 1; i++) {
        if (a[i] + a[i+1] >= L) {
            std::cout << "Possible" << std::endl;
            for (int j = 1; j <= i - 1; j++) {
                std::cout << j << std::endl;
            }
            for (int j = N - 1; i <= j; j--) {
                std::cout << j << std::endl;
            }
            return 0;
        }
    }

    std::cout << "Impossible" << std::endl;
    return 0;

}

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

const int N = 500010;

int a[N];

int main(){
	int len = 0;
	char ch = getchar();
	while (ch >= '0' && ch <= '9'){
		a[len ++] = ch - '0';
		ch = getchar();
	}
	for (int i = 0; i < len >> 1; ++ i){
		std::swap(a[i], a[len - i - 1]);
	}
	int up = 0;
	for (int i = 0; i <= len; ++ i){
		a[i] *= 9;
		a[i] += up;
		up = a[i] / 10;
		a[i] %= 10;
	}
	if (a[len]){
		++ len;
	}
	int sum = 0, k = 0;
	for (int i = 0; i < len; ++ i){
		sum += a[i];
	}
	while (true){
		++ k;
		a[0] += 9;
		sum += 9;
		int sit = 0;
		while (a[sit] >= 10){
			a[sit] -= 10;
			++ a[sit + 1];
			++ sit;
			sum -= 9;
		}
		if (sum <= 9 * k){
			return printf("%d\n", k), 0;
		}
	}
}

Measured memory_bytes: 2176
# https://atcoder.jp/contests/abc129/tasks/abc129_d

import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

def main():
    H, W = map(int, input().split())
    grid = []
    for _ in range(H):
        w = list(input())
        grid.append(w)

    h_path = [[] for _ in range(H)]
    for h in range(H):
        c = 0
        for w in range(W):
            if grid[h][w] == '#':
                if c > 0:
                    h_path[h].append(c)
                    c = 0
                h_path[h].append(0)
            else:
                c += 1
        if c > 0:
            h_path[h].append(c)
    # print(h_path)

    h_query = [[0] * W for _ in range(H)]
    for h in range(H):
        path = h_path[h]
        index = 0
        for p in path:
            l = p if p > 0 else 1
            while l > 0:
                h_query[h][index] = p
                l -= 1
                index += 1

    # print(h_query)

    w_path = [[] for _ in range(W)]
    for w in range(W):
        c = 0
        for h in range(H):
            if grid[h][w] == '#':
                if c > 0:
                    w_path[w].append(c)
                    c = 0
                w_path[w].append(0)
            else:
                c += 1
        if c > 0:
            w_path[w].append(c)
    # print(w_path)

    w_query = [[0] * W for _ in range(H)]
    for w in range(W):
        path = w_path[w]
        index = 0
        for p in path:
            l = p if p > 0 else 1
            while l > 0:
                w_query[index][w] = p
                l -= 1
                index += 1

    # print(h_query)
    # print(w_query)
    def count(i, j):
        h_val = h_query[i][j]
        w_val = w_query[i][j]
        val = h_val + w_val
        if h_val > 0 and w_val > 0:
            val -= 1
        return val

    ans = 0
    for h in range(H):
        for w in range(W):
            if grid[h][w] != '#':
                # print('h = {}, w = {}, count = {}'.format(h, w, count(h, w)))
                ans = max(ans, count(h, w))
                pass
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 309000
using System;

namespace A_Blackjack
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] StrInput = Console.ReadLine().Split();
            if ((int.Parse(StrInput[0]) + int.Parse(StrInput[1]) + int.Parse(StrInput[2])) >= 22){
                Console.WriteLine("bust");
            } else {
                Console.WriteLine("win");
            }
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

i_i c[1000];

signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int2(n, m);
    rep(i, m)scanf("%d %d", &c[i].X, &c[i].Y);
    sort(c, c + m);
    //pri2(c[0].X, c[0].Y);
    int res = 0;
    rep1(i, m){
      res += max(0, n - c[i].X);
    }
    pri(res);

/*/

//*/ break;
  }
  return 0;
}

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


int Common(int x, int y) {
	int r = 1;

	if (x < y) swap(x, y);

	while (r != 0) {
		r = x % y;
		x = y;
		y = r;
	}

	return x;
}

int main(void) {
	int x, y, ans;

	cin >> x >> y;

	cout << Common(x, y) << endl;


	return 0;
}

Measured memory_bytes: 3072
import sys

N, K = map(int, input().split())
S = input()

n_sum = []

ct = 1
for i in range(N-1):
    if S[i+1] == S[i]:
        ct += 1
    else:
        n_sum.append(ct)
        ct += 1

n_sum.append(ct)

if len(n_sum) == 1:
    print(ct)
    sys.exit()

else:
    if S[-1] == '0':
        n_sum.append(ct)
    if S[0] == '0':
        n_sum.insert(0, 0)

if K < len(n_sum)//2:
    Max = -1
    i = 0
    while i+2*K < len(n_sum):
        if i == 0:
            tmp = n_sum[i+2*K]
        else:
            tmp = n_sum[i+2*K] - n_sum[i-1]
        i += 2
        Max = max(Max, tmp)
else:
    Max = ct

print(Max)


Measured memory_bytes: 7164
//Apparat : drobucs, aleonov, vit_72
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <iomanip>
#include <algorithm>
#include <string>
#include <queue>
#include <numeric>

//#pragma warning(disable : 4996)
//#pragma GCC optimize("O3")

using namespace std;

#define nptr nullptr
#define all(x) (x).begin(), (x).end()
#define drobucs ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define ff first
#define ss second
#define pb push_back
#define sz(x) (int)(x).size()

typedef  long long ll;

const int maxn = (int)2e5 + 13;
const ll INFL = 9223372036854775807;
const ll INF = 2147483647;
const ll MOD = (int)1e9 + 7, MOD2 = 998244353;//1e9 + 21, 1e9 + 33, 1e9 + 87, 1e9 + 93
const ll base = 101, base2 = 37;

int a[maxn];
int main() {
	drobucs;
	
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i)cin >> a[i];
	int xr = 0;
	for (int i = 1; i <= n; ++i) xr ^= a[i];
	for (int i = 1; i <= n; ++i) cout << (xr ^ a[i]) << " ";
	return 0;
}

Measured memory_bytes: 4404
S=input()
temp=0

for i in range(len(S)):
    if S[i]!="0" and i%2==0:
        temp+=1
    if S[i]!="1" and i%2==1:
        temp+=1
ans=temp

temp=0
for i in range(len(S)):
    if S[i]!="0" and i%2==1:
        temp+=1
    if S[i]!="1" and i%2==0:
        temp+=1
if temp<ans:
    ans=temp

print(ans)


Measured memory_bytes: 9184
#include<iostream>

using namespace std;
int main(){
    double xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2;
    while(cin>>xa1>>ya1>>xa2>>ya2>>xb1>>yb1>>xb2>>yb2){
        if(xa1>xb2||xa2<xb1||ya1>yb2||ya2<yb1)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
}

Measured memory_bytes: 1220