akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<deque>

using namespace std;

#define sz(x) (int)(x.size())
#define fi(a, b) for(int i=a;i<b;++i)
#define fj(a, b) for(int j=a;j<b;++j)
#define fk(a, b) for(int k=a;k<b;++k)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

//////////

void solve(){
	vector<int> a, t;
	int ans = 0, n, c, k;
	scanf("%d %d %d",&n,&c,&k);
	fi(0, n){
		int v;
		scanf("%d",&v);
		t.pb(v);
	}
	sort(t.begin(), t.end());
	int last = -1;
	fi(0, n){
		if(t[last+1] + k < t[i]){
			++ans;
			last = i - 1;
			continue;
		}
		if(i - last == c){
			last = i;
			++ans;
		}
	}
	if(last != n-1) ++ans;
	printf("%d\n",ans);
}


int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();


	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
const int maxn = 1e5+10;

ll x[maxn],k[maxn];
ll n,a,b;

bool check(ll t){
    memcpy(k,x,sizeof(x));
    for(ll i=1; i<=n; i++){
        k[i] -= t*b;
    }
    ll more = (a-b),cnt=0;
    for(ll i=1; i<=n; i++){
        if(k[i]>0) cnt += (k[i]%more==0) ? (k[i]/more) : (k[i]/more+1);
    }
    return cnt <= t;
}

int main(){
    cin >> n >> a >> b;
    for(int i=1; i<=n; i++){
        x[i] = read();
    }
    ll ans,L=1,R=1e9;
    while(L<=R){
        ll mid = (L+R)/2;
        if(check(mid)) ans=mid,R=mid-1;
        else L=mid+1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import sys
input = lambda:sys.stdin.readline().strip()
s = input()
ans = 0
i = 0
while i<len(s):
    if s[i]=='S':
        i+=1
        continue
    j = i
    while j<len(s) and s[j]=='R':
        j+=1
    ans = max(ans,j-i)
    i = j
print(ans)
    

Measured memory_bytes: 8980
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll a = in(), b = in(), c = in(), d = in();
	cout << max(a * b, c * d) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
using lint=long long;
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  vector<lint> a(n+1,0);
  vector<vector<lint>> dp(n+5,vector<lint>(3,0));
  rep1(i,n)cin>>a[i];
  dp[1][0]=a[1];
  dp[2][0]=a[1]+a[2];
  dp[2][1]=-a[1]-a[2];
  for(int i=3;i<=n;++i){
      dp[i][0]=max(dp[i-1][0],dp[i-1][1])+a[i];
      dp[i][1]=max(dp[i-1][0]-2*a[i-1],dp[i-1][1]+2*a[i-1])-a[i];
  }
  cout<<max(dp[n][0],dp[n][1])<<"\n";
  return 0;
}

Measured memory_bytes: 9592
#include <bits/stdc++.h>
#define rep(n) for (int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define repeat_from_reverse(i, m, n) for( int i = (n) - 1; (i) >= (m); --(i) )
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t t=0; t<v.size(); ++t){cout << " " << #v << "[" << t << "]=" << v[t];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

/****************** 数論 ******************/
// 最大公約数
lint gcd(lint a, lint b) {
    // 引数の一方が 0 なら他方の値を返す
    return b ? gcd(b, a%b) : a;
}

int main(void) {
    int n; cin >> n;
    vector<int> t(n), a(n);
    repeat(i, n) cin >> t[i] >> a[i];
    
    auto fn = [](lint m, lint n) -> lint {
        lint a;
        if (m % n == 0) a = m / n;
        else a = m / n + 1;
        return a;
    };
    
    lint x = 1, y = 1;
    repeat(i, n) {
        lint k = max( fn(x, t[i]), fn(y, a[i]) );
        x = t[i] * k;
        y = a[i] * k;
    }
    cout << x + y << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

int a[100010];
signed main(void)
{
  int n;
  cin >> n;
  REP(i, n) cin >> a[i], a[i]--;

  int now = 0;
  REP(i, n) {
    now = a[now];
    if(now == 1) {
      cout << i+1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;

  return 0;
}


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

typedef struct city_ {	
	long r; // read time
	long p; // prefecture
	long y; // year
	long id; // id
} City;	

bool cmp_y(const City &a, const City &b)
{
    return a.y < b.y;
}

bool cmp_r(const City &a, const City &b)
{
    return a.r < b.r;
}

int main(){
  long n , m ;
  cin >> n >> m;
  long ans = 0;
  long p1 , y1;
  vector<City> v;
  for(long i = 0; i < m ; i++ ){
      cin >> p1 >> y1;
      City *city1 = new City;
      city1->r = i+1;
      city1->p = p1;
      city1->y = y1;
      v.push_back(*city1);
  }
  sort(v.begin(), v.end(),cmp_y);
  vector<long> v2;
  v2.assign(n, 1);
  vector<City> v3;
  for(long i = 0 ; i < m ; i++){
      City city2 = v[i];
      city2.id = v2[(city2.p) - 1 ];
      v2[(city2.p) - 1 ] += 1;
      v3.push_back(city2);
  }    
  sort(v3.begin(), v3.end(),cmp_r);
  string str;
  for(long i = 0; i < m ; i++){
      City city3 = v3[i];
      //先頭に0を詰めて6桁にする
	  ostringstream ss1;
	  ss1 << std::setw(6) << std::setfill('0') << city3.p ;
	  string s1(ss1.str());
	  ostringstream ss2;
	  ss2 << std::setw(6) << std::setfill('0') << city3.id ;
	  string s2(ss2.str());
	  cout << s1 + s2 << endl;
  }
  
  return 0;
}

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

int main(){
    int N;
    cin>>N;
    string S;
    cin>>S;
    int sum=0;
    int i=0;
    while(i<N){
        if(S[i]==S[i+1]){
            i++;
            while(S[i]==S[i+1]){
                i++;
            }
        }
        else
        {
            sum++;
            i++;
        }
    }
    cout<<sum<<endl;

}


Measured memory_bytes: 512
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/3/ITP1_3_D


def main():
    s = input()
    a, b, c = map(int, s.split())
    cnt = 0
    for d in range(a, b+1):
        if c % d == 0:
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5600
#include<queue>
#include<cstdio>
#include<algorithm>

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

using namespace std;

const int INF=1<<29;

int main(){
	int T; scanf("%d",&T);
	while(T--){
		int n,a,b; scanf("%d%d%d",&n,&a,&b);
		int x[1001],y[1001];
		rep(i,n+1) scanf("%d%d",x+i,y+i);

		vector<int> G[1000];
		rep(i,n) rep(j,n) {
			if((x[i+1]-x[j+1])*(x[i+1]-x[j+1])+(y[i+1]-y[j+1])*(y[i+1]-y[j+1])<=50*50){
				G[i].push_back(j);
			}
		}

		int last[1000]; // 最後に発声を終えた時刻
		int cnt=0;
		rep(i,n) last[i]=-INF;
		queue< pair<int,int> > Q;
		rep(i,n) if((x[i+1]-x[0])*(x[i+1]-x[0])+(y[i+1]-y[0])*(y[i+1]-y[0])<=10*10) {
			last[i]=a;
			Q.push(make_pair(a,i));
		}
		while(!Q.empty()){
			int t=Q.front().first,u=Q.front().second; Q.pop();

			cnt++;
			if(cnt>2*n*n){ cnt=-1; break; } // 十分多く回ったら無限に続いていると判断する

			rep(i,G[u].size()){
				int v=G[u][i];
				if(t-last[v]>b){
					last[v]=t+a;
					Q.push(make_pair(t+a,v));
				}
			}
		}

		if(cnt==-1) puts("You're always welcome!");
		else        printf("%d\n",max(*max_element(last,last+n),0));
	}

	return 0;
}

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

int H,W;
vector<vector<int> >field;

void dfs(int h, int w)
{
    field[h][w] = 0;
    
    for(int dh = -1; dh <= 1; dh++)
    {
        for(int dw = -1; dw <= 1; dw++)
        {
            int nh = h + dh;
            int nw = w + dw;
            
            if((nh >= H)||(nh < 0)||(nw >= W)||(nw < 0)) continue;
            if(field[nh][nw] == 0) continue;
            
            dfs(nh,nw);
        }
    }
}



int main()
{
    while(cin >> W >> H)
    {
        if((W == 0)||(H == 0)) break;
        field.assign(H,vector<int>(W,0));
        for(int h = 0; h < H; h++)
        {
            for(int w = 0; w < W; w++)
            {
                cin >> field[h][w];
            }
        }
        
        int count = 0;
        for(int h = 0; h < H; h++)
        {
            for(int w = 0; w < W; w++)
            {
                if(field[h][w] == 0) continue;
                dfs(h,w);
                count++;
            }
        }
        cout << count << endl;
    }
}


Measured memory_bytes: 3292
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		String ans = "Yes";
		while(A > 0 && C > 0){
			A -= D;
			C -= B;
		}
		if(C <= 0){
			ans = "Yes";
		}else{
			ans = "No";
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 27004
#include <iostream>
#include <string>
#include <memory.h>
using namespace std;

class cD
{
public:
	void N()
	{
		int nTemp = 0;
		nTemp = nD[1];
		nD[1] = nD[2];
		nD[2] = nD[6];
		nD[6] = nD[5];
		nD[5] = nTemp;
	}

	void S()
	{
		int nTemp = 0;
		nTemp = nD[1];
		nD[1] = nD[5];
		nD[5] = nD[6];
		nD[6] = nD[2];
		nD[2] = nTemp;
	}

	void W()
	{
		int nTemp = 0;
		nTemp = nD[1];
		nD[1] = nD[3];
		nD[3] = nD[6];
		nD[6] = nD[4];
		nD[4] = nTemp;
	}

	void E()
	{
		int nTemp = 0;
		nTemp = nD[1];
		nD[1] = nD[4];
		nD[4] = nD[6];
		nD[6] = nD[3];
		nD[3] = nTemp;
	}

	void Rotate()
	{
		int nTemp = 0;
		nTemp = nD[2];
		nD[2] = nD[3];
		nD[3] = nD[5];
		nD[5] = nD[4];
		nD[4] = nTemp;
	}

	void input()
	{
		for (int i = 1; i <= 6; i++)
		{
			cin >> nD[i];
		}
	}

	int nD[7] = { 0 };
};


bool check(cD D, cD D2)
{
	int nT = D2.nD[1], nF = D2.nD[2];
	for (int j = 1; j <= 6; j++)
	{
		if (nT == D.nD[j])
		{
			if (1 == j)
			{
				break;
			}
			else if (2 == j)
			{
				D.N();
			}
			else if (3 == j)
			{
				D.W();
			}
			else if (4 == j)
			{
				D.E();
			}
			else if (5 == j)
			{
				D.S();
			}
			else
			{
				D.S();
				D.S();
			}
		}
	}

	int nC = 4;
	int nFlag;
	while (nC--)
	{
		nFlag = 0;
		D.Rotate();
		for (int i = 1; i <= 6; i++)
		{
			if (D.nD[i] == D2.nD[i])
			{
				nFlag++;
			}
		}
		if (6 == nFlag)
		{
			break;
		}
	}

	nC = 4;

	if (6 != nFlag)
	{
		while (nC--)
		{
			nFlag = 0;
			D.N();
			for (int i = 1; i <= 6; i++)
			{
				if (D.nD[i] == D2.nD[i])
				{
					nFlag++;
				}
			}
			if (6 == nFlag)
			{
				break;
			}
		}
	}
	if (6 == nFlag)
	{
		return true;
	}
	else
	{
		return false;
	}
}


int main()
{
	cD D[100];
	memset(D, 0, sizeof(cD) * 100);
	int nCount;
	cin >> nCount;
	for (int i = 0; i < nCount; i++)
	{
		D[i].input();
	}
	bool bFlag = false;
	for (int i = 0; i < nCount - 1; i++)
	{
		for (int j = i + 1; j < nCount; ++j)
		{
			if (check(D[i], D[j]))
			{
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 3112
#include <cstdio>

using namespace std;

int main() {
    long long x, ans = 0;
    
    scanf("%lld", &x);
    
    ans += x / 11 * 2;
    x %= 11;
    if (x >= 1 && x <= 6) {
        ans++;
    } else if (x >= 7) {
        ans += 2;
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 128
#! /usr/bin/env python3

K, S = map(int, input().split())
c = 0
for i in range(max(0, S-K*2), min(K+1, S+1)):
    for j in range(max(0, S-i-K), min(K+1, S-i+1)):
       c += 1
print(c)

Measured memory_bytes: 3064
inputs = input()

a = inputs

ans = 0
while len(a) > 1:
    if a[0] == a[-1]:
        a = a[1:-1]
    elif a[0] == 'x' and a[-1] != 'x':
        ans += 1
        a += 'x'
    elif a[0] != 'x' and a[-1] == 'x':
        ans += 1
        a = 'x' + a
    elif a[0] != a[-1]:
        ans = -1
        break
        
print(ans)

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

int N;
typedef pair<int,int> P;



int main() {
    cin >> N;
    vector<P> hand(N), range(N);
    for (int i = 0; i < N; i++) {
        cin >> hand.at(i).first >> hand.at(i).second;
        range.at(i).first = hand.at(i).first + hand.at(i).second;
        range.at(i).second = hand.at(i).first - hand.at(i).second;
    }
    sort(range.begin(), range.end());

    int tmp = range.at(0).first;
    int count = 1;
    for (int i = 0; i < N; i++) {
        if (range.at(i).second>=tmp) {
            count++;
            tmp = range.at(i).first;
        }
    }
    cout << count;
    
}



Measured memory_bytes: 4820
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n, m; scanf("%d%d", &n, &m);
	std::vector<std::vector<std::pair<int, int>>> g(n);
	std::vector<int> x(m), y(m), h(n, 0);
	for(int i = 0; i < m; i++) {
		int a, b; scanf("%d%d%d%d", &a, &b, &x[i], &y[i]);
		
		g[a - 1].push_back({b - 1, i});
		h[b - 1]++;
	}
	
	std::vector<int> latte, malta(n);
	std::queue<int> qu; qu.push(0);
	while(!qu.empty()) {
		auto p = qu.front(); qu.pop();
		
		latte.push_back(p);
		for(auto e: g[p]) if(!(--h[e.first])) qu.push(e.first);
	}
	for(int i = 0; i < n; i++) malta[latte[i]] = i;
	
	auto dp = make_v<int>(n, n, 2);
	for(auto& w: dp) for(auto& v: w) for(auto& z: v) z = 1 << 30; dp[0][0][0] = 0;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < i; j++) {
			for(auto e: g[latte[j]]) {
				int to = malta[e.first], X = x[e.second], Y = y[e.second];
				
				if(i < to) {
					dp[to][i][0] = std::min({dp[to][i][0],
											 dp[i][j][0] + X,
											 dp[i][j][1] + X});
				} else if(to < i) {
					dp[i][to][0] = std::min({dp[i][to][0],
											 dp[i][j][0] + X,
											 dp[i][j][1] + X});
				} else {
					dp[to][to][0] = std::min({dp[to][to][0],
											  dp[i][j][0] + X,
											  dp[i][j][1] + Y});
				}
			}
			
		}
		int j = i;
		for(auto e: g[latte[j]]) {
			int to = malta[e.first], X = x[e.second], Y = y[e.second];
			
			dp[to][i][1] = std::min(dp[to][i][1], dp[i][j][0] + X);
		}
	}
	printf("%d\n", std::min(dp[n - 1][n - 1][0], dp[n - 1][n - 1][1]));
	return 0;
}



Measured memory_bytes: 58148
#include<iostream>
using namespace std;
int n;
int a[120];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		if(a[i]%2==0)
		{
			if(a[i]%3!=0 && a[i]%5!=0) 
			{
				cout<<"DENIED\n";
				return 0;
			}
		}
	}
	cout<<"APPROVED\n";
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int cycle[9]={0,1,2,4,7,8,11,13,14};
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int round=n/15,remain=n%15;
	int sum=(60+60+(round-1)*120)*round/2;
	for(int i=1;i<=8;i++)
		if(cycle[i]<=remain)
			sum+=cycle[i]+round*15;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <string.h>

#define MAX 200

void riffle(int *a, int n){
	int top[n], btm[n];
	memcpy(top, a, sizeof(int)*n);
	memcpy(btm, a+n, sizeof(int)*n);
	for (int i=0; i<n; i++){
		a[i*2] = top[i];
		a[i*2+1] = btm[i];
	}
}
void cut(int *a, int n, int k){
	int top[n*2], btm[n*2];
	int l;
	l = n*2-k;
	memcpy(top, a, sizeof(int)*k);
	memcpy(btm, a+k, sizeof(int)*l);
	memcpy(a, btm, sizeof(int)*l);
	memcpy(a+l, top, sizeof(int)*k);
}
void printDeck(int *a, int n){
	for (int i=0; i<2*n; i++) printf("%d\n", a[i]+1);
}

int main(void){
	int deck[MAX];
	int n, m, k;
	
	scanf("%d%d", &n, &m);
	for (int i=0; i<n*2; i++) deck[i]=i;
//	puts("before:");
//	printDeck(deck, n);
	for (int i=0; i<m; i++){
		scanf("%d", &k);
		if (k==0)riffle(deck, n);
		else cut(deck, n, k);
	}
//	puts("after:");
	printDeck(deck, n);
	return 0;
}
	

Measured memory_bytes: 1044
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    for(int i = 0; i < S.size(); i++){
        for(int j = 0; j < N; j++){
            if(S[i] == 'Z'){
                S[i] = 'A';
            }else{
                S[i]++;
            }
        }
    }
    cout << S << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

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

const ll max_e = 55555;
ll n;
bool e[55560];

void build_e() {
	e[0] = e[1] = true;
	repi(i, 2, max_e + 1) {
		if (e[i] == false) {
			ll t = i + i;
			while (1) {
				if (t > max_e) break;
				e[t] = true;
				t += i;
			}
		}
	}
	return;
}

int main() {
	cin >> n;
	
	build_e();
	
	vector<ll> vc;

	repi(i, 2, max_e + 1) {
		if (vc.size() == n) break;
		if (e[i] == false && i % 5 == 1) {
			vc.push_back(i);
		}
	}

	repi(i, 0, n) {
		cout << vc[i];
		if (i == n - 1) cout << endl;
		else cout << " ";
	}

	return 0;
}


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

int main()
{
	int N;
	double NN;
	double XX;
	int X1;
	double X2;
	double X3;
	int X4;
	int X5;
	scanf("%d",&N);
        NN=1.0*N;
        XX=NN/1.08;
	X1=XX;
	X2=X1*1.08;
	X3=(1+X1)*1.08;
	X4=X2;
	X5=X3;
	if( (X4!=N) & (X5 != N)) printf(":(\n");
        if(X4==N) printf("%d\n",X1);
	if(X5==N) printf("%d\n",1+X1);
	
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<map>
#define int long long
#define ll long long
using namespace std;
signed main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b )cout << c << endl;
	else if (a == c )cout << b << endl;
	else cout << a << endl;
	getchar(); getchar(); return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7, dp[1 << 25];
bool p[25][25];
inline int cnt(int n)
{
	int res = 0;
	while (n) {
		++res;
		n &= (n - 1);
	}
	return res;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	char c;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j) {
			cin >> c;
			p[i][j] = (c == '1')? true: false;
		}
	dp[0] = 1;
	for (int i = 1; i < (1 << n); ++i) {
		int num = cnt(i);
		for (int j = 0; (1 << j) <= i; ++j) {
			if (i & (1 << j) && p[num][j + 1])
				dp[i] = (dp[i] + dp[i & ~(1 << j)]) % mod;
		}
	}
	cout << dp[(1 << n) - 1] << '\n';
	return 0;
}

Measured memory_bytes: 18688
# include<bits/stdc++.h>
 
using namespace std;
 
# define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;
 
# define S second
# define F first
# define kill(x) return(cout << x << endl, 0)
# define debug(x) cerr<< #x << " : " << x << endl
# define ddebug(x, y) cerr<< #x << " : " << x  << ", " << #y << " : " << y << endl
# define sz(s) (int)s.size()
# define sq(x) (x) * (x)
# define PB(x) push_back(x)
# define smax(x, y) (x) = max((x), (y))
# define smin(x, y) (x) = min((x), (y))
# define all(x) x.begin(), x.end()
# define SP fixed << setprecision(10)
# define UB upper_bound 

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

	string s;
	int k;
	cin >> s >> k;

	for (int i = 0; i < sz(s); i ++)
	{
		if (s[i] == 'a' || k < ('z' - s[i] + 1))
			continue;
		k -= ('z' - s[i] + 1);
		s[i] = 'a';
	}
	s[sz(s) - 1] = (s[sz(s) - 1] - 'a' + k) % 26 + 'a';
	cout << s << endl;

	return 0;
}


Measured memory_bytes: 592
N,M,X,Y =map(int ,input().split())
x =list(map(int ,input().split()))
y =list(map(int ,input().split()))
count =0
for i in range(X+1,Y):
    if max(x) <i and i <=min(y):
        count +=1
        break    
if count ==1:
    print("No War")
else:
    print("War")

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

int cnt[100010]={0};

int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    int sum=0;
    for(int i=0;i<k;i++){
        int s;
        scanf("%d",&s);
        for(int j=0;j<s;j++){
            int a;
            scanf("%d",&a);
            cnt[a]++;
        }
    }
    for(int i=1;i<=n;i++){
        if(!cnt[i]){
            sum++;
        }
    }
    printf("%d",sum);
    return 0;
}


Measured memory_bytes: 3816
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<set>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){
	int n;
	cin >> n;
	vector<int> v;

	int a;
	rep(i,n){
		cin >> a;
		v.push_back(a);
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	int sum = 0;
	rep(i,n){
		if(i%2==0) sum+=v[i];
		else sum -=v[i];
	}

	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
m = gets.to_i
for i in 1..m #??????????????????????????¨???
  all = Hash.new(0)
  a = gets.chomp.split("")
  l = a.length()
  for j in 1..(l-1) #????????????????????¨???
    p1 = ""
    p2 = ""
    for k in 0..(j-1) #?????????1
      p1 = p1 + a[k]
    end
    for k in j..(l-1) #?????????2
      p2 = p2 + a[k]
    end
    q1 = p1.reverse
    q2 = p2.reverse
    all[p1+p2] = 1
    all[p1+q2] = 1
    all[q1+p2] = 1
    all[q1+q2] = 1
    all[p2+p1] = 1
    all[p2+q1] = 1
    all[q2+p1] = 1
    all[q2+q1] = 1
  end
  puts all.size
end

Measured memory_bytes: 9280
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <string.h>

namespace {

const int N = 8;
// the positions of k-queens are fixed.
// Once initialized, the values remain unchanged.
bool row[N] = {false};

bool col[N] = {false};
bool down[2 * N - 1] = {false};
bool up[2 * N - 1] = {false};
int pos[N];

void Print() {
  for (int r = 0; r < N; ++r) {
    const int qc = pos[r];
    for (int c = 0; c < N; ++c) {
      if (c == qc)
        printf("Q");
      else
        printf(".");
    }
    printf("\n");
  }
}

// OK returns true if we can put a queen at (r, c)
inline bool OK(int r, int c) {
  return !col[c] && !down[r - c + N - 1] && !up[r + c];
}

inline void Update(int r, int c) {
  pos[r] = c;
  col[c] = true;
  down[r - c + N - 1] = true;
  up[r + c] = true;
}

inline void Cancel(int r, int c) {
  pos[r] = -1;
  col[c] = false;
  down[r - c + N - 1] = false;
  up[r + c] = false;
}

bool Put(int r) {
  if (row[r])
    return r < 7 ? Put(r + 1) : true;

  for (int c = 0; c < 8; ++c) {
    if (!OK(r, c))
      continue;

    Update(r, c);

    if (r == 7)
      return true;

    if (Put(r + 1))
      return true;
    else
      Cancel(r, c);
  }
  return false;
}

} // namespace

int main() {
  int k;
  std::cin >> k;

  memset(pos, -1, sizeof(int)  * N);
  for (int i = 0; i < k; ++i) {
    int r, c;
    std::cin >> r >> c;
    Update(r, c);
    row[r] = true;
  }

  if (!Put(0)) {
    std::cerr << "ERROR: not found" << std::endl;
    Print();
    std::exit(1);
  }

  Print();

  return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include "string"
using namespace std;
int main() {
    int N;
    cin >> N;
    int res[4] = {0,0,0,0};
    for (int i = 0; i < N; ++i) {
        string verdict;
        cin >> verdict;
        if(verdict=="AC"){
            res[0]++;
        }else if(verdict=="WA"){
            res[1]++;
        }else if(verdict=="TLE"){
            res[2]++;
        }else if(verdict=="RE"){
            res[3]++;
        }
    }
    cout << "AC x "<<res[0]<<endl;
    cout << "WA x "<<res[1]<<endl;
    cout << "TLE x "<<res[2]<<endl;
    cout <<"RE x "<<res[3]<<endl;
    return 0;
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N,sum=0,x=-1;
  string S;
  vector<pair<string,int>> playlist;
  cin>>N;
  for(int i=0;i<N;i++)
  {
    playlist.push_back(make_pair("",0));
    cin>>playlist.at(i).first>>playlist.at(i).second;
  }
  cin>>S;
  for(int i=0;i<N;i++)
  {
    if(playlist.at(i).first==S){x=i+1;break;}
  }
  if(x==-1){return 0;}
  else
  {
    while(x<N){sum+=playlist.at(x).second;x++;}
    cout<<sum<<endl;
  }
}

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

using namespace std;

int time_parse(string time)
{
  int hour = atoi(time.substr(0, 2).c_str());
  int minute = atoi(time.substr(3, 5).c_str());
  int second = atoi(time.substr(6).c_str());
  return hour * 3600 + minute * 60 + second;
}

int main()
{
  int n;
  while (cin >> n && n)
  {
    int table[24 * 3600] = {0};
    string time_in, time_out;
    for (int i = 0; i < n; i++)
    {
      cin >> time_in >> time_out;
      table[time_parse(time_in)]++;
      table[time_parse(time_out)]--;
    }
    int ans = 0, sum = 0;
    for (int i = 0; i < 24 * 3600; i++)
    {
      sum += table[i];
      ans = max(sum, ans);
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3416
#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;
typedef long long llint;

const int maxn = 110;
const int base = 31337;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;

int n;
llint w;
llint wp[maxn], vs[maxn];
vector< llint > v;
vector< llint > vals[10];
vector< llint > pref[10];

int main() {
	scanf("%d%lld", &n, &w);
	for (int i = 0; i < n; i++) {
		scanf("%lld%lld", wp+i, vs+i);
	}

	for (int i = 0; i < n; i++) {
		v.push_back(wp[i]);
	}
	sort(v.begin(), v.end());
	v.resize(unique(v.begin(), v.end()) - v.begin());
	for (int i = 0; i < 4; i++) v.push_back(inf);

	for (int i = 0; i < n; i++) {
		int ind = lower_bound(v.begin(), v.end(), wp[i]) - v.begin();
		vals[ind].push_back(vs[i]);
	}
	for (int i = 0; i < v.size(); i++) {
		pref[i].push_back(0);
		sort(vals[i].begin(), vals[i].end()); 
		reverse(vals[i].begin(), vals[i].end());
		for (int j = 0; j < vals[i].size(); j++) {
			pref[i].push_back(pref[i].back() + vals[i][j]);
		}
	}

	llint sol = 0;
	for (int i = 0; i < pref[0].size(); i++) {
		for (int j = 0; j < pref[1].size(); j++) {
			for (int l = 0; l < pref[2].size(); l++) {
				if ((w - v[0] * i - v[1] * j - v[2] * l) < 0) continue;
				int k = (w - v[0] * i - v[1] * j - v[2] * l) / v[3];
				k = min((int)pref[3].size() - 1, k);

				llint tren = pref[0][i] + pref[1][j] + pref[2][l] + pref[3][k];
				sol = max(sol, tren);
			} 
		}
	}
	printf("%lld", sol);
	return 0;
}

Measured memory_bytes: 3832
/*
9 2
        1 1 1 1 1 0 0 0 0
        1 2
        1 5
        5 6
        5 7
        2 3
        2 4
        3 8
        3 9
*/


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.StringTokenizer;
import java.util.Vector;

public class Main {


    static LinkedList<Integer> adj[];
    static boolean[] visited;
    static boolean[] visited_;
    static int[] ans;
    static int count_ = 0;
    static final int MAX_SIZE = 1000001;
    static Vector<Boolean> isprime = new Vector<>(MAX_SIZE);
    static Vector<Integer> prime = new Vector<>();
    static Vector<Integer> SPF = new Vector<>(MAX_SIZE);

    public static void main(String[] args) throws IOException {
        Reader.init(System.in);
        int n = Reader.nextInt();
        int[] arr = new int[n];
        int[] ans = new int[n];
        for (int i = 0 ; i < n ; i++){
            arr[i] = Reader.nextInt();
        }
        if (n==1){
            System.out.println(0);
            System.exit(0);
        }
        else if (n==2){
            System.out.println(Math.abs(arr[1]-arr[0]));
            System.exit(0);
        }
        else{
            ans[1] = Math.abs(arr[1] - arr[0]);
            for (int i=2; i < n ; i++){
                ans[i] = Math.min(Math.abs(arr[i] - arr[i-2]) + ans[i-2],Math.abs(arr[i]-arr[i-1]) + ans[i-1]);
            }
        }

        for (int i = 0 ; i < n ; i++){
            //System.out.println(ans[i] + " ");
        }
        System.out.println(ans[n-1]);



    }
}

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}

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

int main() {
  int Ans = 0; // 回答：正直者の最大数
  int N; cin >> N;  // 参加人数
  vector<int> A(N); // 各員の証言数
  vector<vector<int>> Y(N,vector<int>(N,-1) );  // i さんの j さんに対する評価（但し i は０から

  // 評価情報の取込
  int tmp_x,tmp_y;  // tmp_x さんに対する i さんの評価は tmp_y
  rep(i,N){
    cin >> A.at(i); // i さんの評価数は i-1 に入る。
    rep(j,A.at(i)){
      cin >> tmp_x >> tmp_y;
      Y.at(i).at(tmp_x-1) = tmp_y;
    }
  }

  // rep(i,N){
  //   rep(j,N){
  //     cout << "i-j: " << i << "-" << j << " : " << Y.at(i).at(j) << endl;
  //   }
  // }

  // 正直者全組み合わせ探索
  rep(i,(1<<N)){
    bitset<15> b(i);  // 全探索用ビットセット

    bool OK=true;   // 全正直者判定が成立するか？
    rep(j,N){
      if(b.test(j)){  // j さんが正直者の場合、j さんのコメントの整合性チェック
        rep(k,N){
          if(Y.at(j).at(k) != -1 && Y.at(j).at(k)!=b.test(k)) { // j さんの評価が、仮定ビットセットと異なる。
            OK=false;
            break;
          }
        }
        if(!OK){break;}
      }
    }
    if(OK){ Ans = max(Ans,__builtin_popcount(i));}

  }

  cout << Ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]


    n = int(lines[0])
    s = lines[1]
    k = int(lines[2])

    return (n, s, k)


def solve(n, s, k):


    c = s[k-1]

    result = []
    for d in s:
        if c == d:
            result.append(c)
        else:
            result.append("*")

    return "".join(result)


def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()


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

int main(void){
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<int> x(N), y(M);
    for (int i=0; i<N; i++) cin >> x[i];
    for (int i=0; i<M; i++) cin >> y[i];
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    if (x[N-1] >= y[0]){
        cout << "War" << endl;
    } else{
        for (int i=y[0]; i>x[N-1]; i--){
            if (i > X && i <= Y){
                cout << "No War" << endl;
                return 0;
            }
        }
        cout << "War" << endl;
    }
    return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    int H, W;
    cin >> H >> W;
    vector<Vi> mas(H, Vi(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> mas[i][j];
        }
    }

    vector<tuple<int, int, int, int>> operations;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (mas[i][j] & 1) {
                --mas[i][j];
                if (j + 1 < W) {
                    ++mas[i][j + 1];
                    operations.emplace_back(i, j, i, j + 1);
                }
                else if (i + 1 < H) {
                    ++mas[i + 1][j];
                    operations.emplace_back(i, j, i + 1, j);
                }
            }
        }
    }

    cout << operations.size() << endl;
    for (const auto& tup : operations) {
        int a, b, c, d;
        tie(a, b, c, d) = tup;
        cout << a + 1 << ' ' << b + 1 << ' ' << c + 1 << ' ' << d + 1 << '\n';
    }

    return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}

int main() {
  ll N, K; cin >> N >> K;
  ll INF = pow(10, 9) + 7;

  ll min_num = 0;
  ll max_num = 0;
  ll cnt = 0;
  for(int i = 0; i < K; ++i) {
    min_num += i;
    max_num += (N - i);
  }

  cnt += max_num - min_num + 1;

  for(int i = K; i <= N; ++i) {
    min_num += i;
    max_num += (N - i);

    cnt += max_num - min_num + 1;
    cnt = cnt % INF;
  }

  cout << cnt << endl;
}

Measured memory_bytes: 3636
local mmi, mma = math.min, math.max
local n, x = io.read("*n", "*n")
local a = {}
local t = {}
for i = 1, n do
  a[i] = io.read("*n")
  t[i] = {a[i]}
end
for i = 1, n do
  local ti = t[i]
  for j = 1, n - 1 do
    local use = i - j
    if use <= 0 then use = use + n end
    ti[j + 1] = mmi(ti[j], a[use])
  end
end
local ret = 0
for i = 1, n do
  ret = ret + t[i][1]
end
for j = 2, n do
  local v = 0
  for i = 1, n do
    v = v + t[i][j]
  end
  ret = mmi(ret, x * (j - 1) + v)
end
print(ret)


Measured memory_bytes: 66552
#include <iostream>
using namespace std;
 
int N, M;
int bulb[11];
int p[11];
 
int countbit(int v) {
  unsigned int c; // c accumulates the total bits set in v
  for (c = 0; v; c++)
    v &= v - 1; // clear the least significant bit set
  return c;
}
 
int main() {
  cin >> N >> M;
  for(int i = 1; i <= M; i++) {
    int k;
    cin >> k;
    for(int j = 0; j < k; j++) {
      int s;
      cin >> s;
      bulb[i] |= (1 << s);
    }
  }
  for(int i = 1; i <= M; i++)
    cin >> p[i];
 
 
  int ans = 0;
  for(int i = 0; i < (1 << (N+1)); i+=2) {
    bool success = true;
    for(int j = 1; j <= M; j++)
      if (countbit(bulb[j] & i) % 2 != p[j]) success = false;
    ans += success;
  }
  cout << ans;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
X = [int(x) for x in input().split()]
X.sort()
L = [X[i+1]-X[i] for i in range(len(X)-1)]
L.sort()
if N-1 > 0:
    print(sum(L)-sum(L[-(N-1):]))
else:
    print(sum(L))

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
std::random_device rnd_dev;
std::mt19937 rnd(rnd_dev() ^ time(NULL));

std::vector<int> init(int n, const std::vector<int> &c, const std::vector<std::vector<int> > &val) {
	(void) val;
	double par[26];
	for (int i = 0; i < 26; i++) par[i] = std::sqrt(c[i]);
	double sum = std::accumulate(par, par + 26, 0.0);
	int times[26];
	double acc = 0;
	for (int i = 0; i < 26; i++) {
		acc += par[i];
		times[i] = (acc + 0.00001) / sum * n;
	}
	for (int i = 25; i--; ) times[i + 1] -= times[i];
	// for (auto &i : times) i--;
	//for (auto i : times) std::cerr << i << std::endl;
	std::vector<int> res;
	for (int i = 0; i < 26; i++) for (int j = 0; j < times[i]; j++) res.push_back(i);
	std::shuffle(res.begin(), res.end(), rnd);
	// assert(res.size() == n);
	return res;
}


std::vector<int> solve(int n, const std::vector<int> &c, const std::vector<std::vector<int> > &val) {
	auto score = [&] (const std::vector<int> &all) {
		int last[26];
		for (auto &i : last) i = -1;
		int res = 0;
		for (int i = 0; i < n; i++) {
			int cur = all[i];
			last[cur] = i;
			for (int j = 0; j < 26; j++) res -= c[j] * (i - last[j]);
			res += val[i][cur];
		}
		return res;
	};
	clock_t start = clock();
	
	auto r26 = init(n, c, val);
	
	std::vector<int> cur = r26;
	int cur_score = score(cur);
	int best_score = -1000000000;
	std::vector<int> best;
	
	while (1) {
		clock_t cur_time = clock();
		if (cur_time - start > 1.95 * CLOCKS_PER_SEC) break;
		int r0 = std::uniform_int_distribution<>(0, n - 1)(rnd);
		int r1 = std::uniform_int_distribution<>(0, n - 1)(rnd);
		std::swap(cur[r0], cur[r1]);
		double threshold = 1.95 - (double) (cur_time - start) / CLOCKS_PER_SEC;
		// std::cerr << threshold << std::endl;
		int new_score = score(cur);
		if (new_score > best_score * (1 - threshold * 0.02)) cur_score = new_score;
		else std::swap(cur[r0], cur[r1]);
		if (best_score < cur_score) best_score = cur_score, best = cur;
	}
	
	return best;
}

void input() {
	int n = ri();
	std::vector<int> c(26);
	for (auto &i : c) i = ri();
	std::vector<std::vector<int> > val(n, std::vector<int>(26));
	for (auto &i : val) for (auto &j : i) j = ri();
	for (auto i : solve(n, c, val)) printf("%d\n", i + 1);
}

void random_test() {
	int n = 365;
	std::vector<int> c(26);
	for (auto &i : c) i = std::uniform_int_distribution<>(0, 100)(rnd);
	std::vector<std::vector<int> > val(n, std::vector<int>(26));
	for (auto &i : val) for (auto &j : i) j = std::uniform_int_distribution<>(0, 20000)(rnd);
	
	auto res = solve(n, c, val);
	
	
	int last[26];
	for (auto &i : last) i = -1;
	int score = 0;
	for (int i = 0; i < n; i++) {
		last[res[i]] = i;
		for (int j = 0; j < 26; j++) score -= c[j] * (i - last[j]);
		score += val[i][res[i]];
	}
	printf("%d\n", score);
}

int main() {
#	ifdef LOCAL
	random_test();
#	else
	input();
#	endif
	return 0;
}



Measured memory_bytes: 3940
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;
ll mpow(ll a, ll b) { ll r = 1; a %= mod; while (b) { r = r * ((b % 2) ? a : 1) % mod, a = a * a % mod, b >>= 1; }return r; }

ll n,a[2][3],dp[25000010];
ll f(ll n, int x, int y) {
	rep(i, 0, n + 1)dp[i] = i;
	rep(i, 1, n + 1)rep(j, 0, 3) {
		if (i < a[x][j])continue;
		if (a[x][j] >= a[y][j])continue;
		dp[i] = max(dp[i], dp[i - a[x][j]] + a[y][j]);
	}
	return dp[n];
}

int main() {
	cin >> n;
	rep(i, 0, 2)rep(j, 0, 3) cin >> a[i][j];
	printf("%lld", f(f(n,0,1),1,0));
	return 0;
}


Measured memory_bytes: 195584
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int M=cin.nextInt();
        Console.WriteLine(48-M);
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

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

typedef long long ll;
ll MOD = 1000000007;

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

    if (a%2 != b%2) cout << "IMPOSSIBLE" << endl;
    else cout << (a+b)/2 << endl;
    
    return 0;
}


Measured memory_bytes: 256