akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

enum class ENextSun { SUN = 7, MON = 6, TUE = 5, WED = 4, THU = 3, FRI = 2, SAT = 1 };

int main()
{
	std::string S = "";
	std::cin >> S;

	if (S == "SUN")
	{
		std::cout << static_cast<int>(ENextSun::SUN) << "\n";
	}
	else if (S == "MON")
	{
		std::cout << static_cast<int>(ENextSun::MON) << "\n";
	}
	else if (S == "TUE")
	{
		std::cout << static_cast<int>(ENextSun::TUE) << "\n";
	}
	else if (S == "WED")
	{
		std::cout << static_cast<int>(ENextSun::WED) << "\n";
	}
	else if (S == "THU")
	{
		std::cout << static_cast<int>(ENextSun::THU) << "\n";
	}
	else if (S == "FRI")
	{
		std::cout << static_cast<int>(ENextSun::FRI) << "\n";
	}
	else if (S == "SAT")
	{
		std::cout << static_cast<int>(ENextSun::SAT) << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<ll, ll>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (ll i = begin; i < n; i++)
#define repe(i, begin, n) for (ll i = begin; i <= n; i++)
#define repr(i, begin, n) for (ll i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (ll i = begin; i >= end; i--)

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

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

const ll inf = 1000000007;
const ll MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

long long modpow(long long a, long long b) {
  a %= MOD;
  long long res = 1;
  while (b) {
    if (b & 1) {
      res = (res * a) % MOD;
    }
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}

string L;
double eps = 1e-9;

int main() {
  cin >> L;

  ll ans = 0;
  ll pre = 1;
  ll len = L.size();
  rep(i, 0, len) {
    if (L[i] == '1') {
      ans += pre * modpow(3, len - i - 1) % MOD;
      ans %= MOD;
      pre *= 2;
      pre %= MOD;
    }
  }
  ans += pre;
  ans %= MOD;

  cout << ans;
}


Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
ll dp[110][100010];

int main(){

    ll t;
    t=1;
    while(t--){
ll n;
cin>>n;
ll k;
cin>>k;
int sum=0;
int weight[n+1];
int values[n+1];

f(i,1,n+1){
cin>>weight[i];
    cin>>values[i]; 
    sum+=values[i];
}
f(i,0,n+1){
    f(j,0,sum+1){
        dp[i][j]=INT_MAX;
    }
}


f(i,0,n+1){
    f(j,0,sum+1){

        if(j==0){dp[i][j]=0;continue;}

        if(i==0){continue;}
    dp[i][j]=dp[i-1][j];    
if (j-values[i]>=0){
  //  cout<<" here "<<i<<" "<<j<<" fg"

dp[i][j]=min(weight[i]+dp[i-1][j-values[i]],dp[i-1][j]);
}

    }
}

ll fl=0;
for (int j=sum;j>=0;j--){
    if(dp[n][j]<=k){
            cout<<j<<endl;
        fl=1;
            break;
    }
}
if(!fl){
  cout<<"0"<<endl;
}

    }


}

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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


int main(){
  int N,H,W;
  cin>>N>>H>>W;
  cout << (N-H+1)*(N-W+1) << endl;
  return 0;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
 using namespace  std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// What follows is a magical ordered_set data structure.
// Supports the following functions:
// find_by_order(ll k) - returns k'th smallest element (0-indexed)
// order_of_key(ll k) - returns number of elements strictly smaller than k.
using namespace __gnu_pbds;
#define ordered_set tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> 

#define mp make_pair
#define pb push_back
#define ff first
#define ss second
const double pi=3.1415926535897932384626433832;
const long long mod= 1e9+7;
//long long primeset[5000000]={};
typedef complex<double> cd;
typedef long long ll;
typedef double ld;
//#define For(i,0,n) for(long long i = 0 ; i<n ;i++) 
cd fast_exp(cd a, long long b)
{
    if (b == 0)
        return 1;
    
    cd res = fast_exp(a, b / 2);
        
    res = res * res;
    
    if (b % 2 == 1)
        res = res * a;
    
    return res;
}
 
long long fastexpon(long long a,long long b,long long mod)
{
    if(b==0)
        return 1;
    
    long long res=fastexpon(a,b/2,mod);
    
    res=(res*res)%mod;
    if(b%2==1)
        res= (res * a)%mod;
 
    return res;
}
 
 
//TEMPLATE ENDS HERE!!!! ------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------------------------
 
 
 
 
 
 
 struct custom
{
    bool operator()(ll a, ll b)
    {
        return a > b;
    }
};


int main()
 {
        
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    string s;
    cin>>s;
    ll len = s.size();
    ll cur = 10;
    ll dp[len][13]={};

    if(s[len-1]=='?')
    {
        for(ll i = 0 ; i<10 ; i++)
        dp[len-1][i]=1;
    }
    else
    {
        ll d= (ll)s[len-1] - (ll)'0';
        dp[len-1][d] =1;
    }
    for(ll i = len-2 ; i>=0 ; i--)
    {
        
        if( s[i] == '?' )
        {
            for(ll j = 0 ; j<13 ;j++)
            {
                for(ll c = 0 ; c<10 ; c++)
                {
                    dp[i][(j+c*cur)%13] =  (dp[i][(j+c*cur)%13]+dp[i+1][j])%mod;  
                }
            }
        }
        else
        {
            for(ll j = 0 ; j<13 ; j++)
            {
                ll d = (ll)s[i] - (ll)'0';
                dp[i][(j+d*cur)%13] = (dp[i][(j+d*cur)%13] + dp[i+1][j])%mod;
            }
        }

        cur = (cur*10)%13;
    }


    cout<<dp[0][5]<<endl;
    //cout<<'\n'<<"time elapsed: "<<clock()*1000.0 / CLOCKS_PER_SEC<<" ms"<<'\n';
    return 0;
    
}

Measured memory_bytes: 10624
import java.util.Scanner;

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

        int N = scanner.nextInt();
        char[] S = scanner.next().toCharArray();

        char current = S[0];
        int count = 1;
        for (int i = 1 ; i < N ; i++) {
            if (S[i] != current) {
                count++;
                current = S[i];
            }
        }

        System.out.println(count);
    }
}


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

int main(){
  int A,B;
  cin >> A >> B;
  
  int cnt = 0;
  for(int i = A; i <= B; ++i){
    if((i/10000 == i%10) && ((i%10000)/1000) == ((i%100)/10)){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(void)
{
	int ba, f, c1, c2;
	int n, i, j, k;
	int ta[105], ha[105];
	
	while(1){
		
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		
		for (i = 0; i < n; i++){
			scanf("%d", &ta[i]);
		}
		
		sort(ta, ta + n);
		j = 0;
		k = 0;
		
		for (i = 1; i <= 2 * n; i++){
			
			if (ta[k] != i){
				ha[j] = i;
				j++;
			}
			else {
				k++;
			}
		}
		
		ba = 0;
		f = 0;
		
		while (1){
			
			if (f == 0){
				
				for (j = 0; j < n; j++){
					if (ta[j] > ba){
						
						ba = ta[j];
						ta[j] = 0;
						f = 1;
						break;
					}
				}
				if (f == 0){
					f = 1;
					ba = 0;
				}
			
			}
			
			c1 = 0;
			
			for (j = 0; j < n; j++){
				if (ta[j] != 0){
					c1++;
				}
			}
				
			if (c1 == 0){
				break;
			}
			
			if (f == 1){
				
				for (j = 0; j < n; j++){
					if (ha[j] > ba){
						
						ba = ha[j];
						ha[j] = 0;
						f = 0;
						break;
					}
				}
				if (f == 1){
					f = 0;
					ba = 0;
				}
				
			}
			c2 = 0;
				
			for (j = 0; j < n; j++){
				if (ha[j] != 0){
					c2++;
				}
			}
				
			if (c2 == 0){
				break;
			}
		}
		printf("%d\n%d\n", c2, c1);
		
	}
	
	return (0);
}

Measured memory_bytes: 1044
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;

const ll MOD = 1e9+7;
const ll INF = 1e18+7;

signed main(){
	int h, w, d;
	cin >> h >> w;
	vector<vector<int>> a(h, vector<int>(w));
	for(auto& x : a)
		for(auto& y : x)
			cin >> y;

	vector<int> v(h * w);
	for(int i = 0; i < h; ++i){
		for(int j = 0; j < w; ++j){
			v[i * w + (i & 1 ? w - 1 - j : j)] = a[i][j];
		}
	}
	vector<int> t;
	for(int i = 0; i < h * w - 1; ++i){
		if(v[i] % 2){
			t.push_back(i);
			++v[i + 1];
		}
	}

	auto g = [&](int x){
		int i = x / w;
		int j = (i & 1 ? w - 1 - x % w : x % w);
		return make_pair(i + 1, j + 1);
	};

	cout << t.size() << endl;
	for(auto& x : t){
		auto p = g(x);
		auto q = g(x + 1);
		cout << p.first << " " << p.second << " " << q.first << " " << q.second << endl;
	}
}


Measured memory_bytes: 4728
#include <stdio.h>

int main(void)
{
	int h, w, i, j;

	while (scanf("%d%d", &h, &w) && h != 0 && w != 0){
		for (i = 0; i < h; i++){
			for (j = 0; j < w; j++){
				if (i == 0 || i == h - 1 || j == 0 || j == w - 1){
					printf("#");
				}
				else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 568
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
#include <stack>
#include <map> // pair
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
typedef std::stack<int> IntStack;
typedef std::stack<char> charStack;
#define START 0
#define FORWARD 1
#define BACK 2
using namespace std;
using ll = long long;
typedef pair <ll, ll > pll;
bool comp(const pll &a, const pll &b) {
	return a.first < b.first;
}
//*********************************************************
// 最大公約数（Greatest Common Divisor）を返す。
// 引数に０がある場合は０を返す。
//*********************************************************
ll gcd(ll a, ll b)
{
	ll tmp, r;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	/* ユークリッドの互除法 */
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
	//// 引数に０がある場合は０を返す
	//if ((0 == m) || (0 == n))
	//	return 0;

	//// ユークリッドの方法
	//while (m != n)
	//{
	//	if (m > n) m = m - n;
	//	else         n = n - m;
	//}
	//return m;
}//gcd

int main()
{
	double a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll x[100004] = {};
	ll y[100004] = {};
	ll z[25000001] = {};
	vector<tuple<ll, ll>> vec;
	string s;
	string t;
	//IntStack yStack;
	//charStack Stack;
	//vector<pair<int, int> > pairs(a);
	//cout << LLONG_MAX<< endl;

	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	cout << std::setprecision(20) << a*b / 2 ;

	if (a/2==c&&b/2==d)
	{
		cout << " 1" <<endl;
	}
	else
	{
		cout << " 0" << endl;
	}
	//cout << ans << endl;


	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//sort(x, x + a, std::greater<ll>());

//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得
//
//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}
//
//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え


/*vector<pair<ll, ll> > hoges(a);
for (int i = 0; i < a; i++)
{
cin >> x[i];
cin >> y[i];
hoges[i] = make_pair(x[i], y[i]);
}
sort(hoges.begin(),hoges.end(),comp);
for (int i = 0; i < a; i++)
{
if (hoges[i].second>=b)
{
ans += hoges[i].first*b;
break;
}
else
{
ans += hoges[i].first*hoges[i].second;
b -= hoges[i].second;

}
}*/

Measured memory_bytes: 256
// Author: Moulik
// Date Created: 07 June 2020
// Filename: B.cpp
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define what_is(x) cerr << "DEBUG::BEGIN\n\tVariable name:\n\t\t" << #x << "\n\tdata:\n\t\t" << x << "\nDEBUG::END" << endl;
#else
#define what_is(x) ;
#endif

// DEFINE OSTREAMS HERE

template<typename T1, typename T2>
ostream & operator<<(ostream &os, const pair<T1,T2> p){
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}

template<typename T>
ostream & operator<<(ostream &os, const vector<T> p){
    os << "{ ";
    for(auto i:p){
        os << i << ",";
    }
    os << "\b";
    os << "}";
    return os;
}

// DEFINE ISTREAMS HERE

template<typename T1, typename T2>
istream & operator >> (istream &in, pair<T1,T2> & p){
    in >> p.first >> p.second;
    return in;
}

// Sorts array in the given order {key is 0 indexed}
template<typename T>
void keySort(vector<T> & arr, vector<int> & key){
    int n = arr.size();
    if(key.size()!=n){
        throw runtime_error("Size of data array not equals to size of key array");
    }
    vector<T> ans(n);
    int ar[n];
    for(int i = 0; i < n; i++){
        ar[key[i]]=i;
    }
    for(int i = 0; i < n; i++){
        ans[i] = arr[ar[i]];
    }
    arr = ans;
}
void solve();

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}


void solve(){
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }
    sort(s.begin(), s.end());
    for(auto i:s){
        cout << i;
    }
    cout << endl;
}

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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

struct coin {
    int x,y,z;
    bool operator<(const coin& a) const {
        return x-y < a.x-a.y;
    }
};

int main() {
    int x,y,z;
    cin >> x >> y >> z;
    int n = x+y+z;
    vector<coin> a(n);
    priority_queue<int> que1,que2;
    vector<ll> sum1(z+1,0),sum2(z+1,0);
    for (int i = 0;i < n;++i) cin >> a[i].x >> a[i].y >> a[i].z;
    sort(a.begin(),a.end());
    for (int i = 0;i < y;++i) {
        sum1[0] += a[i].y;
        que1.push(a[i].z-a[i].y);
    }
    for (int i = y;i < y+z;++i) {
        que1.push(a[i].z-a[i].y);
        sum1[i-y+1] = sum1[i-y]+que1.top()+a[i].y;
        que1.pop();
    }
    for (int i = y+z;i < n;++i) {
        sum2[z] += a[i].x;
        que2.push(a[i].z-a[i].x);
    }
    for (int i = y+z-1;i >= y;--i) {
        que2.push(a[i].z-a[i].x);
        sum2[i-y] = sum2[i-y+1]+que2.top()+a[i].x;
        que2.pop();
    }
    ll ans = 0;
    for (int i = 0;i < z+1;++i) ans = max(ans,sum1[i]+sum2[i]);
    cout << ans << endl;
    return 0;
}

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

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second　//pairの二つ目の要素

int n,m;
vector<int> to[100005];
vector<int> h;


int main(){
    cin>>n>>m;
    int a,b;
    h.resize(n);
    REP(i,n)cin>>h[i];
    REP(i,m){
        cin>>a>>b;
        a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    int ans=0;
    REP(i,n){
        int maxv=0;
        for(int b : to[i]) maxv=max(maxv,h[b]);
        if(maxv<h[i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8752
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N; cin >> N;
    rep(i, 111) {
        if ((N + i) % 111 == 0) {
            cout << N + i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3540
//#include <stdio.h>
#include <bits/stdc++.h>
#include <climits>
using namespace std;
int main()
{
    int n;
    cin >> n;
    string ans = "";
    string s;
    string a;
    int j1;
    int j2;
    int i1 = 0;
    int i2 = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        sort(a.begin(), a.end());
        if (i != 0)
        {
            i1 = 0;
            i2 = 0;
            j1 = a.size() - 1;
            j2 = s.size() - 1;

            while (a.size() > i1)
            {
                //if(j2=-1){
                  //  a="";
                 //   break;
                //}
                // cout <<i1<<" "<<i2<<endl;
                //    cout << a.at(i1)<<"  "<< s.at(i2)<<endl;
                //  cout <<a<<"  "<<s<<endl;
                if (a.at(i1) > s.at(i2))
                {

                    i2++;
                    if (j2 < i2)
                    {
                        //while (a.size() > i1){
                        a.erase(i1);

                        //}
                    }
                }
                else if (a.at(i1) < s.at(i2))
                {

                    a.erase(i1, 1);
                }
                else
                {
                    i1++;
                    i2++;
                    if (j2 < i2)
                    {
                        //while (a.size() > i1){
                        a.erase(i1);

                        //}
                    }
                }
                // cout<<a<<endl;
            }
        }
        s = a;
        if(s==""){
            cout <<"" <<endl;
            return 0;
        }
    }
    cout << s << endl;

    return 0;
}


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

int main(void){
    int n,m,k;
    int num[40] = {};
    cin >> n >> m;
    for(int i = 0;i < n;i++){
        cin >> k;
        for(int j = 0;j < k;j++){
            int a;
            cin >> a;
            num[a]++;
        }
    }
    int count = 0;
    for(int i = 0;i <= m;i++)if(num[i] == n)count++;
    cout << count;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  vi w(n),S(n+1,0);
  rep(i,n){
    cin >> w[i];
    S[i+1]=S[i]+w[i];
  }
  int ans = 1001000;
  rep(i,n){
    int s1 = S[i];
    int s2 = S[n]-S[i];
    mins(ans,abs(s1-s2));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3640
n,a,b=map(int, input().split())
ans = 0
for i in range(n+1):
  d = i
  c = 0
  while d >0:
    c += (d%10)
    d = d // 10
#  print(i,c)
  if a <= c <= b:
    ans += i
print(ans)



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

main(){

  int i,j,N,array[100],key;

  cin>>N;
  for(i=0; i<N; i++)cin>>array[i];

  for(i=0; i<N; i++){
    key=array[i];
    j=i-1;
    while(j>=0  && array[j]>key){
      array[j+1]=array[j];
      j--;
    }
    array[j+1]=key;
    for(j=0; j<N; j++){
      if(j==N-1){
        cout<<array[j]<<endl;
        break;
      }
      cout<<array[j]<<" ";
    }
  }

}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 212345
#define MOD 998244353LL

class Primes {
public:
	bool p[N]={1, 1};
	Primes(){
		REP(i, N){
			if(p[i]) continue;
			// DEBUG("%d is prime\n", i);
			// if(i >= 100) exit(0);
			for(int j = i*2; j < N; j+=i) p[j] = true;
		}
	}

	bool yes(int i){
		return !p[i];
	}
} primes;
char s[N]={};
char u[N]={};
ll t[N]={0};
ll a[N];

vi v, w;

// int lcm(ll a, ll b){
// 	return (int)(a*b/__gcd(a, b));
// }
int main(){
	int n; scanf("%d%s", &n, s);
	REP(i, n) s[i] -= '0';
	REP(i, n){
		t[i+1] = (2 * t[i] + s[i]) % MOD;
	}

	fill(a, a+N, -1);

	FOR(i, 1, n+1) { // size of block
		if(n%i) continue;
		if((n/i)%2 == 0) continue;
		a[i] = t[i];
		
		{
			REP(j, n) u[j] = s[j%i] ^ ((j/i)&1);
			int j = 0;
			while(j < n && s[j] == u[j]) j++;
			REP(i, n) DEBUG("%d", (int)s[i]); DEBUG("\n");
			REP(i, n) DEBUG("%d", (int)u[i]); DEBUG("\n");
			if(s[j] >= u[j]){
			 	a[i]++;
				DEBUG("ok\n");
			}
		}
		
		DEBUG("size=%d, cnt=%lld\n", i, a[i]);
	}
	
	ll ans = 0;
	REP(i, n+1){
		if(!~a[i]) continue;

		v.clear();
		for(int j = 1; j * j <= i; j++){
			if(i%j) continue;
			v.EB(j);
			if(j * j < i) v.EB(i/j);
		}

		DEBUG("%d =>", i);
		w.clear();
		for(int &j : v){
			if((n/j)%2 == 0) continue;
			if(primes.yes(i/j)){
				DEBUG(" %d", j);
				w.EB(j);
			}
		}
		DEBUG(", ");

		ll tmp = 0;
		REP(k, 1<<w.size()){
			int coef = __builtin_parity(k) * -2 + 1;
			int x = i;
			REP(j, (int)w.size()){
				if(k & (1<<j)){
					x = __gcd(x, w[j]);
				}
			}
			DEBUG(" %+d", coef*x);
			tmp += coef * a[x];
		}
		tmp = (MOD + tmp % MOD) % MOD;
		ans += tmp * i * 2;
		ans %= MOD;
		DEBUG("\n");
	}
	
	printf("%lld\n", ans);
}




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

using namespace std;
using ll = long long int;
#define IINF 2e9
#define MOD 1e9+7

#define loop(i, n) for(int i = 0;i < n;i++)
#define vi vector<int>
#define vvi vector<vi>

int main(void){
  int n, m;
  cin >> n >> m;
  vector<string> a(n), b(n);
  loop(i, n) cin >> a[i];
  loop(i, m) cin >> b[i];
  
  if(n == m){
    bool ok = true;
    loop(i, n){
      loop(j, m){
        if(a[i][j] != b[i][j]) ok = false;
      }
    }
    
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
  }
  
  loop(i, n-m){
    loop(j, n-m){
      bool ok = true;
      loop(k, m){
        loop(l, m){
          if(a[i+k][j+l] != b[k][l]) ok = false;
        }
      }
      if(ok){
        cout << "Yes" << endl;
        return 0;
      }
    }
  } 

  cout << "No" << endl;
}


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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef 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_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    string S, T; cin >> S >> T;
    if(S.length() < T.length()){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    int i;
    for(i = S.length()-T.length(); i >= 0; i--){
        bool ok = true;
        for(int j = 0; j < T.length(); j++){
            if(S[i+j] == '?') continue;
            if(S[i+j] != T[j]) ok = false;
        }
        if(ok) break;
        if(i == 0){
            cout << "UNRESTORABLE" << endl;
            return 0;
        }
    }

    for(int j = 0; j < T.length(); j++) S[i+j] = T[j];

    for(int j = 0; j < S.length(); j++){
        if(S[j] == '?')  S[j]= 'a';
    }
    cout << S << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#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 mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------



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

  vector<string> ss;
  rep(i, s.length()) {
    for(int j=1; j <= 5 && i+j <= s.length(); j++) {
      ss.pb(s.substr(i, j));
    }
  }

  sort(all(ss));
  ss.erase(unique(all(ss)), ss.end());

  // rep(i, ss.size()) {
  //   cout << ss[i] << endl;
  // }

  cout << ss[k-1] << endl;

  return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <vector>
using namespace std;
 
template<class T> bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    else return false;
}
 
int main() {
    // 入力
    int N; long long W;
    cin >> N >> W;
    vector<long long> weight(N), value(N);
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];
 
    // DP テーブル定義
    vector<vector<long long> > dp(N+1, vector<long long>(W+1, 0));
 
    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int w = 0; w <= W; ++w) {
 
            // i 番目の品物を選ぶ場合
            if (w - weight[i] >= 0) {
                chmax(dp[i+1][w], dp[i][w - weight[i]] + value[i]);
            }
 
            // i 番目の品物を選ばない場合
            chmax(dp[i+1][w], dp[i][w]);
        }
    }
 
    // 最適値の出力
    cout << dp[N][W] << endl;
}

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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

ll t2[200005];

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  ll n,t;cin>>n>>t;
  ll res=0;
  for(int i=0;i<n;i++){
    cin>>t2[i];
  }
  for(int i=0;i<n-1;i++){
    if(t2[i] + t <= t2[i+1]){
      res+=t;
    } else {
      res += t2[i+1]-t2[i];
    }
  }
  res += t;
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define max_n 1000000

using namespace std;

void solve()
{
	ll k,n;
	cin>>k>>n;
	ll a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	ll ans=k;
	for (int i = 0; i < n; ++i)
	{
		ans=min((a[(i-1+n)%n]-a[i]+k)%k,ans);
		ans=min(ans,(a[i]-a[(i+1)%n]+k)%k);
	}
	cout<<ans<<endl;

}

int32_t main() 
{
	IOS	
	ll T=1;
	// cin>>T;
	for(ll i=1;i<=T;++i)
	{		
		// cout<<"Case #"<<i<<": ";
    	solve();
	}
	return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define M 1777771
#define N 300005
using namespace std;
typedef unsigned long long ull;
int n,m;
string s,t;
ull S[N],A[N];
set<ull> ans;

int main(){
  cin>>n>>m;
  cin>>s;
  ull x=1,y=0;
  for(int i=0;i<s.size();i++){
    y=y*M+s[i];
    S[i]=y;
    A[i]=x;
    x*=M;
  }
  int l=0,r=0;
  for(int i=0;i<m;i++){
    cin>>t;
    if(t=="L++")l++;
    if(t=="L--")l--;
    if(t=="R++")r++;
    if(t=="R--")r--;
    ull substr=S[r];
    if(0<l)substr-=S[l-1]*A[r-l+1];
    ans.insert(substr);
  }
  cout<<ans.size()<<endl;
  return 0;
}

Measured memory_bytes: 21828
#
# abc136 b
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """11"""
        output = """9"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """136"""
        output = """46"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """100000"""
        output = """90909"""
        self.assertIO(input, output)


def resolve():
    N = int(input())

    ans = 0
    for i in range(1, N+1):
        if len(str(i)) % 2 != 0:
            ans += 1
    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()


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

int main(){
    int a,b;
    string s;
    cin>> s;
    int le=s.length();
    a=b=0;
    for(int i=0;i<le;i++){
        if(s[i]=='0'){
            a++;
        }else{
            b++;
        }
    }
    a=a<b?a:b;
    a*=2;
    cout<<a<<"\n";
    return(0);
}

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

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    int cnt = 0;
    for (int i = min(a, b); i >= 1; i--) {
        if (a % i == 0 && b % i == 0) {
            cnt++;
            if (cnt == k) {
                cout << i << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;

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

    int ans = k;
    rep(i, n-1) {
        ans *= (k-1);
    }

    cout << ans << endl;
}

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

void print_vec(vector<int> vec) {
  cout << "[";
  for (int i = 0; i < vec.size(); i++) {
    if (i) {
      cout << ", ";
    }
    cout << vec.at(i);
  }
  cout << "]...size: " << vec.size() << endl;
}

int main() {
  int n;
  cin >> n;
  vector<int> xs(n);
  vector<int> ys(n);

  rep(i, n) { cin >> xs[i]; }
  rep(i, n) { cin >> ys[i]; }

  double p1 = 0;
  rep(i, n) { p1 += abs(xs[i] - ys[i]); }

  double p2 = 0;
  rep(i, n) { p2 += pow(xs[i] - ys[i], 2); }
  p2 = sqrt(p2);

  double p3 = 0;
  rep(i, n) { p3 += pow(abs(xs[i] - ys[i]), 3); }
  p3 = cbrt(p3);

  int p_inf = 0;
  rep(i, n) { p_inf = max(p_inf, abs(xs[i] - ys[i])); }

  printf("%f\n%f\n%f\n%d\n", p1, p2, p3, p_inf);
}



Measured memory_bytes: 3428
#include <iostream>
#include <queue>

using namespace std;

int main(){
  int n; cin >> n;
  priority_queue<int,vector<int>,greater<int> > PQ;
  int sum=0;
  for(int i=0;i<n;i++){
    int x; cin >> x;
    if(x%10!=0) PQ.push(x);
    sum=sum+x;
  }
  if(sum%10!=0) cout << sum << endl;
  else if(PQ.empty()) cout << 0 << endl;
  else{
    int y=PQ.top(); PQ.pop();
    cout << sum-y << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        long a = long.Parse(str[1]);
        long b = long.Parse(str[0]);
        long x = long.Parse(str[2]);
        sb.Append((b == 0 ? (a/x+1) : (a/x-(b-1)/x))+"\n");
    }
}

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

template<typename T>
struct SparseTable {
    vector<vector<T>> st;
    vector<int> lookup;

    SparseTable(const vector<T>& v) {
        int b = 0;
        while ((1 << b) <= v.size()) b++;
        st.assign(b, vector<T>(1 << b));
        for (int i = 0; i < v.size(); i++) {
            st[0][i] = v[i];
        }
        for (int i = 1; i < b; i++) {
            for (int j = 0; j + (1 << i) <= 1 << b; j++) {
                st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
            }
        }
        lookup.resize(v.size() + 1);
        for (int i = 2; i < lookup.size(); i++) {
            lookup[i] = lookup[i >> 1] + 1;
        }
    }

    T query(int l, int r) {
        int b = lookup[r - l];
        return min(st[b][l], st[b][r - (1 << b)]);
    }
};

struct LCA {
    int n, k = 0;
    vector<vector<int>> adj;
    vector<int> vs, depth, id, D;
    SparseTable<pair<int, int>> *st;

    void dfs(int v, int p, int d) {
        id[v] = k;
        vs[k] = v;
        depth[k++] = d;
        D[v] = d;
        for (int s : adj[v]) {
            if (s != p) {
                dfs(s, v, d + 1);
                vs[k] = v;
                depth[k++] = d;
            }
        }
    }

    LCA(const vector<vector<int>>& adj) : n(adj.size()), adj(adj), vs(2 * adj.size() - 1), depth(2 * adj.size() - 1), id(adj.size()), D(adj.size()) {
        dfs(0, -1, 0);
        vector<pair<int, int>> ds;
        for (int i = 0; i < depth.size(); i++) {
            ds.emplace_back(depth[i], i);
        }
        st = new SparseTable<pair<int, int>>(ds);
    }

    int lca(int u, int v) {
        return vs[st->query(min(id[u], id[v]), max(id[u], id[v]) + 1).second];
    }

    int dist(int u, int v) {
        return D[u] + D[v] - 2 * D[lca(u, v)];
    }
};

int main() {
    int n;
    cin >> n;
    vector<vector<int>> adj(n);
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int a;
            cin >> a;
            adj[i].push_back(a);
            adj[a].push_back(i);
        }
    }
    LCA lca(adj);
    int q;
    cin >> q;
    while (q--) {
        int a, b;
        cin >> a >> b;
        cout << lca.lca(a, b) << '\n';
    }
}


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

using namespace std;

int main()
{
	int nums[4];
	string S;
	cin >> S;

	for (int i = 0; i < 4; i++)
	{
		nums[i] = S[i] - '0';
	}

	for (int i = 0; i < 8; i++)
	{
		int bin = i;
		bool flags[3];
		int tmp = nums[0];

		for (int j = 2; j >= 0; j--)
		{
			if (bin >= pow(2, j))
			{
				bin -= pow(2, j);
				tmp -= nums[j + 1];
				flags[j] = true;
			}
			else
			{
				tmp += nums[j + 1];
				flags[j] = false;
			}
		}

		if (tmp == 7)
		{
			string ans = to_string(nums[0]);

			for (int j = 0; j < 3; j++)
			{
				if (flags[j])
				{
					ans += "-";
				}
				else
				{
					ans += "+";
				}
				ans += to_string(nums[j + 1]);
			}

			cout << ans << "=7" << endl;

			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
def ABC113B():
    N = int(input())
    T, A = map(int, input().split())
    H = list(map(int, input().split()))
    for i in range(N):
        H[i] = T - H[i] * 0.006
    ansT = 1000000000
    ansN = 0
    for i in range(N):
        if abs(H[i] - A) <= ansT:
            ansT = abs(H[i] - A)
            ansN = i
    print(ansN + 1)
ABC113B()

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

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1;i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define INF 1000000000
#define PI 3.14159265358979

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

// N, E, S, W
const int dx[4] = { -1, 0,  1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<LL> vll;
//==============================================

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

	int n; cin >> n;
	vi r(n);

	REP(i, n) cin >> r[i];

	int maxV = -INF;
	int minV = r[0];
	REP2(i, 1, n) {
		maxV = max(maxV, r[i] - minV);
		minV = min(minV, r[i]);
	}

	cout << maxV << "\n";
	return 0;
}

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

int main(int argc, char const *argv[])
{
	int x, y;
	for (int i = 0; i < 5; ++i)
	{
		cin >> y;
		if(y == 0)
			x = i+1;
	}

	cout << x;
	return 0;
}

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

using namespace std;

typedef long long int ll;

ll M = 1e9 + 7;

int main()
{
    ll n;
    cin >> n;
    ll dp[2005] = {0};

    dp[0] = 0;
    dp[1] = 0;
    dp[2] = 0;
    dp[3] = 1;
    dp[4] = 1;
    dp[5] = 1;
    dp[6] = 2;

    if(n<3)
        cout << 0 <<"\n";
    else
    {
        for(int i=7 ; i<=n ; i++)
        {
            for(int j=i-3 ; j>=0 ; j--)
                dp[i] = (dp[i] + dp[j])%M;
             dp[i]++;
             dp[i]%=M;
        }
        cout << dp[n];
    }

    return 0;
}


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

const int N = 2e5 + 10;

int n;
pair<int, int> a[N];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d %d", &a[i].second, &a[i].first);
  sort(a, a + n);
  for (int i = 0; i < n; i++)
    swap(a[i].first, a[i].second);

  int t = 0;
  for (int i = 0; i < n; i++) {
    t += a[i].first;
    if (t > a[i].second)
      return puts("No"), 0;
  }

  puts("Yes");
  return 0;
}

Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from heapq import heappop,heappush
    n,k=map(int,input().split())
    A=[0]*n
    for i in range(n):
        t,d=map(int,input().split())
        t-=1
        A[i]=(t,d)
    A.sort(lambda x:-x[1]) # d の降順ソート

    # 各種の中で最大かどうかをわける
    B=[0]*n
    first=[1]*n
    for i,a in enumerate(A):
        t,d=a
        if(first[t]):
            first[t]=0
            B[i]=(d,1)
        else:
            B[i]=(d,0)

    # 初めは貪欲に d の大きい方から k 個取る
    S=[]
    for i in range(k):
        d,f=B[i]
        heappush(S,(f,d))
    x=sum(S[i][1] for i in range(k))
    y=sum(S[i][0] for i in range(k))
    ans=x+y*y

    # 残りの n-k について、Sからf=0で最小のものを捨て、B[k:]からf=1の中で最大のものを加える
    B=B[k:]
    for i in range(n-k):
        d,f=B[i]
        if(f==0): continue
        pf,pd=heappop(S)
        if(pf==1): break
        x+=d-pd
        y+=1
        ans=max(ans,x+y*y)
    print(ans)
resolve()

Measured memory_bytes: 68044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

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

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
ans = []
mx = 0
for i in range(n):
    if abs(a[i])>abs(mx):
        mx = a[i]
        mx_idx = i
for i in range(n):
    if mx*a[i]<0:
        ans.append((mx_idx+1, i+1))
for i in range(n-1):
    if mx>0:
        ans.append((i+1, i+2))
    elif mx<0:
        ans.append((n-i, n-i-1))
print(len(ans))
for x, y in ans:
    print(x, y)

Measured memory_bytes: 3064
/*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_B&lang=jp*/
#include<iostream>

using namespace std;

void println(int *a,int n){
    for(int i=0;i<n;i++){
        cout<<a[i];
        if(i<n-1){
            cout<<" ";
        }
    }
    cout<<endl;
}

int main()
{
    int n;
    int a[100];
    int count=0;

    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n-1;i++){
        int minj=i;
        for(int j=i+1;j<n;j++){
            if(a[j]<a[minj]){
                minj=j;
            }
        }
        if(i!=minj) {
            swap(a[i], a[minj]);
            count++;
        }
    }
    println(a,n);
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 1160
import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N, capacity = inputIntList()
    w = [0 for _ in range(N)]
    v = [0 for _ in range(N)]
    for i in range(N):
        w[i], v[i] = inputIntList()

    dp = [[float("inf") for _ in range(N * 1000 + 1)] for _ in range(N + 1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(N * 1000 + 1):
            if j < v[i]:
                dp[i + 1][j] = min(dp[i][j], dp[i + 1][j])
            else:
                dp[i + 1][j] = min(dp[i][j - v[i]] + w[i], dp[i][j])
    ret = 0
    for value, weight in enumerate(dp[N]):
        if weight <= capacity:
            ret = max(ret, value)

    return ret


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


Measured memory_bytes: 316660
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

string s;
int main() {
	cin >> s;
	ll n = s.size();
	REP(i, max(1ll, n - 2)){
		REP(j, min(3ll, n)) {
			REP(k, min(3ll, n)) {
				if (j != k) {
					if (s[i + j] == s[i + k]) {
						cout << i + 1 << " " << i + min(3ll, n) << endl;
						return 0;
					}
				}
			}
		}
	}
	cout << -1 << " " << -1 << endl;
}



Measured memory_bytes: 512
# import sys
# import math #sqrt,gcd,pi
# import decimal
import queue # queue
import bisect
# import heapq # priolity-queue
# from time import time
# from itertools import product,permutations,\
    # combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    n,m = readInt()
    road = [[] for i in range(n)]
    for i in range(m):
        a,b = readInt()
        road[a-1].append(b-1)
        road[b-1].append(a-1)
    ans = 0
    city = set(i for i in range(n))
    while len(city):
        q = queue.Queue()
        q.put(city.pop())
        visit = set()
        while not q.empty():
            x = q.get()
            visit.add(x)
            for i in road[x]:
                if i not in visit:
                    q.put(i)
                    city.discard(i)
        if len(city):
            ans += 1
    print(ans)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 40084
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <cctype>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    ll n; cin >>n;
    vector<ll> a(n+1); REP(i,n+1) cin >> a[i];
    vector<ll> b(n); REP(i,n) cin >> b[i];

    ll res = 0;
    vector<ll> ac = a;
    vector<ll> bc = b;
    for (ll i = 0; i < n; i++) {
        ll res1 = min(ac[i], bc[i]); 
        res += res1;
        bc[i] -= res1;
        ll res2 = min(ac[i+1], bc[i]);
        res += res2;
        ac[i+1] -= res2;
    }

    ll resr = 0;
    for (ll i = n-1; i >= 0; i--) {
        ll res1 = min(a[i+1], b[i]); 
        resr += res1;
        b[i] -= res1;
        ll res2 = min(a[i], b[i]);
        resr += res2;
        a[i] -= res2;
    }

    cout << max(res, resr) << endl;
    return 0;
}




Measured memory_bytes: 3328