akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll INF = 1LL << 60;

ll dp[8];

ll upd(ll& x, ll y) {
  return x = min(x, y);
}

int gs(int a, int b) {
  if (a < 0 || a > 2)
    return -1;
  return a << 1 | b;
}

void load(int a) {
  static ll tmp[8];
  memcpy(tmp, dp, sizeof(dp));
  fill(dp, dp + 8, INF);
  if (a) {
    dp[6] = tmp[6] + a;
    dp[7] = tmp[7] + a;
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < 2; ++j) {
        int u = gs(i, j);
        for (int t = 0; t < 2; ++t) {
          int inc = (j ^ t ^ a) & 1;
          int v = gs(i + inc, (t ^ a) & 1);
          if (v != -1)
            upd(dp[v], tmp[u] + t);
        }
      }
    }
    upd(dp[6], dp[3]);
  } else {
    dp[6] = tmp[6];
    dp[7] = tmp[7];
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < 2; ++j) {
        int u = gs(i, j);
        for (int t = 1; t <= 2; ++t) {
          int inc = (j ^ t) & 1;
          int v = gs(i + inc, t & 1);
          if (v != -1)
            upd(dp[v], tmp[u] + t);
        }
      }
    }
  }
  upd(dp[0], dp[7]);
  upd(dp[6], dp[0]);
  upd(dp[6], dp[4]);
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  int n;
  scanf("%d", &n);
  for (int i = 1; i <= 5; ++i)
    dp[i] = INF;
  while (n--) {
    int a;
    scanf("%d", &a);
    load(a);
  }
  load(0);
  printf("%lld\n", dp[6]);

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
typedef long long LL;
typedef unsigned long long LONG;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int MAXINT = 2147483647;
const int mod = 1000000007;
const long long MAXLONG = 9223372036854775807;
const LL INT32 = (LL(MAXINT) + 1) * 2;
using namespace std;
typedef pair<int, int> PII;
#define ft fisrt
#define sd second
#define eb emplace_back
#define END '\n'
 
template<class T>
inline bool Read(T &ret) {
    char c;
    int sgn;
    if (static_cast<void>(c = getchar()), c == EOF) return 0;
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (static_cast<void>(c = getchar()), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}
 
template<class T>
inline void Write(T x) {
    if (x < 0) putchar('-'), Write(x);
    if (x > 9) Write(x / 10);
    putchar(x % 10 + '0');
}
 
int main() {
    int n, x, y;
    cin >> n >> x >> y;
    int ans[N] = {0};
    for (int i = 1; i < n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            {
                int dis = j - i;
                if (dis >= (abs(i - x) + abs(j - y)) + 1)
                    dis = abs(i - x) + abs(j - y) + 1;
                if (dis >= (abs(i - y)) + abs(j - x) + 1)
                    dis = abs(i - y) + abs(j - x) + 1;
                ans[dis]++;
            }
        }
    }
    for (int i = 1; i < n; ++i) {
        cout << ans[i] << END;
    }
    return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
struct node
{
	int x,y,next;
}a[200010];int len,last[100010];
inline void ins(int x,int y)
{
	len++;
	a[len].x=x;a[len].y=y;
	a[len].next=last[x];last[x]=len;
}
int fa[100010],f[100010],dep[100010];
inline void dfs(int x)
{
	for(int k=last[x];k;k=a[k].next)
	{
		int y=a[k].y;
		if(y==fa[x])continue;
		fa[y]=x,dep[y]=dep[x]+1;
		dfs(y);
		f[x]=max(f[x],f[y]+1);
	}
}
int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int n=read(),p=read(),rt=read();
	for(int i=1;i<n;i++)
	{
		int x=read(),y=read();
		ins(x,y),ins(y,x);
	}dfs(rt);
	int uf=(dep[p]-1)/2,ans=0,cnt=0,ul=dep[p];
	while(cnt<=uf)
	{
		ans=max(ans,f[p]+ul-cnt-1);
		cnt++,p=fa[p];
	}pr2(ans);
	return 0;
}


Measured memory_bytes: 6016
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

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

const int maxn = 2e5 + 5;

int n;
string s;

vector<int> vec[26];

int d[maxn], trace[maxn];
int lst;

void read_input()
{
    cin >> s;
    n = sz(s);
    for(int i = 0; i < n; ++i)
        vec[s[i] - 'a'].push_back(i);
    for(int i = 0; i < 26; ++i)
        vec[i].push_back(n);
}

void solve()
{
    for(int i = 0; i < 26; ++i)
    {
        bool ok = true;
        for(int j = 0; j < n; ++j)
            if(s[j] == 'a' + i)
            {
                ok = false;
                break;
            }
        if(ok)
        {
            cout << char('a' + i) << '\n';
            return;
        }
    }
    fill(begin(trace), end(trace), -1);
    fill(begin(d), end(d), -1);
    queue<int> q;
    for(int i = 0; i < 26; ++i)
    {
        d[vec[i].front()] = 1;
        q.push(vec[i].front());
    }
    while(!q.empty())
    {
        int i = q.front(); q.pop();
        for(int j = 0; j < 26; ++j)
        {
            int k = upper_bound(vec[j].begin(), vec[j].end(), i) - vec[j].begin();
            k = vec[j][k];
            if(d[k] == -1)
            {
                d[k] = d[i] + 1;
                trace[k] = i;
                if(k == n)
                {
                    lst = j;
                    break;
                }
                q.push(k);
            }
        }
        if(d[n] != -1) break;
    }
    vector<char> ans;
    ans.push_back('a' + lst);
    int cur = trace[n];
    while(cur >= 0)
    {
        ans.push_back(s[cur]);
        cur = trace[cur];
    }
    reverse(ans.begin(), ans.end());
    for(auto&c: ans)
        cout << c;
    cout << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}



Measured memory_bytes: 6056
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit
#include <cstdio>	// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int s[105];
int b[105][105];
int sum[105];
int main()
{
//	cut here before submit 
//	freopen ("testcase.vn", "r", stdin );
	int n, k;
	while (cin >> n >> k && n && k ){
		memset (s, 0, sizeof (s ) );
		memset (b, 0, sizeof (b ) );
		memset (sum, 0, sizeof (sum ) );
		rep (i, k ){
			cin >> s[i];
		} // end rep
		rep (i, n ) rep (j, k ){
			cin >> b[i][j];
		} // end rep

		bool ok = true;
		rep (j, k ){
			rep (i, n ) sum[j] += b[i][j];
			if (sum[j] > s[j] ){
				ok = false;
				break;
			} // end if 
		} // end rep
 		
		if (ok ){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		} // end if	
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
// written by : soumya_27
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ld long double
#define mod ((int)1e9+7)
#define maxx ((int)2e6+6)
#define pb push_back
#define ins insert
#define F first
#define S second
#define ins insert
#define pii pair <int , int>
#define lb lower_bound
#define ub upper_bound
#define usefile freopen("input.txt","r",stdin); freopen("ou(tp)ut.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test int t; cin >> t; while(t--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
int exp(int x,int y,int p){ int res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
int expo(int x,int y){ int res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
int add(int a, int b) {return (a%mod + b%mod + mod)%mod;}
int sub(int a, int b) {return (a%mod - b%mod + mod)%mod;}
int mul(int a, int b) {return ((a%mod)*(b%mod) + mod)%mod;}
int inv(int x) {return expo(x, mod-2);}
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)     
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
// int sv[2000006]={0};
// int fact[1000006]={0};
// void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000006;i++)fact[i]=(fact[i-1]*i)%mod;}
// void sve() {sv[0]=1;sv[1]=1;for(int i=2;i*i<maxx;i++){if(!sv[i]){for(int j=i*i;j<maxx;j+=i)sv[j]=1;}}}//0 hai to prime
// int ncr(int n,int r) {int res=1; res=fact[n]; res=(res*(expo(fact[r],mod-2)))%mod; res=(res*(expo(fact[n-r],mod-2)))%mod; return res;}
// int npr(int n,int r) {int res=1; res=fact[n]; res=(res*(expo(fact[n-r],mod-2)))%mod; return res;}
// using namespace __gnu_pbds;
// #define p_set tree< pair<int,int> ,  null_type ,  less<pair<int,int>> ,  rb_tree_tag ,  tree_order_statistics_node_update>
// #define i_set tree< int ,  null_type ,  less< int > ,  rb_tree_tag ,  tree_order_statistics_node_update>
using namespace std;
#define N 405
#define inf 1e18
int d[N][N];
void solve()
{
    fast
    // test
    {
        cout << setprecision(10);
        int n, m, i, j, k, x, y, q;
        cin >> n;
        int a[n];
        for(i=0 ; i<n ; i++)
            cin >> a[i];
        int p[n] = {0};
        p[0] = a[0];
        for(i=1 ; i<n ; i++)
            p[i] = p[i-1] + a[i];
        for(i=0 ; i<n ; i++)
            for(j=0 ; j<n ; j++)
            {
                if(i != j)
                    d[i][j] = inf;
            }
        for(int len = 2 ; len <= n ; len++)
            for(i=0 ; i<n-len+1 ; i++)
            {
                j = i+len-1;
                for(k=i ; k<j ; k++)
                {
                    int val = d[i][k] + d[k+1][j] + p[j];
                    if(i>0)
                        val -= p[i-1];
                    d[i][j] = min(d[i][j] , val);
                }
            }
        cout << d[0][n-1] << "\n";
    }
}

signed main()
{
    // time__("solve")
    {
        solve();
        
    }
    return 0;
}

Measured memory_bytes: 1536
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cmath>

using namespace std;

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


Measured memory_bytes: 3592
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG abc/abc075/c.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int MAX_N;
int M;
vector<int> parent;// それぞれのnodeのparent，main内でresize必要
vector<int> tree_rank;// それぞれのnodeの属する木のtree_rank

void init(int n){// 初期化．全てのnodeで親を自分自身に，tree_rankを0にする．nもらわなくてもv.size()でいける
    rep(i, n){
        parent[i] = i;
        tree_rank[i] = 0;
    }
}

int root(int x){// node xのrootを返す．parent[x] = root(parent[x])で親をrootにつなぎ替える
    return x == parent[x] ? x : parent[x] = root(parent[x]);
}

bool same(int x, int y){// 同じ木に属するかどうか判定する
    return root(x) == root(y);
}

void unite(int x, int y){// xの属する木とyの属する木を連結する．rankができるだけ低くなるように処理を行う
    x = root(x);
    y = root(y);

    if(tree_rank[x] < tree_rank[y]){
        parent[x] = y;
    }else{
        parent[y] = x;
        if(tree_rank[x] == tree_rank[y]) tree_rank[x]++;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    cin >> MAX_N >> M;
    tree_rank.resize(MAX_N);
    parent.resize(MAX_N);
    int buf[M][2];
    rep(i, M){
        cin >> buf[i][0] >> buf[i][1];
        buf[i][0]--;
        buf[i][1]--;
    }

    int ans = 0;
    rep(i, M){
        init(MAX_N);
        rep(j, M){
            if(i == j) continue;
            unite(buf[j][0], buf[j][1]);
        }
        int a = root(0);
        int flag = 0;
        rep(j, MAX_N){
            if(a != root(j)){
                flag = 1;
                break;
            }
        }
        if(flag == 0){
            ans++;
        }
    }

    cout << M - ans << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <sstream>
#include <string>
using namespace std;
string IntToString(int number)
{
  stringstream ss;
  ss << number;
  return ss.str();
}
int mcxi2int(string s){
  int res=0;
  int i,tmp;
  tmp=1;
  for(i=0;i<s.length();i++){
    if(s[i]-'0'<10&&s[i]-'0'>0){
      tmp=s[i]-'0';
    }
    else{
      if(s[i]=='m') res+=tmp*1000;
      if(s[i]=='c') res+=tmp*100;
      if(s[i]=='x') res+=tmp*10;
      if(s[i]=='i') res+=tmp;
      tmp=1;
    }
  }
  return res;
}
string int2mcxi(int n){
  string s;
  if(n/1000){
    if(n/1000==1) s="m";
    else s=IntToString(n/1000)+"m";
    n-=1000*(n/1000);
  }
  if(n/100){
    if(n/100==1) s+="c";
    else s+=IntToString(n/100)+"c";
    n-=100*(n/100);
  }
  if(n/10){
    if(n/10==1) s+="x";
    else s+=IntToString(n/10)+"x";
    n-=10*(n/10);
  }
  if(n){
    if(n==1) s+="i";
    else s+=IntToString(n)+"i";
  }
  return s;
}
int main(void){
  int n,i;
  string a,b;
  cin>>n;
  
  for(i=0;i<n;i++){
    cin>>a>>b;
    cout<<int2mcxi(mcxi2int(a)+mcxi2int(b))<<endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 3092
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//ここまでテンプレ
int main(){
	int N,D,X;
	cin>>N>>D>>X;
	for(int i=0;i<N;i++){
		int A;
		cin>>A;
		for(int j=1;j<=D;j+=A)
			X++;
	}
	cout<<X<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>

#define int long long

const int MAXW = 100001;
const int MAXN = 100;

int dp[MAXN][MAXW];
int w[MAXN];
int v[MAXN];

int32_t main()
{
    int n, c;
    scanf("%lld%lld", &n, &c);

    for (int i = 0; i < n; ++i)
        scanf("%lld%lld", &w[i], &v[i]);

    for (int j = w[0]; j <= c; ++j)
        dp[0][j] = v[0];

    for (int i = 1; i < n; ++i)
    {
        for (int j = 0; j <= c; ++j)
        {
            dp[i][j] = std::max(dp[i - 1][j], dp[i][j - 1]);
            if (j >= w[i])
                dp[i][j] = std::max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
        }
    }

    printf("%lld\n", dp[n - 1][c]);
    return 0;
}


Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  double n;
  while (cin >> n, n >= 0.0) {
    if (n >= (1 << 8)) {
      cout << "NA" << endl;
      continue;
    }
    bitset<8> bit((int)n);
    n -= (int)n;
    string s = "";
    for (int i = 0; i < 4; i++) {
      n *= 2;
      s += (n >= 1.0) + '0';
      n -= (int)n;
    }
    if (n) {
      cout << "NA" << endl;
      continue;
    }
    cout << bit << "." << s << endl;
  }

  return 0;
}


Measured memory_bytes: 3100
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: x[1], reverse=True)

c = 0
for i, j in b:
    for k in range(c, i + c):
        if k == n:
            break
        if a[k] < j:
            a[k] = j
            c += 1
        else:
            break
print(sum(a))

Measured memory_bytes: 33640
#include <iostream>
#define mod 1000000007
using namespace std;
typedef long long ll;

ll mod_pow(ll x,ll y){
  ll res=1;
  for(int i=0;i<60;i++){
    if(y&(1LL<<i)) res=res*x%mod;
    x=x*x%mod;
  }
  return res;
}

int main(){
  ll m,n;
  cin>>m>>n;
  cout << mod_pow(m,n)<<endl;
  return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <algorithm>
#include <numeric>
#include <set>
int count_digit(const int value) {
	return value < 10 ? 1 : 1 + count_digit(value / 10);
}
bool is_match(const int value, const std::vector<int>& digit) {
	if (count_digit(value) != digit.size()) return false;
	int v = value;
	for (int i = digit.size() - 1; i >= 0; --i) {
		if (digit[i] != -1 && digit[i] != v % 10) {
			return false;
		}
		v /= 10;
	}
	return true;
}
int main() {
	int n, m; std::cin >> n >> m;
	bool can_make = true;
	std::vector<int> digit(n, -1);
	for (auto i = 0; i < m; ++i) {
		int s, c; std::cin >> s >> c; --s;
		if (digit[s] != -1 && digit[s] != c) {
			can_make = false;
		}
		digit[s] = c;
	}
	if (!can_make) {
		std::cout << "-1\n";
	}
	else {
		bool show = false;
		for (auto i = 0; i < 10000; ++i) {
			if (is_match(i, digit)) {
				std::cout << i << std::endl;
				show = true;
				break;
			}
		}
		if (!show) {
			std::cout << "-1\n";
		}
	}
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define fo(nn) for(int ii = 0; ii < nn; ii++)

int main(){
	int n, m, D, P;
	
	while(1){
		int p[20] = {}, ans = 0;
		cin>>n>>m;
		
		if(n == 0 && m == 0) break;
		
		fo(n){
			cin>>D>>P;
			p[P] += D;
		}
		
		for(int i = 10; i; i--){//cout<<ans<<" A "<<i<<" "<<p[i]<<" "<<m<<endl;
			if(m >= p[i]){
				m -= p[i];
			} else if(m == 0){
				ans += p[i] * i;
			} else {//cout<<ans<<" "<<p[i]<<" "<<m<<" "<<i<<endl;
				ans += (p[i] - m) * i;
				m = 0;
			}//cout<<ans<<" "<<i<<" "<<p[i]<<" "<<m<<endl;
		}
		cout<<ans<<endl;
	}

	return 0;
}



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

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long x;
	cin >> x;
	long long p = 100, n = 0;
	while(p < x)
	{
		p += p/100;
		n++;
	}
	cout << n << "\n";
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll long long int
#define inf 1000000000000
#define MOD 1000000007
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define for0(i, n) for (int i = 0; i < n; i++)
#define tc(t) int t; cin >> t; while (t--)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define ps(x,y)         fixed<<setprecision(y)<<x
using namespace std;
ll dp[101][100001];
pll item[100005];
ll knapsack_1( int cap, int n)
{
	if (n == 0 || cap == 0)
		return 0;
	if (dp[n - 1][cap] != -1)
		return dp[n - 1][cap];
	if (item[n - 1].fi > cap)
		return knapsack_1(cap, n - 1);
	else return dp[n - 1][cap] = max(item[n - 1].se + knapsack_1(cap - item[n - 1].fi, n - 1), knapsack_1(cap, n - 1));
}
int main()
{
	IOS
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
	int n, cap;
	cin >> n >> cap;
	for (int i = 0; i < 101; i++)
	{
		for (int j = 0; j < 100001; j++)
		{
			dp[i][j] = -1;
		}
	}
	for (int i = 0; i < n; i++)
	{
		cin >> item[i].fi >> item[i].se;
	}
	ll res = knapsack_1(cap, n);
	cout << res << endl;
}

Measured memory_bytes: 79232
'use strict';

function main(stdin) {
  const input = stdin.split(' ').map(v => parseInt(v, 10));
  const N = input[0];

  const max = Math.ceil(Math.sqrt(N));
  let ans = 0;

  for (let i = 1; i <= max; ++i) {
    if (N % i == 0) ans = N / i + i - 2;
  }

  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim());

Measured memory_bytes: 21192
package main

import (
	"fmt"
	"strings"
)

func moveWhite(s []string) int {
	ans := 0
	whiNext := 0
	for i := 0; i < len(s); i++ {
		if s[i] == "W" {
			ans += i - whiNext
			whiNext++
		}
	}
	return ans
}
func main() {
	var n string
	fmt.Scan(&n)
	str := strings.Split(n, "")

	ans := moveWhite(str)
	fmt.Println(ans)
}


Measured memory_bytes: 5248
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	cin >> N;
	cout << 800 * N - 200 * (N / 15) << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        int c0 = 0;
        int c1 = 0;
        for(int i = 0;i < s.length();i++){
            if(s.charAt(i) == '1'){
                c1++;
            } else {
                c0++;
            }
        }

        System.out.println(Math.min(c0,c1) * 2);
        }
    }

Measured memory_bytes: 24100
from collections import Counter
import itertools
n=int(input())
rgb=list(input())
rgb_counter=Counter(rgb)
n_list=[i for i in range(1,n+1)]
count=0
for i,j in itertools.combinations(n_list,2):
    k=2*j-i
    if k<=n and rgb[j-1]!=rgb[i-1] and rgb[j-1]!=rgb[k-1] and rgb[i-1]!=rgb[k-1]:
        count+=1
print(rgb_counter["R"]*rgb_counter["G"]*rgb_counter["B"]-count)


Measured memory_bytes: 68692
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

int main() {
    const int INF = 1000000000;
    
    int N, M;
    cin >> N >> M;
    vector<int> a(M, 0), c(M, 0);
    rep(i, M) {
        int b;
        cin >> a[i] >> b;
        rep(j, b) {
            int x;
            cin >> x;
            --x;
            c[i] += (1 << x);
        }
    }
    vector<vector<int>> dp(M + 1, vector<int>(1 << N, INF));
    dp[0][0] = 0;
    rep(i, M) rep(j, 1 << N) {
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        dp[i + 1][j | c[i]] = min(dp[i + 1][j | c[i]], dp[i][j] + a[i]);
    }
    if (dp[M][(1 << N) - 1] == INF) cout << -1 << "\n";
    else cout << dp[M][(1 << N) - 1] << "\n";
    return 0;
}


Measured memory_bytes: 16256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
cnt = 0
for i in range(N):
    A = list(map(int, input().split()))
    ABsum = 0
    for j in range(M):
        ABsum += A[j]*B[j]
    ABsum += C
    if ABsum > 0:
        cnt += 1

print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s,t,u;
  int a,b;
  cin >> s >> t >> a >> b >> u;
  if(s == u){
    cout << a-1 << " "<< b << endl;
  }
  else{
    cout << a << " "<< b-1 <<endl;
  }
  return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		String str[] = br.readLine().split(" ");

		long a[] = new long[n];

		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(str[i]);
		}

		long sum = 0;
		for (int i = 0; i < n - 1; i++) {
			if (a[i] > a[i + 1]) {
				sum += a[i] - a[i + 1];
				a[i + 1] += a[i] - a[i + 1];
			}
		}

		System.out.println(sum);
	}
}


Measured memory_bytes: 61392
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int dp[20][1000][2];

signed main() {
    int init_val; cin >> init_val;
    string s = to_string(init_val);
    int N = s.length();

    dp[0][0][0] = 1;
    for(int i=0; i<N; i++) {
        for(int k=0; k<1000; k++) {
            for(int f=0; f<2; f++) {
                int lim = f ? 9 : s[i] - '0';
                for(int x=0; x<lim+1; x++) {
                    if(x == 3 && k/10 == 51) continue;
                    dp[i+1][(k*10+x)%1000][f || x < lim] += dp[i][k][f];
                }
            }
        }
    }

    int sum = 0;
    for(int k=0; k<1000; k++) {
        for(int f=0; f<2; f++) {
            sum += dp[N][k][f];
        }
    }

    cout << init_val - sum + 1 << endl;
    return 0;
}


Measured memory_bytes: 3572
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')
const data = stdin
  .trim()
  .split('\n')[1]
  .split(' ')
  .map(n => Number.parseInt(n))

const x = data.map((n, i) => (n === i + 1 ? 0 : 1)).reduce((prev, cur) => prev + cur, 0)

console.log(x === 0 || x === 2 ? 'YES' : 'NO')


Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int n;
    ll x;
    cin >> n >> x;
    vector<ll> X(n + 1), P(n + 1);
    X[0] = 1, P[0] = 1;
    for(int i = 0; i < n; ++i){
        X[i + 1] = X[i] * 2 + 3;
        P[i + 1] = P[i] * 2 + 1;
    }
    ll ans = 0;
    while(n >= 0 && x > 0){
        if(x == X[n]){
            ans += P[n];
            break;
        }
        ll bound = X[n] >> 1;
        if(x <= bound){
            if(x == bound){
                ans += P[n - 1];
                break;
            }
            --x, --n;
        }
        else{
            ans += P[--n] + 1;
            x -= bound + 1;
        }
    }
    cout << ans << endl;
}

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

int main()
{
    int N, g=0, w=0, y=0, p=0;
    cin >> N;
    vector<char> S(N);

    for (int i = 0; i < N; i++)
    {
        cin >> S.at(i);
    }

    for (int i = 0; i < N; i++)
    {
        if(S.at(i)=='W'){
            w++;
        }
        if (S.at(i) == 'G')
        {
            g++;
        }
        if (S.at(i) == 'Y')
        {
            y++;
        }
        if (S.at(i) == 'P')
        {
            p++;
        }
    }
    if(g==0||w==0||y==0||p==0){
        cout << "Three" << endl;
    }
    else
    {
        cout << "Four" << endl;
    }
    

}

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

int	main()
{
	int		num[210];
	int		n, res;
	bool	flg = true;
	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> num[i];
	res = 0;
	while (flg)
	{
		for (int i = 0; i < n; i++)
		{
			if (num[i] % 2 == 1)
			{
				flg = false;
				break ;
			}
			num[i] /= 2;
		}
		if (flg == true)
			res++;
	}
	cout << res << endl;
}


Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def SS(): return map(str,sys.stdin.readline().rstrip().split())
def II(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
s = S()

l = []

for i in range(len(s) - 2):
  l.append(int(s[i:i+3]))

sa = [abs(753 - i) for i in l]
print(min(sa))

Measured memory_bytes: 13000
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int n = sc.nextInt();
        Integer[] p = new Integer[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }
        if (n == 0) {
            System.out.println(x);
            return;
        } else if (!checkForbiddenList(p, x)) {
            System.out.println(x);
            return;
        } else {
            int ans = 0;
            for (int i = 0; i < 100; i++) {
                if (!checkForbiddenList(p, x - i)) {
                    ans = x - i;
                    break;
                } else if (!checkForbiddenList(p, x + i)) {
                    ans = x + i;
                    break;
                }
            }
            System.out.println(ans);
            return;
        }
    }

    private static boolean checkForbiddenList(Integer[] p, int x) {
        return Arrays.asList(p).contains(x);
    }
}

Measured memory_bytes: 35948
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
int main(){
	int a,b;
	int t;
	cin>>a>>b;
	if(b >= 0 && b <= 9) t = a*10+b;
	else if(b == 100) t = a*1000+b;
	else t = a*100+b;
	int flag = 0;
	for(int i = 1; i <= 1000; i++){
		if(i*i == t) flag = 1;
	}
	if(flag) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	char s[3][3];
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>s[i][j];
		}
	}
	cout<<s[0][0]<<s[1][1]<<s[2][2]<<endl;
	return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>

typedef struct _node {
  struct _node *left, *right;
  int key;
} node;

node *root = NULL;

void insert(int key) {
  node *new, **x;

  x = &root;
  while(*x != NULL) {
    if(key < (*x)->key)
      x = &(*x)->left;
    else if(key > (*x)->key)
      x = &(*x)->right;
  }

  new = (node *)malloc(sizeof(node));
  new->left = NULL;
  new->right = NULL;
  new->key = key;
  *x = new;

  return;
}

void inorder(node *current) {
  if(current == NULL)
    return;

  inorder(current->left);
  printf(" %d", current->key);
  inorder(current->right);
}

void preorder(node *current) {
  if(current == NULL)
    return;

  printf(" %d", current->key);
  preorder(current->left);
  preorder(current->right);
}

void print() {
  inorder(root);
  printf("\n");

  preorder(root);
  printf("\n");
}

int main() {
  int i, n, key;
  char command[20];

  scanf("%d", &n);
  for(i = 0;i < n;i++) {
    scanf("%s", command);
    switch(command[0]) {
      case 'i':
        scanf("%d", &key);
        insert(key);
        break;
      case 'p':
        print();
        break;
    }
  }

  return 0;
}



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


int cnt[200005];


int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin>>n;

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

    for(int i=n-1;i>=1;i-=2)
        if(cnt[i] != 2){
            cout<<"0";
            return 0;
        }
    if(n % 2 == 1 && cnt[0] != 1){
        cout<<"0";
        return 0;
    }

    cout<<pwr(2, n/2);
    return 0;
}







Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N,W;
  cin>>N>>W;
  int w[N],v[N];
  REP(i,N)cin>>w[i]>>v[i];
  map<int,int> dp;
  dp[0]=0;
  REP(i,N){
    auto temp=dp;
    for(auto itr=temp.rbegin();itr!=temp.rend();itr++){
      if(itr->first+w[i]>W)continue;
      dp[itr->first+w[i]]=max(dp[itr->first+w[i]],dp[itr->first]+v[i]);
    }
  }
  // for(auto e:dp){
  //   cerr<<e.first<<" "<<e.second<<endl;
  // }
  cout<<max_element(ALL(dp),[](auto a,auto b){return a.second<b.second;})->second<<endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005


ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=1000000000000;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}


/////////////////////////////////////////////////////////////////

int count(vector<int>s,vector<int>t){
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    int res=0,poss=0,post=0;
    while(poss<=s.size()-1&& post<=t.size()-1){
        if(s[poss]==t[post]){
            res++;
            poss++;post++;
        }else if(s[poss]>t[post]){
            post++;
        }else{
            poss++;
        }
    }
    return res;
}


int main(){
    int n;cin>>n;
    int a[n];rep(i,0,n-1)cin>>a[i];
    int b[n];rep(i,0,n-1)b[i]=a[i];
    sort(b,b+n);
    vector<int>a1,b1;
    rep(i,0,n-1){
        if(i%2==0){
            a1.pb(a[i]);
            b1.pb(b[i]);
        }
    }
    int ans=count(a1,b1);
    cout<<(n+1)/2-ans<<endl;
    return 0;
}

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int A, B, C, K;

    cin >> A >> B >> C >> K;
    int sum = A + B + C;
    int ma = max({A, B, C});
    while(K>0){
        ma *= 2;
        K--;
    }
    cout << ma+sum-max({A,B,C}) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,a[2][101],sum=0,i,j,max=0;
	scanf("%d",&n);
	for(i=0;i<2;i++)
	{
		for(j=0;j<n;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<=i;j++)
		{
			sum+=a[0][j];
		}
		for(j=i;j<n;j++)
		{
			sum+=a[1][j];
		}
		if(sum>max)
		{
			max=sum;
		}
		sum=0;
	}
	printf("%d\n",max);
} 

Measured memory_bytes: 128
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

S = input()
l = len(S)
d = {"A":1,"B":2,"C":3}

dp = [0 for _ in range(4)]
dp[0] = 1
for i in range(l):
    if S[i] == "?":
        dp = [dp[0]*3,dp[1]*3+dp[0],dp[2]*3+dp[1],dp[3]*3+dp[2]]
        for j in range(4):
            dp[j] %= mod
    else:
        j = d[S[i]]
        dp[j] += dp[j-1] % mod

print(dp[3]%mod)

Measured memory_bytes: 42220
use proconio::input;

fn main() {
    input! {
        mut s: String,
    }

    let v: Vec<_> = s.chars().collect();
    let c = *v.last().unwrap();
    if c == 's' {
        s.push_str("es");
    } else {
        s.push('s');
    }
    println!("{}", s);
}


Measured memory_bytes: 2192
n = input()
 
if n[-1] == "2" or n[-1] == "4" or n[-1] == "5" or n[-1] == "7" or n[-1] == "9":
    print("hon")
elif n[-1] == "0" or n[-1] == "1" or n[-1] == "6" or n[-1] == "8":
    print("pon")
else:
    print("bon")

Measured memory_bytes: 9120
import java.io.*;
import java.math.*;
class Main{
    public static void main(String[] args){
	try{
	    BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
	    BigInteger sum= BigInteger.valueOf(1);
	    int n = Integer.valueOf(sc.readLine());
	    for(int i=2; i<=n; i++)
		sum = sum.multiply(BigInteger.valueOf(i));
	    System.out.println(sum);
	}catch(Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 9340
#include <stdio.h>
#define N 10000
int main() {
  int i,n,S[N],q,T[N],cnt=0,j;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&S[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++)scanf("%d",&T[i]);
  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(S[j]==T[i]){
	cnt++;
	break;
      }
    }
  }
  printf("%d\n",cnt);
  return 0;
}


Measured memory_bytes: 2072
#include<bits/stdc++.h>
using namespace std;
map<int,int> Map;
int X[200200];
int main()
{
	int N,K,Sum=0;
	long long Ans=0;
	cin>>N>>K;
	Map[0]=1;
	for(int i=1;i<=N;i++)
	{
		if(i>=K)
			Map[X[i-K]]--;
		int A;
		cin>>A;
		A--;
		Sum=(Sum+A)%K;
		Ans+=Map[Sum];
		Map[Sum]++;
		X[i]=Sum;
	}
	cout<<Ans<<endl;
	return 0;
}

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

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    vector<P> v;
    int x, y;
    while(true) {
        cin >> x >> y;
        if(x == 0 && y == 0) break;
        v.push_back(P(x, y));
    }
    rep(i, v.size()) {
        int f = v.at(i).first;
        int s = v.at(i).second;
        if(f < s) cout << f << " " << s << endl;
        else cout << s << " " << f << endl;
    }
}


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

int a[200010], id[200010];
int vis[200010];
int ans[200010];
int tox[200010];
vector <int> ord;

struct Segment_tree {
	vector <int> T[800010];
	int pos[800010];
	vector <int> merge(vector <int> &a, vector <int> &b) {
		vector <int> c; int p1 = 0, p2 = 0;
		while (p1 < a.size() || p2 < b.size()) {
			if (p2 == b.size() || p1 != a.size() && a[p1] < b[p2]) c.push_back(a[p1++]);
			else c.push_back(b[p2++]);
		}
		return c;
	}
	void Build(int now, int l, int r) {
		pos[now] = 0;
		if (l == r) {
			T[now].push_back(a[l]);
			return ;
		}
		int mid = l + r >> 1;
		Build(now << 1, l, mid), Build(now << 1 | 1, mid + 1, r);
		T[now] = merge(T[now << 1], T[now << 1 | 1]);
	}
	void get_s(int now, int l, int r, int L, int R, int val) {
		if (l == L && r == R) {
			while (pos[now] < T[now].size()) {
				int x = T[now][pos[now]];
				if (x > val) break;
				if (!vis[tox[x]]) {
					ord.push_back(tox[x]);
					vis[tox[x]] = 1;
				}
				pos[now]++;
			}
			return ;
		}
		int mid = l + r >> 1;
		if (R <= mid) get_s(now << 1, l, mid, L, R, val);
		else if (L > mid) get_s(now << 1 | 1, mid + 1, r, L, R, val);
		else get_s(now << 1, l, mid, L, mid, val), get_s(now << 1 | 1, mid + 1, r, mid + 1, R, val);
	}
	void get_b(int now, int l, int r, int L, int R, int val) {
		if (l == L && r == R) {
			while (pos[now] < T[now].size()) {
				int x = T[now].back();
				if (x < val) break;
				if (!vis[tox[x]]) {
					ord.push_back(tox[x]);
					vis[tox[x]] = 1;
				}
				T[now].pop_back();
			}
			return ;
		}
		int mid = l + r >> 1;
		if (R <= mid) get_b(now << 1, l, mid, L, R, val);
		else if (L > mid) get_b(now << 1 | 1, mid + 1, r, L, R, val);
		else get_b(now << 1, l, mid, L, mid, val), get_b(now << 1 | 1, mid + 1, r, mid + 1, R, val);
	}
}seg;

int main () {
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		int x, y; scanf("%d%d", &x, &y);
		id[x] = i;
		a[x] = y;
		tox[y] = x;
	}
	seg.Build(1, 1, n);
	for (int i = 1; i <= n; i++) {
		if (vis[i]) continue;
		ord.clear(), ord.push_back(i), vis[i] = 1;
		for (int it = 0; it < ord.size(); it++) {
			int x = ord[it], y = a[x];
			if (x > 1 && y > 1) seg.get_s(1, 1, n, 1, x - 1, y - 1);
			if (x < n && y < n) seg.get_b(1, 1, n, x + 1, n, y + 1);
		}
		for (int j = 0; j < ord.size(); j++) {
			ans[id[ord[j]]] = ord.size();
		}
	}
	for (int i = 1; i <= n; i++) {
		printf("%d\n", ans[i]);
	}
	return 0;
}


Measured memory_bytes: 56640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    ll n,ans = 0;
    cin >> n;
    for (ll i = floor(sqrt(n)); i > 0 ; --i) {
        if (n % i == 0) {
            n /= i;
            break;
        }
    }
    while (n > 0) {
        n /= 10;
        ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <time.h>
#include <fstream>

using namespace std;

long long maxLL (long long a, long long b){
	if (a>b) return a;
	return b;
}

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

	int f[n][10];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
			cin>>f[i][j];
		}
	}
	long long p[n][11];
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= 10; j++){
			cin>>p[i][j];
		}
	}
	long long total = -100*10e7*10*10;
	for(int i = 1 ; i < 1024; i++){
		long long current = 0;


		for(int j = 0 ; j < n; j++){
			int common = 0;
			for(int k = 0; k < 10; k++){
				if ((f[j][k] == 1) && ((i>>k)&1)) common++;
			}
			current += p[j][common];
		}
		total = maxLL(current, total);
	}
	cout<<total<<endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        while(H!=0||W!=0){
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++) System.out.print("#");
                System.out.println("");
            }
            System.out.println("");
            H = sc.nextInt();
            W = sc.nextInt();
        }
    }
}


Measured memory_bytes: 35088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    string A,B,C;
    cin >>A>>B>>C;
    
    if(A[A.size()-1]==B[0] && B[B.size()-1]==C[0]){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
 


    return 0;
    

}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
int main() {
  int N,M;
  cin>>N>>M;
  vector<int>A(N),B(N);
  vector<pair<int,int>>P(N);
  for(int i=0;i<N;i++){
    cin>>A[i]>>B[i];
    P[i]=make_pair(A[i],B[i]);
  }
  sort(P.begin(),P.end());
  int64_t cost=0,tot=M;
  for(int i=0;i<N;i++){
    int64_t p=P[i].first;
    int64_t q=P[i].second;
    if(tot>=q){cost+=p*q;tot-=q;}
    else if(tot<q){cost+=p*tot;tot-=tot;break;}
    //cout<<cost<<endl;
  }
  cout<<cost<<endl;
  return 0;
}

Measured memory_bytes: 4784
#include<bits/stdc++.h>
#define N 605
using namespace std;
int f[N][N],n;
void work(int d)
{
	int t=0;
	while(d%4==0)
	{
		t++;
		d/=4;
	}
	if(d%2==1)
	{
		for(int i=0;i<2*n;i++)
			for(int j=0;j<2*n;j++)
				if(((i>>t)+(j>>t))%2==1)f[i][j]=1;
	}
	if(d%4==2)
	{
		for(int i=0;i<2*n;i++)
			for(int j=0;j<2*n;j++)
				if((i>>t)%2==1)f[i][j]=1;
	}
}
int main()
{
	int d1,d2;
	scanf("%d%d%d",&n,&d1,&d2);
	memset(f,0,sizeof(f));
	work(d1);work(d2);
	int sum=0;
	for(int i=0;i<2*n;i++)
		for(int j=0;j<2*n;j++)
			if(!f[i][j])
			{
				printf("%d %d\n",i,j);
				sum++;
				if(sum==n*n)return 0;
			}
}

Measured memory_bytes: 2428