akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import deque
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N = int(input())
L = [deque([]) for _ in range(N)]
ans = [-1] * N

for n in range(N-1):
    u, v, w = [int(x) for x in input().strip().split()]
    L[u-1].append((v, w))
    L[v-1].append((u, w))

def dfs(x, w):
    if ans[x-1] >= 0:
        return
    ans[x-1] = w % 2
    for nx, w_ in L[x-1]:
        dfs(nx, (w + w_) % 2)
    return

dfs(1, 0)

for a in ans:
    print(a)

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

use itertools::Itertools;
use proconio::marker::*;
use proconio::*;

#[fastout]
fn main() {
    input! {
        n: usize, x: usize, t: usize,
    }

    println!(
        "{}",
        if n % x == 0 {
            n / x * t
        } else {
            (n / x + 1) * t
        }
    );
}


Measured memory_bytes: 2164
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define sz(x) (int)x.size()
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define REV(x) reverse(x.begin(),x.end())
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int n,m,k;
const int mxN=2e5+5;
int a[mxN],b[mxN];
ll pref[mxN];

int binSearch(int val) {
    int l,h;
    l=0; h=n;
    int res=-1;
    while(l<=h) {
        int mid=l+(h-l)/2;
        if(pref[mid]<=val) {
            res=mid;
            l=mid+1;
        }
        else
            h=mid-1;
    }
    return res;
}

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m >> k;
    F0R(i,n)
        cin >> a[i];
    F0R(i,m)
        cin >> b[i];
    FOR(i,1,n+1)
        pref[i]=pref[i-1]+a[i-1];
    int best=0;
    ll cur=0;
    F0R(i,m+1) {
        int ind=binSearch(k-cur);
        best=max(best,ind+i);
        if(i!=m)
            cur+=b[i];
        if(cur>k)
            break;
    }
    cout << best;

    return 0;
}


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

using namespace std;

int main()
{
    char b;
    cin>>b;
    if(b=='A'){
        cout<<'T'<<endl;
    }else if(b=='T'){
        cout<<'A'<<endl;
    }else if(b=='C'){
        cout<<'G'<<endl;
    }else{
        cout<<'C'<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
while 1:
    n = input()
    if n==0: break
    p = map(int, raw_input().split())
    a = p[0]; s = "";
    for i in xrange(1,n):
        if p[i]!=p[i-1]+1:
            s += " %d-%d"%(a,p[i-1]) if a!=p[i-1] else " "+str(a)
            a = p[i]
    s += " %d-%d"%(a,p[n-1]) if a!=p[n-1] else " "+str(a)
    print s[1:]

Measured memory_bytes: 4236
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

h,w = inpl()
s = [list(input()) for i in range(h)]
cnt = 0
for i in s:
    cnt += i.count('#')
if cnt != h+w-1:
    print('Impossible')
    quit()
for fl in itertools.combinations(range(h+w-2),h-1):
    nx = 0; ny = 0
    for i in range(h+w-2):
        if i in fl:
            ny += 1
        else:
            nx += 1
        if s[ny][nx] == '#':
            continue
        break
    else:
        print('Possible')
        break
else:
    print('Impossible')


Measured memory_bytes: 5080
import sys
n = int(input())
a = list(map(int, (input().split())))
b = list(map(int, (input().split())))

ans = 0
for i in range(n):
    if a[i] > b[i]:
        ans = ans + b[i]
    else:
        ans = ans + a[i]
        next = b[i] - a[i]
        if a[i + 1] > next:
            a[i + 1] = a[i + 1] - next
            ans = ans + next
        else:
            ans = ans + a[i + 1]
            a[i + 1] = 0
print(ans)


Measured memory_bytes: 18476
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define SORT(i) sort((i).begin(),(i).end())
#define INF 2000000000
constexpr ll mod = 1000000007;

int main() {
	int N;
	cin >> N;
	vector<int>a(N);
	int s = 0;
	for (int i = 0;i < N;++i) {
		cin >> a[i];
		s = max(s, a[i]);
	}
	vector<int>data(s + 1, 0);
	for (int i = 0;i < N;++i) {
		data[a[i]]++;
	}
	int ans = 0, cnt = 0;
	for (int i = 0;i < s + 1;++i) {
		if (i == 0) {
			cnt = data[i] + data[i + 1];
			ans = max(ans, cnt);
		}
		else if (i == s) {
			cnt = data[i] + data[i - 1];
			ans = max(ans, cnt);
		}
		else {
			cnt = data[i - 1] + data[i] + data[i + 1];
			ans = max(ans, cnt);
		}
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <tuple>

using namespace std;

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

    // パー <= グー
    int p_cnt = 0, g_cnt = 0;
    for(int i=0; i<s.length(); ++i){
        if(s[i] == 'p'){
            p_cnt++;
        }
        else{
            g_cnt++;
        }
    }
    int ans;
    ans = (g_cnt - p_cnt)/2;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main()
{
    int N,C[500],S[500],F[500],i,j,t,x[500];

    scanf("%d",&N);

    for(i=0;i<N-1;i++){
        scanf("%d %d %d",&C[i],&S[i],&F[i]);
    }

    for(i=0;i<N-1;i++){
        t=S[i];
        for(j=i;j<N-1;j++){
            t=t+C[j];
            if(j!=N-2){
                if(t%F[j+1]!=0){
                    t = t + (F[j+1] - t % F[j+1]);
                }
                while(t<S[j+1]){
                    t = t + F[j+1];
                }
            }
        }
        x[i]=t;
    }
    x[N-1]=0;
    for(i=0;i<N;i++){
        printf("%d\n",x[i]);
    }

    return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!


void solve(){
    int n;
    cin>>n;
    
    int maxm=INT_MIN;
    int smaxm=INT_MIN;
    
    vi arr(n);
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        arr[i]=x;
        if(x>=maxm){
            smaxm=maxm;
            maxm=x;
        }
        else if(x>=smaxm){
            smaxm=x;
        }
    }
    for(int i=0;i<n;i++){
        if(arr[i]==maxm){
            cout<<smaxm<<endl;
        }
        else{
            cout<<maxm<<endl;
        }
    }
}



int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

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

#define DEBUG 0

#if DEBUG
  #define DLOG(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DLOG(...)
#endif

void debug(auto f) {
#if DEBUG
  f();
#endif
}

ll mPrime = int(1e9) + 7;
ll bN, bX;
vector<ll> bS;
vector<ll> facts;
vector<ll> invFacts;
vector<int> tbl;
vector<int> low;  // low[y] == #{ i | s[i] <= y }

ll mAdd(ll x, ll y) {
  ll z = x + y;
  if (z < mPrime)  return z;
  else             return (z - mPrime);
}

ll mSub(ll x, ll y) {
  ll z = x - y;
  if (z >= 0)  return z;
  else         return (z + mPrime);
}

ll mMul(ll x, ll y) {
  return (x * y) % mPrime;
}

ll eGCD(ll a, ll b, ll& s, ll& t) {
  if (a == 0) {
    s = 0;
    t = 1;
    return b;
  }
  ll u;
  ll g = eGCD(b % a, a, t, u);
  s = u - (b / a) * t;
  return g;
}

ll mInv(ll x) {
  ll s, t;
  eGCD(x, mPrime, s, t);
  return s < 0 ? s + mPrime : s;
}


ll tight(ll);

ll loose(ll y, ll len) {
  ll result = mMul(tight(y), mMul(facts.at(len), invFacts.at(low.at(y))));
  DLOG("loose(%lld, %lld) = %lld\n", y, len, result);
  return result;
}

ll tight(ll y) {
  if (tbl.at(y) >= 0)  return tbl.at(y);
  ll len = low.at(y);
  if (len == 0)  return y;
  ll result = 0;
  for (ll i = 0; i < len; i++) {
    ll z = y % bS.at(i);
    result = mAdd(result, loose(z, len-1));
  }
  tbl.at(y) = result;
  DLOG("tight(%lld) = %lld\n", y, result);
  return result;
}

int main() {
  cin >> bN >> bX;
  bS.resize(bN);
  for (ll i = 0; i < bN; i++) {
    cin >> bS.at(i);
  }
  facts.resize(bN+1);
  invFacts.resize(bN+1);
  facts.at(0) = invFacts.at(0) = 1;
  for (ll i = 1; i <= bN; i++) {
    facts.at(i) = mMul(i, facts.at(i-1));
    invFacts.at(i) = mInv(facts.at(i));
  }
  sort(bS.begin(), bS.end());

  low.resize(bX+1);
  ll idx = 0;
  for (ll i = 0; i < bX+1; i++) {
    if (idx < (ll) bS.size() && bS.at(idx) == i)  idx++;
    low.at(i) = idx;
  }

  tbl.resize(bX+1, -1);
  ll ans = loose(bX, bS.size());
  cout << ans << endl;

  return 0;
}



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

int main() {
  int X;
  cin >> X;
  int mp = 0;
  if (X == 1) cout << 1 << endl;
  else {
    for (int i=2; i<=X; i++) {
      for (int j=2;;j++) {
        if (pow(i, j) > X) break;
        else {
          if (mp < pow(i, j)) mp = pow(i,j);
        }
      }
    }
    cout << mp << endl;
  }
}


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

int main() {
	int W, H, x, y, r;

	cin >> W >> H >> x >> y >> r;

	if (x - r < 0 || y - r < 0 || y + r > H||x + r > W)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 3092
#include <stdio.h>

int main(void){
    int A, B, K, X;

    scanf("%d %d", &A, &B);

    X= A+B;
    if (X%2==1)
        printf("IMPOSSIBLE\n");

    else
    {
        K=X/2;
        printf("%d\n",K);
    }
    
}



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

int main()
{
    int64_t K;
    cin >> K;

    int N = 50;
    cout << N << endl;

    int64_t q = K / 50;
    int64_t r = K % 50;
    int64_t base = N - 1 + q;
    for (int i = 0; i < r; i++)
    {
        cout << base + N - (r - 1) << " ";
    }
    for (int i = 0; i < N - r; i++)
    {
        cout << base - r << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <array>
#include <climits>
#include <bitset>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define mp make_pair
#define pb push_back
#define eb emplace_back
using namespace std;		using LL = long long;
using VI = vector<int>;		using VL = vector<LL>;
using VS = vector<string>;	using VD = vector<double>;
using VVI = vector<VI>;		using VVL = vector<VL>;
using PII = pair<int, int>;	using PLL = pair<LL, LL>;
using VP = vector<PII>;		using VPL = vector<PLL>;
const int inf = (int)1e9;	const double PI = acos(-1.0);
const LL MOD = 1000000007;	const double EPS = 1e-12;
const int dx[] = { -1,0,1,0,-1,-1,1,1 }, dy[] = { 0,1,0,-1,-1,1,-1,1 };

int main() {
	int n;
	cin >> n;
	cout << n * n << endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> arr(n);
	for(int i=0; i<n; ++i){
		cin >> arr[i];
	}
	for(int k=0; k<n; ++k){
			if(k+1 != n){
				cout << arr[k] << " ";
			} else{
				cout << arr[k] << endl;
			}
	}
	for(int i=1; i<n; ++i){
		int j;
		int tmp = arr[i];
		
		for( j=i; j>0 && arr[j-1]>tmp; --j){
			arr[j] = arr[j-1];
		}
		arr[j] = tmp;

		for(int k=0; k<n; ++k){
			if(k+1 != n){
				cout << arr[k] << " ";
			} else{
				cout << arr[k] << endl;
			}
		}

	}
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int H, W; cin >> H >> W;
    if(H == 1 || W == 1){
        Out(1);
        return 0;
    }
    int ans = (H * W + 1) / 2;
    Out(ans);

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 int main(void)
 {
     int n,p[20],i,j=0;

     scanf("%d",&n);

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

     for(i=1;i<n-1;i++){
       if((p[i]>p[i-1])&&(p[i]<p[i+1]))
          j++;
       else if((p[i]>p[i+1])&&(p[i]<p[i-1]))
          j++;
     }
       printf("%d\n",j);

       return 0;
 }


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

int main(){
  ll a,b,c;
  cin>>a>>b>>c;
  string ans="No";
  if ((4*a*b)<(c*c+a*a+b*b-2*a*c+2*a*b-2*b*c) and c-a-b>0)
  ans="Yes";
  cout<<ans;


}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
int main(){
	int a, b, d = 0, r = 0;
	double f;
	std::cin >> a >> b;
	d = a / b;
	r = a % b;
	f = 1.0000000000 * a / b;
	std::cout << d <<" "<< r <<" ";
	printf("%.8lf\n", f);
	return 0;
}

Measured memory_bytes: 3196
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int a,b,c,d,ANS=0;
	vector<int>V(101,0);
	cin>>a>>b>>c>>d;
	for(int i=a;i<b;i++){
		V[i]=1;
	}
	for(int i=c;i<d;i++){
		if(V[i]==1){
			ANS++;
		}
	}
	cout << ANS << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef unsigned long long ull;

int main() {
	ull n, m;
	cin >> n >> m;
  
	bool flug[100000];
	ull pen[100000];
	for (ull i = 0; i < n; i++) {
		flug[i] = false;
		pen[i] = 0;
	}
  
	ull ac = 0;
	ull wa = 0;
  
	for (ull i = 0; i < m; i++) {
		ull p;
		string s;
		cin >> p >> s;
		if (flug[p-1] == false) {
			if (s == "AC") {
				flug[p-1] = true;
				ac++;
			} else {
				pen[p-1]++;
				wa++;
			}
		}
	}
	
	for (ull i = 0; i < n; i++)
		if (flug[i] == false) wa -= pen[i];

	cout << ac << ' ' << wa << endl;
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pi pair<int,int>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/

signed main(){
  int n;
  cin>>n;
  vector<pi> p(n);
  rep(i,n){
    int a,b;
    cin>>a>>b;
    p[i]=make_pair(b,a);
  }
  int t=0;
  sort(all(p));
  rep(i,n){
    auto v=p[i];
    t+=v.second;
    if(t>v.first){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;

  return 0;
}


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

// input
int H, W;
vector<int> A, B;

set<P> s;
multiset<int> w;


void input() {
    cin >> H >> W;
    A = B = vector<int>(H);
    rep(i, H) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }
}


int main() {
    input();
    rep(i, W) {
        s.insert(P(i, i));
        w.insert(0);
    }
    rep(i, H) {
        auto x = s.lower_bound(P(A[i], 0));
        auto y = s.lower_bound(P(B[i] + 1, 0));
        if (x != s.end() && y != s.begin() && x != y) {
            y--;
            while (x != y) {
                int v = x->first - x->second;
                w.erase(w.find(v));
                s.erase(x++);
            }
            if (B[i] < W - 1) {
                s.insert(P(B[i] + 1, x->second));
                w.insert(B[i] + 1 - x->second);
            }
            int v = x->first - x->second;
            w.erase(w.find(v));
            s.erase(x);
        }
        ll ans;
        if (w.empty()) ans = -1;
        else ans = ll(i) + 1 + (*w.begin());
        cout << ans << endl;
    }
}


Measured memory_bytes: 23532
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int[] num = new int[3];
		num[0] = scan.nextInt();
		num[1] = scan.nextInt();
		num[2] = scan.nextInt();

		int count5 = 0;
		int count7 = 0;

		for (int number : num) {
			if (number == 5) {
				count5 += 1;
			} else if (number == 7) {
				count7 += 1;
			}
		}

		String result;

		if (count5 == 2 && count7 == 1) {
			result = "YES";
		} else {
			result = "NO";
		}
		System.out.println(result);
	}
}


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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

int n, s[1000005];

void diff(){
	for(int i = 1; i < n; i++){
		s[i] = abs(s[i] - s[i + 1]);
	}
	n--;
}

int tau(int x){
	int ret = 0;
	while(x > 0){
		ret += x / 2;
		x /= 2;
	}
	return ret;
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		char c;
		scanf(" %c", &c);
		s[i] = c - '0';
	}
	// answer has to be 0, 1, or 2
	// parity should give "1" vs "0 or 2"
	int parity = 0;
	for(int i = 1; i <= n; i++){
		// check whether (n-1)C(i-1) is odd
		int twopow = tau(n-1) - tau(i-1) - tau(n-i);
		if(twopow == 0){
			parity ^= (s[i] & 1);
		}
	}
	if(parity == 1){
		printf("1\n");
		return 0;
	}
	
	diff();
	// now every entry needs to be 0 or 2, for answer to be 2
	for(int i = 1; i <= n; i++){
		if(s[i] == 1){
			printf("0\n");
			return 0;
		}
	}
	// use parity again!
	int answer = 0;
	for(int i = 1; i <= n; i++){
		int twopow = tau(n-1) - tau(i-1) - tau(n-i);
		if(twopow == 0){
			answer ^= s[i];
		}
	}
	printf("%d\n", answer);
	return 0;
}

Measured memory_bytes: 4096
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top
    def print_top(self): print(self.top)


label=[int(x) for x in input().split()]
oplist=list(input())
d=dice(label)
for op in oplist:
    d.roll(op)
d.print_top()

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

long dp[1005][1005];

long H, W;
long mod = 1000000007;
char grid[1005][1005] = {};

long route(long h, long w)
{
  if (dp[h][w] != -1)
    return dp[h][w];
  
  if (grid[h][w] == '#')
    return 0;
  
  if (h == H - 1)
    return route(h, w + 1);
  
  if (w == W - 1)
    return route(h + 1, w);
  
  dp[h][w] = route(h + 1, w) + route(h, w + 1);
  return dp[h][w] % mod;
}

int main()
{
  cin >> H >> W;
  for (int h = 0; h < H; h++)
  {
    cin >> grid[h];
  }
  
  for (int h = 0; h < H; h++)
  {
    for (int w = 0; w < W; w++)
    {
      dp[h][w] = -1;
    }
  }
  dp[H - 1][W - 1] = 1;
  
  /*
  for (int h = 0; h < H; h++)
  {
    for (int w = 0; w < W; w++)
    {
      cout << route(h, w) << " ";
    }
    cout << endl;
  }
  cout << endl;
  */
  
  long ans = route(0, 0);
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 9216
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,k = readInts()
    LIST = [0] * n
    for i in range(k):
        d = int(input())
        A = readInts()
        for i in range(d):
            LIST[A[i]-1] = 1
    cnt = 0
    for i in range(n):
        if LIST[i] == 0:
            cnt += 1
    print(cnt)
if __name__ == '__main__':
  main()


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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

#define INF 1e9
#define MOD 1000000007
#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 each(x, v) for (auto& x: (v))
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl

void solve();
void in(){} template<class T, class... U> void in(T &t, U &...u){ cin >> t; in(u...); }
int main() { cin.tie(0); ios::sync_with_stdio(0); solve(); }

void solve() {
  int N;
  in(N);
  vi H(N);
  each(x, H) in(x);
  vi dp(N);
  rrep(i, N - 2, -1) {
    if (H[i + 1] <= H[i]) {
      dp[i] = dp[i + 1] + 1;
    } else {
      dp[i] = 0;
    }
  }
  print(*max_element(all(dp)));
}


Measured memory_bytes: 1024
N, M = map(int, input().split())
A, B = [], []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

C, D = [], []
for i in range(M):
    c, d = map(int, input().split())
    C.append(c)
    D.append(d)

for a, b in zip(A, B):
    best = 1<<30
    res = None
    for i in range(M):
        d = abs(a - C[i]) + abs(b - D[i])
        if res is None or best > d:
            best = d
            res = i
    print(res + 1)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>

using namespace std;

int main(){
	int N,K;
	int dp[11][2001];
	int c,g;
	vector<int> tp[11];
	
	scanf("%d %d",&N,&K);
	for(int i=0;i<N;i++){
		scanf("%d %d",&c,&g);
		tp[g].push_back(c);
	}
	for(int i=1;i<=10;i++){
		sort(tp[i].begin(),tp[i].end());
		reverse(tp[i].begin(),tp[i].end());
		for(int j=1;j<=K;j++){
			int sum=0;
			for(int k=0;k<=(int)tp[i].size();k++){
				if(j-k<0)
				break;
				if(k!=0)
				sum+=tp[i][k-1];
				dp[i][j]=max(dp[i][j],dp[i-1][j-k]+(k-1)*k+sum);
			}
		}
	}
	printf("%d\n",dp[10][K]);
}


Measured memory_bytes: 3392
#include <stdio.h>
#include <math.h>
int main(){
  double x1,x2,x3,x4;
  double y1,y2,y3,y4;
  double dx1,dx2,dy1,dy2;
  int n;
  double epsilon=1.0e-10;
  scanf("%d",&n);
  while(n!=0){
    scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
    dx1=x2-x1;
    dy1=y2-y1;
    dx2=x4-x3;
    dy2=y4-y3;

    if(fabs(dx1*dy2-dx2*dy1)<epsilon)printf("YES\n");
    else printf("NO\n");
    n--;
  }
  return 0;
}

Measured memory_bytes: 620
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    string S;
    cin >> N >> S;
    VEC(int) suffix(N + 1, 0);
    FORD(i, N - 1, -1) {
        int d = S[i] - '0';
        suffix[i] = suffix[i + 1] | (1 << d);
    }

    int prefix = 0;
    set<int> keyset;
    FOR(i, 0, N) {
        int d = S[i] - '0';
        FOR(d1, 0, 10) if (prefix & (1 << d1))
            FOR(d2, 0, 10) if (suffix[i + 1] & (1 << d2))
                keyset.insert(d1 * 100 + d * 10 + d2);
        prefix |= 1 << d;
    }
    
    cout << keyset.size() << endl;
    return 0;
};

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;


template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll X,Y;
  cin>>X>>Y;
  ll ans=0;
  if(X==3){ans+=100000;}
  if(X==2){ans+=200000;}
  if(X==1){ans+=300000;}
  if(Y==3){ans+=100000;}
  if(Y==2){ans+=200000;}
  if(Y==1){ans+=300000;}
  if(X==Y && X==1){ans+=400000;}
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int a,b;
    cin >> a >> b;
    if (a * b % 2 == 0) {
        No;
    }else{
        Yes;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
/*

*/
int main(){
  ll N; cin>>N;
  vector<ll> A(N,0);
  rep(i,N) cin>>A[i];
  sort(all(A));
  ll ans=0;
  ll n=N/2;
  for(ll i=N-1; i>=n; i--)ans+=A[i]*2;
  ans-=A[N-1];
  if(N%2==1) ans-=A[n];
  cout<<ans<<endl;
}

Measured memory_bytes: 4792
def is_same(i, j, k, x):
    total = i*500 + j*100 + k*50
    return total==x

coin_500 = int(input())
coin_100 = int(input())
coin_50 = int(input())
x = int(input())
ans = 0
for i in range(coin_500+1):
    for j in range(coin_100+1):
        for k in range(coin_50+1):
            if is_same(i, j, k, x):
                ans = ans + 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define pb(n) push_back(n);
#define maxii 200005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
vector<int> vi;
vector<lln> vl;
vector<pii> vii;
vector<pll> vll;


lln arr[maxii];
lln arr2[maxii];
//bool check[maxii];
bool check2[1000][1000];
lln n,m;

int main()
{
    cin>>arr[0]>>arr[1];
    if(arr[0]%3==0 || arr[1]%3==0)
    {
        cout<<"Possible";
    }
    else if((arr[0]+arr[1])%3==0)
    {
        cout<<"Possible";
    }
    else cout<<"Impossible";
}






Measured memory_bytes: 3612
def is_valid(num):
    if 1 <= num < 10:
        return True
    ns = map(int, str(num))
    n = len(ns)
    for i in xrange(n - 1):
        if abs(ns[i] - ns[i + 1]) > 1:
            return False
    return True

lunluns = []
for i in xrange(1, 100000):
    if is_valid(i):
        lunluns.append(i)

d = {}

def dfs2(rem, pre):
    if rem == 0:
        return 1
    key = (rem, pre)
    if key in d:
        return d[key]

    res = 0
    if pre == -1:
        for i in xrange(10):
            res += dfs2(rem - 1, -1 if i == 0 else i)
    else:
        for i in xrange(10):
            if abs(i - pre) <= 1:
                res += dfs2(rem - 1, i)
    d[key] = res
    return res

assert dfs2(1, -1) == 10
assert dfs2(1, 1) == 3

def dfs(cur, n, k, pre, buf):
    if cur == n:
        return k == 1

    for i in xrange(10):
        if pre == -1 or abs(i - pre) <= 1:
            u = dfs2(n - cur - 1, -1 if pre == -1 and i == 0 else i)
            if u < k:
                k -= u
            else:
                buf.append(i)
                assert dfs(cur + 1, n, k, -1 if pre == -1 and i == 0 else i, buf)
                break
    return True

def solve(k):
    N = 500
    res = []
    assert dfs(0, N, k, -1, res)
    res = res[::-1]
    while res and res[-1] == 0:
        res.pop()
    if not res:
        res = [0]
    return ''.join(map(str, res[::-1]))

assert solve(3) == '2'
assert solve(1) == '0'
assert solve(2) == '1'
assert solve(4) == '3'

for i, num in enumerate(lunluns):
    assert solve(i + 2) == str(num)

if __name__ == '__main__':
    k = int(raw_input())
    k += 1
    print solve(k)


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

#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ll long long
#define ldb long double 
#define db double
#define str string

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mll map<ll,ll>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int md = 1e9+7;
const int MX = 2e5+5;
const ll INF = 1e18; 
const ldb PI = 4*atan((ldb)1);

ll power(ll a,ll n)
{
 ll res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a*=a;
  n/=2;
}
return res;
}

ll abst(ll a)
{
 return ((a<0)?(-1*a):(a));
}

int main()
{
    int n;
    cin>>n;
    int cnt=0,minn=0;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        if(i==0)
        {
            cnt++;
            minn=x;
        }
        else
        {
            if(minn>x)
            {
                cnt++;
                minn=x;
            }
        }
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 256
a,b = gets.split(" ").map(&:to_i)

cell = Array.new(100){Array.new(50,".") + Array.new(50,"#")}

(a-1).times do |i|
  cell[i/25 *2][(i%25)*2+51] = "."
end

(b-1).times do |i|
  cell[i/25 *2][(i%25)*2] = "#"
end

puts "100 100"

cell.each do |line|
  puts line.join("")
end

Measured memory_bytes: 1916
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int A, B;
    cin >> A >> B;
    if (A < B) swap(A,B);
    if (abs(A-B) > 1) {
        cout << A + A - 1 << endl;
    } else {
        cout << A + B << endl;
    }
}

Measured memory_bytes: 256
s = input()

up = 0
down = 0
prev_x = ''
up_cnt = 0
down_cnt = 0
ans = 0

for i in range(len(s)):
    if (prev_x =='<'or prev_x ==''):
        if s[i] == '<':
            up_cnt += 1
        else: # s[i] == '>' at top
            up = up_cnt
            up_cnt = 0
            down_cnt =+1
            
    else: # prev_x = '>'
        if s[i] == '>':
            down_cnt += 1
        else: # s[i] ='<' at bottom
            down = down_cnt
            down_cnt =0
            up_cnt += 1
            if up == 0:
                ans += (down*(down+1))/2
            else:
                if up > down:
                    ans += (up*(up+1))/2 + (down*(down-1))/2
                else:
                    ans += (up*(up-1))/2 + (down*(down+1))/2
    prev_x = s[i]

if up_cnt > 0 and down_cnt == 0:
    ans += (up_cnt*(up_cnt+1))/2
elif down_cnt > 0 and up_cnt == 0:
    if up > down_cnt:
        ans += (up*(up+1))/2 + (down_cnt*(down_cnt-1))/2
    else:
        ans += (up*(up-1))/2 + (down_cnt*(down_cnt+1))/2

print(int(ans))

Measured memory_bytes: 9912
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>
#include <cmath>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep01(i, n) for(int i = 0; i < (n) + 1; i++)
#define rep10(i, n) for(int i = 1; i < (n); i++)
#define rep11(i, n) for(int i = 1; i < (n) + 1; i++)
#define all(a) (a).begin(), (a).end()
typedef long long int ll;
typedef struct { int x; int y; } Pos;
using namespace std;

string s, s_, t;
int check() {
    int ret = -1;
    bool match;
    rep01(i, (int)s_.length() - t.length()) {
        if (s_[i] == t[0] || s_[i] == '?') {
            match = true;
            rep(j, (int)t.length()) {
                if (s_[i + j] != '?' && s_[i + j] != t[j]) match = false;
            }
            if (match) ret = i;
        }
    }
    return ret;
}
int main() {
    cin >> s_ >> t;
    int b = check();
    if (0 <= b) {
        s = s_;
        rep(i, (int)t.length())
            s[i+b] = t[i];
        rep(i, (int)s.length())
            if (s[i] == '?') s[i] = 'a';
        cout << s << endl;
    }
    else {
        cout << "UNRESTORABLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 3568
import math, sys
from collections import deque
N , M = list(map(int, input().split()))

Es = [[] for _ in range(N+1)]
for i in range(M):
    A , B = list(map(int, input().split()))
    Es[A].append(B)
    Es[B].append(A)

used = [False]*(N+1)
used[1] = True

ans = [-1]*(N+1)

cand = deque([1])
while len(cand)>0:
    tar = cand.popleft()
    for each in Es[tar]:
        if used[each]:
            continue
        cand.append(each)
        ans[each]=tar
        used[each]= True

print("Yes")
for i in range(2,N+1):
    print(ans[i])


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

int main() {
    string S;
    cin >> S;
    if(S == "Sunny") {
        cout << "Cloudy" << endl;
    }
    else if (S == "Cloudy") {
        cout << "Rainy" << endl;
    }
    else if (S == "Rainy") {
        cout << "Sunny" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        hoge();
        System.Console.ReadLine();
    }

    public static void hoge()
    {
        var vars = System.Console.ReadLine();

        if(vars == "RRR")
        {
            System.Console.WriteLine(3);
        }
        else if(vars == "RRS" || vars == "SRR")
        {
            System.Console.WriteLine(2);
        }
        else if(vars == "SSS")
        {
            System.Console.WriteLine(0);
        }
        else
        {
            System.Console.WriteLine(1);
        }

        

        

    }

}

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

int cnt[100002]={0}; //-1:10^5

int main(){
 int n;
  cin >> n;
 int a[n];
  for(int i=0;i<n;i++) {
    cin >> a[i];
    cnt[a[i]+2]++;
    cnt[a[i]+1]++;
    cnt[a[i]]++;
  }
  
  int res=0;
  for(int i=0;i<100002;i++){
   res=max(res,cnt[i]);
  }
  cout << res << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;

int modpow(int x, int n, int m) {
	x %= m;
	int res = 1;
	while(n > 0) {
		if(n & 1)
			res = res * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return res;
}

int dp[N];

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n, k;
	cin >> n >> k;
	int ans = 0;
	for(int i = k; i >= 1; i--) {
		dp[i] = modpow(k / i, n, mod);
		for(int j = 2 * i; j <= k; j += i) {
			dp[i] = (dp[i] - dp[j] + mod) % mod;
		}
		ans = (ans + i * dp[i] % mod) % mod;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 4392
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <bitset>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;
// const ll mod =  998244353 ;
const ll mod =  1000000007 ;
const ll inf = 1e18;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())

template<typename T> void print_vec(vector<T> a) {int n = a.size();REP(i, n) {cout >> a[i]; if(i!=n-1) cout << " "; else cout << endl;}}
ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
template<typename T> ll sum(T begin, T end) {return accumulate(begin, end, 0ll);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

using Pair = pair<ll, ll>;

const char C[] = {'A', 'B', 'X', 'Y'};

signed main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<string> s(n);
    REP(i, n) cin >> s[i];
    vector<string> t = s;
    ll ans = 0;

    REP(x, n) {
        bool ok = true;
        REP(i, n) {
            REP(j, n) {
                t[i][(j+x) % n] = s[i][j];
            }
        }
        REP(i, n) {
            REP(j, n) {
                if(t[i][j] != t[j][i]) {
                    ok = false;
                }
            }
        }
        if(ok) ans += n;
    }
    cout << ans << endl;
    return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] num = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            bool isthere = num.All(s => s == num[0]);
            string result = isthere == true ? "Yes" : "No";
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 11348
#include <iostream>
#include <set>
#include <vector>
#define MOD 998244353
#define SIZE 200002
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
ll Mf[SIZE];
void Mfi(){
    Mf[0] = Mf[1] = 1;
    for(int i = 2; i < 200002; i++)Mf[i] = (Mf[i-1] * i) % MOD;
}
int main(void){
    int n, r, g, b;
    ll ans = 1;
    string s;
    set<int> red;
    set<P> rg;
    int c[300000];
    cin >> n >> s;
    Mfi();
    ans = Mf[n];
    fill(c, c+n*3, -1);

    for(int i=0;i<n*3;i++){
        if(s[i] == 'R'){
            red.insert(i);
        }
    }
    for(int i=0;i<n*3;i++){
        if(s[i] == 'G'){
            auto itr = red.begin();
            if(*itr < i){
                rg.insert(P(*itr, i));
            }else{
                rg.insert(P(i, *itr));
            }
            red.erase(itr);
        }
    }
    for(int i=0;i<n*3;i++){
        if(s[i] == 'B'){
            auto itr = rg.begin();
            int left = itr->first, right = itr->second;
            if(i < left){
                c[i] = left;
                c[right] = left;
            }else if(i < right){
                c[left] = i;
                c[right] = i;
            }else{
                c[left] = right;
                c[i] = right;
            }
            rg.erase(itr);
        }
    }
    /*
    for(int i=0;i<n*3;i++){
        cout << c[i] << " ";
    }
    cout << endl;*/

    r = g = b = 0;
    set<int> rs, gs, bs;
    for(int i=0;i<n*3;i++){
        if(c[i] == -1){
            if(rs.find(i) != rs.end()){
                r--;
                rs.erase(i);
            }else if(gs.find(i) != gs.end()){
                g--;
                gs.erase(i);
            }else if(bs.find(i) != bs.end()){
                b--;
                bs.erase(i);
            }
            continue;
        }else if(i < c[i]){
            if(s[i] == 'R'){
                ans *= ++r;
                rs.insert(c[i]);
            }
            if(s[i] == 'G'){
                ans *= ++g;
                gs.insert(c[i]);
            }
            if(s[i] == 'B'){
                ans *= ++b;
                bs.insert(c[i]);
            }
            //cout << ans << endl;
            ans %= MOD;
        }
    }
    //cout << r << g << b << endl;
    for(int i=n*3-1;i>=0;i--){
        if(c[i] == -1){
            if(rs.find(i) != rs.end()){
                r--;
                rs.erase(i);
            }else if(gs.find(i) != gs.end()){
                g--;
                gs.erase(i);
            }else if(bs.find(i) != bs.end()){
                b--;
                bs.erase(i);
            }
            continue;
        }else if(c[i] < i){
            if(s[i] == 'R'){
                ans *= ++r;
                rs.insert(c[i]);
            }
            if(s[i] == 'G'){
                ans *= ++g;
                gs.insert(c[i]);
            }
            if(s[i] == 'B'){
                ans *= ++b;
                bs.insert(c[i]);
            }
            //cout << ans << endl;
            ans %= MOD;
        }
    }


    cout << ans << endl;
}


Measured memory_bytes: 7940
#include <bits/stdc++.h>
using namespace std;
struct node{
	long long int a,b;
};
bool cmp(node e,node f)
{
	if(e.a!=f.a)
	return e.a<f.a;
	else
	return e.b>f.b;
}
int main(){
long long int n,m,y=0;
cin>>n>>m;
node d[n+1];
for(int i=1;i<=n;i++)
cin>>d[i].a>>d[i].b;
sort(d+1,d+n+1,cmp);
for(int i=1;i<=n;i++){
	if(d[i].b<m)
	{
		y+=d[i].a*d[i].b;
		m-=d[i].b;
	}
	else
	{
		y+=d[i].a*m;
		break;
	}
}
cout<<y;
}


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

int main(){
  int n, m;
  cin >> n >> m;
  vector <int> x(m);
  for (int i = 0; i < m; i++){
    cin >> x.at(i);
  }
  sort(x.begin(), x.end());
  vector <int> dist(m-1);
  for (int i = 0; i < m-1; i++){
    dist.at(i) = x.at(i + 1)-x.at(i);
  }
  if (n >= m){
    cout << 0 <<endl;
  }
  else{
  	make_heap(dist.begin(), dist.end());
  	for (int i = 0; i < n-1; i++){
    	pop_heap(dist.begin(), dist.end());
    	dist.pop_back();  
    }
    cout << accumulate(dist.begin(), dist.end(), 0) << endl;
  }
}


Measured memory_bytes: 1024
import itertools
import collections

def main():
    n = int(input())
    S = [input()[0] for _ in range(n)]

    array = ['M','A','R','C','H']
    combs = itertools.combinations(array, 3)
    coll = collections.Counter(S)

    ans = 0
    for comb in combs:
        ans += coll[comb[0]]*coll[comb[1]]*coll[comb[2]]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 52312