akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
using ll = long long;
using P = pair<int, int>;

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

  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};

mint f(int n){ 
  if(n == 0)return 1;
  mint x = f(n / 2); 
  x *= x; 
  if(n % 2 == 1)x *= 2;
  return x;
}

mint choose(int n, int a){
  mint x = 1, y = 1;
  for(int i = 0; i < a; ++i){
    x *= n - i;
    y *= i + 1;
  }
  return x / y;
}

int dp[200100];
mint mods[200100];
mint ten = 10;

int main(){
  string s;
  cin >> s;
  int n = s.size();
  
  vector<int> cnt(mod, 0);
  for(int i = n - 1; i >= 0; --i){
  	mods[i] = mods[i + 1] + mint(s[i] - '0') * ten.pow(n - 1 - i);
  	++cnt[mods[i].x];
  }

  ll ans = 0;
  for(int i = 0; i < mod; ++i){
  	ans += cnt[i] * (cnt[i] - 1) / 2;
  	if(i == 0)ans += cnt[i];
  }

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


Measured memory_bytes: 5288
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  int x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  int x3,y3,x4,y4;
  int x = x2 - x1;
  int y = y2 - y1;
  x3 = x2 - y;
  y3 = y2 + x;
  x4 = x1 - y;
  y4 = y1 + x;
  cout << x3 << " " << y3 << " " << x4 << " " << y4
 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}
std::vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend
#define all(x) (x).begin(),(x).end()
#define size_t ll
const int mod = 1000000007;
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
int h,w;
int main(){
  cin >> h >> w;
  cout << (roundup(h,w)) << endl; 
}


Measured memory_bytes: 256
while True:
    n, k = [int(i) for i in input().split()]
    if n == 0 and k == 0:
        break
    a = [int(input()) for i in range(n)]
    s = sum(a[0:k])
    max = s
    for i in range(k, n):
        s = s + a[i] - a[i - k]
        if s > max:
            max = s
    print(max)



Measured memory_bytes: 9884
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }
ll n,m;
vector<ll> a;

int main(){
    /*
    n回目のジャンプはnマス飛ぶ。
    n回目のジャンプのときマックスn*(n+1)/2先までいけるで
     */
    ll x;
    cin>>x;
    ll n=0;
    while(n*(n+1)/2<x){
        n++;
    }
    cout<<n<<endl;
    return 0;
}

Measured memory_bytes: 256
//W=BMI×H *h
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	 string a,a1="CODEFESTIVAL2016";
	 int s=16;
	 cin>>a;
	 for(int i=0;i<16;i++){
	 	if(a[i]==a1[i]){
	 		s--;
		 }
	 }
	 cout<<s<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  ll N;
  cin >> N;
  vector<vector<int>> A(10, vector<int>(10, 0));
  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    if (i % 10 == 0) continue;
    string s = to_string(i);
    int a = s[0] - '0';
    if (a == 0) continue;
    A[a][i % 10]++;
  }
  for (int i = 1; i <= N; i++) {
    if (i % 10 == 0) continue;
    string s = to_string(i);
    int a = s[0] - '0';
    if (a == 0) continue;
    ans += A[i % 10][a];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
ll mod=1E9+7;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)

ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
ld id(){ ld x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oe(){ cout << endl; }
void oie(ll x){ oi(x); oe(); }
void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }

ll N,M,X;
ll C[12];
ll A[12][12];
ll cur[12];

ll f(ll n, ll c){
    if(n==N){
        REP(i,0,M){
            if(cur[i]<X){
                return LLONG_MAX;
            }
        }
        return c;
    }
    ll ff=f(n+1,c);
    REP(i,0,M){
        cur[i]+=A[n][i];
    }
    ll tt=f(n+1,c+C[n]);
    REP(i,0,M){
        cur[i]-=A[n][i];
    }
    return min(ff,tt);
}

int main(){
    N=ii(),M=ii(),X=ii();

    REP(i,0,N){
        C[i]=ii();
        REP(j,0,M){
            A[i][j]=ii();
        }
    }
    
    ll c=f(0, 0);
    if(c==LLONG_MAX){
        oie(-1);
    }else{
        oie(c);
    }

    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define COUT(x) cout<<(x)<<"\n"

int main(){
    int h,n;
    cin >> h >> n;
    vector<int> a(n),b(n);
    REP(i,n){
        cin >> a[i] >> b[i];
    }
    vector<int> dp(20050,1e9);
    dp[0]=0;
    for(int i=0;i<20050;i++){
        REP(j,n){
            int tes = min(h,i+a[j]);
            dp[tes]=min(dp[i]+b[j],dp[tes]);
        }
    }
    COUT(dp[h]);
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		Boolean[][] cards = new Boolean[4][14];
		for (int i = 0; i < cards.length; i++) {
			for (int j = 0; j < cards[0].length; j++) {
				cards[i][j]=false;
			}
		}
		String[] suits = {"S","H","C","D"};
		int n = scanner.nextInt();
		for(int i=0;i<n;i++) {
			int tem = 0;
			String rank = scanner.next();
			int num = scanner.nextInt();
			switch (rank) {
			case "S":
				tem = 0;
				break;
			case "H":
				tem = 1;
				break;
			case "C":
				tem = 2;
				break;
			case "D":
				tem = 3;
				break;
			default:
				break;
			}
			cards[tem][num]=true;
		}
		for(int i=0;i<4;i++) {
			for(int j=1;j<=13;j++) {
				if (cards[i][j]!=true) {
					System.out.println(suits[i] + " " + j);
				}
			}
		}
		scanner.close();
	}
}


Measured memory_bytes: 26424
# coding: utf-8
from collections import Counter

num_card = int(input())
l_card = list(map(int, input().split()))
card_counter = Counter(l_card)

num_mod = 0
for card in card_counter.values():
    if card != 1:
        num_mod += (card - 1)

ans = len(card_counter)

if num_mod % 2 == 1:
    ans -= 1

print(ans)

Measured memory_bytes: 18656
n,m=map(int,input().split())
edges=[[0]*n for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  edges[a-1].append(b-1)
  edges[b-1].append(a-1)

visited=[False]*n
count=0
def dfs(u,visited):
  global count
  visited=visited[:]
  visited[u]=True
  if all(visited):
    count+=1
    return
  for v in edges[u]:
    if not visited[v]:
      dfs(v,visited)
  return False

dfs(0,visited)
print(count)

Measured memory_bytes: 3064
short S[40][2];i,f,h,p,t,d,e;M(int*a){return*1[&a]-*a;}main(m){for(;~scanf("%d",&m);){for(i=m;i--;)for(S[i][scanf("%d",S[i])]=t=p=d=h=f=0;h<3;f>8?h+=h-1|d+e>9?1:2:!h&d>9?f+=t=1:(f++,h^=1)|d+e<=9?f-=h:p++)e=d,scanf("%d",&d),S[i][1]+=~(t+p)*d,p=t,t=0;for(qsort(S,m,4,M);m--;)printf("%d %d\n",*S[m],-S[m][1]);}}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a<=0&&b>=0){cout<<"Zero\n";return 0;}
	if(a>0){cout<<"Positive\n";return 0;}
	if(b<0)
	{
		a=abs(a),b=abs(b);
		if((a-b+1)%2==0) cout<<"Positive\n";
		else cout<<"Negative\n";
	}
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
#define endl '\n'
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n, c;
  cin >> n >> c;
  vector<vll> grid(n, vll(n)), d(c, vll(c));
  for (ll i = 0; i < c; i++) {
    for (ll j = 0; j < c; j++) {
      cin >> d[i][j];
    }
  }
  vector<vll> mod(3, vll(0));
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < n; j++) {
      cin >> grid[i][j];
      mod[(i + j) % 3].push_back(grid[i][j]);
    }
  }
  ll ans = inf;
  for (ll i = 0; i < c; i++) {
    ll d1 = 0;
    for (ll x = 0; x < mod[0].size(); x++) {
      d1 += d[mod[0][x] - 1][i];
    }
    for (ll j = 0; j < c; j++) {
      if (i == j) continue;
      ll d2 = d1;
      for (ll x = 0; x < mod[1].size(); x++) {
        d2 += d[mod[1][x] - 1][j];
      }
      for (ll k = 0; k < c; k++) {
        if (i == k || j == k) continue;
        ll d3 = d2;
        for (ll x = 0; x < mod[2].size(); x++) {
          d3 += d[mod[2][x] - 1][k];
        }
        ans = min(ans, d3);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4596
def main():
    n = int(input())
    s = input()
    if n % 2 == 0:
        sl = len(s) // 2 
        s1 = s[:sl]
        s2 = s[sl:]
        if s1 == s2:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
     
if __name__ == '__main__':
    main()

Measured memory_bytes: 9124
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace std;
const long long N=200005, INF=2000000000000000000;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    lld ar[n+1];
    for(int i=1;i<=n;i++)
    cin>>ar[i];
    lld dp[n+1][n+1];
    fill(dp, 0);

    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        dp[i][0]=dp[i-1][0]*(1-ar[i]);
        for(int j=1;j<=i;j++)
        dp[i][j]=((dp[i-1][j]*(1.0-ar[i]))+(dp[i-1][j-1]*ar[i]));
    }
    int lim=(n+1)/2;
    if(n%2==0)
    lim++;
    lld ans=0;
    //print2d(dp,n,n);
    for(int i=lim;i<=n;i++)
    ans+=dp[n][i];
    cout<<ans;
}

Measured memory_bytes: 140928
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include<iomanip>
#include <queue>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repi(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
typedef long long ll;
int main() {
  int n,m;
  cin>>n>>m;
  priority_queue<ll> a;
  rep(i,n)
  {
      ll v = 0;
      cin>>v;
      a.push(v);
  }
  rep(i,m)
  {
      ll v = a.top();
      a.pop();
      a.push(v/2);
  }
  ll s = 0;
  rep(i,n)
  {
      ll v = a.top();
      a.pop();
      s+=v;
  }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 1400
n, m = map(int, input().split())
count = [0]*n

for _ in range(m):
    d = int(input())
    data = list(map(int, input().split()))
    for d in data:
        count[d-1] += 1

ans = 0
for i in count:
    if i == 0:
        ans += 1
print(ans)

Measured memory_bytes: 9192
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cmath>
#include<cstring>
#define loop(i,r,l) for(int (i)=(r);(i)<(l);(i)++)
#define rep(i,n) loop(i,0,n)
using namespace std;

int main(){
    int n,a,b,ra=0,rb=0;
    string s;
    cin>>n>>a>>b>>s;
    rep(i,n){
        if(s[i]=='a'){
            if(ra+rb<a+b){
                cout<<"Yes"<<endl;
                ra++;
            }else cout<<"No"<<endl;
        }
        if(s[i]=='b'){
            if(ra+rb<a+b&&rb<b){
                cout<<"Yes"<<endl;
                rb++;
            }else cout<<"No"<<endl;
        }
        if(s[i]=='c'){
            cout<<"No"<<endl;
        }
    }
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

template <class T>
using vec2 = vector<vector<T>>;

template <class T>
using vec3 = vector<vector<vector<T>>>;

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

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

    double L;
    cin >> L;
    double x = L / 3;
    double result = x * x * x;
    cout << setprecision(10) << result << endl;
    return 0;

}



Measured memory_bytes: 256
using System;

class Program
{
    static void Main()
    {
        Console.ReadLine();
        string inStr = Console.ReadLine();

        string[] arys = inStr.Split(' ');
        string result = "";

        for (int i = arys.Length - 1; i >= 0; i--)
        {
            result = result + arys[i] + " ";
        }

        Console.WriteLine(result.TrimEnd());
    }
}


Measured memory_bytes: 8844
#include <bits/stdc++.h>
const int INF = 1e9;
const int MO = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define rt return
#define ENDL cout<<endl
#define MAXE(a,b) a=max(a,b)
#define MINE(a,b) a=min(a,b)
#define s second
#define f first

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){

    int N,Q;
    cin >> N >> Q;
    string s;
    cin >> s;
    s.insert(s.begin(),' ');
    s.push_back(' ');
    vector<pair<char,char>> vec;
    for(int a = 0;a < Q;a++){
        char t,d;
        cin >> t >> d;
        vec.push_back({t,d});
    }
    reverse(vec.begin(),vec.end());
    vector<bool> flag(N+2, false);
    flag.front() = true;
    flag.back() = true;
    int le = 0;
    int ri = N+1;
    for(int i = 0;i < Q;i++){
        if(le != 0){
            if(s.at(le) == vec.at(i).first && vec.at(i).second == 'R'){
                flag.at(le) = false;

                le--;

            }
        }
        if(ri != 0){
            if(s.at(ri) == vec.at(i).first && vec.at(i).second == 'L'){
                flag.at(ri) = false;
                ri++;
            }
        }
        if(s.at(le+1) == vec.at(i).first && vec.at(i).second == 'L'){
            flag.at(le+1) = true;
            le++;
        }
        if(s.at(ri-1) == vec.at(i).first && vec.at(i).second == 'R'){
            flag.at(ri-1) = true;
            ri--;
        }
    }
    cout<<count(flag.begin(),flag.end(),false)<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 2200000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b) {a = b; return true;}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b) {a = b; return true;}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
    ll n; cin >> n;
    vpl a(n);
    rep(i,n){
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(rall(a));
    ll now = a[0].first;
    vl ans(n,0);
    ll acc = 1;
    ll mn = n;
    rep(i,n){
        ll id = a[i].second;
        if(i==n-1) ans[min(mn,id)] += acc * now;
        else{
            chmin(mn,id);
            ans[mn] += acc * (a[i].first - a[i+1].first);
            acc++;
            now = a[i+1].first;
        }
    }
    rep(i,n) cout << ans[i] << endl;
}

Measured memory_bytes: 3456
#include <iostream>
#include <string>
#include <sstream>

#define rep(i, n) for(int i = 1; i < n; i ++)

using namespace std;

int main(void){
    string in;
    for(int n; cin >> n >> in; cout << in << endl)
        while(n --){
            int counter = 1;
            char pre = in.at(0);
            stringstream ss;

            rep(i, in.length()){
                if(in.at(i) == pre) counter ++;
                else{ ss << counter << pre; counter = 1; }
                pre = in.at(i);
            }
            ss << counter << pre;

            in = ss.str();
        }

    return 0;
}

Measured memory_bytes: 1380
N = int(input())
for n in range(1,3501):
    for w in range(1,3501):
        if 4*n*w-N*(n+w) != 0:
            h = (N*n*w)/(4*n*w-N*(n+w))

            if h > 0 and h.is_integer():
                print(int(h), n, w)
                exit()



Measured memory_bytes: 40684
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int cnt = 0;
    for (int i = a; i <= b; i++) {
        if (c % i == 0) cnt++;
    }
    System.out.println(cnt);
  }
}


Measured memory_bytes: 26308
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5,M=2e5+5;
int n,m,U[M],V[M],id,f[N],dfn[N],low[N];
vector<int>e[N],d[N];
stack<int>s;
bool vis[N];
int mp[N][N];
int vis1[N],vis2[N];
void dfs(int u)
{
    dfn[u]=low[u]=++id;
    s.push(u);
    vis[u]=true;
    for(int i=0;i<e[u].size();i++)
    {
        int v=e[u][i];
        if(!dfn[v]) dfs(v),low[u]=min(low[u],low[v]);
        else if(vis[v]) low[u]=min(low[u],dfn[v]);
    }
    if(low[u]==dfn[u])
    {
        while(s.top()!=u)
            vis[s.top()]=false,f[s.top()]=u,s.pop();
        f[u]=u;s.pop();vis[u]=false;
    }
}
void dfs1(int u,int k)
{
    vis1[u]=k;
    for(int i=0;i<e[u].size();i++)
    {
        int v=e[u][i];if(vis1[v]) continue;
        dfs1(v,k);
    }
}
void dfs2(int u,int k)
{
    vis2[u]=k;
    for(int i=0;i<e[u].size();i++)
    {
        int v=e[u][i];if(vis2[v]) continue;
        dfs2(v,k);
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&U[i],&V[i]);
        e[U[i]].push_back(V[i]);
        d[U[i]].push_back(V[i]);
    }
    for(int i=1;i<=n;i++)
        if(!dfn[i])
        dfs(i);
    for(int i=1;i<=n;i++)
    {
        memset(vis1,0,sizeof(vis1));
        memset(vis2,0,sizeof(vis2));
        vis1[i]=vis2[i]=666;
        int up=e[i].size();
        for(int j=0;j<up;j++)
            if(!vis1[e[i][j]])
            dfs1(e[i][j],d[i][j]);
        for(int j=up-1;j>=0;j--)
            if(!vis2[e[i][j]])
            dfs2(e[i][j],d[i][j]);
        for(int j=1;j<=n;j++)
            if(vis1[j]&&j!=i)
        {
            if(vis1[j]==vis2[j]) mp[i][j]=1;
            else mp[i][j]=2;
        }
    }
    for(int i=1;i<=m;i++)
    {
        if(f[U[i]]==f[V[i]])
        {
            if(mp[U[i]][V[i]]==2) printf("same\n");
            else printf("diff\n");
        }
        else
        {
            if(mp[U[i]][V[i]]==1) printf("same\n");
            else printf("diff\n");
        }
    }
}


Measured memory_bytes: 9728
#include<bits/stdc++.h>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = long long;
using namespace std;
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; }

int main(){
  ll a,b,c; cin >> a >> b >> c;
  set<int> st;
  for(int i = 0; st.count((a*i)%b) == 0; i++){
    st.insert((a*i)%b);
  }
  if(st.count(c)) cout << "YES";
  else cout << "NO";
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  string S;cin>>S;
  if(S.size()<26){
    vector<int> chars(26);
    each(c,S){
      int target =c-'a';
      chars[target]++;
    }
    REP(i,0,26){
      if(chars[i]==0){
        char c=i+'a';
        S+=c;
        break;
      }
    }
    print(S);
    re 0;
  }
  else{
    int longest=0;
    RREP(i,S.size()-2,-1){
      // REP(j,i,S.size()-1){
        int left=S.at(i)-'a',right=S.at(i+1)-'a';
        // print(left,"  ",right);
        if(left<right){
          longest=i+1;
          break;
        // }
      }
      if(longest)break;
    }
    if(longest==0)print(-1);
    else{
      int app=-1;
      string origin=S.substr(0,longest);
      vector<int> chars(26);
      // chars[S.at(longest)-'a']++;
      // print(origin);
      each(c,origin){
        chars[c-'a']++;
      }
      REP(i,S.at(longest-1)-'a',26){
        if(chars[i]==0){
          char c=i+'a';
          S=S.substr(0,longest-1)+c;
          print(S);
          re 0;
        }
      }
      print(-1);
    }
  }

}


Measured memory_bytes: 3668
#include<cstdio>
using namespace std;

int n;
int s[40];

int size(char *w) {
  int counter = 0;
  while (w[counter] != 0) counter++;
  return counter;
}

bool ok(int f, int s) {
  if (s <= 5) return true;
  if (f >= 5 && s <= 12) return true;
  if (f >= 12 && s <= 17) return true;
  if (f >= 17 && s <= 24) return true;
  if (f >= 24 && s <= 31) return true;
  return false;
}

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) break;
    for (int i = 0; i < n; i++) {
      char w[15];
      scanf("%s", w);
      s[i] = size(w);
    }
    for (int i = 0; i < n; i++) {
      int sum = 0;
      for (int j = i; j < n; j++) {
        if (!ok(sum, sum + s[j])) break;
        sum += s[j];
        if (sum == 31) break;
      }
      if (sum == 31) {
        printf("%d\n", i + 1);
        break;
      }
    }
  }
}



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

int main() {

	int N;
	cin >> N;

	string S;
	cin >> S;

	int pi;
	int pj;
	int pk;
	int ans = 0;

	for (int i = 0; i < 10; i++) {
		pi = S.find(to_string(i), 0);
		for (int j = 0; j < 10; j++) {
			pj = S.find(to_string(j), pi + 1);
			for (int k = 0; k < 10; k++) {
				pk = S.find(to_string(k), pj + 1);
				if (pi != string::npos && pj != string::npos && pk != string::npos) {
					ans += 1;
				}
			}
		}
	}
	
	cout << ans << endl;

	return 0;
}







Measured memory_bytes: 256
n,m = map(int,input().split())
py = []
for i in range(m):
    py.append(list(map(int,input().split())))
    py[i].append(i)
py.sort(key=lambda x:x[1])
py.sort(key=lambda x:x[0])
x = py[0][0]
j=0
for i in range(m):
    if x != py[i][0]:
        j = 1
        x = py[i][0]
    else:
        j+=1
    s = str(py[i][0]).zfill(6) + str(j).zfill(6)
    py[i].append(s)
py.sort(key=lambda x:x[2])
for i in range(m):
    print(py[i][3])


Measured memory_bytes: 38472
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
int main()
{
    fast;
    int t;cin>>t;
    vector<unsigned long long int>v(t);
    for(int i=0;i<t;i++)
    {
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    unsigned long long int c=1;
    unsigned long long int p=pow(10,18);
    for(int unsigned long long k:v)
    {
        if(k==0)
        {
            cout<<0<<endl;
            return 0;
        }
        else {

            if(k<=p/c)
            {
                c*=k;
            }
            else {
                cout<<"-1"<<endl;
                return 0;
            }

        }
    }
    cout<<c<<endl;

}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
bool r(string s)
{
    string sf=s;
    reverse(s.begin(),s.end());
    if(sf==s)
	{
		return true;
	}
    return false;
}
int main()
{
    string a;
    cin>>a;
    int n=a.size();
    if(r(a)&&r(a.substr(0,(n-1)/2))&&r(a.substr((n+3)/2-1)))
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}

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

class Program
{
    static void Main(string[] args) {
        int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int x = s[0];
        int y = s[1];
        Console.WriteLine(gcd(x,y));
    }
    static int gcd(int x, int y) {
        if (x<y) return gcd(y,x);
        while(x%y>0) {
            int temp = y;
            y = x%y;
            x = temp;
        }
        return y;
    }
}


Measured memory_bytes: 18444
#[allow(unused_imports)]
use std::io;
#[allow(unused_imports)]
use std::cmp::max;
#[allow(unused_imports)]
use std::cmp::min;

#[allow(unused_macros)]
macro_rules! get {
    ($i:ident) => {
        $i = String::new();
        io::stdin().read_line(&mut $i).ok();
    };
}

#[allow(unused_macros)]
macro_rules! to_vec {
    ($s:ident, $t:ty) => {
        $s.split_whitespace().map(|i| i.parse().ok().unwrap()).collect::<Vec<$t>>()
    }
}

#[allow(unused_macros)]
macro_rules! parse {
    ($s:ident, $t:ty) => {
        $s.trim().parse::<$t>().ok().unwrap()
    }
}

#[allow(unused_macros)]
macro_rules! max {
    ($v:ident) => {
        $v.iter().max().unwrap()
    };
}

#[allow(unused_macros)]
macro_rules! min {
    ($v:ident) => {
        $v.iter().max().unwrap()
    };
}

#[allow(unused_macros)]
macro_rules! sort {
    ($v:ident) => {
        $v.as_mut_slice().sort()
    };
}

#[allow(unused_variables)]
#[allow(unused_mut)]
fn main() {
    let mut s: String;
    get!(s);
    let mut calc = to_vec!(s, String);
    let mut stack: Vec<i32> = Vec::new();
    for i in calc.iter() {
        let mut res: i32;
        match &i as &str {
            "+" => {
                let rhs = stack.pop().unwrap();
                let lhs = stack.pop().unwrap();
                res = lhs + rhs;
            },
            "-" => {
                let rhs = stack.pop().unwrap();
                let lhs = stack.pop().unwrap();
                res = lhs - rhs;
            },
            "*" => {
                let rhs = stack.pop().unwrap();
                let lhs = stack.pop().unwrap();
                res = lhs * rhs;
            },
            _ => {
                res = i.parse::<i32>().unwrap();
            }
        }

        stack.push(res);
    }

    println!("{}", stack.pop().unwrap());
}


Measured memory_bytes: 5044
class SegmentTree(object):

    def __init__(self, init_array, seg_func=min, seg_func_null=10 ** 9 + 7):

        self.seg_func = seg_func
        self.seg_func_null = seg_func_null
        self.n = 1
        while self.n < len(init_array):
            self.n *= 2
        self.dat = [0] * (2 * self.n - 1)
        for i in range(len(init_array)):
            self.dat[self.n - 1 + i] = init_array[i]
        for i in range(self.n - 2, -1, -1):
            self.dat[i] = self.seg_func(self.dat[2 * i + 1], self.dat[2 * i + 2])

    def update(self, k, a):
        k += self.n - 1
        self.dat[k] = a
        while k > 0:
            k = (k - 1) // 2
            self.dat[k] = self.seg_func(self.dat[k * 2 + 1], self.dat[k * 2 + 2])

    def query(self, p, q):
        # [p, q)
        if q <= p:
            return self.seg_func_null

        p += self.n - 1
        q += self.n - 2
        res = self.seg_func_null

        while q - p > 1:
            if p & 1 == 0:
                res = self.seg_func(res, self.dat[p])
            if q & 1 == 1:
                res = self.seg_func(res, self.dat[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = self.seg_func(res, self.dat[p])
        else:
            res = self.seg_func(self.seg_func(res, self.dat[p]), self.dat[q])

        return res


def solve(n, k, a_list):
    seg_tree = SegmentTree([0] * 300001, seg_func=max, seg_func_null=0)
    for i in range(n):
        a = a_list[i]
        r = seg_tree.query(max(0, a - k), min(a + k + 1, 300001))
        seg_tree.update(a, r + 1)
    return seg_tree.query(0, 300001)


def main():
    n, k = map(int, input().split())
    a_list = [int(input()) for _ in range(n)]
    res = solve(n, k, a_list)
    print(res)


def test():
    assert solve(10, 3, [1, 5, 4, 3, 8, 6, 9, 7, 2, 4]) == 7


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 102956
n = int(input())
s = input()
import collections
temp1 = 0
for j in range(1,n-1):
    i,k = j-1,j+1
    while i >= 0 and k < n:
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            temp1 += 1
        i,k = i-1,k+1
c = collections.Counter(s)
temp2 = 1
for key in "RGB":
    temp2 *= c[key]
print(temp2-temp1)

Measured memory_bytes: 9452
#include <cstdio>
#include<iostream>
#include<string>

using namespace std;
   
int main(void){

	string inp;
	int cnt=0;
	bool f;

	while(cin>>inp){
		f=true;
		for(int i=0;i<inp.length()/2;i++){
			if(inp[i]!=inp[inp.length()-1-i]) f=false;
		}
		if(f) cnt++;
	}
	cout<<cnt<<endl;

    return 0;
}

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

namespace Shell_Sort
{
    class Progaram
    {
        private static int[] I_Sort(int[] ca, int n)
        {
            var c = new int[ca.Length];
            ca.CopyTo(c, 0);
            for (int i = n; i < c.Length; i++)
            {
                var v = c[i];
                var j = i - n;
                while (j >= 0 && c[j] > v)
                {
                    c[j+n] = c[j];
                    j -= n;
                    cnt++;                        
                }
                c[j+n] = v;
            }
            return c;
        }

        static int cnt = 0;
        static List<int> g = new List<int>();
        private static int[] Shell_Sort(int[] ca)
        {
            var m = 1;
            var n = ca.Length / 9;
            while (m <= n) m = m * 3 + 1;
            for (;m > 0; m /= 3)
            {
                ca = I_Sort(ca, m);
                g.Add(m);
            }        
            return ca;
        }

        private static string Join(List<int> il)
        {
            var s = "";
            for (var i = 0; i < il.Count; i++)
            {
                s += il[i];
                if (i != il.Count - 1) s += " ";
            }
            return s;
        }

        static void Main()
        {
            Console.ReadLine();
            var ls = new List<int>();
            string s;
            while ((s = Console.ReadLine()) != null)
                ls.Add(int.Parse(s));
            var array = Shell_Sort(ls.ToArray());
            Console.WriteLine("{0}\n{1}", g.Count, Join(g));
            Console.WriteLine("{0}", cnt);
            foreach (var v in array)
                Console.WriteLine("{0}", v);
        }
    }
}

Measured memory_bytes: 35588
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <unordered_map>
#include <cmath>
int main() {
	int n;
	std::vector<int> a;
	
	std::cin >> n;
	for (int i = 0; i < n; i++)
	{
		int num;
		std::cin >> num;
		a.push_back(num);
	}
	std::sort(a.begin(), a.end());

	double ans = a[0];
	for (int i = 1; i < n; i++)
	{
		ans = (ans + (double)a[i]) / (double)2;
	}
	
	std::cout << ans << "\n";	
}

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

using namespace std;

int v[105];
char s[105][105];
char aux[105];

int main(){
    int n,l,i,j;

    cin>>n>>l;

    for(i=1;i<=n;i++){
        cin>>s[i];
        v[i]=i;
    }

    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            if(i!=j)
                if(strcmp(s[i],s[j])<0){
                    strcpy(aux,s[i]);
                    strcpy(s[i],s[j]);
                    strcpy(s[j],aux);
                }

    for(i=1;i<=n;i++)
        cout<<s[i];

    return 0;
}


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

int main() { 
  int N, M;
  int s, c;
  cin >> N >> M;
  
  vector<int> n(N, 10);
  
  for(int i = 0; i < M; i++) {
    cin >> s >> c;
    if(N != 1 && s == 1 && c == 0) {
        cout << -1 << endl;
        return 0;
    }
    if(n[s-1] == 10) {
      n[s-1] = c;
    }
    else if(n[s-1] != c){
      cout << -1 << endl;
      return 0;
    }
  }
  
  if(N == 1) {
      if(n[0] == 10) {
        cout << 0 << endl;
      }
      else {
        cout << n[0] << endl;
      }
  }
  else {
    if(n[0] == 10) {
        cout << 1;
    }
    else {
        cout << n[0];
    }
    for(int i  = 1; i < N; i++) {
      if(n[i] == 10)
        cout << 0;
      else
      	cout << n[i];
    }
    cout << endl;
  }
  return 0; 
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int socket = 1;
		int tap = 0;

		// 入力を受け取る
		int capacity = scan.nextInt();
		int border = scan.nextInt();

		while(socket < border) {
			tap++;
			socket += capacity - 1;
		}

		System.out.println(tap);
	}
}


Measured memory_bytes: 23380
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=998244353;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


int main(){
    LL n,k;cin >> n >> k;
    if(2*k-1>n){
        puts("-1");
        return 0;
    }
    vector<LL> a(n),b(n),c(n);
    int cnt = k;
    for (int i = 0; i < n; i++) {
        a[i] = cnt++;
    }
    for (int i = 0; i + n / 2 < n; i++) {
        b[n / 2 + i] = cnt++;
    }
    for (int i = 0; i < n / 2; i++) {
        b[i] = cnt++;
    }
    for (int i = 0; i + n / 2 < n; i++) {
        c[n / 2 + i] = cnt + i * 2;
    }
    for (int i = 0; i < n / 2; i++) {
        c[i] = cnt + i * 2 + 1;
    }
    for (int i = 0; i < n; i++) {
        cout << a[i] << " " << b[i] << " " << c[i] << endl;
    }
    return 0;
}


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

const int N = 6;
const int MAXCOST = 101;

struct Edge {
  int to, num;
};

vector<Edge> G[N];
int mem[N][MAXCOST];

void init() {
  G[0].push_back((Edge){3,'0'});
  G[0].push_back((Edge){4,'1'});
  G[1].push_back((Edge){3,'1'});
  G[1].push_back((Edge){4,'0'});
  G[2].push_back((Edge){1,'0'});
  G[2].push_back((Edge){4,'1'});
  G[3].push_back((Edge){5,'1'});
  G[4].push_back((Edge){3,'0'});
  G[5].push_back((Edge){1,'1'});
  G[5].push_back((Edge){2,'0'});
}

int dfs(int p, int cost, const string &line) {
  int &res = mem[p][cost];
  if(res != -1) return res;
  res = 0;
  if(cost == line.size()) return res = (p == 1);
  for(int i = 0; i < G[p].size(); ++i) {
    if(G[p][i].num != line[cost]) continue;
    if(dfs(G[p][i].to, cost+1, line)) return res = 1;
  }
  return res;
}

int main() {
  init();
  string line;
  while(getline(cin, line) && line != "#") {
    fill(mem[0], mem[N], -1);
    if(dfs(0, 0, line)) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 1196
N = int(input())

dp = [[0]*3 for i in range(N+1)]

for i in range(N):
  a, b, c = map(int, input().split())
  dp[i+1][0] = max(dp[i][1], dp[i][2]) + a
  dp[i+1][1] = max(dp[i][0], dp[i][2]) + b
  dp[i+1][2] = max(dp[i][0], dp[i][1]) + c

#print(dp)
print(max(dp[-1]))

Measured memory_bytes: 28716
n = int(input())
a,b = map(int, input().split())
p = list(map(int, input().split()))
ans = [0]*3
for i in p:
  if i <= a:
    ans[0] += 1
  elif a < i <= b:
    ans[1] += 1
  else:
    ans[2] += 1
print(min(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int ans = 0;
  int num;
  cin >> num;
  vector <int> cards(num);
  for(int i = 0; i < num; i++)
    cin >> cards.at(i);
  sort(cards.begin(), cards.end());
  reverse(cards.begin(), cards.end());
  for(int i = 0; i < num; i++){
    if(i % 2 == 0){
      ans += cards.at(i);
    }
    else ans -= cards.at(i);
  }
  cout << ans << endl;
  
  
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int N;
vector<int> v;
int main(){
    cin >> N;
    for(int i=0; i<N; ++i){
        int a; cin >> a;
        v.push_back(a);
    }
    bool flag = true;
    for(int i=0; i<N; ++i){
        for(int j=0; j<N; ++j){
            if(!flag) break;
            
            if((abs(v[i]-v[j]))%(N-1)==0&&i!=j){
                cout << v[i] << " " << v[j] << endl;
                flag = false;
            }   
        }
        
    }

    return 0;
}


Measured memory_bytes: 3160
from operator import itemgetter
n=int(input())
a=[list(map(lambda x:x=='#',input())) for i in range(n)]
cr,cc=list(map(sum,a)),[sum(map(itemgetter(i),a)) for i in range(n)]
mx=max(cr)
print(-1 if mx==0 else (not sum([cc[i] for i in range(n) if cr[i]==mx]))+n-mx+sum(map(lambda x:x<n,cc)))

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

using namespace std;


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

ll dp[100005];

#define mp make_pair
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define swap(a,b) {a=a^b;b=a^b;a=a^b;}
ll gcd(ll a, ll b){ return b==0 ? a : gcd(b, a%b); }

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

	
    int t=1;
    ll N;
    ll k;

    //cin >> t;
    while(t-->0){
    	  dp[0]=0;
    	  cin>>N>>k;
    	  ll h[N];
    	  for(int i=0;i<N;i++){
    	  	cin>>h[i];
    	  }

    	  // for(int i=0;i<N;i++)
    	  // 	cout<<h[i]<<" ";
    	  // cout<<"\n";

    	  dp[1]= abs(h[1]-h[0])+dp[0];

    	  for(int i=2;i<N;i++){
    	  	dp[i]=abs(h[i]-h[i-1]) + dp[i-1];
    	  	for(int j=1;j<=k && j<=i ;j++){
    	  		dp[i]=min(dp[i], dp[i-j]+abs(h[i]-h[i-j]) ) ;
    	  	}

    	  }
    	 
    	  cout<<dp[N-1];
    	
    }
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f

using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<pair<int,int>,null_type, less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
const int N=1e5+10, mod=1e9+7;
ll dp[N][110];

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int n,m,i,j;
	cin>>n>>m;
	vector<vector<char>> a(n+1,vector<char>(m+1));
	ll dp[n+1][m+1];
	for(i=1;i<=n;i++)for(j=1;j<=m;j++) cin>>a[i][j];
	for(i=0;i<=n;i++)dp[i][0]=0;
	for(i=0;i<=m;i++)dp[0][i]=0;
	
	dp[1][1]=1;
	for(i=1;i<=n;i++){
		for(j=(i==1?2:1);j<=m;j++){
			if(a[i][j]=='#') dp[i][j]=0;
			else dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
		}
	}
	cout<<dp[n][m];
	
}
// check for any potential overflow before submitting


Measured memory_bytes: 9088
def main():
    A,B,C,K = map(int,input().split())
    if K<=A:
        print(K)
    else:
        summ=A
        K-=A
        if K>B:
            K-=B
            if K>0:
                summ-=K
        print(summ)
if __name__=='__main__':
    main()

Measured memory_bytes: 61736
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll h, w;std::cin >> h >> w;
  if(h%3==0||w%3==0){
    std::cout << 0 << '\n';
    return 0;
  }
  ll ans = 1000000000000;
  ans = min({ans, w, h});
  for(int i=1;i<=h-1;i++){
    ll a = w * i;
    ll b = (h-i)*(w/2 + (w%2==1?1:0));
    ll c = (h-i)*(w/2);
    ans = min(ans, max({a, b, c})-min({a, b, c}));
  }
  for(int i=1;i<=w-1;i++){
    ll a = h * i;
    ll b = (w-i)*(h/2 + (h%2==1?1:0));
    ll c = (w-i)*(h/2);
    ans = min(ans, max({a, b, c})-min({a, b, c}));
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 632
// to format a document: ctrl + K -> ctrl + D

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long int;

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

    string S;
    if (R < 1200)
        S = "ABC";
    else if (R < 2800)
        S = "ARC";
    else
        S = "AGC";

    cout << S << endl;

    return 0;
}

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

int main(void){

    int N,i,count = 0;
    cin >> N;
    int d[N];
    for(i = 0; i < N; i++){
        cin >> d[i];
    }
  	sort(d,d+N);
    for(i = 0; i < N-1; i++){
        count++;
        if(d[i] == d[i+1]){
            count--;
        }
    }
    count ++;
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256