akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;


int main() {
	int n;cin>>n;
  	vector<int> dp(n+1);
  	dp[0]=0;
  	for(int i=1;i<=n;i++){
    	dp[i]=dp[i-1]+1;
      
      	int six=6;
      	while(i>=six){
        	dp[i]=min(dp[i],dp[i-six]+1);
          	six *=6;
        }
      
      	int nine=9;
      	while(i>=nine){
        	dp[i]=min(dp[i],dp[i-nine]+1);
          	nine *=9;
        }
    }
  	cout<<dp[n]<<endl;
}



Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

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

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int main(){
    int n,m;cin>>n>>m;
    vector<vector<P>>p(n+1);
    rep(i,m){
        int a,b;cin>>a>>b;
        p[a].emplace_back(b,i);
    }
    REP(i,1,n)sort(ALL(p[i]));
    vector<vector<P>>s(m);
    REP(i,1,n){
        if(p[i].empty())continue;
        int cnt = 1;
        for(auto x : p[i]){
            s[x.second].emplace_back(i,cnt);
            cnt++;
        }
    }
    rep(i,m){
        int fst,snd;
        for(auto x:s[i]){
        fst = x.first;
        snd = x.second;
        }
        printf("%06d%06d\n",fst,snd);
    }
}



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

int main(){
	int n;
	scanf("%d", &n);
	int ave = (int)(n / 1.08);
	for(int i = ave - 1; i <= ave + 1; i++) {
		if((int)(i * 1.08) == n) {
			printf("%d\n", i);
			return 0;
		}
	}
	printf(":(\n");
}


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;

struct Edge {
    int id, from, to;
};

void bfs(vector<vector<int>> &edges_each_from, map<int, map<int, int>> &colors) {
    queue<int> q;
    q.push(0);

    while (!q.empty()) {
        int from = q.front();
        q.pop();
        int color = 0;
        int ng = -1;

        for (int to : edges_each_from[from]) {
            if (colors.find(from) != colors.end() && colors[from].find(to) != colors[from].end()) {
                ng = colors[from][to];
            }
        }

        for (int to : edges_each_from[from]) {
            if (colors.find(from) != colors.end() && colors[from].find(to) != colors[from].end()) {
                continue;
            } else {
                if (color == ng)color++;
                colors[from][to] = color;
                colors[to][from] = color;
                color++;
                q.push(to);
            }
        }
    }

}

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

    vector<Edge> edges(n - 1);

    map<int, map<int, int>> edge_ids;
    map<int, map<int, int>> colors;

    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edge_ids[a][b] = i;
        edge_ids[b][a] = i;

        edges[i].id = i;
        edges[i].from = a;
        edges[i].to = b;

    }

    vector<vector<int>> edges_each_from(n);

    for (Edge &edge : edges) {
        edges_each_from[edge.from].push_back(edge.to);
        edges_each_from[edge.to].push_back(edge.from);
    }

    bfs(edges_each_from, colors);

    vector<int> ans(n - 1);
    for (int i = 0; i < n - 1; i++) {
        Edge edge = edges[i];
        ans[i] = colors[edge.from][edge.to] + 1;
    }

    int m = *max_element(ans.begin(), ans.end());
    cout << m << endl;
    for (int i : ans) {
        cout << i << endl;
    }

}

Measured memory_bytes: 45056
#include<cstdio>

typedef long long int lli;
using namespace std;

lli N, M;
lli ans = 0;
//bool f1 = true;
//bool f[100000000000][1000000000000] = {};
//lli fn[100000000000][1000000000000] = {};

//lli dp(lli s, lli c);

int main(){

  scanf("%lld %lld",&N, &M);

  if(N*2 <= M){
    ans += N;
    M -= N*2;
    N = 0;
    ans += M / 4;
  }else{
    ans = M / 2;
  }

  printf("%lld", ans);

  return 0;

}


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

int main(){
    int N;
    int nums[100000];

    cin >> N;
    rep(i, N) cin >> nums[i];

    sort(nums, nums+N);

    int mid = nums[N/2] - nums[N/2 - 1];

    cout << mid << endl;
}


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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF 1e9

int main(int argc, char const *argv[])
{
    ll s;
    cin >> s;
    vector<ll> t(1000001, 0);
    REP(i, 1000001)
    {
        if (t[s] == 1)
        {
            cout << i + 1 << endl;
            break;
        }
        t[s] = 1;
        if (s % 2 == 0)
        {
            s /= 2;
        }
        else
        {
            s = 3 * s + 1;
        }
    }
    return 0;
}


Measured memory_bytes: 8064
//2017-11-7
//miaomiao
//
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
 
using namespace std;
 
#define LL long long
#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
 
#define N (100000+5)
 
bool Check(int a, int b, int c){
	if(a > c) swap(a, c);
	if(b != a+1 || c != a+2) return false;
	if(a % 3 != 1) return false;
	return true;
}
 
int a[N][5], num[N];
bool op[N], rev[2], swp[2];
 
int main(){
	int n;
 
	scanf("%d", &n);
	For(j, 1, 3) For(i, 1, n) scanf("%d", &a[i][j]);
	
	For(i, 1, n) if(!Check(a[i][1], a[i][2], a[i][3])){
		puts("No"); return 0;
	}
 
	For(i, 1, n){
		num[i] = max(a[i][1], a[i][3]) / 3;
		op[i] = a[i][1] > a[i][3];
		if((num[i]&1) ^ (i&1)){
			puts("No"); return 0;
		}
	}
 
//	For(i, 1, n) printf("%d%c ", num[i], op[i]? '-': '+');
//	puts("");
 
	For(i, 1, n) rev[i&1] ^= op[i];

	int t;
	For(i, 1, n)
		while(i != num[i]){
			t = num[i];
			swap(num[i], num[t]);
			swp[i&1] ^= 1;
		}
 
	if((swp[0] ^ rev[1]) || (swp[1] ^ rev[0])) puts("No");
	else puts("Yes");
 
	return 0;
}


Measured memory_bytes: 2688
import sys
from collections import deque

N, Q = map(int, sys.stdin.readline().split(" "))

edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, sys.stdin.readline().split(" "))
    # print(a, b)
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
# print(edges)
# sys.exit()

points = [0] * N
for _ in range(Q):
    p, x = map(int, sys.stdin.readline().split(" "))
    points[p-1] += x


visited = set()
counted = [0] * N
q = deque([(0, points[0])])
while q:
    node, point = q.popleft()
    # print(node, point)
    if node in visited:
        continue
    counted[node] = str(point)
    visited.add(node)
    for edge in edges[node]:
        q.appendleft((edge, point + points[edge]))

print(" ".join(counted))

Measured memory_bytes: 129756
#include <bits/stdc++.h>
using namespace std;
char a[100001],b[100001];
int main()
{
	int i,ans=0,ans1=0,l;
	scanf("%s",a);
	l=strlen(a);
	b[0]=a[0];
	for(i=1;i<l;i++)
	{
		b[i]=a[i];
		if(a[i]==a[i-1])
		{
			ans++;
			a[i]='1'-a[i]+'0';
		}
	}
	for(i=l-1;i>=0;i--)
	{
		if(b[i]==b[i+1])
		{
			ans1++;
			b[i]='1'-b[i]+'0';
		}
	}
	printf("%d",min(ans,ans1));
	return 0;
}

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

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;

#define N 100010
vector<int> adj[N];
bool vis[N];
map<pi, int> mp;
int mx;

void dfs(int x, int col)
{
    vis[x] = true;
    int cl = 1;
    mx = max(mx, col);
    for(auto y: adj[x]){
        if(vis[y] == false){
            if(cl == col) cl++;
            mp[{x, y}] = cl;
            mp[{y, x}] = cl;
            dfs(y, cl);
            cl++;
        }
    }
}


int main()
{
    int n;
    cin >> n;
    vector<pi> vec;
    for(int i=1; i<n; i++){
        int u, v;
        cin >> u >> v;
        vec.push_back({u, v});
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1, 0);
    cout << mx << "\n";
    for(pi x: vec){
        cout << mp[x] << "\n";
    }

    return 0;
}


Measured memory_bytes: 20472
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,k,a,b;
    cin>>k>>a>>b;
    for(i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            cout<<"OK";
            return 0;
        }
    }
    cout<<"NG";
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int solve(const vector<int>& v) {
	int now = 0;
	rep(i, 5) {
		while (now % 10 != 0) now++;
		now += v[i];
	}
	return now;
}

int main(int argc, char const *argv[]) {
	vector<int> v;
	rep(i, 5) {
		int d; cin >> d;
		v.emplace_back(d);
	}
	sort(v.begin(), v.end());

	int ans = INF;
	do {
		ans = min(solve(v), ans);
	} while(next_permutation(v.begin(), v.end()));
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define N 200010
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}


signed main(){
  
  map<int,int>M ;
  int n;
  cin>>n;  
  for(int i=0;i<n;i++){
    int d;
    cin>>d;
    M[d]++;
  }

  int m,ans =1;
  cin>>m;
  for(int i=0;i<m;i++){
    int t;
    cin>>t;
    if(M[t]) M[t]--;
    else ans = 0;
  }

  cout<<(ans? "YES":"NO")<<endl;
  return 0;
}


Measured memory_bytes: 12800
n = int(input())
sp = []
for i in range(n):
    sspp = list(map(str, input().split()))
    sspp[1] = int(sspp[1])
    sspp.append(i+1)
    sp.append(sspp)

# sp.sort(key=lambda x: x[0])
sp.sort(key=lambda x: (x[0], -x[1]))

for i in range(n):
    print(sp[i][2])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define all(a)  (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

int main(){
  string s,t; cin >> s >> t;
  string ans = "Yes";
  int n = s.size();
  vvi sg(26),tg(26);

  rep(i, n){
    int c = s[i] - 'a';
    sg[c].push_back(i);
    c = t[i] - 'a';
    tg[c].push_back(i);
  }

  rep(c, 26){
    if(sg[c].size() > 1){
      for (int i = 1; i < sg[c].size(); i++) {
        if(t[sg[c][i]] != t[sg[c][i-1]]) ans = "No";
      }
    }

    if(tg[c].size() > 1){
      for (int i = 1; i < tg[c].size(); i++) {
        if(s[tg[c][i]] != s[tg[c][i-1]]) ans = "No";
      }
    }
  }

  std::cout << ans << '\n';
}


Measured memory_bytes: 3080
#include <cstdio>
#include <vector>
using namespace std;

int main() {
	int n,s=0;
	vector<int> a;
	scanf("%d",&n);
	a.resize(n);
	for(int i=0; i<n; ++i) {
		scanf("%d",&a[i]);
	}
	for(int i=0; i<n-1; ++i) {
		for(int j=n-1; j>=i+1; --j) {
			if(a[j]<a[j-1]) {
				swap(a[j],a[j-1]);
				++s;
			}
		}

	}
	for(int i=0; i<n-1; ++i) {
		printf("%d ",a[i]);
	}
	printf("%d\n%d\n",a[n-1],s);
	return 0;
}

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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}

struct FenwickTree {
    int N;  vi A;
    FenwickTree(int n): N(n+1), A(N) {}
    // Add v to A[0,b)
    void adjust(int b,int v) { for (;b;b-=b&-b) A[b]+=v; }
    // Add v to A[a,b)
    void adjust(int a,int b,int v) { adjust(b,v), adjust(a,-v); }
    int pq(int i) { int r=0; for (i++;i<N;i+=i&-i) r+=A[i]; return r;	}
};

int main(){
    std::ios_base::sync_with_stdio(false); cin.tie(0);
    int n, m; cin >> n >> m;
    vector<int> arr(m + 1, 0);
    vector<vpii> inter(m + 5);
    for (int i = 0; i < n; i++){
        int x, y; cin >> x >> y;
        inter[y - x + 1].emplace_back(x, y);
    }

    FenwickTree tree(m + 1);
    int taken = 0;
    for (int i = 1; i <= m; i++){
        // add larger segments
        for (pii p : inter[i]){
            tree.adjust(p.X, p.Y + 1, 1);
            taken++;
        }
        int res = n - taken;
        for (int j = i; j <= m; j += i){
            res += tree.pq(j);
        }
        cout << res << endl;
    }

}


Measured memory_bytes: 8448
#pragma GCC optimize("Ofast")
  #pragma GCC target("avx,avx2,fma")
  #pragma GCC optimization ("unroll-loops")
  #include <bits/stdc++.h>
  using namespace std;
  //---------------------------------//
  void __print(int x) {cerr << x;}
  void __print(long x) {cerr << x;}
  void __print(long long x) {cerr << x;}
  void __print(unsigned x) {cerr << x;}
  void __print(unsigned long x) {cerr << x;}
  void __print(unsigned long long x) {cerr << x;}
  void __print(float x) {cerr << x;}
  void __print(double x) {cerr << x;}
  void __print(long double x) {cerr << x;}
  void __print(char x) {cerr << '\'' << x << '\'';}
  void __print(const char *x) {cerr << '\"' << x << '\"';}
  void __print(const string &x) {cerr << '\"' << x << '\"';}
  void __print(bool x) {cerr << (x ? "true" : "false");}

  template<typename T, typename V>
  void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
  template<typename T>
  void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
  void _print() {cerr << "]\n";}
  template <typename T, typename... V>
  void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
  #ifndef ONLINE_JUDGE
  #define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
  #else
  #define deb(x...)
  #endif
 //------------------------------//

  typedef long long int ll;
  typedef pair<int,int> pi;
  typedef pair<ll,ll> pll;
  typedef vector<int> vi;
  typedef vector<ll> vll;
  typedef vector<pi> vpi;
  typedef vector<pll> vpll;

  #define  ff           first
  #define  ss           second
  #define  pb           push_back
  #define  IOS          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define  all(x)       (x).begin(), (x).end()
  #define  ps(x,y)      fixed<<setprecision(y)<<x
  #define  rep(i,a,b)   for(ll i=a ; i<b ; ++i)

  const ll MOD = 1e9 + 7;
  const ll INF = 1e18;
  const ll maxn = 1e6 + 4;


  void solve(){
		ll sum=0;
		string s;
		cin >> s;
		for(int i=0;i<s.size();i++){
			sum += (s[i]-'0');
		}
		if(sum%9)cout << "No";
		else cout << "Yes";
  }

  int main(){
    IOS
    	solve();
    //cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }

// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying

Measured memory_bytes: 3740
import sys
sys.setrecursionlimit(10**7)
# 上記の文がないとREになる。


def k(v, distance):  # distanceは0or1
    flag[v] = distance  # 最初は0

    for next_v, w in graph[v]:
        if flag[next_v] == 1 or flag[next_v] == 0:  # 到達済み（親）であればcontinue
            continue
        if (w % 2) == 0:  # そのノードへの距離が偶数であればそのまま（最初は0なので）
            k(next_v, distance)
        else:
            k(next_v, 1-distance)


N = int(input())
graph = [[] for _ in range(N)]

for i in range(N-1):
    u, v, w = map(int, input().split())
    graph[u-1].append((v-1, w))
    graph[v-1].append((u-1, w))
# これによって木が定義できた
# print(graph)

flag = [None for _ in range(N)]  # まだどの頂点も探索していない

k(0, 0)  # 親を強制的に決めてよい, この場合は0のノードを親にしている
for i in range(N):
    print(int(flag[i]))


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

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

struct edge {
	int to,cost;
	edge(int t,int c):to(t),cost(c) {}
};

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

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

string s;
int a,b,c;

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

	cin>>s;
	FOR(i,0,s.size()) {
		if(s[i]=='a') a++;
		else if(s[i]=='b') b++;
		else c++;
	}

	if(abs(a-b)>=2||abs(b-c)>=2||abs(c-a)>=2) {
		cout<<"NO"<<endl;
	}
	else cout<<"YES"<<endl;

	return 0;
}


Measured memory_bytes: 512
N = int(input())

def calc(p, s):
    return p + s

def main():
    l0 = 2
    l1 = 1
    if N == 1:
        print(l1)
    else:
        p = l0
        s = l1
        for i in range(N - 1):
            temp = calc(p, s)
            p = s
            s = temp
        print(s)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
int n;
cin >> n;
int l[2*n];
int i,j;
for(i=0;i<2*n;i++){
cin >> l[i];
}
for(i=0;i<2*n;i++){
for(j=0;j<2*n-1-i;j++){
if(l[j]>l[j+1]){
int x=l[j];
l[j]=l[j+1];
l[j+1]=x;
}
}
}
int ans;
for(i=0;i<n;i++){
ans +=l[i*2];
}
cout << ans << endl;
return 0;
}


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

int N, W, vi, wi;

int main() {
    cin >> N >> W;
    int a[W+1];
    for (int i=0; i<W+1; i++) a[i]=0;
    for (int i=0; i<N; i++) {
        cin >> vi >> wi;
        for (int j=0; j<W+2-wi; j++) {
            if (a[W+1-j]<a[W+1-j-wi]+vi) a[W+1-j] = a[W+1-j-wi]+vi;
        }
    }
    cout << a[W] << endl;
}


Measured memory_bytes: 3140
#include <iostream>

int N,M;
int flag[308];
int number[308];
int order[308][308];
int current[308];
using namespace std;
int main() {
	cin >> N >> M;
	for(int i=0;i<N;i++) for(int j=0;j<M;j++) {
		int vl;
		cin >> vl;
		order[i][j]=vl-1;
		if(j==0) number[vl-1]++;
	}
	int sol=0;
	for(int i=0;i<M;i++) if(sol<number[i]) sol=number[i];
	for(int lp=0;lp<M-1;lp++) {
		int maxv=-1;
		int arg=0;
		for(int i=0;i<M;i++) if(flag[i]==0&&maxv<number[i]) {
			maxv=number[i];
			arg=i;
		}
		//delete arg
		flag[arg]=1;
		for(int i=0;i<N;i++) while(current[i]<M) {
			if(flag[order[i][current[i]]]) {
				number[order[i][current[i]]]--;
				current[i]++;
				if(current[i]<M) number[order[i][current[i]]]++;
			} else {
				break;
			}
		}
		int ksol=0;
		for(int i=0;i<M;i++) if(ksol<number[i]) ksol=number[i];
		if(sol>ksol) sol=ksol;
	}
	cout << sol << endl;
	return 0;
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int peri, n;
  cin >> peri >> n;
  vector<int> v(n);
  for (int &i : v) cin >> i;
  sort(v.begin(), v.end());
  int big_gap = 0;
  for (int i = 0; i < n; i++) {
    if (i == n - 1) big_gap = max(big_gap, abs(v[i] - peri) + v[0]);
    else {
      big_gap = max(big_gap, abs(v[i] - v[i + 1]));
    }
  }
  cout << peri - big_gap << '\n';
  return 0;
}

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

#define fec(i, x, y) (int i = head[x], y = g[i].to; i; i = g[i].ne, y = g[i].to)
#define dbg(...) fprintf(stderr, __VA_ARGS__)
#define File(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define fi first
#define se second
#define pb push_back

template<typename A, typename B> inline char smax(A &a, const B &b) {return a < b ? a = b, 1 : 0;}
template<typename A, typename B> inline char smin(A &a, const B &b) {return b < a ? a = b, 1 : 0;}

typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> pii;

template<typename I> inline void read(I &x) {
	int f = 0, c;
	while (!isdigit(c = getchar())) c == '-' ? f = 1 : 0;
	x = c & 15;
	while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);
	f ? x = -x : 0;
}

const int N = 200000 + 7;
const int LOG = 20;

int n, k;
int a[N], q1[N][LOG], q2[N][LOG], q[N];

inline void ycl1() {
	for (int i = 1; i <= n; ++i) q1[i][0] = a[i];
	for (int j = 1; (1 << j) <= n; ++j)
		for (int i = 1; i + (1 << j) - 1 <= n; ++i)
			q1[i][j] = std::max(q1[i][j - 1], q1[i + (1 << (j - 1))][j - 1]);
}
inline void ycl2() {
	for (int i = 1; i <= n; ++i) q2[i][0] = a[i];
	for (int j = 1; (1 << j) <= n; ++j)
		for (int i = 1; i + (1 << j) - 1 <= n; ++i)
			q2[i][j] = std::min(q2[i][j - 1], q2[i + (1 << (j - 1))][j - 1]);
}
inline int qmax(int l, int r) {
	int k = std::__lg(r - l + 1);
	return std::max(q1[l][k], q1[r - (1 << k) + 1][k]);
}
inline int qmin(int l, int r) {
	int k = std::__lg(r - l + 1);
	return std::min(q2[l][k], q2[r - (1 << k) + 1][k]);
}

inline void work() {
	ycl1();
	ycl2();
	int cnt = 0, ans = 0, tp = 0;
	for (int i = 1; i < k; ++i) {
		while (tp && a[i] <= a[q[tp]]) --tp;
		q[++tp] = i;
	}
	for (int i = k; i <= n; ++i) {
		int mn = qmin(i - k + 1, i), mx = qmax(i - k + 1, i);
		while (tp && a[i] <= a[q[tp]]) --tp;
		q[++tp] = i;
//		dbg("i = %d, tp = %d, q[tp - k + 1] = %d\n", i, tp, q[tp - k + 1]);
		if (tp >= k && q[tp - k + 1] == i - k + 1) {
			cnt = 1;
			continue;
		}
		if (i == k) {
			++ans;
			continue;
		}
		smin(mn, a[i - k]), smax(mx, a[i - k]);
		if (a[i - k] != mn || a[i] != mx) ++ans;
	}
	printf("%d\n", ans + cnt);
}

inline void init() {
	read(n), read(k);
	for (int i = 1; i <= n; ++i) read(a[i]);
}

int main() {
#ifdef hzhkk
//	freopen("hkk.in", "r", stdin);
#endif
	init();
	work();
	fclose(stdin), fclose(stdout);
	return 0;
}

Measured memory_bytes: 33024
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())

#define MOD 1000000007

//逆元で二項係数を計算(MODは素数)　前処理O(n),本計算O(1)
#define MAXN 2000000
long long inv[MAXN + 1];//MODを法とする乗法の逆元
long long fact[MAXN + 1];//階乗
long long ifact[MAXN + 1];//階乗の逆元
void init() {
	inv[1] = 1;
	for (int i = 2; i <= MAXN; i++) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
	fact[0] = ifact[0] = 1;
	for (int i = 1; i <= MAXN; i++) {
		fact[i] = i * fact[i - 1] % MOD;
		ifact[i] = ifact[i - 1] * inv[i] % MOD;
	}
}
long long C(int n, int r) {
	if (n < 0 || r < 0 || r > n)return 0;
	if (r > n / 2)r = n - r;
	return fact[n] * ifact[n - r] % MOD * ifact[r] % MOD;
}

long long f(int y ,int x) {
	return C(x + y, x);
}



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

	init();
	int r1, c1, r2, c2;
	cin >> r1 >> c1 >> r2 >> c2;

	long long cur = f(r1, c1);
	long long ans = cur;
	
	rep(i, r2 - r1 + c2 - c1) {
		cur *= 2;
		if (i >= r2 - r1) {
			cur -= f(r2, c1 + i - (r2-r1));
		}
		else {
			cur += f(r1 + i + 1, c1 - 1);
		}
		if (i >= c2-c1) {
			cur -= f(r1 + i - (c2 - c1), c2);
		}
		else {
			cur += f(r1 - 1, c1 + i + 1);
		}
		cur %= MOD;

		ans += cur;
	}


	ans %= MOD; ans += MOD; ans %= MOD;
	cout << ans << endl;
	
	



	return 0;
}

Measured memory_bytes: 47104
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 998244353
#define inf 1000000000000000007
#define eps 0.0000000001
#define pi acosl(-1)
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
vpl v;
bool comparion(pll a,pll b)
{
	ll x=min(a.ss,a.ff+b.ss);
	ll y=min(b.ss,b.ff+a.ss);
	return (x>y);
}
void solve()
{
	ll n;
	cin>>n;
	string s;
	for(ll i=0;i<n;i++)
	{
		cin>>s;
		ll d=0,x=0;
		for(ll j=0;j<s.length();j++)
		{
			if(s[j]=='(')
				x++;
			else
				x--;
			d=min(d,x);
		}
		v.pb({x,d});
	}
	sort(v.begin(),v.end(),comparion);
	ll cnt=0;
	for(auto i:v)
	{
		ll x=cnt+i.ss;
		if(x<0)
		{
			cout<<"No";
			return;
		}
		cnt+=i.ff;
		if(cnt<0)
		{
			cout<<"No";
			return;
		}
	}
	if(cnt!=0)
		cout<<"No";
	else
		cout<<"Yes";
}
int main()
{
    FAST
    #ifdef ayk_16
    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    #endif
    time_taken_start
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++)
    {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
    time_taken_end
}

Measured memory_bytes: 19692
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {



    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
         FastScanner sc = new FastScanner();
         PrintWriter out = new PrintWriter(System.out);
         String s1=sc.next().toUpperCase();
         String s2=sc.next().toUpperCase();
         String s3=sc.next().toUpperCase();
        System.out.println(s1.charAt(0)+""+s2.charAt(0)+""+s3.charAt(0));
        out.flush();
    }

    static void sort(int[] a) {
        ArrayList<Integer> l=new ArrayList<>();
        for (int i:a) l.add(i);
        Collections.sort(l);
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }
    static void sortReverse(long[] a) {
        ArrayList<Long> l=new ArrayList<>();
        for (long i:a) l.add(i);
//        Collections.sort.(l);
        Collections.sort(l,Collections.reverseOrder());
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }

    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long[] readArrayLong(long n) {
            long[] a=new long[(int)n];
            for (int i=0; i<n; i++) a[i]=nextLong();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }


}

Measured memory_bytes: 37156
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     3e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll> >
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define prll(a)                 cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,cur)               lower_bound(all(v),cur)-v.begin()
#define ub(v,cur)               upper_bound(all(v),cur)-v.begin()
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
long long pows(long long a, long long b) {
  long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll powm(ll x,ll y,ll m=MOD){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll modInverse(ll a, ll m=MOD){if(m == 1)return 0;ll m0=m,y=0,x=1;while(a>1){ll q=a/m,t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0) x+=m0;return x;}
int main()
{
fastIO
ll n,m,i,j,k,x,y,z,t,e,f,p,q,g,l,r,w,h,count1=0,prod=1,a,b,c,d,index,x1,x2,y1,y2,diff,ans=0,sum=0,sum1=0,sum2=0,flag=0,flag1=0,flag2=0;
string s,s1,s2;
cin>>s>>s1;
for(i=0;i<s.size();i++)
{
  if(s[i]!=s1[i])
  {
    flag=1;
    break;
  }
}
if(flag)
{
  cout<<"No\n";
}
else
{
  cout<<"Yes\n";
}
}


Measured memory_bytes: 3652
/*
AizuOnline A0033
Ball
*/
#include <stdio.h>

int tutu1(int b[])
{
  int i,last,cnt;

  last=b[0];cnt=1;b[0]=0;

  for(i=1;i<10;i++)
    {
      if(b[i] > last)
        { last = b[i];
          b[i] = 0;
          cnt ++;
        }
    }
  return(cnt);
}

int isseq(int b[])
{
  int i,minval;

  minval = 0;
  for(i=0;i<10;i++)
    if(b[i] > 0)
      {  if(b[i] < minval)
            return(0);
         else
           minval = b[i];
      }
  return(1);
  
  

}


main()
{
  int n;
  int i;
  int balls[10];

  scanf("%d",&n);
  /* printf("%d\n",n);*/
  while(n--)
  {
    for(i=0;i<10;i++)
      scanf(" %d",&(balls[i]));
    
    tutu1(balls);
    if (isseq(balls))
      printf("YES\n");
    else
      printf("NO\n");

/*    for(i=0;i<10;i++)
      printf("%d ",balls[i]);
*/
}
return(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
template<typename T> T GCD(T a, T b) { if (a % b == 0) { return b; } return(GCD(b, a % b)); }
void Yes() { cout << "Yes" << '\n'; return; }
void No () { cout << "No"  << '\n'; return; }

int main(){
    int Q; cin >> Q;
    while (Q--) {
        long long A, B, C, D;
        cin >> A >> B >> C >> D;
        if (A < B || D < B) { No(); continue; }
        if (B <= A && B <= D && B <= C) { Yes(); continue; }
        long long G = GCD(B, D), M = B - G + A % G;
        (M > C) ? No() : Yes();
    }
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> C(N);
    vector<int> S(N);
    vector<int> F(N);

    for(int i = 0; i < N - 1; i++){
        cin >> C[i] >> S[i] >> F[i];
    }

    for(int i = 0; i < N - 1; i++){
        int t = S[i];
        for(int j = i; j < N - 1; j++){
         if(t % F[j] == 0 && t >= S[j]){ t += C[j]; }
               else if(t % F[j] != 0 && t >= S[j]){ 
                t = F[j] * (t / F[j]) + F[j];
                t += C[j];
               }
               else if( t < S[j]){
                t = S[j];
                t += C[j];
                }
        }
        cout << t << endl;
    }

    cout << 0 << endl;

return 0;
}

Measured memory_bytes: 256
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//define
#define inp(X) cin>>X;
#define inp_long(X) long long X; cin>>X;
#define inp_arr(A,N) long long A[N]; for(long long int i=0;i<N;i++) {cin>>A[i];}
#define sz(A) A.size()
#define pb push_back
#define pf push_front
#define fi first
#define se second
//#define endl '\n'
#define vect(A) vector<long long> A;
#define inp_vect(A,N); vect(A);for(long long i=0;i<N;i++){long long q; cin>>q; A.push_back(q);}
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}
ll modInverse(ll a)
{
   return power(a,MOD-2);
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 

//ll z[1000001]={0};

int main()
{
    /*
    #ifndef ONLINE_JUDGE
       freopen ("input.txt" , "r" , stdin);
		// freopen ("OUTPUT.txt" , "w" , stdout);
	#endif
    */
    fio;
    ll n;
    cin>>n;
    ll p=0;
    ll a[n];
    forin(i,0,n-1)
    {
        cin>>a[i];
    }
    forin(i,0,n-1)
    {
        if(a[i]-1==i-p)
        {

        }
        else
        p++;
    }
    if(p<n)
    {
        cout<<p<<endl;
    }
    else
    cout<<"-1"<<endl;
    
}

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

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(0);
    int n,m;
    cin>>n>>m;
    
    int a,b,res;
    a = n*(n-1)/2;
    b= m*(m-1)/2;
    res= a+b;
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 256
def divisors(n):
    ret = set()
    for i in range(1, int(n**0.5)+2):
        if n % i == 0:
            ret.add(i)
            ret.add(n // i)
    ret.remove(1)
    return ret


def main():
    N = int(input())
    s = divisors(N)
    ans = divisors(N-1)

    for x in s:
        n = N
        if x == 1:
            continue
        while(n % x == 0):
            n = n // x
        if n % x == 1:
            ans.add(x)
    print(len(ans))


main()


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if(a * b % 3 == 0 || (a + b) % 3 == 0){
		cout << "Possible" << endl;
	}
	else{
		cout << "Impossible" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "YES"; } string_type do_falsename() const { return "NO"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  string str; cin >> str;
  const ll n = str.size();
  ll pos = n;
  vector<bool> dp(n+1, false);
  dp[0] = true;
  vector<string> kh{"dream", "dreamer", "erase", "eraser"};
  rep(i, n) {
    if (!dp[i]) continue;
    each(s, kh) {
      if (i+s.size() <= n && str.substr(i, s.size()) == s) {
        dp[i+s.size()] = true;
      }
    }
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 512
# N:正の整数
# ある素数p
# 正の整数e
# z=p**eと表せる
# N % z == 0
# N = N/Z

# 因数分解
# 各因数は1からカウントアップして取れるだけ取る
import math
N=int(input())
p={}

if N<=1:
    print (0)
    exit()


for i in range(2,int(math.sqrt(N)+1)):
    while N % i == 0:
        if i in p:
            p[i]+=1
        else:
            p[i]=1
        N/=i

#素数が残った場合
if N!=1:
    p[N]=1

ans=0
for Pi in p.values():
    for j in range (1,Pi+1) :
        if Pi >= j:
            Pi  -= j
            ans +=1

if ans==0:
    print(1)
    exit()
print (ans)

Measured memory_bytes: 9288
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		TradeMangaer tm = new TradeMangaer(1000);
		//?????????????????????
		while(true){
			String str = br.readLine();
			if(str.equals("")){
				break;
			}
			String[] tmp = str.split(",");
			int id = Integer.parseInt(tmp[0]);
			int date = Integer.parseInt(tmp[1]);
			
			tm.addTrade(id, date, TradeMangaer.LAST_MONTH);
		}
		
		//?????????????????????
		while(true){
			String str = br.readLine();
			if(str == null){
				break;
			}
			String[] tmp = str.split(",");
			int id = Integer.parseInt(tmp[0]);
			int date = Integer.parseInt(tmp[1]);
			
			tm.addTrade(id, date, TradeMangaer.THIS_MONTH);
		}
		
		tm.printTrades();
	}

}

class TradeMangaer {
	private Customer[] customers;
	static int THIS_MONTH = 1;
	static int LAST_MONTH = 2;
	
	public TradeMangaer (int n){
		customers = new Customer[n];
		
		for(int i = 0; i < n; i++){
			customers[i] = new Customer();
		}
	}
	
	public void addTrade(int id, int date, int month){
		int index = indexOfCustomer(id);
		
		if(month == THIS_MONTH){
			customers[index].addTradeThisMonth();
		}
		else if(month == LAST_MONTH){
			customers[index].addTradeLastMonth();
		}
	}
	
	public int indexOfCustomer(int id){
		return id - 1;
	}
	
	public void printTrades(){
		for(int i = 0; i < customers.length ; i++){
			if(customers[i].twoMonthContinue()){
				customers[i].printTrades();
			}
		}
	}
}

class Customer {
	private int tradeLastMonth = 0;
	private int tradeThisMonth = 0;
	private int id;
	static int IDseed = 1;
	
	public Customer () {
		id = IDseed++;
	}
	
	public void addTradeLastMonth(){
		tradeLastMonth++;
	}
	
	public void addTradeThisMonth(){
		tradeThisMonth++;
	}
	
	public boolean twoMonthContinue(){
		if(tradeLastMonth > 0 && tradeThisMonth > 0){
			return true;
		}
		else {
			return false;
		}
	}
	
	public void printTrades(){
		System.out.println(id + " " +(tradeLastMonth+tradeThisMonth));
	}
}

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

int main() {
	int N;
	cin >> N;
	
	vector<int> a(N);

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

	int count = 0;
	int num = 1;

	for (int j = 0; j < N; j++) {
		if (num != a[j]) {
			count++;
		}
		else {
			num++;
		}
	}
	if (count == N) {
		count = -1;
	}
	cout << count << endl;
}

Measured memory_bytes: 1024
N, M, Q = map(int, input().split())
s = [[0 for j in range(N+1)] for i in range(N+1)]
for i in range(M):
    l, r = map(int, input().split())
    s[l][r] += 1

for i in range(1, N+1):
    for j in range(1, N+1):
        s[i][j] += s[i-1][j] + s[i][j-1] - s[i-1][j-1]

for i in range(Q):
    l, r = map(int, input().split())
    print(s[r][r] - s[r][l-1] - s[l-1][r] + s[l-1][l-1])

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

namespace AtCoder
{
    public class Prog
    {
        const int MOD = 1000000007;
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Prog().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(ConsoleInput cin)
        {
            var n = cin.ReadInt;
            var s = cin.ReadStrArray(n);

            var ans = string.Empty;

            foreach (var c in "abcdefghijklmnopqrstuvwxyz")
            {
                var min = int.MaxValue;
                foreach (var str in s)
                {
                    min = Math.Min(min, str.Count(x => x == c));
                }
                ans += new string(c, min);
            }

            Console.WriteLine(ans);
        }
    }
    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; } }
    }
}


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

#define len(x) (int)((x).size())
#define show(x) cout << #x << " = " << x << "\n"

#define maxs(x, y) x = std::max(x, y)
#define mins(x, y) x = std::min(x, y)

using ll = long long;
using ull = unsigned long long;

const int INF = 10000000;
const ll LINF = 1000000000000;

int main() {
    int N, W;
    std::cin >> N >> W;

    std::vector<int> w(N), v(N);
    for(int i = 0; i < N; ++i) {
        std::cin >> w[i] >> v[i];
    }

    // dp[i][j]: min weight of items to achive j value from first i items
    std::vector<std::vector<ll>> dp(N + 1, std::vector<ll>(100005));
    for(int j = 1; j < 100005; ++j) {
        dp[0][j] = LINF;
    }
    for(int i = 1; i <= N; ++i) {
        for(int j = 1; j < 100005; ++j) {
            dp[i][j] = dp[i - 1][j];
            if(j >= v[i - 1]) {
                mins(dp[i][j], w[i - 1] + dp[i - 1][j - v[i - 1]]);
            }
        }
    }

    for(int j = 100000; j >= 0; --j) {
        if(dp[N][j] <= W) {
            std::cout << j << "\n";
            return 0;
        }
    }
}

Measured memory_bytes: 80256
from sys import stdin, stdout # only need for big input

max_honest = 0
testomonies = []
state = []

def dfs(person):
    global max_honest
    if person >= len(state):
        correctState = True
        for p in range(len(state)):
            if state[p] == 1:
                for t in testomonies[p]:
                    x, y = t
                    if state[x] != y:
                        correctState = False
                        break
        if correctState:
            sum = 0
            for s in state:
                sum += s
            max_honest = max(max_honest, sum)
        return

    state[person] = 0
    dfs(person + 1)

    state[person] = 1 
    dfs(person + 1)
    

def solve():
    global state
    n = int(stdin.readline())
    for _ in range(n):
        a = int(stdin.readline())
        t = []
        for _ in range(a):
            x, y = [int(inp) for inp in stdin.readline().split()]
            t.append((x - 1,y))
        testomonies.append(t)
    # print(testomonies)
    state = [-1] * n
    dfs(0)
    print(max_honest)


def main():
    solve()


if __name__ == "__main__":
    main()

Measured memory_bytes: 9232
#include <iostream>
using namespace std;
int main(void){
    int a, b;
    string op;
    
    int ans = 0; 
    
    
    
    for(int i=0; i<20000; i++){
        
        cin >> a >> op >> b;
        
        if (op == "+"){
            ans = a + b;
        }
        else if(op == "-"){
            ans = a - b;
        }
        else if(op == "*"){
            ans = a * b;
        }
        else if(op == "/"){
            ans = a / b;
        }
        else{
            break;
        }
        
        cout << ans << endl;
        
    }
}


Measured memory_bytes: 3148