akhauriyash/Code-Regression huggingface dataset:
M = int(input())
d = [0] * M
c = [0] * M
for i in range(M):
	d[i], c[i] = map(int, input().split())
D = 0
S = 0
for i in range(M):
	D += c[i]
	S += d[i] * c[i]
print((D - 1) + (S - 1) // 9)


Measured memory_bytes: 12532
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; 

const long long N = 1e7+5;
vector<long long>v(N);

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

    long long ans = 0, n;
    cin>>n;
    for(long long i=1;i<=n;i++)
    {
        for(long long j = 1;i * j<=n;j++)
        {
            v[i*j]++;
        }
    }

    for(long long i = 1;i<=n;i++)
    {
        ans+=i*v[i];
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 81252
k,n = list(map(int,input().split()))
a = list(map(int,input().split()))
mn = k+1
for i in range(n):
    nxt= (i+1)%n;
    prv= (i-1+n)%n;
    if a[i]<a[nxt]:
        diff1= k- (a[nxt]-a[i])
    else:
        diff1= a[i]-a[nxt]
    if a[i]>a[prv]:
        diff2=k-(a[i]-a[prv])
    else:
        diff2=a[prv]-a[i]
    mn=min(diff1,mn)
    mn=min(diff2,mn)
print(mn)

Measured memory_bytes: 26444
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<map>
#include<iostream>
#define pk push_back
#define mk make_pair 
using namespace std;
typedef long long LL;
typedef pair<int,int> pi;
const int mod=998244353;
map<string,int> f,g;
int F(string s);
int G(string s){
	if(g.find(s)!=g.end()) return g[s];
	if(s.size()==1) return s[0]-'0'+1;
	g[s]=0;
	for(int i=1;i<s.length();++i)if(s.length()%i==0){
		string t;
		for(int j=0;j<i;++j){
			char r='1';
			for(int k=0;j+k*i<s.length();++k)if(s[j+k*i]=='0') r='0';
			t+=r;
		}
		(g[s]+=F(t))%=mod;
	}
	return g[s];
}
int F(string s){
	if(f.find(s)!=f.end()) return f[s];
	f[s]=0;
	for(int i=1;i<=s.length();++i)
		(f[s]+=1ll*F(s.substr(0,s.length()-i))*G(s.substr(s.length()-i,i))%mod)%=mod;
	return f[s];
}
int main(){
	ios::sync_with_stdio(false);
	f[""]=1;
	string s;cin>>s;cout<<F(s)<<endl;
	return 0;
} 

Measured memory_bytes: 12712
#include<bits/stdc++.h>
#define pb          push_back
#define endl        '\n'
#define pll         pair<int,int>
#define vll          vector<int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define int	    int64_t
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
int n,i,j,k,l,sum=0,flag=0,ans=0,w[101],v[101],m;
int is[301][301][301];
double dp[301][301][301];
double a[3001];
double f(int one , int two , int three){
	if(one == 0 and two == 0 and three==0)
		return 0;
	if(is[one][two][three]!=-1)
		return dp[one][two][three];
	is[one][two][three] = 1;
	double ans = 1.0;
	if(one)
		ans+= (1.0l*one/n) * f(one-1,two,three);
	if(two)
		ans+= (1.0l*two/n) * f(one+1,two-1,three);
	if(three)
		ans+= (1.0l*three/n) * f(one,two+1,three-1);
	return dp[one][two][three] = ((1.0l*ans*n)/(one+two+three));
}
void solve(){
	memset(is,-1,sizeof is);
	cin>>n;
	int one=0,two= 0,three = 0;
	for(int i=0;i<n;i++){
		cin>>j;
		one+=(j==1);
		two+=(j==2);
		three+=(j==3);
	}
	cout<<fixed<<setprecision(10)<<f(one,two,three)<<endl;
}
signed main()
{
    ios
    int test = 1;
    //cin>>test;
    while(test--){
    	solve();
    }
    return 0;
}

Measured memory_bytes: 426496
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    counter = Counter(A)
    dupl_bars = [length for length, cnt in counter.items() if cnt > 1]
    dupl_bars.sort(reverse=True)
    if len(dupl_bars) > 1:
        if counter[dupl_bars[0]] > 3:
            print(dupl_bars[0] ** 2)
        else:
            print(dupl_bars[0] * dupl_bars[1])
    else:
        print(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18600
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 10

ll N,K;
ll D[MAX];
ll a[MAX];

std::vector<int> v;

int main() {
  cin >> N >> K;
  rep(i,K) {
    int a;
    cin >> a;
    D[a] = 1;
  }

  int lim = 10 * N;

  for (int i = N; i <= lim; ++i) {
    int temp = i;
    bool flag = true;

    while (temp > 0) {
      int digit = temp % 10;
      if (D[digit]) {
        flag = false;
        break;
      }
      temp /= 10;
    }

    if (flag) {
      cout << i << endl;
      return 0;
    }
  }

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
using namespace std;
const int MAXN=55;
const int MAXM=110;
const int P=1E9+7;
struct Edge
{
	int from, to;
	Edge(int u, int v): from(u), to(v) {}
};
int n, m, k, cnt, t1, t2, tot;
int c[2*MAXM][MAXM], f[MAXM];
int dfn[MAXN], low[MAXN];
int s1[MAXN], s2[MAXM];
int c1[MAXM], c2[MAXM];
bool ins[MAXN];
vector<Edge> edges;
vector<int> G[MAXN];
int gcd(int a, int b)
{
	if (b==0) return a;
	return gcd(b, a%b);
}
void exgcd(int a, int b, int& x, int& y)
{
	if (b==0) x=1, y=0;
	else exgcd(b, a%b, y, x), y-=a/b*x;
}
int qpow(int a, int b)
{
	int r=1;
	while (b)
	{
		if (b&1) r=1ll*r*a%P;
		a=1ll*a*a%P; b>>=1;
	}
	return r;
}
int inv(int a)
{
	int x, y;
	exgcd(a, P, x, y);
	return (x%P+P)%P;
}
void init()
{
	memset(c, 0, sizeof c);
	c[0][0]=1;
	for (int i=1; i<=m+k; i++)
	{
		c[i][0]=1;
		for (int j=1; j<=i&&j<=m; j++)
			c[i][j]=(c[i-1][j-1]+c[i-1][j])%P;
	}
	memset(f, 0, sizeof f);
	for (int i=1; i<=m; i++)
	{
		for (int j=1; j<=i; j++)
			f[i]=(f[i]+qpow(k, gcd(i, j)))%P;
		f[i]=1ll*f[i]*inv(i)%P;
	}
	edges.clear();
	for (int i=1; i<=n; i++) G[i].clear();
	memset(dfn, 0, sizeof dfn);
	memset(ins, 0, sizeof ins);
	cnt=tot=t1=t2=0;
}
inline void addEdge(int u, int v)
{
	edges.push_back(Edge(u, v));
	edges.push_back(Edge(v, u));
	G[u].push_back(edges.size()-2);
	G[v].push_back(edges.size()-1);
}
void tarjan(int u, int f)
{
	low[u]=dfn[u]=++cnt; ins[u]=1;
	for (int i=0; i<G[u].size(); i++)
	{
		int v=edges[G[u][i]].to;
		if (!dfn[v]||v!=f&&ins[v])
		{
			s2[++t2]=G[u][i];
			if (!dfn[v])
			{
				s1[++t1]=v;
				tarjan(v, u);
				low[u]=min(low[u], low[v]);
				if (low[v]>=dfn[u])
				{
					c1[++tot]=1; c2[tot]=0;
					do c1[tot]++; while (s1[t1--]!=v);
					do c2[tot]++; while (s2[t2--]!=G[u][i]);
				}
			}
			else low[u]=min(low[u], dfn[v]);
		}
	}
	ins[u]=0;
}
int main()
{
//	freopen("B.in", "r", stdin);
//	freopen("B.out", "w", stdout);
	scanf("%d%d%d", &n, &m, &k);
	init();
	for (int i=1; i<=m; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		addEdge(u, v);
	}
	for (int i=1; i<=n; i++)
		if (!dfn[i]) tarjan(i, 0);
	int ans=1;
	for (int i=1; i<=tot; i++)
	{
		if (c1[i]==c2[i]) ans=1ll*ans*f[c2[i]]%P;
		else if (c1[i]<c2[i]) ans=1ll*ans*c[c2[i]+k-1][c2[i]]%P;
		else ans=1ll*ans*k%P;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define full(a) a.begin(),a.end()
#define stoink stack<ll>
#define vec vector <ll>
#define vg vector<vector<ll> >
#define vgw vector<vector<pair<ll,ll> >
#define pa pair<ll,ll>
#define mp make_pair
#define pb push_back
int main() {
    ll n,l;
    cin >> n >> l;
    vec arr(n);
    ll i;
    for( i = 0; i < n; i++) {
        cin >> arr[i];
    }
    bool flag = false;
    for( i = 0; i < n-1 ; i++ ) {
        if( arr[i] + arr[i + 1] >= l) {
            flag = true;
            cout << "Possible" << endl;
            for(ll j = 0 ; j < i ; j++)
                cout<< j + 1 <<endl;
            for(ll j = n - 1 ; j > i + 1; j--)
                cout<< j <<endl;
            cout << i +1 <<endl;
            break;
            }
        }

    if(!flag)
        cout<<"Impossible";
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
//#include <vector>
using namespace std;
 
 
int main(){
   
  int64_t n;
  int64_t ans=0,time=-100000001;
  
  cin>>n;
  
  vector<int64_t> x(n);
  vector<int64_t> l(n);
  vector<int64_t> s(n);
  vector<int64_t> t(n);
  
  
  for(int64_t i=0;i<n;i++){
      cin>>x.at(i)>>l.at(i);
      s.at(i)=x.at(i)-l.at(i);
      t.at(i)=x.at(i)+l.at(i);
  }
  
  pair<int64_t,int64_t> itv[n];
  
 // void solve(){
    for(int64_t i=0;i<n;i++){
          itv[i].first=t.at(i);
          itv[i].second=s.at(i);
    }
      sort(itv,itv+n);
      
      
      for(int64_t i=0;i<n;i++){
          if(time<=itv[i].second){
              ans++;
              time=itv[i].first;
              //cout<<i<<endl;
          }
      } 
    
   cout<<ans<<endl;
   
    
    
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
int n,r;
  
  cin >> n;
  cin >> r;
  
  if (n>=10) {
    cout << r << endl;
  }
  if (n<10) {
    cout << r+100*(10-n) << endl ;
  }
}

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

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif

    int n;
    cin >> n;
    if(n < 1200) {
        cout << "ABC" << endl;
    }
    else if(n < 2800) {
        cout << "ARC" << endl;
    }
    else {
        cout << "AGC" << endl;
    }

    return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n);
#define vsort(v) sort(v.begin(),v.end());
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
bool is_uruu(int y) {
        return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
const ll MOD=1e9+7;
//---------------------------------------------------------------------------//

int main(){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        if(a*b>c*d) {
                cout<<a*b<<endl;
        }else if(a*b<c*d) {
                cout<<c*d<<endl;
        }else{
                cout<<a*b<<endl;
        }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  ll N;
  cin>>N;
  map<ll,int> M;
  if(N==1){
    cout<<0<<endl;
    return 0;
  }
  rep(i,sqrt(N)){
    while(N%(i+2)==0){
      M[i+2]++;
      N/=(i+2);
    }
  }
  if(N!=1) M[N]++;
  auto itr=M.begin();
  ll ans=0;
  rep(i,M.size()){
    rep(j,40){
      if((itr->second)<j*(j+1)/2){
        ans+=j-1;
        break;
      }
    }
    itr++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3724
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);

  auto p = primes(55555);
  foreach (i, pi; p.filter!(pi => pi%5 == 1).take(n).enumerate) {
    write(pi);
    if (i < n-1) write(" ");
  }
  writeln;
}

pure T[] primes(T)(T n)
{
  import std.algorithm, std.bitmanip, std.conv, std.range;

  auto sieve = BitArray();
  sieve.length((n+1)/2);
  sieve = ~sieve;

  foreach (p; 1..((nsqrt(n)-1)/2+1))
    if (sieve[p])
      for (auto q = p*3+1; q < (n+1)/2; q += p*2+1)
        sieve[q] = false;

  auto r = sieve.bitsSet.map!(to!T).map!("a*2+1").array;
  r[0] = 2;

  return r;
}

pure T factor(T)(T n, const T[] p)
{
  auto ma = nsqrt(n)+1;
  foreach (pi; p)
    if (pi > ma) return n;
    else if (n%pi == 0) return pi;
  return n;
}

pure T nsqrt(T)(T n)
{
  import std.algorithm, std.conv, std.range, core.bitop;
  if (n <= 1) return n;
  T m = T(1) << (n.bsr/2+1);
  return iota(1, m).map!"a*a".assumeSorted!"a <= b".lowerBound(n).length.to!T;
}


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

#define debug(x) cout << #x" = " << x;

#define st first
#define nd second
#define all(x) (x).begin(), (x).end()

using namespace std;
using namespace placeholders;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

template <class T> void mini(T &l, T r){l = min(l, r);}
template <class T> void maxi(T &l, T r){l = max(l, r);}

template <class TH> void _dbg(const char *sdbg, TH h){cerr << sdbg << "=" << h << "\n";}
template <class TH, class ...TA> void _dbg(const char *sdbg, TH h, TA... a){
	while (*sdbg != ',') cerr << *sdbg++; cerr << "=" << h << ","; _dbg(sdbg + 1, a...);
}
template <class T> ostream &operator <<(ostream &os, vector<T> V){
	os << "["; for (auto vv: V) os << vv << ","; return os << "]";
}
template <class L, class R> ostream &operator <<(ostream &os, pair<L, R> P){
	return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef SFIC
	#define eput(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
	#define eput(...) 218
#endif

const int MAXN = 2E3 + 10;

int n, m, q;
char s[MAXN][MAXN];
int a[MAXN][MAXN], b[MAXN][MAXN], c[MAXN][MAXN];

int sum(int a[][MAXN], int x1, int y1, int x2, int y2){
	return a[x2][y2] - a[x2][y1 - 1] - a[x1 - 1][y2] + a[x1 - 1][y1 - 1];
}

int main(){
	scanf("%d%d%d", &n, &m, &q);
	for (int i = 1; i <= n; ++i)
		scanf("%s", s[i] + 1);
	for (int i = 1; i <= n; ++i){
		for (int j = 1; j <= m; ++j){
			c[i][j] = c[i][j - 1] + (s[i][j] == '1');
			a[i][j] = a[i][j - 1] + (s[i][j] == '1' && s[i][j] == s[i][j + 1]);
			b[i][j] = b[i][j - 1] + (s[i][j] == '1' && s[i][j] == s[i + 1][j]);
		}
		for (int j = 1; j <= m; ++j)
			a[i][j] += a[i - 1][j], b[i][j] += b[i - 1][j], c[i][j] += c[i - 1][j];
	}

	for (int qi = 0; qi < q; ++qi){
		int x1, y1, x2, y2;
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		printf("%d\n", sum(c, x1, y1, x2, y2) - sum(a, x1, y1, x2, y2 - 1) - sum(b, x1, y1, x2 - 1, y2));
	}
	return 0;
}


Measured memory_bytes: 53120
def count(l):
    res = {}
    for d in l:
        if d in res:
            res[d] += 1
        else:
            res[d] = 1
    return res

n = float(input())
data = list(map(int, input().split()))
t = count(data)
if len(t) == 3:
    ks = list(t.keys())
    if 0 not in t and all(i == n/3 for i in t.values()) and ks[0]^ks[1] == ks[2]:
        print('Yes')
    else:
        print('No')

elif len(t) == 2:
    if 0 in t and t[0] == n/3:
        print('Yes')
    else:
        print('No')

elif len(t) == 1:
    if 0 in t:
        print('Yes')
    else:
        print('No')

else:
    print('No')
        


Measured memory_bytes: 14116
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


//FUNCTION  
 
//solve

void solve(void)
{
  string str;
  cin>>str;
  int N = str.size();
  for (int i = 0; i < N - 1 ; i++)
  {
    if(str[i] == str[i+1])
    {
      cout<<i+1<<" "<<i+2<<endl; 
      return;
    }
    if(i != N -2)
    {
      if(str[i] == str[i+2])
      {
        cout<<i+1<<" "<<i+3<<endl;
        return;
      }
    }
  }
  cout<<-1<<" "<<-1<<endl;
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 512
import Control.Applicative
import Data.Function
import Control.Monad

f :: [[Int]] -> [Int] -> [Int] 
f [] _ = []
f (x:xs) y = (sum $ zipWith (*) x y) : f xs y  

main :: IO ()
main = do
    [n,m] <- map read . words <$> getLine
    nxm <- replicateM n $ map read . words <$> getLine
    mx1 <- replicateM m $ read <$> getLine
    forM_ (f nxm mx1) $ \x -> putStrLn $ show x


Measured memory_bytes: 7568
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        const long MOD = 1000000007;
        var sc = new Scanner();
        int k = sc.nextInt();
        int x = sc.nextInt();

        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        for (int i = x - (k - 1); i <= x + (k - 1); i++)
        {
            Console.Write(i + " ");
        }
        Console.Out.Flush();
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 11092
MOD = 10**9 + 7

N = int(input())
Cs = list(map(int, input().split()))

As = [1]
accA = 1
m = 2
for i in range(1, N):
    A = (accA + m) % MOD
    As.append(A)
    accA = (accA + A) % MOD
    m = m * 2 % MOD

m = 1
for i in reversed(range(N)):
    As[i] = As[i] * m % MOD
    m = m * 2 % MOD

Cs.sort(reverse=True)

ans = 0
for C, A in zip(Cs, As):
    ans += C * A % MOD

print(ans * pow(2, N, MOD) % MOD)


Measured memory_bytes: 26024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	if (k <= a) cout << k << endl;
	else if (k <= a + b) cout << a << endl;
	else cout << a - (k - (a + b)) << endl;
}

Measured memory_bytes: 3524
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [0.0 for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
a,b,c = LI()
print(min(b//a,c))
"""

#B
"""
a,b,k = LI()
i = 1
ans = [1]
while i <= min(a,b):
    i += 1
    if a%i == 0 and b%i == 0:
        ans.append(i)
print(ans[-k])
"""

#C
"""
s = list(map(int,S()))
print(2*min(sum(s),len(s)-sum(s)))
"""

#D
def root(x):
    if par[x] == x:
        return x
    par[x] = root(par[x])
    return par[x]
def unite(x,y):
    x = root(x)
    y = root(y)
    if x == y:
        ans.append(ans[-1])
        return
    sx = s[x]
    sy = s[y]
    if rank[x] < rank[y]:
        par[x] = y
        s[y] += sx
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1
        s[x] += sy
    ans.append(ans[-1]+sx*sy)
n,m  = LI()
v = LIR(m)
v = v[::-1]
par = [i for i in range(n)]
rank = [0 for i in range(n)]
s = [1 for i in range(n)]
ans = [0]
k = n*(n-1)//2
v.pop(-1)
for a,b in v:
    if ans[0] == k:
        ans.append(k)
        continue
    a -= 1
    b -= 1
    unite(a,b)
for i in ans[::-1]:
    print(k-i)
#E
"""
n,a,b = LI()
s = input()
ans = 0
i = 0
while i < n:
    j = i+1
    if s[i:j] in s[:i]:
        while s[i:j] in s[:i]:
            j += 1
            if j >= n-1:break
        j -= 1
        print(s[i:j],s[:i])
        ans += min(b,a*(j-i+1))
    else:
        ans += a*(j-i)
    i = j
print(ans)
"""
#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 93736
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  cin >> n;
  LL a = 0, b = 0;
  VEC<int> c(n);
  REP(i, 0, n) { cin >> c[i]; }
  sort(ALL(c));
  reverse(ALL(c));
  REP(i, 0, n) {
    if (i % 2 == 0)
      a += c[i];
    else
      b += c[i];
  }
  cout<<a-b<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll calc(ll h) {
	if (h == 1) return 1;
	return 1 + 2 * calc(h / 2);
}
int main() 
{
	ll H;
	cin >> H;
	cout << calc(H) << endl;
}


Measured memory_bytes: 3588
A = {chr(i):0 for i in range(97,123)}
S = input().strip()
T = input().strip()
N = len(S)
G = {}
for i in range(N):
    a = S[i]
    if a not in G:
        G[a]=[]
    b = T[i]
    if b not in G[a]:
        G[a].append(b)
flag = 0
cnt = 0
for a in G:
    cnt += 1
    if len(G[a])>1:
        flag = 1
        break
    if len(G[a])==0 and cnt==26:
        break
    b = G[a][0]
    if a!=b:
        cnt += 1
    if A[b]==0:
        A[b] += 1
    else:
        flag = 1
        break
if flag==1:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 41840
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>

using namespace std;
typedef long long ll;
const int maxN=2e5+5;

map<ll,int>mp;
ll a[maxN],b[maxN],c[maxN],d[maxN];

int lowbit(int x)
{
    return x&(-x);
}

int getsum(int x)
{
    int sum=0;
    while(x)
    {
        sum+=c[x];
        x-=lowbit(x);
    }
    return sum;
}

void add(int x)
{
    while(x<maxN)
    {
        c[x]++;
        x+=lowbit(x);
    }
}

int main()
{
    ll k,n,m,K,ans=0;
    cin>>n>>K;
    for(k=1;k<=n;k++)
    {
        cin>>a[k];
        a[k]+=a[k-1];
        b[k]=a[k]-K*k;
        d[k]=b[k];
    }
    sort(b+1,b+n+1);
    m=unique(b+1,b+n+1)-b;
    for(k=1;k<m;k++)
    {
        mp[b[k]]=k;
    }
    for(k=1;k<=n;k++)
    {
        if(d[k]>=0)ans++;
        ans+=getsum(mp[d[k]]);
        add(mp[d[k]]);
    }
    cout<<ans;
    return 0;
}


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

int main(void){
  int a,b,c; cin >> a >> b >> c;
  if(c+b > a) cout << c - (a-b) << endl;
  else cout << 0 << endl;
  return 0;
}


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

int func(int x)
{
    if(x%2==0)
    {
        return x/2;
    }
    else
    {
        return 3*x+1;
    }
}
int main()
{
    int a,b,m;
    cin>>a>>b>>m;
    vector <int> A(a);      //冷蔵庫
    vector <int> B(b);      //電子レンジ    
    vector <int> C(m);      //クーポン

    rep(i,a) cin>>A[i];
    rep(i,b) cin>>B[i];

    int minElementA = *min_element(A.begin(), A.end());  //冷蔵後の最小値
    int minElementB = *min_element(B.begin(), B.end());  //電子レンジの最小値   
    int minV = minElementA+minElementB;

    //クーポン適用
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        cin>>C[i];
        if(A[x-1]+B[y-1]-C[i]<minV)
        {
            minV=A[x-1]+B[y-1]-C[i];
        }
    }

    cout<<minV<<endl;


    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  string s;
  cin>>s;
  int ans=1;
  string pre=s.substr(0,1);
  rep(i,1,sz(s))
    {
      if(s[i]==pre[0] && sz(pre)==1)
	{
	  if(i!=sz(s)-1)
	    {
	      pre=s.substr(i,2);
	      i++;
	      ans++;
	    }
	}
      else
	{
	  pre=s.substr(i,1);
	  ans++;
	}
      trace(i,ans,pre);
    }
  cout<<ans<<endl;
  return 0 ;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

#define P pair<lli,lli>

signed main(){

	lli num=0;
	REP(i,0,4){
		char tmp;
		cin>>tmp;
		num += (tmp=='+'?1:-1);
	}
	cout<<num<<endl;

	return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //cout << fixed << setprecision(6);
    int n; cin >> n;
    vll a(n);
    vll cum(n+1, 0);
    rep(i, n) {
        cin >> a[i];
        cum[i+1] = cum[i] + a[i];
    }

    ll ans = 0;
    rep (i, n) {
        ans += (a[i] * ((cum[n] - cum[i+1]) % MOD)) % MOD;
        ans %= MOD;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6308
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000000000000002
#define N 400003
#define endl "\n"
using namespace std;
ll arr[102][100004];
int main()
{
    
    ll s[1000][7];ll n,w;cin>>n>>w;
    for(ll i=0;i<n;i++)
    {
        cin>>s[i][0]>>s[i][1];
    }
    for(ll i=0;i<=n;i++)
    {
        for(ll j=0;j<=w;j++)
        {
            if(i==0||j==0)
            {
                arr[i][j]=0;
            }
            else
            {
            if(s[i-1][0]<=j)
            {
                arr[i][j]=max(arr[i-1][j],s[i-1][1]+arr[i-1][j-s[i-1][0]]);
            }
            else
            
            {
                arr[i][j]=arr[i-1][j];
            }
            }
        }
    }
    cout<<arr[n][w]<<endl;;
 
    return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=2005;
//i_am_noob
string str;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> str;
	rep(3) if(str[i]=='7'){
		print1("Yes");
		return 0;
	}
	print1("No");
	return 0;
}

Measured memory_bytes: 3652
#!/usr/bin/pypy
N=int(raw_input())
AN=map(int, raw_input().split())

BN=[0 for i in xrange(N)]
for i in AN:
    BN[i-1] += 1
BN.sort()

LN = [0 for i in xrange(N)]
s = 0
j = 0
try:
    for X in xrange(1, N+1):
        while j<N and  BN[j] < X:
            s += BN[j]
            j += 1
        LN[X-1] = int((s + X*(N - j)) / X)
except IndexError:
    pass

KN = [0 for i in xrange(N)]
for i in xrange(len(LN)):
    KN[LN[i]-1] = i+1

for i in xrange(len(KN)-2, -1, -1):
    if KN[i] == 0:
        KN[i] = KN[i+1]

for i in KN:
    print (str(i))

Measured memory_bytes: 65232
#include <algorithm>
#include <stack>
#include <iostream>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;


int main(){
  string s;
  cin >> s;
  int ans = 0;

  const int n = s.size();
  stack<int> st;

  REP(i,n){
    if(st.empty() || s[i] == st.top()){
      st.push(s[i]);
    }else{
      st.pop();
    }
  }

  printf("%d\n", (int)(s.size() - st.size()));
  return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
//
// Created by karayuu on 2018-12-28.
//

int main() {
    int n, a, b;
    string s;

    cin >> n >> a >> b;
    cin >> s;

    int count = 0;
    int a_count = 0;
    for (int i = 1; i <= n; i++) {
        switch (s[i - 1]) {
            case 'a':
                if (count < a + b) {
                    count++;
                    cout << "Yes" << endl;
                } else {
                    cout << "No" << endl;
                }
                continue;

            case 'b':
                if (count < a + b && a_count < b) {
                    count++;

                    cout << "Yes" << endl;
                } else {
                    cout << "No" << endl;
                }
                a_count++;
                continue;

            default:
                cout << "No" << endl;
                continue;
        }
    }
    cout << endl;
}

Measured memory_bytes: 896
from itertools import accumulate
from collections import Counter

s = input()
s = list(s)[::-1]
ten = [1]
for _ in range(len(s)):
  ten.append(ten[-1]*10 % 2019)
  
A = [(int(s[i])  * ten[i])%2019 for i in range(len(s))]
A = list(accumulate(A))
A = [a%2019 for a in A]
A = [0] + A

A = Counter(A).most_common()
ans = 0
for _, count in A:
  if count == 1:
    break
  ans += count*(count-1)//2
print(ans)

Measured memory_bytes: 108836
#include <iostream>
#include <limits.h>

#define MAX 10000
#define NIL -1

using namespace std;

struct Node
{
	int parent;
	int child;
	int sibling;
	int depth;
};

void init_tree(Node T[], int n);
void set_depth(Node T[], int n);
void set_depth_rec(Node T[], int node, int dep);
void print_tree(Node T[], int n);


int main()
{
	int n;
	cin >> n;
	
	Node * T = new Node [n];
	
	init_tree(T, n);
	
	
	print_tree(T, n);
	
}


void init_tree(Node T[], int n)
{
	
	int ID, k;
	
	for (int i = 0; i < n; i++)
	{
		T[i].parent = T[i].child = T[i].sibling = NIL;
	} 
	
	for (int i = 0; i < n; i++)
	{
		cin >> ID >> k;
		
		int next, cld;
		for (int j = 0; j < k; j++)
		{
			cin >> cld;
			if (j) T[next].sibling = cld;
			else  T[ID].child = cld;
			T[cld].parent = ID;	
			next = cld;
		}
	}

	set_depth(T, n);
}

void set_depth(Node T[], int n)
{
	
	int root;
	for (root = 0; root < n; root++)
		if (T[root].parent == NIL) break;
	
	set_depth_rec(T, root, 0);
}

void set_depth_rec(Node T[], int node, int dep)
{
	T[node].depth = dep;
	if (T[node].child != NIL) set_depth_rec(T, T[node].child, dep+1);
	if (T[node].sibling != NIL) set_depth_rec(T, T[node].sibling, dep);
}


void print_tree(Node T[], int n)
{
	for (int i =0; i < n; i++)
	{
		cout << "node " << i << ": ";
		cout << "parent = " << T[i].parent << ", ";
		cout << "depth = " << T[i].depth << ", ";
		
		if (T[i].parent == NIL) cout << "root, ";
		else if (T[i].child == NIL) cout << "leaf, ";
		else cout << "internal node, ";
		

		cout << "[";
		int cld = T[i].child;
		
		while (cld != NIL)
		{
			cout << cld;
			cld = T[cld].sibling;
			if (cld != NIL) cout << ", ";
		}
		

		cout << "]" << endl;
	}
}


Measured memory_bytes: 4640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int s, cnt=1;
    cin>>s;
    map<int,int> mp;
    mp[s]++;
    bool ok=true;
    while(ok){
        cnt++;
        if(s%2==0) s/=2;
        else s=s*3+1;
        if(mp[s]==1) ok=false;
        else mp[s]++;
    }
    cout<<cnt<<endl;
}

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

#define ll long long

int main(void){
    int n; cin >> n;
    vector<ll>a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
        a[i] -= i;
        // cout << a[i] << ' ';
    }
    sort(a.begin(),a.end());
    ll decrease;
    if(n%2==0) decrease = (a[n/2] + a[n/2-1])/2;
    else decrease = a[n/2];

    ll ans=0;
    for(int i=0;i<n;i++){
        ans += abs(a[i]-decrease);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
S = input()
N = len(S)

redarray = [0] * (N+1)
bluarray = [0] * (N+1)

for e,c in enumerate(S):

    if c == "2":
        bluarray[e+1] += 2
    elif c == "1":
        redarray[e+1] += 1
        bluarray[e+1] += 1
    elif c == "0":
        redarray[e+1] += 2

for i in range(1,N+1):
    redarray[i] += redarray[i-1]
    bluarray[i] += bluarray[i-1]

dp = [ [0] * (2*N+1) for _ in range(2*N+1)]
dp[0][0] = 1
MOD = 998244353

for p in range(1, 2*N+1):
    for r in range(0, p):
        idx = p if p <= N else N
        if r < redarray[idx]:
            dp[p][r+1] += dp[p-1][r] % MOD
        if p-1-r < bluarray[idx]:
            dp[p][r] += dp[p-1][r] % MOD

print(dp[2*N][redarray[N]]%MOD)

Measured memory_bytes: 166876
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <deque>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
    //input
    int n;cin >>n;
    vector<long long> a(n + 1);
    for(int i = 1; i < n + 1; i++) cin >> a[i];
    vector<long long> s(n + 2,0);
    
    //compute
    s[1] = a[1];
    for(int i = 1; i < n; i++){
        s[i + 1] = s[i] + a[i + 1];
    }

    long long opt = 10000000000;

    for(int i = 1; i < n; i++){
        long long tmp = abs(s[n] - 2 * s[i]) ;
        if(tmp < opt){
            opt = tmp;
        }
    }

    cout << opt << endl;             

}


Measured memory_bytes: 6428
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int M = sc.nextInt();
      long[] a = new long[N];
      long[] b = new long[N];
      long[] c = new long[M];
      long[] d = new long[M];
      for(int i=0;i<N;i++){
        a[i] = sc.nextLong();
        b[i] = sc.nextLong();
      }
      for(int i=0;i<M;i++){
        c[i] = sc.nextLong();
        d[i] = sc.nextLong();
      }
      for(int i=0;i<N;i++){
        long min = 4*100000000+1;
        long ans = 0;
        for(int j=0;j<M;j++){
          long man = (long)Math.abs(a[i]-c[j])+(long)Math.abs(b[i]-d[j]);
          if(man<min){
            min = man;
            ans = j+1;
          }
        }
        System.out.println(ans);
      }
    }
}

Measured memory_bytes: 35740
import sys
from io import StringIO
import unittest
import os

sys.setrecursionlimit(1000000)

def dfs(now, edge, colors):
    # 枝を全て調査
    for i in edge[now]:
        # 色を設定済みなら何もしない
        if not colors[i[0]] == -1:
            continue

        # 色の設定
        # 親子の距離%2(偶数0:奇数:1) + 親(偶数0:奇数:1) の余りを子に設定(偶数なら0 奇数なら1を設定できるロジック)
        colors[i[0]] = (i[1] % 2 + colors[now]) % 2

        # 再帰処理
        dfs(i[0], edge, colors)


# 実装を行う関数
def resolve():
    n = int(input())
    uvw = [list(map(int, input().split())) for i in range(n - 1)]

    edge = [[] for i in range(n + 1)]

    # 例：edge[0] = [[1, 100][2, 300]]
    # 点0は点1と距離100、点2と距離300でつながっている。
    for i in uvw:
        edge[i[0]].append([i[1], i[2]])
        edge[i[1]].append([i[0], i[2]])

    # -1は「未設定」の意味
    colors = [-1 for i in range(n + 1)]

    # 初期(適当な点を黒に塗る)
    colors[1] = 1

    dfs(1, edge, colors)

    for i in range(1, len(colors)):
        print(colors[i])


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """3
1 2 2
2 3 1"""
        output = """0
0
1"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """5
2 5 2
2 3 10
1 3 8
3 4 2"""
        output = """1
0
1
0
1"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()


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

long long F(long long a, long long b, long long c)
{
    return max({a,b,c}) - min({a,b,c});
}

long long foo(long long X, long long a, long long b)
{
    return min(F(X, a / 2 * b, (a - a / 2) * b), F(X, a * (b / 2), a * (b - b / 2)));
}

int main()
{
    int h, w;
    cin >> h >> w;

    long long ans = 1e18;

    for (int i = 1; i < h; i++)
    {
        ans = min(ans, foo(i * 1ll * w, h - i, w));
    }

    for (int i = 1; i < w; i++)
    {
        ans = min(ans, foo(i * 1ll * h, h, w - i));
    }

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


Measured memory_bytes: 764
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_B&lang=jp
/*
??????
0-1 ???????????¶????????????
????????? vi ????????? wi ??§??????????????? N ??????????????¨???????????? W ??????????????¶????????????????????????
?¬?????????¶?????????????????????????????????????????§???????????¶???????????\????????????

???????????????????????????????¨??????§???????????????????????????
???????????????????????????????????? W ????¶?????????????
?????????????¨?????????§???????±??????????????????????

*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N, W; cin >> N >> W;
	vector<ll> v(N), w(N);
	for (int i = 0; i < N;i++) cin >> v[i] >> w[i];

	vector<vector<ll>> dp(N + 1, vector<ll>(W + 1, 0));
	for (int i = 0; i < N;i++) {
		for (int j = 0; j <= W;j++) {
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			if (j + w[i] <= W) {
				dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
			}
		}
	}
	cout << dp[N][W] << endl;
	return 0;
}

Measured memory_bytes: 10832
#include <iostream>
#include <cstdlib>
#include <list>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(void)
{
    int N;
    int c[100001] = {0};

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

    int arc = 0;
    int ans = 0;
    for (int K = 100000; K > 1; --K)
    {
        arc += c[K];
        if (arc == N/2) ans++;
        else if (arc > N/2) break;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <set>

using namespace std;
set<int> s;
int main(){
	int i,j,n;
	cin >> n;
	int res = 1;
	for(i=0;i<=20;i++){
		s.insert(res); res *= 2;
	}
	if(s.count(n)){
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	cout << 1 << " " << 2 << endl;
	cout << 2 << " " << 3 << endl;
	cout << 3 << " " << 1 + n << endl;
	cout << 1 + n << " " << 2 + n << endl;
	cout << 2 + n << " " << 3 + n << endl;
	if(n==3) return 0;
	int l = 3 + n;
	for(i=4;i<=n - 3;i+=4){
		cout << l << " " << i << endl;
		cout << i << " " << i + 1 << endl;
		cout << i + 1 << " " << i + 2 << endl;
		cout << i + 2 << " " << i + 3 << endl;
		cout << i + 3 << " " << i + n << endl;
		cout << i + n << " " << i + n + 1 << endl;
		cout << i + n + 1 << " " << i + n + 2 << endl;
		cout << i + n + 2 << " " << i + n + 3 << endl;
		l = i + n + 3;
	}
	if(n%4==0){
		cout << n << " " << n - 4 << endl;
		cout << 2*n << " " << (n^(n-4)) + 1 << endl;
	}
	if(n%4==1){
		cout << n - 1 << " " << n << endl;
		cout << n << " " << 1 << endl;
		cout << 1 << " " << 2*n - 1 << endl;
		cout << 2*n - 1 << " " << 2*n << endl;
	}
	if(n%4==2){
		cout << n << " " << n - 1 << endl;
		cout << n - 1 << " " << 3 << endl;
		cout << n - 2 << " " << n - 1<< endl;
		cout << 3 << " " << 2*n << endl;
		cout << 2 << " " << 2*n - 2 << endl;
		cout << 2*n - 2 << " " << 2*n - 1 << endl;
	}
}

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

ll powmod(ll x,ll y){
    ll res=1;
    for(ll i=0;i<y;i++){
        res=res*x%mod;
    }
    return res;
}
int main(){
    ll n;
    cin>>n;
    ll ans=powmod(10,n)-powmod(9,n)-powmod(9,n)+powmod(8,n);
    ans%=mod;
  	if(ans < 0){
    ans=(ans+mod)%mod;
    }
    cout<<ans<<"\n";
}


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

using namespace std;

using   ll=long long;
using   ld=long double;

#define fast           ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl           "\n"
#define long long      int 
#define pb             push_back
#define mp             make_pair
#define vll            vector<ll>
#define f              first
#define s              second
#define pll            pair<ll,ll>
#define ALL(v)         v.begin(),v.end()
#define ALLR(v)        v.rbegin(),v.rend()
#define pii            3.14159265358979323

int chk(ll mid,ll k)
{
    return (240-k-5*((mid*(mid+1))/2))>=0;
}
 
void solve()
{
    string s,t;
    
    cin>>s>>t;
    
    cout<<t<<s;
}
 
 
signed main()
{
 
    fast;
 
    ll t;
    
    t=1;
    
    while(t--)
    {
        solve();
    }
 
    return 0;
}

Measured memory_bytes: 256