akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)

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

  string digit;
  bool same = true;
  for (int i = N; i < 1000; i++)
  {
    digit = to_string(i);
    same = true;
    if (digit.at(0) != digit.at(1) || digit.at(1) != digit.at(2)){
      same = false;
    }
    if (same){
      cout << i << endl;
      break;
    }
  }
  
}

Measured memory_bytes: 3704
#include<stdio.h>

//クイックソート
void quicksort(int a[], int first, int last) {

	int i, j;
	int x, t;

	x = a[(first + last) / 2];
	i = first;
	j = last;
	for (;;) {
		while (a[i] < x)i++;
		while (x < a[j])j--;
		if (i >= j)break;
		t = a[i];
		a[i] = a[j];
		a[j] = t;
		i++;
		j--;
	}
	if (first < i - 1)quicksort(a, first, i - 1);
	if (j + 1 < last)quicksort(a, j + 1, last);
}

int main(void) {

	int i;
	int n;
	int a[100000];

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	quicksort(a, 0, n - 1);

	printf("%d\n", a[n - 1] - a[0]);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define N_PRIME 1000000007
#define ll int64_t


int main(void){
    bool s[128] = {false};
    int a,b,c;
    int count = 0;
    cin >> a>> b>>c;
    
    s[a] = true;
    count++;
    if( s[b] == false ){
        s[b] = true;
        count++;
    }
    if( s[c] == false ){
        s[c] = true;
        count++;
    }
    cout << count << endl;
    
    return 0;
}

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

int main(){
    int n,m;
    int tmp;
    int ch[1001];
    int ch1[1002];
    while(1){
        memset(ch,0,sizeof(ch));
        cin >> n >> m;
        for(int i=0;i<m;i++) ch1[i] = i+1;
        if(n == 0 && m == 0) break;
        int num[n][m];
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                cin >> num[i][j];
                if(num[i][j] == 1){
                    ch[j]++;
                }
            }
        }
        for(int i=0;i<m-1;i++){
            for(int j=m-1;j>i;j--){
                if(ch[j] > ch[j-1]){
                    tmp = ch[j];
                    ch[j] = ch[j-1];
                    ch[j-1] = tmp;
                    tmp = ch1[j];
                    ch1[j] = ch1[j-1];
                    ch1[j-1] = tmp;
                }
            }
        }
        for(int i=0;i<m;i++){
            if(i == m-1) cout << ch1[i] << endl;
            else cout << ch1[i] << " ";
        }
    }
}

Measured memory_bytes: 1556
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt();
        String [] array = new String[n];
        for (int i = 0; i < n; i++) array[i] = in.next();
        List<String> list = new ArrayList<>();
        list.add(array[0]);
        char c = array[0].charAt(array[0].length()-1);
        for (int i = 1; i < n; i++){
            if (list.contains(array[i]) || array[i].charAt(0) != c){
                System.out.println("No");
                return;
            }
            c = array[i].charAt(array[i].length()-1);
            list.add(array[i]);
        }
        System.out.println("Yes");
    }
    
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if (s.substr(0, 4) == "YAKI") cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;
string s;
vi dp;

int main(){
	cin>>n>>s;
	dp=vi(n+1);
	dp[0]++;
	for(int i=0;i<n-1;i++){
		vi DP(n+1);
		for(int j=0;j<n;j++){
			if(s[i]=='>'){
				(DP[0]+=dp[j])%=mod;
				(DP[j+1]+=mod-dp[j])%=mod;
			}
			else{
				(DP[j+1]+=dp[j])%=mod;
				(DP[i+2]+=mod-dp[j])%=mod;
			}
		}
		for(int j=0;j<n;j++) (DP[j+1]+=DP[j])%=mod;
		dp=DP;
	}
	int res=0;
	for(auto i:dp) (res+=i)%=mod;
	cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int MOD = 1000000007;
const int INF = 2000000000;
const long double PI = acosl(-1);
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    string S;
    cin >> S;

    int ans = 0;
    if (S == "hi" || S == "hihi" || S == "hihihi" || S == "hihihihi" || S == "hihihihihi") yes;
    else no;
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/hitachi2020/hitachi2020_a && sh test.sh
cd ~/Desktop/Programming/AtCoder/contest/hitachi2020/hitachi2020_a && sh etest.sh
cd ~/Desktop/Programming/AtCoder/contest/hitachi2020/hitachi2020_a && sh submit.sh
*/


Measured memory_bytes: 256
import sys

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

if N%2!=0 :
  print("No")
  sys.exit(0)
else:
  for i in range(int(N/2)):
      if S[i]!=S[i+int(N/2)]:
        print("No")
        sys.exit(0)
print("Yes")

Measured memory_bytes: 9088
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
*/public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
static class TaskC   {
public void solve(int testNumber, Scanner in, PrintWriter out) {
        int N = in.nextInt();
        int po[][] = new int[2][N];
        int h[] = new int[N];
        for (int i=0; i<N; i++) {
            po[0][i] = in.nextInt();
            po[1][i] = in.nextInt();
            h[i] = in.nextInt();
        }
        for(int cx = 0; cx<=100; cx++){
            loop:for(int cy = 0; cy<=100; cy++){
                int H = 0;
                ArrayList<Integer> pos0 = new ArrayList<>();
                for(int i = 0; i<N; i++){
                    if(h[i] == 0) {
                        pos0.add(i);
                        continue ;
                    }
                    if(H == 0) H = h[i] + Math.abs(po[0][i] - cx) + Math.abs(po[1][i] - cy);
                    if(h[i] + Math.abs(po[0][i] - cx) + Math.abs(po[1][i] - cy) != H) continue loop;
                }
                for(int i : pos0){
                    if(H - Math.abs(po[0][i] - cx) - Math.abs(po[1][i] - cy) > 0){
                        continue loop;
                    }
                }
                out.println(cx+" "+cy+" "+H);
            }
        }
    }

}
}



Measured memory_bytes: 36176
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <climits>
#include <sstream>
using namespace std;

static const unsigned long long int MOD = 1000000007LL;

int n, res = 0;
int a[100001], b[100001];

int main()
{
    cin >> n;

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

    for (int i = n - 1; i >= 0; i--)
    {
        int *id = upper_bound(b, b + n, a[i]);
        int pos = (int)(id - b);
        b[pos] = a[i];
        if (pos > res)
        {
            res = pos;
        }
    }

    cout << res + 1 << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long, long long> ii; 
typedef vector<ii> vii;  
typedef vector<ll> vi;
#define PI acos(-1)
#define endl "\n"
#define f first 
#define s second
#define pb push_back
#define mp make_pair
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

void arrayIn(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
void arrayOut(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cout << A[K]<<' '; } }
vector<int> Graph[100001];	
vector<bool> visited(100001);
//DFS
void DFS(int root) {
	visited[root] = 1;
	cout << root << endl;
	for (int j = 0; j < Graph[root].size(); j++)	{
		if (!visited[Graph[root][j]]) {
			DFS(Graph[root][j]);
		}
	}
}
//BFS
void BFS() {
	queue<int> stored;
	stored.push(1);
	while (!stored.empty())
	{
		int t = stored.front();
		stored.pop();
		cout << t << " ";
		for (int i = 0; i < Graph[t].size(); i++){
			stored.push(Graph[t][i]);
			cout << Graph[t][i] << " ";
		}
		cout << endl;
	}
}

//declare variable-------------------------------------------------------------
	string s;
	ll r[200000];


//--------------------------------------------------------------------------
int main(){
	FASTIO;
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif*/
	// CODE--------------------------------------------------------------
	cin>>s;
	ll n=s.length();
	memset(r,0,n);
	ll k=-1;
	ll cont=0;
	ll R=0,L=0;
	for(ll i=0;i<n;i++){
		cont++;
		if(s[i]=='R'){
			R++;
		}
		else{
			L++;
		}
		if(s[i]=='R' && s[i+1]=='L'){
			k=i;
		}
		if( i+1==n || (s[i]=='L' && s[i+1]=='R') ){
			
			if( R%2==1 && L%2==0 ){
				r[k+1]=cont/2;
				r[k]=cont-r[k+1];
			}
			else{
				r[k]=cont/2;
				r[k+1]=cont-r[k];
			}
			cont=0;
			R=0;
			L=0;
		}
	}
	arrayOut(r,n);


//---------------------------------------------------------------------
	return 0;
}

Measured memory_bytes: 3792
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <math.h>
#define rep(i,n) for(int i = 0; i <(n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

int main(void) {
	ll i, j, k,tmp;
	vector<ll>dp;
	vector<ll>h;
	ll N;
	scanf("%lld", &N);
	for (i = 0; i < N; i++) {
		scanf("%lld", &tmp);
		h.push_back(tmp);
		dp.push_back(INF);
	}
	dp.at(0LL) =0;
	dp.at(1LL) = abs(h.at(1) - h.at(0));
	for (i = 2LL; i < N; i++) {
		chmin(dp.at(i), dp.at(i - 1LL) + abs( h.at(i) - h.at(i - 1LL)));
		chmin(dp.at(i), dp.at(i - 2LL) + abs( h.at(i) - h.at(i - 2LL)));
	}
	printf("%lld\n", dp.at(N - 1));
	return 0;
}

Measured memory_bytes: 2036
#include<stdio.h>

int main(void){
	int a, b, wa, keta;
	
	keta = 0;
	
	while(scanf("%d %d", &a, &b)!=EOF){
		keta = 0;
		
		wa = a+b;
		
		if(wa==0){
			keta++;
		}else{
			while(wa!=0){
				wa = wa/10;
				keta++;
			}
		}
		printf("%d\n",keta);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
    int w,a,b;
    cin >> w >> a >> b;
    int ans;
    if(a<=b){
        if(a+w>=b)ans=0;
        else ans=b-a-w;
    }
    else if(b<a){
        if(b+w>=a)ans=0;
        else ans=a-b-w;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Objects;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) {
		FastScanner cin = new FastScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(FastScanner cin, PrintWriter cout) {
		// 自前の例
		assert Objects.equals(
				solve(4, 5, new int[][] { { 1, 4, 1 }, { 2, 3, 1 }, { 3, 2, 1 }, { 3, 4, 1 }, { 1, 2, 1 } }), "inf");
		// 問題の例
		assert Objects.equals(solve(3, 3, new int[][] { { 1, 2, 4 }, { 2, 3, 3 }, { 1, 3, 5 } }), "7");
		assert Objects.equals(solve(2, 2, new int[][] { { 1, 2, 1 }, { 2, 1, 1 } }), "inf");
		assert Objects.equals(solve(6, 5, new int[][] { { 1, 2, -1000000000 }, { 2, 3, -1000000000 },
				{ 3, 4, -1000000000 }, { 4, 5, -1000000000 }, { 5, 6, -1000000000 } }), "-5000000000");

		int n = cin.nextInt();
		int m = cin.nextInt();
		int[][] abcs = new int[m][];
		for (int i = 0; i < abcs.length; i++)
			abcs[i] = new int[] { cin.nextInt(), cin.nextInt(), cin.nextInt() };

		String ans = solve(n, m, abcs);
		cout.println(ans);
	}

	private static String solve(int n, int m, int[][] abcs) {
		int[][] edges = new int[abcs.length][];
		for (int i = 0; i < abcs.length; i++)
			edges[i] = new int[] { abcs[i][0] - 1, abcs[i][1] - 1, -abcs[i][2] };
		long[] costs = new long[n];
		Arrays.fill(costs, Long.MAX_VALUE / 2);
		costs[0] = 0;
		for (int i = 0; i < n; i++)
			for (int[] e : edges)
				costs[e[1]] = Math.min(costs[e[1]], costs[e[0]] + e[2]);
		long ans1 = costs[n - 1];
		for (int[] e : edges)
			costs[e[1]] = Math.min(costs[e[1]], costs[e[0]] + e[2]);
		long ans2 = costs[n - 1];

		if (ans1 != ans2)
			return "inf";
		else
			return Long.toString(-ans1);
	}

	/**
	 * How to read input in Java — tutorial <br />
	 * By Flatfoot<br />
	 * http://codeforces.com/blog/entry/7018
	 */
	static class FastScanner {
		private BufferedReader br;
		private StringTokenizer st;

		FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new IllegalStateException(e);
				}
			return st.nextToken();
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				throw new IllegalStateException(e);
			}
			return str;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


Measured memory_bytes: 22688
#include<bits/stdc++.h>
    using namespace std;
    
    #define ll long long
    #define pb push_back
    #define printV(v) for(int i=0;i<v._size();i++){cout << v[i]<< " ";} cout << endl
    #define printRev(v) for(int i=v._size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
    #define sortV(v) sort(v.begin(),v.end())
    #define revV(v) reverse(v.begin(),v.end())
    #define FOR(i,from,n) for(int i=from;i<n;i++)
    #define FOL(i,from,n) for(int i=from;i >= n;i--)

        ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,p,q,y;
        string str = "";
        ll mod = 1e9 + 7;

        ll pow(ll base, ll q, ll mod){
            ll answer = 1;
            while(q > 0){
                if(q & 1LL)
                    answer = (answer * base) % mod;

                q = q >> 1LL;
                base = (base*base) % mod;
            }
            return answer % mod;
        }
        

        
        
        void solve(){
            ll n1,n2;
            cin >> n1 >> n2 >> t;
            vector<ll> v1(n1+1);
            vector<ll> v2(n2+1);
            for(int i=0;i<n1;i++)cin>>v1[i];
            for(int i=0;i<n2;i++)cin>>v2[i];
            ll L = -1;
            ll R = n2-1;
            ll mx = 0;
            vector<ll> dp1(n1,v1[0]);
            vector<ll> dp2(n2,v2[0]);
            for(int i=1;i<n1;i++) dp1[i] = dp1[i-1] + v1[i];
            for(int i=1;i<n2;i++) dp2[i] = dp2[i-1] + v2[i];


            while(L < n1){
                if(L == -1) a = 0;
                else a = dp1[L];
                if(a > t) break;
                while(R >= 0 && dp2[R] + a > t){
                    R--;
                }
                mx = max(mx, L + R + 2);
                L++;
            }
            cout << mx << endl;


        }



            



        int main(){
            ios_base::sync_with_stdio(false);

         

            

            int cases = 1;
            //cin >> cases;

            while(cases--) solve();
            return 0;

        }

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

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

    vector<vector<int>> vec(M);

    for(int i=0; i < M; ++i)
    {
        int k; cin >> k;
        vec[i].resize(k);
        for(int j=0; j<k; ++j)
        {
            cin >> vec[i][j];
            --vec[i][j];
        }
    }

    vector<int> p(M);
    for(int i=0; i < M ; ++i) cin >> p[i];

    int ans = 0;

    for(int i=0;i < (1<<N); ++i)
    {
        bool ok = true;
        for(int j=0; j < M; ++j)
        {
            int c = 0;
            for(int id : vec[j])
            {
                if((i>>id)&1)
                {
                    ++c;
                }
            }
            c%=2;
            if(c!=p[j])
            {ok = false;
            }
        }
        if(ok)
        {
            ans++;
        }  
    }

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

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    string s;cin >> s;
    cout << 700+((s[0] == 'o') + (s[1] == 'o') + (s[2] == 'o'))*100 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;

#define rep(i,j,k) for(register int i=j;i<=k;++i)
#define dow(i,j,k) for(register int i=j;i<=k;--i)


const int N=2e5+1000;
long long sum[N],n,ans;
map<long long ,int>mp;
int main(){
	scanf("%lld",&n);
	mp[0]=1;
	rep(i,1,n){
		scanf("%lld",&sum[i]);
		sum[i]+=sum[i-1];
		//cout<<sum[i]<<endl;
		if(mp[sum[i]])ans+=mp[sum[i]],mp[sum[i]]=mp[sum[i]]+1;
		else mp[sum[i]]=1;
		//cout<<ans<<endl;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 14336
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

[[maybe_unused]] constexpr ll LL_MAX = numeric_limits<ll>::max();
[[maybe_unused]] constexpr ll LL_MIN = numeric_limits<ll>::min();
[[maybe_unused]] constexpr ull ULL_MAX = numeric_limits<ull>::max();

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

template <typename T>
void chmin(T& x, T y) {
    x = min(x, y);
}

template <typename T>
void chmax(T& x, T y) {
    x = max(x, y);
}

ll csum(ll x, ll y) {
    if (x > 0 && y > 0 && x > LL_MAX - y) {
        return LL_MAX;
    }
    if (x < 0 && y < 0 && x < LL_MIN - y) {
        return LL_MIN;
    }
    return x + y;
}

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

ll A, B, C, D;

ll solve(ll N, unordered_map<ll, ll>& cache) {
    if (cache.count(N) > 0) {
        return cache[N];
    }
    if (N == 0) {
        cache[N] = 0;
        return cache[N];
    }
    if (N == 1) {
        cache[N] = D;
        return cache[N];
    }
    ll ans = min((__int128_t)N * (__int128_t)D, (__int128_t)LL_MAX);
    using P = pair<ll, ll>;
    for (P type : {P{2,A}, P{3,B}, P{5,C}}) {
        ll m = type.first;
        ll X = type.second;
        {
            ll cnt = N%m;
            ll M = (N - cnt) / m;
            ll ans_loc = X + cnt * D + solve(M, cache);
            chmin(ans, ans_loc);
        }
        {
            if (N % m != 0) {
                ll cnt = m - N%m;
                ll M = (N + cnt) / m;
                ll ans_loc = X + cnt * D + solve(M, cache);
                chmin(ans, ans_loc);
            }
        }
    }
    cache[N] = ans;
    return ans;
}

int main() {
    ll T;
    cin >> T;
    rep(t,0,T) {
        ll N;
        cin >> N >> A >> B >> C >> D;
        unordered_map<ll, ll> cache;
        cout << solve(N, cache) << endl;
    }
}


Measured memory_bytes: 3972
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int w = scanner.nextInt();
			int q = scanner.nextInt();
			if ((w | q) == 0)
				break;
			int[] map = new int[w];
			Arrays.fill(map, -1);
			loop: while (q-- > 0) {
				char c = scanner.next().charAt(0);
				if (c == 's') {
					int id = scanner.nextInt();
					int n = scanner.nextInt();
					int cnt = 0;
					for (int i = 0; i < w; i++) {
						if (map[i] == -1) {
							cnt++;
							if (cnt == n) {
								for (int j = i - n + 1; j <= i; j++) {
									map[j] = id;
								}
								System.out.println(i - cnt + 1);
								continue loop;

							}
						} else
							cnt = 0;
					}
					System.out.println("impossible");
				} else {
					int id = scanner.nextInt();
					for (int i = 0; i < w; i++) {
						if (map[i] == id)
							for (int j = i; j < w; j++) {
								if (map[j] == id)
									map[j] = -1;
								else
									break;
							}
					}
				}
			}
			System.out.println("END");
		}
	}
}

Measured memory_bytes: 20644
#include<stdio.h>

int main(void)
{
  int a,i;
  long count=0;
  
  scanf("%d",&a);
  
  for(i=0;i<a;i++){
    if((i+1)%3==0||(i+1)%5==0)
		count+=0;
    else
        count+=i+1;
  }
  
  printf("%ld\n",count);
  
  return 0;
}

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

int N;
int A[200010];
int B[200010];
vector<int> x[30][2];
int cnt[30];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= 28; j++) {
			int mask = (2 << j) - 1;
			x[j][(A[i] >> j) & 1].push_back(mask & A[i]);
		}
	}
	for (int i = 0; i <= 28; i++) {
		for (int j = 0; j < 2; j++) {
			sort(x[i][j].begin(), x[i][j].end());
		}
	}
	for (int i = 0; i < N; i++) {
		cin >> B[i];
	}
	for (int i = 0; i < N; i++) {
		int BB = B[i];
		for (int j = 28; j >= 0; j--) {
			BB = BB & ((2 << j) - 1);
			if ((1 << j) <= BB) {
				int ub = x[j][1].size();
				int lb = (3 << j) - BB;
				lb = lower_bound(x[j][1].begin(), x[j][1].end(), lb) - x[j][1].begin();
				cnt[j] += (ub - lb) % 2;

				ub = (2 << j) - 1 - BB;
				ub = upper_bound(x[j][0].begin(), x[j][0].end(), ub) - x[j][0].begin();
				lb = 0;
				cnt[j] += (ub - lb) % 2;
			}
			else {
				int ub = (2 << j) - 1 - BB;
				ub = upper_bound(x[j][1].begin(), x[j][1].end(), ub) - x[j][1].begin();
				int lb = 0;
				cnt[j] += (ub - lb) % 2;

				ub = x[j][0].size();
				lb = (1 << j) - BB;
				lb = lower_bound(x[j][0].begin(), x[j][0].end(), lb) - x[j][0].begin();
				cnt[j] += (ub - lb) % 2;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < 30; i++) {
		if (cnt[i] % 2) ans |= 1 << i;
	}
	cout << ans << endl;
	return 0;
}

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

#define rep(i,j) for(int (i)=0;(i)<(j);++(i))

int main() {
    string code[9];
    code[0] = ".,!? ";
    code[1] = "abc";
    code[2] = "def";
    code[3] = "ghi";
    code[4] = "jkl";
    code[5] = "mno";
    code[6] = "pqrs";
    code[7] = "tuv";
    code[8] = "wxyz";
    int n;
    cin >> n;
    rep(i, n) {
        string c;
        cin >> c;
        int idx = -1, cnt = -1;
        rep(j, c.length()) {
            string t = "";
            t += c[j];
            int num = atoi(t.c_str());
            if (num == 0) {
                if (idx != -1 && cnt != -1) cout << code[idx][cnt];
                idx = -1;
                cnt = -1;
            }
            else {
                if (idx == -1 && cnt == -1) {
                    idx = num-1;
                    cnt = 0;
                }
                else {
                    cnt = (cnt+1)%code[idx].length();
                }
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 3000
s = input()

a1 = ''
a2 = ''

for i in range(len(s)):
	if (i % 2 == 0):
		a1 = a1 + '0'
		a2 = a1 + '1'
	else:
		a1 = a1 + '1'
		a2 = a2 + '0'
m1 = 0
m2 = 0

for i in range(len(s)):
	if(s[i] != a1[i]):
		m1 = m1 + 1
	else:
		m2 = m2 + 1

print(min(m1,m2))

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

int main() {
    string s, t;
    cin >> s >> t;
    int ans = t.size();
    for(int i = 0; i < (int) s.size() - (int) t.size() + 1; i++) {
        int cnt = 0;
        for(int j = 0; j < (int) t.size(); j++) {
            cnt += s[i + j] != t[j];
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int maxn=1e5+10;
char a[maxn];
int main()
{
     cin>>a[0]>>a[1]>>a[2]>>a[3];
     int t1=(a[0]-'0')*10+a[1]-'0';
     int t2=(a[2]-'0')*10+a[3]-'0';
     if(t1==0&&t2==0)
        puts("NA");
     else if(t1<=12&&t2<=12&&t1&&t2)
        puts("AMBIGUOUS");
     else if(t1!=0&&t1<=12&&(t2>=12||t2==0))
           puts("MMYY");
     else if((t1==0||t1>=12)&&t2<=12&&t2!=0)
        puts("YYMM");
     else
        puts("NA");

return 0;
    }


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

int main(void) {
  int N;
  scanf("%d", &N);

  vector<int> A(N), B(N);
  REP(i, N) scanf("%d", &A[i]);
  REP(i, N) scanf("%d", &B[i]);

  llint ka = 0, kb = 0;
  REP(i, N) {
    if (A[i] < B[i]) {
      if ((B[i] % 2) != (A[i] % 2)) {
        kb++;
        B[i]++;
      }
      ka += (B[i] - A[i]) / 2;
      A[i] = B[i];
    } else { // B[i] <= A[i]
      kb += A[i] - B[i];
      B[i] = A[i];
    }
  }

  puts(kb <= ka ? "Yes" : "No");
  return 0;
}


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

int main() {
  long long K,N,A[200010],l_max = 0;

  cin >> K >> N;
  cin >> A[0];
  A[N] = A[0] + K;

  for ( int i=1 ; i < N ; ++i ) {
    cin >> A[i];
    l_max = max(l_max,A[i]-A[i-1]);
  }
  l_max = max(l_max,A[N]-A[N-1]);
  cout << K - l_max << endl;
}

Measured memory_bytes: 1792
def main():
    n, mod = map(int, input().split())
    s = input().rstrip()
    a = [int(c)%mod for c in s]
    ans = 0
    if mod == 2 or mod == 5:
        for i in range(n):
            if a[i] == 0:
                ans += i + 1
    else:
        mul = 10 % mod
        for i in reversed(range(n-1)):
            a[i] = (a[i]*mul + a[i+1]) % mod
            mul = mul*10 % mod
        b = [0] * mod
        b[0] = 1
        for i in reversed(range(n)):
            ans += b[a[i]]
            b[a[i]] += 1
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 11220
n=raw_input()
k=n.split(" ")

W=int(k[0])
H=int(k[1])
x=int(k[2])
y=int(k[3])
r=int(k[4])
f=0

if 0<=x-r<=x+r<=W:
  if 0<=y-r<=y+r<=H:
    print "Yes"
    f=1
if f==0:
  print "No"

Measured memory_bytes: 6432
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<deque>

#define maxn 1000005
#define pii pair<int,int>

using namespace std;

inline int getint()
{
	int num=0,flag=1;char c;
	while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;
	while(c>='0'&&c<='9')num=num*10+c-48,c=getchar();
	return num*flag;
}

int n,ans;
char s[maxn],t[maxn];
deque<int>Q;

int main()
{
	n=getint();
	scanf("%s%s",s+1,t+1);
	Q.push_back(n+1);
	for(int i=n,j=n+1,num=0;i;i--)
	{
		int tmp=j;
		while(j&&(j>i||(s[j]!=t[i])))j--;
		if(!j){printf("-1\n");return 0;}
		if(tmp==j)
		{
			while(!Q.empty()&&Q.back()-num>=i)Q.pop_back();
			Q.push_back(i+num);
		}
		else
		{
			num++;
			if(i!=j)ans=max(ans,(int)Q.size()),Q.push_front(j+num);
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);

int main(){
	int n;cin>>n;
	map<string,int>m;
	rep(i,n){
		string s;cin>>s;
		m[s]++;
	}
	int ma =0;
	for(auto c:m){
		ma=max(ma,c.second);
	}
	vector<string>ans;
	for(auto c:m){
		if(c.second==ma)ans.push_back(c.first);
	}
	sort(been(ans));
	rep(i,ans.size())cout<<ans[i]<<endl;

}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)

const char sp = ' ';
const char cmm = ',';
const int MOD = 1000000007;

using ll = long long;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}


#define MAX_N 100001

class UnionFind{
public:
    int par[MAX_N];
    int rank[MAX_N];
    ll numintree[MAX_N];
    void init(int n){
        rep(i, n){
            par[i] = i;
            rank[i] = 0;
            numintree[i] = 1;
        }
    }
    UnionFind(int n){
        init(n);
    }

    int root(int x){
        if(par[x] == x)
            return x;
        else
            return par[x] = root(par[x]);
    }

    bool same(int x, int y){
        return this->root(x) == this->root(y);
    }


    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        ll numx = numintree[x], numy = numintree[y];

        if(rank[x] < rank[y]){
            numintree[root(y)] += numx;
            par[x] = y;
        }
        else{
            numintree[root(x)] += numy;
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
        }
    }
};

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);


    int n, m;
    cin >> n >> m;

    ll inconv = 1;
    for(int i = n-1; i >= 2; --i){
        inconv += i;
    }

    vector<ll> ans;
    ans.push_back(inconv);

    UnionFind uf(n);

    vector<int> a(m), b(m);
    for(int i = m-1; i >= 0; --i){
        int A, B;
        cin >> A >> B;
        a[i] = A-1; b[i] = B-1;
    }

    for(int i = 0; i < m-1; ++i){
        if(!uf.same(a[i], b[i])){
            inconv -= uf.numintree[uf.root(a[i])]*uf.numintree[uf.root(b[i])];
            uf.unite(a[i], b[i]);
        }
        ans.push_back(inconv);
    }

    reverse(ans.begin(), ans.end());

    for(int i = 0; i < m; ++i){
        ppp(ans[i]);
    }



    return 0;
}


Measured memory_bytes: 4596
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}

signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    int n;
    cin>>n;
    int a[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
    }

    int ans(0);
    for (int i = 0; i < n; ++i)
    {
        if(i%2)
        {
            continue;
        }
        if(a[i]%2)
            ans++;
    }
    cout<<ans;
    printclock;
    return 0;
}


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

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

int main(){
  int n,m;

  while(cin>>n>>m){
    if(n<m) swap(n,m);
    int ans = gcd(n,m);
    cout << ans << endl;
  }

  return EXIT_SUCCESS;
}

Measured memory_bytes: 1160
#include <stdio.h>

int  main(void)
{
	
	int n,a[101];
	int max=-1;
	int min=1001;
	
	scanf("%d",&n);
	
	for(int i=0;i<n;i++){
		scanf("%d",&(a[i]));
		
		if(a[i]>max){
			max=a[i];
		}
		
		if(a[i]<min){
			min=a[i];
		}
		
	}
	
	printf("%d\n",max-min);
	
	return 0;
}
	

Measured memory_bytes: 128
#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 fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll n, m, k, ans;
ll a[100001];
int non_decrease;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 1; i < n; i++){
        if(non_decrease == 0){
            if(a[i-1] < a[i]){
                non_decrease = 1;
            }
            if(a[i-1] > a[i]){
                non_decrease = -1;
            }
        }
        else{
            if(non_decrease == 1){
                if(a[i-1] > a[i]){
                    non_decrease = 0;
                    ans++;
                }
            }
            else{
                if(a[i-1] < a[i]){
                    non_decrease = 0;
                    ans++;
                }
            }
        }

    }
    cout << ans + 1;
}


Measured memory_bytes: 1024
(n,a,b)=map(x->parse(Int,x),split(readline()))
s=0
for i=1:n
	x=i
	m=0
	while x>0
		m+=x%10
		x=div(x,10)
	end
	if a<=m<=b
		s+=i
	end
end
print(s)


Measured memory_bytes: 168364
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include <queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;


int main(){
    char c;
    cin >> c;
    cout << char(c + 1) << endl;
    return 0;
}


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

using namespace std;

int main()
{
    int n, fact = 1;

    scanf("%d", &n);

    int t = n;

    while(t) {
        t = t / 10;
        fact = fact * 10;
    }

    while(fact > 1) {
        fact = fact / 10;
        if(n / fact == 7) {
            printf("Yes\n");
            return 0;
        }
        n = n % fact;
    }
    printf("No\n");

    return 0;
}

Measured memory_bytes: 3680
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;

void solve(){
  int a, b; cin >> a >> b;
  cout << a * b - a - b + 1 << endl;
  return;
}
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
from bisect import *
n, m = map(int, input().split())
s = input()

masu = []
for i in range(n+1):
    if s[i] == "0":
        masu.append(i)

now = n
ans = [n]

while now > 0:
    next = masu[bisect_left(masu, now-m)]
    if now != next:
        ans.append(next)
        now = next
    else:
        ans = -1
        break

if ans == -1:
    print(-1)

else:
    ans.reverse()
    for i in range(len(ans)-1):
        print(ans[i+1]-ans[i])


Measured memory_bytes: 8688
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

public class Main {

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

		int n = parseInt(br.readLine());
		Map<Integer, Integer> P = new HashMap<>();

		for (int i = 0; i < n; i++) {
			StringTokenizer st = new StringTokenizer(br.readLine());
			int s, l, p;
			s = parseInt(st.nextToken());
			l = parseInt(st.nextToken());
			p = parseInt(st.nextToken());
			for (int j = s; j <= l; j++) {
				P.putIfAbsent(j, 0);
				P.put(j, Math.max(P.get(j), p));
			}
		}

		int m = parseInt(br.readLine());
		StringBuilder ans = new StringBuilder();
		boolean notfound = false;

		for (int i = 0; i < m; i++) {
			int w = parseInt(br.readLine());
			int[] dp = new int[w + 1];
			for (Map.Entry<Integer, Integer> p : P.entrySet()) {
				for (int j = p.getKey(); j <= w; j++) {
					dp[j] = Math.max(dp[j], dp[j - p.getKey()] + p.getValue());
				}
			}
			if (dp[w] == 0) {
				notfound = true;
				break;
			}
			ans.append(dp[w]).append('\n');
		}

		if (notfound) {
			System.out.println(-1);
		} else {
			System.out.print(ans.toString());
		}
	}
}



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

int main() {
  int N,M,SUM=0;
  cin>>N>>M;

  vector<int> A(N);
  rep(i,N){cin >> A.at(i);
          SUM+=A.at(i);}
  
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  
  int flg=0;
  
rep(i,N){if(A.at(i)*4*M>=SUM){flg++;if(flg>=M){break;}
                         }else{break;}
        }
  if(flg>=M){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
}


Measured memory_bytes: 3608
# -*- coding: utf-8 -*-
import math
def isPrime(n):
    i = 2
    while i*i <= n:
        if n%i == 0:
            return False
        i += 1
    return True

table = []
N = int(input())
for tmp in range(2,N+1):
    if isPrime(tmp):
        table.append(tmp)

table2 = [0 for i in range(len(table))]

factorial = 1
for num in range(2,N+1):
    factorial *= num
    factor = 0
    for i in table:
        while num >= i and num%i == 0:
            table2[factor] += 1
            num /= i
        factor += 1

ans = 1
for tmp2 in table2:
    ans *= tmp2+1

#for num in range (1, factorial+1):
#    if factorial % num == 0:
#       ans += 1 

ans = ans % ((10 ** 9) + 7)
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
using namespace std;
int main()
{
  int k;
  cin>>k;
  string s;
  cin>>s;
  int n=s.size();
  if(n>k)
  {
    s=s.substr(0,k)+"...";
  }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 3608
//
//  main.cpp

#include <iostream>
#include <cmath>


using namespace std;
struct status{
	int toptemp;
	int bottomtemp;
	int fancy;
	
};
status dress[201];
int dp[201][201];//i??\???????????????j????????????????????§????´???????
int temp[201];
int D,N;

int MAX(int i,int j){//i??\?????????j???????????????????????§???????????????
	if(i == 0){//?????\????????????????????????
//		return dress[j].fancy;
		return 0;
	}
	if(dp[i][j] != -1){
		return dp[i][j];
	}
	
//	for(int i=0;i<N;i++){
	for(int J=0;J<N;J++){//i-1??\?????????J(1<D)???????????????????????§???
		if(temp[i-1] >= dress[J].bottomtemp && temp[i-1] <= dress[J].toptemp){
			dp[i][j] = max(dp[i][j],MAX(i-1,J) + abs(dress[J].fancy - dress[j].fancy));
		}
	}
	return dp[i][j];
//		dp[i-1][j]
//	}
}

int main(){	
	
	cin >> D >> N;
	
	
	for(int i=0;i<D;i++){
		cin >> temp[i];
	}
	for(int i=0;i<N;i++){
		cin >> dress[i].bottomtemp >> dress[i].toptemp >> dress[i].fancy;
	}
	

	for(int i=0;i<201;i++){
		for(int j=0;j<201;j++){
			dp[i][j] = -1;
		}
	}
	int answer=0;
	for(int i=0;i<N;i++){
		if(temp[D-1] >= dress[i].bottomtemp && temp[D-1] <= dress[i].toptemp){
			answer = max(answer,MAX(D-1,i));
		}
	}
	cout << answer << endl;
	
	/*
	for(int i=0;i<N;i++){//0??\?????????????¨???????
		if(temp[0] >= dress[i].bottomtemp && temp[0] <= dress[i].toptemp){
			dp[0][i] = dress[i].fancy;
		}
	}
	
	for(int i=1;i<D;i++){
		for(int j=0;j<N;j++){
			if(temp[i] >= dress[j].bottomtemp && temp[i] <= dress[j].toptemp){//i??\??????j??????????????????
				int Maxfancy=-1;
				for(int k=0;k<N;k++){//i-1??\????????¨????????????????????´???????????????????´???????????????§???????????????????????????
					if(dp[i-1][k] == -1)continue;
					Maxfancy = max(Maxfancy,abs(dress[j].fancy - dress[k].fancy));
				}
				dp[i][j] = Maxfancy;
			}
		}
	}
	
	int answer = 0;
	for(int i=1;i<D;i++){
		int Max = -1;
		for(int j=0;j<N;j++){
			Max = max(Max,dp[i][j]);
		}
		answer += Max;
	}
	cout << answer << endl;
	
	vector<int> dresses;
	int matrix[201][2];
	for(int i=0;i<D;i++){
		for(int j=0;j<N;j++){
			if(temp[i] >= dress[j].bottomtemp && temp[i] <= dress[j].toptemp){
				dresses.push_back(dress[j].fancy);
			}
		}
		sort(dresses.begin(),dresses.end());
		matrix[i][0] = dresses[0];
		matrix[i][1] = dresses[dresses.size() - 1];
	}
	
	int dp[201]={};
	dp[0] = max(matrix[0][0],matrix[0][1]);
	
	for(int i=1;i<D;i++){
		dp[i] = max(abs(dp[i-1] - matrix[i][0]),abs(dp[i-1] - matrix[i][1]));
	}
	
	cout << dp[D-1] << endl;
	*/
	return 0;
}

Measured memory_bytes: 3256
n=int(input());s=input()
for p in range(4):
  l=[p//2,p%2]+[0]*(n-2)
  for i in range(1,n):l[(i+1)%n]=[l[i-1],1-l[i-1]][::(-1)**(s[i]=="o")][l[i]]
  for i in range(n):
    if s[i]!="ox"[int(l[(i-1)%n]==l[(i+1)%n])-l[i]]:break
  else:print("".join("WS"[x]for x in l));exit()
print(-1)

Measured memory_bytes: 5476
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int n;

int main()
{
    cin >> n;
    cout << "Christmas ";
    for (int i = n; i < 25; i++) cout << "Eve ";

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}
		long[][] dp = new long[n + 1][2];
		dp[0][0] = 0;
		dp[0][1] = -1_000_000_009;
		for (int i = 1; i < n; i++) {
			dp[i][0] = Math.max(dp[i - 1][0] + a[i - 1], dp[i - 1][1] - a[i - 1]);
			dp[i][1] = Math.max(dp[i - 1][0] - a[i - 1], dp[i - 1][1] + a[i - 1]);
		}

		System.out.println(Math.max(dp[n - 1][0] + a[n - 1], dp[n - 1][1] - a[n - 1]));
	}
}


Measured memory_bytes: 50452
#include <iostream>

int sum_digit(int value) {

  int s = 0;
  while (value > 0) {
    s += value % 10;
    value /= 10;
  }

  return s;
}

int main(int argc, char const* argv[])
{
  int n, a, b;
  std::cin >> n >> a >> b;

  long sum = 0;
  for (int i = 0; i <= n; ++i) {
    int sum_d = sum_digit(i);
    if (a <= sum_d && sum_d <= b) {
      sum += i;
    }
  }

  std::cout << sum << std::endl;
  return 0;
}

Measured memory_bytes: 256
/**
 *      ABC 96 B
 *      author  : kyomukyomupurin
 *      created : 2018/08/23
**/

#include <bits/stdc++.h>
using namespace std;

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (a >= b && a >= c){
        cout << b + c + a * pow(2, k) << endl;
    }
    else if (b >= a && b >= c){
        cout << a + c + b * pow(2, k) << endl;
    }
    else {
        cout << b + a + c * pow(2, k) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256