akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i++)
#define re0(i, n) for (rint i = 0; i < (int) n; i++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template <class T> inline void read(T &x) {
	x = 0; char c = getchar(); int f = 0;
	for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
	for (; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = getchar());
	if (f) x = -x;
}

const int N = 2e5 + 2333;
int n, a[N], du[N];
set <int> s;
set <pair <int, int> > mx;
vector <int> vec;

int main(void) {
	read(n);
	rep (i, n) read(a[i]), s.insert(i), ++du[a[i]];
	rep (i, n) mx.insert({du[i], i});
	int ban = 0;
	while (s.size() > 5) {
		int v = -1;
		if (!mx.empty() && (--mx.end())->first == s.size() - 1) {
			v = (--mx.end())->second;
		} else {
			for (auto it = s.begin(); ; ++it) {
				if (*it != ban) {
					v = *it;
					break;
				}
			}
		}
		assert(v != -1);
		vec.push_back(v);
		ban = a[v];
		s.erase(v);
		mx.erase({du[v], v});
		pair <int, int> t = {du[ban], ban};
		if (mx.count(t)) {
			mx.erase(t);
			du[ban]--; t.first--;
			mx.insert(t);
		}
	}
	vector <int> ret;
	for (auto u : s) ret.push_back(u);
	sort(ret.begin(), ret.end());
	bool found = false;
	do {
		bool valid = true;
		int b = ban;
		for (auto u : ret) {
			if (u == b) {
				valid = false;
			}
			b = a[u];
		}
		if (valid) {
			found = true;
			break;
		}
	} while (next_permutation(ret.begin(), ret.end()));

	if (found == false) {
		cout << -1 << "\n";
		return 0;
	}
	for (auto u : vec) cout << u << " " ;
	for (auto u : ret) cout << u << " " ; cout << "\n";
}


Measured memory_bytes: 11008
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if( min(b,d) - max(a,c) > 0 ){
    cout << min(b,d) -max(a,c) << endl;
  }
  else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N;
    cin >> N;
    vi a(N);
    int sum1=0, sum2=0;
    int res1=0, res2=0;
    rep(i, N) {
        cin >> a[i];
        sum1+=a[i]; sum2+=a[i];
        if(i%2==0) {
            if(sum1<=0) {
                res1 += abs(sum1) + 1;
                sum1 = 1;
            }
            if(sum2>=0) {
                res2 += abs(sum2) + 1;
                sum2 = -1;
            }
        } else {
            if(sum1>=0) {
                res1 += abs(sum1) + 1;
                sum1 = -1;
            } 
            if(sum2<=0) {
                res2 += abs(sum2) + 1;
                sum2 = 1;
            }
        }
    }

    cout << min(res1, res2) << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

const int N = 1e5+7;
int dp[1000][N],n,c,w[N],v[N];

int32_t main()
{
	fast;

	cin>>n>>c;
	for(int i=1;i<=n;i++)
		cin>>w[i]>>v[i];

	int ans = 0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=c;j++)
		{
			dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			if(j>=w[i])
				dp[i][j] = max(dp[i][j],v[i]+dp[i-1][j-w[i]]);
		}
	}
	cout<<dp[n][c];
	return 0;
}

Measured memory_bytes: 80128
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define MAX 10000000
#define SENTINEL 2e10;


int main(){
    int s, w; cin >> s >> w;
    if(s <= w) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

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

bool numCheck(int n) {
    if (n % 3 == 0) {
        return true;
    }
    
    while (n) {
        if (n % 10 == 3) {
            return true;
        }
        n /= 10;
    }
    
    return false;
}

signed main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        if (numCheck(i)) cout << ' ' << i;
    }
    cout << endl;
}


Measured memory_bytes: 3100
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int p = 0,q = 1000000001;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    p = max(p,a);
    q = min(q,a);
  }
  cout << p - q << endl;
  return 0;
}

Measured memory_bytes: 3604
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main() {

    long long a,b,c;
    cin >> a >> b >> c;
    string out = "No";
    long long d = c-a-b;
    if(d > 0 && d*d > 4*a*b) out = "Yes";
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
m,a,d,y,x,Y,X;char*p,b[30][12];check(){for(X=m,Y=0;Y<d;Y++)b[Y][X-1]-49?b[Y][X]-49?0:X++:X--;return X-a;}main(n){while(scanf("%d%d%d%d",&n,&m,&a,&d),n){memset(b,0,360);for(y=0;y<d;)scanf("%s",b[y++]+1);if(!check())puts("0");else{for(y=0;y<d;y++)for(x=0;++x<=n-1;){p=b[y]+x;if(*p==48&&p[-1]-49&&p[1]-49)++*p,check()||main(printf("%d %d\n",1+y,x)),--*p;}puts("1");}}exit(0);}

Measured memory_bytes: 0
#include <stdio.h>

int main(void){
	int i,n,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		if(i%3==0)
			printf(" %d",i);
		else{
			j = i;
			do{
				if(j%10==3){
					printf(" %d",i);
					break;
				}
				j/=10;
			}while(j!=0);
		}
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>

using namespace std;

int main(void) {

	int total = 0;
	int num = 0;
	cin >> num; cin.ignore();

 	vector<int> value(num);
 	vector<int> cost(num);

	for(int i = 0; i < value.size(); i++) {
		cin >> value[i];
	}

	for(int i = 0; i < cost.size(); i++) {
		cin >> cost[i];
	}

	for(int i = 0; i < value.size(); i++) {
		if(value[i] - cost[i] >0) {
			total += value[i] - cost[i];
		}
	}

	cout << total;
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<tuple<string, int, int>> data(N);
  for (int i = 0; i < N; i++) {
    string s; int r;
    cin >> s >> r;
    data.at(i) = make_tuple(s, -r, i+1);
       
  }
  
  sort(data.begin(), data.end());
  
  for (int i = 0; i < N; i++) {
    string a; int b, c;
    tie(a, b, c) = data.at(i);
    cout << c << endl;
  }
}


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

using namespace std;

#define MAX_N 25

int n;
int a[MAX_N];

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

  int count=0;
  for(int i=1;i<n-1;i++){
    if(((a[i-1]<a[i])&&(a[i]<a[i+1]))||((a[i-1]>a[i])&&(a[i]>a[i+1]))){
      count++;
    }
  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    int n,d;
    cin >>n>>d;
    int width=2*d+1;
    cout << ((n-1)/width+1)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll a[100];
int main() {
	ll n; cin >> n;
	rep(i, 0, n)cin >> a[i];

	ll minV = 1 << 21;
	repe(i, -100, 100) {
		ll sum = 0;
		rep(j, 0, n) {
			sum += (a[j] - i)*(a[j] - i);
		}
		if (minV > sum) {
			minV = sum;
		}
	}
	cout << minV << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
char c[3];
int main(){
  rep(i,3){
    cin>>c[i];
  }
  if(c[0]==c[2]){
    prin("Yes");
  }
  else{
    prin("No");
  }

  return 0;
}


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

#define async ios_base::sync_with_stdio(false); cin.tie(NULL);
#define Int long long int
#define let auto
#define of :
#define all(y) y.begin(), y.end()
#define present( x, y ) x.find( y ) != x.end()
#define pb push_back

signed main(){
	int L, R, d, c = 0 ;
	cin >> L >> R >> d ;
	for( int i = L ; i <= R ; i++ ){
		if( i % d == 0 ) c++ ;
	}
	cout << c << endl ;
	return 0 ;
}

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

#define ll long long
#define int ll
#define pii pair<int, int>
#define pb push_back
#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define FORD(i, a, b) for (int i=a; i>=b; i--)
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

using namespace std;

void solve() {
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;

    vector<pair<int, int>> q(Q);
    REP(i, Q) cin >> q[i].first >> q[i].second;

    vector<int> cnt(N);
    int total = 0;
    REP(i, N-1) {
        if ("AC" == S.substr(i, 2)) {
            ++total;
        }
        cnt[i+1] = total;
    }
   
    REP(i, Q) {
        int l = q[i].first;
        int r = q[i].second;
        int ans = cnt[r-1] - cnt[l-1];
        print(ans);
    }
}

signed main() {
    solve();
}


Measured memory_bytes: 3456
n,k = map(int, input().split())
a = [0] + list(map(int, input().split()))
for i in range(n):
    a[i+1] = (a[i] + a[i+1]-1)%k
d = dict()
ans = 0
for i in range(n+1):
    if i >= k:
        d[a[i-k]] -= 1
    if a[i] in d:
        ans += d[a[i]]
        d[a[i]] += 1
    else:
        d[a[i]] = 1
print(ans)


Measured memory_bytes: 110796
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	vector<int> dp(3);
	rep(i,0,n){
		vector<int> c(3);
		vector<int> new_dp(3);
		rep(i,0,3) cin >> c[i];
		rep(i,0,3){
			rep(j,0,3){
				if(i!=j){
					new_dp[i]=max(new_dp[i],dp[j]+c[j]);
				}
			}
		}
		dp=new_dp;
	}
	cout << max(dp[0],max(dp[1],dp[2]));
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


Measured memory_bytes: 256
/*
"Won't stop untill I'm Phenomenal"
- Phenomenal, EMINEM
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;



int main(){
    Shazam;
    int n; cin>>n;
    set<ll> xplusy;
    set<ll> xminusy;
    for(int i = 0 ; i < n; i++){
        ll x,y; cin>>x>>y;
        xplusy.insert(x+y);
        xminusy.insert(x-y);
    }
    cout<<max(abs(*xplusy.rbegin()-*xplusy.begin()),  abs(*xminusy.rbegin()-*xminusy.begin()))<<endl;
    return 0;
}

Measured memory_bytes: 22408
#include<map>
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
typedef long long int ll;
using namespace std;
#define MAX   150002
#define X first
#define Y second
#define MOD 1000000007
#define fr(a,b,c) for(ll a=b;a<c;++a)
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

ll t,n,i,j;
int main()
{
    fastio;
    string s,t;
    cin>>s>>t;
    n=s.length();
    vector <vector<ll > > v(26);
    fr(i,0,n)
        v[s[i]-'a'].pb(i+1);
    ll b,a,ans=0,k;

    if(v[t[0]-'a'].size()==0){
        cout<<"-1";
        return 0;
    }
    a=v[t[0]-'a'][0];
    ans+=a;

    //fr(i,0,26){
      //  fr(j,0,v[i].size())
        //    cout<<v[i][j]<<" ";
        //cout<<endl;
    //}

    fr(i,1,t.length()){
        k=t[i]-'a';
        if(v[k].size()==0){
            cout<<"-1";
            return 0;
        }
        b=upper_bound(v[k].begin(),v[k].end(),a)-v[k].begin();
        if(b==v[k].size())
            b=v[k][0];
        else
            b=v[k][b];

        if(b>a)
            ans=ans+b-a;
        else
            ans=ans+n-a+b;
        //cout<<a<<" "<<b<<" "<<ans<<endl;
        a=b;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1736
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var s = cin.next();
            if(s.Contains("A") && s.Contains("B"))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            
            
        }
    }

    class Scanner
    {
        string[] s;
        int i;

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

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

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

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

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

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

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

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

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


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

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    vector<int> A(N); for (auto &a : A) cin >> a;
    vector<int> B(32);
    int sum = 0, ans = 0;
    for (int a : A) {
        sum ^= a;
        B[__builtin_ctz(a)] = 1;
    }
    for (int i = 30; i >= 0; i--) {
        if (sum & (1 << i)) {
            if (B[i]) {
                sum ^= (1 << (i + 1)) - 1;
                ans++;
            } else {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;

class Program
{
    public static void Main(string[] args)
    {
        bool flag = false;

        int inputNum = int.Parse(Console.ReadLine());
        string[] str = Console.ReadLine().Split(' ');
        int[] inputs = new int[inputNum];

        for(int i = 0; i < inputNum; i++)
        {
           inputs[i] = int.Parse(str[i]);
        }

        for(int i = 1; i < inputNum; i++)
        {
            if (inputs[i - 1] < inputs[i])
            {
                inputs[i] -= 1;
            }
            if (inputs[i - 1] > inputs[i])
            {
                flag = true;
            }
        }

        if (flag)
            Console.WriteLine("No");
        else
            Console.WriteLine("Yes");
    }
}


Measured memory_bytes: 24668
import java.io.PrintWriter
import java.util.*

val pw = PrintWriter(System.out)

fun main(args: Array<String>) {
    val s = read()

    val count = s.count { it == '1' }
    println(count)
    pw.flush()
}

fun inputList() = 
    readLine()!!.split(" ").map(String::toInt)

fun sum_digits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

/****** Decrared Functions ******/

// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }


fun println(value : Any) {
    pw.println(value)
}

fun gcd(a: Long, b: Long): Long = 
    if(b != 0L) a else gcd(b, a % b)

fun lcm(a: Long, b: Long) = 
    if(b==0L) a else gcd(b, a % b)


Measured memory_bytes: 33760
/*
 *Author - Abhas Jain
 */
 
#include <bits/stdc++.h>
 
#define F first
#define S second
#define all(c) c.begin(), c.end()
#define endl '\n'
#define pb push_back
 
 
typedef long long ll;
typedef long double ld;
 
using namespace std;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
 
const ld PI = 3.141592653589793;
const ll INF = 9223372036854775807ll;
const ll mod = 1e9 + 7;
 
void solve() 
{
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
}
 
int main( )
{   
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n,tmp,sum = 0;
    cin >> n;
    vector<int>a(n);
    vector<int>b(n);
    vector<int>c(n-1);

    for(int i = 0;i < n;i++)
        cin >> a[i];
    for(int i = 0;i < n;i++)
        cin >> b[i];
    for(int i = 0;i < n-1;i++)
        cin >> c[i];

    for(int i = 0;i < n;i++){
        sum += b[a[i]-1];
        if(i == 0)
            tmp = a[i]-1;
        else{
            if(tmp == a[i] - 2){
                sum += c[tmp];
            }
            tmp = a[i]-1;
        }
    }

    cout << sum << endl;

    return 0;
}

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

int main() {
	int A,B,C;
	bool qqq=false;
	cin>>A>>B>>C;
	if(A+B+C==17){
		if(A==5||A==7){
			if(B==5||B==7){
			qqq=true;
			}
		}
	}
	qqq?cout<<"YES"<<endl:cout<<"NO"<<endl;
	return 0;
}


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

int main(){
  int n=0;
  int fib[55]={};
  cin>>n;
  fib[0]=fib[1]=1;
  for(int i=2;i<=n;i++){
    fib[i]=fib[i-1]+fib[i-2];
  }
  cout<<fib[n]<<endl;
  return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int n;
	int co[100] = { 0 };
	cin >> n;
	for (int i = 2; i <= n; i++) {
		int i1 = i;
		for (int j = 2; j <= n; j++) {
			if (i1 % j == 0) {
				while (1) {
					if (i1 % j != 0) {
						break;
					}
					i1 /= j;
					co[j]++;
				}
			}
		}
	}
	int ans = 0, ans1 = 0;
	for (int i = 0; i < 100; i++) {
		if (co[i] >= 74) {
			ans++;
		}
		if (co[i] >= 24) {
			for (int j = 0; j < 100; j++) {
				if (i == j) {
					continue;
				}
				if (co[j] >= 2) {
					ans++;
				}
			}
		}
		if (co[i] >= 14) {
			for (int j = 0; j < 100; j++) {
				if (i == j) {
					continue;
				}
				if (co[j] >= 4) {
					ans++;
				}
			}
		}
		if (co[i] >= 4) {
			for (int j = 0; j < 100; j++) {
				if (i == j) {
					continue;
				}
				if (co[j] >= 4) {
					for (int k = 0; k < 100; k++) {
						if (i == k || j == k) {
							continue;
						}
						if (co[k] >= 2) {
							ans1++;
						}
					}
				}
			}
		}
	}
	cout << ans1 / 2 + ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
int main() {
    int n;
    cin >> n;
    long long ans = 1;
    long long MX = 1000000000000000000;
    vector<long long >a(n);
    bool ng = false;
    rep(i, 0, n){
        cin >> a[i];
        if(a[i]==0){
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i, 0, n){
        //a*ans <= MX  ==  a <= MX/ans
        if( a[i] <= MX/ans){
            ans *= a[i];
        } else {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4036
#include<bits/stdc++.h>
#define FastIO ios_base::sync_with_stdio(false), cin.tie(NULL)

typedef long long ll;

using namespace std;

int main()
{
	FastIO;
	ll n; 

	cin >> n;

	if(n % 2 == 0)
		cout << n << "\n";
	else 
		cout << 2*n << "\n";
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  //
  ll x;
  cin >> x;
  vl data(x + 1, 0);
  data[0] = 1;
  vl p = {100, 101, 102, 103, 104, 105};
  REP(i, 1, x + 1) {
    for (auto& t : p) {
      if (i - t >= 0 && data[i - t] > 0) {
        data[i] = 1;
      }
    }
  }
  cout << data[x] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const double pi = 3.141592653589793;

#define INF 1000000000000


signed main(){
  int n;cin>>n;
  if(n>=105&&n<135){cout<<1;}
  else if(n>=135&&n<165){cout<<2;}
  else if(n>=165&&n<189){cout<<3;}
  else if(n>=189&&n<195)cout<<4;
  else if(n>=195) cout<<5;
  else cout<<0;
}


Measured memory_bytes: 256
// package app;

import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);

        final String S = sc.next();
        // final int M = sc.nextInt();
        // final int A = sc.nextInt();
        // final int B = sc.nextInt();
        // final int C = sc.nextInt();
        // final int D = sc.nextInt();

        int cnt = 0;
        for (int i = 0; i < S.length(); i++) {
            cnt += S.charAt(i) == '1' ? 1 : 0;
        }
        // System.out.println();
        System.out.println(cnt);

        // System.out.println(A <= X && A + B >= X ? "YES" : "NO");

    }
}

Measured memory_bytes: 24020
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = [int(input()) for i in range(n)]
    #a = list(map(int, input().split()))
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    n = int(input())
    s = list(int(input()) for i in range(n))
    maxa = sum(s)
    if maxa % 10 != 0:
        print(maxa)
        return 0
    div = sorted([i for i in s if i % 10 != 0])
    if len(div) > 0:
        print(maxa-div[0])
    else:
        print(0)
       
if __name__ == '__main__':
    main()



Measured memory_bytes: 38384
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}    
bool dp1[30005][15],dp2[30005][105],dp3[30005][1005];

signed main()
{
    showoff;
    int n;
    string s;
    cin >> n >> s;
    RFOR(i,n-1,-1){
        FOR(j,0,10)dp1[i][j] = dp1[i+1][j];
        dp1[i][s[i]-'0'] = 1; 
    }
    RFOR(i,n-1,-1){
        FOR(j,0,100)dp2[i][j] = dp2[i+1][j];
        FOR(j,0,10)if(dp1[i+1][j])dp2[i][(s[i]-'0')*10+j] = 1;
    }
    RFOR(i,n-1,-1){
        FOR(j,0,1000)dp3[i][j] = dp3[i+1][j];
        FOR(j,0,100)if(dp2[i+1][j])dp3[i][(s[i]-'0')*100+j] = 1;
    }
    set<int>st;
    FOR(i,0,1000){
        FOR(j,0,n)if(dp3[j][i])st.insert(i);
    }
    cout << sz(st);
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...#include <bits/stdc++.h>
 

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

int main(){
  string s;cin>>s;
  int N=s.size();
  string  check="";
  
  for(int i=N-1;i>=0;i--){
    check.push_back(s.at(i));
    //cout<<check<<endl;
    if(check=="resare" || check=="esare" || check=="remaerd" || check=="maerd"){
      check="";
      //cout<<"if"<<endl;
    }
    
  }
  if(check=="")
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
  //cout<<check;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a) for(int i = 0; i < a; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    string s; cin>>s;
    sort(s.begin(),s.end());
    if(s=="abc") cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <cmath>
#define ll long long  
#define PI 3.14159265358979323846
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb emplace_back
#define watch5(a,b,c,d,e) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d << " | "<<#e<<": "<<e<<endl;
#define watch4(a,b,c,d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define watch3(a,b,c) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<endl;
#define watch2(a,b) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<< endl;
#define watch(a) cerr <<#a<<": "<<a<<endl;
#define F first
#define S second
#define mod 1073741824
using namespace std;

int min(int a, int b){
  return a<b?a:b;
}

int32_t main(){
	IOS;
  string s, t;
  cin >> s >> t;
  int ans = t.size();
  int n = s.size();
  int m = t.size();
  for(int i = 0; i < n - m + 1; i++){
    int cnt = 0;
    for(int j = 0; j < m; j++){
     // watch2(i+j,j)
      if(s[i+j] != t[j]){
        //watch2(s[i+j],t[j])
        cnt++;
      }
    }
    ans = min(ans, cnt);
  }
  cout << ans;
}																				  

Measured memory_bytes: 3652
import math
ans=0
n=int(input())
for i in range(1,n+1):
  for j in range(i,n+1):
    for k in range(j,n+1):
      a=math.gcd(math.gcd(i,j),k)
      if i==j==k:
        ans=ans+a
      elif i==j or i==k or j==k:
        ans=ans+3*a
      else:
        ans=ans+6*a
print(ans)

Measured memory_bytes: 70128
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
	int n,m,x;
	cin >> n >> m >> x;
	
	int c0=0,cn=0;
	rep(i,0,m){
		int a;
		cin >> a;
		if(a < x)
			c0++;
		else
			cn++;
	}

	

	P(min(c0,cn));

	ret 0;
}

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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N, K; cin >> N >> K;
    vector<pl> n(N); REP(i, N) cin >> n[i].first >> n[i].second;
    sort(ALL(n));

    ll c = 0;
    ll i = 0;
    while(true)
    {
        c += n[i].second;
        if(c >= K)
        {
            cout << n[i].first << endl;
            return 0;
        }
        i++;
    }
}

Measured memory_bytes: 4748
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        long K = sc.nextLong();
        char[] s = S.toCharArray();
        char tmp = 0;
        boolean key = false;
        long count = 0;
        char one = s[0];
        boolean ok = true;
        for (int i = 1; i < s.length; i++) {
            if (s[i] != one) {
                ok = false;
            }
        }
        if (ok) {
            System.out.println(K*s.length/2);
            return;
        }
        for (char c : s) {
            if (!key && c == tmp) {
                key = true;
                count++;
            } else if (key) {
                key = false;
            }
            tmp = c;
        }
        key = false;
        tmp = 0;
        long count2 = 0;
        char[] ss = (S+S).toCharArray();
        for (char c : ss) {
            if (!key && c == tmp) {
                key = true;
                count2++;
            } else if (key) {
                key = false;
            }
            tmp = c;
        }
        if (K == 1) {
            System.out.println(count);
        } else {
            System.out.println(count + (count2-count)*(K-1));
        }
    }
}

Measured memory_bytes: 39520
#include <iostream>

using namespace std;

int main()
{
    int a,b,d;
    cin>>a>>b>>d;
    if(a%d)
        {a=(a-a%d)+d;}
    if(b%d)
        b-=b%d;
    int ans=(b-a)/d+1;
    cout<<ans;

}


Measured memory_bytes: 3616
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f3f3f3f3f
#define ll long long
const int maxn = 1e5 + 500;
ll dp[2][maxn];//dp[0][i]表示正向走到i点获得的最大能量，dp[1][i]为反向...
ll g[2][maxn];//g[0][i]表示正向走到i点回到x=0位置所拥有的能量，g[1][i]反之...
ll x[maxn], v[maxn];
ll n, c, sum;
int main() {
	scanf("%lld%lld", &n, &c);
	for (int i = 1; i <= n; i++) scanf("%lld%lld", &x[i], &v[i]);
	for (int i = 0; i <= n + 1; i++)dp[0][i] = dp[1][i] = -inf;
	for (int i = 1; i <= n; i++) {//正向遍历
		sum += v[i];  
		dp[0][i] = max(dp[0][i - 1], sum - x[i]);
		g[0][i] = sum - 2 * x[i];
	}
	sum = 0;
	for (int i = n; i >= 1; i--) {//反向遍历
		sum += v[i];
		dp[1][i] = max(dp[1][i + 1], sum - (c - x[i]));
		g[1][i] = sum - 2 * (c - x[i]);
	}
	ll ans = max(dp[0][n], dp[1][1]);
	for (int i = 1; i <= n; i++) {
		ans = max(ans, g[0][i] + dp[1][i + 1]);
		ans = max(ans, g[1][i] + dp[0][i - 1]);
	}
	printf("%lld\n", ans > 0 ? ans : 0);//若ans<0可以选择不走
	return 0;
}

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

if N == 2:
  print(1)
  exit()

S = set([N-1])
lst = [N]
i = 2
while i*i <= N-1:
  if (N-1) % i == 0:
    S.add(i)
    S.add((N-1)//i)
  i += 1  
  
i = 2
while i*i < N:
  if N % i == 0:
    lst.append(i)
    lst.append(N//i)
  i += 1
    
if i*i == N:
  lst.append(i)
  
lst.sort()

for l in lst:
  if l in S:
    continue
  _N = N
  while _N % l == 0:
    _N //= l
  if _N % l == 1:
    S.add(l)
    
print(len(S))

Measured memory_bytes: 66184
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    // 数値の配列を作る
    const numList0 = input[0].split(' ').map(x => parseInt(x, 10));
    const A = numList0[0];
    const B = numList0[1];

    if (A === B) {
        console.log(0);
        return;
    }

    const div = (A + B) / 2;
    if (Number.isInteger(div)) {
        console.log(div);
    } else {
        console.log('IMPOSSIBLE')
    }
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21192
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if((a * b) % 2 == 1) {
        cout << "Odd" << endl;
    } else {
        cout << "Even" << endl;
    }

    return 0;
}


Measured memory_bytes: 3656
#include<stdio.h>
#include<math.h>
int main()
{
    int a,b,c,d,e,k;
    scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&k);
    if(fabs(a-b)>k){printf(":(");return 0;}
    if(fabs(a-c)>k){printf(":(");return 0;}
    if(fabs(a-d)>k){printf(":(");return 0;}
    if(fabs(a-e)>k){printf(":(");return 0;}
    if(fabs(b-c)>k){printf(":(");return 0;}
    if(fabs(b-d)>k){printf(":(");return 0;}
    if(fabs(b-e)>k){printf(":(");return 0;}
    if(fabs(c-d)>k){printf(":(");return 0;}
    if(fabs(c-e)>k){printf(":(");return 0;}
    if(fabs(d-e)>k){printf(":(");return 0;}
    printf("Yay!");
    return 0;
}

Measured memory_bytes: 128
//https://onlinejudge.u-aizu.ac.jp/courses/lesson/8/ITP2/2/ITP2_2_A
#include <iostream>
#include <stack>
#include <vector>

int main()
{
    int n, q;
    std::cin >> n >> q;
    std::vector<std::stack<int>> st(n);

    int m ,t, x;
    for (int i = 0; i < q; i++)
    {
        std::cin >> m>>t;
        if (m == 0)
        {
            std::cin >> x;
            st[t].push(x);
        }
        else if (m == 1)
        {
            if (st[t].size() > 0)
            {
                std::cout << st[t].top() << std::endl;
            }
        }
        else if (m == 2)
        {
            if (st[t].size() > 0)
            {
                st[t].pop();
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4348
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

int main() {

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

	Int N;
	cin >> N;

	vector<Int> a(N);
	for (Int i = 0; i < N; i++) {
		cin >> a[i];
	}

	Int ans = 0;
	Int right = 0;
	Int sum = 0;
	for (Int left = 0; left < N; left++) {
		while (right < N && ((sum ^ a[right]) == (sum + a[right]))) {
			sum += a[right];
			right++;
		}

		ans += right - left;
		sum -= a[left];
	}

	cout << ans << endl;

}

Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;

signed main() {
	string O, E;
	cin >> O >> E;
	if (O.size() == E.size()) {
		rep(i, O.size())cout << O[i] << E[i];
	}
	else {
		rep(i, E.size())cout << O[i] << E[i];
		cout << O[O.size() - 1];
	}
}

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

int main(){
  long a,b,c; cin>>a>>b>>c;
  long ans;
  if(a%2==0 or b%2==0 or c%2==0) ans=0;
  else ans=min({a*b,b*c,c*a});
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace std;
#define all(a) (a).begin(), (a).end()
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

vector<long long> v;
void rekkyo(int i, int last){
    if(last!=0){
        int h = stol(to_string(i)+to_string(last-1));
        if(h<=323456666) rekkyo(h,last-1);
        v.push_back(h);
    }
    int j = stol(to_string(i)+to_string(last));
    if(j<=323456666) rekkyo(j,last);
    v.push_back(j);
    if(last!=9){
        int k = stol(to_string(i)+to_string(last+1));
        if(k<=323456666) rekkyo(k,last+1);
        v.push_back(k);
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long K;
    cin>>K;
    FOR(i,1,10){
        v.push_back(i);
        rekkyo(i,i);
    }
    sort(all(v));
    cout<<v[K-1]<<endl;
    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

int64_t sub(int64_t n) {
	int64_t a = (n + 1) * n / 2;
	return a;
}

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

	map<string, int64_t> m;

	for (int64_t i = 0; i < N; i++) {
		string S;
		cin >> S;
		sort(S.begin(), S.end());
		if (m.count(S) == 0) {
			m[S] = 1;
		}
		else {
			m.at(S)++;
		}
	}

	int64_t ret = 0;
	for (auto a: m) {
		int64_t n = a.second;
		//cout << n << endl;
		if (n == 1) continue;
		ret += sub(n - 1);
		//cout << ret << endl;
	}

	cout << ret << endl;
}

Measured memory_bytes: 11344
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


bool comp (const pair<string, int> &a, const pair<string, int> &b) {
	if (a.snd > b.snd) return true;
	if (a.snd < b.snd) return false;
	return a.fst < b.fst;
}

int main() {
	for(int N, M, K, L; scanf("%d %d %d %d", &N, &M, &K, &L), (N | M | K | L) != 0; ) {
		vector<pair<string, int> > ns;
		map<string, int> nx;
		rep(i, N) {
			char name[20];
			int x;
			scanf("%s %d", name, &x);
			ns.pb(mp(name, x));
			nx[string(name)] = x;
		}
		set<string> favs;
		vector<pair<string, int> > fx;
		vector<pair<string, int> > nfx;
		rep(i, M) {
			char name[20];
			scanf("%s", name);
			favs.insert(name);
			fx.pb(mp(name, nx[string(name)]));
		}
		
		rep(i, N) if (!present(favs, ns[i].fst)) {
			nfx.pb(ns[i]);
		}
		
		sort(all(fx), comp);
		sort(all(nfx), comp);
		
//		tr(it, ns) cout << it->fst << " " << it->snd << endl;
		
		
		int lb = 0, ub = min(M, K) + 1;
		int mi;
		ll l = L;
		rep(loop, 20) {
			mi = (lb + ub) / 2;
			int r = K - mi;
			if (r >= nfx.size()) {
				lb = mi;
				l = L;
				continue;
			}
			l = L;
			rep(i, mi) {
				if (fx[i].snd > nfx[r].snd) continue;
				if (fx[i].snd < nfx[r].snd) {
					l -= nfx[r].snd - fx[i].snd;
				}
				if (fx[i].fst > nfx[r].fst) l--;
			}
			
			if (l < 0) {
				ub = mi;
			}
			else {
				lb = mi;
			}
		}
		if (l < 0) mi = 0;
		cout << mi << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, n) for (int i=0; i<n; i++)
#define repi(i, n, iv) for (int i=iv; i<n; i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007

using namespace std;
typedef long long ll;

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

	int N, K;
	cin >> N >> K;

	if (K == 1) {
		cout << 0 << endl;
	} else {
		cout << (N - K) << endl;
	}
}


Measured memory_bytes: 256
package main

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

func readStringIntArray(rd *bufio.Reader, n int) ([]int, error) {
	nums := make([]int, 0, n)
	s, _, err := rd.ReadLine()
	if err != nil {
		return nums, err
	}

	arr := strings.Split(strings.TrimSpace(string(s)), " ")
	for _, i := range arr {
		n, err := strconv.Atoi(i)
		if err != nil {
			return nums, err
		}
		nums = append(nums, n)
	}
	return nums, nil
}

func main() {
	rd := bufio.NewReader(os.Stdin)
	nums, err := readStringIntArray(rd, 1)
	if err != nil {
		panic(err)
	}
	n := nums[0]
	nums, err = readStringIntArray(rd, n)
	for i := len(nums) - 1; i >= 0; i-- {
		fmt.Print(nums[i])
		if i > 0 {
			fmt.Print(" ")
		}
	}
	fmt.Println()
}



Measured memory_bytes: 1100
#include <bits/stdc++.h>
#define MAX 1010
using namespace std;

vector<int> adj[MAX];
int visit[MAX];
int graph[MAX][MAX];

vector<int> dfs(int v, int root)
{
	vector<int> ans;
	visit[v] = 1;
	if (v != root)
	{
		for (int i : adj[v])
		{
			if (i != root && visit[i]) return ans;
		}
		if (graph[v][root])
		{
			ans.push_back(v);
			return ans;
		}
	}
	for (int i : adj[v])
	{
		vector<int> res = dfs(i, root);
		if (!res.empty())
		{
			int flag = 1;
			for (int j : res)
			{
				if (graph[v][j] && i != j)
				{
					flag = 0;
					break;
				}
			}
			if (!flag) continue;
			res.push_back(v);
			return res;
		}
	}
	visit[v] = 0;
	return ans;
}

int main(void)
{
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++)
	{
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		adj[u].push_back(v);
		graph[u][v] = 1;
	}
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++) visit[j] = 0;
		vector<int> res = dfs(i, i);
		reverse(res.begin(), res.end());
		if (!res.empty())
		{
			cout << res.size() << endl;
			for (int j : res) cout << j + 1 << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 3840