akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(i=0;i<n;++i)
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define mp make_pair
#define pb push_back
#define fi first
#define sc second

int n,s;

long dp[11][1025][500];
long rec(int now, int state, int sum)
{
	if(dp[now][state][sum]>=0) return dp[now][state][sum];

	long ret=0;
	if(now==n)
	{
		if(sum==s) ret=1;
	}
	else
	{
		for(int i=0; i<=9; ++i)
		{
			//??¢????????¨????????????????????§??????
			if(state>>i&1) continue;

			ret+=rec(now+1,state+(1<<i),sum+(now+1)*i);
		}
	}

	return dp[now][state][sum]=ret;
}

int main()
{
	while(scanf(" %d %d",&n,&s)!=EOF)
	{
		memset(dp,-1,sizeof(dp));
		printf("%ld\n",rec(0,0,0));
	}
}

Measured memory_bytes: 47148
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;

int main() {
	char s[7];
	scanf("%s", s + 1);
	sort(s + 1, s + 4 + 1);
	puts(s[1] == s[2] && s[3] == s[4] && s[1] != s[3] ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

long long nCkmod(long long n, long long k) {
    long long denomi = 1;
    REP(i, n) {
        denomi *= (i + 1);
        denomi %= mod;
    }
    long long numera = 1;
    for (int i = n - k; i > 0; i--) {
        numera *= i;
        numera %= mod;
    }
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
array<int, 101> factoring(int x) {
    array<int, 101> ret{};
    for (int i = 2; x >= i * i; i++) {
        while (x % i == 0) {
            ret[i]++;
            x /= i;
        }
    }
    if (x > 1) ret[x]++;
    return ret;
}

signed main() {
    int n;
    cin >> n;
    vector<int> as(n);
    REP(i, n) { cin >> as[i]; }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int com, b, e;
        cin >> com >> b >> e;
        if (com == 0) {
            cout << *min_element(as.begin() + b, as.begin() + e) << endl;
        } else {
            cout << *max_element(as.begin() + b, as.begin() + e) << endl;
        }
    }
}


Measured memory_bytes: 3144
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for(ll i = 0; i < n; ++i)
#define RANGE(i, x, n) for(ll i = x; i < n; ++i)

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll A, B;
    cin >> A >> B;
    vector<vector<char>> ans(100, vector<char>(100, '.'));
    ll cur_i = 0;
    for(ll i = 1; i < 100; i+=2) {
        for(ll j = 1; j < 100; j+=2) {
            if(B > 1) {
                ans[i][j] = '#';
                --B;
            }else {
                cur_i = i;
                goto t1;
            }
        }
    }
t1:
    for(ll i = cur_i+2; i < 100; ++i) {
        for(ll j = 0; j <100; ++j) {
            ans[i][j] = '#';
        }
    }
    for(ll i = cur_i+3; i < 100; i+=2) {
        for(ll j = 1; j < 100; j+=2) {
            if(A > 1) {
                ans[i][j] = '.';
                --A;
            }else {
                break;
            }
        }
    }
    cout << 100 << " " << 100 << endl;
    REP(i, 100) {
        REP(j, 100) {
            cout << ans[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>

int main(){
    int A,B,K;
    scanf("%d %d %d",&K,&A,&B);
    for(int i=A;i<=B;i++){
        if(i%K==0){printf("OK"); return 0;}
    }    
    printf("NG");
    return 0;
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////
int main(){
	ll n,m;
	cin >> n >> m;
	ll lim = sqrt(m)+1;
	ll M = 0;	
	int i = 1;
	while( n * i <= m && i < lim ){
		if( !(m % i) ){
			M = max( M , ll(i));
			if( m >= n*(m/i) ){
				M = max( M , m/i );
			}
		}
		i++;
	}
	cout << M << endl;
	ret 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
	int a,b;
	cin>>a>>b;
	cout<<max((a+b),max((a*b),(a-b)))<<endl;
	return 0;
}

Measured memory_bytes: 256
H, W, K = map(int, input().split())
S = [''] * H
for i in range(H):
	S[i] = input()
A = [[0] * W] * H
bg = 1
inflg = 0
outcnt = 1
for i in range(H):
	if '#' not in S[i]:
		if inflg == 0:
			outcnt += 1
		else:
			A[i] = A[i-1]
			print(" ".join(str(k) for k in A[i]))
	else:
		inflg += 1
		for j in range(S[i].find('#')):
			A[i][j] = bg
		for j in range(S[i].find('#'),W):
			if S[i][j] == '#':
				A[i][j] = bg
				bg += 1
			else:
				A[i][j] = A[i][j-1]
		if inflg == 1:
			for s in range(outcnt):
				print(" ".join(str(k) for k in A[i]))
		else:
			print(" ".join(str(k) for k in A[i]))


Measured memory_bytes: 3700
#include <vector>
#include <map>
#include <string>
#include <tuple>

using namespace std;

int N;
char S[50];

map<tuple<int, int, string>, long long> memo;
long long f(int L, int R, string s)
{
	if(s.size() > R-L) 	return 0;
	if(L==R) 			return s.empty();

	auto e = tuple<int, int, string>(L, R, s);
	if(memo.count(e)) 	return memo[e];

	long long v = 0;
	if(!s.empty())
	{
		if(S[L] == s.back())
			v += f(L+1, R, s.substr(0,s.size()-1));
		for(int i=L+1; i<R;++i)
			if(S[L] == S[i])
				v += f(L+1,i,string(S+i+1,S+R)+s);
	}
	else
	{
		for(int i=L+1; i<R;++i)
			if(S[L] == S[i])
				v += 2*f(L+1,i,string(S+i+1,S+R));
	}
	return memo[e]=v;
}


int main() {
	scanf("%d", &N);
	scanf("%s", S);
	printf("%lld\n", f(0,2*N,string()));
}

Measured memory_bytes: 256
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_variables)]

use proconio::{fastout, input};
use std::cmp::{max, min};

const INF: i32 = 1001001001;
const LNF: i64 = 1001001001001001001;
const MOD: u32 = 1000000007;

#[fastout]
fn main() {
  input! {
    n: usize,
    m: usize,
  }
  let mc = ModCalc::new(500000);
  let all = (mc.facc[m] / mc.facc[m - n]).pow(2);
  let mut acc = ModInt(0);
  for i in 1..(n + 1) {
    let a = mc.facc[m] / mc.facc[m - i];
    let b = (mc.facc[m - i] / mc.facc[m - n]).pow(2);
    if i % 2 == 1 {
      acc = acc + mc.com(n, i) * a * b;
    } else {
      acc = acc - mc.com(n, i) * a * b;
    }
  }
  let ans = all - acc;
  println!("{}", ans);
}

trait Monoid {
  fn one() -> Self;
}

trait Powerable: std::ops::Mul<Output = Self> + Monoid + Copy {
  fn pow(self, mut n: u64) -> Self {
    let mut r = Self::one();
    let mut x = self;
    while n > 0 { if n & 1 == 1 { r = r * x; } x = x * x; n >>= 1; }
    r
  }
}

#[derive(Clone, Copy)]
struct ModInt(u32);

impl Monoid for ModInt {
  fn one() -> Self { Self(1) }
}

impl Powerable for ModInt {}

impl std::fmt::Display for ModInt {
  fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {
    write!(f, "{}", self.0)
  }
}

impl std::ops::Add for ModInt {
  type Output = Self;
  fn add(self, rhs: Self) -> Self {
    let x = self.0 + rhs.0;
    Self(if x >= MOD { x - MOD } else { x })
  }
}

impl std::ops::Sub for ModInt {
  type Output = Self;
  fn sub(self, rhs: Self) -> Self {
    let x = self.0 + MOD - rhs.0;
    Self(if x >= MOD { x - MOD } else { x })
  }
}

impl std::ops::Mul for ModInt {
  type Output = Self;
  fn mul(self, rhs: Self) -> Self {
    let x = self.0 as u64 * rhs.0 as u64;
    Self(if x >= MOD as u64 { x % MOD as u64 } else { x } as u32)
  }
}

impl std::ops::Div for ModInt {
  type Output = Self;
  fn div(self, rhs: Self) -> Self {
    self * rhs.inv()
  }
}

impl ModInt {
  fn new(x: u32) -> Self {
    Self(x % MOD)
  }
  fn inv(self) -> Self {
    self.pow((MOD - 2) as u64)
  }
}

struct ModCalc {
  facc: Vec<ModInt>,
  finv: Vec<ModInt>,
}

impl ModCalc {
  fn new(n: usize) -> Self {
    let mut facc = vec![ModInt(0); n + 1];
    let mut finv = vec![ModInt(0); n + 1];
    facc[0] = ModInt::one();
    for i in 0..n {
      facc[i + 1] = facc[i] * ModInt((i + 1) as u32);
    }
    finv[n] = ModInt::one() / facc[n];
    for i in (0..n).rev() {
      finv[i] = finv[i + 1] * ModInt((i + 1) as u32);
    }
    ModCalc { facc, finv }
  }
  fn com(&self, a: usize, b: usize) -> ModInt {
    if b > a {
      return ModInt(0);
    }
    self.facc[a] * self.finv[a - b] * self.finv[b]
  }
}

Measured memory_bytes: 6044
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

string s;
int table1[] = { 2,1,0 };
int table2[3][3] = { { 0,1,2 },
					 { 1,1,2 },
					 { 2,2,2 } };
int table3[3][3] = { { 0,0,0 },
					 { 0,1,1 },
					 { 0,1,2 } };
int p, q, r;

int number(int &pos) {
	if (s[pos] == '0') {
		pos++;
		return 0;
	}
	if (s[pos] == '1') {
		pos++;
		return 1;
	}
	if (s[pos] == '2') {
		pos++;
		return 2;
	}
	if (s[pos] == 'P') {
		pos++;
		return p;
	}
	if (s[pos] == 'Q') {
		pos++;
		return q;
	}
	if (s[pos] == 'R') {
		pos++;
		return r;
	}
}

int formula(int &pos) {
	if (s[pos] == '-') {
		pos++;
		return table1[formula(pos)];
	}
	if (s[pos] == '(') {
		pos++;
		int res = formula(pos);
		if (s[pos] == '+') {
			pos++;
			res = table2[res][formula(pos)];
		}
		else if (s[pos] == '*') {
			pos++;
			res = table3[res][formula(pos)];
		}
		pos++;
		return res;
	}
	return number(pos);
}

int main() {
	while (cin >> s&&s != ".") {
		int ans = 0;
		rep(i, 3) {
			rep(j, 3) {
				rep(k, 3) {
					p = i;
					q = j;
					r = k;
					int pos = 0;
					if (formula(pos) == 2) {
						//cout << "!" << p << " " << q << " " << r << endl;
						ans++;
					}
				}
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3228
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int d[101][101];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	while(1){
		int n,m; cin >> n >> m;
		if(!n&&!m)break;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i!=j)d[i][j]=1e9;
			}
		}
		for(int i=0;i<m;i++){
			int t; cin >> t;
			if(!t){
				int x,y; cin >> x >> y;
				x--; y--;
				if(d[x][y]==1e9)printf("-1\n");
				else printf("%d\n",d[x][y]);
			}
			else{
				int x,y,z; cin >> x >> y >> z;
				x--; y--;
				for(int j=0;j<n;j++){
					for(int k=0;k<n;k++){
						d[j][k]=d[k][j]=min(d[j][k],z+min(d[j][x]+d[y][k],d[j][y]+d[k][x]));
					}
				}
			}
		}
	}
}


Measured memory_bytes: 3128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  int n = 0;
  cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  for(int i = 0;i < n;i++)cin >> x[i] >> y[i];
  int res = 0;
  map<pair<int,int>,int> count;
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      if(i == j)continue;
      count[make_pair(x[j] - x[i],y[i] - y[j])]++;
    }
  }
  for(auto& item:count)res = max(res,item.second);
  cout << n - res << endl;
  return 0;
}

Measured memory_bytes: 384
# -*- coding:utf-8 -*-
import math

N = int(input())
a = list(map(int,input().split()))

A,B =0,0

a.sort()

b = a[::-1]

S = math.floor(N/2)

if (N%2) == 0:
	for i in range (S):
		A = A + b[2*i]
		B = B + b[2*i+1]
else:
	for i in range (S):
		A = A + b[2*i]
		B = B + b[2*i+1]
	A = A + b[N-1]
print(A-B)


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

using namespace std;

#define pb push_back
#define mp make_pair
#define MOD ((int)(1e9) + 7)

const int N = ((int)8) + 1;

int n,m;
char g[N][N];
int cnt;


int main ()
{
	scanf("%d %d",&n,&m);
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			char c;
			scanf(" %c",&c);
			if (c == '#')
				cnt++;
		}
	}
	if (cnt == n + m - 1)
		return printf("Possible"),0;
	printf("Impossible");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main(){
	int n;
	while(cin >> n,n){
		set<int> s[50];
		vector<int> day[30];
		for(int i = 0;i < n;i++){
			int f;
			cin >> f;
			for(int j = 0;j < f;j++){
				int t;
				cin >> t;
				day[t - 1].push_back(i);
			}
		}
		int i = 0;
		for(;i < 30;i++){
			set<int> flag;
			for(int j = 0;j < day[i].size();j++) {
				flag.insert(day[i][j]);
				for(auto it = s[day[i][j]].begin();it != s[day[i][j]].end();it++){
					flag.insert(*it);
				}
			}
			for(int j = 0;j < day[i].size();j++) {
				s[day[i][j]] = flag;
			}
			if(flag.size() == n) {
				cout << i + 1 << endl;
				break;
			}
		}
		if(i == 30) cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3236
#include <iostream>

using namespace std;

int main(){
  string ans = "";
  string s;
  long long k;
  cin >> s;
  cin >> k;
  for(int i=0;i<(int)s.size();i++){
    int ind = s[i]-'a';
    if(k >= 26-ind && ind != 0 && i != (int)s.size()-1){
      k -= 26-ind;
      ans += 'a';
    }else if(i != (int)s.size()-1){
      ans += s[i];
    }else{
      char a = 'a' + (s[i]-'a'+k)%26;
      ans += a;
    }
  }
  cout << ans << endl;
  return 0;
}


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


int main(){
    string s,t;
    cin >> s >> t;
    int answer = 0;
    for(int i = 0; i < s.size(); i++){
        if(s.at(i) == t.at(i)){
            answer++;
        }
    }
    
    cout << answer << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

  ll h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, 0, h) cin >> s[i];

  vector<vector<bool>> black(h, vector<bool>(w, false));
  rep(i, 0, h){
    rep(j, 0, w){
      if(s[i][j] == '.') continue;
      if(i != 0 && s[i-1][j] == '#') black[i-1][j] = true, black[i][j] = true;
      if(i != h-1 && s[i+1][j] == '#') black[i+1][j] = true, black[i][j] = true;
      if(j != 0 && s[i][j-1] == '#') black[i][j-1] = true, black[i][j] = true;
      if(j != w-1 && s[i][j+1] == '#') black[i][j+1] = true, black[i][j] = true;
    }
  }

  rep(i, 0, h){
    rep(j, 0, w){
      if(s[i][j] == '#' && black[i][j] == false){
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import deque
H, W = map(int, input().split())
C = [list(input()) for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]
Q = deque()
dist = [[99999]*W for i in range(H)]
for i in range(H):
  for j in range(W):
    if C[i][j] == "#":
      dist[i][j] = 0
      Q.append((i,j))

while Q:
  y,x = Q.popleft()
  for k in range(4):
    ny = y + Y[k]
    nx = x + X[k]
    if (0 <= nx < W) and (0 <= ny < H) and (C[ny][nx] == ".") and (dist[ny][nx] > dist[y][x]+1):
      Q.append((ny,nx))
      dist[ny][nx] = dist[y][x] + 1
ans = 0
for i in range(H):
  ans = max(ans,max(dist[i]))
print(ans)

Measured memory_bytes: 121564
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9+7

N = int(input())

memo = [{} for _ in range(N+1)]

def ok(last4):
    if "AGC" in last4 or "GAC" in last4 or "ACG" in last4 or last4 == "AGGC" or last4 == "ATGC" or last4 == "AGGC" or last4 == "AGTC":
        return False
    else:
        return True

def DFS(now,last3):
    if last3 in memo[now]:
        return memo[now][last3] 
    if now == N:
        return 1
    ret = 0
    for c in "AGCT":
        last4 = last3 + c
        if ok(last4):
            ret += DFS(now+1,last4[1:])
            ret %= MOD
    memo[now][last3] = ret
    return ret

print(DFS(0,"TTT"))

Measured memory_bytes: 75684
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int ok,a,b,c;
    cin>>a>>b>>c;
    if(1==a&&b==1){
        cout<<"Open"<<endl;
    }else if(0==a&&b==0&&c==1){
        cout<<"Open"<<endl;
    }else{
        cout<<"Close"<<endl;
    }
}



Measured memory_bytes: 3104
// Problem : Multiplication 3
// Contest : Virtual Judge - AtCoder
// URL : https://vjudge.net/problem/AtCoder-abc169_c
// Memory Limit : 1048 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")  // disable
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define lll __int128
#define lp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define vec(v, type, sz) vector<type> v(sz)
#define in(v) \
    for (auto &i : v) cin >> i
#define all(v) v.begin(), v.end()
#define prv(v)                         \
    for (auto i : v) cout << i << " "; \
    cout << "\n"
#define MOD 1000000007
#define INF 1000000000
#define INFL 1000000000000000000ll
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vii(v, n, m, val) vector<vector<int>> v(n, vector<int>(m, val))
#define viii(v, i, j, k, val)        \
    vector<vector<vector<int>>> v(i, \
                                  vector<vector<int>>(j, vector<int>(k, val)))
#define pii pair<int, int>
#define pb push_back
#define file_io                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define testcases \
    int tcc;      \
    cin >> tcc;   \
    for (int tc = 1; tc <= tcc; tc++)
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while (!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
    cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if (idx > 0)
        cerr << ", ";
    else
        cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss;
    ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef DB
#define debug(...) \
    debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
    fast_io;
    ll a; double b;ll c;
    cin>>a>>b;
    c=round(b*100);
    cout<<(a*c)/100;
    //ll a; ld b; cin>>a>>b;
    //cout<<(a*b);
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
const int N=510;
const int mod=1e9+7;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,x,C[N][N],cnt[N],f[N][N][N],pw[N][N],fac[N],ifac[N];

int qpow(int a,int b) {
	int ret=1;
	while(b) {
		if(b&1) ret=1ll*ret*a%mod;
		a=1ll*a*a%mod;b>>=1;
	}
	return ret;
}

int getC(int n,int m) {
	if(m<0||n<m) return 0;
	return C[n][m];
}

int main() {
	cin>>n>>x;
	for(int i=1;i<=n;i++) ++cnt[gi()];
	fac[0]=1;
	for(int i=1;i<N;i++) fac[i]=1ll*fac[i-1]*i%mod;
	ifac[N-1]=qpow(fac[N-1],mod-2);
	for(int i=N-1;i;i--) ifac[i-1]=1ll*ifac[i]*i%mod;
	//for(int i=0;i<N;i++) cerr<<fac[i]<<' '<<ifac[i]<<'\n';
	for(int i=0;i<N;i++) {
		C[i][0]=pw[i][0]=1;
		for(int j=1;j<=i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
		for(int j=1;j<N;j++) pw[i][j]=1ll*pw[i][j-1]*i%mod;
	}
	f[x+1][0][0]=1;
	for(int i=x;i;i--)
		for(int j=0;j<=x/i;j++)
			for(int k=0;k<=x;k++)
				for(int l=0;l<=j&&i*l<=k;l++)
					if(f[i+1][j-l][k-i*l]) f[i][j][k]=(f[i][j][k]+1ll*f[i+1][j-l][k-i*l]*ifac[l]%mod*pw[k-(i-1)*j][cnt[i]])%mod;
	int ans=0;
	for(int i=0;i<=x;i++) {
		for(int j=0;j<=x;j++) {
			ans=(ans+1ll*((x-j)&1?mod-1:1)*getC(x-j+1,i)%mod*fac[i]%mod*f[1][i][j])%mod;
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 513408
use proconio::{input, fastout};
use std::f64::consts::PI;

#[fastout]
fn main() {
    input!{
       a: f64,
       b: f64,
       h: f64,
       m: f64
    }

    let th = (h * 60.0 + m)/ 720.0 * 2.0 * PI;
    let tm = m/60.0 * 2.0 * PI;
    let xh = a * th.cos();
    let yh = a * th.sin();
    let xm = b * tm.cos();
    let ym = b * tm.sin();
    let dx = xh - xm;
    let dy = yh - ym;
    let ans = (dx * dx + dy * dy).sqrt();
    println!("{:.15}", ans);

}

Measured memory_bytes: 2924
#include <stdio.h>

int main (void) {
    int w, h, x, y, r;
    
    scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);

    if(((x-r)>=0)&&((y-r)>=0)&&((x+r)<=w)&&((y+r)<=h)) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    
    return 0;
}


Measured memory_bytes: 2108
#include<iostream>
using namespace std;
int main(){
    int a[1000000];
    int n;
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    int ans=0;
    bool flag=true;
    for(int i=0;i<20001;i++){
        for(int j=0;j<n;j++){
            if(flag==false)continue;
            if(a[j]%2){
                flag=false;
            }else a[j]/=2;
        }
            if(flag)ans=i+1;
    }
    cout<<ans<<endl;
}


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


using namespace std;


struct node {
	node *prnt, *left, *right;
	int key = -1;
};
int n;
node *nil = NULL, *root = NULL;


void Init() {
	nil = (node *)malloc(sizeof(node));
	nil->left = nil;
	nil->right = nil;
	nil->prnt = nil;

}

void preWark(node *me) {

	if (me == NULL) return;
	printf(" %d", me->key);
	preWark(me->left);
	preWark(me->right);
}


void inWark(node *me) {

	if (me == NULL) return;
	inWark(me->left);
	printf(" %d", me->key);
	inWark(me->right);
}



void insert(node *z) {
	node *y = NULL;
	node *x = root;

	while (x != NULL)
	{
		y = x;
		if (z->key < x->key) x = x->left;
		else x = x->right;
	}
	z->prnt = y;

	if (y == NULL) root = z;
	else if (z->key < y->key) y->left = z;
	else y->right = z;

}

bool findKey(node *me, int srch) {

	if (me == NULL) return false;
	else if (me->key == srch) return true;
	else
	{
		bool res;
		if (srch < me->key) res = findKey(me->left, srch);
		else res = findKey(me->right, srch);
		return res;
	}
}


int main() {

	int  key, srch;
	string ord;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> ord;

		if (ord[0] == 'i') {
			cin >> key;

			node *nd = new node;
			nd->key = key;
			nd->prnt = nd->left = nd->right = NULL;

			insert(nd);
		}
		else if (ord[0] == 'p') {
			inWark(root);
			printf("\n");
			preWark(root);
			printf("\n");
		}
		else if (ord[0] == 'f') {
			cin >> srch;
			if (findKey(root, srch)) printf("yes\n");
			else printf("no\n");

		}

	}
	return 0;
}




Measured memory_bytes: 21956
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
 
public class Main {
	
	public static void main(String[] args) throws IOException {
		try (Scanner sc = new Scanner(System.in)) {
			final int M = sc.nextInt();
			
			System.out.println(24 - M + 24);
		}
	}
 
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextInt();
			}
			return ret;
		}
 
		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextLong();
			}
			return ret;
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 21204
#include <stdio.h>

int main(void)
{
	int max[7];
	int min[7];
	int i;
	
	for (i = 0; i < 7; i++){
		scanf("%d %d", &max[i], &min[i]);
		if (min[i] < 0){
			min[i] *= -1;
			max[i] += min[i];
		}
		else {
			max[i] -= min[i];
		}
	}
	
	for (i = 0; i < 7; i++){
		printf("%d\n", max[i]);
	}
	
	return (0);
}

Measured memory_bytes: 600
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
const int inf=1e9+7;
const int mod=1e9+7;
using namespace std;
//
int main(){
	string S;
	cin>>S;
	int N=S.size();
	if(S[0]!='1'||S[N-1]!='0'){
		cout<<-1<<endl;
		return 0;
	}
	for(int i=0;i<N-1;i++){
		if(S[i]!=S[N-2-i]){
			cout<<-1<<endl;
			return 0;
		}
	}
	int roo=1;
	cout<<1<<" "<<2<<endl;
	for(int i=3;i<N+1;i++){
		cout<<roo<<" "<<i<<endl;
		if(S[i-2]=='1'){
			roo=i;
		}
	}
	return 0;
}


Measured memory_bytes: 1664
N = int(input())
P = [None] + [int(x) for x in input().split()]
id_list = [None] * (N+1)
for i,x in enumerate(P[1:],1):
    id_list[x] = i

# 左隣にあるインデックスを取得できるようにしておく
# Binary Iindex Treeを使うことで、区間[L,R]内での和をとれば[L,R]内のデータ件数を数えられる
class BIT:
    def __init__(self, n):
        # 要素数を与えてインスタンス化
        self.size = n
        self.tree = [0] * (n + 1) # index must be 1-origin

    def add(self, i, x=1):
        # add x(>= 1) to a_i
        while i <= self.size:
            self.tree[i] += x
            i += i&(-i) # i&(-i) = BITでのi番目の区間の長さ

    def sum(self, i):
        # sum of a_1, a_2, ... , a_i
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & (-i) # i&(-i) = BITでのi番目の区間の長さ
        return s

    def search(self, x):
        # 二分探索。a_1 + a_2 + ... + a_i >= xなる最小のインデックスi(>= 1)を返す
        i = 0
        s = 0
        step = 1<<(N.bit_length()-1) # the largest 2^k (= step) <= N
        while step:
            if i+step <= N and s + self.tree[i+step] < x:
                i += step
                s += self.tree[i]
            step >>= 1
        return i+1


def main():
    bit = BIT(N)
    ans = 0
    for x in range(N,0,-1):
        idx = id_list[x]
        L = bit.sum(idx) # 左にある既に書き込んだ数の個数
        bit.add(idx)
        R = N-x-L # 右にある既に書き込んだ数の個数
        ll = bit.search(L-1) if L >= 2 else 0
        l = bit.search(L) if L >= 1 else 0
        r = bit.search(L+2) if R >= 1 else N+1
        rr = bit.search(L+3) if R >= 2 else N+1
        coef = 0
        if l != 0:
            # [b,c]を含むようにする。(a,b) と(c,d)が自由
            coef += (l - ll) * (r - idx)
        if r != 0:
            # [c,d]を含むようにする。
            coef += (rr - r) * (idx - l)
        ans += x * coef
    print(ans)

main()


Measured memory_bytes: 61428
import java.util.Scanner;

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

		int n = Integer.parseInt(sc.next());
		double[] nums = new double[n];
		double d = 0;

		for (int i = 0; i < n; i++) {
			nums[i] = Double.parseDouble(sc.next());
		}

		for (int i = 0; i < n; i++) {
			d += 1.0 / nums[i];
		}

		System.out.println(1.0 / d);

	}
}


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

int main(){
    ll n;
    cin>>n;
    n--;
    ll m=n;
    ll k=1;
    while(m-powl(26,k)>=0){
        m-=powl(26,k);
        k++;
    }
    vector<int> p(10000000);
    for(int i=0;i<k-1;i++){
        p[i]=m%26;
        m/=26;
    }
    p[k-1]=m;
    for(int i=k-1;i>=0;i--){
        char c='a'+p[i];
        cout<<c;
    }
    cout<<endl;


}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  long long sum = 0;
  long long s = 0;
  for(int i = 0;i < n;i++){
    cin >> a[i];
    sum += a[i];
    if(i%2 == 0){
      s += a[i] * 2;
    }
  }
  vector<int> ret(n);
  ret[0] = s - sum;

  for(int i = 1;i < n;i++){
    ret[i] = a[i-1]*2 - ret[i-1];
  }
  
  for(int i = 0;i < n;i++){
    cout << ret[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 2048
#coding:utf-8
import collections

n = int(input())
s = [input() for _ in range(n)]
ans = []

c = collections.Counter(s)
count_max = max(c.values())
for key, num in c.items():
    if num == count_max:
        ans.append(key)

ans = sorted(ans)

for i in ans:
    print(i)



Measured memory_bytes: 35572
#include <stdio.h>
int main()
{
    char b;
    char ans[] = "ACGTTGCA";
    scanf("%c",&b);
    for(int i = 0; i < 4; i++){
        if(b == ans[i]){
            b = ans[i + 4];
            break;
        }
    }
    printf("%c\n",b);
    return 0;
}

Measured memory_bytes: 128
n=int(input())
s=input()
f=True
if n%2==1:
    print('No')
else:
    l=n//2
    for i in range(l):
        if not s[i]==s[i+l]:
            f=False
            break
    if f:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}


constexpr int contest_num {26};

void calc_satisfy(const vector<vector<ll>>& S, const vector<ll>& C, const vector<int>& order, const int& D) {
  ll answer {};
  vector<int> fin_day(contest_num, -1);
  rep(i, D) {
    answer += S[i][order[i]-1];
    fin_day[order[i]-1] = i;
    rep(j, contest_num) {
      answer -= C[j]*(i-fin_day[j]);
    }
    //cout << answer << '\n';
  }
  cout << answer << '\n';
  //return answer;
}

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

  int D;
  cin >> D;
  vector<ll> c(contest_num);
  rep(i, contest_num) cin >> c[i];
  vector<vector<ll>> s(D, vector<ll>(contest_num));
  rep(i, D) {
    rep(j, contest_num) {
      cin >> s[i][j];
    }
  }
  vector<int> order(D);
  rep(i, D) cin >> order[i];
  int M;
  cin >> M;
  vector<std::pair<int, int>> query(M);
  rep(i, M) cin >> query[i].first >> query[i].second;
  rep(i, M) {
    order[query[i].first-1] = query[i].second;
    calc_satisfy(s, c, order, D);
  }
  //rep(i, D) cout << order[i] << ' ';
  //calc_satisfy(s, c, order, D);
}


Measured memory_bytes: 3956
#include <iostream>
using namespace std;
int dx,dy,x,y,n,count;
int road[20][20];

void check(int i,int j){
	if(i>dx||j>dy)return;
	if(i==dx&&j==dy){
		count++;
		return;
	}
	if(road[i][j]==-1)return;
	check(i,j+1);
	check(i+1,j);
	return;
}



int main(){
	while(1){
		cin >>dx >>dy;
		if(dx==0&&dy==0)break;
		for(int i=1;i<=dx;i++){
			for(int j=1;j<=dy;j++){
				road[i][j]=0;
			}
		}
		cin >> n;
		for(int i=0;i<n;i++){
			cin >> x>>y;
			road[x][y]=-1;
		}
		count=0;
		check(1,1);
		cout << count<<endl;
	}
	return 0;
}

Measured memory_bytes: 3084
use utf8;
use warnings;
use strict;
use POSIX qw/floor/;
use List::Util qw/sum0 min/;
use feature qw/say/;

chomp(my $n = <>);
chomp(my $line = <>);
my @arr = split(/ /, $line);

my $x_min = floor(sum0(@arr) * (1/$n));
my $x_max = $x_min + 1;
my $ans_min = sum0(map {($_-$x_min) * ($_-$x_min)} @arr);
my $ans_max = sum0(map {($_-$x_max) * ($_-$x_max)} @arr);
say min($ans_min, $ans_max);

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

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n*2);
  ll total = 0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    a[n+i] = a[i];
    total += a[i];
  }

  vector<ll> sum(n*2+1,0);
  for(int i=0;i<2*n;i++)sum[i+1] = sum[i] + a[i];

  ll ans = 0;

  int l=0, r=0;
  while(l<n){
    while(r<l+n-1 && 3*(sum[r]-sum[l])<=total)r++; r--;
    //cout << l << " " << r << endl;
    if(r-l>1){
      ll cur = sum[r]-sum[l], rem = total-cur;
      int L=r, R=l+n;
      while(R-L>1){
	ll M = (L+R)/2;
	if(2*(sum[M]-sum[r])<rem)L = M;
	else R = M;
      }

      ll minv = 0;
      if(R<l+n && r<R)minv = max(minv, min(sum[R]-sum[r], sum[l+n]-sum[R]));
      if(R-1<l+n && r<R-1)minv = max(minv, min(sum[R-1]-sum[r], sum[l+n]-sum[R-1]));
      //cout << cur << " " << minv << " " << R << " " << endl;
      minv = min(minv, cur);
      ans = max(ans, minv);
    }
    l++; if(r<l)r++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 4172
#include <iostream>

using namespace std;

int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (0 <= (x - r) && 0 <= (y - r) && (x + r) <= W && (y + r) <= H)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

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

int S[1000],top=0;

void push(int);
int pop(void);

int main(){
  char cal[100];
  int i=0;
  int a,b;
  while(scanf("%s",cal)!=EOF){
    if(cal[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(cal[0]=='-'){
      a=pop();
      b=pop();
      push(b-a);
    }
    else if(cal[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }
  else{
    push(atoi(cal));
  }
  }
  printf("%d\n",pop());
  return 0;
}

void push(int x){
  S[++top]=x;
}
int pop(void){
  top--;
  return S[top+1];
}



Measured memory_bytes: 2108
import java.util.Scanner;

public class Main {

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

	    int n=gi();
	    int[] t= new int[n];
	    
	    int s=0;
	    for (int i=0; i<n;i++) {
	    	t[i]=gi();
	    	s+=t[i];
	    }
	    
	    int m= gi();
	    for (int i=0; i<m;i++) {
	    	int p =gi();
	    	int x= gi();
	    	System.out.println(s -t[p-1] + x);
	    }
        //System.out.println(e);
//        if (xo>w || yo>h) {
//        	System.out.print(0);
//        }else {
//        	System.out.print((h-yo)*(w-xo));
//        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
	
	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35852
n = int(input())


def make3board(x):
    # 3x3のクォリティー2の敷き詰め方
    # aab
    # d.b
    # dcc
    m = x // 3
    base = ["aab", "d.b", "dcc"]
    board = []
    for i in range(m):
        sl = "..." * i
        sr = "..." * (m - 1 - i)
        for bj in base:
            board.append(sl + bj + sr)
    return board


def make4board(x):
    # 4x4のクォリティー3の敷き詰め方
    # aagh
    # bbgh
    # cdee
    # cdff
    m = x // 4
    base = ["aagh", "bbgh", "cdee", "cdff"]
    board = []
    for i in range(m):
        sl = "...." * i
        sr = "...." * (m - 1 - i)
        for bj in base:
            board.append(sl + bj + sr)
    return board


def make5board(x):
    # 5x5のクォリティー3の敷き詰め方
    # aadde
    # bbg.e
    # ccgff
    # ..abc
    # ..abc
    m = x // 5
    base = ["aadde", "bbg.e", "ccgff", "..abc", "..abc"]
    board = []
    for i in range(m):
        sl = "....." * i
        sr = "....." * (m - 1 - i)
        for bj in base:
            board.append(sl + bj + sr)
    return board


def make7board(x):
    # 7x7のクォリティー3の敷き詰め方
    # aabbcc.
    # dd.dd.c
    # ..d..dc
    # ..d..db
    # dd.dd.b
    # ..d..da
    # ..d..da
    m = x // 7
    base = [
        "aabbcc.", "dd.dd.c", "..d..dc", "..d..db", "dd.dd.b", "..d..da",
        "..d..da"
    ]
    return board


def concat_board(board1, board2):
    # クォリティーが同じ２つのboardを対角線上に配置して繋ぐ
    # A..
    # .BB
    # .BB
    x, y = len(board1), len(board2)
    board = []
    sr = '.' * y
    board += [board1[i] + sr for i in range(x)]
    sl = '.' * x
    board += [sl + board2[i] for i in range(y)]
    return board


board = []
if n % 3 == 0:
    board = make3board(n)
elif n % 4 == 0:
    board = make4board(n)
elif n % 5 == 0:
    board = make5board(n)
elif n == 7 or n == 11:
    board7 = [
        "aabbcc.", "dd.dd.c", "..d..dc", "..d..db", "dd.dd.b", "..d..da",
        "..d..da"
    ]
    board = concat_board(board7, make4board(n - 7))
else:
    for x in range(4, n, 4):
        y = n - x
        if y % 5 == 0:
            board = concat_board(make4board(x), make5board(y))
            break

if len(board) != 0:
    print(*board, sep='\n')
else:
    print(-1)


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

int main(){
    for(int m, nmn, nmx; cin>>m>>nmn>>nmx, m;){
        vector<int>vec(m);
        for(int i=0;i<m;i++)cin>>vec[i];
        vector<pair<int, int> >c;
        for(int n = nmn; n <= nmx; n++){
            c.push_back(pair<int, int>(vec[n-1]-vec[n], n));
        }
        sort(c.begin(), c.end());
        cout<<c[c.size()-1].second<<endl;
    }

    return 0;
}


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

int main()
{
  int *s,*t,n,q,i,j,count=0;
//入力処理//
  scanf("%d",&n);
  s=(int *)malloc(n*sizeof(int));
  for(i=0; i<n; i++)
  {
    scanf("%d",&s[i]);
  }
  scanf("%d",&q);
  t=(int *)malloc(q*sizeof(int));
  for(j=0; j<q; j++)
  {
    scanf("%d",&t[j]);
  }
//線形探索の実装//
  for(i=0; i<q; i++)
  {
    j=0;
    s[n-1]=t[i];
    while(s[j]!=t[i])
    {
      j++;
    }
    if(j!=n-1)count++;
  }

  printf("%d\n",count);

  return 0;
}



Measured memory_bytes: 2048
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		try {
			String packageName = new Main().getClass().getPackage().getName();
			System.setIn(new FileInputStream("src/" + packageName + "/input.txt"));
			// System.setOut(new PrintStream(new FileOutputStream("src/" + packageName + "/result.txt")));
		} catch (FileNotFoundException e) {
		} catch (NullPointerException e) {
		}
		new Main().run();
	}

	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	HashMap<String, Integer> c2i;
	Scanner sc;
	void run() {

		c2i = new HashMap<String, Integer>();
		String[] ss = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
		for (int i = 0; i < ss.length; i++)
			c2i.put(ss[i], i);

		sc = new Scanner(System.in);
		int T = sc.nextInt();
		while (T -- > 0) solve();
	}
	void solve() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] T = new int[n];
		int[] S = new int[m];
		for (int i = 0; i < n; i++) T[i] = c2i.get(sc.next());
		for (int i = 0; i < m; i++) S[i] = c2i.get(sc.next());

		boolean ok = false;
		{
			int t = n - 1, s = m - 1;
			while (true) {
				if (t < 0 || t >= n || s < 0) {
					break;
				} else if (T[t] == S[s]) {
					t--;
					s--;
				} else if (T[t] - S[s] == 1 || T[t] - S[s] == -11) {
					t++;
					s--;
				} else if (T[t] - S[s] == -1 || T[t] - S[s] == 11) {
					t -= 2;
					s--;
				} else {
					break;
				}
			}
			if (t == -1 && s == -1) ok = true;
		}
		{
			int t = n - 2, s = m - 1;
			while (true) {
				if (t < 0 || t >= n || s < 0) {
					break;
				} else if (T[t] == S[s]) {
					t--;
					s--;
				} else if (T[t] - S[s] == 1 || T[t] - S[s] == -11) {
					t++;
					s--;
				} else if (T[t] - S[s] == -1 || T[t] - S[s] == 11) {
					t -= 2;
					s--;
				} else {
					break;
				}
			}
			if (t == -1 && s == -1) ok = true;
		}

		System.out.println(ok ? "Yes":"No");
	}
}

Measured memory_bytes: 15000
import sys


def solve(g,  y,  m,  d):
    y = int(y)
    m = int(m)
    d = int(d)

    if y == 31 and m >= 5:
        print('?', y-30, m, d)
    elif y >= 32:
        print('?', y-30, m, d)
    else:
        print(g, y, m, d)


while True:
    s = input()
    if s == "#":
        break
    solve(*map(str,  s.split()))



Measured memory_bytes: 5600
#include"stdio.h"
#include"iostream"
using namespace std;
int a[100005],n,x,i,ans=0;
int main(){
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&x);
        if(x>n) ans++;
        else a[x]++;
    }
    for(i=1;i<=n;i++){
        if(a[i]==0) continue;
        if(a[i]<i) ans+=a[i];
        else if(a[i]>i) ans=ans+a[i]-i;
    }
    printf("%d",ans);
    return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

vector<ll> ans;
vector<ll> cnt;
Graph graph;

void dfs(ll v, ll prev, ll plus) {
    ll c = cnt[v] + plus;
    ans[v] = c;
    for (auto u : graph[v]) {
        if (u != prev) {
            dfs(u, v, c);
        }
    }
}

void solve() {
    ll N, Q;
    cin >> N >> Q;
    ans.resize(N, 0);
    cnt.resize(N, 0);
    graph.resize(N);
    rep(i, N - 1) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    rep(i, Q) {
        ll p, x;
        cin >> p >> x;
        p--;
        cnt[p] += x;
    }
    dfs(0, -1, 0);
    rep(i, N) {
        cout << ans[i] << ' ';
    }
    cout << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 25856
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<unordered_map>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int, int>pii;
const int inf = 0x7fffffff;
const int maxn = 5005;
stack<int>s;


int main()
{
	int cnt = 0;
	int n;
	int t;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> t;
		if (s.empty() || t <= s.top()) {
			cnt++;
			s.push(t);
		}
	}
	cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 1024
//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007
#define pb push_back

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
int main() {
	lli n; cin >> n;

	lli ans = 1;

	for (int i = 1; i <= n; i++) {
		ans *= i;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}





Measured memory_bytes: 256
#include<set>
#include<map>
#include<iostream>
using namespace std;
map<string,int> cnt;
int main()
{
	int n;cin>>n;
	int maxi = 0;
	for(int i=1;i<=n;i++){
		string x;cin>>x;
		cnt[x]++;
		maxi = max(maxi,cnt[x]);
	}
	map<string,int> :: iterator it;
	for(it=cnt.begin();it!=cnt.end();it++){
		if((*it).second==maxi){
			cout << (*it).first << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 25216