akhauriyash/Code-Regression huggingface dataset:
class Trees():
    def __init__(self):
        self.nodes = {}
    def add_nodes(self, id):
        if id not in self.nodes:
            self.nodes[id] = Node(id)
    def add_child(self, id, child_id1, child_id2):
        for child_id in [child_id1, child_id2]:
            if child_id != -1:
                self.add_nodes(child_id)
                self.nodes[id].add_child_id(self.nodes[child_id])
        if child_id1 != -1:
            self.nodes[child_id1].sibling = child_id2
        if child_id2 != -1:            
            self.nodes[child_id2].sibling = child_id1
        self.nodes[id].left = child_id1
        self.nodes[id].right = child_id2
    def setheight(self, id):
        h1, h2 = 0, 0
        if self.nodes[id].right != -1:
            h1 = self.setheight(self.nodes[id].right) + 1
        if self.nodes[id].left != -1:
            h2 = self.setheight(self.nodes[id].left) + 1
        self.nodes[id].height = max(h1, h2)
        return max(h1, h2)
        

         
class Node():
    def __init__(self, id):
        self.node = id
        self.parent = None
        self.depth = 0
        self.nodetype = 'root'
        self.children = []
        self.sibling = -1
        self.degree = 0
        self.height = 0
        self.left = -1
        self.right = -1
     
    def add_child_id(self, child):
        child.parent = self
        self.children.append(child)
        child.update_depth()
        self.update_nodetype()
        child.update_nodetype()
        self.degree += 1
        
     
    def update_depth(self):
        depth = self.depth
        if self.parent:
            self.depth = self.parent.depth + 1
        if depth != self.depth:
            for child in self.children:
                child.update_depth()
 
     
    def update_nodetype(self):
        if self.depth == 0:
            self.nodetype = 'root'
        elif len(self.children) > 0:
            self.nodetype = 'internal node'
        else:
            self.nodetype = 'leaf'
            

     
    def __str__(self):
        parent = self.parent.node if self.parent else -1
        return 'node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}'.format(
            self.node, parent, self.sibling, self.degree, self.depth, self.height, self.nodetype)
     
 
tree = Trees()
 
n = int(input())
 
for i in range(n):
    a = list(map(int,input().split()))
    tree.add_nodes(a[0])
    tree.add_child(id=a[0], child_id1=a[1], child_id2=a[2])

for id in range(n):
    tree.setheight(id)
        

for id in range(n):
    print(f"{tree.nodes[id]}")


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

#define pb push_back
typedef long long int ll;
typedef vector<ll> vl;
typedef map<ll,ll> ii;

ll fast_expo(ll x, ll y){
    
    ll res=1;
    while(y>0){
        if(y&1){
            res*=x;
        }
        x*=x;
        y>>=1;
    }
    return res;
}
//fast expo function
ll fast_expo(ll x, ll y, ll m){
    x%=m;
    ll res=1;
    while(y>0){
        if(y&1){
            res=((res%m)*(x%m))%m;
        }
        x=((x%m)*(x%m))%m;
        y>>=1;
    }
    return res;
}

//sieve function
void sieve(ll x,vl &v){
    bool sieve[x+1];
    memset(sieve,true,sizeof(sieve));
    int i=2;
    while(i*i<=x){
        if (sieve[i]==true){
            for(int j=i+i;j<=x;j+=i){
                sieve[j]=false;
            }
            
        }
    i++;    
    }
    
    for(int i=2;i<=x;i++){
        if(sieve[i])
            v.pb(i);
    }
    
}
//GCD function
int gcd(int x,int y){
    if(x==0)return y;
    return gcd(y%x,x);
}
//main code
int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    int t;cin>>t;
    vl a;
    for(int i=0;i<t;i++){
        ll k;cin>>k;
        a.push_back(k);
    }
    long long mod=1e9+7;
    ii m;
    vl v;
    sieve(100001,v);
    
    
    for(ll i:a){
        int j=0;
        
        while(v[j]*v[j]<=i){
            ll k=v[j];
            ll c=0;
            if (i%k==0){
                while(i%k==0){
                    c++;
                    i/=k;
                }
            
                ll h=m[k];
                m[k]=max(c,h);
            }
            j++;
        }
        if (i>=2){
            ll c=1;
            m[i]=max(m[i],c);
        }
    }
    ll z=1;
    for(auto i:m){
        z=((z%mod)*fast_expo(i.first,i.second,mod))%mod;
    }
    ll y=0;
    for(ll i:a){
        y=((y%mod)+((z%mod)*(fast_expo(i,mod-2,mod)))%mod)%mod;
    }    
    
    cout<<y%mod;
    return 0;
    
}
    

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(17) << res << endl;
 
int main() {
    double a, b;
    double h, m;
    cin >> a >> b >> h >> m;
    double diff = abs(30 * h + 0.5 * m - 6 * m);

    //cerr << diff << endl;
    double rad = M_PI * diff / 180;
    double res = sqrt(pow(a - b  * cos(rad),2) + pow(b * sin(rad),2));
    //double res = sqrt(a * a + cos(rad) * b * b + sin(rad) * b * b);
    cout << setprecision(17) << res << endl;
}


Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, k;
    cin >> n >> k;
    string s = "";
    while(n > 0) {
        s += (char)(n % k + '0');
        n /= k;
    }
    reverse(all(s));
    cout << len(s) << endl;
    return 0;
}


Measured memory_bytes: 256
def calc_cost(arr, choice):
    ans = 0
    for num in arr:
        ans += (num - choice) * (num - choice)
    return ans

def main():
    N = int(raw_input())
    
    arr = [int(x) for x in raw_input().split()]
    
    avg = sum(arr) / N
    
    ans = min(calc_cost(arr, avg+1), calc_cost(arr, avg-1), calc_cost(arr, avg))
    
    print(ans)
    

main()


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

using ll = long long; 
/*

2
1 4


*/
int calc_cost(vector<int> arr, int choice) {
    int ans = 0;
    for (int num : arr) {
        ans += (num - choice) * (num - choice);
    }
    return ans;
}

int main() {
    int N;
    
    scanf("%d", &N);
    
    vector<int> arr(N);
    
    int total = 0;
    
    for (int i = 0; i < N; i++) {
        scanf("%d", &arr[i]);
        total += arr[i];
    }
    
    int avg = total / N;
    
    /*
    sort(arr.begin(), arr.end());
    
    int med = arr[N/2];
    
    cout << med << endl;
    
    int ans = 0;
    
    for (int n : arr) {
        ans += (n - med) * (n - med);
    }
    */
    
    int ans = min({calc_cost(arr, avg-1), calc_cost(arr, avg), calc_cost(arr, avg+1)});
    
    
    printf("%d\n", ans);
	
	return 0;
}
"""

Measured memory_bytes: 85452
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>

using namespace std;
typedef long long ll;

ll X, A;

int main() {
	cin >> X >> A;
	if (X < A) {
		cout << 0 << endl;
	}
	else {
		cout << 10 << endl;
	}
	return 0;
}

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

#define int long long
#pragma GCC optimize ("O3")
#define ll long long
#define vi vector <int>
#define vii vector <pair<int,int> >
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>b;i--)
#define pb push_back
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define PI 3.14159265359


/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace __gnu_pbds;
typedef tree<pii,null_type,less <pii>,rb_tree_tag,tree_order_statistics_node_update>ind_set;
*/
///*X.find_by_order("index")
///X.order_of_key("key")



#define deb(x) cerr<<#x<< " : " <<x<<"\n";
#ifndef local
	#define deb(x) ;
#endif
///----------------------------------------------------------------------------------

int n,arr[100005];
void solve()
{
	cin>>n;rep(i,0,n)cin>>arr[i];
	sort(arr,arr+n);
	if (n&1)
	{
		int ansM=0;
		rep(i,0,n/2+1)ansM-=arr[i];
		rep(i,n/2+1,n)ansM+=arr[i];

		int ansP=0;
		rep(i,0,n/2)ansP-=arr[i];
		rep(i,n/2,n)ansP+=arr[i];

		if (ansP>ansM)
		{
			cout<<ansP<<"\n";

			stack<int> S;
			reverse(arr,arr+n);
			rep(i,0,n/2)S.push(arr[i]),S.push(arr[n/2+i+1]);
			S.push(arr[n/2]);

			while(S.size()!=1)
			{
				int a=S.top();S.pop();int b=S.top();S.pop();
				cout<<b<<" "<<a<<"\n";;
				S.push(b-a);
			}
		}
		else
		{
			cout<<ansM<<"\n";
			stack<int> S;
			//reverse(arr,arr+n);
			rep(i,0,n/2)S.push(arr[i]),S.push(arr[n/2+i+1]);
			S.push(arr[n/2]);

			while(S.size()!=1)
			{
				if (S.size()==2)
				{
					int a=S.top();S.pop();int b=S.top();S.pop();
					cout<<a<<" "<<b<<"\n";break;
				}
				int a=S.top();S.pop();int b=S.top();S.pop();

				cout<<b<<" "<<a<<"\n";
				S.push(b-a);
			}
		}

	}
	else
	{

		int ans=0;
		if (n==2)
		{
			cout<<arr[1]-arr[0]<<"\n";
			cout<<arr[1]<<" "<<arr[0];
			return;
		}

		ans=arr[n-1]-arr[0];
		rep(i,1,n-1)ans+=abs(arr[i]);

		cout<<ans<<"\n";
		rep(i,1,n-1)
		{
			if (arr[i]>=0){cout<<arr[0]<<" "<<arr[i]<<"\n";arr[0]-=arr[i];}
		}
		cout<<arr[n-1]<<" "<<arr[0]<<"\n";
		arr[n-1]-=arr[0];
		rep(i,1,n-1)if (arr[i]<0)
		{cout<<arr[n-1]<<" "<<arr[i]<<"\n";arr[n-1]-=arr[i];}

		return;


	}

}

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

    #ifdef local
    freopen("input.txt","r",stdin);
    ///freopen("output.txt","w",stdout);
    #endif

    clock_t qwertyuiop = clock();
    int t=1;
    ///cin>>t;
    rep(a,0,t)
    {
        ///cout<<"Case #"<<a+1<<": ";
        solve();
    }
    #ifdef local
	{qwertyuiop = clock() - qwertyuiop;double time_taken = ((double)qwertyuiop)/CLOCKS_PER_SEC;cerr<<fixed<<setprecision(5)<<"\n\nTime Taken : "<<time_taken<<" seconds\n";}
	#endif
}


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

vector<int> memo(3),res(3);
vector<int> num(4);

void dfs(int k,int sum){
    if(k == 4){
        if(sum == 7){ res=memo; /*rep(i,3){cout << memo[i];}cout << endl;*/ return; }
    }else{
        memo[k] = 1;
        dfs(k+1,sum+num[k+1]);
      
        memo[k] = 0;
        dfs(k+1,sum-num[k+1]);
    }
}

string pls(int i){ return ( i==1 ? "+" : "-" ); }

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

    string eq;
    cin >> eq;

  	rep(i,4) num[i] = eq[i]-'0';
    
  	dfs(0,num[0]);
  
  	string ans;
  	rep(i,3) ans = ans + eq[i] + pls(res[i]);
    ans = ans + eq[3] + "=7";
    cout << ans << endl;
  
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

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

four = 0
even = 0

for a in A:
    if a % 4 == 0:
        four += 1
    elif a % 2 == 0:
        even += 1

if max(even-1,0) + 2*four >= N - 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var a = cin.ReadIntArray(N);

            var even = a.Where((e, i) => i % 2 == 0).Reverse();
            var odd  = a.Where((e, i) => i % 2 == 1);

            if (N % 2 == 0) WriteLine(string.Join(" ", even.Concat(odd).Reverse()));
            else WriteLine(string.Join(" ", even.Concat(odd)));
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
        public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; }}
        public void ReadLongArrays(long N, out long[] A, out long[] B) { A = new long[N]; B = new long[N]; for (long i = 0; i < N; ++i) { A[i] = ReadLong; B[i] = ReadLong; }}
    }
}

Measured memory_bytes: 44624
li=[int(input()) for i in range(5)]
k=int(input())
if li[1]-li[0]>k or li[2]-li[1]>k or li[3]-li[2]>k or li[4]-li[3]>k or li[4]-li[0]>k:
  print(":(")
else:
  print("Yay!")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;int64_t N,a,b,c,i,V[1<<20],f[1<<20],R[1<<20];main(){for(cin>>N;i<N;cin>>a>>b,a+=1e9,R[i++]=(a<<32)+a+b);for(sort(R,R+N);a=i--;c=V[i]=(c+V[f[i]=a]+1)%998244353)for(;a<N&R[a]<R[i]<<32;a=f[a]);cout<<*V+1;}

Measured memory_bytes: 5888
# https://beta.atcoder.jp/contests/abc058/tasks/abc058_b


def solve():
    # o >= e, o
    # e = 0 or 1
    o = input()
    e = input() + " "
    print(''.join([(l+r) for l, r in zip(o, e)]).strip())


if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}



int main(){

  int N;
  cin >> N;
  vector<ll> A(N);
  for(auto &&x:A)cin >> x;
  ll all = 0;
  for(auto &&x:A)all ^= x;
  FOR(i,0,N){
    if(i!=0)cout<<" ";
    cout << (all ^ A[i]);
  }
  cout << endl;
}



Measured memory_bytes: 4772
# coding: utf-8
x1, y1, x2, y2 = map(int, input().split())

dx = x2 - x1
dy = y2 - y1
x3 = x2-dy
y3 = y2+dx

dx = x3 - x2
dy = y3 - y2
x4 = x3-dy
y4 = y3+dx

print(x3, y3, x4, y4)

Measured memory_bytes: 3060
#include <set>
#include <string>
#include <map>
#include <iostream>
#include <cstdio>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

template<class T> T getAs(){ T v; std::cin >> v; return v; }
inline int getInt(){ return getAs<int>(); }

using namespace std;

vector<vector<int> > next;
vector<vector<int> > pnext;
vector<string> str;

void print(int i){
  // cout << i + 1 << " " << str[i] << endl;
  cout << i + 1 << endl;
  REP(j, next[i].size()) print(next[i][j]);
  REP(j, pnext[i].size()) print(pnext[i][j]);
}

int main(){
  while(int n = getInt()){
    map<string, int> label;
    str = vector<string>(n);
    next = vector<vector<int> >(n);
    pnext = vector<vector<int> >(n);

    REP(i,n) cin >> str[i];

    int prev = -1;
    int start = -1;
    REP(i,n){
      if(str[i] == "-"){
        if(prev == -1){
          start = i;
        }else{
          pnext[prev].push_back(i);
        }
        prev = i;
      }else{
        if(str[i][str[i].size() - 1] == 'v')
          next[i + 1].push_back(i);

        if(str[i].size() > 1){
          char buff[32]; int id;
          sscanf(str[i].c_str(), "%[a-z]%d", buff, &id);
          if(id == 1){
            if(str[i][str[i].size() - 1] != 'v'){
              if(prev == -1){
                start = i;
              }else{
                pnext[prev].push_back(i);
              }
              prev = i;
            }

            if(label.count(buff)){
              next[i].push_back(label[buff]);
              label.erase(label.find(buff));
            }
          }else{
            if(label.count(buff)){
              next[i].push_back(label[buff]);
            }
            label[buff] = i;
          }
        }
      }
    }

    /*
    REP(i,n){
      printf("%d: %s\n", i + 1, str[i].c_str());
      printf("next: "); REP(j, next[i].size()) printf("%d ", next[i][j] + 1); puts("");
      printf("pnext: "); REP(j, pnext[i].size()) printf("%d ", pnext[i][j] + 1); puts("");
    }
    */

    print(start);
    // cout << endl;
  }
  return 0;
}

Measured memory_bytes: 0
using System;
class Program{
    static void Main(string[]args){
     string[] t=Console.ReadLine().Split(' ');
     int a=int.Parse(t[0]);
     int b=int.Parse(t[1]);
     Console.WriteLine(sum(b-a)-b);

    }
    static int sum(int n){
        return (n+n*n)/2;
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int findIndex(vector<int> vec, int value)
{
    vector<int>::iterator iter = std::find(vec.begin(), vec.end(), value);
    size_t index = distance(vec.begin(), iter);
    if(index == vec.size())
    {
        return -1;
    }
    return index;
}


int main()
{
    int s;
    int a[1000000];
    cin >> s;

    a[0] = s;
    for (int i = 1; i < 1000001; i++)
    {
        if (a[i-1] % 2 == 0)
        {
            a[i] = a[i-1] / 2;
        }
        else
        {
            a[i] = 3 * a[i-1] + 1;
        }  
    }

    vector<int> v;
    v.push_back(s);
    int ans = 0;
    for (int i = 1; i < 1000001; i++)
    {
        if (findIndex(v, a[i]) >= 0)
        {
            ans = i + 1;
            break;
        }
        else
        {
            v.push_back(a[i]);
        }
    }

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

Measured memory_bytes: 4096
N,M=map(int,input().split())
ab=[]
for i in range(M):
    a,b=map(int,input().split())
    a,b=a-1,b-2
    ab.append([a,b])
ab.sort(key=lambda x:x[1])
ans=1
x=ab[0][1]
for a,b in ab[1:]:
    if a<=x:
        continue
    x=b
    ans+=1
print(ans)


Measured memory_bytes: 63472
A, B, C, X, Y = map(int, input().split())
P = []

for i in range(0, max(X, Y)+1):
    if min(X, Y)-i >= 0:
        P.append(A*(X-i) + B*(Y-i) + 2*C*i)
    else:
        if X > Y:
            P.append(A*(X-i) + 2*C*i)
        else:
            P.append(B*(Y-i) + 2*C*i)

print(min(P))


Measured memory_bytes: 12672
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b,c,d;
  int temp; 
  
  cin >> a >> b >>c;

  temp =  c;
  for(int cnt =0; cnt <10; cnt ++){
    d = a * temp -b;
    temp = d;
    cout << d << endl;
  }
}


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

using namespace std;

typedef long long LL;

#define MAX_N 1005

int N;
int A, B;
int T[MAX_N];

void input()
{
  cin >> N;
  cin >> A >> B;
  for (size_t i = 0; i < N; i++) {
    cin >> T[i];
  }
}

int solve()
{
  int ret = 0;
  for (size_t i = 0; i < N; i++) {
    ret += (T[i] < A || B <= T[i]);
  }
  return ret;
}

int main()
{
  input();
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
        using namespace std;
        long long m=1000000007;
     
        #define boost ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        #define MAX(a,b) ((a)>(b)?(a):(b))
        #define MIN(a,b) ((a)<(b)?(a):(b))
        #define pb  push_back
        #define p2  second
        #define p1  first
        typedef long long ll;
        typedef long double ld; 
        long long M=1e9+7;			
        #define deb_(x)       cerr<< #x <<" : "<< x << endl;
        #define deb(A,N)    cerr <<" :[";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
        #define deb2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}																				
        #define rep(n) for(int i=0;i<n;i++)																		
        #define range(a,b) for(int i=a;i<=b;i++)																	
        #define loop(i,n) for(int i=0;i<n;i++)
    	void code();
     
        int main()
        {   
        	boost;
           ll t=1;
           // cin>>t;
           while(t--){
           	code();
           }
         
           return 0;
        }
     
       
        void code(){
        	ll n,k;
        	cin>>n>>k;
        	ll A[n];
        	rep(n)cin>>A[i];
        	ll dp[n];
        	dp[0]=0;
        	// dp[1]=abs(A[1]-A[0]);
        	range(1,n-1){
        		if(i<=k)dp[i]=abs(A[i]-A[0]);
        		else{
        			dp[i]=INT_MAX;
        			for(int c=i-1;c>=(i-k);c--){
        				dp[i]=MIN(dp[i],dp[c]+abs(A[c]-A[i]));
        			}
        		}

        	}
        	// deb(dp,n);
        	cout<<dp[n-1]<<endl;

       	
        }

Measured memory_bytes: 1792
// abc159_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    map<ll, ll> mp;
    REP(i, N){
        mp[A[i]]++;
    }
    ll ans = 0;
    for (auto e: mp){
        ll n = e.second;
        ans += n * (n - 1) / 2;
    }

    REP(k, N){
        ll x = mp[A[k]];
        ll tmp;
        if (x == 1){
            tmp = ans;
        } else {
            tmp = ans - (x * (x - 1) / 2) + (x-1)*(x-2)/2;
        }
        print(tmp);
    }




    return 0;
}


Measured memory_bytes: 12800
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int x = sc.nextInt();
        
        String result = "NO";
        if (a <= x && x <= a+b) result = "YES";
        
        System.out.println(result);
    }
}


Measured memory_bytes: 35732
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;++x)
#define Red(x,y,z) for(int x=y;x>=z;--x)
using namespace std;
const int MAXN=1e6+5;
char buf[1<<12],*p1=buf,*p2=buf,nc;int ny;
inline char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;if(nc<0)return nc;
	x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48);return x*ny;
}
int vis[MAXN];
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	for(int t=1,k=read(),n=7%k;;n=(n*10+7)%k,t++){
		if(n==0){cout<<t;return 0;}if(vis[n])break;vis[n]=1;
	}puts("-1");
	return 0;
}



Measured memory_bytes: 7488
import sys

N , K = map(int, input().split())
box = []

for i in range(N):
    box.append([int(i) for i in input().split()])
    
box.sort()
cnt = 0
for i in range(N):
    cnt += box[i][1]
    if cnt >= K:
        print(box[i][0])
        sys.exit()

Measured memory_bytes: 21652
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <climits>

using namespace std;

void call(int n){
	int i = 1;

	do {
		int x = i;
		if ( x % 3 == 0 ){
    		cout << " " << i;
		}
		else {
			while (x)  {
				if ( x % 10 == 3 ){
    				cout << " " << i;
    				break;
				}
				else {
					x /= 10;
				}
			}
		}	
	} while ( ++i <= n ); 

  cout << endl;
}


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




Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  string s;
  ll ch;
  cin>>s>>ch;
  ll num = 0;
  while(s[num]=='1'){
  	num++;
  }
  if(ch<=num){
  	cout<<1<<endl;
  }else{
  	cout<<s[num]<<endl;
  }
}



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

int main(){
  int k,n; cin>>n>>k;
  int ans = ((n-k)/(k-1))+1;
  if ((n-k)%(k-1)!=0) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
using namespace std;
int main(){
    string N;
    cin >> N;
    if(N[0]==N[1]){
        if(N[2]<=N[0]){
            N[2]=N[0];
            cout << N << endl;
        }else{
            N[2]=N[0]+1;
            N[1]=N[2];N[0]=N[1];
            cout << N << endl;
        }
    }if(N[0]>N[1]){
        N[1]=N[0];N[2]=N[1];
        cout << N << endl;
    }if(N[0]<N[1]){
        N[0]=N[0]+1;N[1]=N[0];N[2]=N[1];
        cout << N << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define for_int(i,a,b) for(int i=(a);i<=(b);++i)
#define rep_int(i,a,b) for(int i=(a);i>=(b);--i)
#define for_ll(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep_ll(i,a,b) for(ll i=(a);i>=(b);--i)
#define ull unsigned long long
#define ll long long
#define db double
#define HPMAX 1005
#define KMP_MAX 1005
#define prime_MAX 1000005
#define quick_pow_mod 1000000007
#define PII pair<int,int>
const int factor_N = 10000005;
const int tree_arr_N = 1000005;
using namespace std;
//快读
int read() {
	char c = getchar();
	int x = 0, f = 1;
	for (; !isdigit(c); c = getchar())
		if (c == '-') f = -1;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
	return x * f;
}
string s;
int main() {
	cin >> s;
	if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') cout << 3 << endl;
	else if (s[0] == 'R' && s[1] == 'R') cout << 2 << endl;
	else if (s[1] == 'R' && s[2] == 'R') cout << 2 << endl;
	else if (s[0] == 'S' && s[1] == 'S' && s[2] == 'S') cout << 0 << endl;
	else cout << 1 << endl;
	return 0;
}

Measured memory_bytes: 3616
N = int(input())
l = list(map(int, input().split()))
a, b, c = 0, 0, 0

for i in l:
    if i % 4 == 0:
        c += 1
    elif i % 2 == 0:
        b += 1
    else:
        a += 1

if b >= 1:
    if c >= a:
        print("Yes")
    else:
        print("No")
else:
    if c+1 >= a:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 15020
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
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))

int main() {
    // string s;
    // cin>>s;
    // int cnt=0;
    // for(int i=0;i<s.size()-1;i++){
    //     if(s.at(i)!=s.at(i+1)){
    //         cnt++;
    //     }
    // }
    // cout<<cnt<<endl;

    int x,y;
    cin>>x>>y;
    if(x%y==0){
        cout<<"-1"<<endl;
    }
    else{
        cout<<x<<endl;
    }




    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define A_MAX 1000000
#define A_MAX_HALF 500000
 
using namespace std;
 
int min_factor[A_MAX + 1];
int q[A_MAX + 1];
int a[A_MAX + 1];
 
int main() {
    vector<int> primes;
    for (int i = 2; i <= A_MAX_HALF; ++i) {
        if (!min_factor[i]) {
            min_factor[i] = i;
            primes.push_back(i);
        }
        int min_factor_i = min_factor[i];
        for (int p : primes) {
            int n = i * p;
            if (n > A_MAX) {
                break;
            }
            min_factor[n] = p;
            if (p == min_factor_i) {
                q[n] = q[i];
                break;
            } else {
                q[n] = i;
            }
        }
    }
 
    int N = 0;
    char c = getchar_unlocked();
    do {
        N = 10 * N + c - '0';
    } while ((c = getchar_unlocked()) >= '0');
    for (int i = 0; i < N; ++i) {
        int A = 0;
        c = getchar_unlocked();
        do {
            A = 10 * A + c - '0';
    	} while ((c = getchar_unlocked()) >= '0');
        ++a[A];
    }
 
    int is_pairwise_coprime = 1;
    for (int n = A_MAX; n > 1; --n) {
        int an = a[n];
        if (an) {
            if (an > 1) {
                if (an == N) {
                    printf("not coprime\n");
                    return 0;
                }
                is_pairwise_coprime = 0;
            }
            a[min_factor[n]] += an;
            a[q[n]] += an;
        }
    }
    if (is_pairwise_coprime) {
        printf("pairwise coprime\n");
    } else {
        printf("setwise coprime\n");
    }
 
    return 0;
}

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

int main(){
    LL x, y;
    cin >> x >> y;
    LL ans = abs(abs(x)-abs(y));
    if(x*y > 0){
        if(x > y)   ans += 2;
    }else if(x*y < 0){
        ans++;
    }else{
        if(x > y)   ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 1e4+10, D = 101;

string s;
int d;
int dp[2][D][2];

void add(int& a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> s >> d;
  int n = s.size();
  dp[1][0][0] = dp[1][0][1] = 1;
  for (int i = n-1; i >= 0; i--) {
    for (int r = 0; r < d; r++) {
      dp[0][r][0] = dp[0][r][1] = 0;
      for (int j = 0; j < 10; j++) {
        int nr = (r + j) % d;
        add(dp[0][r][1], dp[1][nr][1]);
      }
      for (int j = 0; j < s[i]-'0'; j++) {
        int nr = (r + j) % d;
        add(dp[0][r][0], dp[1][nr][1]);
      }
      int nr = (r + s[i]-'0') % d;
      add(dp[0][r][0], dp[1][nr][0]);
      //cerr << i << " " << r << " -> " << dp[0][r][0] << " " << dp[0][r][1] << nl;
    }
    swap(dp[0], dp[1]);
  }
  cout << (dp[1][0][0]+MOD-1)%MOD << nl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,i,sum;
    int *p;
    cin>>n>>k;
    p=new int [n];
    for(i=0;i<n;i++)
        cin>>p[i];
    sort(p,p+n);
    sum=0;
    for(i=0;i<k;i++)
        sum+=p[i];
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3636
#define ll long long int
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define maxx(a,b) std::max(a,b)
#define maxxx(a,b,c) std::max(a,std::max(b,c))
#define minn(a,b) std::min(a,b)
#define minnn(a,b,c) std::min(a,std::min(b,c))
#define pii 3.14159265358979323846

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

int main()
{  
  ll a;
  cin>>a;
  ll sum=0;
  sum+=a+pow(a,2)+pow(a,3);
  cout<<sum<<endl;
    
   return 0;
}





Measured memory_bytes: 4032
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

bool pairCompare(const std::pair<string, int>& firstElem, const std::pair<string, int>& secondElem) {
    if(firstElem.second != secondElem.second){
        return firstElem.second > secondElem.second;
    }else{
        if(firstElem.first.size() != secondElem.first.size()){
            return firstElem.first.size() < secondElem.first.size();
        }
        else
            return firstElem.first < secondElem.first;
    }
}

int main(){
    int n;
    map<string, int> m;
    int stringSize = 0;

    cin >> n;
    for(int i=0; i < n; i++){
        string s; int p;
        cin >> s >> p;
        stringSize = max(stringSize, (int)s.size());
        m[s] += p;
    }

    for(int i=0; i <= stringSize; i++){
        map<string, int>::iterator it = m.begin();
        while(it != m.end()){
            if(i == (*it).first.size())
                cout << (*it).first << " " << (*it).second << endl;
            ++it;
        }
    }
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> node[100005];
bool used[100005];
int main(){
  ll n,m;
  cin>>n>>m;
  for(int i=0;i<n;i++) used[i]=false;
  ll s,t;
  cin>>s>>t;
  node[s].push_back(t);
  node[t].push_back(s);
  for(int i=1;i<m;i++){
    ll a,b;
    cin>>a>>b;
    node[a].push_back(b);
    node[b].push_back(a);
  }
  deque<int> ans;
  ans.push_front(s);
  ans.push_back(t);
  used[s]=true;
  used[t]=true;
  while(1){
    bool f1=true,f2=true;
    for(int i=0;i<node[s].size();i++){
      if(!used[node[s][i]]){
        f1=false;
        s=node[s][i];
        ans.push_front(s);
        break;
      }
    }
    used[s]=true;
    if(!f1) continue;

    for(int i=0;i<node[t].size();i++){
      if(!used[node[t][i]]){
        f2=false;
        t=node[t][i];
        ans.push_back(t);
        break;
      }
    }
    used[t]=true;
    if(!f2) continue;
    if(f1&&f2) break;
  }
  cout<<ans.size()<<endl;
  while(!ans.empty()){
    cout<<ans.front()<<" ";
    ans.pop_front();
  }
  cout<<endl;
}


Measured memory_bytes: 6784
n, k = [int(i) for i in input().split()]
v = [int(i) for i in input().split()]

# 左右から計min(n,k-i)個取り出す
# 0<=i<=k//2
# i個捨てる

ans = 0
# k_i回行う
for k_i in range(min(2*n+1,k+1)):
  # i個捨てる
  # k_iがnより大きい場合は捨てる個数の最低数が0より大きい
  rem_min = 0
  if k_i > n:
    rem_min = k_i - n
  for rem in range(rem_min, k_i//2+1):
    #左からj個、右から残りを取る
    for j in range(k_i-rem+1):
      #print(j)
      hand_tmp = v[:j] + v[::-1][:k_i-rem-j]
      hand_tmp.sort()
      #print(hand_tmp)
      # 小さいものからi個捨てる
      hand_tmp = hand_tmp[rem:]
      ans_tmp = sum(hand_tmp)
      if ans_tmp > ans:
        ans = ans_tmp
        
print(ans)
    

Measured memory_bytes: 3064
#include <stdio.h>

void chess(int H, int W) {

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if ((i+j) % 2 == 0) {
                printf("#");
            } else {
                printf(".");
            }
        }
        printf("\n");
    }
    printf("\n");
}

int main(int argc, char const *argv[]) {

    while (1) {
        int H, W;
        scanf("%d %d", &H, &W);

        if (H == 0 && W == 0) {
            break;
        } else {
            chess(H, W);
        }
    }

    return 0;
}



Measured memory_bytes: 2048
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define sz size()
#define pb push_back
#define mp make_pair
#define ALL(X) (X).begin(),(X).end()

using namespace std;

const int INF = 1000000000;
const double eps = 1e-8;

int main(void) {
  while(1){
    int n,m,p;cin>>n>>m>>p;
    if(!n)break;
    int s=0;
    int t=0;
    REP(i,n){
      int x;cin>>x;
      s+=x;
      if(i==m-1)
        t=x;
    }
    if(t==0)
      cout<<0<<endl;
    else{
      int money=s*(100-p)/t;
      cout<<money<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
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; }

int main(){
    ll N,M,K;
    cin>>N>>M>>K;
    set<ll> s;
    for(ll i=0;i<=N;i++){
        for(ll j=0;j<=M;j++){
            if(K==N*j+M*i-2*i*j){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>

#define N 1000

using namespace std;

int main(){
	int data[N];
	int n , sum[N];
	int e[N] , p , q;

	while(1){
		int flag = 0;
		
		cin >> n;
		if(n == 0) break;
	
		for(int i = 0; i < n; i++){
			cin >> e[i] >> p >> q;
			sum[i] = p * q;
		
		}for(int i = 0; i < n; i++){
			for(int j = i + 1; j < n; j++){
				if(e[i] == e[j]){
					sum[i] += sum[j];
				}
			}
		}for(int i =  0; i < n; i++){
			if(sum[i] >= 1000000){
				flag = 1;
				cout << e[i] << endl;
			}
		}if(flag == 0){
			cout << "NA" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 2992
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
main(){
    string S;
    cin >> S;
    if(S[0] == '9' || S[1] == '9')cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
from sys import stdin
from functools import reduce
from operator import mul
MOD = 10**9+7
N, K = [int(_) for _ in stdin.readline().rstrip().split()]

def cmb(n, r):
    if n < r:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    numerator = reduce(mul, range(n, n-r, -1))
    denominator = reduce(mul, range(1, r+1))
    return numerator // denominator

for i in range(1, K+1):
    print(cmb(K-1, i-1) * cmb(N-K+1, i) % MOD)

Measured memory_bytes: 3940
#include <stdio.h>
int main(void) {
	int n, l, m, i, a, e, ma, pm, aps, ans;
	scanf("%d", &n);
	scanf("%d", &l);
	e = 10000;
	pm = 1;
	aps = 0;
	for (i = 0; i < n; i++) {
		aps = aps + l + i;
	}
	for (i = 0; i < n; i++) {
		a = l + i;
		if (a >= 0) {
			if (a < e) {
				e = a;
				pm = 1;
			}
		}
		else {
			ma = 0 - a;
			if (ma < e) {
				e = ma;
				pm = 0;
			}
		}
	}
	if (pm == 1) {
		printf("%d", aps - e);
	}
	else if (pm == 0) {
		printf("%d", aps + e);
	}

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    
    int cnt=0;
    for(int i=a;i<=b;i++){
        string s=to_string(i);
        int cnt2 =0;
        for(int j=0;j<s.size()/2;j++){
            if(s.at(j) == s.at(s.size()-j-1)){
                cnt2 ++;
            }
        }
        if(cnt2==s.size()/2){
            cnt++;
        }
    }
    
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<queue>
#include<string.h>
#include<cstring>
#include<vector>
#include<time.h>
#include<stdlib.h>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define FIN freopen("input.txt","r",stdin)
#define mem(x,y) memset(x,y,sizeof(x))
typedef unsigned long long ULL;
typedef long long LL;
#define MX 11111111
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef pair<pair<int,int>,int> PIII;
typedef pair<int,int> PII;
int n;
char s[MX],ss[MX],p[2]= {'S','W'};
bool check(char *ss)
{
    ss[n]=0;
    for(int i=0; i<2; i++)
        for(int j=0; j<2; j++)
        {
            ss[0]=p[i];
            ss[1]=p[j];
            for(int k=1; k<n-1; k++)
            {
                if(ss[k]=='S')
                {
                    if(s[k]=='o')
                    {
                        if(ss[k-1]=='S')ss[k+1]='S';
                        else ss[k+1]='W';
                    }
                    else
                    {
                        if(ss[k-1]=='S')ss[k+1]='W';
                        else ss[k+1]='S';
                    }
                }
                else
                {
                    if(s[k]=='o')
                    {
                        if(ss[k-1]=='S')ss[k+1]='W';
                        else ss[k+1]='S';
                    }
                    else
                    {
                        if(ss[k-1]=='S')ss[k+1]='S';
                        else ss[k+1]='W';
                    }
                }

            }
            int cnt=0;
            if(ss[n-1]=='S')
            {
                if(s[n-1]=='o')
                {
                    if(ss[n-2]==ss[0])cnt++;
                }
                else
                {
                    if(ss[n-2]!=ss[0])cnt++;
                }
            }
            else
            {
                if(s[n-1]=='o')
                {
                    if(ss[n-2]!=ss[0])cnt++;
                }
                else
                {
                    if(ss[n-2]==ss[0])cnt++;
                }
            }
            if(ss[0]=='S')
            {
                if(s[0]=='o')
                {
                    if(ss[n-1]==ss[1])cnt++;
                }
                else
                {
                    if(ss[n-1]!=ss[1])cnt++;
                }
            }
            else
            {
                if(s[0]=='o')
                {
                    if(ss[n-1]!=ss[1])cnt++;
                }
                else
                {
                    if(ss[n-1]==ss[1])cnt++;
                }
            }
            if(cnt==2) return 1;
        }
    return 0;
}
int main()
{
    //freopen("output2.txt","w",stdout);

    scanf("%d",&n);
    {
        scanf("%s",&s);
        if(check(ss)) printf("%s\n",ss);
        else puts("-1");

    }
    return 0;
}

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

using namespace std;

constexpr int MAXN = 1e6 + 6, MOD = 1e9 + 7;

int n, a, b, c, ans;
string s;
int divisor[MAXN];

int main() {
    std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
        for (int j = i; j <= n; j += i)
            divisor[j]++;
    for (c = 1; c <= n - 1; c++) {
        int ab = n - c;
        ans += divisor[ab];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7504
#include <bits/stdc++.h>
#define ListeningTo ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
using namespace std;

int main() {
    ListeningTo // The 1975 - Somebody Else | youtu.be/ssF-hrwAHHc		

    long double a, b;
    cin >> a >> b;
    cout << (ll)(a*b);
}	


Measured memory_bytes: 3748
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
bool DEBUG = 0; void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void main(string[] args){ args ~= ["", ""]; string cmd = args[1]; if(cmd == "-debug") DEBUG = 1;
if(cmd == "-gen") gen; else if(cmd == "-jury") jury; else solve; } 
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ std.stdio.write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void gen(){
}
void jury(){
}
void solve(){
    int n = scan!int;
    long[] as = scan!long(n);

    as.sort!"a>b"();

    auto ah = new RedBlackTree!(long, "a>b", true);
    ah.insert(as[0]);

    long ans = 0;
    foreach(a; as[1 .. $]){
        ans += ah.front;
        ah.removeFront;
        ah.insert(a), ah.insert(a);
        log("ans:", ans, "ah:", ah[]);
    }

    ans.writeln;
}

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

odds = []
evens = []
for a in A:
    if a%2 == 0:
        evens.append(a)
    else:
        odds.append(a)

num_evens = len(evens)
num_odds = len(odds)

if num_odds%2 == 0:
    num_evens += num_odds/2
    num_odds = 0
    print('YES')
else:
    num_evens += (num_odds-1)/2
    num_odds = 1
    print('NO')




Measured memory_bytes: 14108
S = str(input())

a = True
b = True

if int(S[0]) > 1 or (int(S[0]) == 1 and int(S[1]) > 2) or (int(S[0]) == 0 and int(S[1]) == 0):
    a = False
if int(S[2]) > 1 or (int(S[2]) == 1 and int(S[3]) > 2) or (int(S[2]) == 0 and int(S[3]) == 0):
    b = False

if a == True and b == True:
    print("AMBIGUOUS")
elif a == True and b == False:
    print("MMYY")
elif a == False and b == True:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 38496
#include<vector>
#include<iostream>
#include<queue>
#include<functional>
using namespace std;

struct edge{
	int from, to, cost;
	bool operator > (const edge& other)const {
		return cost > other.cost;
	}
};

using edges = vector<edge>;
using graph = vector<edges>;

void add_edge(graph& g,int from,int to,int cost){
	g[from].push_back(edge{ from,to,cost });
	g[to].push_back(edge{to,from,cost});
}


edges prim(graph& g) {
	const int N = g.size();
	vector<bool>visited(N, false);
	visited[0] = true;
	priority_queue<edge,vector<edge>,greater<edge>>p_que;
	edges mst;
	for (auto e : g[0]) {
		p_que.push(e);
	}
	while (!p_que.empty()) {
		auto e = p_que.top();
		p_que.pop();
		if (visited[e.to]) {
			continue;
		}
		visited[e.to] = true;
		mst.push_back(e);
		for (auto new_e : g[e.to]) {
			p_que.push(new_e);
		}
		
	}
	return mst;


}

int main() {
	int V, E;
	cin >> V >> E;
	graph g(V);
	for (int i = 0; i < E; i++) {
		int from, to, cost;
		cin >> from >> to >> cost;
		add_edge(g, from, to, cost);
	}
	auto mst = prim(g);
	int ans = 0;
	for (auto e : mst) {
		ans += e.cost;
	}
	cout << ans << endl;
	return 0;

}







Measured memory_bytes: 10112