akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int h,w;
    cin>>h>>w;
    if ((h==1&&w!=1)||(h!=1&&w==1)) {
        cout<<1<<endl;
    } else if (h%2==1&&w%2==1) {
        cout<<((h*w)/2)+1<<endl;
    } else {
        cout<<(h*w)/2<<endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int keta(int a) {
    int res = 0;
    while(a > 0) {
        a /= 10;
        res++;
    }
    return res;
}

int hd(int a) {
    int b = 0;
    while(a > 0) {
        b = a % 10;
        a /= 10;
    }
    return b;
}

int get(int a, int b, int num) {
    int n = 1;
    int add = 0;
    rep(i, num - 1) {
        n *= 10;
        if(i != num - 2)
            add += 9 * n;
    }

    return a * n + b + add;
}

int get0(int a, int b, int num) {
    int n = 1;
    rep(i, num - 1) { n *= 10; }

    return a * n + b;
}

int center(int a) {
    int d = 1;
    rep(i, keta(a) - 1) d *= 10;
    a -= hd(a) * d;
    a /= 10;
    return a;
}

int main() {
    int N;
    cin >> N;
    int kt = keta(N);
    vector<vector<int>> nums(10, vector<int>(10));
    for(int i = 1; i <= 9; i++) {
        for(int j = 1; j <= 9; j++) {
            int tmp = 0;
            if(i == j && N >= i)
                tmp++;
            if(i * 10 + j <= N)
                tmp++;
            int p = 10;
            for(int k = 3; k <= kt; k++) {
                if(N >= get(i, j, k))
                    tmp += p;
                else if(N >= get0(i, j, k)) {
                    if(N % 10 >= j)
                        tmp += center(N) + 1;
                    else
                        tmp += center(N);
                }
                p *= 10;
            }
            nums[i][j] = tmp;
        }
    }
    int res = 0;
    for(int i = 1; i <= N; i++) {
        res += nums[i % 10][hd(i)];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	currentList = input[0].split(" ").map( str => parseInt(str, 10) );
 console.log(currentList[0] * currentList[1] / 2);	
};


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {
	char a1,a2,a3;
	cin >> a1 >> a2 >> a3;
	char d1,d2,d3;
	cin >> d1 >> d2 >> d3;
	int ans=0;
	if(a1 == d1){
		ans += 1;
	}
	if(a2 == d2){
		ans += 1;
	}
	if(a3 == d3){
		ans += 1;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter

sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

c = Counter(A)
v, c = zip(*c.most_common(2))
if max(c) == 1:
	print(N-2)
	sys.exit()
if len(v) < 2:
	print(N//2)
	sys.exit()
a = v[0]
b = v[1]

can_a = [a if i%2 else b for i in range(N)]
can_b = [b if i%2 else a for i in range(N)]
#print(can_a, can_b)

cand = [can_a, can_b]
ans = float('INF')
for c in cand:
	cnt = 0
	for i in range(N):
		if c[i] != A[i]: cnt+=1
	ans = min(ans, cnt)

print(ans)


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

int main()
{
	int r;
	cin >> r;
	if (r < 1200)
	{
		cout << "ABC" << endl;
	}
	else if (r < 2800)
	{
		cout << "ARC" << endl;
	}
	else
	{
		cout << "AGC" << endl;
	}
	return 0;
}

Measured memory_bytes: 764
//#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>

/*
ID: jamerz1
PROG: hidden
LANG: C++11
*/

using namespace std;

// TIMER
std::clock_t __start;
double __duration;
void start_timer() { __start = std::clock(); }
void print_timer() {
	__duration = (std::clock() - __start) / (double)CLOCKS_PER_SEC;
	std::cout << "Duration (msec): " << __duration * 1000 << '\n';
}
// END TIMER

//PI
#define M_PI		3.14159265358979323846
// fast input
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)

template <class T>
T min_(T a, T b) { return (a < b ? a : b); }
template <class T>
T max_(T a, T b) { return (a > b ? a : b); }

double EPS_ = 1e-16;
bool eq_(const double& lhs, const double &rhs) {
	return (fabs(lhs - rhs) < EPS_);
}

//#define F first
//#define S second

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef pair<int, int> ii;
typedef pair<double, double> dd;

typedef pair<ll, ll> llll;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<llll> vllll;
typedef vector<int> vi;
typedef vector<ull> vull;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;

const int INF = int(2e9);
const ll INF_LL = LLONG_MAX;
const ll MOD = 1e9 + 7;

vector<vb> open;
vector<vi> profit;

bool is_set(int num, int bit) {
	return (num & (1 << bit)) != 0;
}

vi get_C(int N, int mask) {
	vi C(N, 0);
	for (int per = 0; per < 10; ++per) {
		if (is_set(mask, per)) {
			for (int i = 0; i < N; ++i) {
				C[i] += open[i][per];
			}
		}
	}
	return C;
}

int main()  {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int N;
	bool in;
	cin >> N;
	open.assign(N, vb(10, false));
	profit.assign(N, vi(11));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 5; ++j) {
			for (int k = 0; k < 2; ++k) {
				cin >> in;
				open[i][2*j + k] = in;
			}
		}
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 11; ++j) {
			cin >> profit[i][j];
		}
	}

	ll best_profit = -INF_LL;
	for (int i = 1; i < 1024; ++i) {
		vi C = get_C(N, i);
		ll curr_profit = 0;
		for (int j = 0; j < N; ++j) {
			curr_profit += profit[j][C[j]];
		}
		best_profit = max(best_profit, curr_profit);
	}
	
	cout << best_profit << '\n';

	return 0;
}

Measured memory_bytes: 256
K = input()
D = int(input())
L = len(K)
MOD = 10**9 + 7

dp = [[[0]*D for _ in range(2)] for _ in range(L+1)]
# dp[i][j][d] = num of "up to i-th, j = less than flag, d mod = d"
dp[0][0][0] = 1

for i in range(1, L+1):
    a = int(K[i-1])
    for d in range(D):
        dp[i][0][(d+a)%D] += dp[i-1][0][d]
        dp[i][0][(d+a)%D] %= MOD
        for b in range(10):
            dp[i][1][(d+b)%D] += dp[i-1][1][d] + (b<a)*dp[i-1][0][d]
            dp[i][1][(d+b)%D] %= MOD

print((dp[L][0][0] + dp[L][1][0] - 1)%MOD)

Measured memory_bytes: 92500
// #define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}
int main()
{
    int H, W, N;
    cin >> H >> W >> N;

    if (H<W) swap(H, W);
    int ans = (N+H-1)/H;
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
      cin.tie(0);
      ios::sync_with_stdio(false);
      int A, B;
      cin >> A >> B;
      if((A+B) % 2 == 0){
          cout << (A+B)/2 << endl;
      }
      else{
          cout << "IMPOSSIBLE" << endl;
      }
}


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

int main(){
  int cnt[26]={};
  char c;

  while(scanf("%c", &c)!=EOF){
    if(isupper(c)) cnt[tolower(c)-'a']++;
    else cnt[c-'a']++;
  }
  for(int i=0;i<26;i++) printf("%c : %d\n", 'a'+i, cnt[i]);
  return 0;
}

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

class DisjointSet{
public:
	vector<int> rank, p;//rank:木の高さ p:親の頂点番号
	DisjointSet(){}
	DisjointSet(int size){//頂点の数
		rank.resize(size, 0);
		p.resize(size, 0);
		rep(i, size) makeSet(i);
	}
	bool same(int x, int y){ //同じ木にあるか
		return findSet(x) == findSet(y);
	}
	void unite(int x, int y){ // 木どうしをくっつける
		link(findSet(x), findSet(y));
	}
private:
	void makeSet(int x){
		p[x] = x;
		rank[x] = 0;
	}
	int findSet(int x){ //親を探す（ルートまで）
		if(x != p[x]){
			p[x] = findSet(p[x]);
		}
		return p[x];
	}
	void link(int x, int y){ //木の高さを考慮して木どうしをくっつける
		if(rank[x] > rank[y]){
			p[y] = x;
		}else{
			p[x] = y;
			if(rank[x] == rank[y]) rank[y]++;
		}
	}
};


int main(int argc, char const *argv[])
{
	int n, m; cin >> n >> m;
	vector<int> p(n); {
		rep(i, n) {
			cin >> p[i]; p[i]--;
		}
	}
	vector<int> x(m), y(m); {
		rep(i, m) {
			cin >> x[i] >> y[i];
			x[i]--, y[i]--;
		}
	}

	DisjointSet uf(n);
	rep(i, m) {
		uf.unite(x[i], y[i]);
	}

	int ans = 0;
	rep(i, n) if (uf.same(i, p[i])) ans++;
	printf("%d\n", ans);
	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    REP(i, N) A[i]--;
    vector<ll> S(N+1, 0);
    REP(i, N) S[i+1] = S[i] + A[i];
    //cout << S << endl;

    REP(i, N+1) S[i] %= K;
    //cout << S << endl;

    map<ll, ll> cnt;
    REP(i, min(K, N+1)){
    	cnt[S[i]]++;
    }
    ll res = 0;
    REP(i, N+1){
    	cnt[S[i]]--;
    	res += cnt[S[i]];
    	//dump(cnt[S[i]])
    	if(i+K<N+1)cnt[S[i+K]]++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define ll long long int
#define dbg(x) cout<<"( "<<#x<<" -> "<<x<<" )"<<endl;
using namespace std;
int main()
{
    ll n;
    scanf("%lld",&n);
    ll mini=1000000000000000000;
    for (ll i=1;i*i<=n;i++)
    {
        if (n%i==0)
        {
            ll val1=i;
            ll val2=(n/i);
            mini=min(mini,(val1+val2-2));
        }
    }
    printf("%lld\n",mini);
    return 0;
}

Measured memory_bytes: 3836
//
// Created by akiyu on 2019/07/22.
//

#include <iostream>
#include <cstdio>

using namespace std;

int main(void){
    int a, b;
    scanf("%d %d", &a, &b);
    if((a % (2 * b + 1)) == 0){
        cout << a / (1 + 2 * b) << endl;
    }else{
        cout << a / (1 + 2 * b ) + 1 << endl;
    }
}


Measured memory_bytes: 256
import numpy as np

N = int(input())
X = np.array(list(map(int, input().split())))

ans = 100 * 100 * N
for p in np.arange(np.min(X), np.max(X) + 1):
    s = 0
    for x in X:
        s += (x - p) ** 2
    if s < ans:
        ans = s
    p += 1

print(ans)

Measured memory_bytes: 27212
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pie acos(-1)
#define loop(i,a,n) for(int i=a;i<n;i++)
#define trav(a,x) for(auto &a:x)
#define vi vector<int>
#define vl vector<ll>
#define pii pair<ll,ll>
#define endl "\n"
#define w 100002
vector<int>g[w];
vector<int>indeg(w,0);
vector<int>outdeg(w,0);
vector<int>dp(w,-1);
int ans(int u)
{
    if(dp[u]!=-1)
    return dp[u];
    int res=0;
    for(int c:g[u])
    {
        res=max(res,ans(c));
    }
    return dp[u]=res+1;
}
void solve()
{
    int n,m;
    cin>>n>>m;
    loop(i,0,m)
    {
        int x,y;
        cin>>x>>y;
        g[x].pb(y);
        indeg[y]++;
        outdeg[x]++;
    }
    int val=0;
    loop(i,1,n+1)
    {
        if(indeg[i]==0)
        val=max(val,ans(i));
    }
    //cout<<dp[1];
    cout<<val-1;
}
int main() {
	// your code goes here
	io;
	
    solve();
	return 0;
}


Measured memory_bytes: 11648
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

ll mod = 1e9+7;
  
int main() {
	// 入力
	ll N;cin>>N;
    ll A[N][N-1];
    REP(i,N){
        REP(j,N-1){
            cin>>A[i][j];A[i][j]--;
        }
    }
    
    
	// 解法
    ll days = 0;
    ll count[N];REP(i,N)count[i]=0;
    while (true){
        // printf("days: %lld\n", days);
        ll flag_today = false;
        ll visited[N];REP(i,N)visited[i]=0;
        REP(i,N){
            if (count[i]==N-1) continue; // 選手iが全試合を終えている
            if (visited[i]==1) continue; // 選手iが今日の試合を終えている
            ll tmp = A[i][count[i]]; // 選手iの次の対戦相手
            if (count[tmp]==N-1) continue; // 選手iの次の対戦相手が全試合を終えている
            if (visited[tmp]==1) continue; // 選手iの次の対戦相手が今日の試合を終えている
            if (A[tmp][count[tmp]]==i){  // 選手iの次の対戦相手の次の対戦相手が選手iである
                visited[i]++;visited[tmp]++;
                count[i]++;count[tmp]++;
                flag_today = true; // 今日少なくとも1試合行われた。
                // printf("%lld VS %lld\n", i, tmp);
            }
        }
        if (flag_today==false){
            break;
        }
        else days++;
    }
    REP(i,N){
        if (count[i]!=N-1) days = -1;
    }
	//出力
	cout << days << endl;
}


Measured memory_bytes: 8064
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

//const long long int MOD = 1000000007;
const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R


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

	cin >> N >> M >> K;
	cout << min(K, M / N) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
char ren[1000000];
int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	int xf=0;
	int j2=0;
	scanf("%s",&ren); 
	for(int i=1;i<n;i++)
	{
		if(ren[i]==ren[i-1])
		xf++;
	}
//	printf("xf%d\n",xf);
	if(xf+2*k>n-1)
	xf=n-1;
	else
	xf=xf+2*k;
	
	printf("%d",xf);
}

Measured memory_bytes: 256
s = [int(x) for x in input().split()]

if s[0] == s[1] and s[1] != s[2]:
    print('Yes')
elif s[0] == s[2] and s[1] != s[2]:
    print('Yes')
elif s[1] == s[2] and s[0] != s[1]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <fstream>
#include <cmath>
#include <limits>
#include <chrono>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
#include <cassert>
#pragma warning (disable: 4996)
using namespace std;

using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

struct UnionFind {
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

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

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    if (n < 0)return 0;
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

ll merge_cnt(vector<ll>& a) {
    int n = a.size();
    if (n <= 1) { return 0; }

    ll cnt = 0;
    vector<ll> b(a.begin(), a.begin() + n / 2);
    vector<ll> c(a.begin() + n / 2, a.end());

    cnt += merge_cnt(b);
    cnt += merge_cnt(c);

    int ai = 0, bi = 0, ci = 0;
    while (ai < n) {
        if (bi < b.size() && (ci == c.size() || b[bi] <= c[ci])) {
            a[ai++] = b[bi++];
        }
        else {
            cnt += n / 2 - bi;
            a[ai++] = c[ci++];
        }
    }
    return cnt;
}

int main() {
    ll n;
    cin >> n;
    ll k;
    cin >> k;
    vector<pair<ll,ll>> z(n);
    for (int i = 0; i < k; i++) {
        cin >> z[i].first >> z[i].second;
    }
    vector<ll> dp(n);
    dp[0] = 1;
    ll f = 0;
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < k; j++) {
            if(i - z[j].first>=0)f += dp[i - z[j].first];
            if(i - z[j].second - 1>=0)f -= dp[i - z[j].second - 1];
            f += 998244353;
        }
        dp[i] = f;
        f %= 998244353;
        dp[i] %= 998244353;
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 7960
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define pb push_back
#define mp make_pair
#define ii pair<int,int>
#define vi vector<int>
#define iii pair<int,pair<int,int>>
#define INF 1<<30

using namespace std;
ll getd(ll x, ll y)
{
	if(x>y)
		return x-y;
	else
		return y-x;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	ll A[n];
	ll sum = 0;
	cin>>A[0];
	sum+=(getd(0,A[0]));
	for (int i = 1; i < n; ++i)
	{
		cin>>A[i];
		sum+=(getd(A[i],A[i-1]));
	}
	sum+=(getd(0,A[n-1]));
	ll p[n];
	p[0] = getd(0,A[1])-getd(0,A[0])-getd(A[0],A[1]);
	for (int i = 1; i < (n-1); ++i)
	{
		p[i] = getd(A[i-1],A[i+1])-getd(A[i-1],A[i])-getd(A[i],A[i+1]);
	}
	p[n-1] = getd(A[n-2],0)-getd(A[n-2],A[n-1])-getd(0,A[n-1]);
	for (int i = 0; i < n; ++i)
	{
		cout<<(sum+p[i])<<"\n";
	}
}

Measured memory_bytes: 2816
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
x,y = LI()  # 高橋君、青木君の得票数
for i in range(1,N):
    T,A = LI()
    a = max((x+T-1)//T,(y+A-1)//A)
    x,y = T*a,A*a

print(x+y)

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

int main() {
    ll mod = 998244353;
    string S;
    cin >> S;
    int N = S.size();
    int K;
    cin >> K;
    if (count(S.begin(), S.end(), '0') == 0 || count(S.begin(), S.end(), '1') == 0) {
        cout << 1 << endl;
        return 0;
    }
    
    vector<ll> A;
    ll cnt = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == '0') {
            A.push_back(cnt);
            cnt = 0;
        }
        else cnt++;
    }
    A.push_back(cnt);
    ll M = A.size();
    vector<ll> Asum(M);
    Asum[0] = A[0];
    for (int i = 1; i < M; i++) Asum[i] = Asum[i-1]+A[i];
    
    
    vector<vector<ll>> from(N+1, vector<ll>(N+1, 0));
    from[0][0] = 1;
    for (int i = 0; i < M; i++) {
        vector<vector<ll>> to(N+1, vector<ll>(N+1, 0));
        vector<vector<ll>> nanamesum(N+2, vector<ll>(N+2, 0));
        for (int j = 0; j <= N; j++) {
            for (int k = 0; k <= N; k++) {
                if (j >= 1 && k >= 1) nanamesum[j][k] = (nanamesum[j-1][k-1] + from[j][k])%mod;
                else nanamesum[j][k] = from[j][k];
                //cout << i << j << k << " " << nanamesum[j][k] << endl;
            }
        }
        
        for (int k = 0; k <= N; k++) {
            to[N][k] = nanamesum[N][k];
            ll sum = 0;
            if (A[i] > 0) sum = from[N][k];
            for (int j = N-1; j >= 0; j--) {
                to[j][k] = (nanamesum[j][k] + sum)%mod;
                sum += from[j][k];
                if (j+A[i] <= N) {
                    sum -= from[j+A[i]][k];
                    if (sum < 0) sum += mod;
                }
                //cout << i << j << k << " " << to[j][k] << endl;
            }
        }
        swap(from, to);
    }
    
    ll ans = 0;
    for (ll i = 0; i <= min(N, K); i++) ans += from[0][i];
    cout << ans%mod << endl;
    return 0;
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
#define ll long long 
#define m 1000000007
using namespace std;
ll dp[401][401];
ll p[401];
ll umin(ll a,ll b)
{
  if(a<b)
    return a;return b;
}
int main(int argc, char const *argv[])
{
  ll n;cin >> n;
  ll a[n];for(ll i=0;i<n;i++)
  {
  	cin >> a[i];
  	if(i==0)p[i]=a[i];
  	else p[i]=p[i-1]+a[i];
  	//cout << p[i] << " ";
  }
//cout << "\n"; 
  for(ll i=n-1;i>=0;i--)
  {
  	for(ll j=i;j<=n-1;j++)
  	{
  		if(i==j)dp[i][i]=0;
  		else
  		{
  			dp[i][j]=1e16;
  			for(ll k=i;k<=j-1;k++)
  			{	
  			ll dum = dp[i][k]+dp[k+1][j];
  			if(i==0)
  				dum+=p[j];
  			else
  				dum+=p[j]-p[i-1];
  			if(dp[i][j]>dum)
  				dp[i][j]=dum;
  			}
  		}
  	}
  }
  /*for(ll i=0;i<=n-1;i++)
  {
  	for(ll j=0;j<=n-1;j++)
  		cout << dp[i][j] << " ";
  	cout << "\n";
  }*/
  cout << dp[0][n-1];
  return 0;
}

Measured memory_bytes: 1536
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 20:59:07 2020

@author: naoki
"""

N = int(input())
S = str(input())

Dp = [[0 for _ in range(3)] for _ in range(N)]

if S[0] == "R":
    Dp[0][0] = 1
elif S[0] == "G":
    Dp[0][1] = 1
elif S[0] == "B":
    Dp[0][2] = 1

allcount = 0
for j in range(1,N):
    Dp[j][0] = Dp[j-1][0]
    Dp[j][1] = Dp[j-1][1]
    Dp[j][2] = Dp[j-1][2]
    
    if S[j] == "R":
        Dp[j][0] += 1
        allcount += Dp[j-1][1]*Dp[j-1][2]
    elif S[j] == "G":
        Dp[j][1] += 1
        allcount += Dp[j-1][0]*Dp[j-1][2]
    elif S[j] == "B":
        Dp[j][2] += 1
        allcount += Dp[j-1][0]*Dp[j-1][1]
    
for j in range(1,N):
    for i in range(1,j):
        if j -i -i >= 0:
            if S[j-i] != S[j-2*i] and S[j-i] !=S[j] and S[j-2*i] !=S[j]:
                allcount -= 1
                pass
print(allcount)

Measured memory_bytes: 74728
def main():
    str = input()
    YY = []
    MM = []
    YYMM_flg = False
    MMYY_flg = False
    AMB_flg = False
    NA_flg = False

    for i in range(2):
    	YY.append(str[i])

    for i in range(2, 4):
    	MM.append(str[i])

    yy = int(''.join(YY))
    mm = int(''.join(MM))

    if (yy >= 1 and yy <= 12) and (mm >= 1 and mm <= 12):
    	AMB_flg = True
    elif (mm >= 1 and mm <= 12) and (yy != 0 or mm != 0):
    	YYMM_flg = True
    elif (yy >= 1 and yy <= 12) and (yy != 0 or mm != 0):
    	MMYY_flg = True
    else:
    	NA_flg = True

    if AMB_flg:
    	print("AMBIGUOUS")
    elif YYMM_flg:
    	print("YYMM")
    elif MMYY_flg:
    	print("MMYY")
    elif NA_flg:
    	print("NA")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a = "";
    int N, L;
    cin >> N >> L;
    vector<string> s(N);
    vector<char> c(N);
    for(int i=0;i<N; i++){
        cin >> s[i];
    }
    sort(s.begin(), s.end());
    for(int i = 0; i < N; i++){
        cout << s[i];
    }
    cout << endl;
    return 0;
}


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

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=0;i<N;i++){
    cin >> A[i];
  }
  int ans=A[0];
  for (int i=1;i<N;i++){
    ans=gcd(ans,A[i]);
  }
  cout << ans << endl;
}

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

int main(){
  int n;cin >> n;
  int h[n];rep(i,n)cin >> h[i];
  int dp[n+1];
  dp[0] = 0;
  dp[1] = abs(h[1]-h[0]);
  for(int i=2;i<n;++i){
    dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]),dp[i-2] + abs(h[i]-h[i-2]));
  }
  cout << dp[n-1] << endl;
  return 0;
}

Measured memory_bytes: 1024
K,A,B = map(int,input().split())

ans = 1
cnt = 0

if A + 1 < B and K >= A+1:
    cnt += A + 1
    ans = B
else:
    print(ans + K)
    exit()

if ans >= B:
    k = int((K-cnt) / 2)
    ans += k * (B - A)
    c = int((K-cnt) % 2)
    print(ans+c)
else:
    print(ans + K)


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

#define PI 3.141592653589793238462643383279
typedef long long ll;
const long double EPS = 1e-9;
const ll MOD = 1e9+7;
#define N 100100
int x[N];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << setprecision(20);
    #ifdef LOCAL_TEST
    freopen("input.txt","r",stdin);
    #endif
    int n, m; cin >> n >> m;
    for(int i=0;i<m;i++) cin >> x[i];
    sort(x, x + m);
    multiset<int> st;
    for(int i=1;i<m;i++) st.insert(x[i-1] - x[i]);
    while(!st.empty() && n-- > 1) st.erase(st.begin());
    int ans = 0;
    for(int i : st) ans -= i;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 5376
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
char a[6];
int main(){
	cin>>a;
	for(int i=0;i<strlen(a);i++){
		if(a[i]=='A'&&a[i+1]=='C'){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		String S = sc.next();
		String[] SArray = S.split("");
		if(SArray[0].equals(SArray[1])&&SArray[0].equals(SArray[2])&&SArray[0].equals(SArray[3])) {
			System.out.println("No");
			}else if(SArray[0].equals(SArray[1])) {
			if(SArray[2].equals(SArray[3])){
				System.out.println("Yes");
			}else{
              System.out.println("No");
            }
		}else if(SArray[0].equals(SArray[2])) {
			if(SArray[1].equals(SArray[3])){
				System.out.println("Yes");
			}else{
              System.out.println("No");
            }
		}else if(SArray[0].equals(SArray[3])) {
			if(SArray[1].equals(SArray[2])) {
			System.out.println("Yes");
			}else{
              System.out.println("No");
            }
		}else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 21844
# abc155_a.py
# https://atcoder.jp/contests/abc155/tasks/abc155_a

# A - Poor /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点: 100点

# 問題文
# 3つ組の数について、ある 2 つが等しく、残りの 1 つがそれらと異なるとき、その 3つ組を「かわいそう」であるといいます。
# 3つの整数 A,B,C が与えられるので、この 3つ組がかわいそうであれば Yes を、そうでなければ No を出力してください。

# 制約
#     A,B,Cはいずれも 1 以上 9以下の整数

# 入力
# 入力は以下の形式で標準入力から与えられる。
# A B C

# 出力
# 与えられる 3つ組がかわいそうであれば Yes を、そうでなければ No を出力せよ。

# 入力例 1
# 5 7 5

# 出力例 1
# Yes

# Aと C が等しく、B がそれらと異なるので、この 3つ組はかわいそうです。

# 入力例 2
# 4 4 4

# 出力例 2
# No

# A,B,Cがいずれも等しいので、この 3つ組はかわいそうではありません。

# 入力例 3
# 4 9 6

# 出力例 3
# No

# 入力例 4
# 3 3 4

# 出力例 4
# Yes


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    # N = int(lines[0])
    A, B, C = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    if max(A, B, C) == min(A, B, C):
        result = 'No'
    elif (A-B)*(B-C)*(C-A) != 0:
        result = 'No'
    else:
        result = 'Yes'

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['5 7 5']
        lines_export = ['Yes']
    if pattern == 2:
        lines_input = ['4 4 4']
        lines_export = ['No']
    if pattern == 3:
        lines_input = ['4 9 6']
        lines_export = ['No']
    if pattern == 4:
        lines_input = ['3 3 4']
        lines_export = ['Yes']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9200
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)

ll A[110100];
ll ASUM[110100];
ll X[110100];
int main(){
    int N;
    cin >> N;
    REP(i,N){
        ll a;
        cin >> a;
        A[i] = a;
    }
    sort(A,A+N);
    ASUM[0] = A[0];
    FOR(i,1,N){
        ASUM[i] = ASUM[i-1] + A[i];
    }

    ll thres = ceil((double)A[N-1]/2);
    ll* p = A+N-1;
    while(1){
        //cout << thres << endl;
        ll* pp = lower_bound(A, A+N, thres);
        if(p == pp) break;
        p = pp;
        //cout << *pp << endl;
        thres = ceil((double)*pp/2);
    }
    //cout << thres << endl;

    REP(i,N){
        int num = upper_bound(A,A+N,A[i]*2) - A;
        X[i] = ASUM[num-1];
    }

    //REP(i,N){
    //    cout << X[i] << endl;
    //}

    ll ans = 0;
    REP(i,N){
        ll x = X[i];
        if(x >= thres) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
import math
a,b = map(int, input().split())

def gcm(a, b):
    if a == 0 or b == 0:
        return max(a,b)
    elif a == b:
        return a
    else:
        a2,b2 = min(a,b), max(a,b)
        return gcm(b2 % a2, a2)

g = gcm(a,b)

cnt = 1
while g > 1:
    for i in range(2, int(math.sqrt(g))+1):
        if g % i == 0:
            while g % i == 0:
                g = g // i
            
            cnt += 1
            break
    else:
        g = 1
        
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int monsterHealth = scanner.nextInt();
        int n = scanner.nextInt();
        int totalSum = 0;
        for (int i = 0; i < n; i++) totalSum += scanner.nextInt();
        if (monsterHealth <= totalSum) System.out.println("Yes");
        else System.out.println("No");
    }
}


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

long long cal(int x)
{
    long long ans = 1,y = 2;
    while(x)
    {
        if(x%2)ans*=y;
        y*=y;
        x/=2;
    }
    return ans;
}

int main()
{
    int n,p;
    int a[100];
    cin>>n>>p;
    int x=0,y=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%2)x++;
        else y++;
    }

    long long ans = 0;
    ans = cal(y)*(cal(x)/2ll);
    if(p==0&&x==0)ans = cal(y);
    cout<<ans<<endl;

    return 0;
}

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

using namespace std;

int main() {
  int X;
  cin >> X;
  int ans = 0;
  for (int i = 1; i <= X; ++i) {
    int sum = (i * (i + 1)) / 2;
    if (sum >= X) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}



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

typedef long long ll;
#define MOD 1000000007

int main()
{
    int N;
    cin >> N;
    vector<int> v;
    ll sum = 0;
    for (int i = 0; i < N; ++i)
    {
        ll temp;
        cin >> temp;
        sum += temp;
        v.push_back(temp);
    }
    cout << sum - N << endl;
}


Measured memory_bytes: 3660
S=str(input())
N=len(S)
ans=0
if N==1:
    if S=='R' or S=='D' or S=='U':
        print('Yes')
    else:
        print('No')
else:
    for i in range(0,N-1):
        if i%2 ==1:
            if S[i]=='R':
                ans=1
                break
            
        else:
            if S[i]=='L':
                ans=1
                break

        
    if ans==1:
        print('No')
    else :
        print('Yes')

Measured memory_bytes: 3064
# 最初のK泊までは、1泊あたりX円
# K+1泊目以降は、1泊あたりY円
# N泊したときの宿泊費

N = int(input())
K = int(input())
X = int(input())
Y = int(input())

if N <= K:
    print(X * N)
else:
    print(X * K + Y * (N - K))

Measured memory_bytes: 9100
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>

using namespace std;

int digit_sum(int a) {
	int b;
	b = 0;
	while (a > 0) {
		b = b + a % 10;
		a = a / 10;
	}
	return b;
}

int main(void){
	int N;
	int ans;
	int c;
	ans = 1000000;
	scanf("%d", &N);

	for (int i = 1; i < N; i++) {
		c = digit_sum(i) + digit_sum(N - i);
		if (c < ans) {
			ans = c;
		}
	}

	printf("%d\n", ans);
}









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

// マクロ //
#define rep(v,times) for(int v = 0; v < (int)(times); v++)
#define req(v,first,endplus1) for(int v = first; v < (int)(endplus1); v++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vpii = vector<pii>;
using plili = pair<lint, lint>;
using vplili = vector<plili>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvli = vector<vli>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vvs = vector<vs>;
using mii = map<int, int>;
using mili = map<int, lint>;
using mci = map<char, int>;
using mcli = map<char, lint>;
using msi = map<string, int>;
using msli = map<string, lint>;


// 関数 //
template<class T, class Q> lint gcd_(T a, Q b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T, class Q> lint lcm_(T a, Q b) {
    return a * b / gcd_(a, b);
}

template<class T, class Q> double distance(T a, Q b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

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

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

// 定数 //
const double pi = acos(-1);
const int mod = 1000000007;
const int inf = 1045141919;
const lint linf = ((1LL << 62) - 1);
const int dx4[4] = { 1,0,-1,0 };
const int dy4[4] = { 0,1,0,-1 };
const int dx8[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy8[8] = { 0,1,1,1,0,-1,-1,-1 };

// End of Template //



int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
        
    int H, M, h, m, K;
    cin >> H >> M >> h >> m >> K;
    cout << (h - H) * 60 + (m - M) - K << endl;




}

Measured memory_bytes: 3652
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
m = 0
for i in A:
  m += i
  if m > K:
    break
  ans += 1

C = [0] * N
C[0] = A[0]
for i in range(1, N):
  C[i] = C[i - 1] + A[i]

D = [0] * M
D[0] = B[0]
for i in range(1, M):
  D[i] = D[i - 1] + B[i]

if ans == 0:
  t = 0
else:
  t = C[ans - 1]

k = ans
n = ans
for i in range(M):
  m = D[i]
  if m > K: break
  while m + t > K:
    n -= 1
    if n <= 0:
      t = 0
      break
    t = C[n - 1]
  ans = max(ans, i + 1 + n)

print(ans)
   


Measured memory_bytes: 118172
/* 	* In the name of GOD 
	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

int32_t main(){
	int n;
	cin >> n;
	vector <pair <int, int>> v[n];
	for (int i = 0; i < n; i++){
		int x;
		cin >> x;
		for (int j = 0; j < x; j++){
			int a, b;
			cin >> a >> b;
			v[i].push_back({a - 1, b});
		}
	}
	int mx = 0;
	int po = pow(2, n);
	int a[n];
	for (int i = 0; i < po; i++){
		int x = i, an = 0;
		for (int j = 0; j < n; j++){
			a[j] = x % 2;
			if (x % 2)
				an++;
			x /= 2;
		}
		bool f = true;
		for (int j = 0; j < n; j++){
			for (int k = 0; k < v[j].size(); k++){
				if (a[j] == 1){
					if (a[v[j][k].F] != v[j][k].S){
						f = false;
					}
				}
			}
		}
		if (f){
			mx = max(mx, an);
		}
	}
	cout << mx;
}


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

int main() {
    int N;
    cin >> N;
    long long A[N+1];
    long long B[N];

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

    long long num = 0;

    // A[i], B[i]を受けてA[i+1]の値を変える。そして次のA[i+1]，B[i+1]の組で
    // 再び繰り返す。

    for (int i = 0; i < N; i++) {
        num += min(A[i], B[i]);
        B[i] -= min(A[i], B[i]);
        num += min(A[i+1], B[i]);
        A[i+1] -= min(A[i+1], B[i]);
    }

    cout << num << endl;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll n, k;
    cin >> n >> k;
    vl a(n), b(n);
    ll tot = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        b[i] = max(0ll, a[i]);
        tot += b[i];
    }
    // if (n == 1) {
    //     cout << max(0LL, a[0]) << "\n";
    //     return 0;
    // }
    vl sum(n, 0), possum(n, 0);
    sum[0]    = a[0];
    possum[0] = b[0];
    for (int i = 1; i < n; ++i) {
        sum[i]    = sum[i - 1] + a[i];
        possum[i] = possum[i - 1] + b[i];
    }
    ll ret = -INF;
    for (int i = 0; i <= n - k; ++i) {
        ll temp = tot;
        temp += sum[i + k - 1];
        temp -= possum[i + k - 1];
        if (i != 0) {
            temp -= sum[i - 1];
            temp += possum[i - 1];
        }
        chmax(ret, temp);

        temp -= sum[i + k - 1];
        if (i != 0) {
            temp += sum[i - 1];
        }
        chmax(ret, temp);
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  ll n,m,a,s[100010]={},c=0,d=1,ans=0;
  cin>>n>>m;
  Fr(i,n){cin>>a;s[i]=s[i-1]+a;s[i]%=m;}
  sort(s,s+n+1);
  Fr(i,n){
    if(c!=s[i]){
      c=s[i];
      ans+=(d*(d-1))/2;
      d=0;
    }
    d++;
  }
  ans+=(d*(d-1))/2;
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
import java.io.*;

public class Main {
    public static void main(String[] arg){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String str1 = "abcdefghijklmnopqrstuvwxyz";
        String str2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        try{
            String x;
            x =reader.readLine();
            while(x != null){
                for(int i = 0; i<x.length(); i++){
                    char a = x.charAt(i);
                    for(int j = 0; j < str1.length(); j++){
                        char b = str1.charAt(j);
                        char c = str2.charAt(j);
                        if(a == b){
                            a = c;
                        }else if(a == c){
                            a = b;
                        }
                    }
                    System.out.print(a);
                }
                System.out.println();
                x = reader.readLine();
            }
        }catch(IOException e){
            System.out.println(e);
        }
    }
}


Measured memory_bytes: 25180
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
#include <numeric>
#include <iomanip>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>

///////////////////////////////////////////////////////////////
// namespace
///////////////////////////////////////////////////////////////
using namespace std;
// namespace mp = boost::multiprecision;

///////////////////////////////////////////////////////////////
// types
///////////////////////////////////////////////////////////////
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
// using mpi = mp::cpp_int;
// using mpf = mp::number<mp::cpp_dec_float<1024>>;

///////////////////////////////////////////////////////////////
// mod https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
///////////////////////////////////////////////////////////////
// ll MOD = 1000000007;
//
//  ll mod(ll val) {
//      ll res = val % MOD;
//      if (res < 0) res += MOD;
//      return res;
//  }
//
// ll modinv(ll a) {
//     ll b = MOD, u = 1, v = 0;
//     while (b) {
//         ll t = a / b;
//         a -= t * b; swap(a, b);
//         u -= t * v; swap(u, v);
//     }
//     u %= MOD;
//     if (u < 0) u += MOD;
//     return u;
// }
//
// const int MAX = -1;
// ll fac[MAX], finv[MAX], inv[MAX];
// void com_init() {  // initialize nCk table with O(N)
//     fac[0] = fac[1] = 1;
//     finv[0] = finv[1] = 1;
//     inv[1] = 1;
//     for (int i = 2; i < MAX; i++){
//         fac[i] = fac[i - 1] * i % MOD;
//         inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
//         finv[i] = finv[i - 1] * inv[i] % MOD;
//     }
// }
// ll com(int n, int k){  // nCk
//     if (n < k) return 0;
//     if (n < 0 || k < 0) return 0;
//     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
// }


int main() {
    int N, M; cin >> N >> M;
    vector<int> H(N, 0);
    vector<int> v(N, 1);
    for (int i = 0; i < N; ++i) cin >> H[i];
    for (int i = 0; i < M; ++i) {
        int A, B; cin >> A >> B; --A; --B;
        if (H[A] <= H[B]) v[A] = 0;
        if (H[B] <= H[A]) v[B] = 0;
    }
    cout << accumulate(v.begin(), v.end(), 0) << endl;
    // cout << setprecision(10);
    return 0;
}


Measured memory_bytes: 4000