akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
 
public class Main{
    public static void main(String[] args){
        Main m = new Main();
        m.input();
    }
 
    public void input(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.close();
        ArrayList<Integer> li = primeSet();
        for(int j = 0; j < n; j++){
            System.out.print(li.get(j));
            if(j == n - 1){
                break;
            }
            System.out.print(" ");
        }
        System.out.println();
        
    }

    public ArrayList<Integer> primeSet(){
        ArrayList<Integer> pli = new ArrayList<Integer>();
        ArrayList<Integer> li = new ArrayList<Integer>();
        pli.add(2);
        
        for(int i = 3; i <= 10000; i = i + 2){
            boolean check = true;
            for(int j = 0; j < pli.size(); j++){
                if(i % pli.get(j) == 0){
                    check = false;
                    break;
                }
            }
            if(check){
                pli.add(i);
                if(i % 20 == 1){
                    li.add(i);
                }
            }
        }

        return li;
    }
    
}

Measured memory_bytes: 22044
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<algorithm>
#include<list>
#include<cmath>
#include<iomanip>
#include<queue>
#include<functional>
#include<climits>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<set>
#include<typeinfo>
using namespace std;

const double pi=4*atan(1.0);

constexpr long long mod=static_cast<long long>(1e9+7);

using cWeightEdges=vector<vector<pair<int,int>>>;
using cEdges=vector<vector<int>>;

int main() {
	int N;
	cin>>N;
	vector<array<long long,4>> p(N);
	vector<long long> x(2*N);
	vector<long long> y(2*N);
	set<long long> x_set;
	set<long long> y_set;
	for(auto& val:p){
		cin>>val[0]>>val[1]>>val[2]>>val[3];
		x_set.insert(val[0]);
		x_set.insert(val[2]);
		y_set.insert(val[1]);
		y_set.insert(val[3]);
	}
	for(int i=0;i<N;++i){
		x[i*2]=p[i][0];
		y[i*2]=p[i][1];
		x[i*2+1]=p[i][2];
		y[i*2+1]=p[i][3];
	}
	sort(begin(x),end(x));
	sort(begin(y),end(y));
	auto x_end=unique(begin(x),end(x));
	auto y_end=unique(begin(y),end(y));

	unordered_map<long long,long long> x_Hash;
	unordered_map<long long,long long> y_Hash;
	int cnt=0;
	for(const auto& val:x_set)
		x_Hash.insert(make_pair(val,cnt++));
	cnt=0;
	for(const auto& val:y_set)
		y_Hash.insert(make_pair(val,cnt++));

	for(auto& val:p){
		val[0]=x_Hash[val[0]];
		val[2]=x_Hash[val[2]];
		val[1]=y_Hash[val[1]];
		val[3]=y_Hash[val[3]];
	}

	vector<vector<int>> plane(y_end-begin(y)-1,vector<int>(x_end-begin(x)-1,0));
	for(const auto& val:p){
		for(int i=val[1];i<val[3];++i){
			fill(begin(plane[i])+val[0],begin(plane[i])+val[2],1);
		}
	}

	long long ans=0;
	for(int i=0;i<plane.size();++i){
		for(int j=0;j<plane[i].size();++j){
			if(plane[i][j]==1){
				ans+=(x[j+1]-x[j])*(y[i+1]-y[i]);
			}
		}
	}

	cout<<ans<<endl;

	//system("pause");
	return 0;
}

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

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;

int main(){

	lli a,b,c;
	cin>>a>>b>>c;
	vector<lli> tmp;
	tmp.push_back(a);
	tmp.push_back(b);
	tmp.push_back(c);
	sort(tmp.begin(),tmp.end());

	lli cnt=0;

	lli now = tmp.at(0)+tmp.at(1)+tmp.at(2);
	lli target = tmp.at(2)*3;
	if(((target-now)%2)==0){
		cout<<(target-now)/2<<endl;
	}else{
		cout<<(target-now)/2+2<<endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,X,ans=0,aaa=0;
  cin >> N >> X;
  for(int i=0; i<N; i++){
    int S;
    cin >> S;
    ans += S;
    if(ans <= X){
      aaa++;
    }
  }
  cout << aaa +1 << endl;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int cnt[110];
int main () {
    int n,k;
    cin>>n>>k;
    for(int i=0;i<k;i++){
        int q;
        cin>>q;
        for(int j=0;j<q;j++){
            int m;
            cin>>m;
            cnt[m]++;
        }
    }
    int c=0;
    for(int i=1;i<=n;i++){
        if(!cnt[i])
            c++;
    }
    cout<<c;
}

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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int m(int n, int k) {
    for (int i = 0; i < k; i++) {
        n *= 2;
    }
    return n;
}

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    if (a > b) {
        if (a > c) {
            a = m(a, k);
        } else {
            c = m(c, k);
        }
    } else {
        if (b > c) {
            b = m(b, k);
        } else {
            c = m(c, k);
        }
    }

    cout << a + b + c << endl;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 5e1 + 10;
string check(string str1, string str2, int pos)
{
	for (int i = 0; i < str2.length(); i++)
	{
		if (str1[i + pos] != str2[i])
		{
			if (str1[i + pos] != '?') return "";
			str1[i + pos] = str2[i];
		}
	}
	for (auto &c : str1)
	{
		if (c == '?')
			c = 'a';
	}
	return str1;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	string s1, s2;
	cin >> s1 >> s2;
	string ans = string(s1.length(), 'z');
	int flag = 0;
	for (int i = 0; i + s2.length() <= s1.length(); i++)
	{
		string tmp = check(s1, s2, i);
		if (tmp != "")
		{
			flag = 1;
			ans = min(ans, tmp);
		}
	}
	if (flag)
		cout << ans << endl;
	else
		cout << "UNRESTORABLE" << endl;
	return 0;
}


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

using namespace std;

int compute(int n, int day, int a[], int b[], int c[], int memoA[], int memoB[], int memoC[], int prevActivity){
    if(day == n){
        return 0;
    }
    if(prevActivity == 1){
        if(memoA[day] != -1){
            return(memoA[day]);
        }
        int value = max(b[day] + compute(n, day + 1, a, b, c, memoA, memoB, memoC, 2), c[day] + compute(n, day + 1, a, b, c, memoA, memoB, memoC, 3));
        memoA[day] = value;
        return value;
    }
    if(prevActivity == 2){
        if(memoB[day] != -1){
            return(memoB[day]);
        }
        int value = max(a[day] + compute(n, day + 1, a, b, c, memoA, memoB, memoC, 1), c[day] + compute(n, day + 1, a, b, c, memoA, memoB, memoC, 3));
        memoB[day] = value;
        return value;
    }
    if(prevActivity == 3){
        if(memoC[day] != -1){
            return(memoC[day]);
        }
        int value = max(b[day] + compute(n, day + 1, a, b, c, memoA, memoB, memoC, 2), a[day] + compute(n, day + 1, a, b, c, memoA, memoB, memoC, 1));
        memoC[day] = value;
        return value;
    }
    if(prevActivity == 0){
        int value = a[day] + compute(n, day + 1, a, b, c, memoA, memoB, memoC, 1);
        value = max(value, b[day] + compute(n, day + 1, a, b, c, memoA, memoB, memoC, 2));
        value = max(value, c[day] + compute(n, day + 1, a, b, c, memoA, memoB, memoC, 3));
        return value;
    }
    return 0;
}

int main(){
    int n;
    cin >> n;
    int a[n] = {0};
    int b[n] = {0};
    int c[n] = {0};
    int memoA[n] = {-1};
    int memoB[n] = {-1};
    int memoC[n] = {-1};
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i] >> c[i];
        memoA[i] = -1;
        memoB[i] = -1;
        memoC[i] = -1;
    }
    cout << compute(n, 0, a, b, c, memoA, memoB, memoC, 0) << endl;
}

Measured memory_bytes: 15104
#include <stdio.h>
#include <math.h>
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <utility>
#include <map>
#include <unordered_map>
#include <string>

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)
#define all(c) begin(c),end(c)
#define vmax(c) *max_element(all(c))
#define vmin(c) *min_element(all(c))
 
template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p) {
    out << "[" << p.first << ", " << p.second << "]";
    return out;
}

template<typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::map<T1, T2>& map)
{
    for (typename std::map<T1, T2>::const_iterator it = map.begin();
         it != map.end();
         ++it)
    {
        out << (*it);
    }
    return out;
}

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const long long INF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9; 

// 2次元配列を作る
// vector<vi> my_vector(n, vi(m, 0));

// 多次元配列の dump
// for (auto v : my_vector) {
//     cout << v;
// }

ll N;

auto solve() {
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    int c = 0;
    int rc, gc, bc;
    rc = N / R;
    gc = N / G;
    bc = N / B;
    RREP(r, rc + 1) {
        int rr = R * r;
        // cout << "r" << rr << ":";
        int rrr = (N - rr);
        if (rrr == 0)
        {
            c = c + 1;
            // cout << endl;
            continue;
        }
        RREP(g, rrr / G + 1) {
            int gg = G * g;
            // cout << "g" << gg << ":";
            int ggg = N - rr - gg;
            // cout << "gres" << ggg << ":";

            if (ggg == 0)
            {
                c = c + 1;
                // cout << endl;
                continue;
            }

            if (ggg % B == 0) {
                c = c + 1;
            }
        }
        // cout << rrr << ",";
        // cout << endl;
    }
    // cout << endl;
    // cout << "count: " << c << endl;
    // cout << rc << gc << bc;
    return c;
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // solve();
    cout << solve();
}

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 k = sc.nextInt();
        int[] p = new int[n+1];
        p[0]=0;
        for (int i=1;i<=n;i++)p[i]=p[i-1]+1+sc.nextInt();
        int ans = 0;
        for (int i=k;i<=n;i++){
            ans = Math.max(ans,p[i]-p[i-k]);
        }
        System.out.println(ans/2d);
    }
}


Measured memory_bytes: 60080
// 166 C

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <iomanip>
#include <climits>
#include <string>

using namespace std;

int main(){
    int n, m, buf, a, b, count=0;
    cin >> n >> m;
    vector<int> h(n);
    vector<bool> check(n, true);
    for(int i=0; i<n; i++){
        cin >> buf;
        h.at(i) = buf;
    }
    for(int i=0; i<m; i++){
        cin >> a >> b;
        if(h.at(a-1) < h.at(b-1)){ check.at(a-1) = false; }
        else if(h.at(a-1) > h.at(b-1)){ check.at(b-1) = false; }
        else if(h.at(a-1) == h.at(b-1)){ check.at(a-1) = false; check.at(b-1) = false; }
    }
    for(int i=0; i<check.size(); i++){
        if(check.at(i)) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 3788
while True:
    x = input().split()
    ans = str(x[0]) + " " + str(x[1])
    if int(x[0]) > int(x[1]):
        ans = str(x[1]) + " " + str(x[0])
    if x[0] == "0" and x[1] == "0":
        break
    print(ans)


Measured memory_bytes: 5612
#include <iostream>
#include <string>

using namespace std;

char reverse(char c)
{
    if(c == 'S')
    {
        return 'W';
    }
    else
    {
        return 'S';
    }
}

char get(char ss, string aa)
{
    if (ss == 'o')
    {
        if (aa[1] == 'S')
        {
            return aa[0];
        }
        else
        {
            return reverse(aa[0]);
        }
    }
    if (ss == 'x')
    {
        if (aa[1] == 'S')
        {
            return reverse(aa[0]);
        }
        else
        {
            return aa[0];
        }
    }
}

int main()
{
    int N;
    string ans = "-1";
    string s, a;

    string ptr[4];
    ptr[0] = "SS";
    ptr[1] = "SW";
    ptr[2] = "WW";
    ptr[3] = "WS";

    cin >> N;
    cin >> s;


    for (int i = 0; i < 4;i++)
    {
        a = ptr[i];
        for (int j = 2; j < N;j++)
        {
            char nc = get(s[j-1], a.substr(j - 2, 2));
            a += nc;
        }
        char start = get(s[N - 1], a.substr(N - 2, 2));
        string t = a.substr(0, 2);
        reverse(t.begin(), t.end());
        char end = get(s[0], t);
        //cout << start << " " << end << endl;
        //cout << a << endl;

        if (start == a[0] && end == a[N - 1])
        {
            ans = a;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 704
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <map>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define ll long long
ll solve(ll a,ll b){
    if (!a) return 0;
    ll res=a*(b/a)*2;
    return b%a?res+solve(b%a,a):res-a;
}
ll n,x,ans;
int main(){
    scanf("%lld%lld",&n,&x);
    ans=n+solve(min(x,n-x),max(x,n-x));
    printf("%lld\n",ans);
    return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

int main() {
  int n; cin >> n;
  if( n==5 || n==3 || n==7 ) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}




Measured memory_bytes: 256
from heapq import heappush,heappop


def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))
INF = 1 << 29


def runLength(in_str):
    kukan = 1
    start = 0
    ret = []
    for i in range(1,len(in_str)):
        if in_str[i-1]!=in_str[i]:
            ret.append([in_str[i-1],kukan,start])
            start = i
            kukan=0
        kukan+=1
    ret.append([in_str[-1],kukan,start])
    return ret

N = int_raw()
S= input()

dp = {}

def rec(ss):
    return 0

def main():
    global S
    ans = INF
    numB = [0]*len(S)
    
    for i in range(len(S)):
        if i > 0:
            numB[i]=numB[i-1]
        if S[i]=="#":
            numB[i]+=1
    if numB[len(S)-1]==0 or numB[len(S)-1]==len(S):
        return 0        
    for i in range(len(S)):
        buf = numB[i]+len(S)-1-i-(numB[len(S)-1]-numB[i])
        ans = min(ans, buf)
    ans = min(ans, len(S)-numB[len(S)-1])
    ans = min(ans, numB[len(S)-1])
    return ans



print(main())



Measured memory_bytes: 11240
/*
auth - @sportykush
*/

#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
// using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;

//#define mp make_pair
#define bug(v)                    cerr<<#v<<" = "<<(v)<<endl;
#define ERASE(x)                  x.erase(unique(x.begin(),x.end()),x.end())
#define pb                        emplace_back
#define vii                       vector<int>
#define vll                       vector<ll>
#define vpll                      vector< pair <ll,ll> >
#define pll                       pair <ll,ll>
#define pii                       pair <int,int>
#define pq                        priority_queue< int >
#define khtm                      "\n"
#define F                         first
#define S                         second
#define fr(i,a,n)                 for(i=a;i<n;i++)
#define mem(arr,l)                memset(arr,l,sizeof arr)
#define ALL(x)                    x.begin(), x.end()
#define frr(i,a,n)                for(i=n-1;i>=a;i--)
#define fast                      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define testcase                  ll T; cin>>T; while(T--)


const double pi = 3.14159265359;
const int MAX = 1e6 +2;
const ll inf =  1e18;
const int N = 1010;
//const ll mod = 998244353 ;
const ll mod = 100000007;
inline ll add(ll a,ll b){a+=b;if(a>=mod)a-=mod;return a;}
inline ll mul(ll a,ll b){return (((a+mod)%mod)*(b+mod)%mod)%mod;}
inline ll power(ll a,ll b){ll rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline ll modInverse(ll n, ll p){ return power(n, p-2)%p; }

/*
important builtin functions
__gcd(value1, value2)
__builtin_ffs(x)
  Number of leading zeroes: __builtin_clz(x)
  Number of trailing zeroes : __builtin_ctz(x)
  Number of set bits: __builtin_popcount(x)
*/
 
void stArt()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}
void eNd()
{
	#ifndef ONLINE_JUDGE
  	cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";
  	#endif
}

//////////////////// start /////////////////////////////////
 

ll i,j,k,l,m,r,n;
//ll a[MAX],b[MAX];


int main()
{
 
stArt();
fast
//cout << setprecision(15) << fixed;

	cin >> n;
	k = n%1000;
	cout << (k ? 1000-k : 0);


 eNd();
  return 0;
 
}


Measured memory_bytes: 3604
num = gets.to_i
half = num / 2

arr = gets.chomp.split(" ").map(&:to_i).sort

flag = -1

arr.each_with_index do |item, i|
  if item == arr[i + 1]
    flag = 1
    break
  elsif arr[half] == arr[half -1]
    flag = 1
    break
  else
    half += 1
    break if half == num
  end
end

puts "NO" if flag == 1
puts "YES" if flag == -1


Measured memory_bytes: 20992
x=[0,0,0,0]
for i in range(3):
    a,b=map(int,input().split())
    x[a-1]+=1
    x[b-1]+=1
y=0
for j in range(4):
    if x[j]%2==1:
        y+=1
if y>2:
    print('NO')
else:
    print('YES')

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

typedef long long ll;

using namespace std;

bool used[30];
string str;
vector<string> cand;

void dfs(int t){
	if(t==str.size()) cand.push_back(str);
	else{
		if(str[t]=='a' || used[str[t]-'a']) dfs(t+1);
		if(!used[str[t]-'a'+1] && str[t]!='z'){
			str[t]++;
			used[str[t]-'a'] = 1;
			dfs(t+1);

			used[str[t]-'a'] = 0;
			str[t]--;
		}
	}
}


int main(void){
	while(1){
		cin >> str;
		if(str == "#") break;

		fill(used, used+30, false);
		cand.clear();
		dfs(0);
		cout << cand.size() << endl;
		if(cand.size() <= 10){
			for(int i=0; i<cand.size(); i++){
				cout << cand[i] << endl;
			}
		} else{
			for(int i=0; i<5; i++){
				cout << cand[i] << endl;
			}
			for(int i=cand.size()-5; i<cand.size(); i++){
				cout << cand[i] << endl;
			}
		}
	}

	return 0;
}


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

int gcd(int a, int b){
	return (b>0)? gcd(b, a%b) : a ;
}
int lcm(int a, int b){
	return (a / gcd(a, b) * b);
}

int main(){
	int a, b;
	
	while( cin >> a >> b ){
		cout << gcd(a,b) << " " << lcm(a,b) << endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
 
int main() {
  int n;
  cin >> n;
  
  int p;
  int ans = 1;
  
  cin >>p;
  
  int target;
  rep(i,n-1){
    cin >> target;
    if(target<=p){
      p=target;
      ans++;
    }
  }
  
  cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		Long X = sc.nextLong();
      Long Y = sc.nextLong();
      ArrayList<Long> list = new ArrayList<Long>();
      list.add(X);
      while(true){
        if(list.size() == 1){
          if(X * 2 > Y){
            System.out.println(list.size());
            return;
          }else{
            list.add(X * 2);
          }
        }else{
          if(list.get(list.size() - 1) * 2 > Y){
            System.out.println(list.size());
            return;
          }else{
            list.add(list.get(list.size() - 1) * 2);
          }
        }
      }
	}
}


Measured memory_bytes: 23764
import sys
from collections import deque

n = int(input())
matches = [[a - 1 for a in map(int, line.split())] for line in sys.stdin]
q = deque(range(n))
depth = [0] * n
waiting = [-1] * n

while q:
    a = q.popleft()
    ma = matches[a]
    if not ma:
        continue
    b = ma.pop()
    if waiting[b] == a:
        depth[a] = depth[b] = max(depth[a], depth[b]) + 1
        q.append(a)
        q.append(b)
    else:
        waiting[a] = b

if any(matches):
    print(-1)
else:
    print(max(depth))


Measured memory_bytes: 35848
#define rep(i, m, n) for(int i = m; i < n; i++)
#define repM(i, m, n) for(int i = n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll; using namespace std;
//typedef pair<int,int> pii; using namespace std;

// d = distance(lower_bound(all(x)), upper_bound(all(x)));

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

int main(){
  int N; cin >> N; int A; double a=0;
  rep(i, 0, N) {cin >> A; a += (double)1/A;}
  cout << 1.0d/a << endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

from collections import Counter

n = int(input())
s = [input() for i in range(n)]
c = Counter(s)
c_max = max(c.values())
ans = [j[0] for j in c.items() if j[1] == c_max]
ans = sorted(ans)
for f in ans:
    print(f)


Measured memory_bytes: 38908
N = int(input())
A = list(map(int,input().split()))

c = 0
l = 0
ans = 0

for r in range(N):
    if c&A[r]:
        while c&A[r]:
            c = c^A[l]
            l += 1
    c = c^A[r]
    ans += r-l+1

print(ans)


Measured memory_bytes: 23560
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k; cin >> k;
	if (k <= 9) {
		dunk(k);
		return 0;
	}
	queue<ll> que;
	rrep(i, 10) que.push(i);
	int cnt = 9;
	rep(ri, k) {
		ll tmp = que.front(); que.pop();
		if (tmp % 10 > 0) {
			que.push(tmp * 10 + tmp%10 - 1);
			cnt++;
			if (cnt == k) {
				dunk(tmp * 10 + tmp%10 - 1);
				return 0;
			}
		}
		que.push(tmp * 10 + tmp%10);
		cnt++;
		if (cnt == k) {
			dunk(tmp * 10 + tmp%10);
			return 0;
		}

		if (tmp % 10 < 9) {
			que.push(tmp * 10 + tmp%10 + 1);
			cnt++;
			if (cnt == k) {
				dunk(tmp * 10 + tmp%10 + 1);
				return 0;
			}
		}
	}
	return 0;
}


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

using namespace std;

int main(){

  int n,k;
  cin >> n >> k;

  vector<bool> c(n);

  for (int i = 0; i < k; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int e;
      cin >> e;
      c.at(e-1) = true;
    }

  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (!c.at(i)) {
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3600
W,H,N = map(int,input().split())
limit = {'top': H, 'right': W, 'down': 0, 'left': 0}
for _ in range(N):
  x,y,a = map(int,input().split())
  if a == 1:
    if x > limit['left']:
      limit['left'] = x
  elif a == 2:
    if x < limit['right']:
      limit['right'] = x
  elif a == 3:
    if y > limit['down']:
      limit['down'] = y
  elif a == 4:
    if y < limit['top']:
      limit['top'] = y
height = limit['top'] - limit['down']
width = limit['right'] - limit['left']
if (height > 0) and (width > 0):
  print(height * width)
else:
  print(0)
  


Measured memory_bytes: 3064
use input::Input;

fn main() {
    let mut input = Input::default();

    let x = input.parse();
    let y = input.parse();

    for i in 0..=100 {
        for j in 0..=100 {
            if i + j == x && 2 * i + 4 * j == y {
                println!("Yes");
                return;
            }
        }
    }
    println!("No");
}

#[allow(dead_code)]
pub mod input {
    #[derive(Default)]
    pub struct Input(Vec<String>);

    impl Input {
        pub fn read_line(&mut self) -> String {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok().expect("read error");
            s
        }
        pub fn parse<T: std::str::FromStr>(&mut self) -> T {
            let x = if let Some(x) = self.0.pop() {
                x
            } else {
                let s = self.read_line();
                self.0 = s.split_whitespace().map(String::from).rev().collect();
                self.0.pop().expect("reached EOF")
            };
            x.parse().ok().expect("parse error")
        }
    }
}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll ans = lcm(a, b);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
bool isPrime(int x)
{
	if (x < 2)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	for (int i = 3; i <= sqrt(x); i += 2)
		if (x%i == 0)
			return false;
	return true;
}
int main()
{
	while (true)
	{
		int n;
		cin >> n;
		if (!n)
			break;
		int cnt = 0;
		for (int i = n + 1; i <= 2 * n; i++)
			if (isPrime(i))
				cnt++;
		cout << cnt << endl;
	}
}


Measured memory_bytes: 3104
import java.util.*;

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

        long H = sc.nextLong();
        long W = sc.nextLong();
        long difa = 100000;
        long difb = 100000;

        for(int i=1; i<H; i++){
            long A = i * W;
            long B = (H - i) * (W / 2);
            long C = (H - i) * (W - W / 2);
            long max = Math.max(A, B);
            max = Math.max(max, C);
            long min = Math.min(A, B);
            min = Math.min(min, C);
            difa = Math.min(difa, max - min);

            B = (H - i) / 2 * W;
            C = (H - i - (H - i) / 2) * W;
            max = Math.max(A, B);
            max = Math.max(max, C);
            min = Math.min(A, B);
            min = Math.min(min ,C);
            difa = Math.min(difa, max - min);
        }

        for(int i=1; i<W; i++){
            long A = i * H;
            long B = (W - i) * (H / 2);
            long C = (W - i) * (H - H / 2);
            long max = Math.max(A, B);
            max = Math.max(max, C);
            long min = Math.min(A, B);
            min = Math.min(min, C);
            difb = Math.min(difb, max - min);

            B = (W - i) / 2 * H;
            C = (W - i - (W - i) / 2) * H;
            max = Math.max(A, B);
            max = Math.max(max, C);
            min = Math.min(A, B);
            min = Math.min(min ,C);
            difb = Math.min(difb, max - min);
        }

        System.out.println(Math.min(difa, difb));
    }
}

Measured memory_bytes: 24148
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int start = sc.nextInt();
            int end = sc.nextInt();
            ans += end - start + 1;
        }
        System.out.println(ans);
    }
}



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

int main() {
  ll N;
  cin >> N;
  
  vector<ll> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
  }
  
  ll ans = 1;
  for (int i = 0; i < N; i++) {
    ll gdc = __gcd(ans, T.at(i));
    ans = ans / gdc * T.at(i);
  }
  
  cout << ans << endl;
  
  return 0;
}

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

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define INF 1e9
// constexpr ll INF = 1LL << 60;

struct UnionFind{
  vector<int> par, size;
  UnionFind(int n): par(n), size(n, 1){
    REP(i, n){
      par[i] = i;
    }
  }
  int root(int x){
    if(par[x] == x){
      return x;
    }
    return par[x] = root(par[x]);
  }
  bool same(int a, int b){
    return root(a) == root(b);
  }
  void unite(int a, int b){
    int aroot = root(a);
    int broot = root(b);
    if(aroot == broot) return;
    par[aroot] = broot;
    size[broot] += size[aroot];
  }
  int calSize(int x){
    return size[root(x)];
  }
};

int main(){
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> edges(M);
  REP(i, M){
    cin >> edges[i].first >> edges[i].second;
    edges[i].first--, edges[i].second--;
  }
  ll all = (ll)N*(N-1)/2, ren = 0;
  vector<ll> ans(M);
  UnionFind uf(N);
  REPR(i, M-1){
    int a = edges[i].first, b = edges[i].second;
    ans[i] = all - ren;
    if(!uf.same(a, b)){
      ren += (ll)uf.calSize(a) * uf.calSize(b);
      uf.unite(a, b);
    }
  }
  REP(i, M){
    cout << ans[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 3712
#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 n;
   string s;
   cin >> n >> s;
   int ee=0;
   VI e(n);
   int ww=0;
   VI w(n);
   rep(i,n){
      if(s.at(i)=='W')ww++;
      if(s.at(i)=='E')ee++;
      e.at(i)=ee;
      w.at(i)=ww;
   }
   VI cnt(n);
   rep(i,n){
      if(i==0){
         cnt.at(i)=w.at(n-1)-w.at(0);
      }
      else if(i==n-1){
         cnt.at(i)=e.at(n-2);
      }
      else{
         cnt.at(i)=e.at(i-1)+w.at(n-1)-w.at(i);
      }
   }
   sort(cnt.begin(),cnt.end());
   int x=cnt.at(n-1);
   cout << n-x-1 << endl;

}
    

Measured memory_bytes: 7212
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


x = int(sys.stdin.buffer.readline())
ok = x in [7, 5, 3]

if ok:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 13428
#include <iostream>

using namespace std;

int main(){
    int A[1000][1000];
    int b[1000];
    int Ab[1000];
    int i,j;
    int n,m;
    int sum = 0;
    
    for(i = 0;i < 1000;i++){
        for(j = 0;j < 1000;j++){
            A[i][j] = 0;
            b[j] = 0;
        }
        Ab[i] = 0;
    }
    
    cin >> n >> m;
    
    for(i = 0;i < n;i++){
        for(j = 0;j < m;j++){
            cin >> A[i][j];
        }
    }
    for(j = 0;j < m;j++){
        cin >> b[j];
    }
    
    for(i = 0;i < n;i++){
        sum = 0;
        for(j = 0;j < m;j++){
            sum = sum + A[i][j] * b[j];
        }
        Ab[i] = sum;
    }
    
    for(i = 0;i < n;i++){
        cout << Ab[i] << endl;
    }
    
    return 0;
    
    
}


Measured memory_bytes: 7024
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n; cin>>n;
  string s; cin>>s;
  vector<int> r,g,b;
  for(int i=0; i<n; ++i){
    if(s[i]=='R') r.push_back(i);
    else if(s[i]=='G') g.push_back(i);
    else b.push_back(i);
  }
  int x,y,z;
  long long res=0;
  for(x=0; x<r.size(); ++x)
    for(y=0; y<g.size(); ++y){
      int p=max(r[x],g[y]),q=min(r[x],g[y]),d=p-q,cnt=b.size();
      if(binary_search(b.begin(),b.end(),p+d)==true) --cnt;
      if(binary_search(b.begin(),b.end(),q-d)==true) --cnt;
      if(((p+q)&1)==0) if(binary_search(b.begin(),b.end(),(p+q)/2)==true) --cnt;
      res+=cnt;
    }
  cout<<res;
  return 0;
}

Measured memory_bytes: 3588
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = System.Console.ReadLine().Trim();
            int iN = int.Parse(sS);
            sS = System.Console.ReadLine().Trim();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = 0;
            List<char> lstOut = new List<char>();
            char cBak = 'A';
            for (int i = 0; i < sS.Length; i++)
            {
                if (sS[i] != cBak) { lstOut.Add(sS[i]); }
                cBak = sS[i];
            }

            // 出力
            System.Console.WriteLine("{0}", lstOut.Count.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }


}


Measured memory_bytes: 13408
/**
*    created: 20.06.2020 03:08:44
**/
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

int f(int n, int x) {
    if (n == 0) return 1;
    else if (x == 1) return 0;    
    int l1 = (1LL << (n+1)) - 3;
    int l2 = (1LL << n) - 1;
    if (x <= l1 + 1) return f(n-1,x-1);
    else if (x == l1 + 2) return (l2 + 1);
    else if (x >= l1 + 3 && x <= l1 * 2 + 2) return (l2 + 1 + f(n-1,x-l1-2));
    else return 2 * l2 + 1;
}

signed main() {

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

    int n, x;
    cin >> n >> x;
    cout << f(n,x) << endl;
    return 0;
}

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


bool is_palindrome(string s){
    string t(s.rbegin(),s.rend());
    return s == t;
}
 

int main() {
  string S;
  cin >> S;
  int pos1 = (S.size()-1) / 2;
  string cord1 = S.substr(0, pos1);
  int pos2 = (S.size() + 1)/2;
  string cord2 = S.substr(pos2, string::npos);
  if(is_palindrome(S) && is_palindrome(cord1) && is_palindrome(cord2)) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}

Measured memory_bytes: 256
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nHeroes := scanInt(sc)
	cities := make([]int, nHeroes+1)
	for i := 0; i < nHeroes+1; i++ {
		cities[i] = scanInt(sc)
	}

	heroes := make([]int, nHeroes)
	for i := 0; i < nHeroes; i++ {
		heroes[i] = scanInt(sc)
	}

	nTotal := 0
	for i, killable := range heroes {
		left, right := cities[i], cities[i+1]
		leftKills := min(left, killable)
		rightKills := min(right, killable-leftKills)
		cities[i+1] -= rightKills
		nTotal += leftKills + rightKills
	}

	fmt.Println(nTotal)
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}


Measured memory_bytes: 4608
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;

  int n = s.length();
  map<string, int> mp;
  for (int i = 1; i <= k; i++) {
    for (int j = 0; j <= n - i; j++) {
      mp[s.substr(j, i)]++;
    }
  }
  vector<string> v;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    v.push_back(it->first);
  }
  //sort(v.begin(), v.end());
  cout << v[k - 1] << endl;

  return 0;
}

Measured memory_bytes: 2176
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 512
#define ll long long
int n;
ll a[maxn][maxn];
bool vis[10240];
ll prim[10240],cnt;
void getprim()
{
	for(int i=2;i<10240;i++)
	{
		if(!vis[i])
		{
			cnt++;
			prim[cnt]=i;
		}
		for(int j=1;j<=cnt&&i*prim[j]<10240;j++)
		{
			vis[i*prim[j]]=1;
			if(i%prim[j]==0)
			{
				break;
			}
		}
	}
	return;
}
ll gcd(ll a,ll b)
{
	if(!b)
	{
		return a;
	}else
	{
		return gcd(b,a%b);
	}
}
ll lcm(ll a,ll b)
{
	if(a==0||b==0)
	{
		return a+b;
	}else
	{
		return a/gcd(a,b)*b;
	}
}
int main()
{
	scanf("%d",&n);
	getprim();
	if(n==2)
	{
		printf("4 7\n23 10\n");
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=((i+1)&1)+1;j<=n;j+=2)
		{
			a[i][j]=prim[(i+j)/2]*prim[n+(i-j)/2+(n+1)/2];
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=(i&1)+1;j<=n;j+=2)
		{
			a[i][j]=lcm(lcm(a[i-1][j],a[i+1][j]),lcm(a[i][j-1],a[i][j+1]))+1;
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			printf("%lld ",a[i][j]);
		}
		printf("\n");
	}
	return 0;
}
















Measured memory_bytes: 5120
#include<cstdio>
#include<vector>
using namespace std;
int n, m;
vector<pair<pair<int,int>,int>> dap;
int main()
{
	int n;
	scanf("%d", &n);
	int ch = 0;
	n--;
	for (int i = 20; i >= 0; i--)
	{
		if (n&(1<<i))
		{
			ch = i;
			break;
		}
	}
	if (n == 1)
	{
		printf("2 2\n1 2 0\n1 2 1");
		return 0;
	}
	for (int i = 1; i <=ch; i++)
	{
		dap.push_back({ {i,i + 1},0 });
		dap.push_back({ { i,i + 1 },(1<<(i-1)) });
	}
	int x = 0;
	int prev = 1;
	for (int i = 1; i <= ch+1; i++)
	{
		if (n&(1 << (i - 1)))
		{
			dap.push_back({ {prev, ch + 1}, n - x });
			prev = i;
			x += (1 << (i - 1));
		}
	}
	printf("%d %d\n", ch + 1, dap.size());
	for (int i = 0; i < dap.size(); i++)
		printf("%d %d %d\n", dap[i].first.first, dap[i].first.second, dap[i].second);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}

int main(){
    ll w,h;cin >> w >>h;
    priority_queue<pl,vpl,greater<pl>> que;
    rep(i,w){
        ll x;cin >> x;
        que.push({x,0});
    }
    rep(i,h){
        ll y;cin >> y;
        que.push({y,1});
    }
    w++;h++;
    ll ans=0;
    while(!que.empty()){
        pl p=que.top();que.pop();
        if(p.se){
            ans+=p.fi*w;
            h--;
        }
        else{
            ans+=p.fi*h;
            w--;
        }
       // cout << ans <<endl;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 6512
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int n;
int a[405], pre[405];
int dp[405][405];

int rec(int l, int r) {
	if(l == r) return 0;
	int &ans = dp[l][r];
	if(ans != -1) return ans;
	ans = inf;
	for(int i = l; i <= r; i++) {
		ans = min(ans, rec(l, i) + rec(i + 1, r) + pre[r] - ((l > 0) * pre[l - 1]));
	}
	return ans;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    cin>>n;
    f(i, n) {
    	cin>>a[i];
		if(i) pre[i] = pre[i - 1];
		pre[i] += a[i];
	}
	f(i, n + 1) f(j, n + 1) dp[i][j] = -1;
	cout<<rec(0, n - 1);
    return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>

int S(int N)
{
	int sum = 0;
	while(N)
	{
		sum += N%10;
		N /= 10;
	}
	return sum;
}
int main(void)
{
	int N;
	scanf("%d", &N);
	if(N%S(N) == 0)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MX = 100;
bool arr[MX][MX];
int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int a, b;
	cin >> a >> b; // 0 1
	for(int i=0; i<MX/2; i++) {
		for(int j=0; j<MX; j++) {
			arr[i][j] = 0;
			if(b > 1 && i%2 && j%2) {
				b--;
				arr[i][j] = 1;
			}
		}
	}
	for(int i=MX-1; i>=MX/2; i--) {
		for(int j=0; j<MX; j++) {
			arr[i][j] = 1;
			if(a > 1 && i%2 && j%2) {
				a--;
				arr[i][j] = 0;
			}
		}
	}
	cout << MX << ' ' << MX << '\n';
	for(int i=0; i<MX; i++) {
		for(int j=0; j<MX; j++) {
			cout << (arr[i][j] ? '#' : '.');
		}
		cout << '\n';
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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;
}





int main() {
    int n;
    cin>>n;
    vector<int>c(n-1);
    vector<int>s(n-1);
    vector<int>f(n-1);
    for(int i=0,x,y,z;i<n-1;i++){
        cin>>x>>y>>z;
        c.at(i)=x;
        s.at(i)=y;
        f.at(i)=z;
    }
    for(int i=0;i<n-1;i++){
        int ans=s.at(i)+c.at(i);
        for(int j=i+1;j<n-1;j++){
            if(s.at(j)<=ans){
                if(ans%f.at(j)==0){
                    ans+=c.at(j);
                }
                else{
                    int x=ans%f.at(j);
                    ans-=x;
                    ans+=f.at(j);
                    ans+=c.at(j);
                }
            }
            else{
                ans=s.at(j)+c.at(j);
            }
        }
        cout<<ans<<endl;
    }
    cout<<0<<endl;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)				// repeat
#define repr(i, begin, end) for (ll i = end - 1; begin <= i; i--)		// repeat reverse

#endif

namespace NyaGadgetUnionFind
{
	struct Vertex
	{	// 頂点を表現する構造体
		ll root;
		ll size;
	};

	template <class V> struct Graph
	{	// グラフを表現する構造体
		vector<V> vertex;
		Graph(ll v_size)
		{	// グラフ構造を構造体に格納する
			vertex.resize(v_size);
			rep(i, 0, (ll)vertex.size())
			{	// 各頂点の根を自分自身で初期化、各頂点の木サイズは１で初期化
				vertex[i].root = i;
				vertex[i].size = 1;
			}
		}
		Vertex& FindRoot(ll v_index)
		{
			// 自分自身が根のとき
			if (v_index == vertex[v_index].root)
				return vertex[vertex[v_index].root];
			// 根の探索をすると同時に次からO(1)で根を参照できるようにする
			vertex[v_index].root = FindRoot(vertex[v_index].root).root;
			return vertex[vertex[v_index].root];
		}
		void UnionTree(ll v1_index, ll v2_index)
		{
			ll tree1_root = FindRoot(v1_index).root;
			ll tree2_root = FindRoot(v2_index).root;

			if (tree1_root == tree2_root)
				return;

			// サイズの小さい木の根をサイズの大きい木の根に繋いで結合する
			if (vertex[tree1_root].size < vertex[tree2_root].size)
			{
				vertex[tree1_root].root = tree2_root;
				vertex[tree2_root].size += vertex[tree1_root].size;
			}
			else
			{
				vertex[tree2_root].root = tree1_root;
				vertex[tree1_root].size += vertex[tree2_root].size;
			}
		}
	};
}

using namespace NyaGadgetUnionFind;

class ABC120D
{
public:
	ABC120D()
	{
		cin >> n >> m;
		a.resize(m);
		b.resize(m);
		rep(i, 0, m)
		{
			cin >> a[i] >> b[i];
			a[i]--; b[i]--;
		}
	}
	void Run(void)
	{
		Graph<Vertex> g(n);

		vector<ll> ans(m);
		ans[m-1] = n * (n - 1) / 2;
		repr(i, 1, m)
		{
			if (g.FindRoot(a[i]).size == n)
				break;

			if (g.FindRoot(a[i]).root == g.FindRoot(b[i]).root)
				ans[i - 1] = ans[i];
			else
				ans[i - 1] = ans[i] - g.FindRoot(a[i]).size * g.FindRoot(b[i]).size;

			g.UnionTree(a[i], b[i]);
		}
		for (const auto& e : ans)
			cout << e << endl;
	}
private:
	ll n;
	ll m;
	vector<ll> a;
	vector<ll> b;
};

int main(void)
{
	ABC120D abc120d;
	abc120d.Run();

	return 0;
}


Measured memory_bytes: 5248