akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
//#define int long long int
using namespace std;




int main(){
 string S; cin>>S;
 int x = S.size();

 for(int i=0;i<x;i++){
   cout<<"x";

 }
 cout<<endl;

  


  return 0;
   
}


Measured memory_bytes: 256
n,m,l = map(int, input().split())
A = [[0 for col in range(m)] for row in range(n)]
B = [[0 for col in range(l)] for row in range(m)]
C = [[0 for col in range(l)] for row in range(n)]

for row in range(n):
    cols = list(map(int, input().split()))
    for col in range(m):
        A[row][col] = cols[col]

for row in range(m):
    cols = list(map(int, input().split()))
    for col in range(l):
        B[row][col] = cols[col]

for row in range(n):
    for col in range(l):
        for index in range(m):
            C[row][col] += A[row][index] * B[index][col]
    print(" ".join(map(str, C[row])))


Measured memory_bytes: 6896
def main():
    n = int(input())
    m = [list(map(int, input().split())) for _ in range(n)]

    ans = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            d = m[i][j]
            for k in range(n):
                if k in (i, j):
                    continue
                t = m[i][k] + m[k][j]
                if t < d:
                    print(-1)
                    exit()
                if t == d:
                    break
            else:
                ans += d
    else:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 12776
#include <iostream>
using namespace std;
string S,T;
int C[26] = {0},D[26] = {0};
int main(){
	cin >> S >> T;
	int N = S.size();
	for(int i=0;i<=25;i++){
		C[i] = -1;
		D[i] = -1;
	}
	bool judge = true;
	for(int i=0;i<N;i++){
		if(C[S[i]-'a']==-1){
			C[S[i]-'a'] = T[i]-'a';
		}
		else if(C[S[i]-'a']!=T[i]-'a') judge = false;
		if(D[T[i]-'a']==-1){
			D[T[i]-'a'] = S[i]-'a';
		}
		else if(D[T[i]-'a']!=S[i]-'a') judge = false;
	}
	cout << (judge? "Yes":"No") << endl;
}

Measured memory_bytes: 776
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <complex>
#define LL long long
using namespace std;
const int M = 1e3 + 5, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double PI = acos(-1);

int main() {
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF){
        map<pair<int,int>,bool>mp;
        for(int j=1;j<=m;j++){
            int a,b;
            scanf("%d%d",&a,&b);
            mp[{a,b}]=mp[{b,a}]=1;
        }
        int ok=0;
        if(mp[{1,n}]) ok=1;
        for(int j=2;j<n;j++){
            if(mp[{1,j}]&&mp[{j,n}]) ok=1;
        }
        if(ok) printf("POSSIBLE\n");
        else printf("IMPOSSIBLE\n");
    }
    return 0;
}


Measured memory_bytes: 37760
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
string s;
int r;
int main(){
	ios::sync_with_stdio(0);
	int n;
	cin>>n>>s;
	rep(i,n){
		if(s[i]=='R')
		r++;
	}
	int ans=r;
	rep(i,r)
	if(s[i]=='R')
	ans--;
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3732
import { readFileSync } from 'fs'

function main(input: string[]) {
  let ans = 0
  let s = input[0]
  let t = input[1]
  for (let i = 0; i < s.length; i++) {
    if (s[i] != t[i]) ans++
  }
  console.log(ans)
}

let lines: string[] = [];
const reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', function (line: string) {
  lines.push(line);
});
reader.on('close', function () {
  main(lines)
});


Measured memory_bytes: 34224
#include <iostream>
using namespace std;
char s[1000004];
int  d[1000004];
int main( void )
{
  int M=1000000;
  int n=0;
  for( int i=2; i<M; i++ ){
    if( !s[i] ){
      int j=i*2;
      while( j < M ){ s[j]=1; j+=i; }
      n++;
    }
    d[i] = n;
  }
  while( 1 ){
    cin >> n;
    if( cin.eof() ) break;
    cout << d[n] << endl;
  }
  return 0;
}

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

int main(){
    int a,b,c,x;
    cin>>a>>b>>c>>x;
    int cnt=0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(500*i+100*j+50*k==x)cnt++;
            }
        }
    }
    cout<<cnt<<endl;
    return 0;
}

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

int main(){
    int N;cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    int count = 0;
    bool flag = true;
    while (flag)
    {
        flag = false;
        for (int i = N-1; i >= 1; i--)
        {
            if (A.at(i) < A.at(i-1)){
               int temp = A.at(i);
               A.at(i) = A.at(i-1);
               A.at(i-1) = temp;
               flag = true;
               count++;
            }
        }
           
    }

    for (int i = 0; i < N; i++)
    {
        if (i == N-1) cout << A.at(i) << endl;
        else cout << A.at(i) << " ";
    }
    
    cout << count << endl;
}


Measured memory_bytes: 3100
<?php

    fscanf(STDIN, "%d", $N);
    
    echo calcL($N) . PHP_EOL;

    function calcL($n) {
        global $array;
        $array[0] = 2;
        $array[1] = 1;
        if (isset($array[$n])) {
            return $array[$n];
        } else {
            $array[$n] = calcL($n - 1) + calcL($n - 2);
            return $array[$n];
        }
    }


Measured memory_bytes: 4728
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
using namespace std;
int main(){
	int a = 0, b = 0, c=0, d[100000], e[100000],f=0, count = 0;
	char uc[100000];
	for (int i = 0; i < 3; i++) {
		cin >> uc[i];
		if (uc[i] == '1') {
			count++;
		}
	}
	cout << count << endl;
		return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int n,tmp,count =0;

    cin >> n;

    int * array = new int[n];

    for(int i = 0;i < n;i++)
        cin >> array[i];
    
    tmp = array[0];

    for(int i = 0;i < n;i++){
        if(tmp >= array[i]){
            count++;
            tmp = array[i];
        }

    }

    cout << count << endl;

    delete [] array;
    return 0;
}

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

int main(void) {
    int i, j;
    for (i = 0; i < 5; ++i) {
        int k;
        cin >> k;
        if (k == 0) {
            j = i + 1;
        }
    }
    printf("%d\n", j);
    return 0;
}


Measured memory_bytes: 3744
class Line:
    def __init__(self,p1,p2):
        if p1[1] < p2[1]:self.s=p2;self.e=p1
        elif p1[1] > p2[1]:self.s=p1;self.e=p2
        else:
            if p1[0] < p2[0]:self.s=p1;self.e=p2
            else:self.s=p2;self.e=p1
def dot(a,b):return a[0]*b[0] + a[1]*b[1]
def cross(a,b):return a[0]*b[1] - a[1]*b[0]
def dif(a,b):return [x-y for x,y in zip(a,b)]
def InterSection(l,m):
    a = dif(l.e,l.s);b = dif(m.e,l.s);c = dif(m.s,l.s)
    d = dif(m.e,m.s);e = dif(l.e,m.s);f = dif(l.s,m.s)
    g = lambda a, b : cross(a,b)==0 and dot(a,b)>0 and dot(b,b)<dot(a,a)
    if g(a,b) or g(a,c) or g(d,e) or g(d,f):return True
    elif l.s == m.e or l.s == m.s or l.e == m.e or l.e == m.s:return True
    elif cross(a,b) * cross(a,c) >= 0 or cross(d,e) * cross(d,f) >= 0:return False
    else:return True

q = int(input())
for i in range(q):
    x0,y0,x1,y1,x2,y2,x3,y3 = [int(i) for i in input().split()]
    a = [x0,y0] ; b = [x1,y1] ; c = [x2,y2] ; d = [x3,y3]
    l1 = Line(a,b) ; l2 = Line(c,d)
    if InterSection(l1,l2):print(1)
    else:print(0)

Measured memory_bytes: 7860
# include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, currentSize, a[N];
vector < int > order;
void erase(int index, int &arraySize){
	for(int i = index + 1; i <= arraySize; ++i){
		swap(a[i], a[i - 1]);
	}
	arraySize--;
}
int main(){
	cin >> n;
	currentSize = n;
	for(int i = 1; i <= n; ++i)cin >> a[i];
	while(currentSize >= 1){
		int index = -1, mx = 0;
		for(int i = 1; i <= currentSize; ++i){
			if(a[i] == i){
				if(mx < a[i]){
					mx = a[i];
					index = i;
				}
			}
		}
		if(index == -1){
			cout << "-1\n";
			return 0;
		}
		order.push_back(index);
		erase(index, currentSize);
	}
	reverse(order.begin(), order.end());
	for(int i = 0; i < order.size(); ++i)cout << order[i] << '\n';
}

Measured memory_bytes: 256
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>

#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll mod = 1e9 + 7;

string S;

ll N, K, D;
ll X[100][100];

ll ans;





int main() {

	cin >> N >> D;
	FOR(i, 0, N) {
		FOR(j, 0, D) {
			cin >> X[i][j];
		}
	}
	FOR(i, 0, N) {

		FOR(j, i + 1, N) {
			ll judge = 0;
			FOR(k, 0, D) {
				judge += (X[i][k] - X[j][k])*(X[i][k] - X[j][k]);
			}
			FOR(s, 1, 200) {
				if (judge == s * s) {
					ans++;
					break;
				}
			}
		}

	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>

using namespace std;

#define N 100005

void solve() {
  int L;scanf("%d",&L);
  pair<pair<int,int>,int> edge[60];
  int epos = 0;
  for(int i=1;i<20;++i) {
    edge[epos++] = make_pair(make_pair(i,i+1),0);
  }
  int msb = 0,nodePos = 0;
  --L;
  for(int i=0;i<20;++i) {
    if(L&(1<<i)) {
      msb = i;
    }
  }
  int nodeSum[22];
  nodeSum[1] = 0;
  for(int i=0;i<msb;++i) {
    edge[epos++] = make_pair(make_pair(i+1,i+2), 1<<i);
    nodeSum[i+2] = nodeSum[i+1] + (1<<i);
  }
  int limit = (1<<msb);
  while(limit<=L && epos<60) {
    for(int i=msb+1;i;--i) {
      if(L - nodeSum[i] >=limit) {
        int weight = L - nodeSum[i];
        edge[epos++] = make_pair(make_pair(i,20), weight);
        L = L - nodeSum[i] - 1;
      }
    }
  }
  if(limit<=L) {
    assert(0);
  }
  printf("20 %d\n",epos);
  for(int i=0;i<epos;++i) {
    printf("%d %d %d\n",edge[i].first.first,edge[i].first.second,edge[i].second);
  }
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}


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

using namespace std;

int n;
int ans[505][505];

void solve(int st,int dr,int col){
    if(st == dr){
        return ;
    }
    int mid = (st + dr) / 2;
    for(int i = st;i <= mid;i++){
        for(int j = mid + 1;j <= dr;j++){
            ans[i][j] = col;
        }
    }
    solve(st,mid,col + 1);
    solve(mid + 1,dr,col + 1);
}

int main() {
    cin >> n;
    
    solve(1,n,1);

    for(int i = 1;i <= n;i++){
        for(int j = i + 1;j <= n;j++){
            cout << ans[i][j] << " ";
        }
        cout << "\n";
    }

    return 0;
}


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

int board[10][10];

int main(){
    int H, W;
    cin >> H >> W;
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            cin >> board[i][j];
        }
    }
    int necessary_cost[10];
    bool if_finished[10];
    for(int i = 0; i < 10; i++){
        necessary_cost[i] = 1e9;
        if_finished[i] = false;
    }
    necessary_cost[1] = 0;
    while(true){
        int min_cost = 1e9;
        int min_cost_number = -1;
        for(int i = 0; i < 10; i++){
            if(min_cost > necessary_cost[i] && !if_finished[i]){
                min_cost = necessary_cost[i];
                min_cost_number = i;
            }
        }
        if(min_cost_number == -1){
            break;
        }
        for(int i = 0; i < 10; i++){
            if(min_cost_number != i){
                necessary_cost[i] = min(necessary_cost[i], min_cost + board[i][min_cost_number]);
            }
        }
        if_finished[min_cost_number] = true;
    }
    int ans = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            int input;
            cin >> input;
            if(input != -1){
                ans += necessary_cost[input];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
 
public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int height[] = new int[10];
        
        for(int i = 0; i < 10; i++){
            height[i] = stdIn.nextInt();
        }
        
        Arrays.sort(height);
            
        System.out.println(height[9]);
        System.out.println(height[8]);
        System.out.println(height[7]);

        stdIn.close();
    }
}


Measured memory_bytes: 26400
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int m; cin >> m;
  vector<int> b(m);
  rep(i,m) cin >> b[i];
  set<int> st;
  rep(i,1<<n){
    ll sum=0;
    rep(j,n){
      if((i>>j)&1) sum+=a[j]; 
    }
    st.insert(sum);
  }
  rep(i,m){
    if(st.count(b[i])) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char>cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main()	{
  int n,x;
  cin>>n>>x;
  vector<int>l(n),d(n+1);
  rep(i,n) cin>>l[i];
  int cnt=0;
  rep(i,n){
    d[i+1]=d[i]+l[i];
  }
  rep(i,n+1){
    if(d[i]<=x) cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a[3];
int i,count=0,count1=0;
for(i=0;i<3;i++)
    scanf("%d",&a[i]);
for(i=0;i<3;i++)
{
    if(a[i]==5) count++;
    else if(a[i]==7) count1++;
}
if(count==2&&count1==1) printf("YES");
else printf("NO");
return 0;}


Measured memory_bytes: 128
#include <stdio.h>

int main()
{
	int a,b;
	char op;
	
	for(;;)
	{
		scanf("%d %c %d",&a,&op,&b);
		
		if('?'==op)
		{
			break;
		}
		else if('+'==op)
		{
			printf("%d\n",a+b);
		}
		else if('-'==op)
		{
			printf("%d\n",a-b);
		}
		else if('*'==op)
		{
			printf("%d\n",a*b);
		}
		else if(('/'==op)&&(b!=0))
		{
			printf("%d\n",a/b);
		}
		else
		{
		}
	}
	return 0;
}




Measured memory_bytes: 2760
import sys
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if sum(a)<sum(b):
    print(-1)
    sys.exit()
    
need = 0
amari = []
ans = 0
for ai,bi in zip(a,b):
    dif = ai-bi
    if dif<0:
        need += abs(dif)
        ans += 1
    else:
        amari.append(dif)
amari.sort(reverse=True)
amari

s = 0
for amari_i in amari:
    if s<need:
        s += amari_i
        ans += 1
    else: break
print(ans)

Measured memory_bytes: 20276
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>

using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, mw;
	cin >> n >> mw;
	vector<long long> memo;
	memo.resize(mw + 1, 0);
	for (int i = 0; i < n; i++) {
		int w, v;
		cin >> w >> v;
		for (int j = mw; j >= w; j--) {
			memo[j] = max(memo[j], memo[j - w] + v);
		}
	}
	cout << memo.back();
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
int main(){
    int n, m, k, cnt, tmp, ans = 0; sc(n), sc(m);
    vector<vector<int> > vec(m);
    vector<int> e(m);
    for (int i = 0; i < m; i++){
        sc(k), vec[i].resize(k);
        for (int j = 0; j < k; j++) sc(vec[i][j]);
    }
    for (int i = 0; i < m; i++) sc(e[i]);
    for (int i = 0; i < (1<<n); i++){
        cnt = 0;
        for (int j = 0; j < m; j++){
            tmp = 0;
            for (const auto &x : vec[j]){
                if (i & (1<<(x-1))) tmp++;
            }
            if (tmp%2==e[j]) cnt++;
        }
        if (cnt==m) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int h,w;cin >> h >> w;
    vector<vector<char>> grid(h+2,vector<char>(w+2,'#'));
    rep(i,h)rep(j,w)cin >> grid[i][j];
    vector<vector<ll>> dp(h+2,vector<ll>(w+2));
    dp[0][0]=1;
    rep(i,h)rep(j,w){
        if(grid[i+1][j]=='.'){
            dp[i+1][j]+=dp[i][j];
            if(dp[i+1][j]>=big)dp[i+1][j]-=big;
        }
        if(grid[i][j+1]=='.'){
            dp[i][j+1]+=dp[i][j];
            if(dp[i][j+1]>=big)dp[i][j+1]-=big;
        }
    }
    cout << dp[h-1][w-1] << endl;
}

Measured memory_bytes: 12064
object Main {
  def main(args:Array[String]) {
    val N = scala.io.StdIn.readLine().toInt
    val A = scala.io.StdIn.readLine().split(' ').map(_.toInt)
    val n_odd = A.filter(_%2 == 1).length
    val n_even = A.filter(_%2 == 0).length
    if (n_odd%2 == 0) println("YES")
    else println("NO")
  }
}

Measured memory_bytes: 35224
#include<bits/stdc++.h>
#define int long long
using namespace std;
int dp[1000][20];
int n,k;
int dppp[1000][20];
int cal(int num)
{
    if(num==1) return 9;
    int ans=0;
    for(int i=0;i<10;i++)
        dppp[1][i]=1;
    for(int i=1;i<=9;i++)
    {
        for(int j=i-1;j<=min(9*1LL,i+1);j++)
            dppp[num][i]+=dppp[num-1][j];
        ans+=dppp[num][i];
    }
    dppp[num][0]=dppp[num-1][0]+dppp[num-1][1];
    return ans;
}
int dfs(int lim,int pos,int digit)
{
    if(pos==lim) return dp[pos][digit]=1;
    if(dp[pos][digit]) return dp[pos][digit];
    for(int i=max(0LL,digit-1);i<=min(digit+1,9*1LL);i++)
    {
        //dfs(lim,pos+1,i);
        dp[pos][digit]+=dfs(lim,pos+1,i);
    }
    return dp[pos][digit];
}
void work(int num,int tong)
{
    string s="";
    int sum=tong;
    //cout<<sum<<"\n";
    for(int i=1;i<=9;i++)
    {
        sum+=dppp[num][i];
       // cout<<i<<" "<<sum<<"\n";
        if(sum>=k)
        {
            sum-=dppp[num][i];
            s+=(char)('0'+i);
            int pos=2;
            int digit=i;
            for(;pos<=num;pos++)
            {
                for(int j=max(0LL,digit-1);j<=min(9*1LL,digit+1);j++)
                {
                    sum+=dppp[num-pos+1][j];
                   // cout<<j<<" "<<sum<<"\n";
                    if(sum>=k)
                    {
                        //cout<<j<<" ";
                        s+=(char)('0'+j);
                        digit=j;
                        sum-=dppp[num-pos+1][j];
                        break;
                    }
                }
               // cout<<"\n";
            }
            break;
        }
    }
    cout<<s;
}
signed main()
{
  //  freopen("inp.txt","r",stdin);
    cin>>k;
    if(k<10)
    {
        cout<<k;
        exit(0);
    }
    long long tmp=0;
    for(int i=1;i<=15;i++)
    {
        int pre=tmp;
        tmp+=cal(i);
        //cout<<i<<" "<<tmp<<"\n";
        if(tmp>=k)
        {
            work(i,pre);
            exit(0);
        }
    }
}


Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		String str1  =  sc.next();
		String str2  =  sc.next();
      	int num = str1.length();
      
      	int cnt = 0;
      	char[] ary1 = new char[num];
      	char[] ary2 = new char[num];

      	for(int i = 0; i < str1.length() ; i++){
        	ary1[i] = str1.charAt(i);
        	ary2[i] = str2.charAt(i);

          	if(ary1[i] != ary2[i]){
            	cnt++;
            }
        }
      	System.out.println(cnt);
    }
}

Measured memory_bytes: 41772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
static const long long INF = INT64_MAX;
static const long long MOD = (ll)1e9+7;

#define endl "\n"
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define REP(i, n) for(ll i=0;i<n;i++)
#define SZ(v) (ll)((v).size())
#define WHOLE(v) (v).begin(), (v).end()
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse((v).begin(), (v).end())
#define FOLDL(src, dst, lambda) partial_sum((src).begin(), (src).end(), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum((src).begin(), (src).end(), (dst).begin(), lambda);INV(dst)
#define CUMSUML(src, dst) FOLDL(src, dst, [](auto a, auto b) {return a+b;})
#define CUMSUMR(src, dst) FOLDR(src, dst, [](auto a, auto b) {return a+b;})
#define ACCUM(v, d0, lambda) accumulate((v).begin(), (v).end(), d0, lambda)
#define SUM(v, d0) ACCUM(v, d0, [](auto a, auto b) {return a+b;})
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);v.erase(unique(v.begin(), v.end()), v.end())

template <typename T>void debug(T t) {cerr << t << endl;}
template <typename T, typename ...Args>void debug(T t, Args ...args) {cerr << t << " ";debug(args...);}
template <typename T>void out(T t) {cout << t << endl;}
template <typename T, typename ...Args>void out(T t, Args ...args) {cout << t << " ";out(args...);}

void solve() {
    ll A, B, C;
    cin >> A >> B >> C;
    if(A % 2 == 0 && A == B && B == C) {
        out(-1);
        return;
    }
    ll ans = 0;
    ll tmp1, tmp2, tmp3;
    while(A % 2 != 1 && B % 2 != 1 && C % 2 != 1) {
        tmp1 = (B + C) / 2;
        tmp2 = (C + A) / 2;
        tmp3 = (B + A) / 2;
        A = tmp1;
        B = tmp2;
        C = tmp3;
        ans++;
    }
    out(ans);
}

int main() {
    fast_io;
    solve();
    return 0;
}

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

typedef long long int ll;

int main () {
    string str;
    cin >> str;
    bool flg = false;
    for (int i = 0; i < (int)str.size(); i++) {
        if (str[i] == '7') {
            flg = true;
        }
    }
    if (flg) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3128
#include <stdio.h>

int main(void){
	int sum = 0, max = 0, in;
	for(int i = 0; i < 3; i++){
		scanf("%d", &in);
		if(in > max)max = in;
		sum += in;
	}
	if(sum / 2 == max && !(sum % 2))
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}


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

int main(void){
	
	int r,g,b;
	
	cin>>r>>g>>b;
	
	int sum=100*r+10*g+b;

	if(sum%4==0){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<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 A = sc.nextInt();
   int B = sc.nextInt();
   
   if(A>=10 || B>=10)System.out.println(-1);
   else System.out.println(A*B);
 }
}

Measured memory_bytes: 24020
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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 (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;

using Graph = vector<vector<int>>;
ll modPow(ll x, ll n) {
    if(n==0) return 1;
    ll res = modPow(x*x%MOD, n/2);
    if(n&1) res=res*x%MOD;
    return res;
}
ll mul(ll l, ll r) {
    ll ret =1;
    for(int i=0; i<l-r+1; ++i) {
        ret*=i+r;
        ret%=MOD;
    }
    return ret;
}
ll com(ll n, ll k) {
    ll ret1 = mul(n,n-k+1);
    ll ret2 = mul(k,1);
    ll ret3 = modPow(ret2, MOD-2);
    return ret1*ret3%MOD;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m; cin >> n >> m;
    cout << com(n,2)+com(m,2) << "\n";
}



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

double sum(int b[],int);
void bubble(int b[],int);


int main(){
    int a;
    cin >> a;
    int b[a];
    for (int i=0;i<a;i++)
        cin >> b[i];
    bubble(b,a);
    cout << b[0] << " " << b[a-1] << " " ;
    printf("%.0f\n",sum(b,a));
}

void bubble(int b[],int a){
    int x;
    for (int i=0;i< a-1 ;i++){
        for (int j=0;j<a-1 ;j++)
            if(b[j]>b[j+1]){
                x=b[j];
                b[j]=b[j+1];
                b[j+1]=x;
        }
    }
}

double sum(int b[], int a){
    double sum=0;
    for (int i=0;i<a;i++)
        sum += b[i];
    return sum;
}

Measured memory_bytes: 1276
//
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define speed ios::sync_with_stdio(false)
using namespace std;

string gs(char x){
    string s(1,x);
    return s;
}

int main()
{
	speed;
	
	ll n;
	bool flag=false;
	cin>>n;
	ll a=n/7,b;
	for(ll i=0;i<=a;i++){
		b=n-(7*i);
		if(b%4==0)
		{
			flag=true;
			break;
		}
	}
	if(flag)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
const int MOD=1000000007;
#define endl "\n"
#define fst first
#define snd second
const int UNDEF = -1;
const int INF=1<<30;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;typedef vector<ll> vll;typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;
#ifdef ONLINE_JUDGE
#define assert(...) /* nothing */
#endif
#define DEBUG_CAT
#ifdef DEBUG_CAT
#define dbg(...)   printf( __VA_ARGS__ )
#else 
#define dbg(...)   /****nothing****/
#endif
void solve(long long n){
	int slim=min((ll)(sqrt((ld)n)+4),n-1);
	ll ans=0;
	for (int a=1;a<=slim;a++) {
		if (n%a==0) {
			ll m=(n/a)-1;
			if (a<m) ans+=m;
		}
	}
	printf("%lld\n",ans);
}

int main(){	
	long long N;
	scanf("%lld",&N);
	solve(N);
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    int n;
    cin >> n;

    vi a(n);
    ll ans = 0;
    fo(i, n) {
        cin >> a[i];
        ans += a[i] - 1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::BTreeMap;

fn main() {
    input! {
        n: u32,
        a: [u32; n],
    }

    let mut m: BTreeMap<u32, u32> = BTreeMap::new();

    for i in a.iter() {
        *m.entry(*i).or_insert(0) += 1;
    }

    let ans: u32 = m.iter().map(|(&k, &v)| if k > v { v } else { v - k }).sum();
    println!("{:?}", ans);
}


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

const int MAXN = 301;

int n, ai;
double a1 = 0.0, a2 = 0.0, a3 = 0.0;
double dp[MAXN][MAXN][MAXN] = {0.0};

double solve(int i, int j, int k) {
    if ((i < 0) or (j < 0) or (k < 0) or (i + j + k == 0))
        return 0.0;

    if (dp[i][j][k] == 0.0) {
        double res = (double) n / (i + j + k) - 1.0;
        res += (solve(i - 1, j, k) + 1.0) * (double) i / (i + j + k);
        res += (solve(i + 1, j - 1, k) + 1.0) * (double) j / (i + j + k);
        res += (solve(i, j + 1, k - 1) + 1.0) * (double) k / (i + j + k);
        dp[i][j][k] = res;
    }

    return dp[i][j][k];
}

int main() {
    cout << fixed << setprecision(10);

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> ai;
        if (ai == 1)
            a1++;
        if (ai == 2)
            a2++;
        if (ai == 3)
            a3++;
    }

    cout << solve(a1, a2, a3) << '\n';
}


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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)
int x[4];
int y[4];
int main(){
  REP(i,2) cin >> x[i] >> y[i];
  FOR(i,2,4){
    int dx = x[i-1] - x[i-2];
    int dy = y[i-1] - y[i-2];
    x[i] = x[i-1] - dy;
    y[i] = y[i-1] + dx;
  }
  REP(i,2) cout << x[i+2] << " " << y[i+2] << " ";
  cout <<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws Exception{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
    
    	int kaisu = Integer.parseInt( br.readLine());
    	int tpoint = 0;
    	int hpoint = 0;
    	int kurikaesi = 0;
    	for (int i = 0; i < kaisu; i++)
    	{
    		String[] card = br.readLine().split(" ");
    		String taro = card[0];
    		String hanako = card[1];
    		
    		if (taro.length() <= hanako.length())
    			kurikaesi = taro.length();
    		else if (taro.length() > hanako.length())
    			kurikaesi = hanako.length();
    		
    		for (int j = 0; j < kurikaesi; j++)
    		{
    			if (taro.charAt(j) > hanako.charAt(j))
    			{
    				tpoint += 3;
    				break;
    			}
    			else if (taro.charAt(j) < hanako.charAt(j))
    			{
    				hpoint += 3;
					break;
    			}
    			if (j == kurikaesi - 1)
    			{
    				if (taro.length() == hanako.length())
    				{
    					tpoint += 1;
    					hpoint += 1;
    				}
    				else if (taro.length() < hanako.length())
    					hpoint += 3;
    				else if (taro.length() > hanako.length())
    					tpoint += 3;
    			}
    		}
    	}
		System.out.println(tpoint + " " + hpoint);	
	}

}

Measured memory_bytes: 25212
import math as np
K=int(input())
P=0
for i in range(1,K+1):
    for j in range(1,K+1):
        l=np.gcd(i,j)

        for k in range(1,K+1):
            m=np.gcd(l,k)
            P=m+P
print(P)


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

int main(){
    int n;
    vector<int> v;

    cin >> n;
    for(int i = 0; i < n; i++){
        int t;
        cin >> t;
        v.push_back(t);
    }

    int cnt = 0;
    for(int i = 0; i < n; i++){
        if( i == v[v[i]-1] - 1 ){
            cnt++;
            v[i] = -1;
        }
    }
    cout << cnt << endl;
}

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

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

    int sheets[100][100] = {};
    int sum_col[100] = {};
    int row, col;
    cin >> row >> col;
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < col; j++) {
            cin >> sheets[i][j];
        }
    }

    for (int i = 0; i < row; i++) {
        int sum_row = 0;
        for (int j = 0; j < col; j++) {
            cout << sheets[i][j];

            sum_row += sheets[i][j];
            sum_col[j] += sheets[i][j];
            if (j != col - 1) {
                cout << " ";
            } else {
                cout << " " << sum_row << endl;
            }
        }
    }

    // last row
    int sum_all = 0;
    for (int i = 0; i < col; i++) {
        cout << sum_col[i];
        sum_all += sum_col[i];
        if (i != col - 1) {
            cout << " ";
        } else {
            cout << " " << sum_all << endl;
        }
    }
}


Measured memory_bytes: 3180
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

S = input()
T = input()
q = int(input())

tmp = 0
S_SUM = [0]
for s in S:
	if s == 'A':
		tmp += 2
	else:
		tmp += 1
	S_SUM.append(tmp)

T_SUM = [0]
tmp = 0
for t in T:
	if t == 'A':
		tmp += 2
	else:
		tmp += 1
	T_SUM.append(tmp)

for i in range(q):
	a,b,c,d = inpl()
	sa = (S_SUM[b]-S_SUM[a-1]) - (T_SUM[d]-T_SUM[c-1])
	if sa%3 == 0:
		print('YES')
	else:
		print('NO')


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

using namespace std;
vector<pair<int ,int> > v;
vector<int> g[100001];
int cnt[100001] , u[100001];
map<pair<int ,int> , int> mp;
signed main()
{
    int n , mx = 0, start;
    cin >> n;
    for(int i = 1; i < n; i ++)
    {
        int a , b;
        cin >> a >> b;
        cnt[a] ++;
        cnt[b] ++;
        if(cnt[a] > mx)
        {
            mx = cnt[a];
            start = a;
        }
        if(cnt[b] > mx)
        {
            mx = cnt[b];
            start = b;
        }
        v.push_back({min(a , b) , max(a , b)});
        g[a].push_back(b);
        g[b].push_back(a);
    }
    queue<int> q;
    q.push(start);
    u[start] = 1e6;
    while(!q.empty()) {
        set<int> st;
        int cur = q.front();
        st.insert(u[cur]);
        q.pop();
        int cnt = 1;
        for(auto to : g[cur]) {
            if(u[to] == 0) {
                while(st.count(cnt) == 1)
                    cnt ++;
                st.insert(cnt);
                q.push(to);
                u[to] = cnt;
                mp[{min(cur , to) , max(cur , to)}] = cnt;
            }
        }
    }
    cout << mx << endl;
    for(int i = 0; i < v.size(); i ++) {
        cout << mp[v[i]] << endl;
    }
    return 0;
}


Measured memory_bytes: 13812
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
	int n, m, acc=0, pen=0; cin>>n>>m;
	vector <bool> test(n+1);
	vector <int> arr(n+1);
	vector <int> p(m);
	vector <string> s(m);
	for (int i=0; i<m; i++)
	{
		cin>>p[i];
		cin>>s[i];
		if (test [p[i]]==false && s[i]=="AC")
		{
			test[p[i]]=true;
			acc++;
			pen+=arr[p[i]];
		}
		if (test[p[i]]==false && s[i]=="WA")
		{
			arr[p[i]]++;
		}
	}
	cout<<acc<<endl<<pen<<endl;
	return 0;
}

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

Measured memory_bytes: 20524
#include<iostream>
#define abs(x) ((x>0)?(x):(-(x)))
using namespace std;
int main(){
	int x,a,b;
	cin>>x>>a>>b;
	if(abs(x-a)<abs(x-b)){
		cout<<"A"<<endl;
	}else{
		cout<<"B"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <vector>
#include <numeric>
#include <map>

class RuntimeModInt {
    using u64 = std::uint_fast64_t;
    
    static u64 &mod() {
        static u64 mod_ = 0;
        return mod_;
    }

public:
    u64 num;
    
    RuntimeModInt(const u64 x = 0) : num(x % get_mod()) {}
    u64 &value() noexcept { return num; }
    const u64 &value() const noexcept { return num; }
    RuntimeModInt operator+(const RuntimeModInt rhs) const {
        return RuntimeModInt(*this) += rhs;
    }
    RuntimeModInt operator-(const RuntimeModInt rhs) const {
        return RuntimeModInt(*this) -= rhs;
    }
    RuntimeModInt operator*(const RuntimeModInt rhs) const {
        return RuntimeModInt(*this) *= rhs;
    }
    RuntimeModInt operator/(const RuntimeModInt rhs) const {
        return RuntimeModInt(*this) /= rhs;
    }

    RuntimeModInt &operator+=(const RuntimeModInt rhs) {
        num += rhs.num;
        if (num >= get_mod()) {
            num -= get_mod();
        }
        return *this;
    }
    RuntimeModInt &operator-=(const RuntimeModInt rhs) {
        if (num < rhs.num) {
            num += get_mod();
        }
        num -= rhs.num;
        return *this;
    }
    RuntimeModInt &operator*=(const RuntimeModInt rhs) {
        num = num * rhs.num % get_mod();
        return *this;
    }
    RuntimeModInt &operator/=(RuntimeModInt rhs) {
        u64 exp = get_mod() - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }

    RuntimeModInt &operator=(const u64 num) noexcept {
        this->num = num % get_mod();
        return *this;
    }

    RuntimeModInt pow(u64 k){
        return pow(num, k);
    }

    RuntimeModInt pow(RuntimeModInt x, u64 k) {
		if (k == 0) return 1;
		if (k % 2 == 0) return pow((x * x).num % get_mod(), k / 2);
		else return (x * pow(x, k - 1)).num % get_mod();
	}
    static void set_mod(const u64 x) { mod() = x; }
    static u64 get_mod() { return mod(); }
};

std::ostream &operator<<(std::ostream &out, const RuntimeModInt &m)
{
    out << m.num;
    return out;
}

std::istream &operator>>(std::istream &in, RuntimeModInt &m)
{
    in >> m.num;
    if(m.num >= m.get_mod()){
        m.num %= m.get_mod();
    }
    return in;
}

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    RuntimeModInt::set_mod(m);
    vector<RuntimeModInt> a(n), b(n + 1);
    for(auto&& i : a){
        cin >> i;
    }
    for(int i = 0; i < n; i++){
        b[i + 1] = b[i] + a[i];
        //cout << b[i + 1] << "\n";
    }
    map<uint_fast64_t, int> cnt;
    long long ans = 0;
    for(auto&& i : b){
        ans += cnt[i.num];
        cnt[i.num]++;
    } 
    cout << ans << "\n";
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (110)

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

void Main() {
  ll N, M; cin >> N >> M;
  vector<pair<int, int>> E(M);
  for(int i = 0; i < M; i++){
    int A, B; cin >> A >> B; A--; B--;
    E[i].first = A; E[i].second = B;
  }
  vector<pair<int, int>> V(N, make_pair(-1, 1));

  vector<ll> res(M);
  for(int i = M - 1; i >= 0; i--){
    int A = E[i].first, B = E[i].second;
    int root_A = A, root_B = B;
    while(true){
      if(V[root_A].first == -1){
        if(A != root_A) V[A].first = root_A;
        break;
      }
      root_A = V[root_A].first;
    }
    while(true){
      if(V[root_B].first == -1){
        if(B != root_B) V[B].first = root_B;
        break;
      }
      root_B = V[root_B].first;
    }
    if(root_A == root_B){
      res[i] = 0;
    }else{
      res[i] = V[root_A].second * V[root_B].second;
      V[root_A].first = root_B;
      V[root_B].second += V[root_A].second;
    }
  }
  ll sum = 0;
  for(int i = 0; i < M; i++){
    sum += res[i];
    cout << sum << endl;
  }
}

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

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 3712
#include<stdio.h>
#include<math.h>

int main(void)
{
	int w,h,n;
	int i,j,flag=0;
	int rect; // 長方形の面積
	int rect_x_right,rect_x_left,rect_y_up,rect_y_down; // 更新後の長方形の長さ
	int x[100],y[100];
	int a[100];
	
	rect_x_left = 0;
	rect_y_down = 0;
	
	scanf("%d %d %d",&w,&h,&n);
	rect_x_right = w;
	rect_y_up = h;
	
	for(i=0; i<n; i++){
		scanf("%d %d %d",&x[i],&y[i],&a[i]);
	}
	
	for(i=0; i<n; i++){
		if(a[i] == 1){
			if(x[i] < rect_x_left){
				// 更新なし
			}else{
				rect_x_left = x[i];
			}
			
			if(rect_x_left > rect_x_right) flag = 1;
		}else if(a[i] == 2){
			if(x[i] > rect_x_right){
				
			}else{
				rect_x_right = x[i];
			}
			
			if(rect_x_right < rect_x_left) flag = 1;
		}else if(a[i] == 3){
			if(y[i] < rect_y_down){
				
			}else{
				rect_y_down = y[i];
			}
			
			if(rect_y_down > rect_y_up ) flag = 1;
		}else if(a[i] == 4){
			if(y[i] > rect_y_up){
				
			}else{
				rect_y_up = y[i];
			}
			
			if(rect_y_up < rect_y_down) flag = 1;
		}
		
		// rect = (rect_x_right - rect_x_left) * (rect_y_up - rect_y_down);
		// printf("%d\n",rect);
	}
	
	
	rect = (rect_x_right - rect_x_left) * (rect_y_up - rect_y_down);
	
	if(rect < 0 || flag == 1){
		printf("0\n");
	}else{
		printf("%d\n",rect);
	}
	
	
	
	
	return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n), v(n);
  for (auto& e : h) cin >> e;
  while (m--) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    v[a] = max(v[a], h[b]);
    v[b] = max(v[b], h[a]);
  }
  int r = 0;
  for (int i = 0; i < n; i++) {
    if (h[i] > v[i]) r++;
  }
  cout << r << endl;
}


Measured memory_bytes: 4052
my ($n) = split(' ', <>);
my @a = split(' ', <>);

use List::Util qw/max min/;
use sort 'stable';
my @s = sort {$a <=> $b} @a;
my $n = $s[$#s];
my @d = sort {min($n-$b, $b) <=> min($n-$a, $a)} @s;
my $r = @d[0];

print "$n $r\n";

Measured memory_bytes: 34836
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long ll;

const int maxn = 100005;
int n, ed;
int he[maxn];
struct Edge{
	int v, nx;
	Edge(){;}
	Edge(int _v, int _nx){v = _v, nx = _nx;}
}e[maxn << 1];
inline void Add(int u, int v){
	e[++ed] = Edge(v, he[u]);he[u] = ed;
}
int Dfs(int x, int fa){
	int res = 0;
	for(int i = he[x], v;i;i = e[i].nx){
		v =e[i].v;
		if(v == fa)continue;
		res ^= (Dfs(v, x) + 1);
	}
	return res;
}
int main(){
	scanf("%d", &n);
	for(int i = 1, u, v;i < n;++i){
		scanf("%d%d", &u, &v);
		Add(u, v);Add(v, u);
	}
	puts(Dfs(1, 1) ? "Alice" : "Bob");
	return 0;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll dp[100010] = {};
    rep(i,0,N+1) dp[i] = INF;
    dp[0] = 0;
    vector<ll> v;
    ll cnt = 1;
    while(cnt <= N){
        v.push_back(cnt);
        cnt *= 6;
    }
    cnt = 9;
    while(cnt <= N){
        v.push_back(cnt);
        cnt *= 9;
    }
    rep(i,0,N+1){
        rep(j,0,v.size()){
            if(i - v[j] >= 0){
                dp[i] = min(dp[i], dp[i-v[j]] + 1);
            }
        }

    }
    print(dp[N]);
    
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main() {
	cout << fixed << setprecision(10);
	LLI n, m;
	cin >> n >> m;
	vector<LLI> a(n);
	REP(i, n)cin >> a[i];
	SORT(a);

	vector<pair<LLI, LLI>> v(m);
	REP(i, m) {
		cin >> v[i].second >> v[i].first;
		v[i].second *= -1;
	}
	RSORT(v);

	REP(i, m) {
		v[i].second *= -1;
	}

	int idx = 0;
	REP(i, m) {
		if (n <= idx)break;
		REP(j, v[i].second) {
			if (a[idx] < v[i].first) {
				a[idx] = v[i].first;
				idx++;
			}
			else {
				break;
			}
		}
	}
	LLI sum = 0;
	REP(i, n)sum += a[i];
	cout << sum;
	return 0;
}

Measured memory_bytes: 2688