akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
from string import ascii_uppercase
import sys, bisect, math
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

R,G,B,N = read_int()

def solve():
    ans = 0

    for i in range(0, N + 1, R):
        res = i
        if res > N: continue
        for j in range(0, N + 1 - res, G):
            res = i + j
            if res <= N and (N - res) % B == 0:
                ans += 1
    return ans

if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 4088
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long MOD = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int a, int B) {return (a + (B - 1)) / B;}
long long divCeil(long long a, int B) {return (a + (B - 1)) / B;}
long long divCeil(int a, long long B) {return (a + (B - 1)) / B;}
long long divCeil(long long a, long long B) {return (a + (B - 1)) / B;}

int main()
{
  string s, t;
  cin >> s >> t;

  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
  
  string ans = "No";
  if (s < t) ans = "Yes";
  
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func max(x, y int) int {
	if x >= y {
		return x
	}
	return y
}

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

	fmt.Println(max(a*b, c*d))
}


Measured memory_bytes: 512
n = int(input())
v  = list(map(int, input().split()))
a = [v[i] for i in range(0, n, 2)]
b = [v[i] for i in range(1, n, 2)]
d = {}
for i in a:
    if i not in d:
        d[i] = 1
    else:
        d[i] +=1
e = {}
for i in b:
    if i not in e:
        e[i] = 1
    else:
        e[i] +=1
d = sorted(d.items(), key=lambda x: -x[1])
e = sorted(e.items(), key=lambda x: -x[1])
if d[0] != e[0]:
    print(n-d[0][1]-e[0][1])
else:
    if len(d) == len(e) == 1:
        print(n//2)
    elif len(d) == 1 and len(e) > 1:
        print(n//2-e[1][1])
    elif len(d) > 1 and len(e) == 1:
        print(n//2-d[1][1])
    else:
        print(n-max(d[0][1]+e[1][1], d[1][1]+e[0][1]))


Measured memory_bytes: 105132
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	map<string, int> mp;
	while( n-- ){
		string s; cin >> s;
		sort( s.begin(), s.end() );
		++mp[s];
	}
	ll ans = 0;
	for( auto a : mp ){
		ll k = a.second;
		ans += k*(k-1)/2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 11136
import java.util.Scanner;

public class Main {

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

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		int ans = A + B + C + Math.max(A, Math.max(B, C)) * 9;

		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
X = int(input())

dp = [False for _ in range(110000)]
dp[0] = True

price = [100, 101, 102, 103, 104, 105]

for i in range(X + 1):
    if dp[i]:
        for p in price:
            dp[i + p] = True

if dp[X]:
    print(1)
else:
    print(0)

Measured memory_bytes: 45908
import java.util.*;
public class Main{
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      int x = sc.nextInt();
      int[] cost = new int[n];
      int[][] value = new int[n][m];
      for(int i=0;i<n;i++){
      	cost[i]=sc.nextInt();
      	for(int j=0;j<m;j++){
      		value[i][j]=sc.nextInt();
      	}
      }
      int resultsum=Integer.MAX_VALUE;
      int flag =0;
      for(int i=0;i<(1<<n);i++){
      	int curr =0;
      	int[] currsum= new int[m];
      	for(int j=0;j<n;j++){
      		if(((i>>j)&1)==1){
      			curr = curr+cost[j];
      			for(int k=0;k<m;k++){
      				currsum[k]=currsum[k]+value[j][k];
      			}
      		}
      	}
      	if(check(currsum,x)){
      		flag=1;
      		resultsum= Math.min(resultsum,curr);
      	}
      }
      if(flag==0){
      	System.out.println(-1);
      	return;
      }
      System.out.println(resultsum);
}
public static boolean check(int[] arr, int x){
	for(int i=0;i<arr.length;i++){
		if(arr[i]<x){
			return false;
		}

	}
	return true;
}
}

Measured memory_bytes: 37364
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define f(x) x*x
using namespace std;
int ans;
int main(){
    int ma,n;
    while(cin>>n){
        for(int i=n;i<600;i+=n){
            ans += (f(i) * n);
        }
        cout<<ans<<endl;
        ans=0;
    }
return 0;
}

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

int main()
{
	int n, d, result = 0;
	cin >> n >> d;
	for (int q = 0; q < n; q++)
	{
		double a, b;
		cin >> a >> b;
		if (sqrt(a * a + b * b) <= d)
			result++;
	}
	cout << result;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 233;
char s[maxn];
int f[maxn],g[maxn];
int main()
{
	scanf("%s",s+1);
	int n = strlen(s+1); 
	reverse(s+1,s+1+n);
	for(int i=0;i<=n;i++)f[i] = g[i] = 1e9;
	f[0] = 0;g[0] = 1e9;
	for(int i=1;i<=n;i++){
		int x = s[i]-'0';
		for(int j=0;j<=9;j++){
			int op = (x+j+0)/10;
			int ex = (x+j+0)%10;
			int cost = f[i-1]+j+ex;
			if(op==0)f[i] = min(f[i],cost);
			else     g[i] = min(g[i],cost);
			op = (x+j+1)/10;
			ex = (x+j+1)%10;
			cost = g[i-1]+j+ex; 
			if(op==0)f[i] = min(f[i],cost);
			else     g[i] = min(g[i],cost);
		}
	}
//	cout<<"!"<<f[1]<<" "<<g[1]<<endl;
	int ans = min(f[n],g[n]+1);
	cout << ans << endl; 
}


Measured memory_bytes: 9088
N,K = map(int, input().split())

H = []
for i in range(N):
    H.append(int(input()))

H.sort()

ans = float('inf')
for i in range(N):
    if (i+K-1 > N-1):
        break
    ans = min(ans, H[i+K-1] - H[i])

print(ans)

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int Q;

LL BS(LL x , LL y , LL t){
	if(y-x<2) return x;
	LL z = (x+y)/2;
	return (z/2) * ((z+1)/2) < t ? BS(z,y,t) : BS(x,z,t);
}

int main(){
	cin >> Q;
	repp(rep_q,0,Q){
		LL A,B; cin >> A >> B;
		if(A == B){
			cout << (A-1) * 2 << endl;
			continue;
		}
		if(A < B) swap(A,B);
		LL C = A*B/(B+1);
		C = BS(1,B+C+2,A*B) - B - 1;
		cout << B + C - 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int x = scanner.nextInt(), a = scanner.nextInt(), b = scanner.nextInt();
			if (a >= b) {
				System.out.println("delicious");
			} else if (x + a >= b) {
				System.out.println("safe");
			} else {
				System.out.println("dangerous");
			}
		}
	}
}


Measured memory_bytes: 35768
<?php
$a = trim(fgets(STDIN));  

$arr = str_split($a);
$cnt = count($arr);

if ($cnt % 2 === 0) {               //偶数時
  $mae = $cnt /2;
  $mae2 =0- $mae;
  $ato = $mae - 1;
  $result1 = array_slice($arr , 0, $mae);
  $result2 = array_slice($arr , $mae);
  $result3 = array_reverse($result2);
  $s = implode($result1);
  $t = implode($result3);

      $diff = array_diff_assoc($result1, $result3);
      $f = count($diff);
      echo $f;
    
} else {                     //奇数時
  $ass = $cnt - 1;
  $mae = $ass /2;
  $ato = $mae + 1;
  $result1 = array_slice($arr , 0, $mae);
  $result2 = array_slice($arr , $ato);
  $result3 = array_reverse($result2);
  $s = implode($result1);
  $t = implode($result3);

      $difs = array_diff_assoc($result1, $result3);
      $f = count($difs);
      echo $f;

}
?>


Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
using namespace std;

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if(a==b){
        cout << c << endl;
    }else if(b==c){
        cout << a << endl;
    }else{
        cout << b << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()
#define N 200000
int main()
{
	int n,k;
	cin>>n>>k;
	int arr[n];
	forl(i,0,n) cin>>arr[i];
	int dp[n];
	dp[0]=0;
	forl(i,1,n) dp[i]=INT_MAX;
	forl(i,1,n)
	{
		for(int j=i-1;j>=i-k;j--)
		{
			if(j>=0)
			dp[i]=min(dp[i],dp[j]+abs(arr[j]-arr[i]));
		}
	}
	cout<<dp[n-1]<<endl;
	
	
}

Measured memory_bytes: 1024
use std::collections::HashMap;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let n : u64 = read();
    let mut tn : Vec<u64>= Vec::new();
    for _ in 0..n {
        tn.push(read::<u64>());
    }
    let ans = tn.into_iter().fold(None,|x,y| Some(match x {
        None => y,
        Some(x) => lcm(x,y),
    })).unwrap();
    println!("{}",ans);
}
fn gcd(a:u64,b:u64) -> u64{
    let c = a % b;
    if c == 0{
        b
    } else {
        gcd(b,c)
    }
}
fn lcm(a:u64,b:u64) -> u64{
    a / gcd(a,b) * b
}

Measured memory_bytes: 4352
N = int(input())
A, B = map(int, input().split())
P = list(map(int, input().split()))

c0 = 0
c1 = 0
c2 = 0

for i in range(N):
    if P[i] <= A:
        c0 += 1
    elif A + 1 <= P[i] <= B:
        c1 += 1
    else:
        c2 += 1

print(min(c0, c1, c2))


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 81

//全部売る(k=0)/買う(k=1)/何もしない(k=2)実行時

//dp[i][j][k]:i日目にj株持っている時の最大所持金
ll dp[MAXN][200];

int main(){
  int n;cin>>n;
  vector<ll>a(n);
  rep(i, n)cin>>a[i];

  bool buying=true;
  ll bp=200, sp=0, coin=1000, stocks=0;
  for(auto t: a){
//cout<<t<<' '<<bp<<' '<<sp<<' '<<coin<<' '<<stocks<<endl;
    if(buying){
      if(t>bp){
        buying=false;
        stocks += coin/bp;
        coin%=bp;
        sp=t;
        bp=300;
      }else{
        bp=t;
      }
    }else{
      if(t<sp){
        buying=true;
        bp=t;
        coin+=sp*stocks;
        stocks=0;
        sp=0;
      }else{
        sp=t;
      }
    }
  }

  if(stocks)coin+=sp*stocks;

  cout<<coin<<endl;

  return 0;
}


Measured memory_bytes: 3648
#include <cstdio>

using namespace std;

int comb(int n) { return (n > 1) ? (n * (n - 1)) / 2 : 0; }

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  printf("%d\n", comb(n) + comb(m));
  return 0;
}


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

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

// auto mod int

const i64 MOD = 1'000'000'007;

struct mint {
  long long x;
  mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

// Factorials over ModInts.
struct Factorials {
  // factorials and inverse factorials.
  vector<mint> fact, ifact;

  // n: max cached value.
  Factorials(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < MOD);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }

  // Combination (nCk)
  mint C(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }

  // Permutation (nPk)
  mint P(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[n - k];
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> C(N);
  REP(i, N) { cin >> C[i]; }
  map<int, int> lastc;
  mint ans;
  vector<mint> dp(N + 1);
  dp[0] = 1;
  for (int i = 0; i < N; lastc[C[i]] = i, ++i) {
    dp[i + 1] = dp[i];
    auto it = lastc.find(C[i]);
    if (it == lastc.end()) continue;
    int j = it->second;
    if (j == i - 1) continue;
    dp[i + 1] += dp[j + 1];
    DEBUG(i, j, dp[j], dp[i + 1]);
  }
  REP(i, N + 1) { cerr << dp[i] << ' '; }
  cerr << endl;
  cout << dp[N] << endl;
}


Measured memory_bytes: 14992
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
    llong n,m,h[100010],ans=0;
    map<llong, llong> mp;
    cin >> n >> m;
    rep(i,n){
        cin >> h[i+1];
    }
    rep(i,m){
        llong a,b;
        cin >> a >> b;
        if(h[a] < h[b]) mp[a]++;
        else if(h[a] > h[b]) mp[b]++;
        else{
            mp[a]++;
            mp[b]++;
        }
    }
    for(llong i=1;i<=n;i++){
        if(!(mp[i] > 0)) ans++;
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while(1)
    {
        for(int i=0;i<2;i++)
        {
            if(!(i&1))
            {
                c-=b;
                if(c<=0)
                {
                    cout << "Yes\n";
                    return 0;
                }
            }
            else
            {
                a-=d;
                if(a<=0)
                {
                    cout << "No\n";
                    return 0;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int a,b,c;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
if (a <=c)
	{
		if (c <=b)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	else
	{
		printf("No\n");
	}
	system("pause");
}

Measured memory_bytes: 504
import sys
import math
import collections
from collections import deque
#n = int(input())
#a, b = map(int, input().split())
s = input()
#x = list(map(int, input().split()))
q = int(input())
d = deque([])
for i in range(len(s)):
    d.append(s[i])

rev = 1
for i in range(q):
    que = list(map(str, input().split()))
    if que[0] == "1":
        rev *= -1

    else:
        if rev == 1:
            if que[1] == "1":
                d.appendleft(que[2])
            else:
                d.append(que[2])

        else:
            if que[1] == "1":
                d.append(que[2])
            else:
                d.appendleft(que[2])


if rev == 1:
    for i in range(len(d)):
        print(d.popleft(), end="")
else:
    for i in range(len(d)):
        print(d.pop(), end="")




Measured memory_bytes: 7792
#include <iostream>

using namespace std;

int main() {
    int L, R, d;
    cin >> L >> R >> d;
    int ans = 0;
    for(int i = 0; ; i++) {
        if(d*i >= L && d*i <= R) {
            ans++;
        }
        else if(d*i > R)
            break;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define int long long

using namespace std;

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

	int n ; cin >> n ; 
	if(n >= 30) cout<< "Yes";
	else cout << "No";    

  return 0;
}


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

int main(){
	int a,b,c;
	int ans;
	
	string cunning="776755555555555555555555555555555555555554";
	
	for(int i=0;i<104;i++){
		cin>>a>>b;c=a+b;
		//-----test-----
		if(i<cunning.size()){
			cout<<cunning[i]<<endl;
			continue;
		}
		//--------------
		ans=1;
		while(10<=c){
			c/=10;
			ans++;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<int> a(m);
  int p=0;
  for(int i=0;i<m;i++){
    cin>>a.at(i);
    p+=a.at(i);
  }
  if(n>=p){
    cout<<n-p<<endl;
  }else{
    cout<<-1<<endl;
  }
  return 0;
}

Measured memory_bytes: 3656
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int[] cnt = new int[n];
            int[] p = in.nextIntArray0indexed(2 * m);
            for (int x : p) cnt[x]++;
            for (int x : cnt) {
                if (x % 2 == 1) {
                    out.println("NO");
                    return;
                }
            }
            out.println("YES");
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public int[] nextIntArray0indexed(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt() - 1;
            }
            return res;
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 43536
#include <iostream>

using namespace std;

int main(){
  string s;
  std::cin >> s;
  bool okflag = true;
  for(int i=1; i<s.size(); i++){
    if( s.at(i-1) == s.at(i) ) okflag = false;
  }
  auto ans = (okflag)? "Good" : "Bad";
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define mem0(s) memset(s,0,sizeof(s))
#define meminf(s) memset(s,0x3f,sizeof(s))
#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))
typedef long long ll;
typedef unsigned long long ull;
const int INF=0x3f3f3f3f,max_n=200005;
inline ll lowbit(ll x){return x&(-x);}
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll max(ll a,ll b){return a>b?a:b;}
double r,pi=acos(-1);
int n,x;
int data1[max_n];
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	cin>>n;
	for(int i=2;i<=n;i++)
	{
		cin>>x;
		data1[x]++;
	}
	for(int i=1;i<=n;i++)
	{
		cout<<data1[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 4376
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 123456;
vector<int> ans[MAXN];

int main() {
    int n;
    scanf("%d", &n);
    int tmp = n * 2;
    int k = sqrt(tmp);
    if (k * (k + 1) != tmp) return !printf("No\n");
    printf("Yes\n%d\n", k + 1);
    int cur = 1;
    for (int i = 1; i <= k + 1; i++) {
        printf("%d ", k);
        int cnt = 0;
        for (int j = 1; j < i; j++) {
            printf("%d ", ans[j].back());
            ans[j].pop_back();
            cnt++;
        }
        for (int j = 0; j < k - cnt; j++) {
            printf("%d ", cur);
            ans[i].push_back(cur++);
        }
        puts("");
    }

    return 0;
}


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

int main(){
	int n;
	string s1,s2;

	cin >> n;
	cin >> s1;
	cin >> s2;

	long long int patterns = 3;
	bool prev = false;//一つ前に見たドミノが true:横 false:縦

	for(int i = 0; i < n; ++i){
		if(i == 0){
			if(s1[i] == s2[i]){//縦
				prev = false;
			} else{//横
				++i;
				patterns*=2;
				prev = true;
			}
			continue;
		}
		if(s1[i] == s2[i]){//縦
			if(prev){
				//donothing
			} else{
				patterns *= 2;
			}
			prev = false;
		} else{//横
			++i;
			if(prev){
				patterns *= 3;
			} else{
				patterns *= 2;
			}
			prev = true;
		}
	}

	cout << patterns % 1000000007 << endl;

	return 0;

}

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

const long long int mod=1e9+7;
long long int dp[100005];
int main(){
    int N,M;
    cin >> N >> M;
    int a;
    int i,j;
    for(i=0;i<M;i++){
        cin >> a;
        dp[a]=-1;}
    dp[0]=1;
    for(i=0;i<N;i++){
        if(dp[i+1]>=0 && dp[i]>0)dp[i+1]=(dp[i+1]+dp[i])%mod;
        if(dp[i+2]>=0 && dp[i]>0)dp[i+2]=(dp[i+2]+dp[i])%mod;
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

vector<int> makevec(string &s)
{
    vector<int> ret(26, 0);
    rep(i, s.size())
    {
        ret[s[i] - 'a']++;
    }
    return ret;
}

vector<int> intersection(vector<int> v1, vector<int> v2)
{
    vector<int> ret(26, 0);
    rep(i, 26)
    {
        ret[i] = min(v1[i], v2[i]);
    }
    return ret;
}

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<int> ans(26, 1 << 29);
    rep(i, n)
    {
        string s;
        cin >> s;
        ans = intersection(ans, makevec(s));
    }
    rep(i, 26)
    {
        rep(j, ans[i])
        {
            cout << (char)('a' + i);
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"stdio.h"
#include<string.h>

int main() {
	long int red=0;
	long int blue=0;
	long int btotal=0;
	long int ired;
	long int iblue;
	long int itotal;
	scanf("%ld %ld %ld", &itotal, &iblue, &ired);
	long int i;
	long int cnt = 0;
	//printf("%d", itotal);

	long int calc;
	long int nokori;
	calc = iblue + ired;
	nokori = itotal % calc;
	long int full;
	full = itotal - nokori;
	long int times;
	times = full / calc;



	long int p1;
	p1 = iblue * times;
	btotal = 0;
	blue = red = 0;
	int u;
	for (i = 0; i < nokori; u=0) {
		if (cnt == 0) {
			if (iblue + i > nokori) {
				btotal += nokori - i;
				i += nokori - i;
			}
			else {
				btotal += iblue;
				i += iblue;
			}
			cnt = 1;
		}
		else {
			if (ired + i > nokori) {
				i += nokori - i;
			}
			else {
				i += ired;
			}
			cnt = 0;
		}
	}

	printf("%ld", p1 + btotal);
}

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

char str[100010];

int main()
{
    int i,ans;
    std::ios::sync_with_stdio(false);
    while(cin >> str)
    {
        int len = strlen(str);
        ans = len;
        for(i = 1; i < len; i++)
            if(str[i-1] != str[i])
                ans = min(ans,max(len-i,i));
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 384
ABCD=list(map(int,list(str(input()))))
for i in range(2**3):
    value=ABCD[0]
    for s,m in enumerate("0"*(3-len(bin(i)[2:]))+(bin(i)[2:])):
        if m=="0":value+=ABCD[s+1]
        else:value-=ABCD[s+1]
    if value==7:
        printdata=""
        for s,m in zip(ABCD,"0"*(3-len(bin(i)[2:]))+(bin(i)[2:])):
            printdata+=str(s)
            printdata+="+" if m=="0" else "-"
        printdata+=str(ABCD[-1])+"=7"
        print(printdata)
        break


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N; cin >> N;
  string s; cin >> s;
  int ans=0;
  rep(i,1,N-1){
    string a=s.substr(0,i);
    string b=s.substr(i);

    set<char>st,bb;;
    for(auto c:a)st.insert(c);
    int tmp=0;
    for(auto c:b)bb.insert(c);
    for(auto c:bb)tmp+=st.count(c);
    chmax(ans,tmp);
  }
  cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
int main(){
    int n,x,count=0,ans=0,a,b,c,k,y;
    string s;
    vector<int> v;
        cin>>n>>k>>x>>y;
        for(int i=0;i<n;i++){
        if(i<k)ans+=x;
        else ans+=y;
        }
        cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;

#define SIZE 100010

int u[SIZE],v[SIZE],w[SIZE];
ll wmemo[SIZE];

pair<int,ll> dfs(int now, int path, vector<vector<pair<int,int> > > &way,
        vector<int> &visited, vector<int> &sum, vector<bool> &is_bridge){
  int res_sum = 0;
  visited[now] = 1;

  ll sumw = 0;
  
  for(int i=0;i<way[now].size();i++){
    auto p = way[now][i];
    if(p.second == path) continue;

    if(visited[p.first] == 1){
      sum[p.first]--;
      sum[now]++;
      is_bridge[p.second] = false;
      sumw += w[p.second];
    }else if(visited[p.first] == 0){
      auto res = dfs(p.first, p.second, way, visited, sum, is_bridge);
      res_sum += res.first;
      sumw += res.second + w[p.second]; 
      if(res.first > 0) is_bridge[p.second] = false;
    }
  }

  visited[now] = 2;
  wmemo[path] = sumw;
  return {res_sum + sum[now], sumw};  
}


int main(){
  int n, m, maxw_i;
  ll sumw = 0, maxw = 0;
  
  scanf("%d%d", &n, &m);

  vector<vector<pair<int,int> > > way(n);
  vector<int> visited(n, 0), sum(n, 0);
  vector<bool> is_bridge(m, true);
  
  for(int i=0;i<m;i++){
    scanf("%d%d%d", u+i, v+i, w+i);
    sumw += w[i];
    if(maxw < w[i] || (maxw == w[i] && (u[maxw_i] > u[i] || (u[maxw_i] == u[i] && v[maxw_i] > v[i])))){
      maxw = w[i]; maxw_i = i;
    }
    u[i]--; v[i]--;
    
    way[u[i]].push_back({v[i], i});
    way[v[i]].push_back({u[i], i});
  }

  dfs(0, -1, way, visited, sum, is_bridge);
  
  ll ans1 = sumw - maxw;
  ll ans2 = maxw_i;
  
  for(int i=0;i<m;i++){
    if(is_bridge[i]){
      ll calc = abs((sumw - wmemo[i] - w[i]) - wmemo[i]);
      if(ans1 >= calc){
        if(ans1 > calc || (u[ans2] > u[i] || (u[ans2] == u[i] && v[ans2] > v[i])))
        ans1 = calc;
        ans2 = i;
      }
    }
  }

  //debug(ans1);
  
  printf("%d %d\n", u[ans2]+1, v[ans2]+1);
}



Measured memory_bytes: 13372
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int n, p, t, x, o;
	cin >> n;
	vector<int> cpp[1000];
	cin >> p;
	while (p--)
	{
		cin >> o >> t;
		if (o > 0)
		{
			if (o == 1)
			{
				for (int i = 0; i < cpp[t].size(); i++)
				{
					if (i > 0)cout << " ";
					cout << cpp[t][i];
				}
				cout << endl;
			}
			if (o == 2)
				cpp[t].clear();
		}
		else 
		{
			cin >> x;
			cpp[t].push_back(x);
		}
	}
	return 0;
}


Measured memory_bytes: 5820
import java.util.Scanner;
import java.util.stream.IntStream;

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

        int []a = IntStream.range(0, n).map(x -> in.nextInt()).toArray();
        long [][]dp = new long[n][n];

        for(int i = 0; i < n; i++) {
            dp[i][i] = a[i];
        }
        for (int i = 0; i < n - 1; i++) {
            dp[i][i + 1] = Math.max(a[i], a[i + 1]) - Math.min(a[i], a[i + 1]);
        }

        for(int len = 2; len < n; len++) {
            for(int start = 0; start + len < n; start++) {
                int end = start + len;
                dp[start][end] = Math.max(a[start] - dp[start + 1][end], a[end] - dp[start][end - 1]);
            }
        }
        System.out.println(dp[0][n - 1]);
    }
}


Measured memory_bytes: 137548
import java.util.*;

public class Main{
    public static void main(String args[]){
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	int[] x = new int[6];

	for(int i = 0 ; i < 6 ; ++i){
	    x[i] = 0;
	}
	
	for(int i = 0 ; i < n ; ++i){
	    double a = scan.nextDouble();
	    if(a < 165.0)
		x[0]++;
	    else if(a < 170)
		x[1]++;
	    else if(a < 175)
		x[2]++;
	    else if(a < 180)
		x[3]++;
	    else if(a < 185)
		x[4]++;
	    else
		x[5]++;	
	}
	for(int i = 0 ; i < 6 ; ++i){
	    System.out.print((i+1) + ":");
	    for(int j = 0 ; j < x[i] ; ++j){
		System.out.print("*");
	    }
	    System.out.println();
	}
    }
}

Measured memory_bytes: 20448
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main()
{
  long long N;
  scanf("%lld", &N);

  cout << (1000 - N % 1000) % 1000 << endl;

  return 0;
}


Measured memory_bytes: 3772
/*ex9-2
  Sweet_Sweet_Soul*/


#include <stdio.h>
#include <stdlib.h>

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}


int main(void){
    int count=0;/*答えのカウント*/
    char cube[100001];/*100000文字なのでnull文字含めて確保*/
    char *ptr;/*文字列操作用のポインタ*/
    char tmp;/*pop用の変数*/
    node *list=NULL;/*リスト用のポインタ*/
    scanf("%s",cube);
    ptr=cube;
    while(*ptr!='\0'){
        if(list==NULL || list->elem==*ptr){ /*listの一番上とptrの現在地が一緒 or listが空の場合*/
            push(&list,*ptr);
        }
        else{ /*listの一番上とptrの現在地が一緒*/
            pop(&list);/*listとcubeで一つづつ除去*/
            count=count+2;/*取り出した数をカウント*/
        }
        ptr++;
    }
    printf("%d",count);
    return 0;
}


Measured memory_bytes: 4888
import sys
input = sys.stdin.buffer.readline
N,Q = map(int,input().split())
BIT = [0]*(N+1)

def BIT_query(idx):
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

def BIT_update(idx,x):
    while idx <= N:
        BIT[idx] += x
        idx += idx&(-idx)
    return

c = [-1]+list(map(int,input().split()))
lastAppeared = [-1]*(N+1)
ans = [0]*Q
queries = []
for q in range(Q):
    l,r = map(int,input().split())
    queries.append(r*10**12+l*10**6+q)
queries.sort()

curR = 0
for i in range(Q):
    query = queries[i]
    r = query//10**12
    query %= 10**12
    l = query//10**6
    q = query % 10**6
    while curR < r:
        curR += 1
        new = c[curR]
        last = lastAppeared[new]
        if last != -1:
            BIT_update(last,-1)
        lastAppeared[new] = curR
        BIT_update(curR,1)
    ans[q] = BIT_query(r)-BIT_query(l-1)
for i in range(Q):
    print(ans[i])


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

int main() {
  int n, k, ans = 0;
  cin >> n >> k;
  vector<int> d(k);
  vector<vector<int>> a(k,vector<int>(n,0));
  vector<bool> c(n+1, false);
  for (int i = 0; i < k; i++)
  {
    cin >> d[i];
    for (int j = 0; j < d[i]; j++)
    {
      cin >> a[i][j];
      c[a[i][j]]= true;
    }
    
  }
  for (int i = 1; i < n+1; i++)
  {
    if (c[i] == false)
    {
      ans++;
    }
    
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3632
#[allow(unused_imports)]
use std::cmp::{Ordering};

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

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

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

fn solve() {
    let n = get!(usize);
    let p = get!([f64]);
    
    let mut dp = vec![vec![0.0; n+1]; n+1];
    dp[0][0] = 1.0;
    for i in 0..n {
        for j in 0..n {
            dp[i+1][j+1] += p[i] * dp[i][j];
            dp[i+1][j] += (1.0-p[i]) * dp[i][j];
        }
    }
    println!("{}", dp[n].iter().skip(n/2+1).sum::<f64>());
}


Measured memory_bytes: 94588
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (int i = (a), lim_i = (b); i < lim_i; i++)
#define REP(i, ...) REP_((i), __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Mar  7 21:00:01 JST 2020
 **/

signed main() {
    string s;
    cin >> s;
    bool rev = false;
    string A, B;
    Int Q;
    cin >> Q;
    REP(q, Q) {
        Int t;
        cin >> t;
        if (t == 1) {
            rev = !rev;
            swap(A, B);
        } else {
            Int f;
            char c;
            cin >> f >> c;
            (f == 1 ? A : B).push_back(c);
        }
    }
    reverse(A.begin(), A.end());
    if (rev) reverse(s.begin(), s.end());
    for (string t : {A, s, B}) {
        for (char c : t) cout << c;
    }
    cout << endl;
}


Measured memory_bytes: 1260
// ~/Remember,remember the 6th of March

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-8;
const ll MOD = 1000000007;
const int N = 100000 + 7;

int main()
{
    string s;
    cin>>s;
    if((s[2]==s[3])&&(s[4]==s[5]))
        puts("Yes");
    else puts("No");


    return 0;
}


Measured memory_bytes: 256
s = input()
a_cnt=0
ans=0
i=0
while i < len(s)-1:
    if s[i] == "A":
        a_cnt+=1
        i+=1
    elif s[i] == "B" and s[i+1] == "C":
        ans+=a_cnt
        i+=2
    else:
        a_cnt=0
        i+=1
print(ans)

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,k;cin>>n>>k;
  vector<ll>t(n),d(n);
  rep(i,0,n)cin>>t[i]>>d[i];
  vector<ll>order(n);
  iota(ALL(order),0LL);
  sort(ALL(order),[&](ll x,ll y){return d[x]>d[y];});
  set<ll>st;
  ll sum=0;
  ll cnt=0;
  priority_queue<ll,vector<ll>,greater<ll>>que;
  for(auto i:order){
    if(cnt<k){
      cnt++;
      sum+=d[i];
      if(st.count(t[i]))que.push(d[i]);
      else st.insert(t[i]);      
    }
    else{
      if(st.count(t[i]))continue;
      else if(!que.empty()){
        st.insert(t[i]);
        sum+=d[i]-que.top();
        que.pop();
      }
    }
    ll k=st.size();
    chmax(res,k*k+sum);
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 6012
n = gets.to_s.to_i

memo = Array.new(n + 1){ Array.new(n + 1) }

ans = 0
1.upto(n) do |i|
  1.upto(n) do |j|
    t = memo[i][j] ||= i.gcd(j)
    1.upto(n) do |k|
      ans += memo[t][k] ||= t.gcd(k)
    end
  end
end
 
puts ans

Measured memory_bytes: 14412
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
#include <memory>
#include <time.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);

#include <complex>
typedef complex<double> P;
#define LT(x,y) ((x)-(y)<=-EPS)

vector<P> cross_circles(P c1,double r1,P c2,double r2){
	double d=abs(c2-c1);
	if(LT(r1+r2,d)||LT(d,fabs(r1-r2)))
		return vector<P>();
	double l=0.5*((r1*r1-r2*r2)/d+d);
	double h=sqrt(r1*r1-l*l);
	vector<P> ret(2);
	ret[0]=P(l,+h)*(c2-c1)/d+c1;
	ret[1]=P(l,-h)*(c2-c1)/d+c1;
	return ret;
}

double distance(double y1,double x1,double y2,double x2){
	double dy=y1-y2;
	double dx=x1-x2;
	return sqrt(dy*dy+dx*dx);
}

bool ok(vi &y,vi &x,vi &l, double h){
	int n=y.size();
	vector<P> all_cross;
	REP(i,n){
		FOR(j,i+1,n){
			if(l[i]+EPS<h||l[j]+EPS<h){
				return false;
			}
			double di=sqrt(l[i]*l[i]-h*h);
			double dj=sqrt(l[j]*l[j]-h*h);
			double dist2=distance(y[i],x[i],y[j],x[j]);
			bool intersected=di+dj+EPS>dist2;
			vector<P> cross=cross_circles(P(y[i],x[i]),di,P(y[j],x[j]),dj);
			if(cross.size()==0){
				if(!intersected){
					return false;
				}
			}else{
				all_cross.push_back(cross[0]);
				all_cross.push_back(cross[1]);
			}
		}
		all_cross.push_back(P(y[i],x[i]));
	}

	REP(ci,all_cross.size()){
		bool ok=true;
		REP(k,n){
			double dk=sqrt(l[k]*l[k]-h*h);
			if(distance(y[k],x[k],all_cross[ci].real(),all_cross[ci].imag())>dk+EPS){
				ok=false;
			}
		}
		if(ok){
			return true;
		}
	}
	return false;
}

int main(){
	cout.precision(30);
	int n;
	while(cin>>n,n){
		vi x(n),y(n),l(n);
		int maxl=0;
		REP(i,n){
			cin>>x[i]>>y[i]>>l[i];
			maxl=max(maxl,l[i]);
		}

		double lb=1,ub=maxl;
		REP(time,1000){
			double mid=(lb+ub)/2;
			if(!ok(y,x,l,mid)){
				ub=mid;
			}else{
				lb=mid;
			}
		}
		cout<<ub<<endl;
	}
}

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

#define f first 
#define s second 
#define pb push_back               
#define mp make_pair 

using namespace std;                    

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int N = (int)1e5 + 123, mod = (int)1e9 + 7;

int main(){    
	bool ans = 1;
	string s;
	map<char, int > cnt;
	cin >> s;
	for(int i = 0; i < s.size(); i++)
		cnt[s[i]]++;
	if(cnt['S'] == 0 && cnt['N'] != 0)
		ans = 0;
	if(cnt['S'] != 0 && cnt['N'] == 0)
		ans = 0;
	if(cnt['E'] == 0 && cnt['W'] != 0)
		ans = 0;
	if(cnt['E'] != 0 && cnt['W'] == 0)
		ans = 0;
	if(ans)           
		cout << "Yes";
	else
		cout << "No";
	return 0;
}


Measured memory_bytes: 256