akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

bool all_ch_same(string s) {
  char t = s[0];
  for ( int i = 1; i < s.length(); i++ ) {
    if ( t != s[i] ) { return false; }
  }
  return true;
}
/*
bool erag(string s) {
  int len = s.length();
  if ( len < 5 ) { return false; }
  if ( s[0] == s[len-1] && s[0] == s[len-2] && s[0] == s[len-3] && s[0] != s[len-4]  ) { return true; }
  if ( s[len-1] == s[0] && s[len-1] == s[1] && s[len-1] == s[2] && s[len-1] != s[3] ) { return true; }
  return false;
}
*/

int main() {
  string s1;
  string s2;
  long long k;
  cin >> s1;
  cin >> k;
  s2 = s1 + s1;
  long long l1 = 0;
  long long l2 = 0;

  string t;
  t  = s1;
  for ( int i = 0; i < t.length()-1; i++ ) {
    if ( t[i] == t[i+1] ) { l1++; t[i+1] = '0'; }
  }
  t = s2;
  for ( int i = 0; i < t.length()-1; i++ ) {
    if ( t[i] == t[i+1] ) { l2++; t[i+1] = '0'; }
  }

  long long ans;
  if ( s1.length()%2 == 1 && all_ch_same(s1) ) {
    ans = ( k%2 == 0 ) ? l2*k/2 : l2*(k/2) + l1;
  } else if ( l1 * 2 != l2 ) {
    ans = l1*k + (k-1);
  } else {
    ans = l1*k;
  }

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


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

  int x, y, z, k, s;
  int count = 0;

  scanf("%d%d", &k, &s);

  for (x = 0; x <= k; x++) {
    for (y = 0; y <= k; y++) {
      if (0 <= s - x - y && s - x - y <= k)
        count++;
      }
    }

  printf("%d\n", count);

  return 0;
}

Measured memory_bytes: 128
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	n := nextInt()
	a := make([]int, n)

	a[0] = nextInt()
	for i := 1; i < n; i++ {
		a[i] = a[i-1] + nextInt()
	}

	min := a[n-1]
	for i := 0; i < n; i++ {
		l, r := a[i], a[n-1]-a[i]

		if abs(r-l) < min {
			min = abs(r - l)
		}
	}

	fmt.Println(min)
}


Measured memory_bytes: 5248
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;

namespace AtcoderExpress
{


    class Program
    {
        static long mod = 1000000007;
        static void Main(string[] args)
        {
            //var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var N = long.Parse(Console.ReadLine());

            var dp = new long[N + 1, 4, 4, 4];
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    for (int k = 0; k < 4; k++)
                    {
                        if(!((i == 0 && j == 2 && k == 3) || (i == 0 && j == 3 && k == 2) || (i == 2 && j == 0 && k == 3)))
                        {
                            dp[3, i, j, k] = 1;
                        }
                    }
                }
            }

            for (int n = 4; n <= N; n++)
            {
                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        for (int k = 0; k < 4; k++)
                        {
                            for (int l = 0; l < 4; l++)
                            {
                                if (!((j == 0 && k == 2 && l == 3) || (j == 0 && k == 3 && l == 2) || (j == 2 && k == 0 && l == 3)|| (i == 0 && k == 2 && l == 3) || (i == 0 && j == 2 && l == 3)))
                                {
                                    dp[n, j, k, l] += dp[n-1, i, j, k];
                                    dp[n, j, k, l] %= mod;
                                }
                            }
                        }
                    }
                }
            }

            long ans = 0;
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    for (int k = 0; k < 4; k++)
                    {
                        ans += dp[N, i, j, k];
                        ans %= mod;
                    }
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13232
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <cctype>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <class T>
inline void read(T &ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return ;
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1:1;
    ret = (c == '-') ? 0:(c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return ;
}
inline void outi(int x) {if (x > 9) outi(x / 10);putchar(x % 10 + '0');}
inline void outl(ll x) {if (x > 9) outl(x / 10);putchar(x % 10 + '0');}
typedef long long ll;

ll a,b,c,d;

int main()
{
    read(a);
    read(b);
    read(c);
    read(d);
    ll q=a*c;
    ll w=a*d;
    ll e=b*c;
    ll r=b*d;
    cout<<max(max(q,w),max(e,r))<<endl;
}



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

using namespace std;

int main(){


    long long int n,i,j,k,l;

    cin>>n;

    long long int a[n][3];

    for(i=0;i<n;i++){

        if(i>0){

            for(j=0;j<3;j++){

                cin>>a[i][j];

                if(j==0){
                    a[i][j]=max(a[i][j]+a[i-1][1],a[i][j]+a[i-1][2]);
                }
                else if(j==1){
                    a[i][j]=max(a[i][j]+a[i-1][0],a[i][j]+a[i-1][2]);
                }
                else if(j==2){
                    a[i][j]=max(a[i][j]+a[i-1][0],a[i][j]+a[i-1][1]);
                }
            }
        }
        else{
            for(j=0;j<3;j++)
                cin>>a[i][j];
        }
    }

    long long int p=max(a[n-1][0],a[n-1][1]);
    p=max(p,a[n-1][2]);

    cout<<p<<"\n";

    return 0;
}


Measured memory_bytes: 2688
#include "bits/stdc++.h"

using namespace std;
const int INF=1e9;

int main ()
{

	
	int n;
	cin>>n ;
	vector<int> input(n);
	for(auto & e :input)
	{
		cin>>e;
	}
	
	vector<int> dp(n,INF);
	
	dp[0]=0; 
	for(int i=0;i<n;i++)
	{
		for(int j:{i+1,i+2})
		{
			if(j<n) {	
			dp[j]=min(dp[j],(abs(input[j]-input[i])+dp[i]));
			}
		}
	}
	cout << dp[n-1]<<"\n";	
}


Measured memory_bytes: 3976
package main

import "fmt"

func nextInt() int {
	var i int
	fmt.Scan(&i)
	return i
}

func main() {
	n := nextInt()
	var c, c2, c4 int
	for i := 0; i < n; i++ {
		a := nextInt()
		if a%4 == 0 {
			c4++
			continue
		}
		if a%2 == 0 {
			c2++
			continue
		}
		c++
	}
	if c2 == 0 {
		if c4 < c-1 {
			fmt.Println("No")
			return
		}
	}
	if c2 > 0 && c > 0 {
		if c4 < c {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}

Measured memory_bytes: 5504
/*......................*/
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef long double   ld;
#define int long long
//#include <ext/pb_ds/assoc_container.hpp>   
//#include <ext/pb_ds/tree_policy.hpp>  
//#include <functional> 
//using namespace __gnu_pbds;  
//typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> OST;           //unique elements 
 
#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    pf                       push_front
#define    mp                       make_pair
#define    T                        int t; cin >> t; while(t--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    pll                      pair <long long int , long long int>
#define    setp(x)                  setprecision(x)
#define    vi                       vector<int>
#define    pqb                      priority_queue<int>
#define    pqs                      priority_queue<int,vi,greater<int> >
#define    ook(x)                   order_of_key(x)
#define    fbo(x)                   find_by_order(x)
 
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

vector <int> adj[100005];
 
signed main(){                                       //constraints , long long
     speed upp
     int n , m ,x , y , ans = 0; cin >> n >> m;
     while(n--){
         cin >> x >> y;
         adj[x].pb(y);
     }
     pqb pq;
     f(i,1,m){
         int size = sz(adj[i]);
         f(j,0,size-1){
             pq.push(adj[i][j]);
         }
         if(!pq.empty()){
             ans += pq.top(); pq.pop();
         }
     }
     cout << ans << '\n';
}
 
 

Measured memory_bytes: 5760
n=int(input())
h=list(map(int,input().split()))
dp=[0,abs(h[1]-h[0])]
for i in range(n-2):
	dp.append(min(dp[i]+abs(h[i+2]-h[i]),dp[i+1]+abs(h[i+2]-h[i+1])))
print(dp[-1])

Measured memory_bytes: 13908
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  ll q,h,s,d;
  cin>>q>>h>>s>>d;
  h=min(h,2*q);
  s=min(s,2*h);
  d=min(d,2*s);
  int n;
  cin>>n;
  cout<<n/2*d+(n%2)*s<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
 
#define MAX 100000
#define INFTY 1 << 30
int v,r;
vector<pair<int,int> > adj[MAX];
 
void dijkstra(){
  priority_queue<pair<int,int> > PQ;
  int d[MAX];
  for(int i = 0; i < v; i++){
    d[i] = INFTY;
  }    
  d[r] = 0;
  PQ.push(make_pair(0,r));
  
  while(!PQ.empty()){
    pair<int,int> m = PQ.top(); PQ.pop();
    int u = m.second;
    
    if(d[u] < m.first*(-1)) continue;
    
    for(int i = 0; i < adj[u].size(); i++){
      int v = adj[u][i].first;
      if(d[u]+adj[u][i].second < d[v]){
	d[v] = d[u]+adj[u][i].second;
	PQ.push(make_pair(d[v]*(-1),v));
      }
    }
  }
  for(int i = 0; i < v; i++){
    if(d[i] < INFTY) cout << to_string(d[i]) << endl;
    else cout << "INF" << endl;
  }
}

int main(){
  int e,s,t,d;
  cin >> v >> e >> r;
  for(int i = 0; i < e; i++){
    cin >> s >> t >> d;
    adj[s].push_back(make_pair(t,d));
  }
  dijkstra();
  
  return 0;
}



Measured memory_bytes: 12984
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

#define INF 1e9
#define MOD 1e9 + 7
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)
#define all(in) in.begin(), in.end()

int main(){
    int N;
    cin >> N;
    vector<long long> A(N);
    rep(i, N) cin >> A[i];
    set<long long> numset;
    map<long long, long long> mp;
    long long ans = 0;
    long long count = 0;
    long long num[N];
    rep(i, N){
        if(numset.count(A[i]) == 1){
            mp[A[i]]++;
        }else{
            mp[A[i]] = 1;
            numset.insert(A[i]);
        }
    }
    if(N - 2 < numset.size() && numset.size() <= N) ans = 0;
    else{
        for(auto v: mp){
            long long p = v.first, q = v.second;
            if(q >= 2){
                if(q >= 4){
                    num[count] = p;
                    num[count + 1] =p;
                    count += 2;
                }else{
                    num[count] = p;
                    count++;
                }
            }
        }
        sort(num, num + count, greater<long long>());
        ans = num[0] * num[1];
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 12032
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int H,W,N;
	cin>>H;
	cin>>W;
	cin>>N;
	double h1=N*1.0/H;
	if (h1!=(int)h1){
		h1++;
	}
	double w1=N*1.0/W;
	if (w1!=(int)w1){
		w1++;
	}
	cout<<min((int)h1,(int)w1)<<endl;
	return 0;
}

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    char x, y; cin >> x >> y;
    if( x == y ) cout << '=' << endl;
    else if( x > y ) cout << '>' << endl;
    else cout << '<' << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cmath>

using namespace std;
int main(){
    int n,h;
    long h1[1000000];
    long long count=0;
    long temp;

    cin>>n>>h;
    for(int i=0;i<n;i++)
        cin>>h1[i];
    
    sort(h1,h1+n,greater<long>());
    if(h>=n){
        count=0;
    }else{
        for(int i=0;i<h;i++){
            h1[i]=-1;
        }
        for(int i=0;i<n;i++){
            if(h1[i]!=-1){
                count+=h1[i];
            }
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 3584
import copy

(h, w, n) = list(map(int, input().split()))
dis = [[] for i in range(n + 1)]


def setArr(ph):
    global dis
    res = [False for i in range(w + 2)]
    for i, x in enumerate(list(input())):
        if x == "X":
            continue
        res[i + 1] = True
        if x == ".":
            continue
        if x == "S":
            dis[0] = [ph, i + 1]
            continue
        dis[int(x)] = [ph, i + 1]
    return res


arr = [[] for i in range(h + 2)]
arr[0] = [False for i in range(w + 2)]
arr[-1] = [False for i in range(w + 2)]
for i in range(1, h + 1):
    arr[i] = setArr(i)

res = 0
move = [[1, 0], [0, 1], [-1, 0], [0, -1]]


def ze(start, goal):
    arra = copy.deepcopy(arr)
    global res
    queue = [start, [-1, -1]]
    ap = queue.append
    zu = False
    for q in queue:
        if q[0] < 1:
            res += 1
            ap([-1, -1])
            continue
        if not arra[q[0]][q[1]]:
            continue
        for m in move:
            de = [q[0] + m[0], q[1] + m[1]]

            if de == goal:
                res += 1
                zu = True
                break
            if arra[de[0]][de[1]]:
                ap(de)
        if zu:
            break
        arra[q[0]][q[1]] = False


for i in range(n):
    ze(dis[i], dis[i + 1])

print(res)



Measured memory_bytes: 95652
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	string s;
	cin>>s;
	int n = s(s);
	ll dp[n+1][13];
	rep(i,n+1){
		rep(j,13)dp[i][j] = 0;
	}	
	dp[0][0] = 1;
	rep(i,n){
		if(s[i] == '?'){
			// if(i == 0){
			// 	rep(j,10){
			// 		dp[i][j] = 1;
			// 	}
			// 	continue;
			// }
			rep(j,10){
				rep(k,13){
					dp[i+1][(10*k + j)%13] += dp[i][k];
					dp[i+1][(10*k + j)%13] %= mod;
				}
			}
		}
		else{
			// if(i == 0){
			// 	dp[i][s[i]-'0'] = 1;
			// }
			// else{
			// rep(j,10){
			int j = s[i]-'0';
				rep(k,13){
					dp[i+1][(k*10 + j)%13] += dp[i][k];
					dp[i+1][(k*10 + j)%13] %= mod;
				}
			// }	
			// }
		}
	}
	// rep(i,n){
	// 	rep(j,13){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<"\n";
	// }
	cout<<dp[n][5];
	return 0;
}

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

struct Node{
	char c;
	vector<Node*> adj;
	bool flag=0;
};

Node* root=NULL;

void insert(string s)
{
	reverse(s.begin(),s.end());
	
	Node* node=root;
	
	for(int i=0;i<s.size();i++)
	{
		if(node->adj[s[i]-'a']==NULL)
		{
			Node* new_node=new Node();
			new_node->c=s[i];
			
			new_node->adj=vector<Node*>(26,NULL);
			node->adj[s[i]-'a']=new_node;
			
			node=new_node;
		}
		else
		{
			node=node->adj[s[i]-'a'];	
		}
	}	
	node->flag=1;
}


long long count_ans(vector<string> &s,int n)
{
	root=new Node();
	root->c='0';
	root->adj=vector<Node*>(26,NULL);
	
	long long ans=0;
	
	for(int i=0;i<n;i++)
	{	
		int temp[26]={0};
		for(int j=0;j<s[i].size();j++)
		{
			temp[s[i][j]-'a']++;	
		}
		
		Node* node=root;
		
		for(int j=s[i].size()-1;j>=0 && node!=NULL ;j--)
		{
			for(int k=0;k<26;k++)
			{
				if(temp[k] && node->adj[k]!=NULL && node->adj[k]->flag)
				{
					ans++;	
				}
			}
			
			node=node->adj[s[i][j]-'a'];	
			temp[s[i][j]-'a']--;
		}
		
		insert(s[i]);
	}
	
	return ans;
}

int main()
{
	int n;
	cin>>n;
	
	vector<string> s(n);
	
	for(int i=0;i<n;i++)
	{
		cin>>s[i];	
	}
	
	long long ans=count_ans(s,n);
	reverse(s.begin(),s.end());
	
	cout<<ans+count_ans(s,n)<<endl;
	
	return 0;
}

Measured memory_bytes: 535588
#include<cstdio>

int main() {
    int a,b;
    std::scanf("%d %d",&a,&b);
        if(a < b) {
        std::printf("a < b");
    }
    else if(a > b ) {
        std::printf("a > b");
    }
    else if(a == b){
        std::printf("a == b");
    }
    std::printf("\n");
    return 0;
    }


Measured memory_bytes: 2736
n,k=map(int,input().split())
ct=0
cta=0
for i in range(1,n+1):
  cta=0
  if i>=k:
    ct+=1/n
  else:
    for j in range(30):
      i=i*2
      cta+=1
      if i>=k:
        ct+=1/(n*(2**cta))
        break
print(ct)

Measured memory_bytes: 3060
def main():
    import math
    N,M=map(int,input().split())
    a=[]
    for i in range(M):
        tmp=list(map(int,input().split()))
        tmpc=list(map(int,input().split()))
        c=0
        for j in range(len(tmpc)):
            c+=2**(tmpc[j]-1)
        tmp[1]=c
        a+=[tmp]


    dp=[[10**10 for j in range(2**N)] for i in range(M)]
    dp[0][0]=0
    dp[0][a[0][1]]=a[0][0]


    for i in range(1,M):
        dp[i]=dp[i-1]
        for j in range(2**N):
            z,p=a[i][0],a[i][1]
            q=j|p
            x=dp[i-1][j]+z
            if dp[i][q]>x: dp[i][q]=x

    ans=dp[M-1][2**N-1]
    print(ans if ans<10**10 else -1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 36468
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
struct edge{int a,b;};
edge e[50];

mat mul(mat&A,mat&B){
	mat C(A.size(),vec(B[0].size()));
	for(int i=0;i<A.size();i++){
		for(int k=0;k<B.size();k++){
			for(int j=0;j<B[0].size();j++){
				C[i][j]=(C[i][j]+A[i][k]*B[k][j]);
				if(C[i][j]>1)C[i][j]=1;
			}
		}
	}
	return C;
}

mat pow(mat A,ll n){
	mat B(A.size(),vec(A.size()));
	for(int i=0;i<A.size();i++)B[i][i]=1;
	int f=1;
	while(n){
		if(n&1)B=mul(B,A);
		A=mul(A,A);
		if(f)for(int i=0;i<A.size();i++)A[i][i]=0;
		f=0;
		n>>=1;
	}
	return B;
}

int N,M,Z;

int main(){
	while(cin>>N>>M>>Z){
		if(!N)return 0;
		mat A(M*2+1,vec(M*2+1));
		int s,d;
		for(int i=0;i<M;i++)cin>>e[i].a>>e[i].b;
		for(int i=0;i<M;i++){
			if(e[i].a==1)A[0][2*i+1]=1;
			if(e[i].b==1)A[0][2*i+2]=1;
		}
		for(int i=0;i<M;i++)for(int j=0;j<M;j++){
			if(e[i].b==e[j].a&&e[i].a!=e[j].b)A[2*i+1][2*j+1]=1;
			if(e[i].b==e[j].b&&e[i].a!=e[j].a)A[2*i+1][2*j+2]=1;
			if(e[i].a==e[j].a&&e[i].b!=e[j].b)A[2*i+2][2*j+1]=1;
			if(e[i].a==e[j].b&&e[i].b!=e[j].a)A[2*i+2][2*j+2]=1;
		}
		//for(int i=0;i<=M*2;i++){for(int j=0;j<=M*2;j++)cout<<A[i][j]<<" ";cout<<endl;}
		A=pow(A,Z);
		//for(int i=0;i<=M*2;i++){for(int j=0;j<=M*2;j++)cout<<A[i][j]<<" ";cout<<endl;}
		int f=0;
		for(int i=1;i<=M*2;i++)if(A[0][i]&&(i%2&&e[i/2].b==N||i%2==0&&e[i/2-1].a==N))f=1;
		if(f)cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
}

Measured memory_bytes: 1224
//Try until you reach your goal
#include <bits/stdc++.h>
using namespace std;
# define ll long long
# define endl "\n"
# define str string
# define vll vector<ll>
# define pb push_back
# define mll map<ll,ll>
# define mp make_pair
# define ff first
# define ss second
# define pll pair<ll,ll>
# define f(x,y) for(int x=0;x<y;x++)
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll x,y;
    cin>>x>>y;
    ll k=__gcd(x,y);
    ll k1=x*y;
    ll k2=k1/k;
    cout<<k2;
    return 0;
}

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

int main(){
  int y,m,d;
  char s,t;
  cin >>y>>s>>m>>t>>d;
  
  if(y>=2019&&m>=5){
    cout <<"TBD"<<endl;
  }
  else{cout <<"Heisei"<<endl;
  }
}

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

void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
}

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


Measured memory_bytes: 3096
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

fn gcd(x: i64, y: i64) -> i64 {
  if y == 0 {
    x
  } else {
    gcd(y, x % y)
  }
}

fn lcm(x: i64, y: i64) -> i64 {
  x * (y / gcd(x, y))
}

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let a = read::<i64>();
  let mut ans = 1;

  for _ in 0..a {
    let b = read::<i64>();
    ans = lcm(ans, b);
  }

  println!("{}", ans);
}



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

int count_weight(vector <int> W, int S, int E);
int main() {
	int N;
	cin >> N;
	vector<int> W(N);
	for (int i = 0; i < N; i++) {
		cin >> W.at(i);
	}

	int a = 0, b = 0, min = 0;
	for (int j = 0; j < N; j++) {
		a = count_weight(W, 0, j);
		b = count_weight(W, j + 1, N-1);
		if (a > b) {
			if (min > a - b || j == 0) {
				min = a - b;
			}
		}
		else {
			if (min > b - a || j == 0) {
				min = b - a;
			}
		}
		a = 0;
		b = 0;
	}

	cout << min << endl;

	return 0;
}

int count_weight(vector <int> W, int S, int E) {
	int ans = 0;
	for (int i = S; i <= E; i++) {
		ans += W[i];
	}

	return ans;
}

Measured memory_bytes: 256
s = input()
q = int(input())
for i in range(q):
    data = list(input().split())
    if data[0] == "print":
        left = int(data[1])
        right = int(data[2])
        for i in range(left, right+1):
            print(s[i], end="")
        print()
    elif data[0] == "reverse":
        left = int(data[1])
        right = int(data[2])
        s = s[:left] + s[left:right+1][::-1] + s[right+1:]
    elif data[0] == "replace":
        left = int(data[1])
        right = int(data[2])
        s = s[:left] + data[3] + s[right+1:]



Measured memory_bytes: 5716
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n,k,x,y;
 cin>>n>>k>>x>>y;
 int ans=0;
 ans+=x*min(k,n);
 n-=k;
 if(n>0)
 ans+=y*n;
 cout<<ans<<endl;
 return 0;
}


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

string dv[]={"dream","dreamer","erase","eraser"}; 

int main(){
    string S;
    cin>>S;

    reverse(S.begin(),S.end());
    for(int i=0;i<4;++i) reverse(dv[i].begin(),dv[i].end());

    for(int i=0;i<S.size();){
        bool can=false;
        for(int j=0;j<4;++j){
            if(S.substr(i,dv[j].size())==dv[j]){
                i+=dv[j].size();
                can=true;
            }
        }
        if(!can){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;

    return 0;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int n;
string a = "357";

int dfs(string s) {
  if (s != "" && stoll(s) > n) {
    return 0;
  }
  int res = 0;
  if (count(all(s), '3') && count(all(s), '5') && count(all(s), '7')) {
    res++;
  }
  rep (i, 3) {
    res += dfs(a[i] + s);
  }
  return res;
}

int main() {
  cin >> n;
  cout << dfs("") << endl;
}


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

int main(){
    int n;
    cin >> n;
    string a[n];
    deque<string> x = {};
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i ++){
        if(i % 2 == 0){
            x.push_back(a[i]);
        }else{
            x.push_front(a[i]);
        }
    }
    if(n % 2 == 1){
        reverse(x.begin(),x.end());
    }
    for(int i = 0; i < n; i++){
        if(i != n-1){
            cout << x[i] << " ";
        }else{
            cout << x[i] << endl;
        }
    }
    

    return 0;
}

Measured memory_bytes: 17536
from sys import stdin
N,M,C = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]
A =  [stdin.readline().rstrip().split() for _ in range(N)]

#print(N,M,C)
#print(B)
#print(A)

ans = 0

for i in range(N):
  sum = 0
  for j in range(M):
    sum += int(A[i][j])*int(B[j])
  sum += C
  if sum > 0:
    ans += 1
 
print(ans)

Measured memory_bytes: 3064
s=input()
ls=[int(c) for c in s]
#月,年
if ((ls[0]*10+ls[1]>12) or (ls[0]==0 and ls[1]==0)) and ((ls[2]*10+ls[3]>12) or (ls[2]==0 and ls[3]==0)):
    print("NA")
elif ((ls[0]*10+ls[1]>12) or (ls[0]==0 and ls[1]==0)):
    print("YYMM")
elif ((ls[2]*10+ls[3]>12) or (ls[2]==0 and ls[3]==0)):
    print("MMYY")
else:
    print("AMBIGUOUS")

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

#define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
/* }}} */

signed main() 
{
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int cnt=0;
    rep(i,a+1) rep(j,b+1) rep(k,c+1)
    {
        if(i*500+j*100+k*50==x) cnt++;
    }
    print(cnt);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	string o, e;
	cin >> o;
	cin >> e;
	for(int i = 0; i < o.length(); i++) {
		if((o.length() != e.length())&&(i == o.length() - 1)) {
			cout << o[i];
			break;
		} else {
			cout << o[i] << e[i];
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		if (n >= m) {
			System.out.println(0);
			return;
		}
		int[] arr = new int[m];
		for (int i = 0; i < m; i++) {
			arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		int[] ds = new int[m - 1];
		for (int i = 0; i < m - 1; i++) {
			ds[i] = arr[i + 1] - arr[i];
		}
		Arrays.sort(ds);
		int sum = 0;
		for (int i = 0; i < m - n; i++) {
			sum += ds[i];
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 50088
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

typedef long long ll;

int main() {
    int n;  cin >> n; 
    vector<long long> a(n), b(n), c(n);
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        ans -= b[i];
        c[i] = a[i] + b[i];
    }
    
    sort(c.begin(), c.end(), greater<ll>());

    for (int i = 0; i < n; i += 2) 
        ans += c[i];

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

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

int main(){
  int a,b,flag=0,c=0;
  while(1){
    flag=0;
    cin>>a>>b;
    if(!(a||b))break;
    if(c)cout<<endl;
    c=1;
    for(int i=a;i<=b;i++){
      if(i%4==0 && i%100!=0 || i%400==0){
	cout<<i<<endl;
	flag=1;
      }
    }
    if(!flag)cout<<"NA"<<endl;
  }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int m[10][10];

int calc(vector<int> S){
  int r=0;
  int c;
  for(int i=0;i<4;i++){
    c=S[i];
    r=m[r][c];
  }
  return r; 
}

int main(){
  for (int i=0;i<100;i++){
    cin >> m[i/10][i%10];
  }
 int sample=0;
 int cnt = 0;
  for (int i=0;i<10000;i++){
    sample=i;
    vector<int> S(5);
    S[0]=sample/1000;
    S[1]=(sample-1000*S[0])/100;
    S[2]=(sample-1000*S[0]-100*S[1])/10;
    S[3]=(sample-1000*S[0]-100*S[1]-10*S[2]);
    S[4]=calc(S);
    bool isOk = true;
    for(int j=0;j<5;j++){
      for(int k=0;k<10;k++){
	if(S[j]==k){
	  continue;
	}
	vector<int> tmp=S;
	tmp[j]=k;
	int tmp1=calc(tmp);
	if(m[tmp1][tmp[4]]==0){
	  cnt++;
	  isOk = false;
	  break;
	}
      }

      if(!isOk){
	break;
      }
    }

    if(!isOk){
      continue;
    }
    for(int j=0;j<4;j++){
      if(S[j] == S[j + 1]){
	continue;
      }
      
      vector<int> tmp=S;
      swap(tmp[j],tmp[j+1]);
      int tmp1=calc(tmp);
      if(m[tmp1][tmp[4]]==0){
	cnt++;
	isOk = false;
	break;
      }
    }
  }
  cout<<cnt<<endl;
  
  return 0;
}



Measured memory_bytes: 3136
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

#include <set>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    set<int> s;
    REP(i, 0, n) {
        int a;
        cin >> a;
        s.insert(a);
    }
    cout << (s.size() == n ? "YES" : "NO") << endl;
    return 0;
}


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

#define int long long

vector<vector<int>>uesita(10,vector<int>(10,0));

signed main(void){
    int n; cin >> n;
    int ans = 0;
    for(int i=1;i<=n;i++){
        string s = to_string(i);
        int ue = s[0]-'0', sita = s[s.length()-1] - '0';
        // cout << ue << ' ' << sita << endl;

        uesita[ue][sita]++;
    }
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            // cout <<i << ' ' << j << ' ' <<  uesita[i][j] << endl;
            ans += uesita[i][j]*uesita[j][i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.text.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    
    public static int[] generatePrimes(int n) {
		boolean[] prime = new boolean[n + 1];
		Arrays.fill(prime, 2, n + 1, true);
		for (int i = 2; i * i <= n; i++)
			if (prime[i])
				for (int j = i * i; j <= n; j += i)
					prime[j] = false;
		int[] primes = new int[n + 1];
		int cnt = 0;
		for (int i = 0; i < prime.length; i++)
			if (prime[i])
				primes[cnt++] = i;
		return Arrays.copyOf(primes, cnt);
	}
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        DecimalFormat df = new DecimalFormat("0.000000000000");
        double sum = 0L, mx = 0L;
        int n = in.nextInt();
        int k = in.nextInt();
        double a[] = new double[n+1];
        int x = 0;
        for(int i=1;i<=n;i++){
            x = in.nextInt();
            if(x%2==0){
                a[i] = (x/2)+0.5;
            }else {
                a[i] = (x+1)/2.0;
            }
        }
        for(int i=1;i<=n;i++){
            sum+=a[i];
            if(i>=k){
                mx = Math.max(mx,sum);
                sum-=a[i-k+1];
            }
        }
        out.write(df.format(mx)+"\n");
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 41572
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
const double PI  =3.141592653589793238463;
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<int,int> P;
const int mod = 1e9+7;

struct mint{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a){
        (x+=a.x)%=mod;
        return *this;
    }
    mint& operator-=(const mint a){
        (x-=mod-a.x)%=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x)%= mod;
        return *this;
    }
    mint operator+(const mint a)const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a)const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a)const{
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
      if(!t)return 1;
      mint a = pow(t>>1);
      a*=a;
      if(t%1)a*=*this;
      return a;
    }

    // for prime mod
    mint inv() const {
      return pow(mod-2);
    }
    mint& operator/=(const mint a){
      return (*this) *= a.inv();
    }
    mint operator/(const mint a)const{
      mint res(*this);
      return res/=a;
    }
};

struct combination{
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i<n;++i)fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i>=1;--i) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k){
    if(k<0 || k>n)return 0;
    return fact[n] * ifact[k] + ifact[n-k]; 
  }
};

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];
    ll sum=0;
    rep(i,n){
        sum+=a[i];
        sum%=mod;
    }
    ll ans = 0;
    rep(i,n-1){
        sum-=a[i];
        if(sum<0)sum+=mod;
        ans+=(sum*a[i]);
        ans%=mod;
    }
    cout << ans%mod <<endl;
    return 0;
}

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

int main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int n;
    cin>>n;
    int hap[n+1][4],dp[n+1][4];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=3;j++)
        cin>>hap[i][j];
    }
    dp[1][1]=hap[1][1];
    dp[1][2]=hap[1][2];
    dp[1][3]=hap[1][3];
    for(int i=2;i<=n;i++){
        dp[i][1]=max(dp[i-1][2]+hap[i][1],dp[i-1][3]+hap[i][1]);
        dp[i][2]=max(dp[i-1][1]+hap[i][2],dp[i-1][3]+hap[i][2]);
        dp[i][3]=max(dp[i-1][1]+hap[i][3],dp[i-1][2]+hap[i][3]);
    }
    cout<<max(dp[n][1],max(dp[n][2],dp[n][3]));
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 998244353;//1e9 + 7;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> PDL;
typedef pair<LD, LD> PDD;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

template<class Rng>
void in(Rng& x) {
	cin >> x;
}

template<class T1, class T2>
void in(pair<T1, T2>& p) {
	in(p.first);
	in(p.second);
}

template<class Rng>
void in(vector<Rng>& v, LL st = -1, LL en = -1) {
	if (st == -1) {
		st = 0;
		en = v.size() - 1;
	}
	for (LL n = st; n <= en; n++) {
		in(v[n]);
	}
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL x, y;
	cin >> x >> y;
	if(x < y) {
		if (x >= 0) {
			cout << y - x << "\n";
		}
		else if (y >= 0) {
			if (-x <= y)cout << min(y - x, 1 + y + x) << "\n";
			else cout << min(y - x, 1 - y - x) << "\n";
		}
		else {
			cout << y - x << "\n";
		}
	}
	else {
		if (y >= 0) {
			cout << min(1 + x + y,2-y+x) << "\n";
		}
		else if (x >= 0) {
			if (-y >= x) {
				cout << -x - y + 1 << "\n";
			}
			else {
				cout << 1 + y + x << "\n";
			}
		}
		else {
			cout << min(-y - x + 1, 2 - y + x) << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 256
// AOJ 1350
#include<iostream>
#include<algorithm>
#include<map>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int integer;

struct edge { integer u, v, cost; };

bool comp(const edge& e1, const edge& e2) {
  return e1.cost < e2.cost;
}

const integer EMAX = 1e6;
const integer VMAX = 1000;
const integer INF = 1e10;
edge es[EMAX];
bool used[EMAX];
integer V, E;

integer par[VMAX];
integer lank[VMAX];

void init_union_find(integer N) {
  for (integer i = 0; i < N; i++) {
    par[i] = i;
    lank[i] = 0;
  }
}

integer find(integer x) {
  if (x == par[x]) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

void unite(integer x, integer y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (lank[x] < lank[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (lank[x] == lank[y]) lank[x]++;
  }
}

bool same(integer x, integer y) {
  return find(x) == find(y);
}

integer kraskal(bool causes_side_effect) {
  init_union_find(V);
  integer res = 0;
  REP(i, E) {
    edge e = es[i];
    if (e.cost == INF) continue;
    if (!same(e.u, e.v)) {
      unite(e.u, e.v);
      res += e.cost;
      if (causes_side_effect) {
        used[i] = true;
      }
    }
  }
  return res;
}

bool connected() {
  REP(i, V) {
    if (not same(0,i)) return false;
  }
  return true;
}

pair<integer,integer> solve() {
  sort(es, es + E, comp);
  REP(i, E) { used[i] = false; }
  integer mincost = kraskal(true);

  integer edges = 0, total_cost = 0;
  REP(i, E) {
    if (not used[i]) continue;
    integer temp = es[i].cost;
    es[i].cost = INF;
    integer cost = kraskal(false);
    if (mincost < cost or !connected()) {
      edges++;
      total_cost += temp;
    }
    es[i].cost = temp;
  }
  return make_pair(edges, total_cost);
}

int main() {
  cin >> V >> E;
  REP(i, E) {
    cin >> es[i].u >> es[i].v >> es[i].cost;
    es[i].u--; es[i].v--;
  }
  pair<integer,integer> p = solve();
  cout << p.first << " " << p.second << endl;
}

Measured memory_bytes: 4344
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
long long int n;
int main(){
    cin>>n;
    for(int i=sqrt(n);i>=1;i--)
    {
        if(n%i==0){
            int t=i,l=n/i;
            int s=1;
            while(l>=10){
                s++;
                l/=10;
            }
        cout<<s;
        return 0;
        }
    }
}

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

#define endl '\n'
#define ll long long
#define ull unsigned ll

typedef string BigInt;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	
	ll n, m, a, r, c, h;
	cin >> n;
	m = a = r = c = h = 0;
	string str;
	while(n --){
		cin >> str;
		if(str[0] == 'M') m++;
		if(str[0] == 'A') a++;
		if(str[0] == 'R') r++;
		if(str[0] == 'C') c++;
		if(str[0] == 'H') h++;
	}
	
	ll res[1 + 10];
	res[1] = m*a*r;
	res[2] = m*a*c;
	res[3] = m*a*h;
	res[4] = m*r*c;
	res[5] = m*r*h;
	res[6] = m*c*h;
	res[7] = a*r*c;
	res[8] = a*r*h;
	res[9] = a*c*h;
	res[10] = r*c*h;
	ll sum = 0;
	for(int i = 1; i <= 10; i++) sum += res[i];
	cout << sum;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem(arr,v) memset(arr,v,sizeof(arr))
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     string s1,s2;
     cin>>s1>>s2;
     if(s1.size()>s2.size())
        cout<<"GREATER";
     else if(s1.size()<s2.size())
        cout<<"LESS";
     else
     {
         ll cnt=0;
         for(int i=0;i<s1.size();i++)
         {
             if(s1[i]>s2[i])
             {
                 cnt=10;
                 cout<<"GREATER";
                 break;
             }
             if(s1[i]<s2[i])
             {
                 cnt=10;
                 cout<<"LESS";
                 break;
             }
         }
         if(cnt==0)
            cout<<"EQUAL";
     }
     cout<<endl;
}


Measured memory_bytes: 3604
#include <iostream>

using namespace std;

void yes() {
	cout << "Yes";
}
void no() {
	cout << "No";
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	if (a + b == c) {
		yes();
	}
	else if (b + c == a) {
		yes();
	}
	else if (c + a == b) {
		yes();
	}
	else no();

	return 0;
}

Measured memory_bytes: 256