akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>

typedef unsigned long long u64;

u64 gcd(u64 n1, u64 n2){
    while(1) {
        if(n1 < n2) std::swap(n1, n2);
        if(n1%n2) n1 %= n2;
        else
            return n2;
    }
}

int main(){
    int n;
    u64 first, tmp;
    std::cin >> n >> first;
    for(int i = 1; i < n; i++){
        std::cin >> tmp;
        first = tmp / gcd(first, tmp) * first;
    }
    std::cout << first << std::endl;
    return 0;
}


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

int main(){

  string s;

  cin>>s;

  for(int i=0;i<s.size()-1;i++){
    if(s[i]=='A'&&s[i+1]=='C'){
      cout<<"Yes"<<endl;
      return 0;
    }
  }

  cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define rep(i,l,r)for(int i=(l);i<(r);i++)

//union-find
#define UFLIMIT (1<<18)
int unicnt[UFLIMIT+10];//正ならcnt、非正なら根のindex
void ufinit(int n){rep(i,0,n)unicnt[i]=1;}
int ufroot(int x){return unicnt[x]<=0?-(unicnt[x]=-ufroot(-unicnt[x])):x;}
int ufsame(int x,int y){return ufroot(x)==ufroot(y);}
void uni(int x,int y){if((x=ufroot(x))==(y=ufroot(y)))return;if(unicnt[x]<unicnt[y]){int t=x;x=y;y=t;}unicnt[x]+=unicnt[y];unicnt[y]=-x;}
#undef UFLIMIT


int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	ufinit(n);
	while(q--){
		int t,x,y;
		scanf("%d%d%d",&t,&x,&y);
		if(t==0)uni(x,y);
		else printf("%d\n",ufsame(x,y));
	}
}

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

int main(){
  int N;cin >> N;
  vector<ll> T(N);
  vector<ll> A(N);
  for(int i=0;i<N;i++){
    cin >> T[i] >> A[i];
  }
  ll Tcur=T[0],Acur=A[0];
  for(int i=1;i<N;i++){
    ll K = max((Tcur-1)/T[i],(Acur-1)/A[i]) + 1;
    //cout << K << " " << Tcur << " "<< Acur << endl;
    Tcur = K*T[i];
    Acur = K*A[i];
    //cout << K << " " << Tcur << " "<< Acur << endl;
  }
  cout << Tcur + Acur << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>

#define MAX_VAL 10000
#define MAX_LEN 2000001

int C[MAX_VAL + 1];

void countingSort(unsigned short A[], unsigned short B[], int n) {
    int i;
    for (i = 0; i <= MAX_VAL; i++) C[i] = 0;
    for (i = 1; i <= n; i++) C[A[i]]++;
    for (i = 1; i <= MAX_VAL; i++) C[i] += C[i - 1];
    for (i = n; i >= 1; i--) {
        B[C[A[i]]] = A[i];
        C[A[i]]--;
    }
}

void printarray(unsigned short A[], int n) {
    int i;
    for (i = 1; i <= n; i++) {
        if (i > 1) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
}

int main(void) {
    int n, i;
    unsigned short A[MAX_LEN];
    unsigned short B[MAX_LEN];
    scanf("%d", &n);
    for (i = 1; i <= n; i++) scanf("%hd", &A[i]);
    countingSort(A, B, n);
    printarray(B, n);
    return 0;
}



Measured memory_bytes: 9648
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  int r;
  cin >> r;
  cout << r * r << endl;
}


Measured memory_bytes: 3616
li = []
for i in range(3):
    a,b = map(int, input().split())
    li.append(a)
    li.append(b)

dic = {}

for i in li:
    if i in dic.keys():
        dic[i] += 1
    else:
        dic[i] = 1

dicc = {}
for i in dic.values():
    if i in dicc.keys():
        dicc[i] += 1
    else:
        dicc[i] = 1

if dicc[1] == 2 and dicc[2] == 2:
    print('YES')
else:
    print('NO')



Measured memory_bytes: 3064
k, n = map(int, input().split())
a_list = list(map(int, input().split()))

diff_max = 0

for i in range(len(a_list)-1):
    diff_max = max(diff_max, a_list[i+1] - a_list[i])

diff_max = max(diff_max, a_list[0] + (k - a_list[-1]))

print(k - diff_max)


Measured memory_bytes: 26436
# -*- coding: utf-8 -*-

N = int(input())
s = input()

r, b = 0, 0
for i in range(N):
    if s[i] == "R":
        r += 1
    elif s[i] == "B":
        b += 1

if r > b:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
/*void mayank()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}*/
#define ll long long
#define inf 1e9
const int mxN = 1e6;
ll a[mxN + 10], b[mxN + 1];
int main()
{
	//mayank();
	double d, s, t;
	cin >> d >> t >> s;

	if (t >= (d / s)) {
		cout << "Yes";
	} else {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 3708
N = int(input())
print(N*(N-1)//2 - N//2)
if(N%2 == 0):
    for i in range(1,N):
        for j in range(i+1,N+1):
            if(i+j != N+1):
                print(*[i,j])
else:
    for i in range(1,N):
        for j in range(i+1,N+1):
            if(i+j != N):
                print(*[i,j])

Measured memory_bytes: 9264
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;

int main(){
  long N,n;
  vector<long> A;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>n;
    A.push_back(n);
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  long x,y,flag=0;
  for(int i=0;i<N-1;i++){
    if(A[i]==A[i+3]&&flag==0){
      cout<<A[i] * A[i]<<endl;
      return 0;
    }else if(A[i]==A[i+2]){
      if(flag==0){
        x=A[i];
        flag+=1;
        i +=1;
      }else{
        y=A[i];
        cout<<x*y<<endl;
        return 0;
      }
    }else if(A[i]==A[i+1]){
      if(flag==0){
        x=A[i];
        flag+=1;
        //i +=1;
      }else{
        y=A[i];
        cout<<x*y<<endl;
        return 0;
      }
    }
    }
    cout<<0<<endl;
  return 0;
  }


Measured memory_bytes: 1400
N = int(input())
A = [0]*N

for i in range(N):
  A[i] = int(input())

A.sort()

count = 1
ans = 0
for i in range(N-1):
  if A[i] == A[i+1]:
    count+=1
  else:
    ans+=count%2
    count=1

ans+=count%2

print(ans)

Measured memory_bytes: 13288
#pragma GCC optimize("O3")
#pragma GCC optimize("O1")
#pragma GCC optimize("O2")
#pragma GCC optimize("Os")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(ll i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<pair<int,int>,int> &a, const pair<pair<int,int>,int> &b)
{
    return (a.first.second<b.first.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second<b.second);
}
ll modinv(ll x, ll y, ll modulo)
{
    return ((x%modulo)*(P(y,modulo-2LL,modulo)%modulo))%modulo;
}
void vok()
{
    FAST
    FO
    FI
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    // #endif
}
int main()
{
    vok();
    int a,b,c,d;
    IN a>>b>>c>>d;
    int parity=0;
    while(a>0 && c>0)
    {
        if(parity)
        {
            a-=d;
        }
        else
        {
            c-=b;
        }
        parity^=1;
    }
    if(c<=0)
    {
        OUT "Yes"<<endl
    }
    else
    {
        OUT "No"<<endl
    }
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

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

string t = "AKIHABARA";

bool f(string s, string &u, int i) {
//    cerr << u << '\n';
    if (u.size() + (s.size() - i) > t.size()) return false;
    if (i == s.size() && t.size() == u.size()) {
        return u == t;
    }
    u += 'A';
    if (f(s, u, i)) return true;
    u.resize(u.size() - 1);
    if (i == s.size()) return false;
    u += s[i++];
    if (f(s, u, i)) return true;
    u.resize(u.size() - 1);
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    string s;
    cin >> s;
    string u;
    cout << (f(s, u, 0) ? "YES" : "NO") << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 256
/*
 * wafuIroha.cpp
 *
 *  Created on: 2020/02/23
 *      Author: black
 */
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;

void trace(int* intArray, int arraySize){
	cout << intArray[0];
	for (int i = 1; i < arraySize; ++i){
		cout << " " << intArray[i];
	}
	cout << "\n";
}

int main(){
	int n;
	cin >> n;
	int *a = new int[n];

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

	int flag = 1;
	int count = 0;
	int tmp;
	for (int i=0; flag; ++i){
		flag = 0;
		for (int j=0; j<n-i-1; ++j){
			if (a[j] > a[j+1]){
				tmp = a[j+1];
				a[j+1] = a[j];
				a[j] = tmp;
				count++;
				flag = 1;
			}
		}
	}
	trace(a, n);
	cout << count << endl;

	return 0;
}



Measured memory_bytes: 3080
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int a = 0;//aさんの位置
    int b = 0;//bさんの位置
    int c = 0;//cさんの位置
    int d = 0;//距離
    int value = 0;
    
    scanf("%d%d%d%d",&a,&b,&c,&d);

    //直接的な時の処理
    value = a - c;
    if(value < 0){
        value = value - value * 2;//符号反転処理
    }
    if(value <= d){//
        printf("Yes");
        return 0;
    }
    //間接的な時の処理
    value = a - b;
    if(value < 0){
        value = value - value * 2;//符号反転処理
    }
    if (value <= d) {
        //ここから先にbとcの距離を計算する処理をかく
        value = b - c;
        if(value < 0){
            value = value - value * 2;//符号反転処理
        }
        if (value <= d) {
            printf("Yes");
            return 0;
        }
    }

    printf("No");
    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAXN 2010
#define INF 1000000000
int n,ans=INF;
char a[MAXN],b[MAXN];
int st[MAXN],L[MAXN],R[MAXN];
bool cmpL(int x,int y)
{
	return L[x]<L[y];
}
bool cmpR(int x,int y)
{
	return R[x]<R[y];
}
int main()
{
	scanf("%s%s",a,b);
	n=strlen(a);
	bool f1=0,f2=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]=='1') f1=1;
		if(b[i]=='1') f2=1;
	}
	if(!f2)
	{
		if(!f1) printf("0\n");
		else printf("-1\n");
		return 0;
	}	
	for(int i=0;i<n;i++)
	{
		for(int j=i;b[j]=='0';j=(j-1+n)%n)
			L[i]++;
		for(int j=i;b[j]=='0';j=(j+1)%n)
			R[i]++;
	}
	for(int i=0;i<n;i++)
	{
		int tmp=0,mx=0,r=0;
		for(int j=0,k=i;j<n;k=(k+1)%n,j++)
		{
			if(b[j]==a[k]) continue;
			tmp++;
			if(L[k]>i) st[++r]=k;
		}
		sort(st+1,st+1+r,cmpL);
		for(int j=r;j;j--)
		{
			ans=min(ans,mx*2+i+tmp+(L[st[j]]-i)*2);
			mx=max(mx,R[st[j]]);
		}
		ans=min(ans,mx*2+i+tmp);
		tmp=0,mx=0,r=0;
		for(int j=0,k=(n-i)%n;j<n;k=(k+1)%n,j++)
		{
			if(b[j]==a[k]) continue;
			tmp++;
			if(R[k]>i) st[++r]=k;
		}
		sort(st+1,st+1+r,cmpR);
		for(int j=r;j;j--)
		{
			ans=min(ans,mx*2+i+tmp+(R[st[j]]-i)*2);
			mx=max(mx,L[st[j]]);
		}
		ans=min(ans,mx*2+i+tmp);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(9), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-9, PI = acos(-1);
const int N = 1e5 + 9, M = 5e2 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

vector<int> adj[N];
ll mem[N][2];

ll dfs(int node, int par, int color) {
  if(mem[node][color])
    return mem[node][color];
  ll ret = 1;
  for(int it: adj[node]) {
    if(it == par) continue;
    if(color)
      ret = (ret * dfs(it, node, 0)) % MOD;
    else
      ret = ( ((ret * dfs(it, node, 0)) % MOD) + ((ret * dfs(it, node, 1))% MOD) ) % MOD;
  }
  mem[node][color] = ret;
  return ret;
}

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  int n, u, v;
  cin >> n;
  for (int i = 1; i < n; ++i) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  cout << (dfs(1, -1, 0) + dfs(1, -1, 1)) % MOD;
  return 0;
}


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

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

    vector<int> odds;
    vector<int> evens;
    rep(i, 0, n)
        if (i % 2 == 0)
            evens.push_back(a[i]);
        else
            odds.push_back(a[i]);

    if (n % 2 == 1)
    {
        reverse(evens.begin(), evens.end());
        rep(i, 0, evens.size())
            cout << evens[i] << ' ';
        rep(i, 0, odds.size())
            cout << odds[i] << ' ';
    }
    else
    {
        reverse(odds.begin(), odds.end());
        rep(i, 0, odds.size())
            cout << odds[i] << ' ';
        rep(i, 0, evens.size())
            cout << evens[i] << ' ';
    }
    cout << endl;
    return 0;
}

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

int main()
{
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = a; i <= b; i++) {
		if (i < a + k || i > b - k) {
			cout << i << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
grid = []
for _ in range(h):
    grid.append(list(input()))
res = 0
for i in range(h):
    for j in range(w):
        if grid[i][j] != '.':
            continue
        visited = [[False for _ in range(w)] for _ in range(h)]
        visited[i][j] = True
        queue = [(i, j, 0)]
        while queue:
            c_i, c_j, level = queue.pop(0)
#             visited.append((c_i, c_j))
            for n_i, n_j in ((c_i - 1, c_j), (c_i + 1, c_j), (c_i, c_j - 1), (c_i, c_j + 1)):
                if 0 <= n_i < h and 0 <= n_j < w and grid[n_i][n_j] == '.' and visited[n_i][n_j] == False:
                    queue.append((n_i, n_j, level + 1))
                    visited[n_i][n_j] = True
        res = max(res, level)
print(res)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (ll i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (ll i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;

template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (int i = 0; i < v.size(); ++i)
    {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    for (int i = 0; i < v.size() - 1; ++i)
    {
        os << v[i] << " ";
    }
    if (v.size() > 0)
    {
        os << v[v.size() - 1] << endl;
    }
    return os;
}

int main()
{
    int n;
    cin >> n;
    long long ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        if (i % 3 != 0 && i % 5 != 0){
            ans += i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  vector<int> vec;
  string s;
    cin >> s;
      for(int i=0; i<s.size();i++){
        if(s[i]=='0') vec.push_back(0);
        else if(s[i] == '1') vec.push_back(1);
        else if(vec.empty()) continue;
        else  vec.pop_back() ;
      }
      for(int i=0; i<vec.size(); i++) cout << vec[i];
      cout << endl;
}

Measured memory_bytes: 256
N = gets.to_i
ss = []
N.times do |i|
    ss[i] = gets.to_i
end

ss.sort!

sum = ss.inject(:+)

if sum % 10 != 0
    puts sum
    exit
else
    ss.each do |s|
        if s % 10 != 0
            puts sum - s
            exit
        end
    end
end

puts 0

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+20;
int n,m;
vector<int> e[N];
int q[N],f,r; //deque,保存起点和终点 
int vis[N];
int check(int u)
{
	for(int i=0;i<e[u].size();i++)
	{
		int v=e[u][i];
		if(!vis[v])
			return v;//更改v作为起点 
	}
	return -1;	
}
int main()
{
	while(cin>>n>>m)
	{
		bool flag=true;//first
		for(int i=1;i<=n;i++)
			e[i].clear(),vis[i]=0;
		int u,v;
		f=1e5;//
		r=1e5+1;
		while(m--)
		{
			scanf("%d%d",&u,&v);
			e[u].push_back(v);
			e[v].push_back(u);
			if(flag)
			{
				flag=false;
				vis[u]=vis[v]=1;
				q[f]=u;
				q[r]=v;		
			}
		}
	
		while(true)
		{
			int u=check(q[f]);
			if(u==-1)
				break;
			else
			{
				q[--f]=u;
				vis[u]=1;
			}
		}
		while(true)
		{
			int u=check(q[r]);
			if(u==-1)
				break;
			else
			{
				q[++r]=u;
				vis[u]=1;
			}
		}
		cout<<r-f+1<<endl;
		while(f<=r)
			printf("%d ",q[f++]);
		cout<<endl;	
	}
	return 0;
}

Measured memory_bytes: 9472
using System;

class Program
{
    static void Main()
    {
        string[] line;
        int m=0;
        int f=0;
        int r=0;
        char[] scoreList=new char[50];
        int counter=0;
        for (; ; )
        {
            line = Console.ReadLine().Split(' ');
            if (
                (m = int.Parse(line[0])) == -1 &
                (f = int.Parse(line[1])) == -1 &
                (r = int.Parse(line[2])) == -1
                )
                break;

            else if ((m + 1) * (f + 1) == 0)
            {
                scoreList[counter++] = 'F';
            }
            else if (m + f >= 80)
            {
                scoreList[counter++] = 'A';
            }

            else if (m + f >= 65)
            {
                scoreList[counter++] = 'B';
            }

            else if (m + f >= 50)
            {
                scoreList[counter++] = 'C';
            }

            else if (m + f >= 30)
            {
                if (r >= 50)
                {
                    scoreList[counter++] = 'C';
                }
                else
                {
                    scoreList[counter++] = 'D';
                }
            }

            else
            {
                scoreList[counter++] = 'F';
            }
        }

        for (var i = 0; i < counter; i++) Console.WriteLine(scoreList[i]);
    }
}


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

using namespace std;

typedef long long ll;

const int MAX_N = 1e5 + 5;

vector<int> out_adj [MAX_N];
vector<int> in_adj [MAX_N];

int color [MAX_N];

void dfs (int u, int c, vector<ll> &cnt, int &edgec, int &ok) {
  color[u] = c;
  cnt[c]++;
  
  for (int nxt : out_adj[u]) {
    edgec++;
    if (color[nxt] == -1) {
      dfs(nxt, (c + 1) % 3, cnt, edgec, ok);
    } else if (color[nxt] != (c + 1) % 3) {
      ok = 0;
    }
  }

  for (int prv : in_adj[u]) {
    if (color[prv] == -1) {
      dfs(prv, (c + 2) % 3, cnt, edgec, ok);
    } else if (color[prv] != (c + 2) % 3) {
      ok = 0;
    }
  }
}

typedef long long ll;

ll sq (ll x) {
  return x * x;
}

int main () {
  ios::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;

    out_adj[u].push_back(v);
    in_adj[v].push_back(u);
  }

  for (int i = 1; i <= n; i++) {
    color[i] = -1;
  }

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    if (color[i] == -1) {
      vector<ll> c (3, 0);
      int edgec = 0;
      int ok = 1;
      dfs(i, 0, c, edgec, ok);

      if (!ok) {
        ans += sq(c[0] + c[1] + c[2]);
      } else if (c[0] * c[1] * c[2] == 0) {
        ans += edgec;
      } else {
        ans += c[0] * c[1] + c[0] * c[2] + c[1] * c[2];
      }
    }
  }
  cout << ans << endl;
}


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

int main(){
  int N, M, Q;
  cin >> N >> M >> Q;
  vector<vector<int>> abcd(Q, vector<int>(4));
  for(int i = 0; i < Q; i++){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    abcd[i][0] = a-1;
    abcd[i][1] = b-1;
    abcd[i][2] = c;
    abcd[i][3] = d;
  }
  
  int summax = 0;
  
  for(int tmp = 0; tmp < (1 << 19); tmp++){
    bitset<20> s(tmp);
    if(s.count() == N+M-1)
      break;
    if(s.count() != M-1)
      continue;
    
    vector<int> A(0);
    int cnt = 1;
    for(int i = 0; i < N+M-1; i++){
      if(s[i] == 0)
        A.push_back(cnt);
      else
        cnt++;
    }
    
    int sum = 0;
    
    for(int i = 0; i < Q; i++){
      if(A[abcd[i][1]]-A[abcd[i][0]] == abcd[i][2])
        sum += abcd[i][3];
    }
    
    if(summax < sum)
      summax = sum;
    
  }
  
  cout << summax << endl;
  
  return 0;
  
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int tk[5]={5,7,5,7,7};

void solve(int n){
	string s;
	vi v(n);
	rep(i,n){
		cin>>s;
		v[i]=s.size();
	}
	rep(i,n-4){
		int pos=i;
		int ku=0;
		int wo=0;
		while(pos<n&&ku<5){
			wo+=v[pos];
			pos++;
			if(wo==tk[ku]){
				ku++;
				wo=0;
			}
			else if(wo>tk[ku])break;
		}
		if(ku==5){
			cout<<i+1<<endl;
			return;
		}
	}

}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	while(cin>>n,n)solve(n);
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;

int main(){
    int H, W; cin >> H >> W;
    int A, B; cin >> A >> B;
    vector<vector<int>> V(H, vector<int> (W));
    if(A == 0 || B == 0){
        if(A == 0){
            for(int i = 0; i < W; i++){
                for(int j =0 ; j < B; j++) V[j][i] = 1;
            }
        }
        else{
            for(int i = 0; i < H; i++){
                for(int j = 0; j < A; j++) V[i][j] = 1;
            }

        }

    }
    //else if(H *A != W*B) {cout << "No" << endl; return 0;}
    else {
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if(i == 0 || j == 0) V[i][j] = 1;
            }
        }
        V[0][0] = 0;
        for(int i = 0; i < A-1; i++){
            for(int j = 0; j < H; j++){
                V[j][W-1-i] = (V[j][W-1-i]+1)%2;
            }
        }

        for(int i = 0; i < B-1; i++){
            for(int j = 0; j < W; j++){
                V[H-1-i][j] = (V[H-1-i][j]+1)%2;
            }
        }
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++) cout << V[i][j];
    cout << endl;
    }
    //cout << "No" << endl;
}


Measured memory_bytes: 5248
program ordinary_beauty
  implicit none
  integer :: n, m, d
  real(8) :: p
  character(64) :: s
  read(*,*) n, m, d
  p = 0.d0
  if (d.eq.0) then
    p = real(m-1,8)/real(n,8)
  else
    p = 2.d0*real(m-1,8)*real(n-d,8)/(real(n,8)*real(n,8))
  end if
  write(s,'(f32.16)') p
  write(*,'(a)') trim(adjustl(s))
  return
end program ordinary_beauty

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-12)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}
ll gcd(ll a, ll b){
    if (b == 0) return a;
    return gcd(b, a % b);
}



int main() {
    ld x1, y1, x2, y2, x3, y3; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    ld a = (ld) pow( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2) , 0.5L );
    ld b = (ld) pow( ( x2 - x3 ) * ( x2 - x3 ) + ( y2 - y3 ) * ( y2 - y3) , 0.5L );
    ld c = (ld) pow( ( x3 - x1 ) * ( x3 - x1 ) + ( y3 - y1 ) * ( y3 - y1) , 0.5L );
    ld s = (ld) (a + b + c) / 2.0L;
    ld r = (ld) pow( s * (s - a) * (s - b) * (s - c), 0.5L ) / s;

    ld ma = INF; ld mi = 0.0L;
    while(ma - mi >  EPS) {
        ld mid = (ld) (ma + mi) / 2.0L;
        if( ( 1.0L - (mid / r) ) * max(a, max(b, c) ) > 2 * mid ) mi = mid;
        if( ( 1.0L - (mid / r) ) * max(a, max(b, c) ) < 2 * mid ) ma = mid;
    }
    cout << fixed << setprecision(10) << ma << endl;
    return 0;


}


Measured memory_bytes: 256
#include<iostream>
#define MAX 100000
using namespace std;

int A[MAX];
void update(int i, int x){
  A[i] = x;
}

void find(int s, int t){
  int min = A[s];
  for(int i=s+1; i<=t; i++){
    if(A[i] < min){
      min = A[i];
    }
  }
  cout << min << endl;
}

int main(){

  int n, q;
  cin >> n >> q;
  int com[q],x[q],y[q];
  for(int i=0; i<n; i++)A[i] = 2147483647;
  for(int i=0; i<q; i++)cin >> com[i] >> x[i] >> y[i];
  for(int i=0; i<q; i++){
    if(com[i] == 0)update(x[i],y[i]);
    else if(com[i] == 1)find(x[i],y[i]);
  }
  return 0;
}



Measured memory_bytes: 4624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		boolean[] tri = new boolean[1000001];
		for (int i = 1; i * (i + 1) / 2 <= 1000000; i++)
			tri[i * (i + 1) / 2] = true;
		loop: while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int[] a = new int[Math.max(n, 9000)];
			int sum = 0;
			for (int i = 1; i <= n; i++) {
				a[i] = scanner.nextInt();
				sum += a[i];
			}
			if (tri[sum]) {
				int res = 0;
				int R = n;
				while (res <= 10000) {
					if (slove(R, a)) {
						System.out.println(res);
						continue loop;
					}
					int L = 1;
					for (int i = 1; i <= R; i++) {
						if (a[i] == 1)
							continue;
						a[L++] = a[i] - 1;
					}
					a[L] = R;
					R = L;
					res++;
				}
			}
			System.out.println(-1);

		}
	}

	private boolean slove(int r, int[] a) {
		for (int i = 1; i <= r; i++)
			if (i != a[i])
				return false;
		return true;
	}
}

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

int main(){
  int N;cin >> N;
  ll W;cin >> W;
  ll w;cin >> w;
  vector<vector<ll>> V(4);
  ll v;cin >> v;
  V[0].push_back(v);
  for(int i=1;i<N;i++){
    ll wcur,vcur;
    cin >> wcur >> vcur;
    V[wcur-w].push_back(vcur);
  }
  for(int i=0;i<4;i++){
    sort(V[i].begin(),V[i].end());
    reverse(V[i].begin(),V[i].end());
    for(int j=1;j<V[i].size();j++){
      V[i][j] += V[i][j-1];
    }
  }
  ll Vmax = -1;
  for(ll i=0;i<=V[0].size();i++){
    for(ll j=0;j<=V[1].size();j++){
      for(ll k=0;k<=V[2].size();k++){
        for(ll l=0;l<=V[3].size();l++){
          if(w*(i+j+k+l)+j+2*k+3*l<=W){
            ll Vsum = 0;
            if(i>0){
              Vsum += V[0][i-1];
            }
            if(j>0){
              Vsum += V[1][j-1];
            }
            if(k>0){
              Vsum += V[2][k-1];
            }
            if(l>0){
              Vsum += V[3][l-1];
            }
            if(Vmax==-1){
              Vmax = Vsum;
            }else{
              Vmax = max(Vmax,Vsum);
            }
          }
        }
      }
    }
  }
  cout << Vmax << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using lint=long long;
using real=long double;
constexpr lint mod=1000000007;
struct mint{lint value;};
lint inverse(lint a){
    lint m=mod;
    lint u=0,v=1;
    while(a!=0){
        lint t=m/a;
        m-=t*a;std::swap(a,m);
        u-=t*v;std::swap(u,v);
    }
    assert(m==1);
    if(u<0)u+=mod;
    return u;
}
mint operator*(mint x,mint y){return mint{x.value*y.value%mod};}
mint&operator*=(mint&x,mint y){return x=mint{x.value*y.value%mod};}
mint operator/(mint x,mint y){return mint{x.value*inverse(y.value)%mod};}
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    std::vector<std::vector<lint>>g(n);
    for(lint i=0;i<n-1;i++){
        lint u,v;std::cin>>u>>v;u--,v--;
        g.at(u).push_back(v);
        g.at(v).push_back(u);
    }
    std::vector<lint>p(n,-1),ord;
    std::queue<lint>que;
    que.push(0);
    p.at(0)=0;
    while(!que.empty()){
        lint x=que.front();que.pop();
        ord.push_back(x);
        auto&&v=g.at(x);
        for(lint y:v){
            if(p.at(y)!=-1)continue;
            p.at(y)=x;
            que.push(y);
        }
        if(x)v.erase(std::find(v.begin(),v.end(),p.at(x)));
    }
    auto rord=std::vector<lint>(ord.rbegin(),ord.rend());
    std::vector<lint>sz(n,1);
    for(lint x:rord){
        for(lint y:g.at(x))sz.at(x)+=sz.at(y);
    }
    std::vector<mint>fact(n+1);fact.at(0)=mint{1};
    for(lint i=1;i<=n;i++)fact.at(i)=fact.at(i-1)*mint{i};
    std::vector<mint>dp(n),ep(n);ep.at(0)=mint{1};
    for(lint x:rord){
        dp.at(x)=fact.at(sz.at(x)-1);
        for(lint y:g.at(x)){
            dp.at(x)*=dp.at(y)/fact.at(sz.at(y));
        }
    }
    for(lint x:ord){
        for(lint y:g.at(x)){
            ep.at(y)=dp.at(x)*ep.at(x)*fact.at(n-sz.at(y)-1)*fact.at(sz.at(y))
                /(dp.at(y)*fact.at(sz.at(x)-1)*fact.at(n-sz.at(x)));
        }
    }
    for(lint i=0;i<n;i++){
        std::cout<<(dp.at(i)*ep.at(i)*fact.at(n-1)
            /(fact.at(sz.at(i)-1)*fact.at(n-sz.at(i)))).value<<'\n';
    }
}


Measured memory_bytes: 27504
# https://atcoder.jp/contests/abc056/tasks/arc070_a
x = int(input())

l = 0
r = x
ans = float('inf')
while l <= r:
    mid = (l + r) // 2
    if (mid + 1) * mid // 2 >= x:
        ans = min(ans, mid)
        r = mid - 1
    else:
        l = mid + 1
print(ans)

Measured memory_bytes: 38384
#include <iostream>

int f(int n, int a, int b) {
    int result = 0;
    for (int i = 1; i <= n; i++) {
        int x = i;
        int sum = 0;
        while (x > 0) {
            sum += x % 10;
            x /= 10;
        }
        if (sum >= a && sum <= b) {
            result += i;
        }
    }
    return result;
}

int main() {

    int n, a, b;
    std::cin >> n >> a >> b;

    int result = f(n, a, b);
    std::cout << result << std::endl;

    return 0;
}


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

using namespace std;
#define ll long long

const int N=1e6+100;

ll ma=1e18;


ll dp[3030][3030][4];
ll a[3030][3030];
void solve()
{
    int r,c,k;
    cin>>r>>c>>k;
    for(int i=1;i<=k;i++){
        int x,b,cc;
        cin>>x>>b>>cc;
        a[x][b]=cc;
    }

    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++){
            for(int rr=0;rr<=3;rr++){
                dp[i][j][0]=max(dp[i][j][0],max(dp[i-1][j][rr],dp[i][j-1][0]));
            }

            for(int rr=0;rr<=3;rr++){
                dp[i][j][1]=max(max(dp[i-1][j][rr]+a[i][j],dp[i][j][1]),max(dp[i][j-1][0]+a[i][j],dp[i][j-1][1]));
            }
            dp[i][j][2]=max(dp[i][j-1][1]+a[i][j],dp[i][j-1][2]);
            dp[i][j][3]=max(dp[i][j-1][2]+a[i][j],dp[i][j-1][3]);
        }
    }
    ll ans=0;
   // cout<<dp[3][3][0]<<endl;
    for(int i=0;i<=3;i++){
        ans=max(ans,dp[r][c][i]);
    }
    cout<<ans<<endl;
}
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 358652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

struct edge {
    int from;
    int to;
    long long cost;
    edge(int _from, int _to, long long _cost) : from(_from), to(_to), cost(_cost) {}
};

struct dsu {
    vector<int> p;
    vector<int> sz;
    int n;
    dsu(int _n)
        : n(_n) {
        p.resize(n);
        iota(p.begin(), p.end(), 0);
        sz.assign(n, 1);
    }

    inline int get(int x) {
        if (p[x] == x) {
            return x;
        } else {
            return p[x] = get(p[x]);
        }
    }
    inline bool unite(int x, int y) {
        x = get(x);
        y = get(y);
        if (x == y) {
            return false;
        }
        if (sz[x] < sz[y]) {
            swap(x, y);
        }
        p[x] = y;
        sz[y] += sz[x];
        return true;
    }
};

vector<int> min_span(vector<edge> edges, int n, long long &ans) {
    vector<int> order(edges.size());
    iota(order.begin(), order.end(), 0);
    sort(order.begin(), order.end(), [&](int a, int b) {
        return edges[a].cost < edges[b].cost;
    });
    vector<int> res;
    ans = 0;
    dsu d(n);
    for (int id : order) {
        edge e = edges[id];
        if (d.get(e.from) != d.get(e.to)) {
            d.unite(e.from, e.to);
            res.emplace_back(id);
            ans += e.cost;
        }
    }
    if ((int)res.size() != n) {
        return vector<int>();
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    vector<int> x(n), y(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        a[i] = make_pair(x[i], y[i]);
    }
    sort(x.begin(), x.end());
    x.erase(unique(x.begin(), x.end()), x.end());
    sort(y.begin(), y.end());
    y.erase(unique(y.begin(), y.end()), y.end());
    int s = x.size(), t = y.size();
    dsu uf(s + t);
    for (int i = 0; i < n; i++) {
        int b = lower_bound(x.begin(), x.end(), a[i].first) - x.begin();
        int c = lower_bound(y.begin(), y.end(), a[i].second) - y.begin();
        uf.unite(b, s + c);
    }
    int m = 0;
    map<int, int> mp;
    for (int i = 0; i < s + t; i++) {
        if (uf.get(i) == i) {
            mp[uf.get(i)] = m;
            m++;
        }
    }
    vector<edge> edges;
    for (int i = 1; i < s; i++) {
        int b = mp[uf.get(i - 1)], c = mp[uf.get(i)];
        if (b != c) {
            edges.emplace_back(b, c, x[i] - x[i - 1]);
        }
    }
    for (int i = 1; i < t; i++) {
        int b = mp[uf.get(s + i - 1)], c = mp[uf.get(s + i)];
        if (b != c) {
            edges.emplace_back(b, c, y[i] - y[i - 1]);
        }
    }
    debug(mp);
    debug(m, s, t);
    debug(x, y);
    for (auto e : edges) {
        debug(e.from, e.to, e.cost);
    }
    ll ans;
    min_span(edges, m, ans);
    debug(min_span(edges, m, ans));
    cout << ans << '\n';
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    double x;
    string u;
    double ans = 0;
    for (int i = 0; i < N; i++) {
        cin >> x >> u;
        if (u[0] == 'J') ans += x;
        else ans += x * 380000.0;
    }
    cout << fixed << setprecision(6) << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{

    int x;
    int y = 1;

    do {
    scanf("%d", &x);
    if (x > 0 || x < 0) {
        printf("Case %d: %d\n", y,  x);
        y++;
    }
    } while (x > 0 || x < 0);

    return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int MOD = ri();
	int dp[3 * n + 1][n + 1];
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	auto add = [&] (int &i, int j) {
		i += j;
		if (i >= MOD) i -= MOD;
	};
	for (int i = 0; i < 3 * n; i++) {
		for (int j = 0; j <= n; j++) {
			add(dp[i + 1][j], dp[i][j]);
			if (i + 1 < 3 * n && j < n) add(dp[i + 2][j + 1], (int64_t) dp[i][j] * (i + 1) % MOD);
			if (i + 2 < 3 * n && j < n) add(dp[i + 3][j + 1], (int64_t) dp[i][j] * (i + 1) % MOD * (i + 2) % MOD);
		}
	}
	int res = 0;
	for (auto i : dp[3 * n]) {
		res += i;
		if (res >= MOD) res -= MOD;
	}
	std::cout << res << std::endl;
	return 0;
}




Measured memory_bytes: 47104
using System;

namespace ALDS1_5_B_mergesort_
{
    class Program
    {
        static int count;


        static void Main(string[] args)
        {
           int n = getint(null);
            var S = getsplit();
            var A = Array.ConvertAll(S, int.Parse);
            mergesort(A, 0, n);
            for (int i = 0; i < n-1; i++)
            {
                Console.Write(A[i]+" ");
            }
            Console.WriteLine(A[n-1]);
            Console.WriteLine(count);
        }
        static void merge(int[] A,int left,int mid ,int right)
        {
            int n1 = mid - left;
            int n2 = right - mid;
            var L = new int[n1 + 1];
            var R = new int[n2 + 1];
            int i;
            for (i = 0; i < n1; i++)
            {
                L[i] = A[left + i];
            }
            for (i = 0; i < n2; i++)
            {
                R[i] = A[mid + i];
            }
            L[n1] = int.MaxValue;
            R[n2] = int.MaxValue;
            i = 0;
            int j = 0;
            for (int k = left; k < right; k++)
            {
                if (L[i]<=R[j])
                {
                    A[k] = L[i];
                    i = i + 1;
                }
                else
                {
                    A[k] = R[j];
                    j = j + 1;
                }
                count++;
            }
        } 
        static void mergesort(int[] A,int left,int right)
        {
            if (left+1<right)
            {
               int mid =(left + right) / 2;
                mergesort(A, left, mid);
                mergesort(A, mid, right);
                merge(A, left, mid, right);
            }
        }

        public static string[] getsplit()
        {
            string[] x = Console.ReadLine().Split(' ');
            return x;
        }
        public static int getint(string a)
        {
            if (a == null || a.Length == 0)
            {
                int x = int.Parse(Console.ReadLine());
                return x;
            }
            else
            {
                int x = int.Parse(a);
                return x;
            }
        }

    }
}

Measured memory_bytes: 70024
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define rep(i, f, n) for (int i = (f); i < (int)(n); i++)
#define repe(i, f, n) for (int i = (f); i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

const int INF = 1001001001;

int f(string s) {
  set<char> ss;
  for (auto c : s) ss.insert(c);
  return ss.size();
}

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

  int ans = 0;
  rep(i, 0, N) {
    rep(j, 1, N) {
      set<string> sx, sy;
      string x = S.substr(0, j);
      string y = S.substr(j, S.size());
      int cnt = 0;
      rep(k, 0, 26) {
        char c = 'a' + k;
        if (x.find_first_of(c) == string::npos ||
            y.find_first_of(c) == string::npos)
          continue;
        cnt++;
      }
      ans = max(ans, cnt);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3560
package main

import "fmt"

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	a := make([][]int, h)
	for i := 0; i < h; i++ {
		a[i] = make([]int, w)
		for j := 0; j < w; j++ {
			fmt.Scan(&a[i][j])
		}
	}

	op := make([][4]int, 0)
	for i := 0; i < h-1; i++ {
		for j := 0; j < w; j++ {
			if a[i][j]%2 == 0 {
				continue
			}
			a[i][j]--
			a[i+1][j]++
			op = append(op, [4]int{i, j, i + 1, j})
		}
	}

	for j := 0; j < w-1; j++ {
		i := h - 1
		if a[i][j]%2 == 0 {
			continue
		}
		a[i][j]--
		a[i][j+1]--
		op = append(op, [4]int{i, j, i, j + 1})
	}

	fmt.Println(len(op))
	for _, o := range op {
		fmt.Println(o[0]+1, o[1]+1, o[2]+1, o[3]+1)
	}
}


Measured memory_bytes: 23424
import math
n,k = map(int,input().split())
sum = 0

for i in range(1,n+1,1):
  if i < k:
    sum = sum + (1/2)**(math.ceil(math.log2(k/i)))
  else:
    sum = sum + 1
  
sum = sum * 1/n
print(sum)

Measured memory_bytes: 3060
n = int(input())
a = input().strip()
b = input().strip()
c = input().strip()
ans = 0
for _a, _b, _c in zip(a, b, c):
  if _a != _b and _b != _c and _a != _c:
    ans += 2
  elif _a == _b and _b == _c:
    continue
  else:
    ans += 1
print(ans)

Measured memory_bytes: 3064
n = int(input())
q = [("0",0)]
cnt = 0
while cnt < n - 1:
    qt = []
    for numset in q:
        num = numset[0]
        maxnum = numset[1]
        for i in range(int(maxnum) + 2):
            mx = max(maxnum,i)
            qt += [(num + str(i), mx)]
    q = qt.copy()
    cnt += 1
    
alp = "abcdefghijkl"
    
def show(num):
    ret = ""
    l = len(num)
    for i in range(l):
        ret += alp[int(num[i])]
    return ret

q.sort()

for num in q:
    print(show(num[0]))

Measured memory_bytes: 22524
#include<iostream>
using namespace std;
int main() {
    char p[27], number[27];
    cin >> p;
    for (int i = 0; i < 27; i++) {
        if (p[i] == '\0') {
            break;
        }
        for (int j = 0; j < i; j++) {
            if (p[i] == number[j]) {
                cout << "no" << endl;
                return 0;
            }
        }
        number[i] = p[i];
    }
    cout << "yes" << endl;
    return 0;
}

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

int main(){
  int64_t X,Y;
  cin>>X>>Y;

  int count=1;
  int64_t seq=X;
  while(seq<=Y){
    if(2*seq<=Y){
      ++count;
      seq=2*seq;
    }
    else{
      break;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

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

fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    let mut dp = vec![vec![-1; s.len() + 1]; 2];
    dp[0][0] = 1;
    dp[1][0] = 0;
    for i in 1..s.len() {
        if s[i] == s[i - 1] {
            if dp[1][i - 1] != -1 {
                dp[0][i] = dp[1][i - 1] + 1;
            }
        } else {
            dp[0][i] = max(dp[0][i - 1] + 1, dp[1][i - 1] + 1);
        }
        if i > 1 && dp[0][i - 2] != -1 {
            dp[1][i] = dp[0][i - 2] + 1;
        }
    }
    debug!(dp[0]);
    debug!(dp[1]);
    println!("{}", max(dp[0][s.len() - 1], dp[1][s.len() - 1]));
}

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()
}


Measured memory_bytes: 6396
package main

import "fmt"

func gcd(x, y int) int {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

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

	g := gcd(a, b)
	ans := make(map[int]bool)
	for i := 2; i*i <= g; i++ {
		for g%i == 0 {
			g /= i
			ans[i] = true
		}
	}
	if g > 1 {
		ans[g] = true
	}
	fmt.Println(len(ans) + 1)
}


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

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static int Solve(int N, int[] A)
        {
            int sum = A.Sum();
            var tuples = new Tuple<int, int>[N];
            for (int i = 0; i < N; ++i) { tuples[i] = new Tuple<int, int>(A[i], i); }
            return tuples.OrderBy(t => Math.Abs(t.Item1 * N - sum)).ThenBy(t => t.Item2).First().Item2;
        }

        static void Main(string[] args)
        {
            int N = ReadInt();
            int[] A = ReadInts();
            Console.WriteLine(Solve(N, A));
        }
    }
}


Measured memory_bytes: 13396