akhauriyash/Code-Regression huggingface dataset:
/*
 *  Lang    : C++
 *  Author  : little_angel
 */
#include <bits/stdc++.h>

using namespace std;
#define int long long

int n, a[16][16], dp[1ull << 17u], val[1ull << 17u];

// mask  = number of rabbits already paired

int sol(unsigned int mask) {
    if (~dp[mask])return dp[mask];
    if (mask == (1ull << n) - 1)return 0;
    int maxx = LONG_LONG_MIN;
    int st = (1ull << n) - 1 - mask;
    for (unsigned int i = st; i >= (st & -st); --i) {
        if ((i & mask) != 0)continue;
        int new_sc = val[i] + sol(mask ^ i);
        maxx = max(maxx, new_sc);
    }
    return dp[mask] = maxx;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> a[i][j];
        }
    }

    clock_t s = clock();
    memset(dp, -1, sizeof(dp));

    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            for (int k = 3; k < (1 << n); ++k) {
                if (((1ull << i) & k) && ((1ull << j) & k))val[k] += a[i][j];
            }
        }
    }

    cout << sol(0) << endl;
    cerr << (double) (clock() - s) / CLOCKS_PER_SEC << endl;
}

Measured memory_bytes: 1792
iipt=lambda:int(input())
miipt=lambda:list(map(int,input().split(" ")))
n=iipt()
r=[]
b=[]
for i in range(n):
    r.append(miipt())
for i in range(n):
    b.append(miipt())
r.sort(key=lambda x:x[1], reverse=True)
b.sort()
c=0
for xb, yb in b:
    for i, (xr, yr) in enumerate(r):
        if xr<xb and yr<yb:
            r[i]=(212, 212)
            c+=1
            break
    else:
        continue
print(c)

Measured memory_bytes: 3064
/*
  AOJ 0285
  Title:Tennis
  @kankichi573
*/
#include <stdio.h>
#include <string.h>
int j,y;

void solve(char *his,int j0,int y0,int jwin,int ywin)
{
  char myhis[2][10];

  if(j0==jwin && y0==ywin)
    printf("%s\n",his);
  else if(j0==4 && y0==4)
    {
      if (jwin==5 && ywin==4)
	printf("%sA\n",his);
      else if (jwin==4 && ywin==5)
	printf("%sB\n",his);
      if (jwin==5 && ywin==5)
	{
	  printf("%sAB\n",his);
	  printf("%sBA\n",his);
	}
      if (jwin==6 && ywin==4)
	printf("%sAA\n",his);
      if (jwin==4 && ywin==6)
	printf("%sBB\n",his);
    }
 else
    {
      if(j0<jwin && j0 < 4 || j0==4 && y0==ywin)
	{
	  strcpy(&myhis[0][0],his);
	  myhis[0][j0+y0]='A';
	  myhis[0][j0+y0+1]='\0';
	  solve(&myhis[0][0],j0+1,y0,jwin,ywin);
	}
      if(y0<ywin && y0 < 4 || y0==4 && j0==jwin)
	{
	  strcpy(&myhis[1][0],his);
	  myhis[1][j0+y0]='B';
	  myhis[1][j0+y0+1]='\0';
	  solve(&myhis[1][0],j0,y0+1,jwin,ywin);
	}
    }
}



main()
{
  scanf("%d %d",&j,&y);
  solve("",0,0,j,y);
  return(0);
}

Measured memory_bytes: 604
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 100000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int n,W;
int value[105],weight[105];
int dp[105][10005];

void solve(){
  rep(i,W+1)dp[0][i]=0;
  rep(i,n){
    rep(w,W+1){
      if(w>=weight[i])dp[i+1][w]=max(dp[i][w-weight[i]]+value[i],dp[i][w]);
      else dp[i+1][w]=dp[i][w];
    }
  }
  cout<<dp[n][W]<<endl;
}

int main(){
  cin>>n>>W;
  rep(i,n)cin>>value[i]>>weight[i];
  solve();
  return 0;
}

Measured memory_bytes: 7064
#include <cstdio>
#include <cstring>
int n,b[4];double dp[301][301][301];
int main()
{
	scanf("%d",&n);for(int i=1;i<=n;++i){int x;scanf("%d",&x);++b[x];}
	for(int k=0;k<=n;++k)for(int j=0;k+j<=n;++j)for(int i=0;i+j+k<=n;++i)
	{
		if(!i&&!j&&!k)continue;
		double c1=0,c2=0,c3=0;
		if(i)c1=(double)i/n*dp[i-1][j][k];if(j)c2=(double)j/n*dp[i+1][j-1][k];if(k)c3=(double)k/n*dp[i][j+1][k-1];
		dp[i][j][k]=(double)n/(i+j+k)*(c1+c2+c3+1);
	}
	printf("%.9lf\n",dp[b[1]][b[2]][b[3]]);return 0;
}

Measured memory_bytes: 213120
# %%time
from numba import njit
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))


@njit
def f(A):
    ans = 1
    limit = 10**18
    if np.sum(A == 0) > 0:
        return 0
    elif np.sum(np.log10(A)) > 18:
        return -1
    for i in A:
        ans = ans*i
    return ans if ans<=limit else -1



print(int(f(A)))

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

struct RMQ {
	using type = int;
	static type id() { return INT_MAX; }
	static type op(const type& l, const type & r) { return min(l, r); }
};

template <typename M>
class StarrySkyTree {
	using T = typename M::type;
	const int n;
	vector<T> data, lazy;
	int size(int n) {
		int res = 1;
		while (res < n) res <<= 1;
		return res;
	}
	T sub(int l, int r, int node, int lb, int ub) {
		if (r <= lb || ub <= l) return M::id();
		if (l <= lb && ub <= r) return data[node];
		return M::op(sub(l, r, node << 1, lb, (lb + ub) >> 1)
			, sub(l, r, (node << 1) | 1, (lb + ub) >> 1, ub)) + lazy[node];
	}
	void suc(int l, int r, int node, int lb, int ub, T val) {
		if (ub <= l || r <= lb) return;
		if (l <= lb && ub <= r) {
			data[node] += val;
			lazy[node] += val;
			return;
		}
		suc(l, r, node << 1, lb, (lb + ub) >> 1, val);
		suc(l, r, (node << 1) | 1, (lb + ub) >> 1, ub, val);
		data[node] = M::op(data[node << 1], data[(node << 1) | 1]) + lazy[node];
	}
public:
	StarrySkyTree(int n_) : n(size(n_)), data(n << 1), lazy(n << 1) {}
	void add(int l, int r, T val) {
		suc(l, r + 1, 1, 0, n, val);
	}
	T find(int l, int r) {
		return sub(l, r + 1, 1, 0, n);
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q;
	cin >> n >> q;
	StarrySkyTree<RMQ> sst(n);
	while (q--) {
		int com;
		cin >> com;
		if (com == 0) {
			int s, t, x;
			cin >> s >> t >> x;
			sst.add(s, t, x);
		}
		else {
			int s, t;
			cin >> s >> t;
			printf("%d\n", sst.find(s, t));
		}
	}
	return 0;
}



Measured memory_bytes: 4944
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
f = []
p = []
for i in range(n):
    f.append(inl())
for i in range(n):
    p.append(inl())
mx = -BIG
for t in range(1,2**10):
    s = [(t>>i)%2 for i in range(10)]
    sm = 0
    for i in range(n):
        x = sum([s[j]*f[i][j] for j in range(10)])
        sm += p[i][x]
    mx = max(mx,sm)
print(mx)


Measured memory_bytes: 42092
#include <valarray>
#include <cstdio>
using namespace std;
typedef valarray<int>V;
int n,m;
V e,x,z,w;
void Me(const V &_x,const V &_y){
	int i=0,j;
	for(;i<n;i++)for(j=0;j<n;j++)z[i*n+j]=(_x[slice(i*n,n,1)]*_y[slice(j,n,n)]).sum()%m;
	e=z;
}
void Mx(const V &_x){
	int i=0,j;
	for(;i<n;i++)for(j=0;j<n;j++)w[i*n+j]=(_x[slice(i*n,n,1)]*_x[slice(j,n,n)]).sum()%m;
	x=w;
}
void O(const V &r,const V &s){
	int i=0;
    for(;i<n-1;i++)printf("%d ",(r[slice(i*n,n,1)]*s).sum()%m);
    printf("%d\n",(r[slice(i*n,n,1)]*s).sum()%m);
}
main(){
	int i,a,b,c,t;
	for(;scanf("%d%d%d%d%d%d",&n,&m,&a,&b,&c,&t),n;){
		x.resize(0);
		x.resize(n*n);
		e.resize(0);
		e.resize(n*n);
		z.resize(n*n);
		w.resize(n*n);

		x[0]=b;
		x[1]=c;
		e[0]=1;
		for(i=1;i<n-1;i++){
			x[i*n+i-1]=a;
			x[i*n+i]=b;
			x[i*n+i+1]=c;
			e[i*n+i]=1;
		}
		x[i*n+i-1]=a;
		x[i*n+i]=b;
		e[i*n+i]=1;
		for(;t;t>>=1){
			if(t&1)Me(e,x);
			Mx(x);
		}
		V s(n);
		for(i=0;i<n;i++)scanf("%d",&s[i]);
		O(e,s);
	}
}

Measured memory_bytes: 1100
#include <stdio.h>

int main(){
  int i,j,n,minj,temp,a[100],sw=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  for(i=0;i<=n-1;i++){
    minj=i;

    for(j=i;j<=n-1;j++){
      if(a[j]<a[minj])minj=j;
    }

    temp=a[i];
    a[i]=a[minj];
    a[minj]=temp;
    if(i!=minj)sw++;
  }

  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i!=n-1)printf(" ");
  }

  printf("\n%d\n",sw);

  return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define rep(i, c) for (int i = 0;i<(int)c;i++)
using namespace std;
int main(){
  long long int N, K;
  cin >> N >> K;
  long long int tmp;
  if (N >= K)
  {
    tmp = N % K;
  }
  else
  {
    tmp = N;
  }
  //cout << tmp << endl;
  cout << min(tmp, abs(tmp - K)) << endl;
}

Measured memory_bytes: 256
// ボール: 区別なし, 箱：区別あり, 入れ方: 1 つ以上
#include <iostream>
using namespace std;
const int MOD = 1000000007;
const long long MAXN = 1001024;
long long fac[MAXN], finv[MAXN], inv[MAXN];

// 前処理 O(n)
void comb_init(){
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(long long i = 2; i < MAXN; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算 O(1)
// 定義できない奴は 0 を返すようにしている
long long COM(long long n, long long k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
  
  comb_init();
  int n, k; cin >> n >> k;
  cout << COM(n - 1, n - k) << endl;

  return 0;
}



Measured memory_bytes: 26564
import java.util.Scanner;

public class Main {

  private static final int mod = 1000000007;

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[][] val = new int[n][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        val[i][j] = sc.nextInt();
      }
    }

    int ans = solve(val);
    System.out.println(ans);
  }

  private static int solve(int[][] val) {
    int n = val.length;
    int[] dp = new int[1 << n];
    dp[0] = 1;
    for (int mask = 0; mask < (1 << n) - 1; ++mask) {
      int a = numbersOf1(mask);
      for (int b = 0; b < n; b++) {
        if (val[a][b] == 1 && (mask & (1 << b)) == 0) {
          int mask2 = mask ^ (1 << b);
          dp[mask2] = addSelf(dp[mask2], dp[mask]);
        }
      }
    }
    return dp[(1 << n) - 1];
  }

  private static int numbersOf1(int mask) {
    String s = Integer.toBinaryString(mask);
    int count = 0;
    for (int i = 0; i < s.length(); ++i) {
      if (s.charAt(i) == '1') {
        count++;
      }
    }
    return count;
  }

  private static int addSelf(int s, int i) {
    s += i;
    if (s >= mod) {
      s -= mod;
    }
    return s;
  }
}


Measured memory_bytes: 74220
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
int N, Q;
vector<int> counter;
Graph G;
vector<bool> seen;
vector<int> first_order;
void dfs(const Graph &G, int v, int& ptr) {
    seen[v] = true;
    first_order[v] = ptr++;
    for(auto next_v : G[v]){
        if(seen[next_v]) continue;
        counter[next_v] += counter[v];
        dfs(G, next_v, ptr);
    }
}

int main(){
    cin >> N >> Q;
    Graph G(N);
    for (int i = 0; i < N-1; i++)
    {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    counter.resize(N);
    for (int i = 0; i < Q; i++)
    {
        int v, x;
        cin >> v >> x;
        v--;
        counter[v] += x;
    }

    seen.assign(N, false);
    first_order.resize(N);
    int ptr = 0;
    dfs(G, 0, ptr);

    for (int i = 0; i < N; i++)
    {
        cout << counter[i];
        if(i != N - 1) cout << " ";
        else cout << endl;
    }
    
}

Measured memory_bytes: 27392
A,B,C,D=input().split()
A=int(A)
B=int(B)
C=int(C)
D=int(D)
def dif(x,y):
  if x%y ==0:
    z=x//y
  if x%y>0:
    z=x//y+1
  return(z)

N=dif(C,B)
M=dif(A,D)
if M>=N:
  print('Yes')
else:
  print('No')

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

#define     fast()              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define     ll                  long long int
#define     test()              ll t; cin>>t; while(t--) 
#define     lp0(i,begin,end)    for(ll i=begin;i<end;i++)
#define     lp1(i,begin,end)    for(ll i=begin;i<=end;i++)
#define     rlp(i,begin,end)    for(ll i=end;i>=begin;i--)
#define     prec(n)             fixed<<setprecision(n)
#define     initial(a,i)        memset(a,i,sizeof(a))
#define     pb                  push_back
#define     PI                  3.1415926535897932384626433832795
#define     MOD                 1000000007
#define     F                   first
#define     S                   second
#define     all(a)              (a).begin(),(a).end()
#define     BPC(x)              __builtin_popcountll(x)
#define     gcd(a,b)            __gcd(a,b)

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

ll power(ll x,ll n)
{
    ll result = 1;
    while (n)
    {
        if (n & 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}


// Solution Function
void solution(ll compte)
{
    // cout<<compte<<"\n";
    float r;
    cin>>r;
    cout<<(2.000 * PI *r);
}
// Driver Function
int main()
{
    ll compte = 1;
    //test()
    //{
        solution(compte);
        compte++;
    //}
    return 0;
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define mk make_pair
int main()
{
  ll a,b;
  cin>>a>>b;
  if(b>=a)
  cout<<"unsafe"<<endl;
  else
  cout<<"safe"<<endl;
  
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _h cout<<"here"<<endl;
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;i+=1)
#define prarr(a,n) rep(i,n) cout<<a[i]<<" \n"[i==n-1];// printf("%s\n"," " );
#define ff first
#define ss second
#define pu push_back
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T> 
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.ff<<", "<<p.ss<<')';return out;}
template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
const int inf = 1e9+10;
const ll INF = 1e18+10;
const int MOD = 1e9+7;
const int MAXN = 2e5+10;

void solve()
{
	int n, m, k;
	int h,w;
	char c;
	cin>>h;
	cin>>w>>n;
	int mx = max({h,w});
	int mi = min({h,w});
	int ans = n/mx;
	if(n%mx) ans++;
	cout<<ans<<endl;}
int main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin>>t;
	while(t--){
		solve();
	}
	return 0;

}
    

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

int main() {
  int N , i=0 , sum=0 , p=1; 
  cin >> N ;
  while ( N/p != 0 ){
    sum += (N/p)%10;
    p *= 10;
    i += 1;
  }
  if ( N % sum == 0 )
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 384
//kalyanchirla
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
#define int long long
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define csl ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
int32_t main()
{ 
    csl;

    int n,m;
    cin >> n >> m;

    char arr[n][m];

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin >> arr[i][j];
        }
    }
    char ans[n+2][m+2];
    for(int i=0;i<n+2;i++)
    {
        for(int j=0;j<m+2;j++)
        {
            ans[i][j]='#';
        }
    }
    for(int i=1;i<n+1;i++)
    {
        for(int j=1;j<m+1;j++)
        {
            ans[i][j]=arr[i-1][j-1];
        }
    }
    for(int i=0;i<n+2;i++)
    {
        for(int j=0;j<m+2;j++)
        {
            cout << ans[i][j];
        }
        cout << "\n";
    }
}

Measured memory_bytes: 3656
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60


int main() {
    string S;
    cin >> S;

    int ans = 1e9, N = S.length();

    REP(i, N-1) {
        if(S[i] != S[i+1]) {
            ans = min(ans, max(i+1, N-(i+1)));
        }
    }

    if(ans == 1e9) {
        ans = N;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

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

    vector<pair<long long, long long>> currentState;
    currentState.push_back(make_pair(1000, 0));
    long long cntZeroMax = 1000;
    for(int i = 0; i < N; i++){
        vector<pair<long long, long long>> nextState;
        for(auto p: currentState){
            long long money = p.first;
            long long cnt = p.second;
            if(cnt > 0){
                long long temp = money + A[i] * cnt;
                if(temp > cntZeroMax){
                    cntZeroMax = temp;
                }
                nextState.push_back(p);
            }
            else{
                cntZeroMax = max(cntZeroMax, money);
                long long nextCnt = money / A[i];
                long long nextMoney = money - A[i] * nextCnt;
                nextState.push_back(make_pair(nextMoney, nextCnt));
            }
        }
        nextState.push_back(make_pair(cntZeroMax, 0));

        swap(currentState, nextState);
    }

    cout << cntZeroMax << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv vector<int>
#define endl "\n"
#define test(i) cout<<i<<endl
#define tests(i) cout<<"i: "<<i<<endl;
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(a,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())
void file(){
    #ifdef LOCAL
    freopen("demo.in","r",stdin);
    freopen("demo.out","w",stdout);
    #endif
}
bool sortdes(const pair<int,int> &a, const pair<int,int> &b){return a.ss<b.ss;}
bool sortasc(const pair<int,int> &a, const pair<int,int> &b){return a.ss>b.ss;} 
int gcd(int x,int y){return __gcd(x,y);}
lld fact(lld n);
lld nCr(lld n,lld r){return fact(n) / (fact(r) * fact(n - r));}
lld fact(lld n){ lld res = 1; for(lld i = 2; i <= n; i++){res = res * i;}return res;} 
const int maxi = 1e6+10;
vector<int> v[maxi];
long long a[maxi];
void dfs(int x,int y){
    a[x]+=a[y];
    for(int i:v[x]){
        if(i!=y){
            dfs(i,x);
        }
    }
}

void test_case(){
    int n;
    cin>>n;
    unordered_map<string,int> ump;
    lld cnt=0;
    for(int i=0;i<n;++i){
        string temp;
        cin>>temp;
        sort(temp.begin(),temp.end());
        if(ump[temp]){
            cnt+=ump[temp];
            ++ump[temp];
        }
        else{
            ump[temp]=1;
        }
    }
    test(cnt);
}

int main(){
    fastio;
    file();
    int T=1;
    // int T;
    // cin>>T;
    for(int nr=1;nr<=T;++nr) {
        // cout<<"Case #"<<nr<<": ";
		test_case();
    }
}

Measured memory_bytes: 35748
import java.util.Scanner;

public class Main
{

    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        int H = scan.nextInt();
        int W = scan.nextInt();
        while (W != 0 && H != 0) {
            for (int s = 0; s != H; s++) {

                for (int i = 0; i != W; i++) {
                    System.out.print("#");
                }
                System.out.println();

            }
            H = scan.nextInt();
            W = scan.nextInt();
            System.out.println();

        }
    }
}



Measured memory_bytes: 36756
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n) ; ++i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define emb emplace_back

using namespace std;
using ll = long long;
using P = pair<int,int>;

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> s(m,0);
  vector<int> c(m,0);
  rep(i,m) cin >> s.at(i) >> c.at(i);
  rep(i,m){
    rep(j,m) {
      if(i == j) continue;
      if(s.at(i) == s.at(j) and c.at(i) != c.at(j)) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  if(n==2 or n == 3) {
    rep(i,m) {
       if(s.at(i) == 1 and c.at(i) == 0) {
         cout << "-1" << endl;
         return 0;
       }
    }
  }

  vector<int> ans(n,0);
  rep(i,m) {
      ans.at(s.at(i)-1) = c.at(i);
  }


  if (ans.at(0) == 0 and n == 1) {
    cout << "0";
    return 0;
  }
  else if(ans.at(0) == 0) ans.at(0) = 1;
  rep(i,n) cout << ans.at(i);

  cout << endl;


  return 0;
}


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

int pos;
vector<int> in, pre, post;

void rec(int left, int right){ //不包括right
	if(left>=right) return;
	int m = pre[pos++];

	int position = distance(in.begin(),find(in.begin(), in.end(), m));
	
	rec(left, position);
	rec(position+1, right);
	post.push_back(m);
}

void sovle(){
	pos=0;
	rec(0, pre.size());
	for(int i=0; i<post.size(); i++){
		if(i) cout<<" ";
		cout<<post[i];
	}
}

int main(){
	int n;

	cin>>n;
	int tem1, tem2;
	for(int i=0; i<n; i++){
		cin>>tem1;
		pre.push_back(tem1);
	}
	for(int i=0; i<n; i++){
		cin>>tem2;
		in.push_back(tem2);
	}
	sovle();
	cout<<endl;
	return 0;
}


Measured memory_bytes: 3160
from itertools import accumulate
from sys import stdin
N, K = [int(_) for _ in stdin.readline().rstrip().split()]
P = [int(_) for _ in stdin.readline().rstrip().split()]
evs = [(1+p)/2 for p in P]
evs = [0] + list(accumulate(evs))
ans = 0
for i in range(K, N+1):
    ans = max(ans, evs[i]-evs[i-K])
print(ans)

Measured memory_bytes: 79540
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int A, B, N;
  cin >> A >> B >> N;
  if (B == 1)
    cout << 0;
  else{
    if (N < B){
      long long int C = A*N/B;
      cout << C <<endl;
    }
    if (N >= B){
      long long int C = A*(B-1)/B;
      cout << C <<endl;
    }
  }
}


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

int main() {
  string s;
  cin>>s;
  set<char> t;
  bool ans=true;
  rep(i,s.size()){
    char u=s[i];
    if(t.count(u)){
      ans=false;
    }
    t.insert(u);
  }
  if(ans){
    cout<<"yes"<<endl;
  }else{
    cout<<"no"<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int foo(int r)
{
  return (r*(r-1))/2;
}
int main()
{
    int n,m,ans=0;
    cin>>n>>m;
    if(n>=2)
    {
        ans = ans + foo(n);
    }
    if(m>=2)
    {
        ans = ans + foo(m);
    }
    cout<<ans<<endl;

}

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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if ( a - c <= d && c - a <= d) cout << "Yes";
	else if (a - b <= d && b - a <= d && b - c <= d && c - b <= d) cout << "Yes";
	else cout << "No";
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

N, *S = open(0).read().split()
dic = defaultdict(int)
for s in S:
    dic[s] += 1

print(f'AC x {dic["AC"]}')
print(f'WA x {dic["WA"]}')
print(f'TLE x {dic["TLE"]}')
print(f'RE x {dic["RE"]}')


Measured memory_bytes: 17092
fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map{it.toInt()}
    val A = readLine()!!.split(" ").map{it.toInt()}
    val num = arrayOf(
        0,
        2
        ,
        5
        ,
        5
        ,
        4
        ,
        5
        ,
        6
        ,
        3
        ,
        7
        ,
        6
    )

    val dp = arrayOfNulls<String>(N + 1)
    dp[0] = ""

    for (i in 1..N) {
        for (j in A) {
            if (num[j] > i) continue
            val m = i - num[j]
            if (dp[m] == null) continue
            if (dp[i] == null) {
                dp[i] = j.toString() + dp[m]
            } else {
                val t = j.toString() + dp[m]
                if (t.length != dp[i]!!.length) {
                    if (t.length > dp[i]!!.length) {
                        dp[i] = t
                    }
                } else {
                    if (t > dp[i]!!) {
                        dp[i] = t
                    }
                }
            }
        }
    }

    println(dp[N])

//    val H = ArrayList<Pair<Int, List<Int>>>()
//    for (s in 1 until (1 shl 9)) {
//        val l = (1..9).filter { (s shr (it - 1)) and s == 1 }
//
//        if (!A.containsAll(l)) {
//            continue
//        }
//
//        for (i in )
//    }
}


Measured memory_bytes: 165580
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Char
import Data.Ratio
import Data.Ord
import Data.Array.IO
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
-- end of templete

gen a = (a:a2:gen a3)
  where
    a2 = a * 2
    a3 = a2 / 3


main = map (sum . take 10 . gen . read) . lines <$> getContents >>= mapM_ print

Measured memory_bytes: 4336
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <vector>
namespace fastIO{
#define getchar() my_getchar()
#define putchar(x) my_putchar(x)
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;
	char buf[IN_BUF], *ps = buf, *pt = buf;
	inline char my_getchar() {
		return ps == pt && (pt = (ps = buf) + fread(buf, 1, IN_BUF, stdin), ps == pt) ? EOF : *ps++;
	}
	template<typename T> inline bool read(T &x){
		char op = 0, ch = getchar();
		for (x = 0; !isdigit(ch) && ch != EOF; ch = getchar()) if (ch == '-') op ^= 1;
		if (ch == EOF) return false;
		for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ '0');
		if (ch != '.') return op ? x = -x : 0, true; else ch = getchar();
		T t = 1;
		for (; isdigit(ch); ch = getchar()) t /= 10, x += (ch ^ '0') * t;
		return op ? x = -x : 0, true;
	}
	inline int reads(char *s){
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar()) ;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) s[n++] = ch;
		return s[n] = '\0', n;
	}
	char pbuf[OUT_BUF], *pp = pbuf;
	struct _flusher{ ~_flusher(){ fwrite(pbuf, 1, pp - pbuf, stdout); } } OutputFlusher;
	inline void my_putchar(char x){
		pp == pbuf + OUT_BUF ? fwrite(pbuf, 1, OUT_BUF, stdout), pp = pbuf : 0, *pp++ = x;
	}
	template<typename T> inline void print_(T x){
		if (x == 0) return putchar('0'), void(0);
		std::vector<int> num;
		for (x < 0 ? putchar('-'), x = -x : 0; x; x /= 10) num.push_back(x % 10);
		while (!num.empty()) putchar(num.back() ^ '0'), num.pop_back();
	}
	template<typename T> inline void print(T x, char ch = '\n'){
		print_(x), putchar(ch);
	}
	inline void prints_(const char *s, int n = -1){
		if (n == -1) n = strlen(s);
		for (register int i = 0; i < n; ++i) putchar(s[i]);
	}
	inline void prints(const char *s, int n = -1, char ch = '\n'){
		prints_(s, n), putchar(ch);
	}
	template<typename T> inline void printd_(T x, int n){
		if (x < 0) x = -x, putchar('-');
		long long a, b;
		for (register int i = 0; i < n; ++i) x *= 10;
		x = (long long)(x + 0.5);
		for (register int i = 0; i < n; ++i) x /= 10;
		a = x, x -= a;
		for (register int i = 0; i < n; ++i) x *= 10;
		b = x;
		print_(a);
		if (n) putchar('.'); else return;
		std::vector<int> num(n);
		for (register int i = 0; i < n; ++i) num[i] = b % 10, b /= 10;
		while (!num.empty()) putchar(num.back() ^ '0'), num.pop_back();
	}
	template<typename T> inline void printd(T x, int n, char ch = '\n'){
		printd_(x, n), putchar(ch);
	}
}
using namespace fastIO;
long long n, a, b;
void solve(){
	read(n), read(a), read(b);
	print(n / (a + b) * a + std::min(n % (a + b), a));
}
int main(){
#ifdef AT_HOME
	freopen("test.in", "r", stdin);
	freopen("test.out", "w", stdout);
#endif
	int T = 1;
	// read(T);
	while (T--) solve();
}

Measured memory_bytes: 2304
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int a, b, c; cin >> a >> b >> c;
	int k; cin >> k;
	int res = 0;
	res += min(a, k);
	k = max(k - a, 0);
	k = max(k - b, 0);
	res += -k;
	cout << res << endl;
}

Measured memory_bytes: 3636
/*
    Author Kushal Srivastava
    COllege: BIT Mesra
    */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n";
int func(int,int[]);int n;ll ans=0;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;
	cin >> n;
	int a[n],dp[n];
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
	}
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(int i=2;i<n;i++)
	{
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));

	}
	cout << dp[n-1] << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
    int N, K; cin >> N >> K;
    map<int, vector<int>> mp;
    for (int i = 0; i < N; ++i) {
        int t, d; cin >> t >> d;
        mp[t].push_back(d);
    }
    vector<int> maxes, others;
    for (auto& p : mp) {
        auto mt = p.second;
        sort(mt.rbegin(), mt.rend());
        maxes.push_back(mt[0]);
        for (int j = 1; j < mt.size(); ++j) others.push_back(mt[j]);
    }
    sort(maxes.rbegin(), maxes.rend());
    sort(others.rbegin(), others.rend());
    vector<int64> maxes_s(N + 1, 0), others_s(N + 1, 0);
    for (int i = 0; i < maxes.size(); ++i) maxes_s[i + 1] = maxes_s[i] + maxes[i];
    for (int i = 0; i < others.size(); ++i) others_s[i + 1] = others_s[i] + others[i];
    int kmax = min(K, (int)mp.size());
    int64 ans = 0;
    for (int64 k = 1; k <= kmax; ++k) {
        int64 result = maxes_s[k] + others_s[K - k] + (k * k);
        ans = max(ans, result);
    }
    cout << ans << endl;
    return;
}
int main() {
    solve();
    return 0;
}

Measured memory_bytes: 13304
MOD = 10**9+7
def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

def cmb(n,k,p):
    if n < k:
        return 0
    if n-k<k:
        k=n-k

    # 分母
    comb = 1
    for x in range(n-k+1, n+1):
        comb = (comb * x) % MOD

    # 逆行列
    d = 1
    for x in range(1, k+1):
        d = (d * x) % MOD
    comb *= pow(d, MOD-2, MOD)
    return comb % MOD

n,a,b=list(map(int,input().split()))

# 2**n-1
total = power_func(2,n,MOD)-1
print((total-cmb(n,a,MOD)-cmb(n,b,MOD))%MOD)



Measured memory_bytes: 38640
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    vector<int> dp(n, INF);
    dp[0] = 0;
    rep(i, n){
        for(int j = 1; j <= k; j++){
            if(i + j >= n){
                continue;
            }
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
        }
    }
    cout << dp[n-1] << endl;

    return 0;
}


Measured memory_bytes: 1792
a=input()
b=input()

memo = []

def swap(word,x,y):
	word=word.replace(x,'+')
	word=word.replace(y,'-')
	word=word.replace('+',y)
	word=word.replace('-',x)
	return word
	
for i in range(len(a)):
	if a[i] != b[i]:
		if a[i] in memo or b[i] in memo:
			print('No')
			break
		else:
			a=swap(a,a[i],b[i])
			memo.append(a[i])
			memo.append(b[i])
	
else:
	if a==b:
		print('Yes')
	else:
		print('No')
		

        

Measured memory_bytes: 3848
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    string s;
    cin >> s;
    if(s[0]==s[1] && s[1] == s[2]){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define MN 100000
using namespace std;
inline int read()
{
	int 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;
}
long long ans=0;
int n,m,head[MN+5],cnt=1,back[MN+5],flag=0,totv,tote,vis[MN+5],c[MN+5],num[3];
struct edge{int to,next;}e[MN*2+5];
inline void ins(int*head,int f,int t){e[++cnt]=(edge){t,head[f]};head[f]=cnt;}
void dfs(int x)
{
	++totv;++num[c[x]];vis[x]=1;
	for(int i=head[x];i;i=e[i].next)
		if(++tote,!vis[e[i].to]) c[e[i].to]=(c[x]+1)%3,dfs(e[i].to);
		else if(c[e[i].to]!=(c[x]+1)%3) flag=0;
	for(int i=back[x];i;i=e[i].next)
		if(!vis[e[i].to]) c[e[i].to]=(c[x]+2)%3,dfs(e[i].to);
		else if(c[e[i].to]!=(c[x]+2)%3) flag=0; 
}
int main()
{
	n=read();m=read();
	for(int i=1,j,k;i<=m;++i) j=read(),k=read(),ins(head,j,k),ins(back,k,j);
	for(int i=1;i<=n;++i) if(!vis[i]) 
	{
		totv=tote=0;flag=1;num[0]=num[1]=num[2]=0;
		dfs(i);
		if(flag&&num[0]&&num[1]&&num[2]) ans+=1LL*num[0]*num[1]+1LL*num[1]*num[2]+1LL*num[2]*num[0];
		else if(flag) ans+=tote;
		else ans+=totv+1LL*totv*(totv-1);
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 6528
#include<map>
#include<cstdio>
#include<vector>
#include<algorithm>

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

using namespace std;

typedef long long ll;

const int M=1000003;

vector<int> G[50000];

map<pair<int,int>,ll> dp[2][2];
ll dfs(int l,int r,bool bl,bool br){
	if(l+1==r) return bl&&br?1:0;

	if(dp[bl][br].count(make_pair(l,r))>0) return dp[bl][br][make_pair(l,r)];

	int u=*upper_bound(G[r].begin(),G[r].end(),l);

	ll res=0;
	res+=dfs(l,u,bl, true)*dfs(u,r,false,br); // 頂点 u を [u,r] 側のマッチングに使う
	res+=dfs(l,u,bl,false)*dfs(u,r, true,br); // 頂点 u を [l,u] 側のマッチングに使う
	if(!bl && binary_search(G[l].begin(),G[l].end(),u)){
		res+=dfs(l,u,true,true)*dfs(u,r,true,br); // 辺 l-u をマッチングに使う
	}
	if(!br && binary_search(G[r].begin(),G[r].end(),u)){
		res+=dfs(l,u,bl,true)*dfs(u,r,true,true); // 辺 u-r をマッチングに使う
	}
	return dp[bl][br][make_pair(l,r)]=res%M;
}

int main(){
	for(int n,m;scanf("%d%d",&n,&m),n;){
		rep(u,n) G[u].clear();
		rep(u,n){
			G[u].push_back((u+1)%n);
			G[u].push_back((u-1+n)%n);
		}
		rep(i,m){
			int u,v; scanf("%d%d",&u,&v); u--; v--;
			G[u].push_back(v);
			G[v].push_back(u);
		}
		rep(u,n) sort(G[u].begin(),G[u].end());

		rep(i,2) rep(j,2) dp[i][j].clear();
		printf("%lld\n",(dfs(0,n-1,false,false)+dfs(0,n-1,true,true))%M);
	}

	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define MOD 1000000007

int Please_accept_my_solution_;

/*
    Don't be like my girlfriend
    Accept me🙏🙏 ;) !
*/

int main()
{
  
    IOS
    int n,k;
    string s;
    cin>>n>>k;
    cin>>s;
    for(int i=0;i<s.length();i++)
    {
    	if(k==i+1) cout<<char(32+s[i]);
    	else cout<<s[i];
    }
    

    return 0;
}
        

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

    void Solve() {
        UL N, K; scanf("%d%d", &N, &K);
        vector<UL> A(N); rep(i, N) { scanf("%d", &A[i]); A[i]--; }
        vector<UL> C(K);
        UL Z = 0; UL q = 0;
        UL ans = -1;
        rep(p, N) {
            if (A[p] < K) {
                if (!C[A[p]]) Z++;
                C[A[p]]++;
            }
            while (Z == K) {
                if (A[q] >= K) { q++; continue; }
                if (C[A[q]] != 1) { C[A[q]]--; q++; }
                else break;
            }
            if (Z == K) ans = min(ans, p - q + 1);
        }
        if (ans == -1) printf("0\n");
        else printf("%d\n", ans);
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    //cout << fixed << setprecision(10);
    p->Solve();
    return 0;
}




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

typedef class dice {
private:

public:
    int mae;
    int ushiro;
    int migi;
    int hidari;
    int ue;
    int shita;

    dice(int qian, int hou, int zuo, int you, int shang, int xia): mae(qian), ushiro(hou), hidari(zuo), migi(you), ue(shang), shita(xia) {}

    void toEast() {
        int tmp = this->ue;
        this->ue = this->hidari;
        this->hidari = this->shita;
        this->shita = this->migi;
        this->migi = tmp;
    }

    void toWest() {
        int tmp = this->ue;
        this->ue = this->migi;
        this->migi = this->shita;
        this->shita = this->hidari;
        this->hidari = tmp;
    }

    void toNorth() {
        int tmp = this->ushiro;
        this->ushiro = this->ue;
        this->ue = this->mae;
        this->mae = this->shita;
        this->shita = tmp;
    }

    void toSouth() {
        int tmp = this->ushiro;
        this->ushiro = this->shita;
        this->shita = this->mae;
        this->mae = this->ue;
        this->ue = tmp;
    }
}* diceptr;

int main() {
//    freopen("in.txt", "r", stdin);

    int a,b,c,d,e,f;
    string action;

    cin >> a >> b >> c >> d >> e >> f;
    cin >> action;

    diceptr dice1 = new dice(b, e, d, c, a, f);
    for (int i = 0; i < action.length(); ++i) {
        char tmp = action[i];
        switch(tmp) {
            case 'E':
                dice1->toEast();
                break;
            case 'W':
                dice1->toWest();
                break;
            case 'N':
                dice1->toNorth();
                break;
            case 'S':
                dice1->toSouth();
                break;
            default:
                break;
        }
    }

    cout << dice1->ue << endl;
}

Measured memory_bytes: 3144
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n,u,v,m;
    cin>>n>>u>>v>>m;
    vector<int> ax(n),ay(n),bx(n),by(n);
    int as=0,al=0,ar=0,bl=0,br=0,bs=0;
    map<int,pair<int,int>> a,b;
    rep(i,n)rep(j,n){
        int x;cin>>x;
        a[x]={i,j};
    }
    rep(i,n)rep(j,n){
        int x;cin>>x;
        b[x]={i,j};
    }
    set<int> st;
    rep(i,m){
        int x;cin>>x;
        if(st.count(x))continue;
        st.insert(x);
        if(a.count(x)){
            auto p = a[x];
            if(++ax[p.first]==n)++as;
            if(n>=2){
            if(++ay[p.second]==n)++as;
            if(p.first==p.second&&++al==n)++as;
            if(p.first+p.second==n-1&&++ar==n)++as;
            }
        }
        if(b.count(x)){
            auto p = b[x];
            if(++bx[p.first]==n)++bs;
            if(n>=2){
            if(++by[p.second]==n)++bs;
            if(p.first==p.second&&++bl==n)++bs;
            if(p.first+p.second==n-1&&++br==n)++bs;
            }
        }
        if(as>=u&&bs>=v){
            cout<<"DRAW"<<endl;
            return 0;
        }
        if(as>=u){
            cout<<"USAGI"<<endl;
            return 0;
        }
        if(bs>=v){
            cout<<"NEKO"<<endl;
            return 0;
        }
    }
    cout<<"DRAW"<<endl;
    return 0;
}


Measured memory_bytes: 21740
#include<stdio.h>
#include<algorithm>
using namespace std;
int b[100000];
int c[100000];
long long dp[100000];
long long segtree[262144];
void set(int a,long long b){
	a+=131072;
	while(a){
		segtree[a]=max(segtree[a],b);
		a/=2;
	}
}
long long query(int a,int b,int c,int d,int e){
	if(b<c||d<a)return 0;
	if(c<=a&&b<=d)return segtree[e];
	return max(query(a,(a+b)/2,c,d,e*2),query((a+b)/2+1,b,c,d,e*2+1));
}
pair<int,int> dat[100000];
int m[100000];
int main(){
	int a;
	scanf("%d",&a);
	long long sum=0;
	for(int i=0;i<a;i++){
		scanf("%d",c+i);
		b[i]=i+1;
		sum+=b[i];
	}

	for(int i=0;i<a;i++)dat[i]=make_pair(c[i],i);
	std::sort(dat,dat+a);
	for(int i=0;i<a;i++){
		long long val=query(0,131071,0,dat[i].second,1);
		dp[dat[i].second]=val+b[i];
		set(dat[i].second,dp[dat[i].second]);
	}
	printf("%lld\n",(sum-query(0,131071,0,131071,1)));
}

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

int main() {
  int a, b, c, d, ans;
  cin >> a >> b >> c >> d;
  
  if (a < c) {
    if (c < b) {
      if (b < d) ans = b - c;
      else ans = d - c;
    } else ans = 0;
  } else {
    if (a < d) {
      if (d < b) ans = d - a;
      else ans = b - a;
    } else ans = 0;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3640
import math
a,b,x=map(int,input().split())
if a*a*b/2 == x:
    # 丁度半分
    h=b
    w=a
elif a*a*b/2 > x:
    # 半分未満
    h=b
    w=2*x/b/a
else:
    # 半分越え
    h=2*(b-x/a/a)
    w=a
print(math.degrees(math.atan(h/w)))

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

int main() {
    int n;
    std::string s, t;

    std::cin >> n >> s >> t;

    if (s == t) {
        std::cout << n << std::endl;
        return 0;
    }

    int itti = 0;
    for (int i = 1; i < s.length(); i++) {
        if (s.substr(s.length() - i, i) == t.substr(0, i)) {
            itti = i;
        }
    }

    if (itti >= n) {
        std::cout << itti << std::endl;
    } else {
        std::cout << n + (n - itti) << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	int n, x;
	char p;

	cin >> n;
	int lp = 0;
	bool flag = true;
	REP(i, n) {
		cin >> p >> x;
		if(p == '(') {
			lp += x;
		} else {
			lp -= x;
		}

		if(lp < 0) {
			flag = false;
		}
	}

	if(lp) {
		flag = false;
	}

	if(flag) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 1160
n,m=gets.split.map &:to_i
d,cash=[],0;n.times{d<< gets.split.map(&:to_i)}
d.sort_by!{|a,b|a}
n.times{|t|
  if (tmp=m-=d[t][1])<0
    cash+=(d[t][1]+tmp)*d[t][0]
    break
  else
    cash+=d[t].inject(:*)
  end
}
p cash

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

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

	int num[n];

	for(int i=0; i<n; i++){
		cin >> num[i];
	}

	for(int i=n-1; i>=1; i--){
		cout << num[i] << " " ;
	}
	
	cout << num[0];

	cout << endl;

	return 0;
}

Measured memory_bytes: 3072