akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

int main(){
  ll n,m;
  ll p;
  ll wa=0,ac=0;
  string s;
  cin>>n;
  vector<int> was(n,0);
  cin>>m;
  for(int i=0;i<m;i++){
    cin>>p;
    cin>>s;
    if(was[p]<0){
      continue;
    }
    if(s=="AC"){
      wa+=was[p];
      was[p]=-1;
      ac++;
    }else{
      was[p]++;
    }
  }
  cout<<ac<<" "<<wa<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

string nisin(ll n) {
    string res;
    while (n) {
        if (n & 1) res = "1" + res;
        else res = "0" + res;
        n /= 2;
    }
    return res;
}

int main() {
    ll l, r;
    cin >> l >> r;
    string s = nisin(l), t = nisin(r);
    while(s.size() < t.size()) s = "0" + s;
    while(t.size() < s.size()) t = "0" + t;
    int n = s.size();
    auto dp = make_v(n+1, 2, 2, 2, 2, 0LL);
    dp[0][0][0][0][0] = 1; // dp[cur][l < x][y < r][x < y][zero]
    for (int i = 0; i < n; ++i) {
        for (int a = 0; a < 2; ++a) {
            for (int b = 0; b < 2; ++b) {
                for (int c = 0; c < 2; ++c) {
                    for (int d = 0; d < 2; ++d) {
                        int p = a ? 0 : s[i]-'0';
                        int q = b ? 1 : t[i]-'0';
                        for (int e = p; e <= q; ++e) {
                            for (int f = e; f <= q; ++f) {
                                if(!d && (e ^ f)) continue;
                                (dp[i+1][a || p < e][b || f < q][c || e < f][d || e] += dp[i][a][b][c][d]) %= MOD;
                            }
                        }
                    }
                }
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 2; ++j) {
            for (int k = 0; k < 2; ++k) {
                for (int m = 0; m < 2; ++m) {
                    ans += dp[n][i][j][k][m];
                }
            }
        }
    }
    cout << ans%MOD << "\n";
    return 0;
}

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

set<int> s;

int main()
{
	int n;
	cin >> n;
	int t;
	for(int i = 0; i < n; i++) {
		cin >> t;
		s.insert(t);
	}
	set<int>::iterator it;
	while(s.size() > 1) {
		it = s.end();
		it--;
		int t = *it, t2 = *(--it); it++;
//		cout << t << " " << t2 << " " << s.size() << endl;
		s.erase(it);
		if(t % t2 != 0)
			s.insert(t%t2);
		
	}
	it = s.begin();
	cout << *it << endl;	
}

Measured memory_bytes: 4992
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define All(obj) (obj).begin(),(obj).end()

using namespace std;


int main() {
	speed;
	int a, b;
	cin >> a >> b;
	if (a%b != 0)cout << 1;
	else { cout << 0; }
	return 0;
}


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

void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}
//using namespace std;
int main() {
  	int h,w,k;
  	std::cin>>h>>w>>k;
  	int color[7][7]={};
  	for(int ih=0;ih<h;ih++){
		std::string str;
        std::cin>>str;
      	for(int iw=0;iw<w;iw++){
            if(str.substr(iw,1)=="."){
              	color[ih+1][iw+1]=0;
            }else{
              	color[ih+1][iw+1]=1;
            //std::cout<<"("<<ih<<","<<iw<<") ";
            }
        }
    }
  	//std::cout<<std::endl<<std::endl;
  	int answer=0;
  	
  	for(int nh=0;nh<h;nh++){
      	for(int nw=0;nw<w;nw++){
		  	foreach_comb(h, nh, [&](int *indexes_h) {
		  		foreach_comb(w, nw, [&](int *indexes_w) {
                  	int nBlack = 0;
    				for(int ih=1;ih<=h;ih++){
    					for(int iw=1;iw<=w;iw++){
                          	if(color[ih][iw]==0) continue;
                          	bool isRed = false;
                          	for(int paintH=0;paintH<nh;paintH++){
                              	if(ih==indexes_h[paintH]+1){
                                  	isRed=true;
                                  	break;
                                }
                            }
                          	if(!isRed){
                          		for(int paintW=0;paintW<nw;paintW++){
                              		if(iw==indexes_w[paintW]+1){
                                  		isRed=true;
                                  		break;
                                	}
                                }	
                            }
                       		if(!isRed){
                              	nBlack++;
                        		//std::cout<<"("<<ih<<","<<iw<<") ";
                            }
                        }
                    }
                  	if(nBlack==k) answer++;
                  	//std::cout<<std::endl;
  				});
  			});
        }
    }
  	
  	std::cout<<answer<<std::endl;
  	return 0;
}

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

using namespace std;

int main(int argc, char* argv[]) {
  int N;
  cin >> N;

  vector<int> p(N);
  for (int i = 0; i < N; ++i)
    cin >> p[i];

  int ret = 0;
  for (int i = 0; i < N; ++i) {
    if (p[i] == i + 1) {
      ++ret;
      if (i < N - 1 && p[i + 1] == i + 2)
        ++i;
    }
  }

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 640
#include <queue>
#include <vector>
#include <iostream>
using namespace std;
const long long inf = 1LL << 62;
const long long snuke = 1000000000000000;
struct edge {
	int to, cost;
	edge() : to(-1), cost(0) {};
	edge(int to_, int cost_) : to(to_), cost(cost_) {};
};
struct state {
	int pos; long long cost;
	state() : pos(-1), cost(0) {};
	state(int pos_, long long cost_) : pos(pos_), cost(cost_) {};
};
bool operator<(const state& s1, const state& s2) {
	return s1.cost > s2.cost;
}
vector<long long> shortest_path(int src, vector<vector<edge> > &G) {
	priority_queue<state> que; que.push(state(src, 0));
	vector<long long> dist(G.size(), inf);
	dist[src] = 0;
	while (!que.empty()) {
		state u = que.top(); que.pop();
		for (edge e : G[u.pos]) {
			if (dist[e.to] > dist[u.pos] + e.cost) {
				dist[e.to] = dist[u.pos] + e.cost;
				que.push(state(e.to, dist[e.to]));
			}
		}
	}
	return dist;
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, M, S, T, U, V, A, B;
	cin >> N >> M >> S >> T; --S, --T;
	vector<vector<edge> > G1(N), G2(N);
	for (int i = 0; i < M; ++i) {
		cin >> U >> V >> A >> B; --U, --V;
		G1[U].push_back(edge(V, A));
		G1[V].push_back(edge(U, A));
		G2[U].push_back(edge(V, B));
		G2[V].push_back(edge(U, B));
	}
	vector<long long> d1 = shortest_path(S, G1);
	vector<long long> d2 = shortest_path(T, G2);
	vector<long long> ans(N);
	long long cur = 0;
	for (int i = N - 1; i >= 0; --i) {
		cur = max(cur, snuke - d1[i] - d2[i]);
		ans[i] = cur;
	}
	for (int i = 0; i < N; ++i) {
		cout << ans[i] << '\n';
	}
	return 0;
}

Measured memory_bytes: 16120
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;

// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;
int nums[100001];
vector<int> graph[100001];
pair<int, int> ahead[100001];
int full[100001];
int marked = 0;
bool imp = false;
vector<pair<int, int> > edges;
pair<int, int> dfs(int node, int par){
    if (imp){
        return {-1, -1};
    }
    
    int maxl = -1000000000;
    int minr = 1000000000;
    for (int i : graph[node]){
        if (i == par){
            continue;
        }
        edges.emplace_back(node, i);
        pair<int, int> p = dfs(i, node);
        maxl = max(maxl, p.first);
        minr = min(minr, p.second);
        if (node == 3){
            //cout << p.first << " " << p.second<< endl;
        }
    }
    
    if (nums[node] != -1){
        ahead[node] = {nums[node], nums[node]};
        return {nums[node]-1, nums[node]+1};
    }
    if (graph[node].size() == 1){
        ahead[node] = {-1000000000, 1000000000};
        return {-1000000000, 1000000000};
    }
   
    ahead[node] = {maxl, minr};
    return {maxl-1, minr+1};
}
int res[100001];
bool inrange(int l, int r, int num){
    if (num < l || num > r){
        return false;
    }
    return true;
}
bool bad = false;
void mark(int node, int par, int last){
    int l = ahead[node].first;
    int r = ahead[node].second;
    if (inrange(l, r, last+1)){
        res[node] = last+1;
    }else if (inrange(l, r, last-1)){
        res[node] = last-1;
    }else{
        bad = true;
        return;
    }
    for (int j : graph[node]){
        if (j == par){
            continue;
        }
        mark(j, node, res[node]);
    }
}
int main ()
{
  prep();
  int n;
  cin >> n;
  
  for (int i=0; i<n-1; i++){
      int a, b;
      cin >> a >> b;
      graph[a].push_back(b);
      graph[b].push_back(a);
  }
  int k;
  cin >> k;
  memset(nums, -1, sizeof(int)*(n+1));
  
  for (int i=0; i<k; i++){
      int v, m;
      cin >> v >> m;
      nums[v] = m;
      marked = v;
  }
  dfs(marked, -1);

  for (int i=1; i<=n; i++){
      if (ahead[i].first > ahead[i].second){
          cout << "No";
          return 0;
      }
      //cout << ahead[i].first << " " << ahead[i].second << endl;
  }
  
  
  mark(marked, -1, nums[marked]-1);
  if (bad){
      cout << "No";
      return 0;
  }
  cout << "Yes\n";
  for (int i=1; i<=n; i++){
      cout << res[i] << '\n';
  }
  return 0; 
}


Measured memory_bytes: 16756
'use strict';
var Main = function(stdin) {
  var line = stdin.split('\n');
  var result = (function(data) {
  	return data.sort(function(a,b){
  		return a - b;
  	})
  	.join(' ');
  }(
  	line[0].split(' ').map(Number)
  ));
  console.log(result);
};

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7644
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse4")

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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);
const ld EPS = 1e-6;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
const char nl = '\n';

template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> void ckmin(T& a, T b) { a = min(a, b); }
template <class T> void ckmax(T& a, T b) { a = max(a, b); }

// (Integer/Long).bitCount(x)
int pct(int x) { return __builtin_popcount(x); }
int pctll(ll x) { return __builtin_popcountll(x); }

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
void setIO(string s = "") {
	unsyncIO();
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); }
}

// Binary Exponentiation
ll pow(ll b, ll e, ll m = 0LL, ll ans = 1LL) { while (e) { if (e & 1LL) { ans *= b; if (m) ans %= m; } b *= b, e >>= 1LL; if (m) b %= m; } return ans; }



void solve(int tcn) {
	int n;
	cin >> n;
	ll s1 = 0LL, s2 = 0LL;
	F0R(i, n) {
		ll a;
		cin >> a;
		s1 += a, s2 += a * a;
		s1 %= MOD, s2 %= MOD;
	}
	ll ans = (s1 * s1 % MOD - s2 + MOD) * ((MOD + 1LL) / 2LL) % MOD;
	cout << ans << nl;
}

int main() {
    setIO();

    int t = 1; //cin >> t;
	for (int i = 1; i <= t; ++i) {
		//cout << "Case #" << i << ": ";
		solve(i);
	}
	return 0;
}

Measured memory_bytes: 3648
using System;
namespace std
{
	class Program
	{
		static void Main(string[] args) 
		{
            var input = Console.ReadLine ().Split (' ');
            var a = int.Parse (input[0]);
            var b = int.Parse (input[1]);
	
        	if (a < b) {
	            Console.WriteLine("a < b");
	        }
	        else if(a > b) {
	            Console.WriteLine("a > b");
	        }
	        else {
                Console.WriteLine("a == b");
    
	        }
		}
	}
}


Measured memory_bytes: 15952
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ASSERT(C, ...) assert( (C) || (PRINT(__VA_ARGS__), false) )
template <class Head> void PRINT(Head head) {
    std::cout << head << "\n";
}
template <class Head, class... Tail> void PRINT(Head head, Tail... tail) {
    std::cout << head << " ";
    PRINT(tail...);
}

ll solve() {
    ll N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    int a, b;
    for ( int i = 0; i < M; i++ ) {
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
    }

    auto check_atomic = [&](vector<int>& vs) {
        ASSERT(vs.size() > 1, "");
        unordered_set<int> s;
        for ( int v : vs ) s.insert(v);
        for ( int v : vs ) {
            int c = 0;
            for ( int u : G[v] ) {
                if ( s.find(u) != s.end() ) c++;
            }
            if ( c > 1 ) return false;
        }
        return true;
    };

    vector<int> depth(N, -1);
    vector<int> ix, tr(N,-1), ans;
    function<void(int, int)> dfs = [&](int v, int d) {
        if ( depth[v] != -1 ) {
            if ( tr[v] != -1 ) {
                vector<int> tmp;
                for ( int i = tr[v]; i < d; i++ ) tmp.push_back(ix[i]);
                if ( check_atomic(tmp) ) {
                    ans = tmp;
                }
            }
            return;
        }
        depth[v] = d;
        tr[v] = d;
        for ( auto x : G[v] ) {
            ix.push_back(x);
            dfs(x, d+1);
            if ( !ans.empty() ) return;
            ix.pop_back();
        }
        tr[v] = -1;
    };
    
    for ( int i = 0; i < N; i++ ) {
        if ( depth[i] != -1 ) continue;
        ix.push_back(i);
        dfs(i, 0);
        if ( !ans.empty() ) break;
        ix.pop_back();
    }

    if ( ans.empty() ) {
        cout << -1 << "\n";
        return 0;
    }
    cout << ans.size() << "\n";
    for ( int i = 0; i < ans.size(); i++ ) {
        cout << ans[i] + 1 << "\n";
    }
    return 0;
}

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

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
 
 
int main()
{
    int n,i,x;
    scanf("%d %d",&n,&x);
    long long ans=0,sum,a,b;
    scanf("%lld",&a); //第一个 盒子中的糖果个数
    if(a>x)   // x 是最后每个盒子要剩余的个数，  如果第一个盒子的糖果个数a大于x
    {
       ans+=a-x;  //  ans 是多出的个数
       a=x; 
    }
 
    for( i=1; i<n; i++) //剩下的 n-1 个盒子
    {
        scanf("%lld",&b);  
        sum=a+b;
        if(sum>x)
        {
            ans+=sum-x;
            a=b-sum+x;   
        }
        else a=b;       
    }                   
    printf("%lld",ans); // 
    return 0;
}

Measured memory_bytes: 128
package main

import (
        "fmt"
)

func solution(n int, a []int) int {
        var out int = 1

        for _, num := range a {
                if num == 0 {
                        return 0
                }
        }
        for _, num := range a {
                out *= num
                if out > 1e18 || out < num {
                        return -1
                }
        }
        return out
}

func main() {
        var n int
        fmt.Scan(&n)
        a := make([]int, 0, n)
        for i := 0; i < n; i++ {
                var t int
                fmt.Scan(&t)
                a = append(a, t)
        }
        fmt.Println(solution(n, a))
}

Measured memory_bytes: 6316
n = int(input())
a = input().split()
for i in range(len(a)):
    a[i]=int(a[i])
# print(a)
a.sort()
# print(a)
# #両端をとっておく
hashi1 = a[0]
hashi2 = a[-1]
a.remove(a[0])
a.remove(a[-1])
# print(a)
minus_list = []
plus_list = []
printlist = []
for i in range(len(a)):
    if a[i]>0:
        plus_list.append(a[i])
    else:
        minus_list.append(a[i])
# print(minus_list)
# print(plus_list)
for j in range(len(minus_list)):
    printlist.append(hashi2)
    printlist.append(minus_list[j])
    hashi2 = hashi2-minus_list[j]
    
for l in range(len(plus_list)):
    printlist.append(hashi1)
    printlist.append(plus_list[l])
    hashi1 = hashi1 - plus_list[l]
    
printlist.append(hashi2)
printlist.append(hashi1)
print(hashi2-hashi1)
# print(printlist)
for n in range(0,len(printlist),2):
    print(printlist[n],printlist[n+1])

Measured memory_bytes: 15180
S = input()
cnt = [0]*2019
cnt[0] = 1
n = 0
t = 1
for i in reversed(S):
    n += int(i)*t
    n %= 2019
    cnt[n] += 1
    t *= 10
    t %= 2019
print(sum(i*(i-1)//2 for i in cnt))

Measured memory_bytes: 68568
#include <iostream>
using namespace std;
int main()
{
    string s;
    cin >> s;
    while(s.size()!=19)
        cin >> s;
    for (int i = 0; i < 19; i++)
    {
        if (s[5] == ','&& s[13] == ',')
        {
            s[5] = ' ';
            s[13] = ' ';
        }
    }
   cout << s<<"\n";
    return 0;
}


Measured memory_bytes: 256
bool debug=false;
#include <stdio.h>
#include <math.h>
double myabs(double x){return x>0?x:-x;}
double min(double a,double b){return a>b?b:a;}
int main(){
	double l,mid,r,ntheta,dis,x,y,ori,theta,speed,runner,sniper;
	scanf("%lf%lf%lf%lf",&x,&y,&theta,&speed);
	dis=sqrt(x*x+y*y);
	if(y==0)ori=0;
	else ori=atan(myabs(y/x))/acos(-1)*180;
	if(x<0)ori=180-ori;
	if(y<0)ori=360-ori;
	if(debug)printf("ori=%lf\n",ori);
	theta=myabs(ori-theta);
	theta=min(360-theta,theta);
	if(debug)printf("%lf\n",theta);
	l=0,r=dis;
	for(int i=0;i<100;i++){
		mid=(l+r)/2;
		runner=sqrt(dis*dis-mid*mid)/(mid*speed/180*acos(-1));
		ntheta=acos(mid/dis)/acos(-1)*180;
		sniper=(ntheta+theta)/speed;
		if(debug)printf("l=%lf r=%lf runner=%lf sniper=%lf ntheta=%lf\n",l,r,runner,sniper,ntheta);
		if(runner<sniper)r=mid;
		else l=mid;
	}
	printf("%.20lf\n",r*speed/180*acos(-1));
}


Measured memory_bytes: 2980
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;
string yes = "Yes";
string no = "No";

int  main()
{
	int a,b,x; cin >> x >> a >> b;
	x-=a;
	x -= x/b * b;
	cout << x << endl;
	return (0);
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <bitset>
#include <vector>
using namespace std;

#define LL long long

#define fi first
#define se second
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(a,b) (((a)+(b))>>1)
#define maxx(a,b) ((a)<(b)?(b):(a))
#define minx(a,b) ((a)<(b)?(a):(b))
#define absx(a) ((a)<0?-(a):(a))
#define mk(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define itr iterator
#define lowbit(x) ((x)&-(x))

typedef unsigned LL ULL;
typedef unsigned uint;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;

template< typename T > inline void read(T &x) {
    bool f; char ch; f=0; x=0; ch=getchar();
    while(ch<'0' || ch>'9') {if(ch=='-') f=1; ch=getchar();}
    while(ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    if(f) x=-x;
}

template< typename T > inline void Max(T &a, T b) {if(a<b) a=b;}
template< typename T > inline void Min(T &a, T b) {if(b<a) a=b;}
template< typename T > inline T Abs(T a) {if(a<0) return -a; else return a;}

const double pi=(double) acos(-1.0);
const int MOD=(int) 1e9+7;
const int INF=(int) 0x3f3f3f3f;
const LL  LINF=(LL) INF<<32|INF;
const int SINF=(uint) ~0>>1;
const LL  SLINF=(ULL) (-1)>>1;
const double DINF=(double) 1e50;
const double eps=(double) 1e-8;
const int maxn=(int) 1e5+20;
const int maxm=(int) 1e5+20;
const int maxk=(int) 5e2+20;

inline int sig(double x) {return x<-eps?-1:x>eps;}

//--------------start------------------

int n;
int a[maxn],b[maxn],c[maxn];

void work()
{
    read(n);
    for(int i=0;i<n;i++) read(a[i]);
    for(int i=0;i<n;i++) read(b[i]);
    for(int i=0;i<n;i++) read(c[i]);

    sort(a,a+n);
    sort(b,b+n);
    sort(c,c+n);

    LL ans=0;
    for(int i=0;i<n;i++)
    {
        int p=b[i];

        int x=0, y=0;

        int l, r, mid;

        l=0, r=n-1;
        while(l<=r)
        {
            mid=MID(l,r);
            if(a[mid]<p)
            {
                x=mid+1;
                l=mid+1;
            }
            else
            {
                r=mid-1;
            }
        }

        l=0, r=n-1;
        while(l<=r)
        {
            mid=MID(l,r);
            if(c[mid]>p)
            {
                y=n-mid;
                r=mid-1;
            }
            else
            {
                l=mid+1;
            }
        }
        ans+=(LL) x*y;
    }

    cout <<ans <<endl;
}

//--------------end--------------------

int main()
{
#ifdef yukihana0416
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif // yukihana0416
    work();
    return 0;
}


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

#define WHITE 0
#define GRAY 1
static const int MAXV = 10000, MAXE = 100000;
int V, E;
vector<int> G[MAXV];
list<int> ans;
int col[MAXV];
int indeg[MAXV];

void bfs(int s) {
	queue<int> Q;
	Q.push(s);
	col[s] = GRAY;
	while (!Q.empty()) {
		int u = Q.front();
		Q.pop();
		ans.push_back(u);
		for (int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			indeg[v]--;
			if (indeg[v] == 0 && col[v] == WHITE) {
				Q.push(v);
				col[v] = GRAY;
			}
		}
	}
}

void topologicalsort() {
	for (int u = 0; u < V; u++) {
		if (indeg[u] == 0 && col[u] == WHITE) {
			bfs(u);
		}
	}
}

int main() {
	cin >> V >> E;
	for (int i = 0; i < V; i++) {
		col[i] = WHITE;
		indeg[i] = 0;
	}
	for (int i = 0; i < E; i++) {
		int s, t;
		cin >> s >> t;
		G[s].push_back(t);
		indeg[t]++;
	}
	topologicalsort();
	for (int i = 0; i < V; i++) {
		cout << ans.front() << endl;
		ans.pop_front();
	}
	return 0;
}



Measured memory_bytes: 4104
from collections import defaultdict


def main():
    N, M = list(map(int, input().split(' ')))
    pref = defaultdict(list)
    for c in range(M):
        p, y = list(map(int, input().split(' ')))
        p -= 1
        pref[p].append((c, y))
    nums = ['' for _ in range(M)]
    for p in range(N):
        pref[p].sort(key=lambda a: a[1])
        for x, city in enumerate(pref[p]):
            nums[city[0]] = '{:06}{:06}'.format(p + 1, x + 1)
    for n in nums:
        print(n)


if __name__ == '__main__':
    main()

Measured memory_bytes: 51040
#include <iostream>
#include<algorithm>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a;
    c=0;
    int S[a];
    for(int i=0;i<a;i++){
        cin>>S[i];
    }
    sort(S,S+a);
    b=S[a-1];
    for(int i=0;i<a-1;i++){
        c=c+S[i];
    }
    if(b<c){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    
    
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define vi vector<int>

using ll = long long;
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const ll DIV =1e9+7;
//const double PI = M_PI;
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
inline ll inv(ll x, ll div){return pow(x, div - 2, div);}
#define chmax(a,b) a=max(a,b)

/*Coding Space*/
int main(){
  ll n; cin >> n;
  ll sum = 0;
  ll m = LLINF;
  rep(i,n){
    ll in; cin >> in;
    sum += in;
    m = min(m, in);
  }
  if(n % 2 == 0 && m % 2 == 0 && sum % 2 == 0){
    cout << "Second" << endl;
  }

  if(n % 2 == 0 && m % 2 == 1 && sum % 2 == 1)
    cout << "First" << endl;
  if(n % 2 == 0 && m % 2 == 0 && sum % 2 == 1)
    cout << "First" << endl;
  if(n % 2 == 0 && m % 2 == 1 && sum % 2 == 0)
    cout << "First" << endl;
  if(n % 2 == 1 && m % 2 == 1 && sum % 2 == 1)
    cout << "First" << endl;
  if(n % 2 == 1 && m % 2 == 0 && sum % 2 == 0)
    cout << "Second" << endl;
  if(n % 2 == 1 && m % 2 == 0 && sum % 2 == 1)
    cout << "First" << endl;
  if(n % 2 == 1 && m % 2 == 1 && sum % 2 == 0)
    cout << "Second" << endl;
}



Measured memory_bytes: 3112
from collections import deque

h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
visited = [[-1] * w for _ in range(h)]
move = [(1,0), (0,1), (-1,0), (0,-1)]

sy, sx= 0, 0
gy, gx = h-1, w-1

queue = deque([(sy, sx, 0)])

while queue:
    y, x, dist = queue.popleft()
    for dy, dx in move:
        if maze[y+dy:y+dy+1] and maze[y+dy][x+dx:x+dx+1]:
            if maze[y+dy][x+dx] == "." and visited[y+dy][x+dx] == -1:
                visited[y+dy][x+dx] = dist + 1
                queue.append((y+dy, x+dx, dist+1))
shortest_distance = visited[gy][gx]

if shortest_distance == -1:
    print("-1")
else:
    white_count = 0
    for row in maze:
        for cell in row:
            if cell == ".":
                white_count += 1

    score = white_count - 1 - shortest_distance
    print(score)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
LL A[300001];
vector<LL>v;
int main(){
	cin>>N;
	REP(i,3*N){
	    cin>>A[i];
	    v.push_back(A[i]);
	}
	sort(v.begin(),v.end());
	LL ans=0;
	REP(i,N){
	    ans+=v[3*N-2-i*2];
	}
        cout<<ans<<endl;
	return(0);
}

Measured memory_bytes: 8432
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
   string s;
   cin >> s;
   int ans = INT_MAX;
   for(int i = 0; i+2 < s.size(); i++) {
        ans = min(ans, abs(753 - stoi(s.substr(i, 3))));
   }
   cout << ans << endl;
}





Measured memory_bytes: 256
let inp = readLine()!.split(separator: " ").map { Int($0)! }

let n = inp[0]
let m = inp[1]

let mod = 1000000007

var banned = Set<Int>()

for _ in 0..<m {
  let a = Int(readLine()!)!
  banned.insert(a)
}

var dp: [Int] = .init(repeating: 0, count: n + 1)

dp[0] = 1
for i in 1...n {
  if banned.contains(i) {
    continue
  }
  dp[i] = dp[i-1] + (i - 2 < 0 ? 0 : dp[i-2])
  dp[i] %= mod
}
print(dp[n] % mod)

Measured memory_bytes: 11320
using System;

class V {

   public int edge;
   public int[] a;
   public int d;
   public int f;
    
   public V(int k) {
       edge = k;
       a = new int[edge];
   }
}

class B11{
   public static void Main() {

       int n = int.Parse(Console.ReadLine());
       int time = 0;

       V[] ver = new V[n + 1];

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

           string[] num = Console.ReadLine().Split();
           int u = int.Parse(num[0]);
           int k = int.Parse(num[1]);
           ver[u] = new V(k);

           for(int j = 0; j < k; j++) {
               ver[u].a[j] = int .Parse(num[2 + j]);
           }
       }

       for(int i = 1; i <= n; i++) {
           if(ver[i].d == 0) {
               DFS(ver, i, ref time);
           }
       }

       for(int i = 1; i <= n; i++) {
           Console.WriteLine(i + " " + ver[i].d + " " + ver[i].f);
       }

   }

   static void DFS(V[] ver, int u, ref int time) {

       if(ver[u].d == 0) {

           ver[u].d = ++time;

           if(ver[u].edge != 0) {

               for(int i = 0; i < ver[u].edge; i++) {
                   if(ver[ver[u].a[i]].d == 0) {
                       DFS(ver, ver[u].a[i], ref time);
                   }
               }

           }
       }

       if(ver[u].f == 0) {
           ver[u].f = ++time;
       }

   }

}


Measured memory_bytes: 15932
#include <stdio.h>
#include <stdlib.h>

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main(void) {
    int n, count = 0;
    scanf("%d", &n);
    int l[n];
    for(int i = 0; i < n; i++) scanf("%d", &l[i]);
    qsort(l, sizeof(l)/sizeof(int), sizeof(int), asc);
    for(int i = 0; i < n-2; i++) {
        for(int j = i+1; j < n-1; j++) {
            for(int k = j+1; k < n; k++) {
                if(l[k] < l[i] + l[j]) count++;
            }
        }
    }
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 128
"use strict";

const gcd = (a, b) => {
    if (b > a)
        return gcd(b, a);
    if (b === 0)
        return a;
    return gcd(b, (a % b));
}

const main = (input) => {
    const spi = input.split('\n');
    const k = Number(spi[0]);

    let ans = 0;
    for (let a = 1; a <= k; a++) {
        for (let b = 1; b <= k; b++) {
            let x = gcd(a, b);
            for (let c = 1; c <= k; c++) {
                ans += gcd(x, c);
            }
        }
    }

    console.log(ans);
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 32380
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int n,m,v,p;
    cin>>n>>m>>v>>p;
    p--;
    vector<int>a(n);
    REP(i,n) cin >> a[i];
    sort(a.rbegin(),a.rend());
    //show(a);
    int l=-1,r=n;
    int x;
    while(l+1<r){
         x=(l+r)/2;
        if(x<=p){
            l=x;
            continue;
        }
        int sum=0;
       if(a[x]+m >=a[p]){
           for (int i = 0; i < n; i++)
           {
               if(i<p) sum+=m;
               if(p<=i && i<x) sum+=m - (a[i] - a[x]);
               if(i==x) sum+=m;
               if(i > x) sum+=m; 
           }
           if(sum<m*v) r=x;
           else l=x;
       }
       else{
           r=x;
       }
      // cerr<<x<<" "<<sum<<endl; 

    }
    cout<<r<<endl;

    
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n;
  cin>>n;
  map<int,int> mp;
  int a,b;
  REP(i,n){
    cin>>a;
    mp[a]++;
  }
  
  a=b=0;
  for(auto p:mp){
    if(p.second>=2){
      REP(i,p.second/2){
        if(a<p.first){
          a = p.first;
          if(a>b){
            swap(a,b);
          }
        }
      }
    }
  }
  long long ans;
  ans = (long long)a*b;
  cout<<ans<<endl;
  return 0;
}

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

long long int MOD = 1000000007;

long long int modpow(long long int a, long long int n) {
  long long int res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

int main() {
  long long int N;
  cin >> N;
  long long int ans = modpow((long long int)10, N);
  ans = (ans - 2 * modpow((long long int)9, N) % MOD) % MOD;
  ans = (ans + modpow((long long int)8, N)) % MOD;
  if (ans < 0) ans += MOD;
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int A,B,C,K; cin>>A>>B>>C>>K;
	int ret=min(A,K);
	K-=min(A,K);
	K-=min(B,K);
	ret-=K;
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
	long long s;
	cin >> s;
	int ans = 1000;
	while(s>=100){
		int x = s%1000;
		ans = min(ans, abs(753-x));
		s /= 10;
	}
	cout << ans << endl;
}

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

int main(){
  int n,loop;
  cin >> n;
  char c,mxchar;
  vector<int> vot(26);
  int mx,sc,tie;
  while(n){
    vot.assign(26,0);
    mx=0;
    sc=0;
    tie=1;
    for(loop=0;loop<n;loop++){
      cin >> c;
      vot[c-65]++;
      if(vot[c-65]>mx){
        mx=vot[c-65];
        mxchar=c;
      }else if(vot[c-65]>sc){
        sc=vot[c-65];
      }
      if(mx-sc>n-loop-1){
        cout << mxchar << " " << loop+1 << endl;
        tie=0;
        for(loop++;loop<n;loop++){
          cin >> c;
        }
        break;
      }
    }
    if(tie){
      cout << "TIE" << endl;
    }
    cin >> n;
  }
  return 0;
}


Measured memory_bytes: 3072
K = int(input())

import functools

def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
def gcd(nums):
    return functools.reduce(euclid, nums)

def solution(K):
    ans = 0
    for i in range(1,K+1):
        for j in range(1,K+1):
            for k in range(1,K+1):
                num = (i,j,k)
                ans += gcd(num)
    print(ans)

solution(K)


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

#define int long long int
#define mp make_pair
using namespace std;

int dp[100002];
vector<int> v(100002);
int n,k;

int fun(int pos)
{
    if(pos > n-1){
        return 10000000000000;
    }
    if(dp[pos] != -1){
        return dp[pos];
    }
    dp[pos] = 0;
    int c = 10000000000000;
    for (int i = 1; i <= k; ++i) {
        c = min(c , abs(v[pos] - v[pos + i]) + fun(pos + i));
    }
    dp[pos] = c;
    return dp[pos];
}

int32_t main() {
    scanf("%lld", &n);
    scanf("%lld", &k);
    for (int i = 0; i < n; ++i) {
        scanf("%lld", &v[i]);
    }
    for (int i = 0; i < n; ++i) {
        dp[i] = -1;
    }
    dp[n-1] = 0;
    dp[n-2] = abs(v[n-1] - v[n-2]);
    int ans = fun(0);
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
int main(){
	char s[10];
	int ans = 0;
	scanf("%s",&s);
	for(int i = 0;i < strlen(s);i++){
		if(s[i] == '+'){
			ans++;
		}
		else if(s[i] == '-'){
			ans--;
		}
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 998244353 //1000000007 // //100000000
#define INF 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll dx[4] = {0, 0, 1, -1};
ll dy[4] = {1, -1, 0, 0};

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}


void solve(){
    ll a[5];
    rep(i, 5) cin >> a[i];
    ll ans = 0, k = 0;
    rep(i, 5){
        if(a[i] % 10 ==0 ) ans +=a[i];
        else{
            k = max(k, 10-a[i]%10);
            while(a[i]%10) a[i]++;
            ans += a[i];
        }
    }
    cout << ans - k ;
}
main(){
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 256
a, b, c, x, y = map(int, input().split())
if a + b <= 2 * c:
    print(a * x + b * y)
else:
    m = min(x, y)
    ans = 2 * c * m
    if x != m:
        if a > 2 * c:
            ans += 2 * c * (x - m)
        else:
            ans += a * (x - m)
    else:
        if b > 2 * c:
            ans += 2 * c * (y - m)
        else:
            ans += b * (y -m)
    print(ans)

Measured memory_bytes: 3064
module Main where
import Debug.Trace
import Data.List
import Data.Char
import Data.Array
import Data.Maybe
import Data.Ord
import Control.Monad

solve :: String -> String -> Bool
solve s t = search (s ++ s) where
    search [] = False
    search ss 
        | take lenT ss == t = True
        | otherwise = search (tail ss)
    lenT = length t
                
main :: IO() 
main = do
    l <- getLine
    p <- getLine
    putStrLn $ if solve l p then "Yes" else "No"



Measured memory_bytes: 3580
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

#define Max 110
#define y second
#define x first

pair<int, int> red[Max];
pair<int, int> blu[Max];
int a[Max];
int b[Max];
int c[Max];
int d[Max];
int N;

int main(int argc, const char * argv[]) {
    N = inputValue();
    rep(i, N) {
        a[i] = inputValue();
        b[i] = inputValue();
        red[i] = make_pair(a[i], b[i]);
    }
    rep(i, N) {
        c[i] = inputValue();
        d[i] = inputValue();
        blu[i] = make_pair(c[i], d[i]);
    }

    sort(blu, blu+N, [](auto& a, auto& b) {return a.first < b.first;});

    int ans = 0;
    int large = 1000000;
    rep(k, N) {
        int maxr = -1;
        int maximum = -large;
        rep(r, N) {
            if (red[r].x >= blu[k].x || red[r].y >= blu[k].y) continue;
            if (red[r].y >= 0 && red[r].y > maximum) {
                maxr = r;
                maximum = red[r].y;
            }
        }
        if (maxr < 0) continue;
        // printf("%d %d %d %d\n", blu[k].x, blu[k].y, red[maxr].x, red[maxr].y);
        red[maxr] = make_pair(-1, -1);
        ans += 1;
    }

    output(ans);

    return 0;
}

Measured memory_bytes: 888
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.PriorityQueue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class Main {
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}

class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {

numChars = stream.read(buf);

} catch (IOException e) {

throw new InputMismatchException();

}

if (numChars <= 0)

return -1;

}

return buf[curChar++];

}
public int readInt() {

int c = read();

while (isSpaceChar(c))

c = read();

int sgn = 1;

if (c == '-') {

sgn = -1;

c = read();

}

int res = 0;

do {

if (c < '0' || c > '9')

throw new InputMismatchException();

res *= 10;

res += c - '0';

c = read();

} while (!isSpaceChar(c));

return res * sgn;

}


public long readLong() {

int c = read();

while (isSpaceChar(c))

c = read();

int sgn = 1;

if (c == '-') {

sgn = -1;

c = read();

}
long res = 0;
do {

if (c < '0' || c > '9')

throw new InputMismatchException();

res *= 10;

res += c - '0';

c = read();

} while (!isSpaceChar(c));

return res * sgn;

}
public String readString() {

int c = read();

while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {

res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {

if (filter != null)

return filter.isSpaceChar(c);

return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object...objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object...objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}}
InputReader in= new InputReader(System.in);
OutputWriter out = new OutputWriter(System.out);
StringTokenizer tok;
public static void main(String[] args) throws IOException
{
   new Main().run();
}

void run() throws IOException
{  
   solve();
   out.flush();
   tok=null;
}


void solve()  throws IOException{
	int n=in.readInt();
	out.printLine((1000- (n % 1000))%1000);
	
	
	
}

}

Measured memory_bytes: 32508
/*Practice hard*/
#include <bits/stdc++.h>
using namespace std;


//_______MACROS_______//
#define   fast  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define   int   long long int
#define   pb    push_back
#define   f     first
#define   s     second

signed main()
{
    fast ;
    int n;
	cin >> n;
    string str , temp ;
    cin >> str ;
    temp = str.substr(0,n);
    if (str.size() > n)
    {
        temp += "...";
    }
    cout << temp << endl;
	return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll INF = 1LL<<60;
/////////////////////////////////
template<class T> inline bool chmin(T &a,T b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}

ll dp[110][100010];

int N;
ll weight, w[110], v[110];

int main(){
    cin >> N >> weight;
    rep(i, N) cin >> w[i] >> v[i];
    rep(i, 110) rep(j, 100010) dp[i][j] = INF;

    dp[0][0] = 0;
    for (int i = 0; i < N;i++){
        for (int j = 0; j <= N * 1000;j++){
            if(j-v[i]>=0){
                chmin(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
            }
            chmin(dp[i + 1][j], dp[i][j]);
        }
    }
    ll ans = 0;
    rep(i, 100010) if (dp[N][i] <= weight) ans = i;
    cout << ans << endl;
}

Measured memory_bytes: 89560
n=int(input())
a=[0]*n
for i in range(n):
    a[i]=int(input())
flag=[False]*n

ans=1
button=1
#flag[button-1]=True
#button=a[button-1]
for i in range(n):
    if a[button-1]==2:
        break
    if flag[button-1]==False:
        ans+=1
        flag[button-1]=True
        button=a[button-1]
    else:
        ans=-1
print(ans)

Measured memory_bytes: 7796