akhauriyash/Code-Regression huggingface dataset:
from pprint import pprint
from bisect import bisect_left
import numpy


def read():
    X, Y, A, B, C = list(map(int, input().strip().split()))
    P = list(map(int, input().strip().split()))
    Q = list(map(int, input().strip().split()))
    R = list(map(int, input().strip().split()))
    return X, Y, A, B, C, P, Q, R

def argsort(x, reverse=False):
    return sorted(range(len(x)), key=lambda k: x[k], reverse=reverse)

def solve(X, Y, A, B, C, P, Q, R):
    P = list(sorted(P, reverse=True))
    Q = list(sorted(Q, reverse=True))
    R = list(sorted(R, reverse=True))

    i = X
    j = Y
    score = sum(P[0:i]) + sum(Q[0:j])
    for r in R:
        if i > 0 and j > 0:
            if P[i-1] < Q[j-1] and P[i-1] < r:
                score = score - P[i-1] + r
                i -= 1
            elif Q[j-1] <= P[i-1] and Q[j-1] < r:
                score = score - Q[j-1] + r
                j -= 1
            else:
                break
        elif i > 0:
            if P[i-1] < r:
                score = score - P[i-1] + r
                i -= 1
            else:
                break
        elif j > 0:
            if Q[j-1] < r:
                score = score - Q[j-1] + r
                j -= 1
            else:
                break
        else:
            break
    return sum(P[:i] + Q[:j] + R[:(X-i)+(Y-j)])

if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))


Measured memory_bytes: 31484
use std::io;
fn main() {
    let mut l1 = String::new();
    let stdin = io::stdin();
    stdin.read_line(&mut l1).unwrap();
    let mut iter = l1.split_whitespace();
    let mut v1: i32 = iter.next().unwrap().parse().unwrap();
    let v2: i32 = iter.next().unwrap().parse().unwrap();
    let mut count = 0;
    loop {
        if v1 < v2 {
            break;
        }
        v1 = v1 / v2;
        count += 1;
    }
    count += 1;
    println!("{}", count);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sort(a) sort(all(a))
#define ff first
#define ss second
#define vi vector<int>
#define pii pair<int, int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define mod (int)1e9+7
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define repf(i,a,b) for(i=a;i<b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define N 100005
int main()
{
	FAST
    int t=1;
//    cin>>t;
    while(t--)
    {
		ll n,q,i;
		cin>>n;
		vll a(n);
		map<ll,ll>mpp;
		ll sum=0;
		repf(i,0,n) 
		{
			cin>>a[i];
			mpp[a[i]]++;
			sum+=a[i];
		}
		cin>>q;
		while(q--)
		{
			ll x,y;
			cin>>x>>y;
			ll cnt=mpp[x];
			sum-=(x*mpp[x]);
			mpp[x]=0;
			mpp[y]+=cnt;
			sum+=(y*cnt);
			cout<<sum<<endl;
		}
    }
    return 0;
} 


Measured memory_bytes: 10044
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long N,T;
  long long t[N];
  cin >> N >> T;
  for(int i=0; i<N; i++){
    cin >> t[i];
  }
  long long ans = 0;
  for(int i=0; i<N-1; i++){
    if(t[i+1] - t[i] < T){
      ans += t[i+1] - t[i];
    }else{
      ans += T;
    }
  }
  cout << ans + T << endl;
  return 0;
}

Measured memory_bytes: 3072
#include <stdio.h>


int n,boxA[20],boxM[200];
int solve(int,int);
int main(){

  int i,q;

    scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&boxA[i]);
  }

  scanf("%d",&q);

  for(i=0;i<q;i++){
    scanf("%d",&boxM[i]);
    if((solve(0,boxM[i]))==1) printf("yes\n");
    else printf("no\n");
 }




  return 0;
}



/*make_combination()
for(i=0;i<n;i++){
  S[i]=0; //iを選択しない
  rec(0);

  rec(i)
    if(i==n){
      printf("%s",S);
      return }

  rec(i+1);
  S[i]=1 //iを選択する
    rec(i+1);
  S[i]=0 //i1を選択しない
*/
int solve(int i,int m){
  int res;
  if(m==0){
    return 1;
  }
  if(i>=n){
    return 0;
  }
  res = solve(i+1,m) || solve(i+1,m-boxA[i]);

  return res;

}



Measured memory_bytes: 2044
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <string>
#include <cctype>
#include <vector>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=60;
const int dx[]={0,-1,1,0};
const int dy[]={1,0,0,-1};
bool nt[N][N][4];
int dis[N][N];
int n,m,bx,by,ex,ey;
void bul(int x,int y,int m){
	if(m){
		nt[x-1][y][2] = 0;
		nt[x][y][1] = 0;
	}
	else{
		nt[x][y-1][0] = 0;
		nt[x][y][3] = 0;
	}
}
void reb(int x,int y,int m){
	if(m){
		nt[x-1][y][2] = 1;
		nt[x][y][1] = 1;
	}
	else{
		nt[x][y-1][0] = 1;
		nt[x][y][3] = 1;
	}
}
int bfs(){
	if(bx == ex && by == ey) return 0;
	queue<int> q;
	int x,y,a,b;
	while(!q.empty()) q.pop();
	memset(dis,0,sizeof dis);
	q.push((bx<<10)|by);
	dis[bx][by] = 1;
	while(!q.empty()){
		int u=q.front();q.pop();
		x = u>>10;
		y = u&0xff;
		for(int i=0;i<4;i++)if(nt[x][y][i]){
			a = x+dx[i];
			b = y+dy[i];
			if(a == ex && b == ey) return dis[x][y];
			if(dis[a][b]) continue;
			dis[a][b] = dis[x][y] + 1;
			q.push((a<<10)|b);
		}
	}
	return -1;
}
int main() {
	//freopen("in.txt", "r", stdin);
	int k;
	while(~scanf("%d%d%d",&n,&m,&k)){
		memset(nt,1,sizeof nt);
		for(int i=0;i<n;i++){
			nt[i][0][3] = 0;
			nt[i][m-1][0] = 0;
		}
		for(int j=0;j<m;j++){
			nt[0][j][1] = 0;
			nt[n-1][j][2] = 0;
		}
		while(k--){
			scanf("%d%d%d%d",&bx,&by,&ex,&ey);
			if(bx == ex){
				if(by > ey) swap(by,ey);
				for(int j=by;j<ey;j++)
					bul(bx,j,1);
			}
			else{
				if(bx > ex) swap(bx,ex);
				for(int i=bx;i<ex;i++)
					bul(i,by,0);
			}
		}
		scanf("%d%d%d%d",&bx,&by,&ex,&ey);
		int ans=0,bg=bfs(),tmp;
		if(bg == -1){
			puts("0");
			continue;
		}
		for(int i=0;i<n;i++)
		for(int j=0;j<m;j++){
			if(nt[i][j][0]){
				bul(i,j+1,0);
				tmp = bfs();
				if(tmp - bg>ans)
					ans = tmp-bg;
				reb(i,j+1,0);
			}
			if(nt[i][j][2]){
				bul(i+1,j,1);
				tmp = bfs();
				if(tmp - bg>ans)
					ans = tmp-bg;
				reb(i+1,j,1);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1240
//start of jonathanirvings' template v3.0.3 (BETA)

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

int data[2][105];
int n;

int main()
{
  scanf("%d",&n);
  REP(i,2) REP(j,n) scanf("%d",&data[i][j]);
  int risan = 0;
  REP(j,n)
  {
    int now = 0;
    REP(i,n) if(i < j) now += data[0][i];
    else if (i == j) now += data[0][i] + data[1][i];
    else now += data[1][i];
    MAX(risan,now);
  }
  printf("%d\n",risan);
  return 0;
}











Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define sort(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
  int n, x;
  cin >> n >> x;
  vi child;
  int sum =0;
  for (int i = 0; i < n ; i++) {
    int a;
    cin >> a ;
    sum += a;
    child.pb(a);
  }
  sort(child);
  int ans = 0;
  int tmp = x;
  for(int i=0; i<n; i++) {
    if (tmp == 0) { break; }
    if (i < n-1) {
      if (child[i] <= tmp) {
        tmp -= child[i];
        ans++;
      }
    } else {
      if (tmp == child[i]) ans++;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int main(){
    char s[20]; scanf("%s", s + 1);
    int N = strlen(s + 1);
    int cnt = 0;
    for(int i = 1; i <= N; ++i){
        cnt += s[i] == 'o';
    }
    printf("%s", cnt + 15 - N >= 8 ? "YES" : "NO");
    return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  ll N;
  cin >> N;
  ll ans;
  ll sub;
  for(ll k = 1; k * k <= 3 * 1e7; k++){
    if(k * (k+1) / 2 >= N){
      ans = k;
      sub = k * (k+1) / 2 - N;
      break;
    }
  }

  for(ll i = 1; i <= ans; i++){
    if(i != sub){
      cout << i << endl;
    }
  }



  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include <random>
#define ll long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const int INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,k;
    cin>>n>>k;
    ll ans=k;
    rep(i,n-1){
        ans*=(k-1);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
int a[1000000];
bool tf[1000000];
void f(){
    for(int i = 0;i < 1000000;i++){
        tf[i] = true;
    }
    tf[0] = tf[1] = false;
    for(int i = 2;i < 1000000;i++){
        if(tf[i]){
            for(int j = 2 * i;j < 1000000;j += i){
                tf[j] = false;
            }
        }
    }
    int sum = 0;
    for(int i = 1;i < 1000000;i++){
        sum = (tf[i] == true)? sum + 1 : sum;
        a[i] = sum;
    }
}
int main(){
    f();
    int x;
    while(std::cin >> x){
        std::cout << a[x] << "\n";
    }
    return 0;
}


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

using namespace std;

int main (){
    int a, b;
    cin>>a>>b;
    if(b>=a)
        cout<<0<<endl;
    else{
        b = b*2;
        a = a-b;
        if(a>=0){
            cout<<a<<endl;
        }
        else cout<<0<<endl;
    }
    return 0;
}

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

int main() {
  int n, d, a;
  cin >> n >> d >> a;
  vector<pair<int, int>> v(n);
  for (int i = 0; i < n; i++) {
    int x, h;
    cin >> x >> h;
    v[i] = make_pair(x, h);
  }
  sort(v.begin(), v.end());

  auto f = [&](int l, int p) {
    int r = n;
    while (l < r) {
      int c = (l + r) / 2;
      if (v[c].first <= p)
        l = c + 1;
      else
        r = c;
    }
    return l;
  };

  long long ans = 0;
  int rdc = 0, lmt[n] = {};
  for (int i = 0; i < n; i++) {
    rdc -= lmt[i];
    if (v[i].second <= rdc) continue;
    int c = (v[i].second - rdc + a - 1) / a;
    ans += c;
    int dmg = a * c;
    rdc += dmg;
    int r = f(i, v[i].first+2*d);
    if (r < n) lmt[r] += dmg;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
import collections

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

c = collections.Counter(l)

col_tuple_list = c.most_common()

a = []

most_num = col_tuple_list[0][1]
for word_tuple in col_tuple_list:
    if most_num == word_tuple[1]:
        a.append(word_tuple[0])
    else:
        break
a = sorted(a)
for i in a:
    print(i)

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

#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define fi first
#define se second
#define ii pair<int, int>
#define pb push_back
#define mp make_pair

const int N = 8e5 + 10;
const int MOD = 1e9 + 7;
const int oo = 1e9;

int n, m, cnt;
int d[N];
vector<ii> vi[N];
map<ii, int> ma;

void addeg(int u, int v, int ci){
    vi[u].pb(ii(v, ci));
    vi[v].pb(ii(u, ci));
}

void Solve()    {
    FOR(i, 1, cnt) d[i] = oo;
    priority_queue< ii, vector<ii>, greater<ii> > pq;

    d[1] = 0; pq.push(ii(0, 1));

    while(!pq.empty())  {
        int u = pq.top().se, du = pq.top().fi;
        pq.pop();
        if(d[u] != du) continue;

        for(ii v: vi[u])    if(d[v.fi] > du + v.se) {
            d[v.fi] = du + v.se;
             pq.push(ii(du + v.se, v.fi));
        }
    }
    if(d[n] == oo) cout << "-1";
    else cout << d[n]/2;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    cnt = n;

    FOR(i, 1, m)    {
        int u, v, ci; cin >> u >> v >> ci;
        int nex = ma[ii(u, ci)];
        if(!nex)    {
            ma[ii(u, ci)] = nex = ++cnt;
        }

        int rev = ma[ii(v, ci)];
        if(!rev)    {
            ma[ii(v, ci)] = rev = ++cnt;
        }
        addeg(nex, rev, 0);
        addeg(nex, u, 1);
        addeg(rev, v, 1);
    }
    Solve();
}


Measured memory_bytes: 65276
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N; string S, T;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> S >> T;
	rep(i, 0, N) cout << S[i] << T[i];
	cout << endl;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x) cout<<#x<<" = "<<(x)<<endl;
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n; cin >> n;
  int l[n];
  REP(i,n) cin >> l[i];

  int maxl = 0,sum=0;
  REP(i,n) {
    maxl=max(maxl,l[i]);
    sum+=l[i];
  }
  Yes(maxl < sum-maxl);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int MOD = 1000000007;

int main() {
    string s;
    cin >> s;
    int N = s.size();
    ll dp[100010][4] = {};
    for(int i=N; i >= 0; --i){
        for(int j=3; j>=0; --j){
            if(i==N){
                dp[i][j] = (j == 3 ? 1: 0);
            }else{
                dp[i][j] = dp[i+1][j] * (s[i] == '?' ? 3LL : 1LL);
                if(j < 3 && (s[i] == '?' || s[i] == "ABC"[j])){
                    dp[i][j] += dp[i+1][j+1];
                }
                dp[i][j] %= MOD;
            }
        }
    }
    cout << dp[0][0] << endl;
    return 0;
}

Measured memory_bytes: 3584
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))

count = 0
for i in range(n):
    if a[i] < 0:
        a[i] = -a[i]
        count += 1

ans = sum(a)
if count % 2 == 0:
    print(ans)
else:
    print(ans - min(a) * 2)


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

ll gcd(ll m, ll n) {//最大公約数
    if (n == 0)return m;
    return gcd(n, m % n);
}//gcd

ll lcm(ll m, ll n) {//最小公倍数
    return m / gcd(m, n) * n;
}

int main(){
  int n; cin>>n;
  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
  }
  int ans=a[0];
  rep(i,n-1){
    ans=gcd(ans,a[i+1]);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000
int MOD=1000000007;
struct edge {
    int to, cost;
};

int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}

map<int,int> factor(int n){
  map<int,int>res;
  for(int i=2;i*i<=n;i++){
      for(; n%i==0;n/=i) res[i]++;
  }
  if(n>1)res[n]++;
  return res;
}
////////////////////////////////////////////////////////////
int n,m,q;
vector<int>h(11),a(51),b(51),c(51),d(51);
int ans=0;
void dfs(int pos,int last){
  if(pos==n){
    int t=0;
    rep(i,q){
    if(h[b[i]]-h[a[i]]==c[i])t+=d[i];
  }
  ans=max(t,ans);
  return;
}

  h[pos]=last;
  if(pos!=n-1){
    for(int i=last;i<=m;i++){
    dfs(pos+1,i);
  }
}
  else dfs(pos+1,last);

}


signed main() {
cin>>n>>m>>q;
rep(i,q){cin>>a[i]>>b[i]>>c[i]>>d[i];a[i]--;b[i]--;}
for(int i=1;i<=m;i++){
  dfs(0,i);
}
cout<<ans<<endl;
}


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

int main () {
  int A,B;
  cin >> A >> B;
  
  if(A%3==0||B%3==0||(A+B)%3==0){
    cout << "Possible";
  }
  else {
    cout << "Impossible";
  }
}

Measured memory_bytes: 256
N,M,C =map(int,input().split())
List=[[int(j) for j in input().split()] for i in range(N+1)]
ANS = 0

# B
for i in range(1,N+1):
    row_sum = 0
    for j in range(M):
        #print("A",List[i][j])
        row_sum += List[i][j] * List[0][j]
    #print(row_sum)
    if row_sum + C > 0:
        ANS +=1

print(ANS)

Measured memory_bytes: 3060
#include <stdio.h>

int A[1000000], n;

/* 二分探索 */
int binarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;
  while(left < right) {
    mid = (left + right) / 2;
    if(key == A[mid]) return 1; /* keyを発見 */
    if(key > A[mid]) left = mid + 1; /* 後半を探索 */
    else if(key < A[mid]) right = mid; /* 前半を探索 */
  }
  return 0;
}

int main(void) {
  int i, q, k, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++) {
    scanf("%d",&k);
    if(binarySearch(k))
      sum++;
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 2148
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int dy[]={-1,0,1,0},dx[]={0,-1,0,1};
int w,h;
char cl[50][51],cr[50][51];
bool v[2500][2500];

int main()
{
	while(scanf("%d%d",&w,&h),w)
	{
		rep(i,h)scanf("%s%s",cl[i],cr[i]);
		int ly,lx,ry,rx;
		rep(i,h)rep(j,w)
		{
			if(cl[i][j]=='L')ly=i,lx=j;
			if(cr[i][j]=='R')ry=i,rx=j;
		}
		rep(i,h*w)rep(j,h*w)v[i][j]=0;
		queue<int> Q;
		Q.push(ly*w+lx); Q.push(ry*w+rx);
		while(!Q.empty())
		{
			ly=Q.front()/w; lx=Q.front()%w; Q.pop();
			ry=Q.front()/w; rx=Q.front()%w; Q.pop();
			if(cl[ly][lx]=='%'&&cr[ry][rx]=='%')
			{
				puts("Yes"); goto END;
			}
			
			rep(d,4)
			{
				int lly=ly+dy[d],llx=lx+dx[d],rry=ry+dy[d],rrx=rx-dx[d];
				if(lly<0||lly>=h||llx<0||llx>=w||cl[lly][llx]=='#')lly=ly,llx=lx;
				if(rry<0||rry>=h||rrx<0||rrx>=w||cr[rry][rrx]=='#')rry=ry,rrx=rx;
				
				if(v[lly*w+llx][rry*w+rrx])continue;
				if((cl[lly][llx]=='%')^cr[rry][rrx]=='%')continue;
				v[lly*w+llx][rry*w+rrx]=1;
				Q.push(lly*w+llx); Q.push(rry*w+rrx);
			}
		}
		puts("No"); END:;
	}
	return 0;
}

Measured memory_bytes: 7456
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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;}

int main(){
  ll N,ans=1;
  string S;
  cin>>N>>S;
  
  ll C[26];
  REP(i,26) C[i]=1;
  
  REP(i,N){
    C[S.at(i)-'a']++;
  }
  
  REP(i,26){
    ans*=C[i];
    ans%=MOD;
  }
  
  co(ans-1);
  return 0;
}

Measured memory_bytes: 512
def gcd(x, y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)

a,b=map(int,input().split())

g=gcd(a,b)
t=1
ans=0
while t**2<=g:  #10**6
  if g%t==0:
    k=1
    for i in range(2,round(t**0.5)+1):  #10**3
      if t%i==0:
        k=0
        break
    if k:
      ans+=1
    #print(t)
  l=g//t
  if l!=t and g%l==0:
    k=1
    for i in range(2,round(l**0.5)+1):
      if l%i==0:
        k=0
        break
    if k:
      ans+=1
    #print(l)
  t+=1
print(ans)

Measured memory_bytes: 42716
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 1 ; i <= 50000 ; i++) {
            if (i * 108 / 100 == n) {
                System.out.println(i);
                return;
            }
        }
        System.out.println(":(");
    }

}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<endl
#define AA(i) cout<<i<<endl
const int U=2e5+5;
const ll MOD=998244353;
const int INF = 1001001001;

int main(){
    int N,R; cin>>N>>R;
    int ans;
    if(N<10) ans = R + 100 * ( 10 - N);
    else ans = R;
    AA(ans);
    return 0;
}

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

int main() {
    string s;
    getline(cin, s);
    
    string buf;
    vector<string> words;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != ' ' && s[i] != '.' && s[i] != ',') {
            buf.push_back(s[i]);
        } else {
            if (3 <= buf.size() && buf.size() <= 6) {
                words.push_back(buf);
            }
            buf.clear();
        }
    }
    cout << words[0];
    for (int i = 1; i < words.size(); i++) {
        cout << ' ' << words[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 0
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize,
        dv: [(usize, usize); n]
    };

    let mut c = 0;
    for (d1, d2) in dv {
        if d1 == d2 {
            c += 1;
        } else {
            c = 0;
        }
        if c == 3 {
            println!("Yes");
            return;
        }
    }
    println!("No");
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2216
#include<stdio.h>
#define _USE_MATH_DEFINES
#include<math.h>

int main(void)
{
	int i,n;
	double p1=0,p2=0,p3=0,p4=0,tmp,d1,d2,d3,d4;
	double strx[1001]={0,},stry[1001]={0,},strz[1001]={0,}; 
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%lf",&strx[i]);
	for(i=0;i<n;i++) scanf("%lf",&stry[i]);	
	for(i=0;i<n;i++){
		tmp=fabs(strx[i]-stry[i]);
		p1+=tmp;
		p2+=tmp*tmp;
		p3+=tmp*tmp*tmp;
		if(tmp>p4) p4=tmp;;
	}
	d1=p1;
	d2=sqrt(p2);
	d3=pow(p3,1.0/3.0);	
	d4=p4;

	printf("%lf\n%lf\n%lf\n%lf\n",d1,d2,d3,d4);

	return 0;   
}

Measured memory_bytes: 708
N, K  = map(int, input().split())
R, S, P  = map(int, input().split())
T = list(input())
Group = [[0]*0 for h in range(K)]
Ans = 0

for i in range(len(T)):
    L = i % K
    Group[L].append(T[i])

for i in range(K):
    A = Group[i][0]
    Bit = 0
    for j in range(len(Group[i])):
        if Group[i][j] == A and Bit == 0:
            Bit = 1
            A = Group[i][j]
            if Group[i][j] == "r":
                Ans += P
            elif Group[i][j] == "s":
                Ans += R
            else:
                Ans += S
        elif Group[i][j] == A and Bit == 1:
            Bit = 0
            A = Group[i][j]
        else :
            Bit = 1
            A = Group[i][j]
            if Group[i][j] == "r":
                Ans += P
            elif Group[i][j] == "s":
                Ans += R
            else:
                Ans += S
print(Ans)

Measured memory_bytes: 62600
#include <iostream>
using namespace std;
int main() 
{
	int S, h, m, s, amari;
	cin >> S;
	h = S / 3600;
	amari = S % 3600;
	m = amari / 60;
	s = amari % 60;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}


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

int main()
{
	int n, x, sum = 0, cnt = 1;
	vector<int> l;
	cin >> n >> x;
	l.resize(n);
	for (int i = 0; i < n; i++)
	{
		cin >> l[i];
	}
	for (int i = 0; i < n; i++)
	{
		sum += l[i];
		if (sum > x)
			break;
		cnt++;
		// cout << sum << endl;		
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    double[] x = new double[n];
    double[] y = new double[n];
    double minx = 1000;
    double maxx = 0;
    double miny = 1000;
    double maxy = 0;
    for(int i = 0; i < n; i++) {
      x[i] = sc.nextDouble();
      y[i] = sc.nextDouble();
      minx = Math.min(minx, x[i]);
      maxx = Math.max(maxx, x[i]);
      miny = Math.min(miny, y[i]);
      maxy = Math.max(maxy, y[i]);
    }
    double ansx = minx;
    double ansy = miny;
    
    double leftx = minx;
    double rightx = maxx;

    for(int i = 0; i < 50; i++) {
      double lx = (double)(2 * leftx + rightx) / (double)3;
      double rx = (double)(leftx + 2 * rightx) / (double)3;
      double flx = 0;
      double frx = 0;
      double lxy = 0;
      double rxy = 0;
      double lefty = miny;
      double righty = maxy;
      for(int j = 0; j < 50; j++) {
        double ly = (double)(2 * lefty + righty) / (double)3;
        double ry = (double)(lefty + 2 * righty) / (double)3;
        double t1 = 0;
        double t2 = 0;
        for(int k = 0; k < n; k++) {
          t1 = Math.max(t1, (lx - x[k]) * (lx - x[k]) + (ly - y[k]) * (ly - y[k]));
          t2 = Math.max(t2, (lx - x[k]) * (lx - x[k]) + (ry - y[k]) * (ry - y[k]));
        }
        if(t1 <= t2) {
          righty = ry;
          flx = t2;
          lxy = ry;
        } else {
          lefty = ly;
          flx = t1;
          lxy = ly;
        }
      }
      lefty = miny;
      righty = maxy;
      for(int j = 0; j < 50; j++) {
        double ly = (double)(2 * lefty + righty) / (double)3;
        double ry = (double)(lefty + 2 * righty) / (double)3;
        double t1 = 0;
        double t2 = 0;
        for(int k = 0; k < n; k++) {
          t1 = Math.max(t1, (rx - x[k]) * (rx - x[k]) + (ly - y[k]) * (ly - y[k]));
          t2 = Math.max(t2, (rx - x[k]) * (rx - x[k]) + (ry - y[k]) * (ry - y[k]));
        }
        if(t1 <= t2) {
          righty = ry;
          frx = t2;
          rxy = ry;
        } else {
          lefty = ly;
          frx = t1;
          rxy = ly;
        }                
      }      
      if(flx <= frx) {
        rightx = rx;
        ansx = rx;
        ansy = rxy;
      } else {
        leftx = lx;
        ansx = lx;
        ansy = lxy;
      }
    }

    double ans = 0;
    
    for(int i = 0; i < n; i++) {
      double t = (ansx - x[i]) * (ansx - x[i]) + (ansy - y[i]) * (ansy - y[i]);
      t = Math.sqrt(t);
      ans = Math.max(ans, t);
    }

    System.out.println(ans);
  }
}

Measured memory_bytes: 25172
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int N = 1e6 + 19, Mod = 1e9 + 7;
ll n;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    ll tot = 0;
    ll m = n - 1;
    for (ll i = 1; i * i <= m; i ++)
        if (m % i == 0)
        {
            if (i != 1)
                tot ++;
            if (m / i != i)
                tot ++;
        }
    vector < ll > A;
    for (ll i = 1; i * i <= n; i ++)
        if (n % i == 0)
        {
            A.push_back(i);
            if (n / i != i)
                A.push_back(n / i);
        }
    for (ll a : A)
    {
        if (a == 1)
            continue;
        ll tmp = n, c = 0;
        while (tmp % a == 0)
            tmp /= a, c = 1;
        if (c == 0)
            continue;
        if (tmp % a == 1)
            tot ++;
    }
    printf("%lld\n", tot);
    return 0;
}

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

using namespace std;
string s,t;
int i,ok;
int main()
{
    cin>>s>>t;
    ok=1;
    if(t.size()==s.size()+1)
    {
        for(i=0;i<s.size()&&ok;i++)
            if(s[i]!=t[i])
            ok=0;

    }
    if(ok)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ii pair <int , int>
#define is pair <int, string>
#define ll long long
#define mx 100000
#define sf scanf
#define sf(n) scanf("%d",&n)
#define pf printf
using namespace std;
vector <int> v;

/*int intConvert(string s){
    int n;
    stringstream geek(s);
    geek >> n;
    return n;
}*/

/*string strConvert(int n){
    string s;
    stringstream ss;
    ss << n;
    s=ss.str();
    return s;
}*/


int main(){
    int n,k;
    sf(n),sf(k);

    int cnt=0;
    while(n--){
        int a;
        sf(a);
        if(a>=k) cnt++;
    }
    pf("%d\n",cnt);


    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int prog[] = new int[n];
		for(int i = 0; i < n; i++) {
			prog[i] = sc.nextInt();
		}

		int q = sc.nextInt();
		for(int i = 0; i < q; i++) {
			int b = sc.nextInt();
			int e = sc.nextInt();
			int k = sc.nextInt();
			int count = 0;
			for(int j = b; j < e; j++) {
				if(prog[j] == k) count++;
			}
			System.out.println(count);
		}
	}

}




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

int main(){
   int a,b,c;
   cin >> a >> b >> c;

   if((a*100 + b * 10 + c) % 4 == 0 ) puts("YES");
   else puts("NO");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> dp(100010,-1),x(100010);
int n,k;

int ans(int curr){
    if(curr == n-1){
        return 0;
    }
    if(dp[curr] != -1){
        return dp[curr];
    }
    int ret = abs(x[curr]-x[curr+1]) + ans(curr+1);
    for(int i = 2 ; i <= k ; i += 1){
        if(curr + i == n){
            break;
        }
        ret = min(ret,abs(x[curr] - x[curr+i]) + ans(curr+i));
    }
    dp[curr] = ret;
    return ret;
}

int main()
{
    cin >> n >> k;
    for(int i = 0 ; i < n ; i += 1){
        cin >> x[i];
    }
    cout << ans(0);
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

bool ng(int a, int b, int c) {
  if (a + 2 == c && b + 1 == c) return false;
  if (a == b && b == c) return false;
  return true;
}

int main() {

  int n; cin >> n;
  while (n--) {
    vector<int> cs(9);
    rep (i, 9) cin >> cs[i];
    rep (i, 9) {
      char c; cin >> c;
      if (c == 'G') cs[i] += 10;
      if (c == 'B') cs[i] += 20;
    }

    vector<int> is(9);
    rep (i, 9) is[i] = i;
    do {
      bool bl = true;
      rep (k, 3) {
        if (ng (cs[is[3*k+0]], cs[is[3*k+1]], cs[is[3*k+2]])) bl = false;
      }
      if (bl) {
        cout << 1 << endl;
        goto more;
      }
    } while (next_permutation(all(is)));
    cout << 0 << endl;

more:;
  }

  return 0;
}

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

using namespace std;

#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define F(i,x,n,y) for(i=x;i<n;i+=y)
#define fi(i,x,n) for(i=x;i<n;++i)
#define f(n) for(int i=0;i<n;++i)
#define fr(i,x,n) for(i=x;i>=n;--i)
#define endl '\n'
#define int ll

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

int const tam=100005;
const int MOD=1000000007;
int inv[tam];
int fac[tam];
int finv[tam];
int is[tam];

void prec(){
    inv[1]=1;
    fac[0]=fac[1]=1;
    finv[1]=finv[0]=1;
    int i;
    fi(i,2,tam){
        //inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        inv[i]=(MOD-(MOD/i)*inv[MOD%i]%MOD)%MOD;
        fac[i]=fac[i-1]*i%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

int nck(int x,int y){
    if(y>x) return 0;
    int val= fac[x]*(finv[y]*finv[x-y]%MOD)%MOD;
    return val;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int a[tam];
    int l,r;
    f(n+1){
        cin>>a[i+1];
        if(is[a[i+1]]!=0){
            l=is[a[i+1]];
            r=i+1;
        }
        is[a[i+1]]=i+1;
    }
    prec();
//    make();
    f(n+1){
        auto ans=nck(n+1,i+1);
        ans-=nck(l+n-r,i);
        ans=(MOD+(ans%MOD))%MOD;
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 5120
use std::cmp::min;
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let (n,k) = {
        let t = read_vec::<i64>();
        (t[0],t[1])
    };
    let mut v:Vec<i64> = Vec::new();
    for _ in 0..n {
        v.push(read::<i64>());
    }
    v.sort();

    let ans = v.windows(k as usize).fold(1e10 as i64 ,|y,x|{
        let diff = x[(k-1) as usize] - x[0];
        min(diff,y)
    });
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;
 
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
    for (T &x : vec)
        is >> x;
    return is;
}

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

    int multicnt=0, halfcnt=0;
    if(k%2==0){
        FOR(i,1,n+1){
            if(i%k==0){
                multicnt++;
            }else if(i%k==k/2){
                halfcnt++;
            }
        }
    }else{
        FOR(i,1,n+1){
            if(i%k==0){
                multicnt++;
            }
        }
    }

    ll ans = pow(multicnt,3) + pow(halfcnt,3);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

signed main(){
    ll A, B, N;
    cin >> A >> B >> N;
    PRINT(A * min(N, (B - 1)) / B);
    return 0;
}

Measured memory_bytes: 3620
program all_green
  implicit none
  integer :: d, g, p(10), c(10)
  integer :: i, j, n, s, m(10), ubnd, t
  p = 0
  c = 0
  m = 0
  read(*,*) d, g
  g = g/100
  n = 0
  ubnd = 2**d
  do i = 1, d
    read(*,*) p(i), c(i)
    c(i) = c(i)/100
    n = n + p(i)
    m(i) = i*p(i)+c(i)
  end do
  do j = 0, ubnd-1
    s = 0
    t = 0
    do i = 1, d
      if (btest(j,i-1)) then
        s = s + m(i)
        t = t + p(i)
      end if
    end do
    if (s.lt.g) then
      do i = d, 1, -1
        if (.not.btest(j,i-1)) then
          if (s+i*(p(i)-1).ge.g) then
            t = t + ceiling(real(g-s,8)/real(i,8))
            if (t.lt.n) n = t
          end if
          exit
        end if
      end do
    else
      if (t.lt.n) n = t
    end if
  end do
  write(*,'(i0)') n
  stop
end program all_green

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n;
    cin >> n;

    vpair edge;
    rep(i, n) {
        srep(j, i+1, n) {
            int a = i+1;
            int b = j+1;
            if (n&1) {
                if (a+b == n) continue;
            }
            else {
                if (a+b == n+1) continue;
            }
            edge.emplace_back(a, b);        
        }
    }

    cout << edge.size() << endl;
    for (auto e : edge) {
        cout << e.fi << " " << e.se << endl;
    }
    return 0;
}

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

#define MAX 25
#define MOD 1000000007
#define EXP 1024*2048 + 10

using namespace std;
typedef long long int lli;

int n;

int v[MAX][MAX];
int dp[MAX][EXP];

int DP(int i, int mask)//já escolhi até o homem i - 1 e tenho essas mulheres sobrando
{
	if(dp[i][mask] != -1) return dp[i][mask];

	if(i == n - 1)
	{
		int women = log2( mask );

		return dp[i][mask] = v[i][women];
	}

	int aux = mask;

	lli ans = 0;

	while(aux > 0)
	{
		int last = aux & -aux;
		aux -= last;

		last = log2(last);

		if(v[i][last] == 0) continue;

		ans += DP(i + 1 , mask - (1 << last));
	}

	return dp[i][mask] = (ans%MOD);
}

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

	memset(dp , -1 , sizeof(dp));

	for(int g = 0 ; g < n ; g++)
		for(int h = 0 ; h < n ; h++)
			scanf("%d",&v[g][h]);

	printf("%d\n",DP(0 , (1 << n) - 1));
}

Measured memory_bytes: 205056
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
#define REP(i,x)for(__typeof(x) i=0;i<x;i++)

string res;
set<string> m;
int H,W,dx,dy,min_len;
char s[200];
string MAP[11];
bool visit[20][20];
void dfs(int x,int y,int k){
  if(k==min_len){
    if(m.count(string(s)))res=min(res,string(s));
    m.insert(string(s));
  }else if(k>min_len){
    if(m.count(string(s)))res=string(s),min_len=k;
    m.insert(string(s));
  }
  m.insert(string(s));
  if(visit[y][x])
    return;
  s[k]=MAP[y][x];  visit[y][x]=1;
  dfs((x + dx + W) % W, (y + dy + H) % H, k + 1);
  s[k]=0;  visit[y][x]=0;
}
int main() {
  while(cin>>H>>W,H){
    REP(i,H)cin>>MAP[i];
    m.clear();
    min_len=1; res="0";
    REP(y,H)REP(x,W){
      for(dx=-1;dx<=1;dx++){
        for(dy=-1;dy<=1;dy++){
          if(dx|dy)dfs(x,y,0);
        }
      }
    }
    cout<<res<<endl;
  }
}

Measured memory_bytes: 27192