akhauriyash/Code-Regression huggingface dataset:
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")

h,w=map(int,input().split())
c=[list(map(int,input().split())) for i in range(10)]
a=[list(map(int,input().split())) for i in range(h)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j]=min(c[i][j],c[i][k]+c[k][j])
# print(c)
ans=0
for i in range(h):
    for j in range(w):
        if a[i][j]==-1:
            continue
        ans+=c[a[i][j]][1]
print(ans)

Measured memory_bytes: 40284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define REP(i, n) for(int i=0; i<n; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll mod = 1e9+7;

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    int n, k; cin >> n >> k;
    vector<int> h(n);
    REP(i, n){
        cin >> h[i];
    }
    sort(ALL(h));
    int diff = inf;
    REP(i, n-k+1){
        diff = min(h[k+i-1] - h[i], diff);
    }
    cout << diff << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

long long int gcd(long long int x, long long int y)
{
	if (y == 0) { return x; }
	return gcd(y, x % y);
}

int main(void)
{
	int n;
	cin >> n;
	if (n <= 2) { cout << 0 << endl; }
	else if (3 <= n && n <= 4) { cout << 1 << endl; }
	else if (n % 2 == 0) { cout << n / 2 - 1 << endl; }
	else{ cout << n / 2 << endl; }
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
def f():
    if m == 0:
        if n == 1:
            return 0
        elif n == 2:
            return 10
        elif n == 3:
            return 100
    else:
        for i in range(1000):
            x = str(i)
            if len(x) == n:
                cnt = 0
                for j in range(m):
                    if x[sc[j][0] - 1] == str(sc[j][1]):
                        cnt += 1
                        if cnt == m:
                            return x
                    elif x[sc[j][0] - 1] != str(sc[j][1]):
                        break
    return -1
print(f())

Measured memory_bytes: 8988
n,a,b=map(int,input().split())
mod=10**9+7

def nck(n,r,mod):
    r=min(n,r)
    if r==0:
        return 1
    num,inv_num=1,1
    for i in range(1,r+1):
        num=num*(n-i+1)%mod
        inv_num=inv_num*i%mod
    return num*pow(inv_num,mod-2,mod)%mod

ans=pow(2,n,mod)
t=nck(n,a,mod)
s=nck(n,b,mod)
ans-=t+s+1
while ans<0:
  ans+=mod
print(ans)


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

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

typedef long long ll;

const int INF=1e9+7;
const int MAX_N=1e2+5;
int c[MAX_N][MAX_N];
int h,w;
void put(int x,int i){
	int r=x/w;
	int col;
	x%=w;
	if(r%2==0)col=x;
	else col=w-x-1;
	c[r][col]=i;
}
int main(){
	cin>>h>>w;
	int n;
	cin>>n;
	int now=0;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		while(a--){
			put(now++,i+1);
		}
	}
	rep(i,h){
		rep(j,w){
			if(j)cout<<" ";
			cout<<c[i][j];
		}
		cout<<endl;
	}
}


Measured memory_bytes: 384
import java.util.*;
class Main{
    public static void main(String[] args){
	Scanner stdIn=new Scanner(System.in);
	int x = stdIn.nextInt();
	int a = stdIn.nextInt();
	int b = stdIn.nextInt();
	if(b<=a){
	    System.out.println("delicious");
	}else{
	    if(a<=b-x-1){
		System.out.println("dangerous");
	    }else{
		System.out.println("safe");
	    }
	}
    }
}


Measured memory_bytes: 21844
N,W=map(int,input().split())
goods=[[] for i in range(4)]
w1=-1
for i in range(N):
    w,v=map(int,input().split())
    if i==0:
        w1=w
    goods[w-w1].append(v)
S=[]
for x in range(4):
    goods[x].sort(reverse=True)
    G=goods[x]
    now=[0]*(len(G)+1)
    for i in range(len(G)):
        now[i+1]=now[i]+G[i]
    S.append(now)
ans=0
for i in range(1+len(goods[0])):
    for j in range(1+len(goods[1])):
        for k in range(1+len(goods[2])):
            wnow=W-w1*(i+j+k)-j-2*k
            if wnow<0:
                continue
            else:
                ans=max(ans,S[0][i]+S[1][j]+S[2][k]+S[3][min(len(S[3])-1,wnow//(w1+3))])
print(ans)

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

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()

template<typename T>
void chmin(T &x, T y) { x = min(x, y); }

template<typename T>
void chmax(T &x, T y) { x = max(x, y); }

typedef long long int lli;
typedef long double ld;
typedef tuple<int,int> P;

const int INF = INT_MAX/2 - 1;
const double EPS = 1e-14;
const int dx[4] = {0, 1, 0, -1}; // {-1,  0,  1, -1, 1, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0}; // {-1, -1, -1,  0, 0,  1, 1, 1};
typedef vector<vector<vector<char>>> Board;
struct Point {
  int x, y, z;
};
const char BLACK = 'B', WHITE = 'W';

bool is_in(Point p, int size) {
  return
    0 <= p.x && p.x < size &&
    0 <= p.y && p.y < size &&
    0 <= p.z && p.z < size;
}

bool check(const Board &b, Point init, Point dir, int m, char color) {
  int count = 0;
  Point p = init;
  int size = b.size();
  while (is_in(p, size)) {
    if (b[p.x][p.y][p.z] == color) {
      count++;
      if (count == m) { return true; }
    } else {
      count = 0;
    }
    p.x += dir.x, p.y += dir.y, p.z += dir.z;
  }
  return false;
}

bool match(const Board &b, int n, int m, char color) {
  const vector<Point> dirs = {
    {1, 0, 0}, {0, 1, 0}, {0, 0, 1},
    {0, 1, 1}, {1, 0, 1}, {1, 1, 0},
    {-1, 0, 1}, {-1, 1, 0}, {0, -1, 1}, {0, 1, -1}, {1, -1, 0}, {1, 0, -1},
    {1, 1, 1}, {-1, 1, 1}, {1, -1, 1}, {1, 1, -1}
  };
  REP(i, n) REP(j, n) REP(k, n) {
    for (Point dir : dirs) {
      if ( check(b, {i, j, k}, dir, m, color) ) { return true; }
    }
  }
  return false;
}

void push_back(vector<char> &seq, char color) {
  for (char &space : seq) {
    if (space) continue;
    space = color;
    return;
  }
  throw; /* balls overflow */
}

void solve(int n, int m, const vector<P> &hands) {
  int ans = 1;
  Board b(n, vector<vector<char>>(n, vector<char>(n)));
  for (P hand : hands) {
    int x, y; tie(x, y) = hand;
    push_back(b[x][y], (ans % 2 ? WHITE:BLACK));
    if (match(b, n, m, BLACK)) {
      cout << "White " << ans << endl;
      return;
    }
    if (match(b, n, m, WHITE)) {
      cout << "Black " << ans << endl;
      return;
    }
    ans++;
  }
  cout << "Draw" << endl;
}

int main() {
  cout << fixed << setprecision(10);
  int m, n, p;
  while (cin >> n >> m >> p and n) {
    vector<P> hands;
    REP(i, p) {
      int x, y;
      cin >> x >> y;
      hands.emplace_back(--x, --y);
    }
    solve(n, m, hands);
  }
  return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string w;
    cin>>w;
    int l;
    l=w.size();
    if(l%2!=0)
    {
        cout<<"No"<<"\n";
    }
    else
    {   int c=0;
        for(int i=0;i<l;i++)
        {
            for(int j=0;j<l;j++)
            {
                if(w[i]==w[j])
                {
                   c++;
                }
            }
            if(c%2!=0)
            {
               cout<<"No"<<"\n";
               break;
            }
        }
        if((c%2==0)&&(c>0))
        {
            cout<<"Yes"<<"\n";
        }
    }


return 0;}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(ll i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N = 1e6+7;
 
void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

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


int main()
{
	string s,t;
  cin>>s;
  cin>>t;
  int count=0;
  int len=s.size();
  for(int i=0;i<len;i++)
    if(s[i]!=t[i])
      count++;
  cout<<count;
return 0;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n, x, ans = 0;
    cin >> n >> x;
    vector<ll> a(n);
    rep(i, n)cin >> a[i];
    rep(i, n-1){
        if(a[i]+a[i+1] > x){
            if(a[i]+a[i+1]-x <= a[i+1]){
                ans += a[i]+a[i+1]-x;
                a[i+1] -= a[i]+a[i+1]-x;
            }
            else{
                ans += a[i+1];
                a[i+1] = 0;
                ans += a[i]-x;
                a[i] -= a[i]-x;  
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(){
  ll N,D; cin>>N>>D;
  D*=D;
  ll cnt=0;
  for( ll i=0; i<N; i++ ){
    ll a,b;
    cin>>a>>b;
    if(a*a+b*b <= D) cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3632
/* ****AWARE**** */
#include<bits/stdc++.h>
#include <limits.h> 
#define cut ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll          long long
#define pb          push_back
#define endl        '\n'
#define pii         pair< ll, ll>
#define vi          vector< ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(  ll i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp13       make_pair
using namespace std; 
#define MAX  3000
#define MODULO 2
using namespace std;   
#define hell 1000000007 
#define hell1 30000000000000000
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define mysizeof(i) (char*)(&i+1)-(char *)(&i);
ll T;
ll dp[MAX][MAX];
vector<ll>v;
void solve()
{    ll i,j,n,a,k,mn,cnt=1,ans,sum=0,l,r;
     cin>>n;
     for(i=0;i<n;i++)
     	cin>>a,v.pb(a);

     for(l=n-1;l>=0;l--)
     {

     	for(r=l;r<n;r++)
     	{
            
            if(l==r)
            {
            	dp[l][r]=0;
            	continue;
            }
            dp[l][r]=1e13;
            sum=0;
            for(i=l;i<=r;i++)
            	sum+=v[i];
            for(i=l;i<=r;i++)
            {
            	 dp[l][r]=min(dp[l][r],dp[l][i]+dp[i+1][r]+sum);
            }
     	}
     }
   cout<<dp[0][n-1];
      
    
    
}
           
int main(){ 
cut; 
ll t; 
//cin>>t;
//T=t;
 t=1;
while(t--)
solve();
return 0;
}
     


Measured memory_bytes: 5884
#include<stdio.h>

int main(void)
{
	int S;
	int h, m, s;
	scanf("%d", &S);
	
	h=S/3600;
	m=(S-h*3600)/60;
	s=S-h*3600-m*60;
	printf("%d:%d:%d\n", h, m, s);
	return 0;
}


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

ll llabs(ll n){
  if(n >= 0){
    return n;
  }

  return -n;
}

ll llmin(ll a, ll b){
  if(a > b){
    return b;
  }

  return a;
}

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

  ll a, b;

  a = llabs(n - (ll)(n / k) * k);

  b = llabs(a - k);

  cout << llmin(a, b);
  
  return 0; 
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

int main(int argc, char *argv[]) {
  int n;
  std::cin >> n;
  std::string s;
  std::cin >> s;
  for (int i = 0; i < n; ++i) {
    char c;
    std::cin >> c;
    std::cout << s.at(i) << c;
  }
  std::cout << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  int n, m;
  cin >> n >> m;
  vector<int> x(m);
  for (int i = 0; i < m; i++){
    cin >> x[i];
  }
  sort(x.begin(), x.end());
  vector<int> y(m-1);
  ll sum = 0;
  for (int i = 0; i < m - 1; i++){
    y[i] = x[i+1]-x[i];
  }
  sort(y.begin(), y.end());

  for (int i = 0; i < m - n; i++){
    sum += y[i];
  }

  cout << sum << endl;


  return 0;
}



Measured memory_bytes: 1024
import math
import sys
# libraries

alpha,beta = map(int, input().split())
    
for i in range(1010):
    sierra = math.floor(i*0.08)
    tango = math.floor(i*0.10)
    if sierra == alpha and tango == beta:
            print(i)
            break
else:
    print(-1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define ranger(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define repr(i, b) for (int i = (b)-1; i >= 0; i--)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S>& p) {
	os << '(' << p.first << ',' << p.second << ')';
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

const int M = 1000000007;
vector<vector<int>> dp;

signed main() {
	int n;
	cin >> n;

	bool a[30][30] = {};
	rep(i, n) rep(j, n) cin >> a[i][j];

	dp = vectors(n + 1, 1 << n, 0LL);
	dp[0][0] = 1;
	show((1 << n)) rep(i, n) {
		rep(s, 1 << n) {
			if (dp[i][s] == 0) continue;
			rep(j, n) {
				if (not a[i][j] or (s >> j) bitand 1) continue;
				(dp[i + 1][s bitor (1 << j)] += dp[i][s]) %= M;
				// show(bitset<3>(s bitor(1 << j)))
			}
		}
		// cout << dp << endl;
	}
	cout << dp.back().back() % M << endl;
}


Measured memory_bytes: 377216
// C++ program to find the longest repeated 
// non-overlapping substring 
#include<bits/stdc++.h> 
using namespace std; 
  
// Returns the longest repeating non-overlapping 
// substring in str 
string longestRepeatedSubstring(string str) 
{ 
    int n = str.length(); 
    int LCSRe[n+1][n+1]; 
  
    // Setting all to 0 
    memset(LCSRe, 0, sizeof(LCSRe)); 
  
    string res; // To store result 
    int res_length  = 0; // To store length of result 
  
    // building table in bottom-up manner 
    int i, index = 0; 
    for (i=1; i<=n; i++) 
    { 
        for (int j=i+1; j<=n; j++) 
        { 
            // (j-i) > LCSRe[i-1][j-1] to remove 
            // overlapping 
            if (str[i-1] == str[j-1] && 
                LCSRe[i-1][j-1] < (j - i)) 
            { 
                LCSRe[i][j] = LCSRe[i-1][j-1] + 1; 
  
                // updating maximum length of the 
                // substring and updating the finishing 
                // index of the suffix 
                if (LCSRe[i][j] > res_length) 
                { 
                    res_length = LCSRe[i][j]; 
                    index = max(i, index); 
                } 
            } 
            else
                LCSRe[i][j] = 0; 
        } 
    } 
  
    // If we have non-empty result, then insert all 
    // characters from first character to last 
    // character of string 
    if (res_length > 0) 
        for (i = index - res_length + 1; i <= index; i++) 
            res.push_back(str[i-1]); 
  
    return res; 
} 
  
// Driver program to test the above function 
int main() 
{ 
  int n;
  cin >> n;
    string str;
  cin >> str;
    cout << longestRepeatedSubstring(str).size() << endl;
    return 0; 
} 

Measured memory_bytes: 97920
#include <bits/stdc++.h>
using namespace std;
char s[5];
inline void cas1()
{int now=2,tp=1;
while(1)
{printf ("? %d\n",now);
fflush(stdout);scanf ("%s",s);
if (s[0]=='Y') {printf ("! %d\n",tp);return;}
now*=10;tp*=10;
}
return;
}
inline bool check(int m)
{printf ("? %lld\n",10ll*((long long)(m)));
fflush(stdout);scanf("%s",s);
if (s[0]=='Y') {return 1;}
return 0;
}
inline void cas2()
{int now=1,ws=0;
int p[11]={0,1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};
while(1)
{printf ("? %d\n",now);
fflush(stdout);scanf ("%s",s);
if (s[0]=='N') {break;}
ws++;now*=10;
}
int l=p[ws]+1,r=p[ws+1]-1;
while (l<=r)
{int mid=(l+r)>>1;
if (check(mid)) {r=mid-1;}
else {l=mid+1;}
}
printf ("! %d\n",l);
return;
}
int main (){
	printf ("? 1000000000\n");
	fflush(stdout);scanf ("%s",s);
	if (s[0]=='Y') {cas1();}
	else {cas2();}
	return 0;
}

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

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

    //お菓子を持っていたらtrueにする各人に関する配列
    bool judge[n];

    rep(i,n){
        judge[i] = false;
    }

    rep(i,k){
        int d;
        cin >> d;

        rep(j,d){
            int x;//diのお菓子をもつ人

            cin >> x;
            judge[x-1] = true;
        }
    }

    int ans = 0;
    rep(i,n){
        if(!judge[i]){
            ans++;
        }
    }

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

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b,c;
	cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b;
	return 0;
}


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

#define pb push_back
#define ff first
#define ss second

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

int a, b, c;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> a >> b >> c;
	cout << (c / a) * b;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(n));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> a[i][j];
    }
  }
  int total_sz = (1 << n);
  vector<ll> group_sum(total_sz, 0), f(total_sz, 0);
  for (int mask = 0; mask < total_sz; ++mask) {
    vector<int> v;
    for (int i = 0; i < n; ++i) {
      if (mask >> i & 1) {
        v.push_back(i);
      }
    }
    ll score = 0;
    int sz = v.size();
    for (int i = 0; i < sz; ++i) {
      for (int j = i + 1; j < sz; ++j) {
        score += a[v[i]][v[j]];
      }
    }
    f[mask] = group_sum[mask] = score;
  }

  for (int mask = 0; mask < total_sz; ++mask) {
    for (int submask = mask; submask; submask = (submask-1) & mask) {
      f[mask] = max(f[mask], f[mask ^ submask] + group_sum[submask]);
    }
  }
  cout << f[total_sz-1] << '\n';
  return 0;
}


Measured memory_bytes: 4300
#include<stdio.h>

/*入居者情報から、アパートの入居状況を表示する*/
/*棟数(b)：4、階数(f)：3、部屋数(r)：10*/
int main(){
	
	char c;
	int i,j,k,l;
	int person;
	int exam[50][4]={0};		//{中間試験、期末試験、再試験、中間+期末}
	
	c = '0';
	
	for(i=0; i<50; i++){
		for(j=0; j<3; j++){
			scanf("%d%c",&exam[i][j],&c);
			exam[i][3] = exam[i][0] + exam[i][1];
			if(c == '\n'){
				break;
			}
		}
		if(exam[i][0]==-1&&exam[i][1]==-1&&exam[i][2]==-1){
			person = i;
			break;
		}
	}
	
	for(i=0;i<person;i++){
		if(exam[i][0] == -1 || exam[i][1] == -1){
			printf("F\n");
		}else{
			if(exam[i][3]>=80){
				printf("A\n");
			}else if(exam[i][3]>=65){
				printf("B\n");
			}else if(exam[i][3]>=50){
				printf("C\n");
			}else if(exam[i][3]>=30){
				if(exam[i][2]>=50){
					printf("C\n");
				}else{
					printf("D\n");
				}
			}else if(exam[i][3]<30){
				printf("F\n");
			}else{
				printf("想定外の点数です。\n");
			}
		}
	}
	
	return 0;
}




Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 777;
int n , m ;
int no[N][N];
int col[N] , C[2];
vector<pair<int,int>>vec;
int mem[N][N];

int Sum(int x){ return x*(x-1)/2; }

int dp(int i,int j){
if( i == vec.size() )
    return (n-j)*(n-j-1)/2;

int &ret=mem[i][j];
if( ret != -1 )return ret;
return ret = min( dp(i+1,j+vec[i].first)  + Sum(j+vec[i].first)  - Sum(j)
                , dp(i+1,j+vec[i].second) + Sum(j+vec[i].second) - Sum(j) );
}

bool dfs(int u,int c){

if( col[u]!=-1 )
    return col[u]==c;
col[u]=c;
C[c]++;
for(int v=1;v<=n;v++)
    if( !no[u][v] && u!=v )
        if( !dfs(v,1-c))
            return 0;
return 1;
}


int main(){
memset(col,-1,sizeof col);

scanf("%d %d",&n,&m);
for(int i=1;i<=m;i++){
    int u,v;
    scanf("%d %d",&u,&v);
    no[u][v]=1;
    no[v][u]=1;
}

for(int i=1;i<=n;i++)
    if( col[i]==-1 ){
        C[0]=C[1]=0;
        if(!dfs(i,0)) return cout<<-1<<endl,0;
        vec.push_back( {C[0],C[1]} );
    }

memset(mem,-1,sizeof mem);
printf("%d\n",dp(0,0));

return 0;
}


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

int main(){
  string s;
  cin >> s;
  int n = s.length() - 2;
  bool flag = true;
  string s1, s2;
  while(flag){
    s = s.substr(0, n);
    s1 = s.substr(0, n / 2);
    s2 = s.substr(n / 2, n);
    if(s1 == s2){
      flag = false;
      n = s1.length() * 2;
    }else{
      n -= 2;
    }
  }
  cout << n << endl;
  return 0;
}


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

using namespace std;
const int MaxN = (int)2e5;

int N, M;
set<int> G[MaxN];

list<int> tour;

void del_edge(int a,int b)
{
    G[a].erase(b);
    G[b].erase(a);
}

void get_tour(int start, list<int>::iterator it)
{
    int cur = start;
    list<int>::iterator init_it = it;
    while(true)
    {
        int nxt = *G[cur].begin();
        del_edge(cur, nxt);
        cur = nxt;
        auto x = tour.insert(it, cur);
        if(init_it == it)
            init_it = x;
        if(cur == start)
            break;
    }
    list<int>::iterator cur_it = init_it;
    while(cur_it != it)
    {
        if(G[*cur_it].empty())
        {
            cur_it++;
            continue;
        }
        list<int>::iterator next = cur_it;
        next++;
        get_tour(*cur_it, next);
        cur_it = next;
    }
}

int main()
{
    cin >> N >> M;
    for(int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].insert(b);
        G[b].insert(a);
    }
    for(int i = 0; i < N; i++)
        if(G[i].size() % 2 == 1)
        {
            cout << "No";
            return 0;
        }

    int n4 = 0;
    for(int i = 0; i < N; i++)
        if(G[i].size() >= 6)
        {
            cout << "Yes";
            return 0;
        }
        else if(G[i].size() == 4)
            n4++;
    if(n4 >= 3)
    {
        cout << "Yes";
        return 0;
    }
    if(n4 <= 1)
    {
        cout << "No";
        return 0;
    }

    int u = -1, v = -1;
    for(int i = 0; i < N; i++)
        if(G[i].size() == 4)
        {
            if(u == -1)
                u = i;
            else 
                v = i;
        }

    int fu, su, fv, sv;

    tour.push_back(0);
    get_tour(0, tour.end());
    
    list<int>::iterator it;

    for(fu = 0, it = tour.begin(); it != tour.end() && *it != u; it++, fu++);
    it++;
    for(su = fu + 1; it != tour.end() && *it != u; it++, su++);

    for(fv = 0, it = tour.begin(); it != tour.end() && *it != v; it++, fv++);
    it++;
    for(sv = fv + 1; it != tour.end() && *it != v; it++, sv++);

    if((fv > fu && fv < su && (sv < fu || sv > su)) || (fv < fu && (fu < sv && sv < su)))
        cout << "No";
    else
        cout << "Yes";
    return 0;
}

Measured memory_bytes: 19072
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        
        if(s.equals("AAA") || s.equals("BBB")){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
}

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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	vector<int> c(4,0);
	bool ans = 1;
	repp(i,0,3){
		int a,b; cin >> a >> b;
		++c[a-1];
		++c[b-1];
		if(c[a-1] > 2 || c[b-1] > 2) ans = 0;
	}
	cout << (ans?"YES":"NO") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

// template<class T> struct edge { int to; T cost;};


// Bellman-Ford法2---------------------------------------------
// <https://atcoder.jp/contests/abc061/tasks/abc061_d>上のやつこれ通らんやんけ！
// 解説PDFを元に改良
// これは始点から行ける所に負の閉路があればtrueを返す。また negative[i]がtrueなら頂点iは負の閉路の影響を受ける

template<class T> struct edge { int from, to; T cost;};

int N,M; // 各々頂点数、辺数
const int MAX_N = 2500;
const int MAX_M = 5000;
vector<int> d(MAX_N);   // 最短距離             // llにするときは(ry
vector<edge<int>> es(MAX_M); // 辺              // llにするときはここもllにしてくれ
vector<bool> negative(MAX_N);
const int INFC = 1001001001;

// s番目の頂点から各頂点への最短距離を求める。但しtrueならアカン負の閉路が存在する
bool bellman_ford(int s){
  rep(i, N) d[i] = INFC;
  d[s] = 0;
  rep(vv, N-1){ rep(i, M){
    auto e = es[i];
    if (d[e.from] != INFC && d[e.to] > d[e.from] + e.cost) d[e.to] = d[e.from] + e.cost;
  }}
  bool nclose = false;
  rep(vv, N-1){ rep(i, M){ // 離島、負の閉路について
    auto e = es[i];
    if (d[e.from] == INFC) continue;
    if (d[e.from] + e.cost < d[e.to]) negative[e.from] = true, nclose = true;
    if (negative[e.from]) negative[e.to] = true;
  }}
  return nclose;
}

int solve(){
  cin >>N >>M;
  int P; cin >>P;
  d.assign(N, INFC);
  es.assign(M, {0,0,0});
  rep(i, M){
    int a,b,c; cin >>a >>b >>c; a--; b--;
    c = c - P; c *= -1;
    es[i] = {a, b, c};
  }
  bellman_ford(0);
  if (negative[N-1]) return -1;
  return max(-d[N-1], 0);
}

int main() {
  cout <<solve() <<endl;
}

Measured memory_bytes: 3664
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AnandOza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        COneQuadrillionAndOneDalmatians solver = new COneQuadrillionAndOneDalmatians();
        solver.solve(1, in, out);
        out.close();
    }

    static class COneQuadrillionAndOneDalmatians {
        private static final char A = 'a';

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();

            StringBuilder answer = new StringBuilder();
            while (n > 0) {
                n--;
                answer.append((char) (A + n % 26));
                n /= 26;
            }

            out.println(answer.reverse());
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 25656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef long int li;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll>P;
typedef tuple<ll, int, int>T;
#define PI 3.14159265358979


int main(){
  int X,Y;
  cin>>X>>Y;
  if(Y%2==1){cout<<"No";}
  else{
    int g=Y/2-X;
    int h=2*X-Y/2;
    if(g>=0&&h>=0){cout<<"Yes";}
    else{cout<<"No";}
  }
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define all(v)   v.begin(), v.end()
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define THINK_TWICE_CODE_ONCE cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n)  ((n)? (ll)(log10(n))+1 : 1)
#define mem(x, val)    memset(x, val, sizeof(x)) //be careful
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef string str;
typedef pair<int, int> pii;

const int N = 1000;
ll dp[N][N];
char arr[N][N];
int n, m;
ll solve(int r = 0, int c = 0){
    if(r==n || c==m) return 0;

    if(arr[r][c]=='#') return 0;

    if(r==n-1 && c==m-1) return 1;

    ll &ret = dp[r][c];

    if(~ret) return ret;

    return ret = (solve(r+1, c)%MOD + solve(r, c+1)%MOD)%MOD;
}
int main()
{
    THINK_TWICE_CODE_ONCE
    //freopen("test cases\\.txt", "r", stdin) ;
    cin>>n>>m;
    for(int i =0; i<n; i++)
        for(int j = 0; j<m; j++)
            cin>>arr[i][j];
    mem(dp, -1);
    cout<<solve();
	return 0;
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,d;
cin>>a>>b>>c>>d;
if(a+b>c+d)cout<<"Left"<<endl;
else if(a+b==c+d)cout<<"Balanced"<<endl;
else cout<<"Right"<<endl;
  return(0);
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc= new Scanner(System.in);
        String s ="ACL";
        String t="";
        int n = sc.nextInt();
    	for(int k=1;k<=n;k++){
            t += s;
        }
        System.out.println(t);
    }
}

Measured memory_bytes: 39436
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

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

    vector<int> A(N, 0);
    vector<int> B(N, 0);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        B[i] = A[i];
    }

    sort(B.begin(), B.end(), greater<int>());
    int max_val = B[0];
    int second_val = B[1];

    for(int i = 0; i < N; i++) {
        if(A[i] == max_val) cout << second_val << endl;
        else if(A[i] == second_val) cout << max_val << endl;
        else cout << max_val << endl;
    }

}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
using ll = long long;
using ui = unsigned int;


int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    ll s = 0;
    for (int i=0; i<N; i++) {
        ll tmp;
        cin >> tmp;
        A[i] = tmp;
        s += tmp;
    }
    vector<ll> X(N);
    X[0] = s;
    for (int i = 1; i < N-1; i+=2)
    {
        X[0] -= 2*A[i];
    }
    
    for (int i = 1; i < N; i++)
    {
        X[i] = 2 * A[i-1] - X[i-1];
    }

    for (auto e : X) {
        cout << e << " ";
    }
    cout << "\n";
}

Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cstring>
#include <cstdio>
#define rep(i,n) for(int i = 0 ; i < n ; i++)
using namespace std;

typedef map<long long,int> U;

long long gcd(long long a,long long b){
	return b ? gcd(b,a%b) : a;
}

long long lcm(long long a,long long b){
	return a / gcd(a,b) * b;
}

U factor(long long N){
	U p;
	for(int i = 2 ; i * i <= N ; i++){	
		while(N%i==0)p[i]++,N/=i;
	}
	if( N != 1 ) p[N]++;
	return p;
}
U gcd(U a,U b){
	U c;
	for( U::iterator it = a.begin() ; it != a.end() ; ++it){
		if( b.count(it->first) ) continue;
		c[it->first] = min(it->second,b[it->first]);
	}
	return c;
}
U lcm(U a,U b){
	U c;
	for( U::iterator it = a.begin() ; it != a.end() ; ++it){
		c[it->first] = max(c[it->first],it->second);
	}
	for( U::iterator it = b.begin() ; it != b.end() ; ++it){
		c[it->first] = max(c[it->first],it->second);
	}
	return c;
}
U mul(U a,U b){
	for( U::iterator it = a.begin() ; it != a.end() ; ++it){
		b[it->first] += it->second;
	}
	return b;
}
U div(U a,U b){
	for( U::iterator it = b.begin() ; it != b.end() ; ++it){
		a[it->first] -= it->second;
	}
	return a;
}
long long conv(U a){
	long long res = 1;
	for( U::iterator it = a.begin() ; it != a.end() ; ++it){
		for(int j = 0 ; j < it->second ; j++) res *= it->first;
	}
	return res;
}
int main(){
	ios_base::sync_with_stdio(false);
	int n;
	
	while(cin >> n && n){
		U  A[10],B[10] = {};
		U l;
		for(int i = 0 ; i < n ; i++){
			long long a_,b_;
			cin >> a_ >> b_;
			U a = factor(a_);
			U b = factor(b_);
			U g = gcd(a,b);
			a=div(a,g);
			b=div(b,g);
			l = lcm(l,b);
			A[i] = a;
			B[i] = b;
		}
		U L;
		for(int i = 0 ; i < n ; i++){
			U a = div(mul(A[i],l),B[i]);
			//cout << a << endl;
			B[i] = l;
			A[i] = a;
			L = lcm(a,L);
		}
		for(int i = 0 ; i < n ; i++){
			cout << conv(div(L,A[i])) << endl;
		}
		
	}
}

Measured memory_bytes: 928
N = int(input())
A = list(map(int, input().split()))
cnt = 1
flg = 0
for i in range(1, N):
    if flg == 0:
        if A[i-1] < A[i]:
            flg = 1
        elif A[i-1] > A[i]:
            flg = -1
    if flg == -1:
        if A[i-1] < A[i]:
            flg = 0
            cnt += 1
    if flg == 1:
        if A[i-1] > A[i]:
            flg = 0
            cnt += 1
print(cnt)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
#define pii pair<LL,LL>

using namespace std;

int main(){

    string s,t;cin>>s>>t;
    LL scnt[s.size()+1],tcnt[t.size()+1];
    scnt[0]=tcnt[0]=0;

    REP(i,s.size()){
        if(s[i]=='A')scnt[i+1]=scnt[i]+1;
        else scnt[i+1]=scnt[i]-1;
    }
    REP(i,t.size()){
        if(t[i]=='A')tcnt[i+1]=tcnt[i]+1;
        else tcnt[i+1]=tcnt[i]-1;
    }

    //+1 = -2 なので+30000000000 %3 が等しいかどうか
    int q;cin>>q;
    REP(i,q){
        int a,b,c,d;cin>>a>>b>>c>>d;
        if((scnt[b]-scnt[a-1]+30000000)%3==(tcnt[d]-tcnt[c-1]+3000000)%3)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;

    }

    return 0;
};

Measured memory_bytes: 2560
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := nextInts(n)

	ans := 0
	for i := 0; i < n; i++ {
		l, r := i, i+1
		for r+1 < n && (a[r]-a[l])*(a[r+1]-a[r]) >= 0 {
			r++
		}
		ans++
		i = r
	}
	puts(ans)
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 3072
/*

Sviatoslav Bidzilia 2019
CF: anakib1

*/

#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <chrono>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <deque>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdarg.h>
#include <functional>
#include <utility>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unisgned long long
#define ld long double
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))
#define pii pair<int, int>
#define tii triple<int, int, int>
#define e 1e-7
#define PI acos(-1)
#define inf 1e17
#define sz(a) (int)(a.size())
#define vi vector<int>
#define F first
#define S second
#define rng(x) for(int _ = 0; _ < (x); _++)
#define rngi(i, x) for(int i = 0; i < (x); i++)
#define rngsi(s, i, x) for(int i = (s); i <(x); i++)
#define int long long

template<typename A, typename B, typename C>
struct triple
{
	A X;
	B Y;
	C Z;
	triple(A a = 0, B b = 0, C c = 0) :X(a), Y(b), Z(c) {}
};
template<typename A, typename B, typename C>
triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0)
{
	return triple<A, B, C>(a, b, c);
}
template<typename A, typename B, typename C>
bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b)
{
	if (a.X != b.X)
		return a.X < b.X;
	if (a.Y != b.Y)
		return a.Y < b.Y;
	return a.Z < b.Z;
}
template<typename T, typename SS>
ostream& operator<<(ostream& ofs, const pair<T, SS>& p)
{
	ofs << "( " << p.F << " , " << p.S << " )";
	return ofs;
}
template<typename T>
void print(T a)
{
	for (auto i : a)
		cout << i << ' ';
	cout << '\n';
}
template<typename T>
T max(T a, T b, T c)
{
	return max(a, max(b, c));
}
template<typename T>
T min(T a, T b, T c)
{
	return min(a, min(b, c));
}
struct custom_hash
{
	static uint64_t splitmix64(uint64_t x)
	{
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const
	{
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};
signed main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	srand(time(NULL));
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	int n, k; cin >> n >> k;
	const int mod = 1e9 + 7;
	vi a(n + 1); a[0] = 0; rngi(i, n) a[i + 1] = (a[i] + i + 1) % mod;
	vi b(n + 1); b[0] = n; rngi(i, n) b[i + 1] = (b[i] +n - i - 1) % mod;
	int ans = 0;
	for (int v = k; v <= n + 1; v++) (ans += b[v - 1] + mod - a[v - 1] + 1) %= mod;
	cout << ans << '\n';
}

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

using namespace std;

const vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  vector<vector<bool>> used(H, vector<bool>(W, false));
  auto f = [&](int64_t y, int64_t x) {
    int b = 0, w = 0;
    queue<pair<int, int>> que;
    que.push(make_pair(y, x));

    while (!que.empty()) {
      auto q = que.front();
      que.pop();

      int y = q.first, x = q.second;
      for (int k = 0; k < 4; k++) {
        int ny = y + dy[k], nx = x + dx[k];
        if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
        if (used[ny][nx] || S[y][x] == S[ny][nx]) continue;
        if (S[ny][nx] == '.') w++;
        if (S[ny][nx] == '#') b++;
        que.push(make_pair(ny, nx));
        used[ny][nx] = true;
      }
    }
    return make_pair(b, w);
  };
  int64_t res = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (used[i][j] || S[i][j] == '.') continue;
      used[i][j] = true;
      pair<int64_t, int64_t> cnt = f(i, j);
      res += (cnt.first + 1) * cnt.second;
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(998244353)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

// 素数かどうかの判定
bool IsPrime(ll num){
    if(num<2) return false;
    else if(num==2) return true;
    else if(num%2==0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for(ll i=3; i<=sqrtNum; i+=2){
        if(num%i==0) return false;
    }
    return true;
}


signed main() {
	ll n; cin>>n;
	string ans="";
	while(n>0){
		if(n%26==0) ans='z'+ans, n-=26;
		else ans=(char)('a'+n%26-1)+ans;
		n/=26;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
//#define int long long
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int inf = 1e9+10;

void solve(){
	
	int n, w;
	cin >> n >> w;
	
	vector<int> peso(n), value(n);
	for(int i = 0; i < n; i++)
		cin >> peso[i] >> value[i];
		
	vector<vector<int>> dp(2, vector<int>(1e6, inf));
	
	dp[0][0] = 0;
	dp[1][0] = 0;
	int ans = 0;
	for(int pos = 0; pos < n; pos++){
		int par = (pos & 1);
		int next = 1 - par;
		for(int val = 0; val <= 1e5; val++){
			dp[next][val+value[pos]] = min(dp[next][val+value[pos]], dp[par][val] + peso[pos]);
			dp[next][val] = min(dp[par][val], dp[next][val]);
			if(dp[next][val+value[pos]] <= w)
				ans = max(ans, val+value[pos]);
		}
	}
	
	cout << ans << endl;
}

int32_t main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	
	int tc = 1;
	//cin >> tc;
	while(tc--)
		solve();
}


Measured memory_bytes: 12032
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map
#include<cmath>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 10000007

typedef  long long ll;

using namespace std;

ll gcd(ll a,ll b){
    if (b==0)return a;
    return gcd(b,a%b);
}

ll deg(int i){
  ll ret = 1;
  while(i != 0){
    if(i/10 == 0){
      break;
    }
    i/=10;
  }
  
  return i;
}

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


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


Measured memory_bytes: 3328
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);

	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	ll n, m;
	cin >> n >> m;
	ll arr[n + 1];
	for (ll i = 1; i <= n; i++)
	{
		cin >> arr[i];
	}
	vector<vector<ll> >c(n + 1);
	for (ll i = 1; i <= m; i++)
	{
		ll a, b;
		cin >> a >> b;
		c[a].pb(b);
		c[b].pb(a);
	}
	ll ans = 0;
	for (ll i = 1; i <= n; i++)
	{
		if (c[i].size() == 0)
		{
			ans++;
			continue;
		}
		ll f = 0;
		ll temp = arr[i];
		for (auto x : c[i])
		{
			if (arr[x] < temp)
			{
				f++;
			}
		}
		if (f == c[i].size())
		{
			ans++;
		}
	}
	cout << ans << endl;

}



Measured memory_bytes: 9788
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define ALL(a) (a).begin(),(a).end()
#define EACH(e,v) for(auto& e:v)
#define SORT(v) sort(ALL(v))
#define PERM(v) SORT(v);for(bool c##p=1;c##p;c##p=next_permutation(ALL(v)))
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = 1000'000'007;
 
signed main(){
 int n;
 cin>>n;
 cout<<(n%2==0 ? n/2-1 : n/2)<<endl;
}

Measured memory_bytes: 256