akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

const int maxn = 3005;
int d[maxn][maxn];
int pr[maxn];
int l[maxn], r[maxn], to[maxn];

const int mod = 1e9 + 7;

void udd(int &a, int b) {
    a += b;
    if (a >= mod)
        a -= mod;
}

int mul(ll a, ll b) {
    return a * b % mod;
}

int main() {
    #ifdef LOCAL
    assert(freopen("f.in", "r", stdin));
    #else
    #endif
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    forn (i, n)
        pr[i + 1] = pr[i] + (s[i] == '1');
    forn (i, m) {
        cin >> l[i] >> r[i];
        --l[i];
    }
    int last = 0, ptr = 0;
    forn (i, n) {
        last = max(last, i + 1);
        while (ptr < m && l[ptr] == i) {
            last = max(last, r[ptr]);
            ++ptr;
        }
        to[i] = last;
    }
    d[0][0] = 1;
    forn (i, n) {
        int b = to[i];
        forn (j, i + 1) {
            if (d[i][j] == 0)
                continue;

            if (j < pr[b]) {
                udd(d[i + 1][j + 1], d[i][j]);
                //cerr << "go 1\n";
            }
            if ((i - j) < (b - pr[b])) {
                udd(d[i + 1][j], d[i][j]);
                //cerr << "go 0\n";
            }
        }
    }
    cout << d[n][pr[n]] << '\n';
}


Measured memory_bytes: 12544
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int X = sc.nextInt();
        int T = sc.nextInt();
        int count = N/X;
        int plus = N%X == 0 ? 0 : 1;
        System.out.println(T*(count+plus));
    }
}

Measured memory_bytes: 35712
import java.util.Scanner;

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

        if(9 < Math.max(a, b)) {
            System.out.println(-1);
        } else {
            System.out.println(a * b);
        }
    }
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int a, b;
  cin >> a >> b;
  int count = 0, now = 1;
  while (now < b) {
    now += a - 1;
    count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
  string s; bool flag = true;
  cin >> s; int cnt = 0;
  if (s[0] != 'A')flag = false;
  if ('A' <= s[1] && s[1] <= 'Z')flag = false;
  if ('A' <= s[s.length() - 1] && s[s.length() - 1] <= 'Z')flag = false;
  if (flag) {
    for (int i = 2; i < s.length() - 1; i++) {
      if (s[i] == 'C')cnt++;
      if ('A' <= s[i] && s[i] <= 'Z' && s[i] != 'C')flag = false;
    }
  }
  if (flag && cnt == 1)cout << "AC" << endl;
  else cout << "WA" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 2e5+5;
int a[maxn];


int main()
{
	int n,m;
	scanf("%d%d",&m,&n);
	for (int  i= 1; i<=n; i ++ )
	{
		scanf("%d",&a[i]);
	}
	sort(a + 1, a + 1 + n);
	int ans = a[n] - a[1];
	for (int i = 2; i <= n; i ++ )
	{
		ans = min(ans,a[i - 1] + m - a[i]);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 896
/* Karen {{{
  ___  ____
 |_  ||_  _|
   | |_/ /    ,--.   _ .--.  .---.  _ .--.
   |  __'.   `'_\ : [ `/'`\]/ /__\\[ `.-. |
  _| |  \ \_ // | |, | |    | \__., | | | |
 |____||____|\'-;__/[___]    '.__.'[___||__]
}}} */
// include {{{
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <math.h>
#include <string>
#include <vector>
#include <complex>
#include <iostream>
#include <algorithm>

using namespace std;

// }}}
/* cpp template {{{*/


#define endl '\n'

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)

typedef double D;      // 座標値の型。doubleかlong doubleを想定
typedef long long ll;
typedef long double lb;
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<string, int> psi;

inline bool inside(int y, int x, int H, int W){return (y >= 0 && x >= 0 && y < H && x < W);}
inline int in() {int x; std::cin >> x; return x;}

template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T>
void print(T x) {
  std::cout << x << '\n';
}

/* 定数 */
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 9;
const D EPS  = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};


/* }}} */

bool b[100000] = {true};
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N = in(), M = in();
  int x, y;
  int No[100000];
  int cnt = 0;
  for (int i = 0; i < N; i++){
    No[i] = 1;
  }

  for (int i = 0; i < M; i++){
    x = in();
    y = in();

    x--;
    y--;
    if (b[x]){
      b[y] = true;
      No[x]--;
      No[y]++;
      if (No[x] == 0){
        b[x] = false;
      }
    }
    else {
      No[x]--;
      No[y]++;
    }
  }
  for (int i = 0; i < N; i++){
    if (b[i]) cnt++;
    //cout << b[i] << endl;
  }
  cout << cnt << endl;


  return (0);
}



Measured memory_bytes: 768
Scanf.scanf "%d %d %d" (fun n a b ->
    let digit k =
        let rec loop i acc =
            if i = 0 then acc else loop (i / 10) (acc + (i mod 10))
        in
        loop k 0
    in
    let rec loop i acc =
        if i > n then acc else
            let d = digit i in
            loop (i + 1) (if d >= a && d <= b then acc + i else acc)
    in
    loop 1 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 3844
n = int(input())
s = list(input() for i in range(n))
m = int(input())
t = list(input() for i in range(m))
a = s + t
a = list(set(a))
p = 0

for i in range(len(a)):
    plus = s.count(a[i])
    minus = t.count(a[i])
    if plus - minus > p:
        p = plus - minus

print(p)

Measured memory_bytes: 9192
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef pair<long long,long long> pll;
typedef long long ll;
const int inf   = 1<<30-1;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  int n,m;
  cin>>n>>m;
  string s[n];
  rep(i,n){
    cin>>s[i];
    if(i%2==0)s[i][0]='#';
    else s[i][m-1]='#';
    }
  string t;
  rep(i,m-1)t+='#';
  rep(i,n){
    if(i%2==0)cout<<s[i]<<endl;
    else cout<<t<<"."<<endl;
    }
  cout<<endl;
  
   rep(i,n){
    if(i%2==1)cout<<s[i]<<endl;
    else cout<<"."<<t<<endl;
    }
  return 0;
  }

  

Measured memory_bytes: 1024
#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define init(a, b) memset(a, b, sizeof(a))
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef unordered_map<int,int> uoii;
typedef unordered_map<string,int> uosi;

#define MOD = 1e9+7;

/******* Debugging Class Template *******/
#define DEBUG

#ifdef DEBUG

    #define de(args...)     (Debugger()) , args

    class Debugger
    {
        public:
        Debugger(const std::string& _separator = " - ") :
        first(true), separator(_separator){}

        template<typename ObjectType> Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std:cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std:cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif





int32_t main()
{
   
    IOS
    
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<=n-3;i++){
        if(s.substr(i,3)=="ABC") ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
// https://beta.atcoder.jp/contests/abc102/tasks/abc102_a

#include<iostream>
using namespace std;
int main()
{
	int N;
	cin >> N;

	long long A = 1LL;
	int count = 1;
	while(!(A%2==0 && A%N==0)){
		A = (long long)(N * count);
		count++;
	}
	cout << A << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int N, M;
  int i=0;
  int y=0;
  int x=0;
  int a, b, c;
  
  scanf("%d %d\n", &N, &M);
  int L[M], R[M];
  for(i=0; i<M; i++){
    scanf("%d %d\n",&x, &y);
    L[i]=x;
    R[i]=y;
  }
  b=0;
  c=N;
  
  for(i=0; i<M; i++){
    if(b<=L[i]){
      b=L[i];
    }
    if(R[i]<=c){
      c=R[i];
    }
  }
  
  a=(c-b+1);
  
  if(c<b){
    printf("0\n");
  }
  else{
    printf("%d\n",a);
  }
  
  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>
#include <set>
#include <queue>

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;

int main() {
	int n, m, x, y;
	cin >> n >> m;

	vector<vector<int>> tos(n);
	vector<set<int>> froms(n);

	for (int i = 0; i < m; i++) {
		cin >> x >> y;
		x--;
		y--;

		tos[x].emplace_back(y);
		froms[y].insert(x);
	}

	vector<int> longests(n, 0);
	queue<int> que;
	for (int i = 0; i < n; i++) {
		if (froms[i].size() == 0) {
			que.push(i);
		}
	}

	while (!que.empty()) {
		auto pos = que.front();
		que.pop();

		if (longests[pos] == 0) {
			longests[pos]++;
		}

		for (auto to: tos[pos]) {
			longests[to] = max(longests[to], longests[pos] + 1);

			froms[to].erase(pos);
			if (froms[to].empty()) {
				que.push(to);
			}
		}
	}

	int ans = *max_element(longests.begin(), longests.end());
	ans--;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 15488
import java.util.Scanner;

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

    int MAX_V = 100 * 1000;
    int N = scanner.nextInt();
    int W = scanner.nextInt();
    int[] w = new int[N + 1];
    int[] v = new int[N + 1];
    for (int i = 1; i <= N; i++) {
      w[i] = scanner.nextInt();
      v[i] = scanner.nextInt();
    }

    long INF = 1_000_000_000_000L;
    long[][] dp = new long[N + 1][MAX_V + 1];
    for (int i = 1; i <= MAX_V; i++) dp[0][i] = INF;
    for (int i = 1; i <= N; i++) {
      for (int j = 1; j <= MAX_V; j++) {
        dp[i][j] = dp[i - 1][j];
        if (j >= v[i]) dp[i][j] = Math.min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
      }
    }
    for (int i = MAX_V; i >= 0; i--) {
      if (dp[N][i] <= W) {
        System.out.println(i);
        return;
      }
    }
  }
}


Measured memory_bytes: 128212
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;

int main(){
	string s;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5]&&s[0]!=s[1]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e10;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};


const ll MD=2019;

long long ruijou(ll n, ll k){
    if(k==0) return 1;
    ll x=k/2;
    long long t=ruijou(n,x);
    t=(t*t)%MD;
    if(k%2==1) return (n*t)%MD;
    else return t%MD;
}

int main(){
    string S; cin>>S;
    ll N=S.size();
    vec d;
    for(int i=N-1; i>=0; i--) d.pb(S[i]-'0');
    vec SUM(N+1,0);
    rep(i,N) SUM[i+1]=(SUM[i]+d[i]*ruijou(10,i))%MD;
    //rep(i,N+1) cout<<SUM[i]<<endl;
    vec count(MD,0);
    ll ans=0;
    rep(i,N+1) count[SUM[i]]++;
    rep(i,MD) ans+=(count[i]*(count[i]-1)/2);
    cout<<ans<<endl;
}

Measured memory_bytes: 6604
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>

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

    int ar[201]={0};
    for(int i=1;i<=200;++i)
    {
        for(int j=1;j*j<=i;++j)
        {
            if(i%j==0)
            {
                if(j*j==i){++ar[i];}
                else{ar[i]+=2;}
            }
        }
    }
    //for(int i=0;i<201;++i){cout<<ar[i]<<" ";}
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;++i)
    {
        if(i%2==1&&ar[i]==8){++ans;}
    }
    cout<<ans<<endl;

return(0);
}

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


int pt[100];
int main(){
	int x;
	cin >> x;
	vector<int> a[3];
	int N;
	for(int k = 0 ; k < 2 ; k++){
		cin >> N;
		for(int i = 0 ; i < N ; i++){
			string s; cin >> s;
			int d = count(s.begin(),s.end(),'D');
			int p;
			cin >> p;
			if( d == s.size() )
				a[d].push_back(p);
		}
	}
	int ans = 0;
	for(int i = 0 ; i < 3 ; i++) sort(a[i].rbegin(),a[i].rend());
	for(int i = 0 ; i < a[1].size()+1 ; i++)
		for(int j = 0 ; j < 1+a[2].size() ; j++)
			if( i + 2 * j <= x ){
				int r = 0;
				for(int k = 0 ; k < i ; k++)
					r += a[1][k];
				for(int k = 0 ; k < j ; k++)
					r += a[2][k];
				ans = max(ans,r);
			}
	cout << ans << endl;
}

Measured memory_bytes: 1228
N,X=map(int,input().split())
C=list(map(int,input().split()))

def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

A=[0]*N
for i in range(N):
    A[i]=abs(C[i]-X)

ans=A[0]
for i in range(1,N):
    ans=gcd(ans,A[i])

print(ans)

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

int main(){
  string s;
  cin >> s;
  vector<ll> num(s.size()+1,0);
  for(ll i=0;i<s.size();++i){
    if( s.at(i) == '<' ) num.at(i+1) = max(num.at(i+1),num.at(i)+1);
  }
  for(ll i=s.size()-1;i>=0;--i){
    if( s.at(i) == '>' ) num.at(i) = max(num.at(i),num.at(i+1)+1);
  }
  ll ans = 0;
  rep(i,num.size()) ans += num.at(i);
  
 /* rep(i,s.size()){
    cout << num.at(i) << " " << s.at(i) << " ";
  }
  cout << num.back() << endl;*/
  
  cout << ans << endl;
    
  return 0;
}

Measured memory_bytes: 4740
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define cst first
#define dur second
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e5 + 5, M = 2 * N + 5;

int main(){
    int n;
    scanf("%d", &n);
    int cnt = 0;
    for(int i = 1 ; i <= n ; ++i){
        int x;
        scanf("%d", &x);
        if(x != i)++cnt;
    }
    if(cnt == 0 || cnt == 2)
        puts("YES");
    else puts("NO");
}


Measured memory_bytes: 256
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

int main(){
    ll N;
    cin>>N;
    vector<int> a(N+1);
    for(ll i=1;i<=N;i++){
        cin>>a[i];
    }
    map<ll,int> mp;
    for(ll i=N;i>=1;i--){
        ll _sum=0;
        for(ll j=2;i*j<=N;j++){
            _sum+=mp[i*j];
        }
        if(_sum%2==a[i])continue;
        mp[i]=1;
    }
    vector<ll> b;
    for(auto p:mp){
        if(p.second==1)b.push_back(p.first);
    }
    cout<<b.size()<<endl;
    if(b.size()==0)return 0;
    for(ll i=0;i<b.size();i++){
        cout<<b[i]<<" ";
    }
    cout<<endl;

}

Measured memory_bytes: 15092
N = int(raw_input())
A1 = map(int, raw_input().split())
A2 = map(int, raw_input().split())

max_candies = 0

#print A1[0:0]

for p in range(N):
    candies = sum(A1[0:(p+1)]) +  sum(A2[p:N])
#    print p,  A1[0:(p+1)], A2[p:N], candies
    if  candies > max_candies:
        max_candies = candies
    else:
        pass

print max_candies


Measured memory_bytes: 2696
import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def search(topx, topy, botx, boty, grid):
    ret = grid[boty][botx]
    if topx > 0: ret -= grid[boty][topx - 1]
    if topy > 0: ret -= grid[topy - 1][botx]
    if topx > 0 and topy > 0: ret += grid[topy - 1][topx - 1]
    return ret

def Main():
    H, W, K = read_ints()
    chocolate = [list(read_str()) for _ in range(H)]
    
    grid = [[0] * W for _ in range(H)]
    for h in range(H):
        for w in range(W):
            if chocolate[h][w] == '1': grid[h][w] += 1
            if w > 0: grid[h][w] += grid[h][w - 1]
            if h > 0: grid[h][w] += grid[h - 1][w]
            if h > 0 and w > 0: grid[h][w] -= grid[h - 1][w - 1]

    ans = INF
    for bit in range(1 << ~-H):
        cnt = 0
        cut = []
        for h in range(~-H):
            if bit >> h & 1:
                cnt += 1
                cut.append(h)
        cut.append(~-H)

        white = [0] * len(cut)
        topx = 0
        flag = False
        for w in range(~-W):
            topy = 0
            for i in range(len(cut)):
                if search(topx, topy, w, cut[i], grid) > K:
                    flag = True
                    break
                white[i] = search(topx, topy, w+1, cut[i], grid)
                topy = cut[i] + 1
            if flag: break
            for x in white:
                if x <= K:
                    continue
                topx = w + 1
                cnt += 1
                break
        if not flag:
            ans = min(ans, cnt)
    print(ans)
    

if __name__ == '__main__':
    Main()

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

int main(){

int a,b,c,count;

cin >> a;

for(int i=0; i<a; i++){

    cin >> b >> c;
 
    if(b>c && b%c !=0) cout << b%c << endl;
 
    else if(b > c && b%c == 0) cout << c << endl;

    else cout << b << endl;
}

return 0;
}

Measured memory_bytes: 1160
n, d, a = [int(i) for i in input().split()]
xh = [[int(i) for i in input().split()] for _ in range(n)]
xh.sort()
da = [0] * n
r = [0] * n
ru=0

ans = 0
j=0
for i in range(n):
    da[i]+=ru
    if xh[i][1] > da[i]:
        up = (xh[i][1] - da[i]) // a
        if (xh[i][1] - da[i]) % a != 0:
            up += 1
        ans += up
        up *= a
        da[i] += up
        ru+=up
        
        while j!=n-1 and xh[j+1][0] <= xh[i][0] + 2 * d:
            j += 1
        r[j]+=up
    
    ru-=r[i]
print(ans)



Measured memory_bytes: 84184
#include <bits/stdc++.h>
#define for0(i,b) for(int i=0 ; i< b ;i++)
#define for1(i,b) for(int i=1 ; i<=b ;i++)
#define reps(i,a,b) for(int i=a ; i< b.length() ;i++)
typedef long long ll;
#define MOD 1000000007

using namespace std;




int main()
{
  ll i,j,k,sum=0,n,res;
  ll col[3]={0,0,0} ;
  string str ;
  cin >> n >> str ;
  for(ll i=0 ; i<n ; i++){
    if(str[i]=='R')col[0]++ ;
    else if (str[i]=='G') col [1]++;
    else col[2]++;
  }
  // cout <<col[0]<< " "<<col[1]<<" "<<col[2]<<endl;
res = col[0] * col[1] * col[2] ;
// cout << res<<endl   ;
for(ll i=0 ; i<n ; i++){
  for(ll j=i+1 ; j<n ;j++){
    k = j + (j-i) ;
    if(k>=n)continue ;
    if(str[i]!=str[j] && str[i]!=str[k] && str[j]!=str[k]) res-- ;

  }
}
cout << res ;


  return 0 ;
}






//    for0(k,n){
  //      for0(j,k){
    //        for0(i,j){
      //          if(str[i]!=str[j] && str[i]!=str[k] && str[j]!=str[k] && (j-i)!=(k-j)){
        //        sum+=1;
        //           }
        //        }
        //      }
        //    }
        //
        // cout << sum ;


Measured memory_bytes: 3624
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll x, ans = 0, sum = 0;
    for (ll i = 0; i < n; i++) {
        cin >> x;
        a[i] = x - i - 1;
    }
    sort(a.begin(), a.end());
    ll mid = (n % 2 ? a[n / 2] : a[n / 2 - 1]);
    for (ll i = 0; i < n; i++) {
        ans += abs(a[i] - mid);
    }
    cout << ans << endl;
}


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

template <typename Abel> struct BIT {
    const Abel UNITY_SUM = 0;
    vector<Abel> dat;
    BIT(int n) : dat(n + 1, UNITY_SUM) { }  // [1, n]
    inline void add(int i, Abel x) {
        while (i < dat.size()) { dat[i] += x; i += i & -i; }
    }
    inline Abel sum(int i) {    // [1, i]
        Abel res = UNITY_SUM;
        while (i > 0) { res += dat[i]; i -= i & -i; }
        return res;
    }
    inline Abel sum(int a, int b) { return sum(b - 1) - sum(a - 1); }   // [a, b)
    /* debug */
    Abel operator[](int i) { return sum(i, i + 1); }
    void debug() {
        for (int i = 1; i < dat.size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

template<typename T> long long inversion_number(const vector<T> &a) {
    int n = a.size();
    vector<T> b = a;
    sort(begin(b), end(b)); b.erase(unique(begin(b), end(b)), end(b));
    long long res = 0;
    BIT<int> bit(n);
    for (T ai: a) {
        int order = lower_bound(begin(b), end(b), ai) - begin(b) + 1;
        res += bit.sum(1, order + 1); bit.add(order, 1);
    }
    return res;
}

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for (auto &ai: a) cin >> ai;
    vector<long long> acc(n + 1);
    for (int i = 0; i < n; i++) acc[i + 1] = acc[i] + a[i] - k;
    cout << inversion_number(acc) << endl;
    return 0;
}

Measured memory_bytes: 4992
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct node{
   int r;
  int l;
  int p;
  int key;
};
typedef struct node  Node;
#define NIL NULL
Node root[250];

int main(){
  int n,i,x;
  Node t;
  char com[20];;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&root[i].key);
    

  }
  
  for(i=1;i<=n;i++){
    if(i!=1){
      root[i].p=i/2;
    }
    
    root[i].l=2*i;
    root[i].r=2*i+1;
  }
  for(i=1;i<=n;i++){

    printf("node %d: key = %d, ",i,root[i].key);
    if(i!=1)printf("parent key = %d, ",root[root[i].p].key);
    if(root[root[i].l].key!=NIL) printf("left key = %d, ",root[root[i].l].key);
    if(root[root[i].r].key!=NIL) printf("right key = %d, ",root[root[i].r].key);
    printf("\n");
  }
  return 0;
}




Measured memory_bytes: 2148
#include "stdio.h"

int main() {

    int n,m,i=0,c=0;

    scanf("%d",&n);

    while(n){

    n--;

    if(i==0){

    scanf("%d",&i);

    c++;continue;

    }

    scanf("%d",&m);

    if(m<=i){

    i=m;

    c++;

    }

    }

    printf("%d",c);

    return 0;

}

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

	public static void main(String[] args) {
		
		// TODO Auto-generated method stub
		Scanner reader=new Scanner(System.in);
		int A=reader.nextInt();
		int B=reader.nextInt();
		int C=reader.nextInt();
		if(A==B && C!=A) {
			System.out.print(C);
		}
		else if(A==C && B!=A) {
			System.out.print(B);
		}
		else {
			System.out.print(A);
		}
	}
	
	

}


Measured memory_bytes: 21844
#83
N, A, B  = list(map(int, input().split()))
total = 0

#各桁の数字合計計算
def add_keta(n):
    ans = 0
    while n > 0 :
        ans += n % 10
        n = n // 10
    return ans


#各桁の数字合計計算
for i in range(1, N+1):
    sum = add_keta(i)
    if A <= sum and sum <= B:
        total += i

print(total)

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>

#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef long long ll;

int main()
{

    int n;
    cin >> n;
    bool y = false;
    for (int i = 1; i < 10; ++i)
    {
        for (int j = 1; j < 10; ++j)
        {
            if (j * i == n)
            {
                y = true;
                break;
            }
        }
    }

    (y) ? cout << "Yes" : cout << "No";

    return 0;
}

Measured memory_bytes: 256
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
                
#define int long long
#define ll long long 
bool FLAG = 0;
#define debug(x) if (FLAG) { 	cerr << #x << " = " << x << endl;}
#define debug_vec(x) if (FLAG) {cerr << #x << " = {"; for (auto to x) cout << to << ", "; cout << "}" << endl}
#define F first
#define S second                               
#define sqr(x) ((x) * (x))
#define make make_pair
#define pb push_back
#define sz(x) (int)(x.size()) 
#define all(x) x.begin (), x.end ()

using namespace std;
                        
typedef unsigned long long ull;
typedef long double ld;

const int MOD = 998244353, N = (int)1e6+ 222;
const int INF = (int)1e18;
const ld eps = (ld)1e-6;

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

int n, a[N], b[N], k;

inline void solve () {
	cin >> n;
	n--;
	string s = "";
	while (n != -1) {
		s += (n % 26) + 'a';
		n /= 26;
		n--;
	}
	reverse(all(s));
	cout << s;
}	
	    

signed main () {
	#ifdef Maga
		freopen("input", "r", stdin);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=1<<17,mod=1e9+7;
int Pow(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=(LL)x*x%mod)
		if (y&1)
			ans=(LL)ans*x%mod;
	return ans;
}
void Add(int &x,int y){
	if ((x+=y)>=mod)
		x-=mod;
}
void Del(int &x,int y){
	if ((x-=y)<0)
		x+=mod;
}
int Add(int x){
	return x>=mod?x-mod:x;
}
int Del(int x){
	return x<0?x+mod:x;
}
int n,m;
int a[N];
int Fac[N],Inv[N];
void prework(){
	int n=N-1;
	Fac[0]=1;
	For(i,1,n)
		Fac[i]=(LL)Fac[i-1]*i%mod;
	Inv[n]=Pow(Fac[n],mod-2);
	Fod(i,n,1)
		Inv[i-1]=(LL)Inv[i]*i%mod;
}
int C(int n,int m){
	if (m<0||m>n)
		return 0;
	return (LL)Fac[n]*Inv[m]%mod*Inv[n-m]%mod;
}
int dp[20][N];
int main(){
	prework();
	n=read(),m=read();
	For(i,1,m)
		a[i]=read();
	dp[m+1][0]=1;
	Fod(i,m+1,2)
		For(j,0,(1<<n)-1){
			int v=dp[i][j];
			if (!v)
				continue;
			Add(dp[i-1][j],v);
			For(k,0,n-1)
				if (~j>>k&1){
					Del(dp[i-1][j|1<<k],
						(LL)v*C((1<<n)-a[i-1]-j,(1<<k)-1)%mod
						*Fac[1<<k]%mod);
//					printf("aft(dp[%d][%d],dp[%d][%d] = %d\n",i,j,i-1,j|1<<k,dp[i-1][j|1<<k]);
				}
		}
//	Fod(i,m+1,1){
//		printf("i = %d, ",i);
//		outarr(dp[i],0,(1<<n)-1);
//	}
	int ans=0;
	For(i,0,(1<<n)-1)
		Add(ans,(LL)dp[1][i]*Fac[(1<<n)-i-1]%mod);
	ans=(LL)ans*(1<<n)%mod;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10240
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] a = new int[3];
        for(int i=0;i<3;i++){
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        System.out.println(a[0]+" "+a[1]+" "+a[2]);
        sc.close();
    }
}


Measured memory_bytes: 26308
using System;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;

static class WhatDayIsToday
{
    static void Main()
    {
        var ci = new CultureInfo( "en-US" );
        Console.In.ReadToEnd()
            .Split( 
                new[] { '\r', '\n' },
                StringSplitOptions.RemoveEmptyEntries )
            .TakeWhile( x => x != "0 0" )
            .Select( x => Array.ConvertAll( x.Split( ' ' ), int.Parse ) )
            .Select( x => new DateTime( 2004, x[0], x[1] ) )
            .Select( x => x.ToString( "dddd", ci ) )
            .ToList()
            .ForEach( Console.WriteLine );
    }
}

Measured memory_bytes: 6284
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
inline ll read(){
	ll f=1,res=0;char c=getchar();
	while(c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){res=res*10+c-'0',c=getchar();}
	return f*res;
}
const ll mod=1e9+7;
const int maxn=2e5+5;
const int maxm=8005;
ll fac[maxm];        //阶乘
ll inv[maxm];        //逆元 
ll a[maxn],b[maxn],n,ans;
ll f[maxm/2][maxm/2],base=maxm/4;
const ll inv2=500000004;
ll quickMod(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
void getFac(){
    fac[0]=inv[0]=1;
    for(int i=1;i<=maxm;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=quickMod(fac[i],mod-2);        //表示i的阶乘的逆元 
    }
}
ll getC(ll n,ll m){
    return fac[n]*inv[n-m]%mod*inv[m]%mod;//C(n,m) = n!/((n-m)!*m!) % (1e9+7)
}
int main(){
//	freopen("math.in","r",stdin);
//	freopen("math.out","w",stdout);
	getFac();
	n=read();
	for(int i=1;i<=n;i++) a[i]=read(),b[i]=read(),f[base-a[i]][base-b[i]]++;
	for(int i=1;i<=maxm/2-1;i++){
		for(int j=1;j<=maxm/2-1;j++){
        	f[i][j]=(f[i][j]+(f[i-1][j]+f[i][j-1])%mod)%mod;
        //	printf("%d %d %lld\n",i,j,f[i][j]);
		}//cout<<"orz"<<" "<<i;
	}
	ans=0;
	for(int i=1;i<=n;i++){
		ans=(ans+f[base+a[i]][base+b[i]])%mod;
		ans=(ans-getC(2*a[i]+2*b[i],2*a[i]))%mod;
	}
	ans=(ans+mod)%mod;
	ans=ans*inv2%mod;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128640
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	int t = 24 * 3600 + 59 * 60 + 59;

	while (true) {
		int n;
		cin >> n;

		if (!n) break;
		vi time(t + 1);

		rep(i, n) {
			int sh, sm, ss, eh, em, es;

			scanf("%d:%d:%d", &sh, &sm, &ss);
			scanf("%d:%d:%d", &eh, &em, &es);

			time[sh * 3600 + sm * 60 + ss]++;
			time[eh * 3600 + em * 60 + es]--;
		}
		int ans = 0;
		rep(i, t) {
			time[i + 1] += time[i];
			chmax(ans, time[i + 1]);
		}
		cout << ans << endl;

	}
}


Measured memory_bytes: 3480
#include <iostream>
#include<stdio.h>
#include<stack>
#include<queue>

#define MAX 100
#define WHITE 1
#define GRAY 2
#define BLACK 3

using namespace std;

int color[MAX], d[MAX], f[MAX];
int n, A[MAX][MAX];
int nt[MAX];
int dis[MAX]; //?????¶???????????????????????????
int tt = 0;

void dfs_visit_1(int u) { //???????????°
    color[u] = GRAY;
    d[u] = ++tt;
    for(int v = 0; v < n; v++) {
        if(A[u][v] == 0) continue;
        if(color[v] == WHITE) dfs_visit_1(v);
    }
    color[u] = BLACK;
    f[u] = ++tt;
}

int next(int u) {
    for(int v = nt[u]; v < n; v++) {
        nt[u] = v+1;
        if(A[u][v] == 1) return v;
    }
    return -1;
}

void dfs_visit_2(int u) { //????????°
    for(int i = 0; i < n; i++) nt[i] = 0;
    color[u] = GRAY;
    d[u] = ++tt;
    stack<int> S;
    S.push(u);

    while(!S.empty()) {
        int u = S.top();
        int v = next(u);
        if(v != -1) {
            if(color[v] == WHITE) {
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }else {
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs() { // ?????????????????°
    for(int i = 0; i < n; i++) {
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;
    for(int i = 0; i < n; i++) {
        if(color[i] == WHITE) dfs_visit_2(i);
    }
    for(int i = 0; i < n; i++) {
        printf("%d %d %d\n", i+1, d[i], f[i]);
    }
}

void bfs(int u) {
    dis[0] = 0;
    for(int i = 1; i < n; i++) dis[i] = -1;
    queue<int> Q;
    Q.push(u);
    while(!Q.empty()) {
      int u = Q.front();
      Q.pop();
        for(int v = 0; v < n; v++) {
            if(A[u][v] == 1 && dis[v] == -1) {
                Q.push(v);
                dis[v] = dis[u] + 1;
            }
        }
    }

    for(int i = 0; i < n; i++) {
        printf("%d %d\n", i+1, dis[i]);
    }
}

int main()
{
    int u, k, v;
    scanf("%d",&n);

    for(int i = 0; i < n; i++) {
        scanf("%d%d", &u, &k);
        for(int j = 0; j < k; j++) {
            scanf("%d", &v);
            A[u-1][v-1] = 1;
        }
    }

    /*
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            printf("%d", A[i][j]);
            if(j != n-1) printf(" ");
        }
        printf("\n");
    }
    */
    //dfs();
    bfs(0);

    return 0;
}

Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll n;
	cin>>n;
	ll arr[n];
	for(ll i=0;i<n;i++)
        cin>>arr[i];
        ll cnt=0;
    for(ll i=0;i<n;i++)
    {
        for(ll j=i+1;j<n;j++)
        {
            for(ll k=j+1;k<n;k++)
            {

                ll a = arr[i];
                ll b = arr[j];
                ll c = arr[k];
                if(a!=b&&b!=c&&a!=c)
                {
                        if(a+b>c&&b+c>a&&a+c>b)
                            cnt++;
                }

            }
        }
    }
    cout<<cnt<<endl;
}



Measured memory_bytes: 3612
#include <iostream>

using namespace std;

int main(){
	int coin[6];
	int a, b, total;

	a = 5;
	b = 10;
	total = 0;

	for (int i = 0; i < 6; i++){
		cin >> coin[i];
	}

	for (int i = 1; i <= 6; i++){
		if (i % 2 != 0){
			coin[i] *= a;
			a *= 10;
		}
		else {
			coin[i] *= b;
			b *= 10;
		}
	}

	for (int j = 0; j < 6; j++){
		total += coin[j];
	}

	if (total >= 1000){
		cout << "1" << endl;
	}
	else {
		cout << "0" << endl;
	}

}

Measured memory_bytes: 3104
#include <stdio.h>

int main(int argc, char**argv) {
	int C, D, E, A, B, out = 0, f;
	scanf("%d%d%d%d%d", &A, &B, &C, &D, &E);
	if (A < 0) {
		out = (0-A)*C + D + (B-0)*E;
	} else {
		out = (B-A)*E;
	}
	printf("%d\n", out);
	return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    map<ll,ll> mp;
    for(i = 0;i <= 12;++i){
        mp[i] = 0;
    }
    ++mp[0];
    for(i = 0;i < n;++i){
        ll d;
        cin >> d;
        ++mp[d];
    }
    ll ans = 0;
    for(ll bit = 0;bit < (1 << 13);++bit){
        set<ll> se;
        for(i = 0;i < 13;++i){
            if(bit & (1 << i)) se.insert(i);
        }
        vector<ll> tmp;
        for(i = 0;i < 13;++i){
            if(mp[i] > 2){
                cout << 0 << endl;
                return 0;
            }else if(mp[i] == 2){
                tmp.push_back(i);
                tmp.push_back((24-i)%24);
            }else if(mp[i] == 1){
                if(se.count(i)){
                    tmp.push_back(i);
                }else{
                    tmp.push_back((24-i)%24);
                }
            }
        }
        sort(all(tmp));
        ll tans = 1e9;
        for(i = 0;i < tmp.size()-1;++i){
            ll t = tmp.at(i+1) -  tmp.at(i);
            tans = min(tans, t);
        }
        tans = min(tans, 24-tmp.back());
        ans = max(ans, tans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;

#define iter(i, n) for (int i = 1; i <= n; ++i)
#define NR 101000

typedef long long i64;

vector<int> e[NR];
int n, a[NR], d[NR];
bool valid = true;

i64 dfs(int x, int fa) {
	if (d[x] == 1) {
		return a[x];
	}
	i64 sum = 0, mx = 0;
	for (int v : e[x]) if (v != fa) {
		i64 tmp = dfs(v, x);
		sum += tmp; mx = max(mx, tmp);
	}
	if (a[x] > sum || (sum + 1) / 2 > a[x]) { valid = false; return 0; }
	i64 delta = sum - a[x];
	if (delta > (mx * 2 <= sum ? sum / 2 : sum - mx)) { valid = false; return 0; }
	return sum - 2 * delta;
}

int main() {
	//freopen("10C.in", "r", stdin);
	scanf("%d", &n);
	iter(i, n) scanf("%d", &a[i]);
	iter(i, n - 1) {
		int x, y;
		scanf("%d%d", &x, &y);
		e[x].push_back(y);
		e[y].push_back(x);
		++d[x], ++d[y];
	}
	int root = -1;
	iter(i, n) if (d[i] != 1) root = i;
	if (root == -1) {
		if (a[1] == a[2]) puts("YES");
		else puts("NO");
		return 0;
	}
	if (dfs(root, 0) != 0 || !valid) puts("NO");
	else puts("YES");
	return 0;
}

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

using namespace std;

int main(void)
{
    int i, ans=0;
    string s;

    cin >> s;

    for(i=0; i<4; i++){
        if(s[i]=='+'){
            ans++;
        }
        else{
            ans--;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import deque
#探索
def bfs(Sy,Sx):

    dis=[[-1]*W for i in range(H)]
    dis[Sy][Sx]=0
    q=deque()
    q.append([Sy,Sx])#pairとして入れる
    nun=0

    #qの中身が無くなるまで続ける(bfsのメイン部分)
    while(len(q)!=0):
        y=q[0][0]
        x=q[0][1]
        q.popleft()
        
        #四方向それぞれ条件を満たせるか調べていく
        for dy,dx in ([0, 1], [1, 0], [0, -1], [-1, 0]):
            ny=y+dy
            nx=x+dx
            if ny<0 or ny>=H or nx<0 or nx>=W:
                continue
            if field[ny][nx]=="#":
                continue
            if dis[ny][nx]!=-1:
                continue
            dis[ny][nx]=dis[y][x]+1
            nun=max(nun,dis[ny][nx])
            q.append([ny,nx])
    return nun
  
#入力
H,W=map(int,input().split())
field=[input() for i in range(H)]

#各開始地点からの距離をそれぞれ求め最大のものを出力
ans=-1
for y in range(H):
    for x in range(W):
        if field[y][x]=="#":
            continue
        ans=max(ans,bfs(y,x))
print(ans)

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

int main() {
  long long n;	cin >> n;
  long long m=1e12;
  for(int a=1;a<=sqrt(n);a++){
    long long b=n/a;
    if(a*b==n)	m=min(a+b-2,m);
  }
  cout << m;
}

Measured memory_bytes: 3688
#include<bits/stdc++.h>
#define ll long long
#define forn(i,n) for(ll i=0;i<(n);i++)
#define maxx ((ll)1e6+5)
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
	 int n;
	 cin>>n;
	 int a[n-1];
	 int b[n]={0};
	 forn(i,n-1){
	 cin>>a[i];
	 b[a[i]-1]++;
}
	forn(i,n)
	cout<<b[i]<<endl;
	   return 0;
}

Measured memory_bytes: 5184
"use strict";
const Main = (input) =>{
   let xs = input.trim().split(' ').map(v=>parseInt(v,10));
   let takaHP = xs[0];
   let takaAT = xs[1];
   let aokiHP = xs[2];
   let aokiAT = xs[3];
   let ans1 = 0;
   let ans2 = 0;
   while(true){
    let HP = aokiHP - takaAT;
        aokiHP = HP;
        ans1++
        if(aokiHP<=0){
        break;
        }
   }
   while(true){
    let HP = takaHP - aokiAT;
        takaHP = HP;
        ans2++
        if(takaHP<=0){
        break;
        }
   }
    
     if(ans1<=ans2){
        console.log('Yes');
     }else{
        console.log('No');
     }
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 29620
#include <iostream>
 
 
using namespace std;
 
int hig(int x, int y){
	if(x < y){
		return y;
	}
	else{
		return x;
	}
}
 
int main(){
    int n, w, h;
    cin >> w >> h >> n;
    
    int sol = 0, veci = hig(w, h);
    
    for(int i = 0; i < veci; ++i){
    	n -= veci;
    	sol++;
    	
    	if(n <= 0){
    		break;
		}
	}
	
	cout << sol;
 
 
	return 0;
}

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

int main() {
  int H, W;
  string S;

  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    S += s;
  }
  // cout << S << endl;

  for (int i = 0; i < H * W; i++) {
    int lu, cu, ru, l, r, ld, cd, rd, bomb = 0;
    lu = ((i - W - 1) / W) * W + (i - W - 1) % W; // 左上
    cu = lu + 1;
    ru = lu + 2;
    l = i - 1;
    r = i + 1;
    ld = ((i + W - 1) / W) * W + (i + W - 1) % W;
    cd = ld + 1;
    rd = ld + 2;
    // cout << lu << cu << ru << endl;
    // cout << l << S.at(i) << r << endl;
    // cout << ld << cd << rd << endl;
    // 爆弾だったら何もしない
    if (S.at(i) == '#') cout << '#';
    else {
      if (0 <= lu && (i / W) - 1 == lu / W) if (S.at(lu) == '#') bomb += 1;
      if (0 <= cu && (i / W) - 1 == cu / W) if (S.at(cu) == '#') bomb += 1;
      if (0 <= ru && (i / W) - 1 == ru / W) if (S.at(ru) == '#') bomb += 1;
      if (((i / W) * W) - 1 < l) if (S.at(l) == '#') bomb += 1;
      if (r < i / W * W + W) if (S.at(r) == '#') bomb += 1;
      if (ld < H * W && (i / W) + 1 == ld / W) if (S.at(ld) == '#') bomb += 1;
      if (cd < H * W && (i / W) + 1 == cd / W) if (S.at(cd) == '#') bomb += 1;
      if (rd < H * W && (i / W) + 1 == rd / W) if (S.at(rd) == '#') bomb += 1;
      cout << bomb;
    }
    if (i % W == W - 1) cout << endl;
  }
}


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

using namespace std;

int main()
{
    int k,s;
    cin >> k >> s;

    int cnt = 0;
    for(int i = 0; i <= k; i++) {
        if(i > k) break;
        for(int j = 0; j <= k; j++) {
            if(j > k) break;
            int z = s - i - j;
            if(0 <= z && z <= k) cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N;
vector<int> A, B;
int main()
{
    cin >> N;
    A.resize(N);
    B.resize(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++)
    {
        cin >> B[i];
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    int result = 0;
    for (int k = 0; k < 29; k++)
    {
        const int T = 1 << k;
        vector<int> B_MOD(N);
        for (int i = 0; i < N; i++)
        {
            B_MOD[i] = B[i] % (1 << (k + 1));
        }
        sort(B_MOD.begin(), B_MOD.end());
        int cnt = 0;
        for (int i = 0; i < N; i++)
        {
            int A_MOD = A[i] % (1 << (k + 1));
            int idx1 = lower_bound(B_MOD.begin(), B_MOD.end(), T - A_MOD) - B_MOD.begin();
            int idx2 = lower_bound(B_MOD.begin(), B_MOD.end(), 2 * T - A_MOD) - B_MOD.begin();
            cnt += idx2 - idx1;
            int idx3 = lower_bound(B_MOD.begin(), B_MOD.end(), 3 * T - A_MOD) - B_MOD.begin();
            int idx4 = lower_bound(B_MOD.begin(), B_MOD.end(), 4 * T - A_MOD) - B_MOD.begin();
            cnt += idx4 - idx3;
        }
        if (cnt % 2)
        {
            result += 1 << k;
        }
    }
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 2672
import java.util.*;
import java.lang.*;
import java.io.*;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		String u, nl = System.getProperty("line.separator");
		StringBuilder 
			p = new StringBuilder(1000),
		  	d = new StringBuilder("."),
		  	s = new StringBuilder("#"),
		  	k = new StringBuilder(50);
		Scanner r = new Scanner(System.in);
		int h, w, ww = 0;
		while (4 > ww++) {
			d.append(d);
			s.append(s);
		}
		ww = d.length();
		while (0 < ((h = r.nextInt()) | (w = r.nextInt()))) {
			while (w > ww) {
				d.append(d);
				s.append(s);
				ww += ww;
			}
			p.append(u = s.substring(0, w)).append(nl);
			k.setLength(0);
			k.append(d.substring(0, w)).append(nl)
			.replace(0, 1, "#").replace(w - 1, w, "#");
			while (2 < h--) {
				p.append(k);
			}
			p.append(u).append(nl).append(nl);
		}
		System.out.print(p);
	}
}

Measured memory_bytes: 18372
import Data.List ( sortBy )
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  _  <- getLine
  as <- readInts 
  print . point . alisAndBob' . sort' $ as

sort' 
  :: Ord a => [a] -> [a]
sort' = sortBy (flip compare)

point
  :: ([Int],[Int]) -> Int
point (as,bs) = sum as - sum bs

alisAndBob'
  :: Ord a => [a] -> ([a],[a])
alisAndBob' ns = (alice, bob)
  where
    helper f = map snd . filter f
    ns' = zip (cycle [True, False]) ns
    alice = helper fst         ns'
    bob   = helper (not . fst) ns'

Measured memory_bytes: 508