akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i,n) for(int i = 0;  i < n ; ++i)
#define REP(i,a,b) for(int i = a ; i <= b ; ++i)
#define filei freopen("input.txt", "r", stdin);
#define fileo freopen("output.txt", "w", stdout);
#define gooi cout<<"Case #"<<i+1<<" :";
#define s(n) scanf("%d",&n)
#define rev(i,n) for(int i = n ; i >= 0 ; --i)
#define REV(i,a,b) for(int i = a ; i >= b ; --i)
#define miN(a,b) (((a)<(b))?(a):(b))
#define sc(n) scanf("%c",&n)
#define tr(c,i) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define INF 1000000000
#define pii pair<long long int,long long int>
#define pb(a) push_back(a)
#define F first
#define S second
typedef long long ll;
using namespace std;
void pre(){}
void solve(){
    int d;
    map<int,int>m;
    for(int i=0;i<6;i++){
        cin>>d;
        m[d]++;
    }
    map<int,int>m1;
    for(auto i:m){
        m1[i.S]++;
    }
    if(m1[1]==2 && m1[2]==2){
        cout<<"YES"<<"\n";
    }else{
        cout<<"NO"<<"\n";
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
       	solve();
    }   
}





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

int main()
{
    int n;
    cin >> n;
    int a = 0;
    for(int i=0;i<=25;i++){
        for(int j=0;j<15;j++){
            if(i == 0 && j== 0){}
            else if(n%(4*i+7*j) == 0){
                a++;
                break;
            }
        }
        if(a == 1){break;}
    }
    if(a == 1){cout << "Yes" << endl;}
    else{cout << "No" << endl;}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ll x;
  cin >> x;
  ll ans = 0;
  ans += x / 500 * 1000;
  x %= 500;
  ans += x / 5 * 5;
  cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
s=list(input())
ans=0
for i in range(n):
    count=0
    x=s[:i+1]
    y=s[i+1:]
    setx=set(x)
    for j in setx:
        if j in y:
            count+=1
    ans=max(ans,count)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

vector<int> G[MAX_N];
int used[MAX_N];

bool dfs(int u, int cri, ll& sz){
    bool nbi = false;
    used[u] = cri;
    sz++;
    each(v, G[u]){
        if(used[v] == 0){
            nbi |= dfs(v, 3-cri, sz);
        }else if(used[v] == cri){
            nbi = true;
        }
    }
    return nbi;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    rep(i,m){
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].pb(b), G[b].pb(a);
    }
    ll bi = 0, al = 0;
    vector<pll> vec;
    rep(i,n){
        if(!used[i]){
            ll sz = 0;
            if(dfs(i, 1, sz)){
                vec.pb(pll(sz, 0));
            }else{
                if(sz == 1) continue;
                vec.pb(pll(sz, 1));
                bi++;
            }
            al += sz;
        }
    }
    ll ans = (ll)n*n;
    rep(i,len(vec)){
        ans -= vec[i].fi*al-len(vec);
        if(vec[i].se){
            ans += bi;
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 11776
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	string s;
	cin >> s;
	if (s[0] == s[1] && s[1] == s[2]) cout << s << endl;
	else if (s[0] == s[1] && s[1] < s[2]) {
		int ans = s[0] - '0';
		ans += 1;
		cout << 100 * ans + 10 * ans + ans << endl;
	}
	else if (s[0] == s[1] && s[1] > s[2]) {
		int ans = s[0] - '0';
		cout << 100 * ans + 10 * ans + ans << endl;
	}

	else if (s[0] < s[1]) {
		int ans = s[0] - '0';
		ans += 1;
		cout << 100 * ans + 10 * ans + ans << endl;
	}
	else if (s[0] > s[1]) {
		int ans = s[0] - '0';
		cout << 100 * ans + 10 * ans + ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
double dp[60][5100];
int v[10];
int at[60];
int ty[60];
int val[60];
int ev[60];
int ep[60];
double eps=1e-9;
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c),a){
		for(int i=0;i<60;i++)for(int j=0;j<5100;j++)
			dp[i][j]=0;
		dp[0][0]=1;
		for(int i=0;i<a;i++)scanf("%d",v+i);
		for(int i=0;i<=b;i++)ev[i]=ep[i]=0;
		for(int i=0;i<c;i++){
			scanf("%d%d%d",at+i,ty+i,val+i);
			ev[at[i]]=ty[i];
			ep[at[i]]=val[i];
		}
		for(int i=0;i<b;i++){
			for(int j=0;j<=i*100;j++){
				if(dp[i][j]<eps)continue;
				for(int k=0;k<a;k++){
					int to=min(b,i+v[k]);
					int pr=j;
					if(ev[to]==1){
						to=min(b,to+ep[to]);
					}
					else if(ev[to]==2){
						pr+=ep[to];
					}
					else if(ev[to]==3){
						pr=max(pr-ep[to],0);
					}
					dp[to][pr]+=dp[i][j]/a;
				}
			}
		}
		double ret=0;
		for(int i=0;i<5100;i++)ret+=dp[b][i]*i;
		printf("%d\n",(int)(ret+eps));
	}
}

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

struct UnionFind {

    vector<int> data;

    UnionFind(int n) {
        data.resize(n+5, -1);
    }

    bool unite(int x, int y) {
        int rootX = getRoot(x);
        int rootY = getRoot(y);
        if ( rootX == rootY ) return false;
        if ( data[rootX] < data[rootY] ) swap(rootX, rootY);
        data[rootX] += data[rootY];
        data[rootY] = rootX;
        return true;
    }

    int getRoot(int i) {
        return ( data[i] < 0 ) ? i : ( data[i] = getRoot(data[i]) );
    }

    int getSize(int n) {
        return -data[getRoot(n)];
    }

    bool isUnited(int x, int y) {
        return (getRoot(x) == getRoot(y));
    }
};

UnionFind unionFind ( 100100 );
int p[100100];

signed main() {

    int n, m;
    scanf("%d %d", &n, &m);
    for ( int i = 0; i < n; i++ ) {
        scanf("%d", &p[i]);
    }
    for ( int i = 0; i < m; i++ ) {
        int x, y;
        scanf("%d %d", &x, &y);
        unionFind.unite ( x, y );
    }
    int cnt = 0;
    for ( int i = 1; i <= n; i++ ) {
        if ( unionFind.isUnited ( i, p[i-1] ) ) cnt++;
    }
    printf("%d\n", cnt);

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
#define ll long long
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define endl '\n'
//#define int ll
using namespace std;
const ll inf = 1ll<<60;
const int iinf = 2147483647;
const ll mod = 1e9+7;
 
signed main (){
   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
   string str; cin>>str;
   if (str=="SUN") cout<<7<<endl;
   if (str=="MON") cout<<6<<endl;
   if (str=="TUE") cout<<5<<endl;
   if (str=="WED") cout<<4<<endl;
   if (str=="THU") cout<<3<<endl;
   if (str=="FRI") cout<<2<<endl;
   if (str=="SAT") cout<<1<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N;
        public long MOD = 1000000007;
        public int[] A;

        public void Run()
        {
            N = Input.ReadInt();
            A = Input.ReadIntArray();

            int[] L = new int[N];
            int[] R = new int[N];

            for (int i = 0; i < N; i++)
            {
                if (i == 0) L[i] = A[i];
                else
                {
                    L[i] = GCD(L[i - 1], A[i]);
                }
            }


            for (int i = N - 1; i >= 0; i--)
            {
                if (i == N - 1) R[i] = A[i];
                else
                {
                    R[i] = GCD(R[i + 1], A[i]);
                }
            }

            int ret = 1;
            ret = Math.Max(ret, L[N - 2]);
            ret = Math.Max(ret, R[1]);
            for (int i = 0; i < N - 2; i++)
            {
                ret = Math.Max(ret, GCD(L[i], R[i + 2]));
            }

            Console.WriteLine(ret);
        }

        // validation: AOJ 0005
        public static int GCD(int a, int b)
        {
            return b == 0 ? a : GCD(b, a % b);
        }
    }

    // libs ----------


    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }

    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 29020
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                String s = sc.next();
                if(s.charAt(0) == s.charAt(2)){
                        System.out.println("Yes");
                }else{
                        System.out.println("No");
                }
        }
}
//色とりどりな、とり！w

Measured memory_bytes: 35520
#include<stdio.h>
int a[200010];
int ans[200010];
int main(){
  int n;
  scanf("%d",&n);
  for(int i=2;i<=n;i++)scanf("%d",&a[i]); 
  for(int i=2;i<=n;i++)ans[a[i]]++;
  for(int i=1;i<=n;i++)printf("%d\n",ans[i]);
}


Measured memory_bytes: 3232
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
#include <bitset>
#include <string>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

int main(void){
	int N;	cin >> N;
  int A[N];

  ll ans = 0;
  int cnt = 0;
  int mi = INF;

  rep(i,N)  {
    int a;  cin >> a;
    A[i] = a;
  }
  // int idx = 0;
  // rep(i,N)  {
  //   int a = A[i];
  //   cout << a << ' ';
  //   if ((a < 0) && (i != N-1))  a *= -1;
  //   else{
  //     if (i != N-1) idx = i;
  //   }
  //   if (i == N-1) {
  //     if (N-1-idx % 2 == 0) {
  //         if (a < 0)  a *= -1;
  //       }
  //     }
  //   cout << a << endl;
  //   ans += a;
  // }
  // cout << endl;

  rep(i,N)  {
    int a = A[i];
    if (a < 0)  {
      cnt++;
      a *= -1;
    }
    mi = min(mi,a);
    ans += a;
  }

  if (cnt%2 == 1) ans -= mi*2;

  cout << ans << endl;





	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <climits>

class Nodes;

class Node {
public:
    Node(int n) : id(n), cost(INT_MAX) { }
    void addEdge(int to, int cost) { edgesTo.push_back(to); edgesCost.push_back(cost); }
    int getId() { return id; }
    int getCost() { return cost; }
    void setCost(int alt) { cost = alt; }
    void print() { std::cout << id << " " << cost << std::endl; }
    void printAll() {
        std::cout << id << " " << cost;
        for (std::vector<int>::iterator itr = edgesTo.begin(), itr2 = edgesCost.begin();  itr != edgesTo.end(); ++itr, ++itr2) {
            std::cout << " " << *itr << " " << *itr2;
        }
        std::cout << std::endl;
    }
    void updatesCost(Nodes* nodes);
private:
    int id;
    std::vector<int> edgesTo;
    std::vector<int> edgesCost;
    int cost;
};

class Nodes {
public:
    void readFromIn() {
        int size;
        std::cin >> size;
        for (int i=0; i<size; ++i) {
            int id;
            int sizeOfEdges;
            std::cin >> id >> sizeOfEdges;
            Node *node = new Node(id);
            for (int j=0; j<sizeOfEdges; ++j) {
                int to;
                int cost;
                std::cin >> to >> cost;
                node->addEdge(to, cost);
                //std::cout << to << cost << std::endl;
            }
            nodes.push_back(node);
        }
        nodes[0]->setCost(0);
    }
    std::vector<Node*>::iterator findNodeWithTheLeastDistance(std::vector<Node*> &queue) {
        std::vector<Node*>::iterator min=queue.begin();
        for (std::vector<Node*>::iterator itr=queue.begin()+1; itr != queue.end(); ++itr) {
            if ((*min)->getCost() > (*itr)->getCost()) {
                min = itr;
            }
        }
        return min;
    }
    void dijkstrasAlgorithm() {
        std::vector<Node*> queue(nodes);

        while (!queue.empty()) {
            std::vector<Node*>::iterator u = findNodeWithTheLeastDistance(queue);
            int n = (*u)->getId();
            //std::cout << "**" << n << std::endl;
            queue.erase(u);

            getNode(n)->updatesCost(this);
        }
    }
    void print() {
        for (std::vector<Node*>::iterator itr=nodes.begin(); itr != nodes.end(); ++itr) {
            (*itr)->print();
        }
    }
    Node* getNode(int n) {
        return nodes[n];
    }
private:
    std::vector<Node*> nodes;
};

void Node::updatesCost(Nodes* nodes) {
    for (std::vector<int>::iterator itr = edgesTo.begin(), itr2 = edgesCost.begin();  itr != edgesTo.end(); ++itr, ++itr2) {
    Node* v = nodes->getNode(*itr);
    int alt = cost + *itr2;
    if (alt < v->getCost()) {
        v->setCost(alt);
    }
    //nodes->print();
}
    /*
for (i=0; i<nodes[u]->sizeOfEdges; ++i) {
    int v = nodes[u]->edgesTo[i];
    int alt = nodes[u]->cost + nodes[u]->edgesCost[i];
    if (alt < nodes[v]->cost) {
        nodes[v]->cost = alt;
    }
}
*/
}

int main(int argc, char *argv[])
{
    Nodes nodes;

    nodes.readFromIn();
    nodes.dijkstrasAlgorithm();
    nodes.print();
    return 0;
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int N,M;
	cin>>N>>M;
	vector<int> a(N);
	rep(i,0,N) cin>>a[i];
	
	vector<pair<int,int>> b(M);
	rep(i,0,M) cin>>b[i].second>>b[i].first;
	
	sort(a.begin(),a.end());
	sort(b.rbegin(),b.rend());
	
	int l=0;
	ll res=0;
	for (auto p:b) {
		int x,y;
		tie(x,y)=p;
		
		while (l<N && a[l]<=x && y>0) {
			res+=x;
			l++;
			y--;
		}
	}
	
	while (l<N) {
		res+=a[l];
		l++;
	}
	
	cout<<res<<endl;
}


Measured memory_bytes: 1408
# -*- coding:utf-8 -*-
N, M = map(int, input().split())
coordinate = []
checkpoint = []
tmplist = []
for tmp in range(N):
    a, b = map(int, input().split())
    coordinate.append((a,b))
for tmp in range(M):
    c, d = map(int, input().split())
    checkpoint.append((c,d))
for i in range(N):
    for j in range(M):
        tmplist.append(abs(coordinate[i][0]-checkpoint[j][0])+abs(coordinate[i][1]-checkpoint[j][1]))
    print(tmplist.index(min(tmplist))+1)
    tmplist = []

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <string>
#define pii pair<int,int>
#define fi first
#define se second
#define pcc pair<char,char>

using namespace std;

typedef long long ll;

int main(){
        int a, b, c;
        cin >> a >> b >> c;
                if(a != b && a != c) cout << a << endl;
                else if(b != a && b != c) cout << b << endl;
                else cout << c << endl;

        return 0;
}


Measured memory_bytes: 256
def min(a, b) a<b ? a:b end
N=gets.to_i
#N = 10**12
n = Math.sqrt(N).to_i

ans=Float::INFINITY
(1..n).each do |i|
  if N % i == 0
    num = i + N/i - 2
    ans = min(ans, num)
  end
end

p ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main(){
    long a,b,c,x,y,tong,tien=0,min,banh=0,banh1=0;
    cin>>a>>b>>c>>x>>y;
    if ((a+b)/2>=c) {
        int Min=(x>y) ? y : x;
        banh=Min*c*2;
        if(x>Min) banh+=(x-Min)*a;
        if(y>Min) banh+=(y-Min)*b;
        int M=(x>y) ? x : y;
        banh1=2*c*M;
    }
    else banh=a*x+b*y;
    if(banh1==0 || banh1>banh) cout<<banh;
    else cout<<banh1;
    return 0;
}

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

int n,m;
long long sum,ans;
long long a[maxl];
char s[maxl];

inline void prework()
{
	scanf("%d",&n);sum=0;
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]),sum+=a[i];
}

inline void mainwork()
{
	long long now=0;ans=sum;
	for(int i=1;i<=n;i++)
		now+=a[i],ans=min(ans,abs(sum-now-now));
}

inline void print()
{
	printf("%lld",ans);
}

int main()
{
	int t=1;
	//scanf("%d",&t);
	for(int i=1;i<=t;i++)
	{
		prework();
		mainwork();
		print();
	}
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <tuple>
#include <map>
using namespace std;

int N, Q; string S; vector<int>vec;

int main() {
	cin >> N >> Q >> S;
	for (int i = 0; i < N - 1; i++) {
		if (S[i] == 'A' && S[i + 1] == 'C') vec.push_back(i + 1);
	}
	for (int i = 1; i <= Q; i++) {
		int l, r; cin >> l >> r;
		int pos1 = lower_bound(vec.begin(), vec.end(), l) - vec.begin();
		int pos2 = lower_bound(vec.begin(), vec.end(), r) - vec.begin();
		cout << pos2 - pos1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1276
import sys
input = lambda: sys.stdin.readline().rstrip()

from itertools import accumulate

N, K = map(int, input().split())

S = input()

num = []

if S[0] == '0':
    num.append(0)

if S[-1] == '1':
    S += '0'
else:
    S += '1'

cnt = 1

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cnt += 1
    else:
        num.append(cnt)
        cnt = 1

if S[-2] == '0':
    num.append(0)

num = [0] + num

cum_sum = list(accumulate(num))


ans = 0
for i in range(0, len(cum_sum), 2):
    right = i + K * 2 + 1

    if right > len(cum_sum)-1:
        right = len(cum_sum) - 1

    ans = max(ans, cum_sum[right]-cum_sum[i])

print(ans)

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

int main(void){
	int n;
	int a[11];
	int b=1, ans=1;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
		if(a[i]%2==0){
			b *= 2;
		}
		ans *= 3;
	}
	cout << ans-b << endl;

	return 0;
}

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

#define hmax 50
#define wmax 50

int m[hmax+1][wmax+1];
int dp[hmax][wmax];
int h, w;

int solve(int x, int y){

  if(dp[y][x] != -1) return dp[y][x];
  int ans;
  // cout << x << " " << y << endl;
  if(y == h-1 && x == w-1) return dp[y][x] = 0;
  if(y == h-1) ans = solve(x+1,y)+m[y][x+1];
  else if(x == w-1) ans = solve(x,y+1)+m[y+1][x];
  else ans = min(solve(x,y+1)+m[y+1][x], solve(x+1,y)+m[y][x+1]);

  return dp[y][x] = ans;

}

int main(){

  cin >> h >> w;
  memset(dp,-1,sizeof(dp));
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      char ch;
      cin >> ch;
      m[i][j] = ch - '0';
    }
  }
  int ans = solve(0,0);

  cout << ans << endl;


}

Measured memory_bytes: 1192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int n = kb.nextInt();
		int c1 = 0;
		int c2 = 0;
		int c3 = 0;
		int c4 = 0;
		for (int i = 0; i < n; i++) {
			String s = kb.next();
			if (s.equals("AC")) {
				c1 += 1;
			} else if (s.equals("WA")) {
				c2 += 1;
			} else if (s.equals("TLE")) {
				c3 += 1;
			} else {
				c4 += 1;
			}
		}
		System.out.println("AC x " + c1 + "\nWA x " + c2 + "\nTLE x " + c3 + "\nRE x " + c4);
		kb.close();
	}

}


Measured memory_bytes: 49172
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#define pi 3.14159265358979323846264338
using namespace std;

int main() {
	double r;
	cin >> r;
	cout << fixed << setprecision(8) << r*r*pi<<" "<<r*2*pi<<endl;
	return 0;
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << x << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  rep (i, n) cin >> a[i];
  unordered_map<int, int> num;
  rep (i, n)++ num[a[i]];
  vector<int> b;
  allrep (n, num) b.push_back(n.second);
  const int bn = b.size();
  sort(all(b));
  vector<int> sumv(bn + 1);
  rep (i, bn) sumv[i + 1] = sumv[i] + b[i];
  unordered_map<int, int> large;
  rep (i, bn) large[b[i]] = i;
  unordered_map<int, int> k_max;
  int r = -1;
  rep1 (x, n) {
    if (large.find(x) != large.end()) r = large[x];
    int sum = sumv[r + 1] + x * (bn - r - 1);
    k_max[sum / x] = x;
  }
  vector<int> ans(n + 1);
  int now = 0;
  rrep1 (i, n) {
    if (k_max.find(i) != k_max.end()) now = k_max[i];
    ans[i] = now;
  }
  rep1 (i, n) cout << ans[i] << "\n";
  return 0;
}

Measured memory_bytes: 18548
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main(void){
    int d;
    cin >> d;
    string s = "Christmas ";
    for(auto i = 0; i < 25 - d; ++i){
        s += "Eve ";
    }
    cout << s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

int solve(int a){
    int res = 1;
    while(a >= 10){
        res ++;
        a /= 10;
    }
    return res;

}

signed main(){
    int n;
    cin >> n;
    int res = 0;
    FOR(i,1,n+1){
        if(solve(i) %2 == 1) res ++;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>

using namespace std;

int main()
{
	int a,b,c,d;
	int m,n;
	while(~scanf("%d %d %d %d \n",&a,&b,&c,&d)){
		m = a+b;
		n = c+d;
		if(m > n) printf("Left\n");
		if(m == n) printf("Balanced\n");
		if(m < n) printf("Right\n");
	}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	int a, b;
	int c, d;
	cin >> a >> b >> c >> d;
	if(abs(a-c)) {
		cout << 1 << endl;
	} else {
		cout << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}

struct Edge {
    int u, v, c = -1;  
};

const int MAXN = 1e5;
int N;
vector<Edge*> edges;
vector<Edge*> adj[MAXN];
int numberOfColor;

void dfs(int curr, int prev, int prevColor) {
    int currColor = 1;
    for(auto e : adj[curr]) {
        int next = (e->u == curr ? e->v : e->u);
        if(next == prev) continue;
        if(currColor == prevColor) currColor++;
        dfs(next, curr, currColor);
        e->c = currColor++;
    }
}

int main() {
    cin >> N;
    rep(i, N - 1) {
        Edge *e = new Edge();
        edges.push_back(e);
        cin >> e->u >> e->v;
        --e->u; --e->v;
        adj[e->u].push_back(e);
        adj[e->v].push_back(e);
    }
    rep(i, N) {
        numberOfColor = max(numberOfColor, sz(adj[i]));
    }
    cout << numberOfColor << "\n";
    dfs(0, -1, 0);
    for(auto &e : edges) {
        cout << e->c << "\n";
    }
}

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

int vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main()
{
    int aa,a,b,c,i=0,m;
    vector<int> box(110); //1<=A<=100より、余りは99通り
    cin >> aa >> b >> c;

    while (true)
    {
        i++;
        a = aa*i;
        m = a%b;
        if(m==c) {
            cout <<"YES"<< endl;
            return 0;
        }
        if(vector_finder(box,m)==1) {
            cout << "NO" << endl;
            return 0;
        }
        box.push_back(m);
    }
    return 0;
}

Measured memory_bytes: 3640
n = gets.to_i
x = gets.chomp.split(" ").map(&:to_i)
ans = 1000000
(1..100).each do |i|
    count = 0
    (0...n).each do |j|
        count += (x[j] - i) ** 2 
    end
    ans = [ans,count].min
end
puts ans

Measured memory_bytes: 1788
//#include <bits/stdc++.h>                          //include all library  
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
//#include <priority_queue>
#include <string.h>
#include <functional> // greater<int> はfunctionalヘッダ
using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)          //REP(i, 10){...} //i=0～i=9までのループ
#define REPR(i, n) for(int i = n;i >= 0;i--)        //REPR(i, 10){...} //i=10～i=0までのループ
#define FOR(i, m, n) for(int i = m;i < n;i++)       //FOR(i, 3, 10){...} //i=3～i=9までのループ
#define FORR(i, m, n) for(int i = m;i >= n;i--)     //FORR(i, 10, 3){...} //i=10～i=3までのループ
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define PI 3.141592653589
#define npos -1

int main()
{
  int n,a;
  cin >> n >> a;
  cout << n*n - a << endl;
}



Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]
s=input()
for i in range(len(s)-2):
    if s[i]==s[i+1]:
        print(i+1,i+2)
        break
    elif s[i]==s[i+2]:
        print(i+1,i+3)
        break
else:
    if len(s)==2 and s[0]==s[1]:
        print(1,2)
    else:
        print("-1 -1")

Measured memory_bytes: 3188
#include<iostream>
#include<set>
#include<algorithm>

using namespace std;

long long gcd(long long x, long long y){
    if(y > x) return gcd(y, x);
    if(x % y == 0) return y;
    return gcd(y, x % y);
}

long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}

int main(void){
    int N;
    long long ans = 1;
    cin >> N;
    for(int i = 0; i < N; i++){
        long long T;
        cin >> T;
        ans = lcm(T, ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INFTY (1<<30)
using namespace std;
int H,heap[2000001];
void maxHeapify(int i){
  int l,r,largest;
  l=i*2;
  r=i*2+1;
  //左の子、自分、右の子で値が最大のノードを選ぶ
  if(l<=H&&heap[l]>heap[i]) largest=l;
  else largest=i;
  if(r<=H&&heap[r]>heap[largest]) largest=r;
  if(largest!=i){
    swap(heap[i],heap[largest]);
    maxHeapify(largest);
  }
}
void increasekey(int i,int key){
  if(key<heap[i]) return;
  heap[i]=key;
  while(i>1&&heap[i/2]<heap[i]){
    swap(heap[i/2],heap[i]);
    i=i/2;
  }
}
void insert(int key){
  H++;
  heap[H]=-INFTY;
  increasekey(H,key);
}
int extract(){
  int maxv;
  if(H<1) return -INFTY;
  maxv=heap[1];
  heap[1]=heap[H--];
  maxHeapify(1);
  return maxv;
}
int main(){
  int key;
  string com;
  while(1){
    cin>>com;
    if(com=="end") break;
    if(com=="insert"){
      scanf("%d",&key);
      insert(key);
    }else printf("%d\n",extract());
  }
  return(0);
}



Measured memory_bytes: 7236
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>


using namespace std;

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

const ll mod = 1000000007;
ll inv[200002];
ll nCr[200002];
ll n_1Cr[200002];

//逆元
// b / a ≡ b * invers(a,n) % n (mod n)
ll modinv(ll a, ll m) {
   	ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}


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


int main() {
	ll n , k;
	cin >> n >> k;

	for (int i = 1; i < 200001; i++) {
		inv[i] = modinv(i, mod);
	}

	nCr[0] = 1;
	for (int i = 1; i <= n ; i++) {
		ll cur =  nCr[i - 1] * (n + 1 - i) % mod;

		nCr[i] = (cur * inv[i]) % mod;
	}

	n_1Cr[0] = 1;
	for (int i = 1; i <= n - 1; i++) {
		ll cur =  n_1Cr[i - 1] * (n - i) % mod;

		n_1Cr[i] = (cur * inv[i]) % mod;
	}

	if (n <= k) {
		k = n;
	}
	ll ans = 0;
	for (int i = 0; i <= k; i++) {
		//cout << "i:" << i;

		ans += (nCr[i] * n_1Cr[n-i-1]) % mod;
		//cout << "nCr[i]: " << nCr[i] << endl;
		//cout << "n_1Cr[n-i-1]: " << n_1Cr[n-i-1] << endl;
		ans = ans % mod;
 	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  ll  n,  m;  cin >> n >> m;
  fin((n - 1) * (m - 1))
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


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

using namespace std;
typedef long long ll;

const int MaxN = 2005;

int n, m, dir[MaxN], u[MaxN], v[MaxN], w[MaxN], par[MaxN], dep[MaxN], fe[MaxN];

vector<int> edge[MaxN], pass[MaxN];

void dfs(int x, int fa) {
  for (int y : edge[x])
    if (y != fa) {
      par[y] = x; dep[y] = dep[x] + 1;
      dfs(y, x);
    }
}

bool f[MaxN][2], vis[MaxN];
void refresh(int i, int o) {
  for (int x = u[i]; x != w[i]; --fe[x], f[x][o ^ 0] = true, x = par[x]);
  for (int x = v[i]; x != w[i]; --fe[x], f[x][o ^ 1] = true, x = par[x]);
}

bool decrease() {
  for (int i = 1; i <= n; i++) {
    if (fe[i] == 1 && (!f[i][0] || !f[i][1])) {
      bool c1 = f[i][0], c2 = 1;
      for (auto x : pass[i]) {
        if (!vis[x]) {
          int p = u[x];
          while (p != w[x]) {
            if (p == i)
              c2 = false;
            p = par[p];
          }
          dir[x] = (c1 ^ c2); vis[x] = true; refresh(x, c1 ^ c2); 
          break;
        }
      }     
      return true;
    }
  }
  return false;
}

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d%d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  dfs(1, 0);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", u + i, v + i);
    for (int x = u[i], y = v[i]; x != y; ) {
      if (dep[x] < dep[y]) swap(x, y);
      ++fe[x]; pass[x].push_back(i); x = par[x]; 
      w[i] = x;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) ans += min(fe[i], 2);
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) if (fe[i] < 2) fe[i] = 0;
  for (int i = 1; i <= m; i++) {
    if (!vis[i]) {
      vis[i] = true;
      for (refresh(i, 0); decrease(); ); 
    }
  }
  
  for (int i = 1; i <= m; i++) {
    int x = u[i], y = v[i];
    if (dir[i])
      swap(x, y);
    printf("%d %d\n", x, y); 
  }
  return 0;
}



Measured memory_bytes: 7040
package main

import "fmt"

func main() {
	var n, y int
	fmt.Scan(&n, &y)

	for i := 0; i <= n; i++ {
		for j := 0; j <= (n - i); j++ {
			k := n - (i + j)
			total := 10000*i + 5000*j + 1000*k
			if total == y {
				fmt.Println(i, j, k)
				return
			}
		}
	}
	fmt.Println(-1, -1, -1)
}


Measured memory_bytes: 512
import java.io.*;
import java.util.*;

//solution classes here

public class Main {

    //main solution here

    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        String s = sc.next();
        if(s.charAt(2)==s.charAt(3) && s.charAt(4)==s.charAt(5))
            out.println("Yes");
        else
            out.println("No");

        out.flush();
        out.close();
    }

    //solution functions here


    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}

/* *****************************************************************************************************************************
 * I'M NOT IN DANGER, I'M THE DANGER!!!
 * *****************************************************************************************************************************
 */

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}
int main()
{   init();
    string s,t;
    int ans=0;
    cin>>s>>t;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i])ans++;
    }
    cout<<ans;
}


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

using namespace std;

typedef long long ll;
typedef long long unsigned int llui;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef set<int> si;
typedef map<string, int> msi;

#define INF INT_MAX
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define sz(a) int((a).size())
#define UNIQUE(x) (x).erase(unique((x).begin(),(x).end()),(x).end())
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define clr(a) memset(a,0,sizeof(a))
#define trace(x) cout << '>' << #x << ':' << x << endl;
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << endl;

inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

#define LSOne(S) (S&(-S))

const double pi = acos(-1);
const int oo = 0x3f3f3f3f;

template<class T> inline T gcd(T a,T b) //NOTES:__gcd(0,0) gives exception
  {if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}

int cmp(double x, double y = 0, double tol = EPS) {
    return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

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

/*bool sortby(const pair<ll,ll> &a,const pair<ll,ll> &b)
{
    return (a.second < b.second);
}*/

const int MAX_N = 123456;

int arr[MAX_N];
int l[MAX_N];
int r[MAX_N];

int main() {
	int N,x,y;
    l[0]=0;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
        scanf("%d",l+1+i);
        l[i+1]+=l[i];
	}
	for(int i=0;i<N;i++){
        scanf("%d",r+1+i);
	}
    for(int i=N-1;i>0;i--){
        r[i]+=r[i+1];
    }
    int ans=0;
    for(int i=1;i<=N;i++){
        arr[i]=l[i]+r[i];
        ans=max(ans,arr[i]);
    }
    printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
def main():
    N, T = map(int, input().split())
    l = []
    cost = 1001
    for i in range(N):
        l.append(list(map(int, input().split())))
    for i in range(N):
        if l[i][1] <= T:
            t = l[i][1]
            if l[i][0] < cost:
                cost = l[i][0]
    if cost == 1001:
        print('TLE')
    else:
        print(cost)
main()  

Measured memory_bytes: 9108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)


int main() {
  int N;
  cin>>N;
  vector<int>P(N);
  vector<int>Q(N);
  rep(i,N){
      cin>>P[i];
  }
  rep(i,N){
      cin>>Q[i];
  }
  vector<int>R(N);
  rep(i,N){
      R[i]=i+1;
  }
  int c=0;
  int d=0;
  int cnt=1;
  while(next_permutation(R.begin(),R.end())){
      bool a=true;
      bool b=true;
      rep(i,N){
          if(R[i]==P[i]){
          }
          else{
              a=false;
          }
          if(R[i]!=Q[i]){
              b=false;
          }
      }
      if(a==true){
          c=cnt;
      }
      if(b==true){
          d=cnt;
      }
    cnt++;
  }
  cout<<abs(c-d)<<endl;
}


Measured memory_bytes: 3620
import sys

M = int(input())

b_list = list(map(int, input().split()))
b_list.insert(0,0)
result_list = [0] * (M+1)

def getCount(index):
    multi = 2
    count = 0
    while True:
        next_index = index * multi
        if next_index > M:
            break
        count += result_list[next_index]
        multi += 1
    
    return count
        

for i in range(M, 0, -1):
    num = b_list[i]
    count = getCount(i)
    if count % 2 == num:
        result_list[i] = 0
    else:
        result_list[i] = 1

result_list.pop(0)
ans = ""
for i in range(len(result_list)):
    if result_list[i] == 1:
        ans += str(i+1) + " "

print(result_list.count(1))
if ans != "":
    print(ans)




Measured memory_bytes: 9140
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

const ll max_m = 1000000000;
const ll max_n = 100000;

ll a[max_n];
ll sum[max_n+1];
//ll count[max_m];

int main(){
  ll n,m;
  cin >> n >> m;
  ll cnt = 0;
  map<ll,ll> count;
  fill(sum,sum+n+1,0);
  //fill(count,count+m,0);
  count[0]++;
  REP(i,n){
    cin >> a[i];
    sum[i+1] += sum[i]+a[i];
    count[sum[i+1]%m]++;
    if(a[i]%m==0) cnt++;
  }
  ll ans = 0;
  for(pair<ll,ll> cnt :count){
    ans += cnt.second*(cnt.second-1)/2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5760
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d

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

cntset=set()
for i in range(1000):
    s=str(i)
    if i <10:
        s="00"+s
    if 10<=i<100:
        s="0"+s
    if S.find(s[0])==-1:
        continue
    if S[S.find(s[0])+1:].find(s[1])==-1:
        continue
    g=S.find(s[0])+S[S.find(s[0])+1:].find(s[1])
    if S[g+2:].find(s[2])==-1:
        continue
    cntset.add(s)
    
print(len(cntset))

Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 212345
ll a[N], b[N] = {};

int main(){
	int n; scanf("%d", &n);
	REP(i, n) scanf("%lld", a+i);
	REP(i, n) b[a[i]]++;
	ll ans = 0;
	REP(i, N) ans += b[i] * (b[i]-1) / 2;
	REP(i, n){
		printf("%lld\n", 
				ans
				- b[a[i]] * (b[a[i]]-1) / 2
				+ (b[a[i]]-1) * (b[a[i]]-2) / 2);
	}
}


Measured memory_bytes: 4736
n = int(input())
S = sorted([int(input()) for i in range(n)])

if sum(S) % 10 != 0:
    print(sum(S))
else:
    S = S + [-1]
    for i in range(n + 1):
        if S[i] == -1:
            print(0)
        elif S[i] % 10 != 0:
            del S[i]
            print(sum(S) + 1)
            break

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

using namespace std;

bool ok(int x, int y)
{
    return ((x - 1) % 3 <= (y - 1) % 3);
}

int main()
{
    char s[100001];
    
    while (scanf("%s", s) && s[0] != '#'){
        int st[2] = {-1, -1}, last = 1, vio = 0;
        int st2[2] = {-1, -1}, last2 = 0, vio2 = 0;
        
        for (int i = 0; s[i]; i++){
            s[i] -= '0';
            
            if (st[last] <= 0){
                st[1 - last] = s[i];
                last = 1 - last;
            }
            else {
                if ((last & 1) ? ok(s[i], st[last]) : ok(st[last], s[i])){
                    st[1 - last] = s[i];
                    last = 1 - last;
                }
                else {
                    st[last] = s[i];
                    vio++;
                }
            }
            
            if (st2[last2] <= 0){
                st2[1 - last2] = s[i];
                last2 = 1 - last2;
            }
            else {
                if ((last2 & 1) ? ok(s[i], st2[last2]) : ok(st2[last2], s[i])){
                    st2[1 - last2] = s[i];
                    last2 = 1 - last2;
                }
                else {
                    st2[last2] = s[i];
                    vio2++;
                }
            }
        }
        
        printf("%d\n", min(vio, vio2));
    }
    
    return (0);
}

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

int main() {
  char al[100];

  rep(i,26){
    al[i] = 'A' + i;
  }

  //cout << al[3] << endl;

  int n; cin >> n;
  string s; cin >> s;
  rep(i,s.length()){
    int j;
    for(j=0; j<30; j++){
      if(s[i] == al[j]) break;
    }
    char ans = 'A' + (j+n)%26;
    cout << ans;
  }
}


Measured memory_bytes: 256