akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define v vector<ll> 
#define vv vector<v>
#define p pair<ll,ll>
#define mid (start+end)/2
#define fi first
#define se second
ll MOD=1e9+7;	
vector<ll> prefix_function (string Z) 
{
    int n = (int) Z.length();
    vector<ll> F (n);
    F[0]=0;
    for (int i=1; i<n; ++i) 
   	{
        int j = F[i-1];
        while (j > 0 && Z[i] != Z[j])
            j = F[j-1];
        if (Z[i] == Z[j])  
        	++j;
        F[i] = j;
    }
    return F;
}
int LIM=5e5+10;
v previuos(LIM);

v ans(LIM,-1);
bool inf=0;
void dfs(int n,v &stk)
{
	//cout<<n<<endl;
	if (stk[n]==1)
	{
		inf=1;
		return ;
	}
	if (ans[n]!=-1)
		return ;
	stk[n]=1;
	int temp=0;
	if (previuos[n]==-1)
	{
		temp=0;
	}
	else
	{
		dfs(previuos[n],stk);
		temp=ans[previuos[n]]+1;
	}
	if (inf==1)
		return ;
	ans[n]=temp;
	stk[n]=0;
}
int main() {
	string s,t;
	cin>>s>>t;
	string s1=s;
	while (s.length()<t.length())
		s.append(s1);
	s.append(s1);
	s=t+"#"+s;

	v kmp=prefix_function(s);
	int n1=s1.length();
	int n=s.length();
	int m=t.length();
	int counter=n1-1;
	for (int i=n-1; i>n-1-n1; i--)
	{
		if (kmp[i]==m)
			previuos[counter]=((counter-m)%n1+n1)%n1;
		else
			previuos[counter]=-1;
		//cout<<counter<<" "<<previuos[counter]<<"a"<<" "<<kmp[i]<<endl;
		counter--;
	}
	//cout<<"a"<<endl;	
	ll fans=0;
	v stk(n1+1,0);
	for (int i=0; i<n1; i++)
	{
		dfs(i,stk);
		fans=max(fans,ans[i]);
	}
	if (inf)
		cout<<-1<<endl;
	else
		cout<<fans<<endl;
	return 0;
}

Measured memory_bytes: 48120
#include <bits/stdc++.h>
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
using pil = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
#define MOD 1000000007
#define MOD2 998244353

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k;
    cin >> n >> k;
    long long ans = 0;
    for (ll i = k; i < n+2; i++) {
        ll smallest = i * (i-1) / 2;
        ll largest = smallest + i * (n-i+1);
        ll add = largest - smallest + 1;
        ans += add;
        ans %= MOD; 
    }
    cout << ans << endl;
}


Measured memory_bytes: 3604
#include <iostream>
  #include <complex>
  #include <vector>
  #include <string>
  #include <algorithm>
  #include <cstdio>
  #include <numeric>
  #include <cstring>
  #include <ctime>
  #include <cstdlib>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <list>
  #include <cmath>
  #include <bitset>
  #include <cassert>
  #include <queue>
  #include <stack>
  #include <deque>
 #include <iomanip>
#include <fstream>
#include <climits>
 
  using namespace std;
   
 
//abcdefghijklmnopqrstuvwxyz
//ABCDEFGHIJKLMNOPQRSTUVWXYZ

  typedef long long ll;
  typedef long double lld;
  typedef unsigned long long ull;
  int INF = INT_MAX;
  ll mod = 1000000007;
  // lld PI = 3.141592653;
 

set<int> adj[200000+10];
vector<bool> visited(2e5+10);

int dfs(int v){
// cout<<v<<endl;
  visited[v] = true;
  int sz = 1;
  for (auto u: adj[v]){
    if (visited[u]) continue;
    sz+=dfs(u);
  }
  return sz;

}
void solve(){
  
int n,m;
cin>>n>>m;
for (int i = 0;i<m;i++){
  int a,b;
  cin>>a>>b;
  adj[a].insert(b);
  adj[b].insert(a);
}
int ans = 0;
for (int i = 1;i<=n;i++){
  if (visited[i]) continue;
  ans  = max(dfs(i),ans);
}
cout<<ans<<endl;

}

  int main()
  {
      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int q = 1;
    while(q--) solve();

}

Measured memory_bytes: 32868
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  VL as(N);
  FOR(a,as) {
    cin >> a;
  }
  int ans = 1;
  bool up = false;
  bool down = false;
  ll cur = as[0];
  REP(i,1,N) {
    ll a = as[i];
    if(!up && !down) {
      if(a == cur) continue;
      if(a > cur) {
        up = true;
      } else {
        down = true;
      }
      cur = a;
    } else if(up) {
      if(a < cur) {
        ans++;
        up = down = false;
      }
      cur = a;
    } else {
      if(a > cur) {
        ans++;
        up = down = false;
      }
      cur = a;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using Graph =vector<vector<int>>;
vector<bool> visit(100,false);
#define mp make_pair
vector<int> dis(100,-1);

void bfs(int s,Graph graph)
{
    int n=graph.size();
    queue<int> que;
    dis[s]=0;
    visit[0]=true;
    que.push(s);
    int v,u;
    while (!que.empty())
    {
        v=que.front();
        que.pop();
        for (int i=0;i<n;i++)
        {
            if (!visit[i] && graph[v][i])
            {
                visit[i]=true;
                dis[i]=dis[v]+1;
                que.push(i);
            }
        }
    }
}

int main()
{
    int n;cin >> n;
    Graph graph(n,vector<int> (n,0));
    int v,k,u;
    for (int i=0;i<n;i++)
    {
        cin >> v;
        cin >> k;
        for (int j=0;j<k;j++)
        {
            cin >>u;
            graph[v-1][u-1]=1;
        }
    }
    bfs(0,graph);
    for (int i=0;i<n;i++)
    {
        cout << i+1<<" "<<dis[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

vector<bool> so;
vector<ll> sosu;
void findso(){
	FOR(i,0,300001)so.push_back(true);
	FOR(i,2,300001){
		if(i%7!=1 && i%7!=6){
			so[i] = false;
			continue;
		}
		if(so[i]){
			ll j = i*2;
			while(j<300001){
				so[j] = false;
				j += i;
			}
		}
	}
	FOR(i,2,300001)if(so[i])sosu.push_back(i);
}



int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	findso();
	while(1){
		ll n;
		cin >> n;
		if(n==1)break;
		cout << n << ":";
		FOR(i,0,sosu.size()){
			if(sosu[i]>n)break;
			if(n%sosu[i]==0){
				cout << " " << sosu[i];
			}
		}
		cout << endl;
	}
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    int b = 0, r = 0;
    rep(i, 0, n){
        if(s[i] == 'B') b++;
        else r++;
    }
    if(r > b) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
PYI = []
for i in range(M):
    p, y = map(int, input().split())
    PYI.append([p, y, i])
PYI.sort(key=lambda x: (x[0], x[1]))


P = 0
c = 1
ans = []
for p, y, i in PYI:
    if p != P:
        c = 1
        P = p
    else:
        c += 1
    ans.append([i, '{:06d}{:06d}'.format(p, c)])

ans.sort(key=lambda x: x[0])
for i, a in ans:
    print(a)


Measured memory_bytes: 41480
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> a(n + 1, -inf);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        if (a[i] > i) {
            cout << -1 << endl;
            return 0;
        }

        if (i > 0 && a[i] - a[i - 1] > 1) {
            cout << -1 << endl;
            return 0;
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        int j = i;
        while (a[j + 1] >= a[j]) {
            while (a[j + 1] - a[j] == 1) {
                ++j;
            }
            int s = j;
            while (a[j + 1] - a[j] == 0) {
                ++j;
            }
            ans += (ll)a[j] * (ll)(j - s);
        }
        ans += (ll)a[j];
        i = j;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
 
ll pwr(ll base, ll p, ll mod=MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}


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


const int N = 100002;
int n, done[N][2];
vector<int> adj[N];


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

    int m;
    cin>>n>>m;
    while(m--){
    	int a, b;
    	cin>>a>>b;
    	adj[a].pb(b);
    	adj[b].pb(a);
    }

    queue<ii> qq;
    qq.push(ii(1, 0));
    done[1][0] = 1;
    while(!qq.empty()){

    	int v = qq.front().ff;
    	int parity = qq.front().ss;
    	qq.pop();

    	for(auto vv : adj[v])
    		if(!done[vv][1^parity]){
    			done[vv][1^parity] = 1;
    			qq.push(ii(vv, 1^parity));
    		}
    }

// cout<<"done: ";for(int i=1;i<=n;i++)	cout<<done[i][0]<<":"<<done[i][1]<<" ";cout<<endl;


    ll even = 0, odd = 0, ans = 0;
    for(int i=1;i<=n;i++){
    	if(done[i][0] && done[i][1]){
    		ans += i-1;
    		even++;	odd++;
    	}
    	else if(done[i][0]){
    		ans += odd;
    		even++;
    	}
    	else if(done[i][1]){
    		ans += even;
    		odd++;
    	}
// cout<<"after i = "<<i<<", "<<odd<<" "<<even<<" "<<ans<<endl;
    }

    for(int i=1;i<=n;i++)
    	for(auto it : adj[i])
    		if(it > i){
    			ans -= ((done[i][0]&&done[it][1]) || (done[i][1]&&done[it][0]));
// cout<<"eliminated "<<i<<" "<<it<<endl;
    		}

    cout<<ans;
    return 0;
}









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

long array[200000];

int main() {
  int N;
  cin >> N;
  for (int i = 1; i < N; i++){
    int l;
    cin >> l;
    array[l-1]++;
  }
  for (int i = 0; i < N; i++){
    cout << array[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 5184
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;

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

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}
const ll mod = 1e9 + 7;

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

const ll INF = 1e9;
/////////////////////////////////////////////////////////////////////////////////////////
int n,m;
string s,t;
int dp[2000][2000];
void solve(){
    for (int i = 0;i < n;i++){
        for (int j = 0;j < m;j++){
            if (s[i] == t[j]){
                dp[i+1][j+1] = dp[i][j] + 1;
            }
            else {
                dp[i+1][j+1] = max(dp[i][j + 1],dp[i+1][j]);
            }
        }
    }
     cout << dp[n][m] << endl;
}
int main(){
    int q;
    cin >> q;
    vector<string> x(q),y(q);
    vector<int> ans(q);
    

    for (int i = 0;i < q;i++){
        cin >> s >> t;
        n = s.size();
        m = t.size();
        solve();
    }

    return 0;
}


Measured memory_bytes: 10940
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
const int maxn = 1000100;
char s[maxn];
int n;
int f[2][maxn];
int solve(int c, int p){
	if(p == -1){
		if(c != 0) return 1<<30;
		return 0;
	}
	if(f[c][p] != -1) return f[c][p];
	int ans = 1<<30;
	for(int d = 0; d <= 9; d++){
		int v = s[p] - '0';
		int nc = 0;
		int now = d - v;
		if(c) now -= 1;
		if(now < 0) now += 10, nc = 1;
		ans = min(ans, now + d + solve(nc, p - 1));
	}
	// cout << c << ' ' << p << ' ' << ans << '\n';
	return f[c][p] = ans;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	scanf("%s", s + 1);
	s[0] = '0';
	n = strlen(s + 1) + 1;
	memset(f, -1, sizeof(f));
	cout << solve(0, n - 1) << '\n';
	return 0;
}


Measured memory_bytes: 71552
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

class BIT{
public:
	int n = 1;
	vector<int> bit;
	void init(int N){	//[1, N]のBIT作成
		while(n < N+1)n *= 2;
		bit.resize(n+1);
		fill(all(bit), 0);
	}
	void add(int i, int x){
		while(i <= n){bit[i] += x;i += i&-i;}
	}
	int get(int i){
		if(i == 0)return 0;
		int s = 0;
		while(i > 0){s += bit[i];i -= i&-i;}
		return s;
	}
	int lower_bound(int k, int ret = -1){	//ret=見つからなかったときに返すidx
		int lb = 0, ub = n+1;
		while(ub-lb > 1){
			if(get((lb+ub)/2) >= k)ub = (lb+ub)/2;
			else lb = (lb+ub)/2;
		}
		return ub == n+1 ? ret : ub;
	}
};

int a[400000], s[400000];
vector<int> vs;
map<int, int> zip;
signed main(){
	int n, k;
	scanf("%lld%lld", &n, &k);
	rrep(i,n)scanf("%lld", &a[i]);
	rrep(i,n)a[i] -= k;
	rrep(i,n)s[i] += s[i-1]+a[i];
	rrep(i,n)vs.pb(s[i]);
	vs.pb(0);
	ZIP(vs);
	rep(i,vs.size())zip[vs[i]] = i+1;
	
	BIT bit;
	bit.init(vs.size()+1);
	bit.add(zip[0], 1);
	int ans = 0;
	rrep(i,n){
		ans += bit.get(zip[s[i]]);
		bit.add(zip[s[i]], 1);
	}
	printf("%lld\n", ans);
	return 0;
}







Measured memory_bytes: 22000
using System;
class Program{
  static void Main(string[] args){
    int n = int.Parse(Console.ReadLine());
    string s = Console.ReadLine();
    int b = s.Replace("R","").Length;
    if(n-b>b){
      Console.WriteLine("Yes");
    }else{
      Console.WriteLine("No");
    }
  }
}

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

int main(){
    ll n,k,s;
    cin>>n>>k>>s;
    ll res = s+1;
    if(s == 1e9) res = 1;
    vector<int> a(n,s+1);
    for(int i=0; i<k; i++) cout<<s<<" ";
    for(int i=k; i<n; i++) cout<<res<<" ";
}

Measured memory_bytes: 1664
from bisect import bisect_left as bl
n = int(input())
tlst = sorted([int(input()) for _ in range(n)])
max_t = tlst[-1]
divisors = [i for i in range(1, max_t + 1) if max_t % i == 0]

ans = 0
for t in tlst:
  ind = bl(divisors, t)
  ans += divisors[ind] - t
print(ans)


Measured memory_bytes: 10652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace ConsoleApplication
{
    class Program
    {


        public static void Main(string[] args)
        {
            var parms = System.Console.ReadLine().Split();
            int bc = int.Parse(parms[1])*10+int.Parse(parms[2]);

            if(bc % 4 == 0)
            {
                System.Console.WriteLine("YES");
            }
            else
            {
                System.Console.WriteLine("NO");
            }

        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;

int d;
ll g;
VI p, c;
VLL dp;

ll f(int dd)
{
    ll point = 0ll;
    int cnt = 0;
    REP(i,d) {
        if ((dd & 1<<i) != 0) {
            point += p[i] * (i + 1) * 100 + c[i];
            cnt += p[i];
        }
    }

    RREP(i,d) {
        if (point >= g) {
            break;
        }

        if ((dd & 1<<i) == 0) {
            int tcnt = min((g - point + (i + 1) * 100 - 1) / ((i + 1) * 100), (ll)p[i]);
            point += tcnt * (i + 1) * 100;
            cnt += tcnt;
        }
    }

    return cnt;
}

int main()
{
    cin>>d>>g;
    p.resize(d); c.resize(d);
    int sum = 0;
    REP(i,d) {
        cin>>p[i]>>c[i];
        sum += p[i];
    }

    ll ans = INF * 100;
    REP(i,1<<d) {
        MIN(ans, f(i));
    }

    cout<<ans<<endl;

    return 0;
}


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

int main() {
    string s;
    cin >> s;
    int k;
    cin >> k;
    int n = s.size();
    set<string> dic;
    for (int i = 1; i <= k; i++) {
        rep(j, n-i+1) {
            // char c[i];
            string c;
            rep(l, i) {
                // c[l] = s[j+l];
                c.push_back(s[j+l]);
            }
            dic.insert(c);
        }
    }
    int i = 0;
    for (string p : dic) {
        i++;
        if (i == k) {
            cout << p << endl;
        }
    }
}

Measured memory_bytes: 4780
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
vector<int> dx = {-1, -1, -1, 0, 0, 1, 1, 1};
vector<int> dy = {-1, 0, 1, -1, 1, -1, 0, 1};

int main () {
    int ans;
    rep(i, 5) {
        int x; cin >> x;
        if (x != i+1) ans = i+1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3572
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    S = []
    twos = 1
    sign = 1
    while N != 0:
        if N%(2*twos) != 0:
            S.append('1')
            if sign < 0:
                N += twos
            else:
                N -= twos
        else:
            S.append('0')
        sign = -sign
        twos *= 2
    if len(S) == 0:
        S = ['0']
    S.reverse()
    print(''.join(S))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 62036
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Math;

namespace ConsoleApp15
{
    class Class220
    {
        static List<long> list = new List<long>();
        static void Main()
        {
            int K = int.Parse(Console.ReadLine());
            for(int j = 1; j <= 10; j++)
            {
                if (list.Count < K)
                {
                    for (int i = 1; i <= 9; i++)
                    {
                        DFS(j, 1, i);
                    }
                }
                else break;
            }
            
            list.Sort();
            Console.WriteLine(list[K-1]);

        }
        static void DFS(int n,int k,long num)
        {
            if (k < n)
            {
                string s = num.ToString();
                for (int i = 0; i <= 9; i++)
                {
                    if(Abs(long.Parse( s[k-1].ToString())-i)<=1)
                    {
                        DFS(n, k + 1, long.Parse(s + i.ToString()));
                    }
                }
            }
            else
            {
                list.Add(num);
            }
            
        }
        
    }
    public class PriorityQueue<T>
    {
        public long Size { get; private set; } = 0;
        public long MaxSize { get; private set; } = 0;
        private T[] m_heap;
        private Comparison<T> Comp = null;

        public PriorityQueue(long maxSize, Comparison<T> comp)
        {
            if (maxSize <= 0)
                throw new Exception();
            MaxSize = maxSize;
            m_heap = new T[maxSize];

            Comp = comp;
        }

        public void Push(T x)
        {
            if (Size == MaxSize)
            {
                T[] new_heap = new T[MaxSize << 1];
                Array.Copy(m_heap, new_heap, MaxSize);
                m_heap = new_heap;
                MaxSize <<= 1;
            }

            long i = Size++;
            while (i > 0)
            {
                long p = (i - 1) / 2;
                if (Comp(m_heap[p], x) <= 0)
                    break;
                m_heap[i] = m_heap[p];
                i = p;
            }
            m_heap[i] = x;
        }

        public T Pop()
        {
            if (Size == 0)
                throw new Exception("Queue is empty.");

            T result = m_heap[0];
            T x = m_heap[--Size];
            long i = 0;
            while (i * 2 + 1 < Size)
            {
                long c1 = i * 2 + 1, c2 = i * 2 + 2;
                if (c2 < Size && Comp(m_heap[c2], m_heap[c1]) < 0)
                    c1 = c2;
                if (Comp(m_heap[c1], x) >= 0)
                    break;
                m_heap[i] = m_heap[c1];
                i = c1;
            }
            m_heap[i] = x;

            return result;
        }
    }
}


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

class Cake
{
public:
	int w,h,sz;
	Cake(){}
	Cake(int w, int h)
		:w(w),h(h)
	{
		sz=w*h;
	}

	bool operator<(const Cake& c) const
	{
		return sz<c.sz;
	}
};

int main()
{
	int N,W,H;
	while(cin >> N >> W >> H, (N||W||H))
	{
		vector<Cake> cakes;
		cakes.push_back(Cake(W,H));
		while(N--)
		{
			int id,p;
			cin >> id >> p;
			id--;

			int w=cakes[id].w, h=cakes[id].h;
			cakes.erase(cakes.begin()+id);

			p%=(w+h);

			Cake n1,n2;
			if(p<w) 
			{
				n1=Cake(p,h);
				n2=Cake(w-p, h);


			}
			else 
			{
				p-=w;
				n1=Cake(w, p);
			    n2=Cake(w, h-p);
			}

			if(n2<n1) swap(n1,n2);
			cakes.push_back(n1);
			cakes.push_back(n2);

		}

		sort(cakes.begin(), cakes.end());

		for(int i=0; i<cakes.size(); i++)
		{
			if(i!=0) cout << " ";
			cout << cakes[i].sz;
		}

		cout << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int NIL = -1;
const int MAX = 10000;
const int MOD = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    string s;
    cin >> s;
    if (s.size() < 4) cout << "No" << '\n';
    else cout << (s.substr(0, 4) == "YAKI" ? "Yes" : "No") << '\n';
}


Measured memory_bytes: 3624
#include <stdio.h>

int main() {
  char s[10];
  scanf("%s", s);
  int i = 0, max = 0, count = 0;
  while (s[i] != '\0') {
    if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
      count++;
    } else {
      count = 0;
    }
    if (max < count) {
      max = count;
    }
    i++;
  }
  printf("%d\n", max);
  return 0;
}


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

int main(){

  int N;
  cin >> N;

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


  int cnt;
  int max_cnt = 0;
  for (int  len = 1; len < S.size(); len++){
    vector<char> v1(len), v2(N-len);
    copy(S.begin(), S.begin()+len, v1.begin());
    copy(S.begin()+len, S.end(), v2.begin());
    

    // unique v1
    sort(v1.begin(), v1.end());
    decltype(v1)::iterator result = std::unique(v1.begin(), v1.end());
    v1.erase(result, v1.end());

    // count for each v1, included in v2?
    cnt = 0;
    for (int i = 0; i < v1.size(); i++){
      for (int j = 0; j < v2.size(); j++){
        if (v1[i] == v2[j]){
          cnt++;
          break;
        }
      }
      max_cnt = max(max_cnt, cnt);
   }
  }

  cout << max_cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> B(N - 1);
    vector<int> A(N);
    rep(i, N - 1)
    {
        cin >> B[i];
    }
    A[0]=B[0];
    A[N-1]=B[N-2];
    reps(i,N-1,1){
        A[i]=min(B[i],B[i-1]);
    }
    cout << accumulate(A.begin(), A.end(), 0) << endl;
   // system("pause");
    return 0;
}

Measured memory_bytes: 256
def f_frog_jump(N, S):
    ans = 0
    for c in range(1, N):
        # k=0のとき、スタートからゴールへ飛ぶしかない(得点0)ので、k=1から始める
        current_ans, k = 0, 1
        while k * c < N - 1:
            a = N - 1 - k * c
            b = a - c
            # k, cを決めたとき、進む距離<=戻る距離になる(負の座標に到達する)か、
            # 同じ座標に複数回到達する場合、得点を計算する意味がない
            if not (a <= b or b <= 0 or (a % c == 0 and a <= k * c)):
                current_ans += S[N - 1 - k * c] + S[k * c]
                ans = max(ans, current_ans)
            k += 1
    return ans
    # 参考: http://sigma1113.hatenablog.com/entry/2019/05/27/181729

N = int(input())
S = [int(i) for i in input().split()]
print(f_frog_jump(N, S))

Measured memory_bytes: 14592
N = int(input())
L = input().split()
L = [int(x) for x in L]

L=sorted(L)

if(N%2==0):
	low_K = N//2-1
	if(L[low_K]!=L[low_K+1]):
		print(L[low_K+1]-L[low_K])
	else:
		print(0)
else:
	print(0)

Measured memory_bytes: 14396
#include <iostream>

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

int main() {
  int n, m;
  std::cin >> n >> m;

  int a[m];
  rep(i, m) a[i] = 0;

  rep(i, n) {
    int k;
    std::cin >> k;
    rep(j, k) {
      int id;
      std::cin >> id;
      id--;
      a[id]++;
    }
  }

  int cnt = 0;
  rep(i, m) {
    if (a[i] == n) cnt++;
  }
  std::cout << cnt << '\n';

  return 0;
}


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

int main() {
  int ans=0;
  string s,t;
  cin >> s >> t;
  for(int i=0;i<s.size();i++){
    if(s.at(i) != t.at(i))
      ans ++;
  }
  cout << ans;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
// ohne Speedup
#define l_ength size
const int inf = (1<<30);
const int mod = 2019;
using ll = long long;
using namespace std;

ll dp[2][2019];

int main(){
	string s; cin >> s;
	dp[0][s[0]-'0'] = 1;
	ll ans = 0;
	for( int i = 1; i < s.size(); ++i ){
		int d = s[i]-'0';
		int k = i%2;
		for( int r = 0; r < mod; ++r ) dp[k][r] = 0;
		for( int r = 0; r < mod; ++r ){
			dp[k][((r*10)+d)%mod] += dp[(k+1)%2][r];
		}
		dp[k][d] += 1;
		ans += dp[k][0];
	}
	cout << ans << endl;
}


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

#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define int long long
#define endl '\n'

using namespace std;

const int N = 2e6 + 77 ;
int cnt[N] , g;

int32_t main(){
    fast;
    int n ; cin >> n ;
    bool pp = true;
    for(int i = 0 ; i < n ; ++i){
        int a ; cin >> a ;
        g = __gcd(g,a);
        cnt[a]++;
    }

    for(int i = 2 ; i < N ; ++i){
        int sum = 0;
        for(int j = i ; j < N ; j += i) sum += cnt[j];
        if(sum > 1) {pp = false;break;}
    }

    if(pp) cout << "pairwise coprime" << endl;
    else if(g==1) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;
    return 0;
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a[ohara],b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos,par[ohara],ran[ohara],mi[ohara],other[ohara],used[ohara],group=0;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

void init(int nn) {
	for (int i=0; i<nn; i++) {
		par[i] = i;
		ran[i] = 0;
    mi[i]=INF;
	}
}//初期化

ll root(ll xx){
    if(par[xx]==xx){
        return xx;
    }
    else{
        return par[xx]=root(par[xx]);
    }
}
//木の根を求めている。
 
bool same(ll xx,ll yy){
    return root(xx)==root(yy);
}
//同じ集合？？
 
void unite(ll xx,ll yy){
    xx=root(xx);
    yy=root(yy);
    if(xx==yy)return;
    
    if(ran[xx]<ran[yy]){
        par[xx]=yy;
    }
    else{
        par[yy]=xx;
        if(ran[xx]==ran[yy])ran[xx]++;
    }
}

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

      
      cin>>n>>m;
      init(n+1);
      map<ll,ll> mp;
      map<ll,ll> mpp;
      map<ll,ll> help;
      rep(i,n)cin>>a[i];
      rep(i,m){
        cin>>b>>c;
        b++;c++;
        unite(b,c);
      }
      rrep(i,1,n+1){
        mi[root(i)]=min(a[i-1],mi[root(i)]);
        help[root(i)]++;
      }
      rrep(i,1,n+1){
        if(help[root(i)]!=0){
          group++;
          help[root(i)]=0;
        }
        if(mp[root(i)]==0){
          used[root(i)]=mi[root(i)];
          ans+=mi[root(i)];
          mp[root(i)]++;
        }
      }
      rrep(i,1,n+1){
        if(a[i-1]==used[root(i)]){
          if(mpp[root(i)]==0)mpp[root(i)]++;
          else other[cnt++]=a[i-1];
        }
        else{
          other[cnt++]=a[i-1];
        }
      }
      if(cnt<group-2)Cout("Impossible");
      else{
        if(group==1){
          Cout(0);
        }
        else{
        sort(other,other+cnt);
        rep(i,group-2){
          ans+=other[i];
        }
        Cout(ans);
        }
      }
      
     

       
return 0;
}


Measured memory_bytes: 32128
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=0;i<b;i++)
#define REP(i,a,b) for(int i=0;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout <<(f?"Yes":"No")<<endl//fが真の場合Yesを出力、偽の場合Noを出力
#define yes(f) cout <<(f?"yes":"no")<<endl
#define YES(f) cout <<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())

using namespace std;

const int mod=1e9+7;

signed main(){
    int a;
    int b;
    cin >> a >> b;
    if(a+b<=16&&a<=8&&b<=8) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int N,ans[10][10],cs=0;

int main(){
	while(cin>>N){
		if(N==0)return 0;
		int x=0,y=0,n=1,m=1,sw=0;
		cs++;
		while(m>0){
			for(int i=0;i<m;i++)ans[y--][x++]=n++;
			if(m==N)sw=1;
			if(sw==0){m++;y++;}
			else {m--;x--;y+=2;}
			for(int i=0;i<m;i++)ans[y++][x--]=n++;
			if(m==N)sw=1;
			if(sw==0){m++;x++;}
			else {m--;x+=2;y--;}
		}
		cout<<"Case "<<cs<<":"<<endl;
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				if(ans[i][j]<10)cout<<" ";
				if(ans[i][j]<100)cout<<" ";
				cout<<ans[i][j];
			}
			cout<<endl;
		}
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
#define INF 2000000000
#define REP(i,b,n) for(int i = (b); i < n; i++)
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int gcd(int a, int b){return b ? gcd(b, a % b): a;}
void yes(){cout<<"Yes"<<endl;return;}
void no(){cout<<"No"<<endl;return;}

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(c, b/a) << endl;
    return 0;
}


Measured memory_bytes: 384
#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<<"Right"<<endl;
  }
  else{
    cout<<"Balanced"<<endl;
  }
}

Measured memory_bytes: 256
// JavaProgram.cpp
// Author : Priydarshi Singh (@dryairship)
// One cat just leads to another. One bug leads to two others.

#include <bits/stdc++.h>
using namespace std;

// I like my types defined.
typedef long long           ll;
typedef pair<int, int>      pii;
typedef vector<int>         vi;
typedef vector<pii>         vii;
typedef set<int>            si;
typedef map<string, int>    msi;
typedef map<int, int>       mii;

// Traditional science is all about finding "hashtag define"s.
#define fr(i, n)            for(ll i=0; i<(n); ++i)
#define frC(i, n, c)        for(int i=0; (i<(n)) && (c); ++i)
#define frA(i, a, n)        for(int i=a; i<=(n); ++i)
#define frD(i, a, n)        for(int i=a; i>=(n); --i)
#define fill(a)             memset(a, 0, sizeof(a))
#define fill1(a)            memset(a, -1, sizeof(a))
#define revsort(a, b)       sort(a, b, greater<int>())
#define ff                  first
#define ss                  second
#define pb                  push_back 
#define dout                if(DEBUGGING) cout
#define dbg                 if(DEBUGGING) 
#define endl                "\n"

// When you realize MOD > INF...
int DEBUGGING    =          0;
const int INF    =          1000000000;
const int MOD    =          1000000007;
const ll LINF    =          1e18;
const double PI  =          3.1415926535897932;
const double EPS =          1e-7;

// I'D SPAM. Hehe.
ll gcdEx                    (ll a, ll b, ll *x, ll *y){if(!a){*x=0;*y=1;return b;} 
ll x1,y1,gcd=gcdEx          (b%a,a,&x1,&y1); *x=y1-(b/a)*x1;*y=x1; return gcd;}
ll modI(ll b, ll m)         {ll x,y;gcdEx(b,m,&x,&y);return (x%m+m)%m;}
ll modD(ll a, ll b)         {return (modI(b,MOD)*(a%MOD))%MOD;}
ll modS(ll a, ll b)         {return ((a%MOD)-(b%MOD)+MOD)%MOD;}
ll modP(ll x, ll y)         {ll r=1; x%=MOD; while(y>0){if(y&1){r=(r*x)%MOD;} y=y>>1; x=(x*x)%MOD;} return r;}
ll modA(ll a, ll b)         {return ((a%MOD)+(b%MOD))%MOD;}
ll modM(ll a, ll b)         {return ((a%MOD)*(b%MOD))%MOD;}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve(int TEST_CASE){
    ll x;
    cin >> x;
    ll a,b;
    frA(i,-1000,1000){
        frA(j,-1000,1000){
            if(pow(i,(ll)5)-pow(j,(ll)5)==x){
                a=i;
                b=j;
                break;
            }
        }
    }
    cout << a << " " << b;
}

int main(int argc, char* argv[]){
    if(argc==2 && argv[1][1]=='v') DEBUGGING = 1;
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin.exceptions(cin.failbit);
    int nTestCases=1;
    //cin >> nTestCases;
    frA(i,1,nTestCases) solve(i);
    return 0;
}

Measured memory_bytes: 4032
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    P = list(map(int, input().split()))
    C = list(map(int, input().split()))

    res = -f_inf
    for now in range(n):
        cnt = 0
        score = [0]
        visited = set()
        for j in range(k):
            next_now = P[now] - 1
            if next_now not in visited:
                score.append(score[-1] + C[next_now])
                visited.add(next_now)
                now = next_now
                cnt += 1
            else:
                break
        score.pop(0)
        if k - cnt == 0:
            res = max(res, max(score))
        else:
            if score[-1] <= 0:
                res = max(res, max(score))
            else:
                q, r = divmod(k, cnt)
                if r == 0:
                    res = max(res, max(score) + score[-1] * (q - 1))
                else:
                    res = max(res, max(score[:r]) + score[-1] * q, max(score[r:]) + score[-1] * (q - 1))
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 168880
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

//const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod

signed main(){

    int N, MOD; cin >> N >> MOD;

    vec dp(N, 0);
    dp[0] = 1;
    REP(i, N - 1){
        int c = min(i + 1, N - i);
        FOR(j, c, N) (dp[j] += dp[j - c]) %= MOD;
    }

    int ans = 0;
    REP(i, N){
        (ans += dp[i] * (N - i)) %= MOD;
    }
    Out(ans);

    return 0;
}


Measured memory_bytes: 256
h,w,k=map(int,input().split())
pattern=[]
n_pattern=[]
pattern.append(1)
n_pattern.append(0)
for i in range(w-1):
    pattern.append(0)
    n_pattern.append(0)
def f(x):
    if x==0:
        return 1
    elif x==1:
        return 1
    elif x==2:
        return 2
    elif x==3:
        return 3
    elif x==4:
        return 5
    elif x==5:
        return 8
    elif x==6:
        return 13
    elif x==7:
        return 21
for i in range(h):
    for j in range(w):
        a=f(w-1-j)*f(j)*pattern[j]
        if j>=1:
            b=f(w-1-j)*f(j-1)*pattern[j-1]
        else:
            b=0
        if j<=w-2:
            c=f(w-2-j)*f(j)*pattern[j+1]
        else:
            c=0
        n_pattern[j]=a+b+c
    for j in range(w):
        pattern[j]=n_pattern[j]
print(pattern[k-1]%(10**9+7))



Measured memory_bytes: 38896
N=int(input())
S=[int(input()) for _ in range(N)]

if sum(S)%10:
  print(sum(S))
else:
  T=[]
  for s in S:
    if s%10:
      T.append(s)
  T.sort()
  
  if len(T)==0:
    print(0)
  else:
    print(sum(S)-T[0])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO                     \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);
typedef long long ll;
/**
 * Uncomment the #define below if problem contains multiple test cases
 */
// #define MULTIPLE_TESTS 1
template <typename T>
inline void readGrid(vector<vector<T>>& grid, int R, int C) {
  grid.assign(R, vector<T>(C));
  for (int i = 0; i < R; ++i) {
    for (int j = 0; j < C; ++j) {
      cin >> grid[i][j];
    }
  }
}

const int N = 6;
vector<int> row(N, 0), col(N, 0);
int tot = 0;
vector<vector<char>> grid;
int h, w, k;
ll ans = 0;
void check(vector<int> rows, vector<int> cols) {
  vector<vector<int>> done(h, vector<int>(w, 0));
  int curr = 0;
  for (int i = 0; i < rows.size(); ++i) {
    int cur = rows[i];
    for (int j = 0; j < w; ++j) {
      if (grid[cur][j] == '#' && !done[cur][j]) {
        ++curr;
        done[cur][j] = 1;
      }
    }
  }
  for (int i = 0; i < cols.size(); ++i) {
    int cur = cols[i];
    for (int j = 0; j < h; ++j) {
      if (grid[j][cur] == '#' && !done[j][cur]) {
        ++curr;
        done[j][cur] = 1;
      }
    }
  }
  if (tot - curr == k) {
    ++ans;
  }
}

void countAllNextCol(int cur, vector<int> rows, vector<int> cols) {
  if (cur == w) {
    check(rows, cols);
    return;
  }
  countAllNextCol(cur + 1, rows, cols);
  cols.push_back(cur);
  countAllNextCol(cur + 1, rows, cols);
}
void countAllFirstRow(int cur, vector<int> rows) {
  if (cur == h) {
    vector<int> tmp;
    countAllNextCol(0, rows, tmp);
    return;
  }
  countAllFirstRow(cur + 1, rows);
  rows.push_back(cur);
  countAllFirstRow(cur + 1, rows);
}
void solve() {
  cin >> h >> w >> k;

  readGrid(grid, h, w);

  for (int r = 0; r < h; ++r) {
    for (int c = 0; c < w; ++c) {
      if (grid[r][c] == '#') {
        ++row[r];
        ++col[c];
        ++tot;
      }
    }
  }

  vector<int> tmp;
  countAllFirstRow(0, tmp);

  cout << ans << endl;
}

int main() {
  FAST_IO;
  int t = 1;
#ifdef MULTIPLE_TESTS
  cin >> t;
#endif

  while (t--) {
    solve();
  }

  return 0;
}

Measured memory_bytes: 3652
//https://atcoder.jp/contests/abc121/tasks/abc121_d
#include <iostream>
#include <algorithm>
#include <string>
#include <utility>
using namespace std;

long judge(long n){
  if(n%2==0){
    if(n%4==0){
      return n;
    }
    else{
      return n^1;
    }
  }
  else{
    if((n+1)%4==0){
      return 0;
    }
    else{
      return 1;
    }
  }
}

int main(int argc, char const *argv[]) {
  long A,B;
  cin >> A >> B;

  long a = judge(A-1)^judge(B);
  cout << a << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >>n;
    string s;
    for(int i=0;i<n;i++){

        cin >>s;
        if(s=="Y"){
            cout <<"Four"<<endl;
            return 0;
        }
    }
    cout <<"Three"<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
*A, = map(int, input().split())
minv = min(A)
maxv = max(A)
mini = A.index(minv)
maxi = A.index(maxv)

ans = []


def op(x, y):
    A[y] += A[x]
    ans.append([x, y])


if minv < 0 and maxv > 0:
    if abs(minv) <= maxv:
        for i in range(N):
            if A[i] < 0:
                op(maxi, i)
    else:
        for i in range(N):
            if A[i] > 0:
                op(mini, i)

minv = min(A)
maxv = max(A)
mini = A.index(minv)
maxi = A.index(maxv)

if maxv <= 0:
    op(mini, N-1)
    for i in range(N-2, -1, -1):
        op(i+1, i)
else:
    op(maxi, 0)
    for i in range(1, N):
        op(i-1, i)

print(len(ans))
for x, y in ans:
    print(x+1, y+1)


Measured memory_bytes: 62480
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <limits.h>
#include <map>
#include <numeric>

namespace test {
	std::string to_string (char val) {
		return std::string (1, val);
		// return std::string{val};
	}
	//if( str.find ("r") != string::npos)
}

using namespace std;
typedef long long int llint;

int main (void) {
	string n; cin >> n;
	cout << ( n[0] == n[2] ? "Yes" : "No" ) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>

#define MAX_N 100000
#define MAX_K 100000
#define MAX_W 10000

using namespace std;

int w[MAX_N];

int check(int n, int k, int p)
{
    int i = 0;;
    for (int j = 0; j < k; j++) {
        int sum = 0;
        while (sum + w[i] < p) {
            sum += w[i];
            i++;
            if (i >= n) return n;
        }
    }
    return i;
}

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

    long long left = 0;
    long long right = n * MAX_W;
    long long mid;
    while (left < right) {
        mid = (left + right) / 2;
        int v = check(n, k, mid);
        if (v >= n) right = mid;
        else left = mid + 1;
    }
    printf("%d\n", right - 1);

    return 0;
}

Measured memory_bytes: 3120