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

struct dice{
    vector<int> d;
    int top;
    void set(){
        for(int i=0;i<6;i++){
            cin >> d.at(i);
        }
        return;
    }
    void roll(char c){
        if(c=='E'){
            top=d.at(0);
            d.at(0)=d.at(3);
            d.at(3)=d.at(5);
            d.at(5)=d.at(2);
            d.at(2)=top;//ここをtopにすることで配列の更新が行われるようになる
        }
        else if(c=='N'){
            top=d.at(0);
            d.at(0)=d.at(1);
            d.at(1)=d.at(5);
            d.at(5)=d.at(4);
            d.at(4)=top;
        }
        else if(c=='W'){
            top=d.at(0);
            d.at(0)=d.at(2);
            d.at(2)=d.at(5);
            d.at(5)=d.at(3);
            d.at(3)=top;
        }
        else if(c=='S'){
            top=d.at(0);
            d.at(0)=d.at(4);
            d.at(4)=d.at(5);
            d.at(5)=d.at(1);
            d.at(1)=top;
        }
        return;
    }
};

int main(){
    dice D;
    D.d={0,0,0,0,0,0};
    D.set();
    string s;
    cin >> s;
    for(int i=0;i<s.length();i++){//1回転で4面変化
        D.roll(s.at(i));
    }
   // int ans=D.d.at(0);
    cout<< D.d.at(0) << endl;//D.topにするとまずいらしい。たぶんtopには一個前の状態でのtopが入ってる
    return 0;
}





/*struct dice {
    int name;
    int eye;
};

int main() {
    vector<dice> d(6);
    for(int i = 0; i < 6; i++) {
        d.at(i).name = i+1;
        cin >> d.at(i).eye;
    }


}*/


Measured memory_bytes: 3168
N = int(input())
X = [int(i) for i in input().split()]

X_sort = sorted([[i,v] for i,v in enumerate(X)], reverse=True, key=lambda x: x[1
])
ans = [0] * N
for i in range(N):
    if i<(N//2):
        ans[X_sort[i][0]] = X_sort[N//2][1]
    else:
        ans[X_sort[i][0]] = X_sort[(N//2)-1][1]
        
for a in ans:
    print(a)


Measured memory_bytes: 45504
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rep1n(i, n) for(int i=1;i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
int main() {
	int n = 3;
	auto c = mat(int, n, n, 0);
	rep(i, n)rep(j, n)cin >> c[i][j];
	vector<int>a(n, 0), b(n, 0);
	rep(i, n)b[i] = c[0][i];
	rep1n(i, n - 1)a[i] = c[i][0] - b[0];
	bool al = true;
	rep(i, n)rep(j, n) {
		if (c[i][j] != a[i] + b[j]) {
			al = false;
			break;
		}
	}
	Yes(al);

	return 0;
}





Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){

        Scanner scan = new Scanner( System.in );

        int x = Integer.parseInt( scan.next() );
        int y = Integer.parseInt( scan.next() );

        boolean flag = false;
        for(int i=0; i<= x; i++){
            if( ( 2*i + 4*(x-i) ) == y ){
                flag = true;
                break;
            }
        }

        if(flag){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35684
import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()

    for i in range(len(S)):
        for j in range(len(S)):
            if S[:i] + S[j:] == 'keyence':
                print('YES')
                exit()
    else:
        print('NO')


if __name__ == '__main__':
    main()


Measured memory_bytes: 4060
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  int n,c;
  cin >> n >> c;
  vector<tuple<int,int,int>> inp(n);
  rep(i,n){
    int x,y,z;
    cin >> x >> y >> z;
    z--;x--;y--;
    inp.at(i) = make_tuple(z,x,y);
  }
  sort(inp.begin(),inp.end());
  vector<vector<bool>> data(c,vector<bool>(1e5,false));
  rep(i,n){
    int x,y,z;
    tie(z,x,y) = inp.at(i);
    for(int i=x;i<=y;i++){
      data.at(z).at(i) = true;
    }
  }
  int ans = 0;
  rep(i,1e5){
    int count = 0;
    rep(j,c){
      count += data.at(j).at(i);
    }
    ans = max(ans,count);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int a[55],b[55],c[55],d[55],q[15],ans=0;
int n,m,Q;
void dfs(int pos,int now){
	if(pos>n){
		//for(int i=1;i<=n;i++)
		//cout<<q[i]<<" ";
		//cout<<ans<<endl;
		int tmp=0;
		for(int i=1;i<=Q;i++){
			if(q[b[i]]-q[a[i]]==c[i]) 
			tmp+=d[i];
		}
		ans=max(tmp,ans);
		return ;
	}
	for(int i=now;i<=m;i++){
		q[pos]=i;
		dfs(pos+1,i);
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>Q;
	for(int i=1;i<=Q;i++)
	cin>>a[i]>>b[i]>>c[i]>>d[i];
	dfs(1,1);
	cout<<ans;
}

Measured memory_bytes: 3600
ans=0
num = int(input())

def div (num,n=0):
    if num<1:return n-1
    else:return div(num/10,n+1)

m=div(num)
mod = num-10**m+1
    
for i in range(m):
    if i%2==0: ans += 10**(i+1)-10**i
if m%2==0: ans+=mod

print(ans)        
    

Measured memory_bytes: 2940
# a, b = map(int,input().split())
# l = list(map(int,input().split()))

n = input()
if n[-1] == "2" or n[-1] == "4" or n[-1] == "5" or n[-1] == "7" or n[-1] == "9":
    print("hon")
elif n[-1] == "0" or n[-1] == "1" or n[-1] == "6" or n[-1] == "8":
    print("pon")
else:
    print("bon")

Measured memory_bytes: 9056
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int n,a=1,b=1,c,ans=0;
    cin >> n;
    while(1){
        while(1){
            if(n<a*b)break;
            else c = n-(a*b);
            if(((a*b)+c)==n and c!=0)ans++;
            b++;
        }
        a++;b=1;
        if(a==n)break;
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
    #define rep(i,n) for(int i = 0; i < (n); i++)
     
    using namespace std;  
   
    int main() {
     int a,b,c;
     cin >> a>>b>>c;
     
     if(a>b) swap(a,b);
     if(b>c) swap(b,c);
     if(a>b) swap(a,b);
      
     cout << a << ' '<< b << ' '<< c<< '\n';
    
     return 0;
    }


Measured memory_bytes: 3100
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<time.h>
#include<ctime>
#include<functional>
#define int long long
#define INT INT_MAX
#define LONG LLONG_MAX
#define f(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
typedef long long ll;
using namespace std;

ll GCD(ll a, ll b) {
	if (b == 0)return a;
	return GCD(b, a%b);
}

ll LCM(ll a, ll b) {
	return a / GCD(a, b)*b;
}

ll mypow(ll a, ll b, ll c) {
	if (b == 0)return 1;
	if (b % 2)return mypow(a, b - 1, c)*a%c;
	else return mypow(a, b / 2, c)*mypow(a, b / 2, c) % c;
}

signed main() {
	int a, b;
	cin >> a >> b;
	if (a >= 0 == b >= 0) {
		if (a > b) {
			if (b == 0) cout << a + 1 << endl;
			else cout << a - b + 2 << endl;
		}
		else cout << abs(a - b) << endl;
	}
	else if(b)cout << abs(abs(a)-abs(b))+1 << endl;
	else cout << abs(a) << endl;
	return 0;
}

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

int main() {
    string s;
    cin>>s;
    int l=0,r=s.size()-1;
    while (s[l]!='A')
        l++;
    while (s[r]!='Z')
        r--;
    cout<<r-l+1<<endl;
    return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define int long long

string s;
signed main() {
	cin >> s;
	string t1 = s.substr(0, 4);
	string t2 = s.substr(5, 2);
	string t3 = s.substr(8, 2);
	string t4 = t1 + t2 + t3;
	if (stoi(t4) <= 20190430) {
		cout << "Heisei" << endl;
	}
	else {
		cout << "TBD" << endl;
	}

}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

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

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

ll extended_factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
        ans %= (ll)(1e9+7);
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

char alphabet[] = {
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
};

// 二分探索
// llrep(i,N){
//     b = B[i];
//     auto cntA = lower_bound(A.begin(), A.end(), b);//イテレータなのでそのままllに変換とかはできない
//     auto cntC = upper_bound(C.begin(), C.end(), b);
//     ll cntA_ll = distance(A.begin(), cntA);
//     ll cntC_ll = C.size() - distance(C.begin(), cntC);
//     cnt += (cntA_ll * cntC_ll);
// }


bool visited[52];
int N,M,a,b;
bool edge[52][52];


void dfs(int v){
    visited[v] = true;
    Rep(i,N){
        if (edge[v][i] && !visited[i]){
            dfs(i);
        }
    }
}

int main(){
    cin >> N >> M;
    vector<int> A;
    vector<int> B;

    rep(i,52){
        rep(j,52){
            edge[i][j]=false;
        }
    }
    rep(i,M){
        cin >> a >> b;
        edge[a][b]=true;
        edge[b][a]=true;
        A.push_back(a);
        B.push_back(b);
    }
    //全てのMについて、切ってみても連結を保てるか見る
    int ans=0;
    rep(i,M){
        a = A[i];
        b = B[i];
        edge[a][b] = edge[b][a] = false;
        //1ノードから全てのノードにアクセスできるか試す。
        rep(i,52) visited[i] = false;
        dfs(1);
        bool bridge = false;
        Rep(i,N){
            if (!visited[i]) bridge = true;
        }
        if (bridge) ans ++;
        edge[a][b] = edge[b][a] = true;
    }

    cout << ans << endl;


    return 0;
}


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

from functools import reduce

SUM = reduce(lambda x,y: abs(x) + abs(y) , A)

cntMinu = 0
for a in A:
    if a < 0 : cntMinu += 1

if cntMinu % 2 == 0:
    print(SUM)
    exit()

minAbs = 10**9 + 1
for a in A:
    if minAbs > abs(a): minAbs = abs(a)

print(SUM - 2 * minAbs )




Measured memory_bytes: 64752
# include <iostream>
# include <cstdio>
# include <cstring>

using namespace std;

long long c[10][10];

int main(void)
{
    long long N;
    scanf("%lld",&N);
    memset(c,0,sizeof(c));
    for (int i=1;i<=9;i++)
    for (int j=1;j<=9;j++)
    {

        if (i==j&&i<=N) c[i][j]++;
        long long tmp = 10;
        while (i*tmp+j<=N)
        {
        if (i==N/tmp)
        {
            c[i][j]+=N%tmp/10+1;
            if (j>N%10) c[i][j]--;
        }else
        c[i][j]+=tmp/10;     
        tmp*=10;
        }
    }
    long long ans = 0;
    for (int i=1;i<=9;i++)
    for (int j=1;j<=9;j++)
    ans+=c[i][j]*c[j][i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

ll n, m, l, q;
VVP G;
VVL ans;
constexpr ll INF = 1e15;
typedef tuple<ll,ll,ll> nakiri; // cnt, dist, idx

void dijkstra(vector<vector<pair<ll,ll>>> G, vector<ll> &cnt, vector<ll> &d, ll srt){
    priority_queue<nakiri, vector<nakiri>, greater<nakiri>> que;
    que.push({0, 0, srt});
    d[srt] = 0;
    cnt[srt] = 0;
    while(!que.empty()){
        auto q = que.top();
        que.pop();
        auto cur_cnt = get<0>(q);
        auto cur_d = get<1>(q);
        auto cur_id = get<2>(q);
        if(cur_cnt > cnt[cur_id]) continue;
        if(cur_cnt == cnt[cur_id] && cur_d > d[cur_id]) continue;
        for(auto g : G[cur_id]){
            if(g.second > l) continue;
            ll next_d = cur_d + g.second;
            ll next_cnt = cur_cnt;
            if(next_d > l) {
                next_d = g.second;
                next_cnt++;
            } 
            if(cnt[g.first] < next_cnt) continue;
            if(cnt[g.first] == next_cnt && d[g.first] <= next_d) continue;
            cnt[g.first] = next_cnt;
            d[g.first] = next_d;
            que.push({cnt[g.first], d[g.first], g.first});
        }
    }
}

int main(){

    // input
    cin >> n >> m >> l;
    G.resize(n);
    rep(i, 0, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        G[a].push_back({b, c});
        G[b].push_back({a, c});
    }
    
    // dijkstra from all nodes
    ans.resize(n, VL(n));
    rep(i, 0, n) {
        VL cnt(n, INF), d(n, INF);
        dijkstra(G, cnt, d, i);
        rep(j, 0, n) ans[i][j] = cnt[j];
    }

    // query
    cin >> q;
    rep(i, 0, q){
        ll s, t;
        cin >> s >> t;
        s--; t--;
        cout << (ans[s][t] >= INF ? -1 : ans[s][t]) << endl;
    }

    return 0;
}

Measured memory_bytes: 9260
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define zero(x) (fabs(x)<eps)
#define pi acos(-1.0)
#define f1 first
#define f2 second
#define CLR(x,y) memset(x,y,sizeof(x))
using namespace std;
typedef long long LL;
typedef pair <int, int> PII;
template<typename X> inline bool minimize(X&p,X q){if(p<=q)return 0;p=q;return 1;}
template<typename X> inline bool maximize(X&p,X q){if(p>=q)return 0;p=q;return 1;}
#define fr(i,x,y) for(int i=x;i<=y;i++)
#define ms(x,y) memset(x,y,sizeof(x))
int n,k;
int a[5005];
int c[5005];
bool dp[5005][5005];
bool g[5005][5005];
int lowbit(int x)
{
    return x&(-x);
}
void add(int i)
{
    while(i<k)
    {
        c[i]+=1;
        i+=lowbit(i);
    }
}
int sum(int i)
{
    int s=0;
    while(i>0)
    {
        s+=c[i];
        i-=lowbit(i);
    }
    return s;
}
void doit()
{
    scanf("%d%d",&n,&k);
    int yy=0;
    fr(i,1,n)
    {
        scanf("%d",&a[i]);
        if (a[i]<k) yy=1;
    }
    if (n==1)
    {
        printf("%d\n",yy);
        return;
    }

    fr(i,1,n)fr(j,i+1,n)
            if (a[i]>a[j])
            {
                yy=a[i];
                a[i]=a[j];
                a[j]=yy;
            }

    fr(i,1,n)
    if (a[i]>=k) {n=i-1;break;}

    ms(dp,0);dp[0][0]=1;
    fr(i,1,n)
    {
        fr(j,0,k) dp[i][j]=dp[i-1][j];
        for(int j=k-a[i];j>=0;j--)
            if (dp[i][j]) dp[i][j+a[i]]=1;
    }
    ms(g,0); g[n+1][0]=1;
    for(int i=n;i>=1;i--)
    {
        fr(j,0,k) g[i][j]=g[i+1][j];
        for(int j=k-a[i];j>=0;j--)
            if (g[i][j]) g[i][j+a[i]]=1;
    }

    int ans=0,xx,zz;
    fr(i,1,n)
    {
        /*
        fr(j,1,k)
            printf("~%d %d\n",j,dp[i-1][j]);
        fr(j,1,k)
            printf("!%d %d\n",j,g[i+1][j]);
*/
        ms(c,0);
        fr(j,1,k)if (g[i+1][j]) add(j);
        yy=0;
        fr(j,0,k-1)if (dp[i-1][j]){
                xx=k-a[i]-j;
                if (xx<=0&&0<=k-1-j)   {yy=1;break;}

                zz=sum(k-1-j)-sum(xx-1);
                if (zz>0){yy=1;break;}

            }
        ans+=yy;
        //printf("~~~~~~~~~~~%d\n",ans); printf("\n");

    }
    printf("%d\n",n-ans);
}
int main() {

    //while (1)
    {
        doit();
    }

    return 0;
}

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

int H, W;
string A[100];

bool check() {
  for (int i = 0; i < H; i++) {
    bool ok = true;
    for (int j = 0; j < W; j++) {
      if (A[i][j] == '#') {
        ok = false;
      }
    }
    if (ok) {
      for (int k = i; k < H-1; k++) {
        swap(A[k],A[k+1]);
      }
      H--;
      return true;
    }
  }
  for (int j = 0; j < W; j++) {
    bool ok = true;
    for (int i = 0; i < H; i++) {
      if (A[i][j] == '#') {
        ok = false;
      }
    }
    if (ok) {
      for (int k = 0; k < H; k++) {
        A[k] = A[k].substr(0,j)+A[k].substr(j+1);
      }
      W--;
      return true;
    }
  }
  return false;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> A[i];
  }
  while (check());
  for (int i = 0; i < H; i++) {
    cout << A[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.IO;
using System.Text;
using N = System.Int64;

static class Program
{
    static public void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        var solver = new Solver();
        solver.Solve();
        Console.Out.Flush();
    }
}

public class Solver
{
    public void Solve()
    {
        N n = rn;
        N d1 = 0, d2 = 0;
        N t = 0;
        for(int i = 0; i < n; i++)
        {
            d1 = rn; d2 = rn;
            if (d1 == d2)
            {
                t++;
                if (t >= 3) { Write("Yes");return; }
            }
            else { t = 0; }
        }
        Write("No");
    }

    N Gcd(params N[] n) { N p = n[0]; for (N i = 1; i < n.Length; i++) { p = Gcd(p, n[i]); } return p; }
    N Gcd(N a, N b) { return (a == 0) ? b : Gcd(b % a, a); }

    N rn { get { return sc.Integer(); } }
    double rd { get { return sc.Double(); } }
    string rs { get { return sc.Scan(); } }
    public StreamScanner sc = new StreamScanner(Console.OpenStandardInput());

    void Write<T>(T t) { Console.WriteLine(t.ToString()); }
    void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); }
    void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); }
    void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); }
}



public class StreamScanner
{
    public StreamScanner(Stream stream) { str = stream; }
    private readonly Stream str;
    private readonly byte[] buf = new byte[1024];
    private int len, ptr;
    public bool isEof = false;
    public bool IsEndOfStream { get { return isEof; } }
    private byte read()
    {
        if (isEof) throw new EndOfStreamException();
        if (ptr >= len)
        {
            ptr = 0;
            if ((len = str.Read(buf, 0, 1024)) <= 0)
            {
                isEof = true;
                return 0;
            }
        }
        return buf[ptr++];
    }
    public char Char()
    {
        byte b = 0;
        do b = read();
        while (b < 33 || 126 < b);
        return (char)b;
    }
    public string Scan()
    {
        var sb = new StringBuilder();
        for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
            sb.Append(b);
        return sb.ToString();
    }
    public N Integer()
    {
        N ret = 0; byte b = 0; var ng = false;
        do b = read();
        while (b != '-' && (b < '0' || '9' < b));
        if (b == '-') { ng = true; b = read(); }
        for (; true; b = read())
        {
            if (b < '0' || '9' < b)
                return ng ? -ret : ret;
            else ret = ret * 10 + b - '0';
        }
    }
    public double Double() { return double.Parse(Scan()); }
}


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

ll f(ll h)
{
  if (h == 1)
  {
    return h;
  }
  return 2 * f(h / 2) + 1;
}

int main()
{
  ll h;
  cin >> h;
  cout << f(h) << endl;
}


Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

typedef long long ll;
using namespace std;
static const int MAX = 100000;

typedef pair<ll, ll> P;
vector<ll> A;
ll N, M;
vector<P> V;

int main() {

    cin >> N >> M;
    ll a;
    for (int i = 0; i < N; i++) {
        cin >> a;
        A.push_back(a);
    }
    int b, c;
    for (int i = 0; i < M; i++) {
        cin >> b >> c;
        V.push_back(make_pair(c, b));
    }
    sort(A.begin(), A.end());
    sort(V.begin(), V.end(), greater<P>());

    /*
    for (int i = 0; i < N; i++) {
        cout << A[i] << ' ';
    }
    cout << '\n';
    for (int i = 0; i < M; i++) {
        cout << V[i].second << ' '  <<V[i].first << '\n';
    }
    */

    int j = 0;
    for (int i = 0; i < N; i++) {
        if (j >= M) break;
        if (A[i] > V[j].first) continue;
        if (V[j].first > 0) {
            A[i] = V[j].first;
            V[j].second--;
            if (V[j].second == 0) 
                j++;
        }
    }
    ll ans = 0;
     for (int i = 0; i < N; i++) {
        ans += A[i];
    }
     /*
    cout << '\n';
    for (int i = 0; i < M; i++) {
        cout << V[i].second << ' '  <<V[i].first << '\n';
    }
    */

   
    cout << ans << '\n';
    
}


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

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

	int bin[3][3];
	int N;
	for(int i=0; i<3; i++){
		for(int j=0; j<3; j++){
			cin >> bin[i][j];
		}
	}

	map<int,bool> mp;
	cin >> N;
	for(int i=1; i<=N; i++){
		int x;
		cin >> x;
		mp[x] = true;
	}

	bool ok = false;
	for(int i=0; i<3; i++){
		if(mp[bin[i][0]]&&mp[bin[i][1]]&&mp[bin[i][2]]) ok = true;
		if(mp[bin[0][i]]&&mp[bin[1][i]]&&mp[bin[2][i]]) ok = true;
	}

	if(mp[bin[0][0]]&&mp[bin[1][1]]&&mp[bin[2][2]]) ok = true;
	if(mp[bin[0][2]]&&mp[bin[1][1]]&&mp[bin[2][0]]) ok = true;

	cout << (ok ? "Yes\n" : "No\n");


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
 
typedef tree<pair<long long,int>, null_type, less<pair<long long,int>>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
 
#define f first
#define se second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pi pair<int, int>
#define all(num) num.begin(), num.end()
#define lp(i, nodess) for (int i = 0; i < nodess; i++)
#define mem(u, vis) memset(u, vis, sizeof(u))
#define X real()
#define Y imag()
#define angle(u) (atan2(u.Y, u.X))
#define vec(u, v) ((v) - (u))
//#define length(u) (hypot(u.Y , u.X))
#define normalize(u) (u) / length(u)
#define dotP(u, v) ((conj(u) * v).X)
#define crossP(u, v) ((conj(u) * v).Y)
#define same(p1, p2) (dotP(vec(p1, p2), vec(p1, p2)) < EPS)
#define lengthSqr(u) dotP(u, u)
#define rotate0(p, ang) ((p)*exp(point(0, ang)))
#define rotateA(p, ang, about) (rotate0(vec(about, p), ang) + about)
#define reflect0(vis, m) conj(vis / m) * m
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const double PI = acos(-1.0);
const double EPS = (1e-10);
const long long int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
typedef long long int ll;
typedef unsigned long long ull;
typedef complex<double> point;
long long fastpow(ll nodess, ll num, ll m) {
  if (!num)
    return 1;
  if (num % 2)
    return nodess * fastpow(nodess, num - 1, m)%m;
  ll p = fastpow(nodess, num / 2, m);
  p %= m;
  p *= p;
  p %= m;
  return p;
}
 
ll my_mod(ll num, ll mod) {
  ll reto = num % mod;
  while (reto < 0)
    reto += mod;
  return reto;
}
 
ll gcd(ll u, ll v) { return !u ? v : gcd(v % u, u); }
/*long long dist(pair<ll, ll> u, pair<ll, ll> v) {
  return 
      abs(u.f - v.f)  + abs(u.se - v.se);
}*/
long long getDist(pair<ll, ll> &u, pair<ll, ll> &v) {
  return 
     (u.f - v.f)*(u.f - v.f)  + (u.se - v.se)*(u.se-v.se);
}
 
 
 
/*vector<int> ap;
int np[MX+5];
void s(){
    mem(np , 1);
    np[1] = np[0] = 0;
    for(ll i = 2 ; i*i<= MX ;i++){
        if(np[i]){
            for(ll j= i*i ; j <=MX; j+=i) np[j] = 0;
        }
    }
    int idx = 1;
    for(ll i = 2 ; i<= MX ; i++){
		if(np[i]){
			np[i] = idx;
			idx++; 
			ap.pb(i);
		}
	}
	//cout<<idx;
}*/

#define int ll
const int MX = 1e3 +9;

int32_t main(){
    IO;
	string s;
	cin>>s;
	deque<char> dq;
	for(char c: s) dq.push_back(c);
	int q;
	cin>>q;
	int norm = 1;
	while(q--){
		int t;
		cin>>t;
		if(t == 1) norm*=-1;
		else{
			int f;
			char c;
			cin>>f>>c;
			if(f == 1){
				if(norm == 1) dq.push_front(c);
				else dq.push_back(c);
			}else{
				if(norm == -1) dq.push_front(c);
				else dq.push_back(c);
			}
		}
	}
	string ans = "";
	for(char c : dq) ans += string(1,c);
	if(norm == 1) cout<<ans;
	else{
		reverse(all(ans));
		cout<<ans;
	}
    return 0;
}


Measured memory_bytes: 1368
#include<bits/stdc++.h>
using namespace std;
vector <tuple <string, int, int>> S;
int main() {
    int N;
    string s;
    int t;
    cin >> N;
    for(int i=0; i<N; ++i) {
        cin >> s >> t;
        S.emplace_back(s, -t, i);
    }
    sort(S.begin(), S.end());
    for(auto x: S)
        cout << get<2>(x)+1 << endl;
    return 0;
}

Measured memory_bytes: 256
k = int(input())

if k in [2, 5, 10] == 0:
    print(-1)
    exit()

n_map = {}
current = 7 % k
cnt = 1
while True:
    if current == 0:
        print(cnt)
        exit()
    if current in n_map:
        print(-1)
        exit()
    else:
        n_map[current] = True
    cnt += 1

    current = 10 % k * current + 7
    current %= k


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

c = 0

for i in range(6):
    if N >= 10 ** i:
        if i % 2 == 1:
            c += 9 * (10 ** (i - 1))
    else:
        if i % 2 == 1:
            c += N - (10 ** (i - 1)) + 1
        break

print(c)



Measured memory_bytes: 2940
#include <bits/stdc++.h>
    using namespace std;
     
    #define endl "\n"
    #define long long long
     
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        cout.tie(nullptr);
        
        long int l,r;
        cin>>l>>r;
     
        long int ans = LONG_MAX;
     
        for(long int i = l; i <= r-1; i++){
            unordered_set<long int> remainders;
            for(long int j = i+1; j <= r; j++){
                if(remainders.find((i*j) % 2019) == remainders.end()){
                    ans = min(ans,(i*j) % 2019);
                    if(ans == 0)
                        goto a;
                    remainders.insert((i*j) % 2019);
                }
                else
                    break;
            }
        }
     
        a : cout<<ans;
        return 0;
    }

Measured memory_bytes: 384
//author: Harsh :)
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define maxN 100007
using namespace std;
int main(){
  fastio;
  ll a=0,b=0,c=0;
  cin>>a>>b>>c;
  if((a==b and c!=a) or (a==c and b!=a) or (b==c and a!=c)) cout<<"Yes";
  else cout<<"No";
  return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>

int main( void ) {

	int n, i, a, b, c;

	scanf( "%d", &n );

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

		scanf( "%d %d %d", &a, &b, &c );

		if ( a * a + b * b == c * c || b * b + c * c == a * a || c * c + a * a == b * b ) {

			printf( "YES\n" );

		} else {

			printf( "NO\n" );

		}

	}

	return 0;

}

Measured memory_bytes: 580
main = do
  s <- getLine
  putStrLn $ unwords [j |j <- (cut [[]] s),length j >= 3, length j <= 6]

cut :: [String] -> String -> [String]
cut l [] = l
cut l (' ':xs) = cut (l ++ [[]]) xs
cut l (',':xs) = cut (l ++ [[]]) xs
cut l ('.':xs) = cut (l ++ [[]]) xs
cut l (x:xs) = cut (append l x) xs

append :: [String] -> Char -> [String]
append l c  = init l ++ ((last l ++ (c:[])):[])

Measured memory_bytes: 5604
fun main(args: Array<String>) {
    val n = readInt()
    val a = readLongList()
    val m = 1000000007

    var sum = 0L
    var ans = 0L
    for (i in 0 until n) {
        ans = (ans + a[i] % m * sum) % m
        sum = (sum + a[i] % m) % m
    }
    println(ans)
}

// read
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 65340
using namespace std;
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#define w(x) int x;cin>>x;while(x--)
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define MOD 1e9+7
#define ll long long

void abc()
{
	FIO;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}








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

	cout << max({a * c, a * d, b * c, b * d});







}










Measured memory_bytes: 3688
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	a, b, c := oneInt(), oneInt(), oneInt()

	if a < b {
		if a <= c && b >= c {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	} else {
		if b <= c && a >= c {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

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

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}

func cumSum(nums []int) []int {
	sums := []int{0}

	for i := 0; i < len(nums); i++ {
		sums = append(sums, sums[i]+nums[i])
	}
	return sums
}


Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60


int main() {
    string S;
    cin >> S;
    int l = S.length();

    vector<ll> n(26);
    REP(i, l) n[S[i] - 'a']++;

    ll ans = 1;
    REP(i, 26) REP(j, 26) if(i < j) ans += n[i] * n[j];

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

Measured memory_bytes: 640
i,a[1<<17],b[1<<17];c;
main(s){
	for(;~(c=getchar_unlocked());)c-10?a[i]=a[i]*10+c-48:++i;
	for(b[i=s]=1;!b[s=a[s]]++&&s-2;++i);
	printf("%d",s-2?-1:i);
}

Measured memory_bytes: 896
# coding: utf-8
# Your code here!

n=int(input())
abc=[[int(i) for i in input().split()] for _ in range(n)]

dp = [[0]*3 for _ in range(n+1)]
dp[1] = abc[0]

for i in range(2,n+1):
    for j in range(3):
        dp[i][j] = max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3])+ abc[i-1][j]

print(max(dp[n]))

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

int main()
{
    int n;
    cin >> n;
    ll d = 1e9 + 7;
    ll p = 1;
    for (ll i = 1; i <= n; i++)
    {
        p *= i;
        p %= d;
    }
    cout << p << endl;
    return 0;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;
//stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
//小数点の表し方 cout << fixed << setprecision(5);

int main(){
    string s,t;
    cin >> s >> t;
    int n = s.size();
    vector<int> as(n),at(n);
    map<char,int> ms,mt;
    ms[s[0]] = 1;
    mt[t[0]] = 1;
    as[0] = 1;
    at[0] = 1;
    for(int i=0;i<n;i++){
        if(ms[s[i]] == 0){
            ms[s[i]] = ms.size();
            as[i] = ms[s[i]];
        }else{
            as[i] = ms[s[i]];
        }
    }
    for(int i=0;i<n;i++){
        if(mt[t[i]] == 0){
            mt[t[i]] = mt.size();
            at[i] = mt[t[i]];
        }else{
            at[i] = mt[t[i]];
        }
    }
    /*
    for(int i=0;i<n;i++){
        cout << as[i] << endl;
    }
    */
   for(int i=0;i<n;i++){
       if(at[i] != as[i]){
           cout << "No" << endl;
           return 0;
       }
   }
   cout << "Yes" << endl;
}

Measured memory_bytes: 2312
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

x,y = map(int,input().split())
a = set([1,3,5,7,8,10,12])
b = set([4,6,9,11])
c = set([2])
if (x in a and y in a) or (x in b and y in b) or(x in c and y in c):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3316
def solve():
    n = int(input())
    S = [int(s) for s in input().split(' ') if s]
    q = int(input())
    T = [int(s) for s in input().split(' ') if s]
    ret = 0
    for t in T:
        if t in S:
            ret += 1

    print(ret)
    
solve()


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B < C + D){
    cout << "Right" << endl;
  }
  else if (A + B == C + D){
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
d1 = defaultdict(int)
d2 = defaultdict(int)
for i,a in enumerate(A):
    d1[i+a] += 1
    d2[i-a] += 1
ans = 0
for k,v in d1.items():
    ans += v*d2[k]
print(ans)


Measured memory_bytes: 74048
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	a := nextInt()
	b := nextInt()
	if a == b {
		fmt.Println(a + a)
	} else {
		fmt.Println(max(a, b) + max(a, b) - 1)
	}
}

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

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

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}


template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};




int main(){

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

    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];

    int cnt = 0;
    rep(i, n){
        int love = a[i]-1;
        if(i == a[love]-1){
            ++cnt;
        }
    }

    ppp(cnt/2);
    return 0;



}


Measured memory_bytes: 640
#include <bits/stdc++.h> // imports every library in c++
using namespace std; // ; is essential | says that you are USING the libraries

//  COMMAND TO USE WHEN RUNNING CODE: g++ day7.cpp -o day7 -std=c++11 -O2  | to run: ./(name of file)  //

stack<char> S;
stack<char> n2;
string s;

int main() {
    cin >> s;
    for (int i=0; i<s.length(); i++) {
        if (s[i] == '0' || s[i] == '1') {
            S.push(s[i]);
        } else {
            if (S.empty() == 0) {
                S.pop();
            }
        }
    }
    while (S.empty() == 0) {
        n2.push(S.top());
        S.pop();
    }
    while (n2.empty() == 0) {
        cout << n2.top();
        n2.pop();
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 256
import sys

A, B, C, K = map(int, input().split())

S = 0

if A >= K:
    S = S + K * 1
    K = 0
    print(S)
    sys.exit()
else:
    S = S + A * 1
    K = K - A

if B >= K:
    K = 0
    print(S)
    sys.exit()
else:
    K = K - B

if C >= K:
    S = S + K * (-1)
    K = 0
    print(S)
    sys.exit()
else:
    S = S + C * 1
    print(S)

Measured memory_bytes: 9216
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans[ohara],b,c,d,tmp,tmpp,m,h,w,x[ohara],y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
map<pair<ll,ll>,ll> mp;
map<ll,ll> cou;
map<ll,ll> couu;
pair<ll,ll> p[ohara];

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>n;
    rep(i,n)cin>>x[i],p[i]=make_pair(x[i],i);
    sort(p,p+n);
    rep(i,n)ans[x[i]]=i+1;
    
    rep(i,n){
        tmp=p[i].second;
        ll le,ri;
        le=tmp;
        ri=n-tmp-1;
        ll cntt=0;
        rrep(j,1,n*n){
            if(cntt==le)break;
            if(ans[j]==0)ans[j]=tmp+1,cntt++;
        }
        /*
        cntt=0;
        rrrep(j,n*n,1){
            if(cntt==ri)break;
            if(ans[j]==0)ans[j]=tmp+1,cntt++;
        }
        */
    }
    reverse(p,p+n);

    rep(i,n){
        tmp=p[i].second;
        ll le,ri;
        le=tmp;
        ri=n-tmp-1;
        ll cntt=0;
        /*
        rrep(j,1,n*n){
            if(cntt==le)break;
            if(ans[j]==0)ans[j]=tmp+1,cntt++;
        }
        */
        
        cntt=0;
        rrrep(j,n*n,1){
            if(cntt==ri)break;
            if(ans[j]==0)ans[j]=tmp+1,cntt++;
        }
    }
    

    rrep(i,1,n*n+1){
        cou[ans[i]]++;
        mp[{ans[i],cou[ans[i]]}]=i;
    }
    rep(i,n){
        if(mp[{i+1,i+1}]!=x[i]){
            Cout("No");
            return 0;
        }
    }

    rrep(i,1,n*n+1){
        if(ans[i]==0){
            Cout("No");
            return 0;
        }
    }

    rrep(i,1,n*n+1){
        couu[ans[i]]++;
    }
    rrep(i,1,n+1){
        if(couu[i]!=n){
            Cout("No");
            return 0;
        }
    }
    
    
    Cout("Yes");
    rrep(i,1,n*n+1){
        if(i==n*n)Cout(ans[i]);
        else cout<<ans[i]<<" ";
    }
    
    return 0;
}


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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define fore(i,a) for (auto &i : a)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int mod = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = LLONG_MAX / 2;
const static double eps = 1e-10;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

template<typename T> vector<T> slide_max(const vector<T> &V, int width) {
    deque<T> deq;
    vector<T> ret;

    for(int i = 0; i < V.size(); i++) {
        while(!deq.empty() && V[deq.back()] <= V[i]) {
            deq.pop_back();
        }

        deq.push_back(i);
        ret.emplace_back(deq.front());

        if(i - width + 1 >= 0) {
            if(deq.front() == i - width + 1) deq.pop_front();
        }
    }
    
    return ret;
}

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, M, K;
    cin >> N >> M >> K;
    vector<llong> A(N);
    rep(i, N) cin >> A[i];

    vector<llong> pre_dp(N);
    rep(i, N) pre_dp[i] = A[i];

    for (int k = 2; k <= K; ++k) {
        vector<llong> next_dp(N, 0);

        vector<llong> smax = slide_max<llong>(pre_dp, M);

        for (int i = k - 1; i < N; ++i) {
            next_dp[i] = max(next_dp[i], pre_dp[smax[i - 1]] + k * A[i]);
        }

        pre_dp.swap(next_dp);
    }

    llong ans = -1;
    rep(i, pre_dp.size()) {
        ans = max(ans, pre_dp[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4468
#include<stdio.h>
int main(void)
{
	int a,b,c,s,i;
	s=1;
	while(scanf("%d %d",&a,&b)!=EOF){
		 c=a+b;
		 s=1;
		 i=10;
		 while(c>=10){	
               s=s+1;
			   c=c/10;
		 }
		 printf("%d\n",s);
	}
	return 0;
}


Measured memory_bytes: 2040
from functools import reduce
m, d = map(int, input().split())
count = 0
for i in range(4, max((4, m+1))):
  for j in range(22, max((22, d+1))):
    if j < 22:
      continue
    dd = str(j)
    if '1' in dd:
      continue
    if i == reduce(lambda x, y: int(x) * int(y), dd):
      count += 1
print(count)


Measured memory_bytes: 3572
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

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

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(1, 1E8); \
                 auto rnd = bind(__dis, __gen)

const int INF = 1E18;
const int mod = 1E9 + 7;

int32_t main() {
    fastIO();
    
    int a, b, k;
    cin >> a >> b >> k;
    
    set<int> nums;
    for (int i = 0; i < k; ++i) nums.insert(a + i), nums.insert(b - i);
    
    for (auto x : nums) {
        if (a <= x and x <= b) cout << x << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)n; i++)
int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  cout << A+B+C - max(max(A,B),C) << endl;
}


Measured memory_bytes: 256