akhauriyash/Code-Regression huggingface dataset:
#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 ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
const double eps = 1e-6;

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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

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

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

#define int long long
const int mod = 998244353;
void solve(){

	int n;
	cin>>n;
	pair<int,int> p[n];
	for(int i = 0 ; i < n;  ++i)
		cin>>p[i].ff>>p[i].ss;
	sort(p , p + n);

	int dp[n+1];
	dp[n] = 1;

	stack<pair<int,int>> s;
	s.push({n , 1e12});

	for(int i = n - 1 ; i >= 0 ; --i){

		while(s.top().ss < p[i].ff + p[i].ss)
			s.pop();

		dp[i] = dp[i+1];

		dp[i]+=dp[s.top().ff];
		dp[i]%=mod;

		s.push({i , p[i].ff});
	}

	cout<<dp[0]<<endl;
}

signed main(){

    //fast;
    int t = 1;
    //cin>>t;
    for(int i = 1 ; i <= t; ++i){

    	solve();
    }
}




Measured memory_bytes: 6528
#include<stdio.h>

#define MAX 25
#define NIL -1

typedef struct{
  int prev,left,right;
}Node;

Node T[MAX];

void preParse(int u){
  if(u == NIL)
    return;
  printf(" %d",u);
  preParse(T[u].left);
  preParse(T[u].right);

}
void inParse(int u){
  if(u == NIL)
    return;
  inParse(T[u].left);
  printf(" %d",u);
  inParse(T[u].right);
}
void postParse(int u){
  if(u == NIL)
    return;
  postParse(T[u].left);
  postParse(T[u].right);
  printf(" %d",u);
}

int main(){
  int u,n,i,a,left,right;

  scanf("%d",&n);
  for(i = 0; i < n; i++)
    T[i].prev = NIL;
  for(i = 0; i < n; i++){
    scanf("%d %d %d",&a,&left,&right);
    T[a].left = left;
    T[a].right = right;
    if(left != NIL)
      T[left].prev = a;
    if(right != NIL)
      T[right].prev = a;    
  }
  //    NIL
  //     |
  //     2 <-
  //   /   \
  //  1     0
  // / \   / \
  //N   N N   N
  for(i = 0; i < n; i++)
    if(T[i].prev == NIL) u = i;
  
  printf("Preorder\n");
  preParse(u);
  printf("\nInorder\n");
  inParse(u);
  printf("\nPostorder\n");
  postParse(u);
  printf("\n");
  
  return 0;
}



Measured memory_bytes: 2112
S = input()

if S == 'SUN':
    print(7)
if S == 'MON':
    print(6)
if S == 'TUE':
    print(5)
if S == 'WED':
    print(4)
if S == 'THU':
    print(3)
if S == 'FRI':
    print(2)
if S == 'SAT':
    print(1)



Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main() {
	int WH[30][2];
	int W, H;
	int N = 0;
	while (cin >> W >> H) {
		if (W == 0 && H == 0) break;
		WH[N][0] = W;
		WH[N][1] = H;
		N++;
	}
	for (int i = 0; i < N; i++) {
		for (int h = 0; h < WH[i][0]; h++) {
			for (int w = 0; w < WH[i][1]; w++) {
				if ((w + h) % 2 == 0) {
					cout << "#";
				}
				else {
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3068
import sys,collections as cl,bisect as bs,math
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(float,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

a,b = m()

b = int(round(b*100,0))

	


print(int(a)*b//(100))



Measured memory_bytes: 9392
#include <iostream>
#include <vector>
#include <set>
#include <numeric>
#include <algorithm>
// #include <cmath>
// #include <string>
// #include <map>
// #include <iomanip>

// #define MOD 1000000007

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

void p() {
    cout << "\n";
}
template<class Head, class... Body>
void p(Head head, Body... body) {
    cout << head << ",";
    p(body...);
}

template<typename T>
ostream& operator<<(ostream& os, const multiset<T>& s) {
    os << "{";
    for (const auto& i : s) {
        os << i << " ";
    }
    os << "}";
    return os;
}


int main(int argc, char const *argv[]) {
    int N;
    cin >> N;
    vector<int> a(N*3);
    for (int i = 0; i < N*3; ++i) {
        cin >> a[i];
    }

    vector<ll> sum1(N+1), sum2(N+1);
    multiset<int> items1, items2;
    for (int i = 0; i < N; ++i) {
        items1.insert(a[i]);
        items2.insert(a[N*3-1-i]);
    }
    sum1[0] = accumulate(items1.begin(), items1.end(), 0LL);
    sum2[0] = accumulate(items2.begin(), items2.end(), 0LL);
    // p(sum1[0], sum2[0]);

    // cout << items1 << endl;
    // cout << items2 << endl;

    for (int i = 0; i < N; ++i) {
        int added1 = a[N+i];
        items1.insert(added1);
        auto iter1 = items1.begin();
        int deleted1 = *iter1;
        items1.erase(iter1);
        sum1[i+1] = sum1[i] + added1 - deleted1;

        int added2 = a[N*2-1-i];
        items2.insert(added2);
        auto iter2 = prev(items2.end());
        int deleted2 = *iter2;
        items2.erase(iter2);
        sum2[i+1] = sum2[i] + added2 - deleted2;

        // p(i);
        // p(items1);
        // p(items2);
    }

    ll ans = sum1[0] - sum2[N];
    for (int i = 1; i <= N; ++i) {
        ans = max(ans, sum1[i] - sum2[N-i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 12416
#include <vector>
#include <iostream>
using namespace std;
int main(void)
{
    long N;
    cin >> N;
    vector<long> data (N, 0);
    vector<long> c (N, 0);

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

    long count = 0;
    
    for (long j = 0; j < N; j++)
      	c[data[j]-1]++;

    for (long i = 0; i < N; i++)
       count += c[i] * (c[i] - 1) / 2;

    for (long k = 0; k < N; k++)
		cout << (count - c[data[k]-1] +1) << endl;
}

Measured memory_bytes: 5760
k, a, b = gets.split.map(&:to_i)

if b - a <= 2
  puts(k + 1)
else
  if k - a + 1 <= 1
    puts(k + 1)
  else
    move = k - a + 1
    # move.tapp
    if move % 2 == 0
      puts([a + move / 2 * (b - a), k + 1].max)
    else
      puts([a + move / 2 * (b - a) + 1, k + 1].max)
    end
  end
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define to first
#define wgt second 

using namespace std;

const int MAXN=100100;

typedef pair<int,int> pii;
typedef vector<pii> vec;
typedef vector<vec> Graph;

Graph G(MAXN);
int n,d[MAXN];

void SPFA(int s)
{
	queue<int> que;
	fill(d,d+n,INT_MAX);
	d[s]=0;
	que.push(s);
	while(!que.empty())
	{
		int u=que.front();que.pop();
		for(int i=0;i<G[u].size();i++)
			if(d[G[u][i].to]>d[u]+G[u][i].wgt)
			{
				d[G[u][i].to]=d[u]+G[u][i].wgt;
				que.push(G[u][i].to);
			}
	}
}

int main()
{
	int e,r;
	scanf("%d %d %d",&n,&e,&r);
	for(int i=0;i<e;i++)
	{
		int s,t,d;
		scanf("%d%d%d",&s,&t,&d);
		G[s].push_back(make_pair(t,d));
	}
	SPFA(r);
	for(int i=0;i<n;i++)
		if(d[i]==INT_MAX)
			printf("INF\n");
		else
			printf("%d\n",d[i]);
	return 0;
}

Measured memory_bytes: 12472
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }



int main(){
    LL n;
    vector<tuple<string, LL, LL>> d;
    cin >> n;
    for(LL i = 0; i < n; ++i){
        string s;
        LL p;
        cin >> s >> p;
        d.emplace_back(s, -p, i);
    }
    sort(d.begin(), d.end());
    for(LL i = 0; i < n; ++i){
        cout << get<2>(d[i]) + 1 << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    //def
    int n, j, sum=0;
    cin >> n;
    int num[n];
    for(int i=0;i<n;i++){
        cin >> num[i];
    }
    
    //equation
    for(int i=0;i<n;i++){
        for(j=2;j<sqrt(num[i]);j++){
            if(num[i]%j==0){
                break;
            }
        }
        if(j > sqrt(num[i])){
            sum++;
        }
    }
    
    //output
    cout << sum << endl;
    
    return 0;
}


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

using namespace std;

void sol()
{
	int n;
	cin >> n;
	
	int h=0;
	
	while(n>=500)
	{
		h+=1000;
		n-=500;
	}
	
	while(n>=5)
	{
		h+=5;
		n-=5;
	}
	
	cout << h << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	sol();
}

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

count = 0

if N >= 10:
    count += 9
else:
    count += N

if N < 100:
    print(count)
    exit(0)

if N >= 1000:
    count += 1000 - 100
else:
    count += N - 99
    print(count)
    exit(0)

if N < 10000:
    print(count)
    exit(0)

if N >= 100000:
    count += 100000 - 10000
else:
    count += N - 9999

print(count)
exit(0)



Measured memory_bytes: 3060
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()


edges = []
for i in range(M):
    A, B = nl()
    edges.append((A, B))

class UnionFind(object):
    def __init__(self, n):
        self.parents = [i for i in range(n)]
        self.sizes = [1] * n
    def find(self, x):
        if self.parents[x] == x:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.sizes[x] < self.sizes[y]:
            self.parents[x] = y
            self.sizes[y] += self.sizes[x]
        else:
            self.parents[y] = x
            self.sizes[x] += self.sizes[y]

uf = UnionFind(N)
res = [N*(N-1)//2]
for a, b in edges[::-1]:
    ra = uf.find(a-1)
    rb = uf.find(b-1)
    if ra != rb:
        new_res = res[-1] - uf.sizes[ra] * uf.sizes[rb]
    else:
        new_res = res[-1]
    uf.union(a-1, b-1)
    res.append(new_res)

res = res[::-1]
for r in res[1:]:
    print(r)



Measured memory_bytes: 25464
#include<bits/stdc++.h>
using namespace std;
const int N =200005;
string s[N];
set<string>st;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s[i];
		st.insert(s[i]); 
	}
	cout<<st.size()<<endl;
	
}

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

#define     fast()              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define     ll                  long long int
#define     test()              ll t; cin>>t; while(t--) 
#define     lp0(i,begin,end)    for(ll i=begin;i<end;i++)
#define     lp1(i,begin,end)    for(ll i=begin;i<=end;i++)
#define     rlp(i,begin,end)    for(ll i=end;i>=begin;i--)
#define     prec(n)             fixed<<setprecision(n)
#define     initial(a,i)        memset(a,i,sizeof(a))
#define     pb                  push_back
#define     PI                  3.1415926535897932384626433832795
#define     MOD                 1000000007
#define     F                   first
#define     S                   second
#define     all(a)              (a).begin(),(a).end()
#define     BPC(x)              __builtin_popcountll(x)
#define     gcd(a,b)            __gcd(a,b)

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

ll power(ll x,ll n)
{
    ll result = 1;
    while (n)
    {
        if (n & 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}


// Solution Function
void solution(ll compte)
{
    // cout<<compte<<"\n";
    string s, t;
    cin >> s >> t;
    t.pop_back();
    if (s == t)
    cout << "Yes" << endl;
    else
    cout << "No" << endl;

}
// Driver Function
int main()
{
    ll compte = 1;
    //test()
    //{
        solution(compte);
        compte++;
    //}
    return 0;
}


Measured memory_bytes: 3600
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
                
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pretime float(clock()-clk)/CLOCKS_PER_SEC
#define max2(a,b) ((a)>(b) ? (a) : (b))   
#define min2(a,b) ((a)<(b) ? (a) : (b)) 
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i) 
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lli long long int 
#define ins insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
#define inf 1000000000000000

using namespace std;
typedef vector<lli>   vll;
typedef vector<int>   vi;
typedef set<lli>      sll;
typedef set<int>      si;
typedef pair<lli,lli> pll;
typedef pair<int,int> pii;
clock_t clk=clock();       

int i,j;
void solve(void);

int main()
{
  speedio;
   int t=1;  
  // cin>>t;
   while(t--)
     solve();

  return 0;
}
//
vll node[100001];
map < pii , lli > m;
bool vis[100001],col[100001];

void dfs(int idx,lli dist)
{
   vis[idx]=1;
    if(dist%2==1) col[idx]=1;

    int k;
    rep(k,0,sz(node[idx])-1)
     if(vis[ node[idx][k] ]==0)
       dfs( node[idx][k],dist+m[mp(idx,node[idx][k])]) ;

   return;
}
void solve()
{
  int n; cin>>n;
  rep(i,1,n-1)
  {
  	int u,v,w; cin>>u>>v>>w;
    node[u].pb(v);
    node[v].pb(u);
    m[mp(u,v)]=m[mp(v,u)]=w;
  }

  dfs(1,0);
  rep(i,1,n)
   cout<<"\n"<<col[i];
}

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

int main(){
    int n, k;
    string s;
    cin >> n >> s >> k;
    char c = s[k - 1];
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] != c)
        {
            s[i] = '*';
        }
        
    }
    cout << s << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int a[100005];
int gcd(int a, int b)
{
	if (b == 0)return a;
	return gcd(b, a % b);
}
int main()
{
	int n; scanf("%d", &n);
	for (int i = 0; i < n; i++)scanf("%d", &a[i]);
	for (int i = 1; i < n; i++)a[i] = gcd(a[i], a[i - 1]);
	printf("%d\n", a[n - 1]);
	return 0;
}

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

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

string large(string s, string t){
    string ss = "", tt = "";
    int i = 0;
    while(i<s.size() && s[i]=='0')i++;
    while(i<s.size()){
        ss += s[i];
        i++;
    }
    i = 0;
    while(i<t.size() && t[i]=='0')i++;
    while(i<t.size()){
        tt += t[i];
        i++;
    }
    if(ss.size() == tt.size()){
        if(ss>tt) return ss;
        else return tt;
    }else if(ss.size() > tt.size()){
        return ss;
    }else{
        return tt;
    }
}

int main(void) {
    int i,j;
    int h, w;
    while(cin >> w >> h, h+w){
        vs s(h);
        rep(i,h) cin >> s[i];
        vector<vs> dp(h+1,vs(w+1));
        rep(i,h)rep(j,w)if(s[i][j]>='0' && s[i][j]<='9'){
            dp[i+1][j] = large(dp[i+1][j], dp[i][j]+s[i][j]);
            dp[i][j+1] = large(dp[i][j+1], dp[i][j]+s[i][j]);
        }
        string ans="";
        rep(i,h+1)rep(j,w+1)ans = large(ans, dp[i][j]);
        cout << ans << endl;
    }
}



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

const int INF = 1e9 + 10;

template <typename itr> void output(itr first, itr last) {
  for (auto iter = first; iter != last; ++iter) {
    for (int i : *iter) {
      if (i == INF)
        cerr << "INF"
             << ", ";
      else
        cerr << i << ", ";
    }
    cerr << endl;
  }
  cerr << endl;
}

int main() {
  int V, E, r;
  cin >> V >> E >> r;
  vector<int> S(E), T(E), D(E);
  vector<int> C(V, INF);
  bool n_cycle = false;
  vector<bool> checked(V, false);
  C[r] = 0;
  checked[r] = true;
  for (int i = 0; i < E; i++) {
    cin >> S[i] >> T[i] >> D[i];
  }
  for (int i = 0; i < V + 10; i++) {
    bool update = false;
    for (int i = 0; i < E; i++) {
      int s = S[i], t = T[i], d = D[i];
      if (checked[s] && C[s] + d < C[t]) {
        C[t] = C[s] + d;
        checked[t] = true;
        update = true;
      }
    }
    if (!update) {
      break;
    }
    if (i == V + 1) {
      n_cycle = true;
      break;
    }
  }
  if (n_cycle) {
    cout << "NEGATIVE CYCLE" << endl;
    return 0;
  }
  for (int i : C) {
    if (i == INF)
      cout << "INF" << endl;
    else
      cout << i << endl;
  }
}



Measured memory_bytes: 3116
(let* ((n (read))
    (a (make-array n))
    (mae 0)
    (ans 0))
    (loop for i below n do
        (setf (aref a i) (read))
    )
    (loop for i below n do
        (if (<= (aref a i) mae)
        (progn
            (incf ans (- mae (aref a i)))
            (setf mae (+ (aref a i) (- mae (aref a i))))
        )
        (setq mae (aref a i))
        )
    )
    (princ ans)
)

Measured memory_bytes: 78576
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		long sum = B-A+1;
		long maxC = B/C;
		long minC = A/C;
		long maxD = B/D;
		long minD = A/D;
		Main main = new Main();
		long gcd = main.gcd(C, D);
		long maxCD = B/((C*D)/gcd);
		long minCD = A/((C*D)/gcd);
		sum =sum -(maxC-minC);
		if (A%C==0) {
			sum--;
		}
		sum =sum -(maxD-minD);
		if (A%D==0) {
			sum--;
		}
		sum =sum +(maxCD-minCD);
		if (A%(((C*D)/gcd))==0) {
			sum++;
		}
		System.out.println(sum);
	}

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

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

const int MOD = 1e9 + 7;

long long n;
long long dp[1500000];
long long s = 0;

int main()
{
    cin >> n;
    dp[0] = 1;
    dp[1] = 1;
    s = 2;
    for (int i = 2; i <= n; i++)
    {
        dp[i] = (s + MOD - dp[i - 2]) % MOD;
        s = (dp[i] + s) % MOD;
        //cout << dp[i] << "\n";
    }
    long long ans = 0;
    for (int i = 0; i + 1 < n; i++)
    {
        ans = (ans + ((n - 1) * (n - 1) + i + 1) % MOD * dp[i]) % MOD;
    }
    ans = (ans + dp[n - 1] * (n - 1)) % MOD;
    ans = (ans + dp[n])  % MOD;
    cout << ans % MOD;
}


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


def read(): return list(map(int, input().split()))


data = read()
flag = True
for i in data:
    if (i % 2 == 0):
        if (i % 3 != 0 and i % 5 != 0):
            flag = False
            break
if (flag == True):
    print('APPROVED')
else:
    print('DENIED')


Measured memory_bytes: 2940
#include <iostream>
#include <vector> //可変長配列
#include <queue> //キュー
#include <unordered_map> //ハッシュ連想配列
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define ll long long int
#define INFTY (1<<21)
#define maxN 100

using namespace std;

int main(void){
    cin.sync_with_stdio(false);
    int N; cin>>N;
    vector<int> a;
    for(int i = 0; i < N; i++){
        int t; cin>>t; a.push_back(t);
    }
    sort(a.begin(), a.end(), greater<int>());
    int ans=0;
    for(int i = 0; i < N; i++){
        if(i%2==0) ans+=a[i];
        else ans-=a[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#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(){
    int count=0;
    int max=0; 
    int l;   
    string s;
    cin>>s;
    l=s.size();
    rep(i,l){
        count=0;
          
            for(int j=i;j<l;j++){
            if(!(s[j]=='A'||s[j]=='G'||s[j]=='C'||s[j]=='T')){
            break;
            }
            count++;
            }
        
        if(max<=count)max=count;
    }

    cout<<max;
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#define ALL(X) X.begin(), X.end()
#define SZ(A) int((A).size())
#define RALL(X) X.rbegin(), X.rend()
#define FOR(B) for (size_t i = 0; i < B; i++)
#define FOR2(B) for (size_t j = 0; j < B; j++)
#define FORE(B) for (size_t i = 1; i <= B-1; i++)
#define FORC(A, B) for (size_t i = A; i < B; i++)
#define PRINT(X) cout << X << endl
#define PRINTALL(E, X) { FOR(X) {cout << E[i] << endl; } }
#define PRINTSIDE(E, X) { FOR(X) {cout << E[i] << " ";} }
#define READALLI(V, N) FOR(N) {int x; cin >> x; V.push_back(x); }
#define READALL(V, N) FOR(N) {LL x; cin >> x; V.push_back(x); }
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXN 100000
#define SQRSIZE  317
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<LL>VL;
typedef vector<PII> VPII;
typedef map<int, int> MII;
typedef map<char, int>MCI;
typedef map<string, int> MSI;
typedef set<int> SI;
const int INF = (1 << 30);

struct Route{
    int cost, time = 0;

};

bool routeSort(Route e, Route w){ return e.time < w.time; };

int main() {

   int n, t;
   n = t = 0;
   cin >> n >> t;
    vector<Route> routes;
   for(int q = 0; q < n; q++){
       int cost, time;
       cost = time = 0;
       cin >> cost >> time;
       Route r;
       r.cost = cost;
       r.time = time;
       routes.push_back(r);
   }
   sort(routes.begin(), routes.end(), routeSort);
   int ans = 1e6;
   if(routes[0].time > t){
       cout << "TLE\n";
       return 0;
   }
   for(int q = 0; q < routes.size(); q++){
       if(routes[q].time <= t)
           ans = min(routes[q].cost, ans);
       //cout << routes[q].cost << " time: " << routes[q].time << "\n";
   }
    cout << ans << endl;
    return 0;
}






Measured memory_bytes: 256
// 配りDP
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}

const long long INF = 1LL << 60;

int N;
long long h[100010];

// dp
long long dp[100010];

int main() {
    int N,K; cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化
    for (int i = 0; i < 100010; ++i) dp[i] = INF;
    dp[0] = 0;

    for (int i = 0; i < N; i++) {
        for (int j = 1; j <= K; j++) {
            if (i+j < N) {
                chmin(dp[i+j], dp[i]+abs(h[i] - h[i+j]));
            }
        }
    }

    // for (int i = 1; i < N; ++i) {
    //     for (int j = 1; j <= K; ++j) {
    //         if (i > j-1) chmin(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    //     }
    // }

    cout << dp[N-1] << endl;
}


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

public class Main {

	private static Scanner sc;

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
	}

	private void solve() {
        try {
        	long start = System.currentTimeMillis();
        	long N = sc.nextLong();
        	long K = sc.nextLong();
        	long plus = N % K;
        	long minus = - (plus - K);

        	if(plus<=minus) {
        		System.out.println(plus);
        	}else {
        		System.out.println(minus);
        	}


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

	private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }

}


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

int  num[1024];
int  scr[1024];
int  swp[1024][1024];
bool bar[1024][1024];

int main()
{
	int N,M,H,K;
	while(cin>>N>>M>>H>>K, N||M||H||K)
	{
		for(int i=0; i<N; i++)
		{
			cin >> scr[i];
		}

		memset(bar, 0, sizeof(bar));
		for(int i=0; i<M; i++)
		{
			int a,b;
			cin >> a >> b;
			bar[b-1][a-1] = true;
		}

		for(int i=0; i<N; i++)
		{
			num[i] = i;
		}

		memset(swp, 0, sizeof(swp));
		for(int h=H-2; h>=0; h--)
		for(int i=0; i<N-1; i++)
		{
			if(bar[h][i])
			{
				swp[num[i]][num[i+1]] = 1;
				swp[num[i+1]][num[i]] = 1;
				swap(num[i],num[i+1]);
			}
		}

		int ans = 0;
		for(int i=0; i<K; i++)
		{
			ans += scr[num[i]];
		}

		int dif = 0;
		for(int i=0; i<K; i++)
		for(int j=K; j<N; j++)
		{
			if(swp[num[i]][num[j]])
			{
				dif = max(dif, scr[num[i]]-scr[num[j]]);
			}
		}

		cout << ans-dif << endl;
	}
}

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

int main()
{
	int n, taro = 0, hanako = 0;
	string a, b;
	cin >> n;
	while (n--) {
		cin >> a >> b;
		if (a < b) {
			hanako += 3;
		}
		else if (a == b) {
			taro++;
			hanako++;
		}
		else {
			taro += 3;
		}
	}
	cout << taro << ' ' << hanako << endl;
	return 0;
}

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

long long int dp[102][22];

int main()
{
  int n,sum=0,number[102]={};
  cin>>n;
  for(int i=1;i<n;i++){
    cin>>number[i];
  }
  int last;
  cin >> last;
  dp[1][number[1]]=1;
  for(int i=2;i<=n-1;i++){
    for(int j=0;j<=20;j++){
      if(dp[i-1][j]!=0){
        if((j-number[i])>=0){
          dp[i][j-number[i]]+=dp[i-1][j];
        }
        if((j+number[i])<=20){
          dp[i][j+number[i]]+=dp[i-1][j];
        }
      }
    }
  }
  cout<<dp[n-1][last]<<endl;
  return 0;
}

Measured memory_bytes: 1172
#include <stdio.h>
int main() {int RB[10],N,i,j;while (scanf("%d",&N)!=EOF && N) {i=0;while (i<10) RB[i++]=0;while (N--) scanf("%d",&i),RB[i]++;i=0;while (i<10) {if (!RB[i]) putchar('-');for (j=0;j<RB[i];putchar('*'),j++);puts(""),i++;}} return 0;}

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

bool *prime(){
    bool* isP=new bool[1001];
    isP[0]=isP[1]=false;
    for(int i=2;i<=1000;i++) isP[i]=true;
    
    for(int i=2;i<=1000;i++){
        if(isP[i]){
            for(int j=2;i*j<=1000;j++) isP[i*j]=false;
        }
    }

    return isP;
}

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

    int cnt[1001];
    for(int i=0;i<=1000;i++) cnt[i]=0;
    bool *isP;
    isP=prime();
    for(int i=2;i<=N;i++){
        for(int j=2;j<=i;j++){
            if(isP[j]){
                for(int chk=i;chk%j==0;chk/=j){
                    cnt[j]++;
                }                
            }
        }
    }

    long long res=1;
    for(int i=0;i<=N;i++){
        res=(res*(cnt[i]+1))%1000000007;
    }

    cout << res << endl;

    delete[] isP;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc=new Scanner(System.in);
    	int n=sc.nextInt();
    	int[] x=new int[n];
    	boolean can = true;
    	for(int i=0;i<n;i++)
    		x[i] = sc.nextInt();
    	Arrays.sort(x);
    	for(int i=0;i<n-1;i++) {
    		if(x[i]==x[i+1]) {
    			can = false;
    				break;
    		}
    	}
    	String s = can?"YES":"NO";
    	System.out.println(s);
	}
}

Measured memory_bytes: 65332
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.S;
		var n=s.Length;
		var m=sc.I;
		var dp=new int[m+1][][];
		for(int i = 0;i<=m;i++) {
			dp[i]=new int[n][];
			for(int j = 0;j<n;j++) {
				dp[i][j]=new int[n-j];
				for(int k = 0;k+j<n;k++) {
					if(j==0){dp[i][j][k]=1;}
					else if(j==1){
						if(s[k]==s[k+j]||i>0){dp[i][j][k]=2;}
						else{dp[i][j][k]=1;}
					}
					else if(s[k]==s[k+j]){dp[i][j][k]=dp[i][j-2][k+1]+2;}
					else{
						dp[i][j][k]=Max(dp[i][j-1][k],dp[i][j-1][k+1]);
						if(i>0){dp[i][j][k]=Max(dp[i][j][k],dp[i-1][j-2][k+1]+2);}
					}
				}
			}
		}
		Console.WriteLine("{0}",dp[m][n-1][0]);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

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

public class P
{
    public char c { get; set; }
    public int L { get; set; }
}

public class hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var ps = getP(s);
        var ans = getAns(ps);
        Console.WriteLine(ans);
    }
    static int getAns(List<P> ps)
    {
        var ans = 0;
        var psc = ps.Count();
        for (int i = 0; i <= psc - 3; i++)
        {
            if (ps[i].c == 'J' && ps[i + 1].c == 'O' && ps[i + 2].c == 'I' && 
               ps[i].L >= ps[i + 1].L && ps[i + 2].L >= ps[i + 1].L) ans = Max(ans, ps[i + 1].L);
        }
        return ans;
    }
    static List<P> getP(string s)
    {
        var sL = s.Length;
        var ans = new List<P>();
        var nc = s[0]; var count = 1;
        var p = 1;
        while (p < sL)
        {
            if (s[p] == nc) count++;
            else
            {
                ans.Add(new P { c = nc, L = count });
                nc = s[p];
                count = 1;
            }
            p++;
        }
        if (count > 0) ans.Add(new P { c = nc, L = count });
        return ans;
    }
}



Measured memory_bytes: 53524
#include <iostream>

using namespace std;

bool p(const string& str, size_t l, size_t r) {
    int ll = l;
    int rr = r - 1;
    while (ll <= rr) {
        if (str[ll] != str[rr]) return false;
        ++ll;
        --rr;
    }
    return true;
}

int main() {
    
    string str;
    cin >> str;
    if (p(str, 0, str.size()) && p(str, 0, (str.size() - 1) / 2) && p(str, (str.size() + 1) / 2, str.size())) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll x;
    cin >> x;
    if(1200 > x) cout << "ABC";
    else cout << "ARC";
    cout << endl;
    return 0;
}


Measured memory_bytes: 3536
#include<bits/stdc++.h>
using namespace std;
int N, M;
vector<vector<int>> connect;
vector<bool> visited;
bool DFS(int curr, int num) {
	if (curr == N) return true;
	if (num >= 3) return false;
	visited[curr] = true;
	for (int n : connect[curr]) {
		if (visited[n]) continue;
		if (DFS(n, num + 1)) {
			return true;
		}
	}
	return false;
}

int main() {
	cin >> N >> M;
	connect = vector<vector<int>>(N + 1, vector<int>());
	visited = vector<bool>(N + 1, false);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		connect[a].push_back(b);
		connect[b].push_back(a);
	}
	if (DFS(1, 1)) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 12016
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var n int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &n)

	for i := 1; i <= 9; i++ {
		if 111*i >= n {
			fmt.Println(111 * i)
			break
		}
	}
}


Measured memory_bytes: 1840
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

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

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

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

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

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

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

vector<int> tpsort(vector<vector<int>>& G) {
    int V = G.size();
    vector<int> sorted_vertices;
    queue<int> que;
    vector<int> indegree(V);
    for (int i = 0; i < V; i++) {
        for (int j = 0; j < G[i].size(); j++) {
            indegree[G[i][j]]++;
        }
    }
    for (int i = 0; i < V; i++) {
        if (indegree[i] == 0) {
            que.push(i);
        }
    }
    while (que.empty() == false) {
        int v = que.front();
        que.pop();
        for (int i = 0; i < G[v].size(); i++) {
            int u = G[v][i];
            indegree[u] -= 1;
            if (indegree[u] == 0) que.push(u);
        }
        sorted_vertices.push_back(v);
    }
    return sorted_vertices;
}

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> z(n);
    for (int i = 0; i < n; i++) {
        cin >> z[i];
    }
    sort(z.begin(), z.end());
    vector<bool> bol(k+1,true);
    for (int i = 0; i < k+1; i++) {
        for (int j = 0; j < n; j++) {
            if (i - z[j] < 0)break;
            if (bol[i - z[j]] == true)bol[i] = false;
        }
    }
    if (bol[k] == false)cout << "First" << endl;
    else cout << "Second" << endl;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(){
    int S,h,m,s;
    
    0 <= S <= 86400;
    
    scanf("%d",&S);
    
    s = (S % 3600) % 60;
    m = (S % 3600) / 60;
    h = S / 3600;
    
    printf("%d:%d:%d\n",h,m,s);
    
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    long long A[N],sum1;
    sum1=0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        sum1 += (2*((i+1)%2)-1)*A[i];
        //cout << "sign sum1 = " << (2*((i+1)%2)-1) << " " << sum1 << endl;
    }

    for(int i=0; i<N; i++){
        if(i==0){
            cout << sum1 << " ";
        }else{
            sum1=-sum1+2*A[i-1];
            cout << sum1;
            if(i!=N-1) cout << " ";
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

class tree {
public:
	int t_d;
	vector<tree> t_child;
	tree* t_par;
	tree(int d, tree* par);
	int solve();
};

tree::tree(int d, tree* par) {
	t_d = d;
	t_par = par;
}

int tree::solve() {
	int sz = t_child.size();
	if (sz == 0) {
		return t_d;
	} else {
		vector<int> v;
		for (int i = 0; i < sz; i++) {
			v.push_back((t_child[i]).solve());
		}
		sort(v.begin(), v.end());
		int c = 0;
		for (int i = 0; i < (sz+1)/2; i++) {
			c += v[i];
		}
		return c;
	}
}

int main() {
	int n;
	cin >> n;
	string a;
	for (int i = 0; i < n; i++) {
		cin >> a;
		tree z(0, NULL);
		tree* pz = &z;
		int counter = 0;
		int sz = a.size();
		for (int j = 1; j < sz-1; j++) {
			if (a[j] == '[') {
				((*pz).t_child).push_back(tree(0, pz));
				int psz = ((*pz).t_child).size();
				pz = &((*pz).t_child)[psz-1];
			} else if (a[j] == ']'){
				counter /= 2;
				counter++;
				if (((*pz).t_child).size() == 0) {
					(*pz).t_d = counter;
				} 
				counter = 0;
				pz = (*pz).t_par;
			} else {
				counter *= 10;
				counter += a[j]-'0'; 
			}
		}
		cout << z.solve() << endl;
	}
	return 0;
}

Measured memory_bytes: 1484
card_gate = input().split()
card = int(card_gate[0])
gate = int(card_gate[1])
L_list = []
R_list = []

for i in range(0, gate):
    id_list = input().split()
    L_list.append(int(id_list[0]))
    R_list.append(int(id_list[1]))

print(len(range(max(L_list), min(R_list)+1)))


Measured memory_bytes: 10996
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
xyz = []
for _ in range(n):
    line = list(map(int, input().split()))
    xyz.append(line)

score = -1
for xo in [1,-1]:
    for yo in [1,-1]:
        for zo in [1,-1]:
            idx = sorted(range(n), reverse=True, key=lambda i:xo*xyz[i][0]+yo*xyz[i][1]+zo*xyz[i][2])
            X = 0
            Y = 0
            Z = 0
            for i in range(m):
                X += xyz[idx[i]][0]
                Y += xyz[idx[i]][1]
                Z += xyz[idx[i]][2]
            score = max(score, abs(X)+abs(Y)+abs(Z))

print(score)


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

using ll = long long int;
using P = std::pair<ll, ll>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rag(con) std::begin(con), std::end(con)

constexpr int V = 1e5 + 5;

std::vector<int> to[V * 2];

bool used[V * 2];

P operator+(const P &lhs, const P &rhs)
{

    return P(lhs.first + rhs.first, lhs.second + rhs.second);
}

P dfs(int x)
{
    P res(0, 0);
    for (auto y : to[x])
    {
        if (!used[y])
        {
            used[y] = 1;
            res = res + dfs(y);
        }
    }
    return res + ((x < V) ? P(1, 0) : P(0, 1));
}

int main()
{
    int n;

    std::cin >> n;

    rep(i, n)
    {
        int x, y;
        std::cin >> x >> y;
        y += V;
        to[x].push_back(y);
        to[y].push_back(x);
    }

    ll ans = 0;

    rep(i, V * 2)
    {
        if (!used[i])
        {
            used[i] = 1;
            P p = dfs(i);
            ans += p.first * p.second;
        }
    }

    std::cout << ans - n << std::endl;

    return 0;
}

Measured memory_bytes: 15308
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.Keyence
{
    class C
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] array = ReadInts();
            int[] bArray = ReadInts();
            long aSum = 0;
            long bSum = 0;
            for(int i = 0; i < n; i++)
            {
                aSum += array[i];
                bSum += bArray[i];
            }
            if (aSum < bSum)
            {
                Console.WriteLine(-1);
                return;
            }
            var pluses = new List<int>();
            long minusSum = 0;
            int minusCnt = 0;
            for (int i = 0; i < n; i++)
            {
                if (array[i] < bArray[i])
                {
                    minusSum += bArray[i] - array[i];
                    minusCnt++;
                }
                if (array[i] > bArray[i]) pluses.Add(array[i] - bArray[i]);
            }
            if (minusCnt == 0)
            {
                Console.WriteLine(0);
                return;
            }
            if (minusSum == 0)
            {
                Console.WriteLine(minusCnt);
                return;
            }

            long pSum = 0;
            pluses.Sort();
            pluses.Reverse();
            for (int i = 0; i < pluses.Count; i++)
            {
                pSum += pluses[i];
                if (pSum >= minusSum)
                {
                    Console.WriteLine(minusCnt + i + 1);
                    return;
                }
            }
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 37724
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;

int main(void){
    int n,l;cin>>n>>l;
    string s[n];
    for(int i=0;i<n;i++)cin>>s[i];
    sort(s,s+n);
    for(int i=0;i<n;i++)cout<<s[i];
    cout<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define max(X, Y) ((X) > (Y) ? (X) : (Y))

int main()
{
    int n;
    int ans = 0;
    int tmp;
    int maxv = -1;

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &tmp);

        ans += tmp;

        maxv = max(maxv, tmp);
    }

    ans = ans - (maxv / 2);

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

    return 0;
}


Measured memory_bytes: 128
def main():
    S = [i for i in input()]
    O = S[:]
    K = int(input())
    if len(S) == 1:
        return K // 2
    r = 0
    for i in range(1, len(S)):
        if S[i] == S[i - 1]:
            r += 1
            S[i] = S[i].upper()
    if S[-1] != S[0]:
        return r * K

    S = S + O
    p = 0
    for i in range(len(O), len(S)):
        if S[i] == S[i - 1]:
            p += 1
            S[i] = S[i].upper()
    if S[-1] == S[0]:
        return r + p * (K - 1)
    return (r + p) * (K // 2) + r * (K % 2)
   

print(main())


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    int a[n];
    int count=1;
     int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum=sum+a[i];
        if(sum<=x)
        {
            count++;
        }
    }
    cout<<count<<endl;
    
    
}

Measured memory_bytes: 3560