akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 100005;
int a[maxn]={0};
long long node[maxn]={0};
int main()
{
    long long sum =0 ;
    int n;
    cin >> n;
    for(int i=0;i<=n;i++){
        cin >> a[i];
        sum+=a[i];
    }
    long long num  = 0 ;
    for(int i=n;i>=0;i--){
        node[i]=node[i+1]+a[i];
    }
    num = 1;
    for(int i=0;i<=n&&num<=sum;i++){

        //cout << num << endl;
        node[i] = min(num,node[i]);
        num = num-a[i];
        if(num<0){
            cout << -1 << endl;
            return 0;
        }

        num*=2;
    }
    sum =0 ;
    for(int i=0;i<=n;i++){
        sum+=node[i];
    }
    cout << sum <<endl;
    return 0;
}


Measured memory_bytes: 4768
from collections import deque
def solve():
    S = list(input())
    T = list(input())

    d = deque(S)
    for _ in range(len(S)):
        d.appendleft(d.pop())
        if list(d) == T:
            print('Yes')
            return
    print('No')


if __name__ == '__main__':
    solve()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int h,w;cin>>h>>w;
    int t[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>t[i][j];
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int a,b;cin>>b;a=t[i][j];
            if(a>b)t[i][j]=a-b;
            else t[i][j]=b-a;
        }
    }
    bool dp[h][w][13000];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            for(int k=0;k<13000;k++){
                dp[i][j][k]=false;
            }
        }
    }
    dp[0][0][t[0][0]]=true;
    int roty[2]={-1,0},rotx[2]={0,-1};
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            for(int q=0;q<2;q++){
                int oi=i+roty[q],oj=j+rotx[q];
                if(oi<0||oj<0)continue;
                for(int k=0;k<13000;k++){
                    if(dp[oi][oj][k]==true){
                        int nkp=k+t[i][j],nkm=k-t[i][j];
                        dp[i][j][nkp]=true;
                        int kk=nkm;
                        if(nkm<0){
                            kk=nkm*(-1);
                        }
                        dp[i][j][kk]=true;
                    }
                }
            }
        }
    }
    for(int i=0;i<13000;i++){
        if(dp[h-1][w-1][i]==true){
            cout<<i<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 81536
#include <stdio.h>
int main(void){
    // Your code here!
    int N;
    int weight[101];
    int lsum,rsum,sa,min;
    int i,j;
    lsum = 0;
    rsum = 0;
    //input
    scanf("%d",&N);
    for(i=1;N>=i;i++){
        scanf("%d",&weight[i]);
        lsum += weight[i];
    }
    min = lsum - rsum;
    //calc sum
    for(j=1;N>=j;j++){
        lsum -= weight[j];
        rsum += weight[j];
        if(lsum >= rsum) sa = lsum - rsum;
        else             sa = rsum - lsum;
        
        if(min > sa)    min = sa;
    }
    printf("%d\n",min);
    
    return 0;
}


Measured memory_bytes: 128
import java.io.*;
import java.util.*;

public class Main {

    static BufferedReader br;
    static StringTokenizer st;

    public static void main(final String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        long N;
        N = readLong();
        long K;
        K = readLong();
        List<Long> H = new ArrayList<>();
        for(int i = 0 ; i < N ; i++){
                H.add(readLong());
        }

        final Solver solver = new Solver();
        solver.solve(N, K, H);
    }

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine().trim());
        return st.nextToken();
    }

    static long readLong() throws IOException {
        return Long.parseLong(next());
    }

    static int readInt() throws IOException {
        return Integer.parseInt(next());
    }
}

class Solver {
    public void solve(long N, long K, List<Long> H) {
        H.sort(Collections.reverseOrder());

        long ans = 0;
        for (int i = (int) K; i < N; i++) {
            ans += H.get(i);
        }
        System.out.println(ans);
    }
}



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

using namespace std;

// 無限大の値
const long long INF = 1LL << 60;

// DP テーブル
long long dp[100010];

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define long long ll

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

int main(){
    int n;
    cin >> n;
    vector<int> h(n,-1);
    rep(i,n){
        cin >> h[i];
    }
    rep(i,100010) dp[i] = INF;
    dp[0] = 0;
    for(int i = 1; i < n; ++i){
        if(i != 1) chmin(dp[i],dp[i-2]+abs(h[i-2]-h[i]));
        chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
    }
    
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1408
def main():
    a=inputList()
    n=a[0]
    k=a[1]

    blue=k
    red=n-k

    for i in range(1,k+1):
        print(solve(red,blue,i))


def solve (red,blue,i):
    if(red<i-1):
        return 0

    ans=comb(red+1,i)*comb(blue-1,i-1)
    return ans%(10**9+7)

def comb(a,b):
    if(a-b<0):
        return 0
    if(a==b):
        return 1

    ans=1
    b=min(b,a-b)
    for i in range(b):
        ans*=a-i
        ans//=i+1

    ans %=10**9+7

    return ans


def inputList():
    a=list(map(int,input().split()))
    return a

def multisort(li,index):
    return sorted(li,key=lambda x: x[index])

if(__name__=='__main__'):
    main()

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

using ll = long long;

namespace MC {
    const int MAX_N = 1000010;   // 10^6
    const ll MOD = 1000000007;  // 10^9+7

    array<ll, 2 * MAX_N + 1> fact;
    array<ll, 2 * MAX_N + 1> inv_fact;  // n!の逆元

    ll pow(ll a, ll b) {
        if (b == 0) return 1;
        else if (b % 2 == 0) {
            ll d = pow(a, b / 2);
            return (d * d) % MOD;
        } else {
            return (a * pow(a, b - 1)) % MOD;
        }
    }

    ll factorial(ll n) {
        return fact[n];
    }

    ll inverse(ll n) {
        return pow(n, MOD - 2);
    }

    ll inverse_factorial(ll n) {
        return inv_fact[n];
    }

    ll nPk(ll n, ll k) {
        if (n < 0 || n < k) return 0;
        else return (factorial(n) * inverse_factorial(n - k)) % MOD;
    }

    ll nCk(ll n, ll k) {
        if (n < 0 || n < k) return 0;
        else return (nPk(n, k) * inverse_factorial(k)) % MOD;
    }

    ll nHk(ll n, ll k) {
        if (n < 0 || k < 0) return 0;
        else if (k == 0) return 1;
        else return nCk(n + k - 1, k);
    }

    // 要素がn個あるとき
    void initialize(int n) {
        if (2 * n > 2 * MAX_N) {
            cerr << "現在のfactのサイズでは足りない可能性があります" << endl;
            exit(1);
        }

        // 階乗%MODを計算
        fact[0] = 1;
        for (ll i = 1; i <= 2 * MAX_N; i++) {
            fact[i] = (i * fact[i - 1]) % MOD;
        }
        // mod逆元の階乗を計算
        inv_fact[2 * MAX_N] = inverse(factorial(2 * MAX_N));
        for (ll i = 2 * MAX_N - 1; i >= 0; i--) {
            inv_fact[i] = ((i + 1) * inv_fact[i + 1]) % MOD;
        }
    }
};

int main() {
    ll H, W, A, B;
    cin >> H >> W >> A >> B;

    MC::initialize(H + W);

    ll ans = 0;
    for (int b = B + 1; b <= W; b++) {
        ans += MC::nCk(H - A + b - 2, H - A - 1) * MC::nCk(A + W - b - 1, A - 1);
        ans %= MC::MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int a,b; cin >> a >> b;
    if(a>0&&a<10&&b>0&&b<10) cout << a*b << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define endl "\n"

using namespace std;


const double PI = acos(-1);



int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, x=0;
    while(n!=0){
        x+=1;
        cin>>n;
    }
    cout<<x<<endl;

    return 0;

}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define ll  long long int
#define scll(x) scanf("%lld",&x)
using namespace std;
ll freq[100000000];
struct boo{
ll l;
ll r;
ll index;
ll result;
};
ll n;
bool comp(boo A,boo B)
{
    ll blocksize=(ll)sqrt(n*1.0);
    if(A.l/blocksize!=B.l/blocksize)
    return A.l/blocksize<B.l/blocksize;
      else
        return A.r<B.r;
}
void query(ll a[],boo st[],ll siz)
{
   ll currL=0,i;
   ll currR=0;
   ll distinct=0;
   for(i=0;i<siz;i++){
        ll le=st[i].l;
        ll ri=st[i].r;
    while(currL<le)
    {
        freq[a[currL]]--;
        if(!freq[a[currL]])
            distinct--;
            currL++;
    }
    while(currL>le)
    {
        freq[a[currL-1]]++;
        if(freq[a[currL-1]]==1)
            distinct++;
             currL--;
    }
    while(currR<=ri)
    {
        freq[a[currR]]++;
        if(freq[a[currR]]==1)
            distinct++;
        currR++;
    }
    while(currR>ri+1)
    {
        freq[a[currR-1]]--;
        if(!freq[a[currR-1]])
            distinct--;
        currR--;
    }
    st[st[i].index].result=distinct;
}
}
int main()
{
    ll i=0,j,m;
    scll(n);
    scll(m);
    ll a[n];
      for(j=0;j<n;j++)
      {
          scll(a[j]);
      }
      ll l1,r1;
      struct boo st[m];
      for(i=0;i<m;i++){
          scll(l1);
          scll(r1);
          l1--;
          r1--;
          st[i].l=l1;
          st[i].r=r1;
          st[i].index=i;
      }
sort(st,st+m,comp);
query(a,st,m);
for(i=0;i<m;i++)
{
printf("%lld\n",st[i].result);
}
//for(j=0;j<i;j++)
    //cout<<st[j].l<<" "<<st[j].r<<"\n";
return 0;
}



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

#define endl '\n'
#define ll long long
#define re register
#define pb(x) push_back(x)
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
const db pi = acos(-1);
const long long infl = LLONG_MAX;

#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 

int32_t main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ll t,i,x,j,y,z=0,k=0,n;
string s;
cin>>n;		ll a[n];

if(n==1)	return cout<<"YES",0;
// n=s.size();
rep(i,0,n,1)	cin>>x,z+=(x&1);

z=z&1;
if(z)	 cout<<"NO";
else  cout<<"YES";
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using i64 = int64_t;

constexpr int INF = 1 << 25;
constexpr int MOD = 1000000007;

class Point {
public:
  double x;
  double y;
  Point(double x_, double y_) : x(x_), y(y_) {};
  ~Point() = default;
  void print();
};

void Point::print() {
  cout << this->x << " " <<  this->y << endl;
}

Point operator+(Point lhs, Point rhs) {
  return Point(lhs.x + rhs.x, lhs.y + rhs.y);
}

// 内分点
Point div_point(Point p1, Point p2, double a, double b) {
  return Point(
    (b * p1.x + a * p2.x) / (a + b),
    (b * p1.y + a * p2.y) / (a + b)
  );
}

// 回転行列
Point rot_point(Point p1, Point p2, double theta) {
  return p1 + Point(
    (p2.x - p1.x) * cos(theta) - (p2.y - p1.y) * sin(theta),
    (p2.x - p1.x) * sin(theta) + (p2.y - p1.y) * cos(theta)
  );
}

void koch(int d, Point p1, Point p2) {
  if (d == 0) return;
  
  auto theta = M_PI * 60. / 180.;
  auto s = div_point(p1, p2, 1., 2.);
  auto t = div_point(p1, p2, 2., 1.);
  auto u = rot_point(s, t, theta);
  
  koch(d - 1, p1, s);
  s.print();
  koch(d - 1, s, u);
  u.print();
  koch(d - 1, u, t);
  t.print();
  koch(d - 1, t, p2);
}

int main() {
  int n;
  cin >> n;
  
  Point a(0., 0.), b(100., 0.);
  a.print();
  koch(n, a, b);
  b.print();
}



Measured memory_bytes: 3380
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  long long N,r;
  string S;
  cin >> N >> S;
  r=0;
  
  if (N%2==1) {cout << "No" << endl;}
  else {
    for (int i=0;i<N/2;i++) {
      //cout << S.at(i) << S.at(i+N/2) << endl;
	  if (S.at(i)!=S.at(i+N/2) && r==0) {r=1;}
	}
	if (r==0) {cout << "Yes" << endl;} else {cout << "No" << endl;}
  }

}

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

using namespace std;

#define sz(a) int(a.size())

struct ConvexHullTrick {
	struct Line {
		double m,b;
		Line(double m,double b):m(m),b(b){}
		double inter(const Line &L)const{
			return (L.b-b) / (m - L.m);
		}
		double eval(double x){
			return m*x + b;
		}
	};
	vector<Line> V;
	vector<double> X;
	int C;
	ConvexHullTrick():C(0){ };
	void add(Line l){
		while(V.size() >= 2){
			if(V[V.size()-2].inter(l) < X.back()){
				V.pop_back();
				X.pop_back();
			} else break;
		}
		if(!V.empty()){
			X.push_back(V.back().inter(l));
		}
		V.push_back(l);
		C = min(C , (int)X.size());
	}
	double eval(double x){
		int p = lower_bound(X.begin(),X.end(), x) - X.begin();
		return V[p].eval(x);
	}
	// only if x are used in increasing order
	double evalConstant(double x){
		while(C < X.size() && x > X[C])C++;
		return V[C].eval(x);
	}
};

int main() {
	int n;
	long long c;
	cin >> n >> c;
	vector <int> h (n);
	for (int &t : h) cin >> t;
	ConvexHullTrick CHT;
	CHT.add(ConvexHullTrick::Line(2*h[n-1],c+1LL*h[n-1]*h[n-1]));

	vector <long long> ans (n);
	for (int i = n-2; i >= 0; i--) {
		ans[i] = CHT.eval(-h[i]) + 1LL*h[i]*h[i];
		CHT.add(ConvexHullTrick::Line(2*h[i],ans[i]+1LL*h[i]*h[i]+c));
	}
	cout << ans[0] << endl;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;

int main()
{
    int n;cin >>n;
    int co=0;
    while(n>0){
        if(n%10==2)co++;
        n/=10;
    }
    cout << co << endl;
    return 0;
}


Measured memory_bytes: 256
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
#include <functional>																							   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra																													   																				   list<int>::iterator it;																								   
																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS//////////////////////////////////////////////////////

int l,r;
int pref_sum[100005];
char s[100005];

///////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	int n, q;
	cin >> n >> q;
	for(int i = 1; i <= n; i++){
		cin >> s[i];
	}
	
	pref_sum[0] = 0;
	for(int i = 1; i <= n; i++){
		if(s[i] == 'C' && s[i-1] == 'A'){
			pref_sum[i] = pref_sum[i-1] + 1;
		}
		else pref_sum[i] = pref_sum[i-1];
	}
	
	//cout << endl << "pref sum: " << endl;
	//for(int i = 1; i <= n; i++){
		//cout << pref_sum[i] << " ";
	//}
	//cout << endl;
	
	
	for(int i = 0; i < q; i++){
		cin >> l >> r;
		cout << pref_sum[r] - pref_sum[l] << '\n';
	}
	
	
    
	return 0;
}


Measured memory_bytes: 1280
s = list(input())
n = int(input())
ret = ""
for i, ss in enumerate(s):
    a = 123 - ord(ss)
    if a == 26:
        a = 0
    if i == len(s) - 1:
        c = ord(ss) + (n % 26)
        if c > 122:
            c -= 26
        ret += chr(c)
        break
    if n < a:
        ret += ss
    else:
        n -= a
        ret += 'a'

print(ret)


Measured memory_bytes: 4152
/*
 *  Created by Andrei Arhire 02/08/2020
 *  Copyright © 2020 Andrei Arhire. All rights reserved.
 */
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lll long long
#define llf __float128
#define lld long double
using namespace std;
const lll NR = 2e5 + 10  ,oo = 2e9 + 10, MOD = 1e9 + 7 ;
const long double pi = 2*acos(0.0);

lld a [ NR ] , st , dr , mid , k ;
int n ;
lld ok ( lld val )  {
    int sol = 0 ;
    for ( int i = 1 ; i <= n ; ++ i )   {
        sol += ((int)((lld)( a [ i ] / val ))) ;
    }
    return sol ;
}

signed main () {
    int i , cnt ;

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0) ;
   cin >> n >> k ;
   for ( i = 1 ; i <= n ; ++ i )    {
       cin >> a [ i ] ;
   }

   st = 0 ;
   dr = 1e9 ;
   for ( cnt = 1 ; cnt <= 300 ; ++ cnt )    {
        mid = ( st + dr ) / 2 ;
        if ( ok ( mid ) <= k )  {
            dr = mid ;
        }   else    {
            st = mid ;
        }
   }
   int x = st ;
   if ( ( st - x ) >= 0.0000000000001 ) cout << x + 1 << '\n' ;
   else                     cout << x << '\n' ;
    return 0 ;
}


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


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

  sort(a.rbegin(),a.rend());
  ll ans=0;
  int ti=n-1;
  for(int i=0;i<n;++i){
    int l=2;
    if(i==0)l=1;
    for(int j=0;j<l;++j){
      if(ti>0){
        ans+=a[i];
        ti--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4792
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    ll sum=0,k=s.length();
    for(ll i=0;i<k;i++)
    if(s[i]=='o')
    sum++;
    if(sum+15-k>=8)
    cout<<"YES";
    else
    cout<<"NO";
}


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

int main() {
  long long N,M,Z,A,B,C,ans,a,b;
  cin >>N>>M;
  ans=0;
  for(int i=0;i<M;i++){
    cin>>A;
    ans+=A;
  }
  if(ans>N){
    cout<<-1<<endl;
    return 0;
  }
  cout<<N-ans<<endl;
}


Measured memory_bytes: 3640
import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException{
    BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
    String s=buf.readLine();
    String[] x=s.split(" ");
    int a=Integer.parseInt(x[0]);
    int b=Integer.parseInt(x[1]);
    int c=Integer.parseInt(x[2]);
    int tmp;
    
    if(b<a){
        tmp=b;
        b=a;
        a=tmp;
    }
    if(c<b){
        tmp=c;
        c=b;
        b=tmp;
    }
    if(b<a){
        tmp=a;
        a=b;
        b=tmp;
    }
    System.out.println(a+" "+b+" "+c);
  }
}

Measured memory_bytes: 24088
import java.util.Scanner;

public class Main {

    static long ans = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        int[] a = new int[q];
        int[] b = new int[q];
        int[] c = new int[q];
        int[] d = new int[q];
        for (int i = 0; i < q; i++) {
            a[i] = Integer.parseInt(sc.next());
            b[i] = Integer.parseInt(sc.next());
            c[i] = Integer.parseInt(sc.next());
            d[i] = Integer.parseInt(sc.next());
        }
        int[] e = new int[n + 1];
        dfs(1, n, 1, e, a, b, c, d, q, m);
        System.out.println(ans);
    }

    private static void dfs(int v, int n, int num, int[] e, int[] a, int[] b, int[] c, int[] d, int q, int m) {
        if (n < v) {
            long temp = 0;
            for (int i = 0; i < q; i++) {
                if (e[b[i]] - e[a[i]] == c[i]) {
                    temp += d[i];
                }
            }
            ans = Math.max(ans, temp);
            return;
        }
        for (int i = num; i <= m; i++) {
            e[v] = i;
            dfs(v + 1, n, i, e, a, b, c, d, q, m);
        }
    }
}

Measured memory_bytes: 36748
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
#define int long long
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
int a[114514],b[114514];
signed main(){
	ic(n)
	int sum=0;
	rep(0,i,n)cin>>a[i];
	rep(0,i,n){
		if(a[i]<114514){
			b[a[i]]++;
		}
		else{
			sum++;
		}	
	}		
	rep(1,i,114514){
		if(b[i]>=i)sum+=b[i]-i;
		else sum+=b[i];
	}
	c(sum)	
}	

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//---------------------------------------------------------------------------------------------------
ll MOD = 1000000007;
ll f[201010], rf[201010];
ll inv(ll x) {
    ll res = 1;
    ll k = MOD - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % MOD;
        y = (y * y) % MOD;
        k /= 2;
    }
    return res;
}
void init() {
    f[0] = 1;
    for(int i = 1; i < 201010; i++) f[i] = (f[i - 1] * i) % MOD;
    for(int i = 0; i < 201010; i++) rf[i] = inv(f[i]);
}
ll C(int n, int k) {
    ll a = f[n]; // = n!
    ll b = rf[n-k]; // = (n-k)!
    ll c = rf[k]; // = k!

    ll bc = (b * c) % MOD;

    return (a * bc) % MOD;
}
//---------------------------------------------------------------------------------------------------

void add(ll &a, ll b)
{
    a = (a+b)%MOD;
}

int main()
{
    init();
    ll n, m, k;
    cin >> n >> m >> k;
    ll ans = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            ll fline = (m-j)*(m-j-1)/2;
            ll linesum = (j+1)*j/2 + fline;
            ll lineex = (1+ n-1-i) * (n-1-i) / 2;
            add(ans, fline);
            add(ans, (n-1-i)*linesum % MOD);
            add(ans, lineex * m % MOD);
        }
    }
    ans = C(n*m-2, k-2) * ans % MOD;
    cout << (ans+MOD)%MOD << endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 10000100
//#define NIL -1

LL lpow(LL x, LL n){
    LL ans = 1;
    while(n>0){
        if((n&1)==1){
            ans = ans * x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

int main() {
    string s;
    cin >> s;
    LL n=s.size();
    vector<LL> keta(n, 0);
    LL start=lpow(2,n-1);
    LL ans=0;
    keta[0]=start;
    for(LL i=0; i<n; i++){
        LL tmp=0;
        LL s_num=s[n-1-i]-'0';
        for(LL j=n-1; j>=0; j--){
            tmp*=10;
            tmp+=keta[j]*s_num;
            //cout << keta[j] << endl;
        }
        //cout << tmp << endl;
        ans+=tmp;
        for(LL j=n-1; j>=0; j--){
            keta[j]=keta[j-1]/2;
        }
        if(n>=2){
            keta[0]=start/2;
        }
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main(){
	string s1,s2;
	int ans=0;
	cin >> s1;
	s2 ="CODEFESTIVAL2016";
	for(int i=0;i<16;i++){
		if(s1[i]!=s2[i])ans+=1;
	}
	cout << ans << endl;
	return 0;
}

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

#define ROOP(i,n) for(i=0;i<n;i++)

//prototype declaration
int getint();
long long getllint();
double getdint();
char getch();
void setstring(char *s);
void showint(int i);
void showllint(long long i);
void showdouble(double i);
void showchar(char c);
void showstring(char *s);

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int min(int a, int b) {
	return a < b ? a : b;
}

int main(void) {
	int a, b, i, j;
	a = getint();
	b = getint();
	if (a % 2 == 0 || b % 2 == 0) {
		showstring("No");
	} else {
		showstring("Yes");
	}
	return 0;
}

int getint() {
	int i;
	scanf("%d", &i);
	return i;
}

long long getllint() {
	long long i;
	scanf("%lld", &i);
	return i;
}

double getdint() {
	double i;
	scanf("%lf", &i);
	return i;
}

char getch() {
	char c;
	scanf("%c", &c);
	return c;
}

void setstring(char *s) {
	scanf("%s", s);
}

void showint(int i) {
	printf("%d\n", i);
}

void showllint(long long i) {
	printf("%lld\n", i);
}

void showdouble(double i) {
	printf("%lf\n", i);
}

void showchar(char c) {
	printf("%c\n", c);
}

void showstring(char *s) {
	printf("%s\n", s);
}


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

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

string s;

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

    cin >> s;

    if (isupper(s[0]))
        cout << "A\n";
    else
        cout << "a\n";

    return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

int main()
{
    vector<int> h; int t;
    REP(10){ cin >> t; h.push_back(t);}
    sort(all(h));

    cout << h[9] << endl;
    cout << h[8] << endl;
    cout << h[7] << endl;

    return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
long double EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////////////////

void a(){
    cout<<"Heisei"<<endl;
}
void b(){
    cout<<"TBD"<<endl;
}

int main(){fastio;
    string s;cin>>s;
    string t="2019/04/30";
    rep(i,0,9){
        if(i==4||i==7)continue;
        if(s[i]<t[i]){
            a();return 0;
        }else if(s[i]>t[i]){
            b();return 0;
        }
    }
    a();
    return 0;
}


Measured memory_bytes: 256
from collections import deque
n,k=map(int,input().split())
v=list(map(int,input().split()))
cs_l=[0]
cs_r=[0]
cs1,cs2=0,0
for i in range(n):
  cs1+=v[i]
  cs2+=v[-i-1]
  cs_l.append(cs1)
  cs_r.append(cs2)

ans=0
for i in range(1,k+1):# 取得する操作をi回行う
  for l in range(i+1): # 左からl個取る
    r=i-l
    if r+l>=n:
      point=cs_r[-1]
      minus=[vi for vi in v if vi<0]
      n_minus=min(n-k,len(minus))
    else:
      point=cs_l[l]+cs_r[r]
      minus=[vi for vi in v[:l] if vi<0]
      if r>0:
        minus+=[vi for vi in v[-r:] if vi<0]
      n_minus=min(k-r-l,len(minus))
    if n_minus>0:
      minus.sort()
      point-=sum(minus[:n_minus])
    ans=max(ans,point)

print(ans)



Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m;
cin>>n>>m;
int sum=0;
if((n>1))
{
    sum=sum+(n*(n-1))/2;
}
if(m>1)
{
    sum=sum+(m*(m-1))/2;
}
cout<<sum<<endl;
    return 0;
}

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

template <class T, class U, class BinaryOperation = std::multiplies<>>
constexpr T power(T a, U n, T init = 1,
                  BinaryOperation binary_op = BinaryOperation{}) {
  static_assert(std::is_integral_v<U> and not std::is_same_v<U, bool>);
  assert(n >= 0);
  while (n) {
    if (n & 1) init = binary_op(init, a);
    if (n >>= 1) a = binary_op(a, a);
  }
  return init;
}

template <class T>
std::map<T, int> factorize(T n) {
  std::map<T, int> res;
  for (T i = 2; i * i <= n; ++i)
    while (n % i == 0) ++res[i], n /= i;
  if (n != 1) ++res[n];
  return res;
}

template <class T>
std::tuple<T, T, T> extgcd(T a, T b) {
  static_assert(std::is_integral_v<T> and std::is_signed_v<T>);
  std::array<T, 2> x{1, 0}, y{0, 1};
  while (b) {
    T q = a / b;
    std::swap(x[0] -= q * x[1], x[1]);
    std::swap(y[0] -= q * y[1], y[1]);
    std::swap(a -= q * b, b);
  }
  if (a < 0) x[0] = -x[0], y[0] = -y[0], a = -a;
  return {x[0], y[0], a};
}

int main() {
  using namespace std;
  cin.tie(nullptr)->sync_with_stdio(false);
  int64_t n;
  cin >> n;
  n *= 2;
  vector<int64_t> v;
  for (auto [p, e] : factorize(n)) v.push_back(power(p, e));
  int m = size(v);
  auto ans = n - 1;
  for (int bt = 1; bt < (1 << m) - 1; ++bt) {
    int64_t a = 1, b = 1;
    for (int i = 0; i < m; ++i)
      if (bt >> i & 1)
        a *= v[i];
      else
        b *= v[i];
    auto [x, y, g] = extgcd(a, b);
    assert(g == 1);
    if (x < 0) {
      x += b;
      y -= a;
    }
    y = -y;
    assert(x > 0), assert(y > 0);
    assert(a * x - b * y == 1);
    ans = min(ans, b * y);
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3660
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double d = 0.0;
        int n = sc.nextInt();
        for (int i=0;i<n;i++)d+=1/sc.nextDouble();
        System.out.println(1/d);
    }
}


Measured memory_bytes: 37980
import java.util.Scanner;

public class Main {
	public static void main(String[] args){



		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();

		int a = 0;
		for(int i=1;i<50000;i++) {
			if((int)(i*1.08)==n) {
				System.out.println(i);
				a=i;
				break;
			}

		}
		if(a==0)System.out.println(":(");
	}
}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/


Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int d,n;
  cin >> d >> n;
  int ans = n;
  rep(i,d) ans *= 100;
  if(n==100) {
    n = 1;
    rep(i,d) n *= 100;
    ans += n;
  } 
  cout << ans << endl;
}


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

using namespace std;

int main(){
  int H,W;
  cin>>H>>W;
  char c[105][105];
  for(int h=1;h<=H;h++){
    for(int w=1;w<=W;w++){
      cin>>c[h][w];
    }
  }

  for(int h=1;h<=H;h++){
    for(int w=1;w<=W;w++){
      cout<<c[h][w];
    }
    cout<<"\n";
    for(int w=1;w<=W;w++){
      cout<<c[h][w];
    }
    cout<<"\n";
  }

  return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;


int main()
{
	FAST;
	string str;
	cin >> str;
	
	if(str.size()&1)
	{
	    cout << "No";
	    return 0;
	}
	sort(str.begin() , str.end());
	for(int i=0 ; i<str.size() ; i++)
    {
        if(str[i] != str[i+1])
        {
            cout << "No";
            return 0;
        }
        i++;
    }
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
import math

x = int(input())

ans = 1
for b in range(2, int(math.sqrt(x)) + 1):
  for p in range(1, int(math.sqrt(x)) + 1):
    bp = b ** p
    if bp <= x:
      ans = max(bp, ans)
    else:
      break
      
print(ans)

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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    int N;
    cin >> N;
    int ans=0;
    if(N>=105) ans++;
    if(N>=135) ans++;
    if(N>=165) ans++;
    if(N>=189) ans++;
    if(N>=195) ans++;
    
    cout << ans << endl;
    return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

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


	ll ans = 0LL;
	using state = tuple<int, int>;
	priority_queue<state> pq;

	rep(i, n) if(b[i] > a[i]) pq.push(state(b[i], i));

	while(!pq.empty()){
		int pos = get<1>(pq.top()); pq.pop();
		const int ppos = (pos + n - 1) % n;
		const int npos = (pos + 1) % n;
		const int thr = max({a[pos], b[ppos], b[npos]});
		const int diff = b[ppos] + b[npos];
		const int num = (b[pos] - thr + diff - 1) / diff;

		ans += num;
		b[pos] -= diff * num;

		const int nthr = max({ a[npos], b[(npos + n - 1) % n], b[(npos + 1) % n]});

		if (b[npos] > nthr) {
			pq.push(state(b[npos], npos));
		}

		const int pthr = max({a[ppos], b[(ppos + n - 1) % n], b[(ppos + 1) % n]});

		if (b[ppos] > pthr)	{
			pq.push(state(b[ppos], ppos));
		}
	}


	rep(i, n) if(a[i] != b[i]) ans = -1;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3956
function Main(input){
	input=input.split("\n");
	let x=parseInt(input[0],10);
	let h = (x / 3600 | 0);
	let m = (x - h * 3600) / 60 | 0;
	let s = x - h * 3600 - m * 60;
	console.log("%d:%d:%d", h, m, s);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 15096
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;
ll t[101];

ll gcd(ll x, ll y){
		if(y == 0)return x;
		else return gcd(y, x % y);
}

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)cin >> t[i];
	if(n == 1){
			cout << t[0] << endl;
			return 0;
	}
	ll gc = (t[0] / gcd(t[0], t[1])) * t[1];
	for(int i = 2; i < n; i++){
			gc = (gc / gcd(gc, t[i])) * t[i];
	}
	cout << gc << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, k;
string s;
int mypow(int a, int b) {
	if (!b)return 1;
	if (b % 2)return mypow(a, b - 1) * a;
	int memo = mypow(a, b / 2);
	return memo * memo;
}
signed main() {
	cin >> n >> k >> s;
	k = min(k, (int)13);
	char mi = 'z';
	rep(i, n)mi = min(mi, s[i]);
	string ans = s, t = s;
	reverse(t.begin(), t.end());
	s += t;
	rep(i, n + 1) {
		t = s.substr(i, n);
		int cnt = 0;
		for (int j = n - 1; j >= 0; j--) {
			if (t[j] == mi)cnt++;
			else break;
		}
		if (n <= mypow(2, k - 1) * cnt) {
			ans = min(ans, string(n, mi));
			continue;
		}
		string r = t.substr((mypow(2, k - 1) - 1) * cnt, n - mypow(2, k - 1) * cnt) + string(mypow(2, k - 1) * cnt, mi);
		reverse(r.begin(), r.end());
		ans = min(ans, r);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

int main(){
   int n;
   cin>>n;
   int a[n+1];
   int b[n+1];
   int su=0;
   rep1(i,n){
       cin>>a[i];
       b[i]=0;
   }
   for (int i=n; i>0; --i){
       int p=1;
       int co = a[i];
       for(int j = i; j <= n; j += i) {
            co ^= b[j];
        }
       if (co%2==1){
           b[i]=1;
           su++;
       }
       
   }
   if (su==0){
       cout<<0<<endl;
   }
   else{
        cout<<su<<endl;
        rep1(i,n){
            if (b[i]==1){
                cout<<i;
                cout<<" ";
            }
        }
        cout<<endl;
   }
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define MOD 1000000007
#define MAX 3005
int dp[MAX][MAX];
signed main()
{
	int n,i,j;
	cin>>n;
	string s;
	cin>>s;
	dp[0][1]=1;
	for(i=1;i<n;i++)
	{
		dp[i][0]=0;
		dp[i][n+1]=0;
		if(s[i-1]=='<')
		for(j=1;j<=i+1;j++)
		{
			if(dp[i-1][j-1]>0||dp[i][j-1]>0)
			dp[i][j]=(dp[i][j-1]+dp[i-1][j-1])%MOD;
		}
		if(s[i-1]=='>')
		for(j=i+1;j>=1;j--)
		{
			if(dp[i-1][j]>0||dp[i][j+1]>0)
			dp[i][j]=(dp[i][j+1]+dp[i-1][j])%MOD;
		}
	
	}
	int x=0;
	for(j=1;j<=n;j++)
	x=(x+dp[n-1][j])%MOD;
	cout<<x<<"\n";

}

Measured memory_bytes: 68992
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define lp(i, n) for (int i = 0; i < (n) ; ++i)
#define sz(v) (ll)(v).size()
#define int long long
#define mod 1000000007

void solve() {
        int n; cin>> n;
        int sm= 0;
        for (int i= 1; i<= n; i++) {
                for (int j= 1; j<= n; j++) {
                        for (int k= 1; k<= n; k++) {
                                sm+= __gcd(i, __gcd(j, k));
                        }
                }
        }
        cout << sm;
}

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int t = 1;
        //cin >> t;
        while ( t-- ) {
                solve();
        }
return 0;
}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	// Read problems carefully and always check constraints.
	const int inf = 1e9;
	int n, m;
	cin >> n >> m;
	vector<int> a(m), b(m), c(m);
	for(int i = 0; i < m; i++) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--;
		b[i]--;
	}             
	vector<vector<int>> dist(n, vector<int>(n));
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(i == j) {
				dist[i][j] = 0;
			}
			else {
				dist[i][j] = inf;
			}
		}
	}
	for(int i = 0; i < m; i++) {
		dist[a[i]][b[i]] = c[i];
		dist[b[i]][a[i]] = c[i];
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			for(int k = 0; k < n; k++) {
				dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < m; i++) {
		bool flag = false;
		for(int j = 0; j < n; j++) {
			for(int k = 0; k < n; k++) {
				if(dist[j][k] == dist[j][a[i]] + c[i] + dist[b[i]][k]) {
					flag = true;
				}
			}
		}
		if(!flag) {
			ans++;
		}
	}
	cout << ans << endl;
	
	return 0;	
}


Measured memory_bytes: 384
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){

    int n;
    string s;
    IN n >> s;
    vi w(n),e(n);

    (s[0] == 'W')? w[0] = 1 : e[0] = 1;
    
    rep(i,1,n){
	if(s[i] == 'W'){
	    w[i] = w[i-1] + 1;
	    e[i] = e[i-1];
	}else{
	    w[i] = w[i-1];
	    e[i] = e[i-1] + 1;
	}
    }
    
    int ans = n;

    rep(i,0,n){
	ans = min(ans,  ((i > 0)?w[i]:0) + (e[n-1] - e[i]));
    }
    P(ans);
    return  0;
}


Measured memory_bytes: 3076
#include<stdio.h>

int main(){
  int i, N, K, D, P, disp;
  disp = 1;

  scanf("%d %d", &N, &K);

  for(i=1; i<=N; i++){
    D = disp*2;
    P = disp+K;
    if(D<P){
      disp = D;
    } else{
      disp = P;
    }
  }
  printf("%d\n", disp);
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const string YES = "";
const string NO  = "";

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

    int h, a, cnt;

    cin >> h >> a;

    cnt = 0;
    while (h > 0) {
        h -= a;
        cnt++;
    }

    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
#include <climits>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int n,i;

int main() {
    cin >> n >>i;
    int res = n-i+1;
    put(res);
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;

template <class RandomIt>
RandomIt partition_(RandomIt first, RandomIt last) {
    using T=typename RandomIt::value_type;
    T x=last[-1];
    RandomIt it=first-1;
    for (RandomIt it2=first; it2<last-1; ++it2)
        if (*it2 <= x) {
            ++it;
            swap(*it, *it2);
        }

    swap(*++it, last[-1]);
    return it;
}

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

    vector<int> A(n);
    for (size_t i=0; i<n; ++i)
        scanf("%d", &A[i]);

    vector<int>::iterator pivot=partition_(A.begin(), A.end());
    for (vector<int>::iterator it=A.begin(); it<pivot; ++it)
        printf("%d ", *it);

    printf("[%d] ", *pivot);

    for (vector<int>::iterator it=pivot+1; it<A.end(); ++it)
        printf("%d%c", *it, it<A.end()-1? ' ':'\n');

    return 0;
}

Measured memory_bytes: 2788