akhauriyash/Code-Regression huggingface dataset:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = list(map(lambda x: x - 1, A)) # 0-indexed

pos = 0
memo = [[False, 0] for _ in range(N)] # memo[i]: [bool, tel_cnt] , [数えたか、何回移動したか]
memo[0] = [True, 0]
distance = 0
l_pos = 0
tel_cnt = 0
while True:
    next = A[pos]
    tel_cnt += 1
    if memo[next][0]: # 数えた
        r_pos, l_pos = memo[pos][1], memo[next][1]
        distance = r_pos - l_pos
        break
    memo[next][1] = tel_cnt
    memo[next][0] = True
    # index 更新
    pos = next

def find_idx_by_telcnt(tel_cnt):
    for i in range(N):
        m = memo[i]
        if m[1] == tel_cnt:
            return i

if K <= l_pos:
    print(find_idx_by_telcnt(K) + 1)
else:
    diff = K - l_pos
    rem = diff % (distance + 1)
    ans_pos = l_pos + rem
    print(find_idx_by_telcnt(ans_pos) + 1)


Measured memory_bytes: 40076
#include <iostream>
using namespace std;
int a[100];

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = n - 1; i > 0; i--) {
        cout << a[i] << " ";
    }
    cout << a[0] << endl;
    return 0;
}

Measured memory_bytes: 3080
// C++ program to find LCM of two numbers
#include <iostream>
using namespace std;
// Recursive function to return gcd of a and b
class gfg
{
    public : unsigned long long gcd(unsigned long long a, unsigned long long b){
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }


    // Function to return LCM of two numbers
    unsigned long long lcm(unsigned long long a, unsigned long long b)
    {
        return (a*b)/gcd(a, b);
    }
};
// Driver program to test above function
int main()
{
	gfg g;

	unsigned long long a,b,c,d;
	cin>>a>>b>>c>>d;

    unsigned long long cm=g.lcm(c,d);
    //cout<<cm<<endl;


    long long numbers=(b-a)+1;
    a--;
    unsigned long long res=(b/c)-(a/c);
    res+=(b/d)-(a/d);

    //cout<<"Res = "<<res<<endl;

    res-=(b/cm)-(a/cm);
    //cout<<"Final res = "<<res<<endl;

    cout<<numbers-res<<endl;


}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include  "bits/stdc++.h"
using namespace std;
#define I_AM_SPEED  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define printclock  cerr <<"Time : "<<(double)clock()/(double)CLOCKS_PER_SEC<<" sec\n";
#define mp(a , b)   make_pair(a , b)
#define eb(a)       emplace_back(a)
#define SZ(n)       ((int)(n).size())
#define all(n)      (n).begin(), (n).end()
#define anal           '\n'
#define mod         1000000007
#define fst         first
#define sec         second
#define pr(n)       cerr << n  << " ";
#define pfor(a)       for(auto (w) : (a)) pr(w)
//const double PI = acos(-1.0);
typedef long long ll;
typedef unsigned long long ull;

//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-



//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
int main(){
I_AM_SPEED;
#ifndef ONLINE_JUDGE  
        freopen("input.in", "r", stdin);
        freopen("output.in", "w", stdout);
#endif 
//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
     
         int ans = 0, cnt = 0;
         for(int i = 1; i <= 3; i++){
              char ch;
              cin >> ch;
              if(ch == 'R') cnt++;
              else cnt = 0;
              ans = max(cnt, ans);
         }
         cout << ans << anal;
     
//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
//printclock; 
return  0 ;      
}        



      

Measured memory_bytes: 3588
#include<stdio.h>
int main(){
  int W,H,x,y,r;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
  if (x - r >= 0 && y - r >= 0 && x + r <= W && y + r <= H) printf("Yes\n");
  else printf("No\n");
}


Measured memory_bytes: 2704
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define st first
#define nd second
#define pii pair<int,bool>
#define mp make_pair

using namespace std;

int a[111][2];
int n;

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

    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i][0]>>a[i][1];
    }

    for(int i=1;i<=n-2;i++)
    {
        int cnt = 0;
        for(int j=i;j<=i+2;j++)
        {
            if(a[j][0] == a[j][1]) cnt++;
        }
        if(cnt == 3)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n; cin >> n;
    long long ar[n+5] = {};
    for(int i = 1; i <= n; i++)
    {
        cin >> ar[i];
    }
    long long sum = 0;
    for(int i = 2; i <= n; i++)
    {
        if(ar[i] < ar[i-1])
        {
            sum += abs(ar[i-1]-ar[i]);
            ar[i] += abs(ar[i]-ar[i-1]);
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 5152
#include <iostream>
using namespace std;
int main(void){
    int n, a[100] = {0}; //100個
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    cout << a[n-1];
    for(int i = 1; i < n; i++){
        int j = (n-1) - i;
         
        cout << " " << a[j];
    }
    cout << endl;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int N,T;
  cin>>N>>T;
  vector<int>t(N);
  for(int i=0;i<N;i++)cin>>t[i];
  ll memo=0;
  ll ans=0;
  for(int i=0;i<N;i++){
    if(t[i]<=memo){
      ans+=T-(memo-t[i]);
    }
    else{
      ans+=T;
    }
    memo=t[i]+T;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int main() {
  int N;
  cin >> N;
  vector<int> xs(N), ls(N);
  vector<P> ps(N);
  rep(i, N) {
    cin >> xs[i] >> ls[i];
    ps[i] = P(xs[i] + ls[i], xs[i] - ls[i]);
  }
  sort(ps.begin(), ps.end());
  int count = 1;
  int pos = ps[0].first;
  for (int i = 1; i < N; i++) {
    if (pos <= ps[i].second) {
      pos = ps[i].first;
      count++;
    }
  }
  cout << count << endl;

  return 0;
}

Measured memory_bytes: 4832
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
#include <atcoder/convolution>
using namespace std;
using namespace atcoder;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << "\n"

void solve(){
    ll N,M;
    cin >> N >> M;
    vector<ll> a(N,0),b(M,0);
    rep(i,0,N) cin >> a[i];
    rep(i,0,M) cin >> b[i];
    vector<ll> v = convolution<998244353>(a,b);
    printa(v, N+M-1);


}

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

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

int main()
{
  int n, t, threshold = 0;
  cin >> n;
  vector<int> w(n);
  for(int i=0; i<n; i++)
  {
    cin >> w[i];
    threshold += w[i];
  }
  
  threshold = (threshold + 1) / 2;
  
  int s1 = 0;
  for(int i=0; i<n; i++)
  {
    s1 += w[i];
    
    if(s1 > threshold)
    {
      if(abs(s1 - w[i] - threshold) < abs(s1 - threshold))
      {
        s1 -= w[i];
        t = i;
        break;
      }
      else
      {
        t = i + 1;
        break;
      }
    }
  }
  int s2 = accumulate(w.begin() + t, w.end(), 0);
  cout << abs(s1 - s2) << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <cstdint>
#include <cstdlib>
#include <algorithm>
#include <cmath>

typedef long long ll;
using namespace std;

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

    cout << ((n/1000 == 0) ? "ABC" : "ABD") << endl;
    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

alias Pair = Tuple!(int, "a", int, "b");

void main() {
    int N, T;
    scan(N, T);

    auto ans = inf;

    foreach (i ; 0 .. N) {
        int ci, ti;
        scan(ci, ti);
        if (ti <= T) ans = min(ans, ci);
    }

    writeln(ans < inf ? ans.to!string : "TLE");
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll div_ceil(ll, ll);

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

int main() {
  string S = "";
  std::cin >> S;
  // REP(i, 200000 / 3) { S += "ABC"; }
  ll A_count = 0;
  ll count = 0;
  REP(i, S.size() - 1) {
    if (S[i] == 'A') {
      A_count++;
    } else if (S[i] == 'B') {
      if (S[i + 1] == 'C') {
        count += A_count;
        i++;
      } else {
        A_count = 0;
      }
    } else if (S[i] == 'C') {
      A_count = 0;
    }
  }
  std::cout << count << '\n';
}

ll div_ceil(ll a, ll b) {
  ll quotient = a / b;
  ll remainder = a % b;
  if (remainder == 0) {
    return quotient;
  } else {
    return quotient + 1;
  }
}


Measured memory_bytes: 640
l = list(map(int, input().split()))
count = count2 = 0
for i in range(3):
  if(l[i] == 5):
    count+=1
  elif(l[i] == 7):
    count2 += 1
    
if(count == 2 and count2 == 1):
    print("YES")
else:
	print("NO")

Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int main()
{
  string n;
  cin>>n;
  int c;
  c=0;
  int i;
  for(i=0;i<=2;i+=1){
    string p;
    p=n[i];
    if(p=="7"){
      cout<<"Yes"<<endl;
      c=1;
      break;
    }
    else{
      continue;
    }
  }
  if(c==0){
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());
        int[] input = new int[n];

        for(int i = 0; i < n; i++){
            input[i] = Integer.parseInt(br.readLine());
        }

        Arrays.sort(input);

        ArrayList<Integer> al = new ArrayList<Integer>();

        for(int i = 0; i < Math.min(4,n); i++){
            for(int j = 0; j < Math.min(4,n); j++){
                if(i == j) continue;
                al.add(Integer.parseInt(String.valueOf(input[i]) + String.valueOf(input[j])));
            }
        }

        Collections.sort(al);
        System.out.println(al.get(2));
    }
}


Measured memory_bytes: 29140
#include<iostream>
using namespace std;
int main() {
  	long x, y;
  	cin >> x >> y;
  	long i;
  	int j = 0;
  	for(i = x; i <= y; i *= 2) {
      	j += 1;
    }
  	cout << j << endl;
  	return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(1, n - 1):
  if p[i-1] < p[i] and p[i] < p[i+1]:
    count += 1
  elif p[i+1] < p[i] and p[i] < p[i-1]:
    count += 1
print(count)

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N, M; cin >> N >> M;
	vector<vector<int>>S(M);
	rep(i, 0, M) {
		int k; cin >> k;
		rep(j, 0, k) {
			int s; cin >> s;
			s--;
			S[i].eb(s);
		}
	}
	int ans = 0;
	vector<int>P(M); rep(i, 0, M) { cin >> P[i]; }
	rep(bits, 0, (1ll << N)) {
		int cnt = 0;
		vector<int>p(M);
		rep(i, 0, M) {
			int f = 0;
			for (auto s : S[i]) {
				if ((bits >> s) & 1) {
					p[i]++;
				}
			}
		}
		int f = 1;
		rep(i, 0, M) {
			if (P[i] % 2 != p[i] % 2) {
				f = 0;
			}
		}
		ans += f;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
int main(void){
  int h,w,a,b;
  scanf("%d %d %d %d",&h,&w,&a,&b);
  FOR(b){
    FOR(a)PRC('0');
    FOR(w-a)PRC('1');
    PRS("");
  }
  FOR(h-b){
    FOR(a)PRC('1');
    FOR(w-a)PRC('0');
    PRS("");
  }
  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>

using namespace std;
int main() {
    double a,b,c,d;
    cin >> a >> b >> c >> d ;
    double e;
    e = (c-a)*(c-a)+(d-b)*(d-b);
    printf("%.7f\n", sqrt(e));
    
}



Measured memory_bytes: 3268
#include<iostream>
#include<algorithm>
#define inf 1000000001
using namespace std;

long long merge(int a[],int left,int mid,int right){
int n1=mid-left,n2=right-mid;
	int L[n1+1],R[n2+1];
	int i,j,k;
	long long cnt=0;
	for(i=0;i<n1;i++)
	L[i]=a[left+i];
	for(j=0;j<n2;j++)
	R[j]=a[mid+j];
	L[n1]=R[n2]=inf;
	
	i=j=0;
	for(k=left;k<right;k++){
		if(L[i]<=R[j]){
		a[k]=L[i];
			
			i++;
		}
		else {
		a[k]=R[j];
			cnt+=n1-i;
			j++;
		}
	}
	return cnt;
}
long long mergesort(int a[],int left,int right){
	if(left+1<right){
		int mid=(left+right)/2;
		long long v1,v2,v3;
		v1=mergesort(a,left,mid);
		v2=mergesort(a,mid,right);
		v3=merge(a,left,mid,right);
		return v1+v2+v3;
	}
	else return 0;
}

main(){
	int n,a[200000];
	cin>>n;
	for(int i=0;i<n;i++)
	cin>>a[i];
	cout<<mergesort(a,0,n)<<endl;
	return 0;
}



Measured memory_bytes: 4636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        // code goes here
        int[] arr = nextIntArray(br, 3);
        int x = (int) Math.ceil(arr[0]*1.0/arr[1]);
        sb.append(x*arr[2]);
        System.out.print(sb.toString());
    }

    private static int nextInt(BufferedReader br) throws IOException{
        return Integer.parseInt(br.readLine());
    }

    private static int[] nextIntArray(BufferedReader br, int n) throws IOException{
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        return arr;
    }

    static class Pair<A, B>{
        A first;
        B second;
        public Pair(A first, B second){
            this.first = first;
            this.second = second;
        }
    }
}


Measured memory_bytes: 32900
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */
  for(i=1;i<=n;i++){
    scanf("%hu",&A[i]);
  }
  
  for(i=0;i<=VMAX;i++){
    C[i]=0;
  }

  for(j=1;j<=n;j++){
    C[A[j]]++;
  }
  for(i=1;i<=VMAX;i++){
    C[i]=C[i]+C[i-1];
  }

  for(j=n;j>0;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
  
  for(i=1;i<=n;i++){
    printf("%u",B[i]);
    if(i!=n){
      printf(" ");
    }
  }
  printf("\n");
  free(A);
  free(B);
  return 0;
}



Measured memory_bytes: 9196
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,n) for(int i=0;i<n;i++)
#define lop(i,a,b) for(int i=a;i<=b;i++)
#define int long long int
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
#define mp make_pair
#define sz(a) int((a).size())
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define tr(container, it) for(auto it = container.begin(); it != container.end(); it++)
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define so(v) sort(all(v))
#define sod(v) sort(allr(v))
#define mfind(c, element) (c.find(element) != c.end())
#define gfind(c, element) (find(all(c),element) != c.end())
#define gfindindex(c, element) (find(all(c),element)-c.begin())
#define vp(x) cout << #x << " --> " << x << endl;
#define cp1(v) cout << #v << "--->" << endl; for (auto it : v)  cout << it << " "; cout << endl;
#define cpp1(v) cout << #v << "-->" << endl; for(auto it:v){cout << it.fi << " " << it.se << endl;}
#define ccp1(v) cout << #v << "--->" << endl;for (auto it:v){for(auto it1 : it){cout << it1 << " ";}cout<< endl;}
#define bsnp np3(low,high,mid);
#define hmm1 high=mid-1;
#define lmp1 low=mid+1;
#define hmp1 high=mid+1;
#define lmm1 low=mid-1;
#define fi first
#define se second
#define endl "\n"
#define np1(x) cout<<#x<<"="<<x<<'\n'
#define np2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define np3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
// upper_bound(all(a),k,greater<int>()) gives first no smaller(not greater) than k

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};//comparison used for sorting set<pair<i,i>,cmp>
bool myComparison(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
//increasing ordr basedd on 2nd
};
main()
{
IOS;
string s,t;
cin>>s>>t;
int ans=1e18;
int S=s.size(),T=t.size();
for(int i=0;i+T<=S;i++)
{   int cnt=0;
    for(int j=0;j<T;j++)
    {
        if(s[i+j]!=t[j])
        cnt++;
    }
    ans=min(ans,cnt);
}

cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N;
  cin >> N;
  vector<int> D(N+1);
  D[0] = 0;
  rep(i, N) cin >> D[i+1];
  sort(all(D));
  vector<int> cnt(24);
  int flag = 0;
  rep(i, N+1) {
    if(flag) {
      cnt[D[i]%24]++;
    } else {
      cnt[(24-D[i])%24]++;
    }
    flag = 1-flag;
  }
  int ans = 24;
  int tmp = 0;
  rep(i, 25) {
    if(cnt[i] > 1) ans = 0;
    if(i) {
      tmp++;
      if(cnt[i%24]) {
	ans = min(tmp, ans);
	tmp = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
con = 300000

def getlist():
	return list(map(int, input().split()))

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.rank = [0] * (n + 1)
        self.size = [1] * (n + 1)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            if self.same_check(x, y) != True:
                self.size[y] += self.size[x]
                self.size[x] = 0
            self.par[x] = y
        else:
            if self.same_check(x, y) != True:
               self.size[x] += self.size[y]
               self.size[y] = 0
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
               self.rank[x] += 1

    def siz(self, x):
        x = self.find(x)
        return self.size[x]

#処理内容
def main():
	#受け取り、処理
	N, K, L = getlist()
	UFp = UnionFind(N)
	UFr = UnionFind(N)
	for i in range(K):
		p, q = getlist()
		UFp.union(p, q)
	for i in range(L):
		r, s = getlist()
		UFr.union(r, s)

	for i in range(1, N):
		UFp.find(i)
		UFr.find(i)

	s1 = UFp.par
	s2 = UFr.par
	s3 = []
	
	for i in range(1, N + 1):
		s3.append([s1[i], s2[i]])

	#前計算
	D = defaultdict(int)
	for i in range(N):
		a = s3[i][0]
		b = s3[i][1]
		D[a * con + b] += 1
	#答え
	ans = []
	for i in range(N):
		ans.append(D[s3[i][0] * con + s3[i][1]])
	print(" ".join(list(map(str, ans))))

if __name__ == '__main__':
	main()

Measured memory_bytes: 134356
n = int(input())
l = [0 for _ in range(n)]
already = set()
next = 1
c = 0
for i in range(n):
  a = int(input())
  l[i] = a
while c <= n:
  next = l[next-1]
  c += 1
  if next == 2:
    print(c)
    break
  elif next in already:
    print(-1)
    break
  already.add(next)

Measured memory_bytes: 19132
#include <iostream>
#include <cmath>
#include <cstdlib>

using namespace std;

int main()
{
    long long h, w;
    cin >> h >> w;

    long long min = w * h;

    for (int k = 0; k < 2; k++)
    {
        for (int i = 1; i <= w - 1; i++)
        {
            long long s1 = i * h;
            long long s2 = (w - i) * (h / 2);
            long long s3 = (w - i) * (h - h / 2); 
            long long s_max = s1;
            if(s2 > s_max) s_max = s2;
            if(s3 > s_max) s_max = s3;
            long long s_min = s1;
            if(s2 < s_min) s_min = s2;
            if(s3 < s_min) s_min = s3;
            if (s_max - s_min < min)
            {
                min = s_max - s_min;
            }

            s1 = i * h;
            s2 = ((w - i) / 2) * h;
            s3 = ((w - i) - (w - i) / 2) * h;
            s_max = s1;
            if(s2 > s_max) s_max = s2;
            if(s3 > s_max) s_max = s3;
            s_min = s1;
            if(s2 < s_min) s_min = s2;
            if(s3 < s_min) s_min = s3;
            if (s_max - s_min < min)
            {
                min = s_max - s_min;
            }
        }

        long long tmp = w;
        w = h;
        h = tmp;
    }
    cout << min << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define D(x) cout << #x << "=" << x << " "
#define E puts("")
using namespace std;
typedef long long LL;
inline int getint() {
	int a = 0, f = 1; char c = getchar();
	while (c > '9' || c < '0') { if (c == '-') f = -1; c = getchar();}
	while (c <= '9' && c >= '0') { a = a * 10 + c - '0'; c = getchar();}
	return a * f;
}

int main(int argc, char const *argv[]) {
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	int X = getint(), Y = getint();
	printf("%d\n", X + Y / 2);
	return 0;
}

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

int main()
{
	bool b = true;
	int n,k;
	cin >> n >> k;
	vector<char> s;
	s.resize(k);
	for (int i = 0; i < k; i++) {
		cin >> s[i];
	}

	for (;b; n++) {
		b = false;
		string s2;
		s2 = to_string(n);
		sort(s2.begin(), s2.end());
		for (int j = 0; !b && j < s.size(); j++) {
			if (binary_search(s2.begin(), s2.end(), s[j])) {
				b = true;
			}
		}
	}

	cout << n-1 << endl;

    return 0;
}

Measured memory_bytes: 256
nl = list(input())
n = len(nl)

ans = 0
dp = [[0, 0] for i in range(n+1)]
for idx, i in enumerate(nl[::-1]):
    i = int(i)
    if idx == 0:
        dp[1][0] = dp[idx][0] + i
        dp[1][1] = dp[idx][0] + 10 - i
    else:
        dp[idx+1][0] = min(dp[idx][0] + i, dp[idx][1] + i + 1)
        dp[idx+1][1] = min(dp[idx][0] + 10 - i, dp[idx][1] + 10 - i - 1)
print(min(dp[-1][0], dp[-1][1]+1))


Measured memory_bytes: 186300
/***
coded by adarsh
***/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef vector<ll> vec; 
typedef vector<vector<ll>> vec2;
typedef pair<ll,ll> pair1;
typedef pair<string,ll> pair2;
typedef pair<ll,string> pair3;
typedef pair<string,string> pair4;
#define fl(i,a,b) for(i=a;i<b;i++)
#define rfl(i,a,b) for(i=b-1;i>=a;i--)
#define f first
#define s second

int main() 
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    char a;cin>>a;
    int b=a;
    b+=1;
    char c=b;
    cout<<c;
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    ll n,c=0,c1=n;
    cin>>n>>s;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='R')
        c++;
        else
        c1++;
    }
    if(c==n)
    {
        cout<<"0"<<endl;
        return 0;
    }
    else if(c1==n)
    {
        cout<<"0"<<endl;
        return 0;
    }
    else
    {
        c=0;
        ll i=0,j=n-1;
        while(j>i)
        {
            if(s[i]=='W'&&s[j]=='R')
                {c++;i++;j--;}
            else if(s[i]=='R'&&s[j]=='W')
                {i++;j--;}
            else if(s[i]=='R'&&s[j]=='R')
                i++;
            else if(s[i]=='W'&&s[j]=='W')
                j--;
        }
        cout<<c<<endl;
    }
    return 0;
}

Measured memory_bytes: 3784
#include <ios>
#include <iostream>
#include <string>

long long int cnt[26] = {};

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);
    std::string s;
    long long int n;
    long long int ans = 0;
    std::cin >> s;
    n = s.length();
    ans = n*(n-1)/2+1;
    for (int i = 0; i < n; i++)
        cnt[s.at(i)-'a']++;
    for (int i = 0; i < 26; i++)
        ans -= cnt[i]*(cnt[i]-1)/2;
    std::cout << ans << '\n';
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

void move(VLL & array){
  ll maxNum = -1;
  ll maxIdx = 0;
  rep(i,array.size()){
    if(maxNum < array[i]){
      maxNum = array[i];
      maxIdx = i;
    }
  }

  rep(i,array.size()){
    if(maxIdx == i) array[i] -= array.size();
    else array[i] += 1;
  }
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  // inptut & define
  ll k;
  const ll N = 50;
  cin >> k;

  ll a = (k+49LL)/N;
  VLL array(N);
  rep(i,N) array[i] = a+i;
  int moveTime = (N - (k%N))%N;
  rep(i,moveTime) move(array);


  // Out put
  cout << N << endl;
  rep(i,array.size()) cout << array[i] << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
  	cin>>s;
    if(s[2]==s[3] && s[4] == s[5])cout<<"Yes"<<endl;
    else{
        cout<<"No"<<endl;
    }
    
 return 0;   
}
  
  
  
  


Measured memory_bytes: 256
// see https://gist.github.com/LumaKernel/ff55d49ee1af69b7388f15b707e75c15
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>
#include <random>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<P> VP;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RREP(i,n) RFOR(i,0,n)

#define LFOR(i,a,b) for(ll i=(a);i<(b);++i)
#define RLFOR(i,b,a) for(ll i=(b)-1;i>=(a);--i)

#define ALL(a) (a).begin(),(a).end()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define PB push_back
#define EACH(i,c) REP(i,(int)(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define dump(x) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";
#define dump2(x,y) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x)\
			<< " , " << #y << " = " << (y) << "\n";

typedef pair<int, P> IP;

const int INF = 1e9;
const double EPS = 1e-10;

int n,m;
int g1[300][300],g2[300][300];
string s;

ll solve(){

	cin >> n;
	REP(i, n)REP(j, n){
		int x;
		cin >> x;
		g1[i][j] = x;
		g2[i][j] = x;
	}

	REP(k, n)REP(i, n)REP(j, n)
			g2[i][j] = min(g2[i][j], g2[i][k] + g2[k][j]);

	REP(i,n)REP(j,n)if(g1[i][j]!=g2[i][j])return -1;

	vector<IP> v;
	REP(i,n)REP(j,n)if(i<j){
		v.PB(IP(g1[i][j], P(i, j)));
	}
	SORT(v);

	ll ans = 0;
	EACH(it, v){
		int i = v[it].second.first, j =  v[it].second.second;
		bool flag = false;
		REP(w, n)if(i!=w&&j!=w){
			if(g1[i][j] == g1[i][w] + g1[w][j]){
				flag = true;
				break;
			}
		}
		if(!flag)ans += v[it].first;
	}
	return ans;
}

int main() {
	cout << solve();
	cout << endl;
}


Measured memory_bytes: 1788
# include<iostream>
# include<vector>
#include<algorithm>
#include<cstdlib>
#include <math.h>
using namespace std;

int check(int a){
    for(int i =1; i <= a;i++){
        if(i*i == a){
            return 1;
        }
    }
    return 0;
}

int main(){
    int n, d;cin >> n >> d;
    vector<vector <int>> a(n, vector<int>(d, 0));
    for(int i=0; i<n ;i++){
        for(int l=0;l<d;l++){
            cin >> a[i][l];
        }
    }
    int ans =0;
    int res = 0;
    for(int i=0; i<n-1 ;i++){
        for(int k = i+1; k<n; k++){
            res = 0;
            for(int l=0;l<d;l++){
                res += pow((a[i][l]-a[k][l]),2.0);
            }
        if(check(res) == 1){ans++;}
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
while True:
    n = int(input())
    if n == 0:
        break
    else:
        A = []
        Sum = []
        for i in range(n):
            A.append(int(input()))
        Wa = 0
        for i in range(0,n):
            Wa += A[i]
            Sum.append(Wa)
        for i in range(0 , n):
            for j in range(0 , i):
                Num = Sum[i] - Sum[j]
                Sum.append(Num)
        print(max(Sum))
                
                

Measured memory_bytes: 190620
/*
	*#*#*#* Author GaryMr *#*#*#*
########################################################################
	是否可以简化问题：
	是否可以化具体为抽象
	字符串问题是否可以用数学模拟递归过程（取c[i]或不取来算结果）
	二分？左闭右开？
	long long？
	逆向思维？
	dp？
	贪心？
	匹配括号 左减右>=0
	多组数据清空？
	dp优化用g？
	线段树：左闭右开！
	线段树：find： if(l>=b||r<=a) return 0x3f3f3f3f; if(r<=b&&l>=a) return tree[k];
	线段树：满二叉树 
	循环跳出条件 
	代数设出每个值寻找关系？
	优先队列：priority_queue<类型> q;   
	priority_queue<类,vector<类>, less<类> > pq1; 　　　 // 使用递减	
	priority_queue<类，vector<类>, greater<类> > pq2; 　　// 使用递增
	判断括号，判断是否长度为偶数
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;a++)
#define rl(a,b,c) for(int a=b;a>=c;a--)
#define niv vector<int>
#define IT iterator
#define FIR first
#define SEC second
using namespace std;
const int MAX=0x3f3f3f3f;
const int MAXN=1e5;
int a[MAXN],n;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	long long sum=0;int tot=0;
	int minima=0x3f3f3f3f;
	cin>>n;
	rb(i,1,n) {
	cin>>a[i];
	if(a[i]<0)tot++;
	minima=min(minima,abs(a[i]));
	sum+=abs(a[i]);
	}
	if(tot%2==0){
		cout<<sum<<endl;
	}
	else cout<<sum-2*minima;
	return 0;
}

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


int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> ac(n, 0);
  vector<int> wa(n, 0);
  rep(i, m)
  {
    int p;
    string s;
    cin >> p >> s;
    p--;
    if (ac[p] == 1)
      continue;
    if (s == "AC")
      ac[p] = 1;
    else
      wa[p]++;
  }
  rep(i, n)
    wa[i] *= ac[i];
  cout << accumulate(ac.begin(), ac.end(), 0) << ' ' << accumulate(wa.begin(), wa.end(), 0) << endl;
  return 0;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define ld long double
#define mem(x,y) memset(x,y,sizeof x)

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	string s;
	cin>>s;
	cout<<s;
	if(s.back()!='s') cout<<'s';
	else cout<<"es";
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 3636
#include<stdio.h>


int main(void){

    int A,B,C,K;
    int sum=0;

    scanf("%d %d %d %d", &A, &B, &C, &K);

    if(A>=K){
        sum = K;
    }
    else{
        sum = A;
        K-=A;
        if(B<K){
            K-=B;
            sum -=K;
        }
    }

    printf("%d", sum);
    return 0;
}

Measured memory_bytes: 1736
n = int(input())
monsters = list(map(int, input().split(' ')))
kills = list(map(int, input().split(' ')))
monsters_orig = sum(monsters)
 
for i in range(n):
    extra_attack = kills[i] - monsters[i]
    monsters[i] = max(0, monsters[i] - kills[i])
    if extra_attack > 0:
        monsters[i+1] = max(0, monsters[i+1] - extra_attack)
    
print(monsters_orig - sum(monsters))

Measured memory_bytes: 85596
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

int main()
{
	int n;
	cin >> n;
	double ret = 0;
	for (int i = 0; i < n; i++)
	{
		double d;
		string s;
		cin >> d >> s;
		ret += s == "JPY" ? d : d * 380000;
	}
	cout << fixed << setprecision(10) << ret << endl;
	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++)
#define rep1(i, n) for(int i=1; i<=(int)(n); i++)
#define rep2(i, n, m) for(int i=(int)n; i<=(int)m; i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> wi;
typedef vector<ll> vl;
const ll inf=1LL << 60;
const ll MOD=1000000007;

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

  ll n;
  cin >> n;
  ll ans=0;
  if(n%2==0){
    n/=10;
    ans+=n;
    while(n>=5){
      n/=5;
      ans+=n;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3652
from itertools import permutations
import math

N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
ans_list = []
for i in permutations(range(N)):
    ans = 0
    for j in range(N-1):
        ans += math.sqrt((XY[i[j]][0] - XY[i[j+1]][0])**2 + (XY[i[j]][1] - XY[i[j+1]][1])**2)
    ans_list.append(ans)
print(sum(ans_list)/len(ans_list))


Measured memory_bytes: 4400
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int,int> mypair;

int main(){
	int n;
	cin>>n;
	priority_queue<mypair> q;
	for(int i=0;i<n;i++){
int a,b;
cin>>a>>b;
	q.push(mypair(a,b));

	}
cout<<q.top().first+q.top().second<<endl;
return 0;
}


Measured memory_bytes: 1400
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(),p = sc.nextInt(),gu=0,ki=0;
		for(int i=0;i<n;i++)
			if(sc.nextInt()%2==0)gu++;else ki++;
		if(ki==0) System.out.println(p==0?1L<<(n):0);
		else System.out.println(1L<<(n-1));
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;typedef long long int _sgp3DG1KQll;_sgp3DG1KQll 
_sgp3DG1KQa[300000];_sgp3DG1KQll _sgp3DG1KQrot[300000];int main()
{_sgp3DG1KQll _sgp3DG1KQn;cin>>_sgp3DG1KQn;_sgp3DG1KQll 
_sgp3DG1KQi=1;while(_sgp3DG1KQi<=_sgp3DG1KQn){cin>>
_sgp3DG1KQa[_sgp3DG1KQi];if(_sgp3DG1KQi>=_sgp3DG1KQa[
_sgp3DG1KQi]){_sgp3DG1KQll _sgp3DG1KQram=_sgp3DG1KQi-
_sgp3DG1KQa[_sgp3DG1KQi];if(_sgp3DG1KQram+1<=_sgp3DG1KQn){
_sgp3DG1KQrot[_sgp3DG1KQram+1]=_sgp3DG1KQrot[_sgp3DG1KQram+1
]+1;}}_sgp3DG1KQi++;}_sgp3DG1KQll _sgp3DG1KQsum=0;
_sgp3DG1KQi=1;while(_sgp3DG1KQi<=_sgp3DG1KQn){_sgp3DG1KQll 
_sgp3DG1KQxhm=_sgp3DG1KQa[_sgp3DG1KQi];_sgp3DG1KQll 
_sgp3DG1KQexpect=_sgp3DG1KQi+_sgp3DG1KQa[_sgp3DG1KQi]+1;if(
_sgp3DG1KQexpect<=_sgp3DG1KQn){_sgp3DG1KQsum=_sgp3DG1KQsum+
_sgp3DG1KQrot[_sgp3DG1KQexpect];}_sgp3DG1KQi++;}cout<<
_sgp3DG1KQsum;return 0;}



Measured memory_bytes: 6672
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>

using namespace std;
int main()
{
    string S;
    cin >> S;
    const int N = S.size();
    
    vector<int> ans(N, 0);
    int i = 0;
    while(i < N){
        int rs = 0;
        while(i < N && S[i] == 'R'){
            ++rs;
            ++i;
        }
        int rl = i;
        int ls = 0;
        while(i < N && S[i] == 'L'){
            ++ls;
            ++i;
        }
        ans[rl - 1] += (rs + 1)/ 2 + ls / 2;
        ans[rl] += rs / 2 + (ls + 1)/ 2;
    }
    
    cout << ans[0];
    for(int i = 1; i < N; ++i){ cout << " " << ans[i]; }
    cout << endl;
}


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

#define A first
#define B second

const int MAXN = 1e5+5;

int x, y, z, n;
ll a[MAXN], b[MAXN], c[MAXN];
ll ans = 0;
pii s[MAXN];
set<pii> sb, sc;
ll sumb[MAXN], sumc[MAXN];

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

    cin >> x >> y >> z;
    n = x + y + z;

    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i] >> c[i];
        b[i] -= a[i];
        c[i] -= a[i];
        ans += a[i];
        s[i] = pii(c[i]-b[i], i);
    }

    sort(s, s+n);
    ll sum = 0;

    for (int i = 0; i < n; ++i) {
        int x = s[i].B;
        sb.insert(pii(b[x], x));
        sum += b[x];
        if (sb.size() > y) {
            pii t = (*sb.begin());
            sum -= t.A;
            sb.erase(t);
        }

        if (i >= y-1)
            sumb[i] = sum;
    }

    sum = 0;
    for (int i = n-1; i >= 0; --i) {
        int x = s[i].B;
        sc.insert(pii(c[x], x));
        sum += c[x];
        if (sc.size() > z) {
            pii t = (*sc.begin());
            sum -= t.A;
            sc.erase(t);
        }

        if (sc.size() == z)
            sumc[i] = sum;
    }

    ll best = -(1LL<<60);

    for (int i = y-1; i <= n-z-1; ++i)
        best = max(best, sumb[i] + sumc[i+1]);
    cout << ans + best << endl;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
	string s;cin>>s;
	long long rez=0,r=0,g=0,b=0;
	for(int i = 0 ; i < n ; i ++){
		s[i]=='R'?r++:s[i]=='B'?b++:g++;
		for(int j = i-1 ; j >= 0 ; j --){
			int k=j-(i-j);
			if(k>=0&&s[j]!=s[i]&&s[i]!=s[k]&&s[j]!=s[k])rez--;
		}
	}
	rez+=r*g*b;
	cout<<rez;
}

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

using namespace std;

int main(){

int P;
int Q;
int R;
int a;
int b;
int c;
int answar;
cin>>P>>Q>>R;


if((P+Q)<=(Q+R)){
    a=(P+Q);
}
if((P+Q)>=(Q+R)){
  a=(Q+R);
}
if((P+Q)>=(Q+R)){
    c=(Q+R);
}
if((P+Q)<=(Q+R)){
  c=(P+Q);
}
if((P+R)<=(Q+R)){
    b=(P+R);
}
if((P+R)>=(Q+R)){
  b=(Q+R);
}
//cout<<<<endl;



if(a<=b && a<=c){
    answar=a;
}
if(b<=c && b<=a){
    answar=b;
}
if(c<=a && c<=b){
    answar=c;
}
cout<<answar<<endl;
return 0;


}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    
    int S;
    int h,m,s;
    
    scanf("%d", &S);
    h = S/3600;
    m = (S-h*3600)/60;
    s = S-h*3600-m*60;
    
    printf("%d:%d:%d\n", h,m,s);
    
    return 0;
}


Measured memory_bytes: 1976
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur = nil->next;
  while( cur != nil && cur->key != key ){
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deletenode(NodePointer t){
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deletenode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if ( t == nil ) return;
  deletenode(t);
}

void delete(int key){
  NodePointer t = listSearch(key);
  if ( t == nil ) return;
  deletenode(t);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(void)
{
  int key, n, i, size = 0;
  int np = 0, nd = 0;                //np:insertのとき+　nd:deleteのとき+
  char com[20];

  scanf("%d", &n);
  init();

  for(i = 0; i < n; i++){
    scanf("%s%d", com, &key);
    if(com[0] == 'i'){              //insertの先頭の文字は'i'
      insert(key);
      np++;
      size++;
    }
    else if(com[0] == 'd'){         //deleteの先頭の文字は'd'
      if(strlen(com) > 6){
        if(com[6] == 'F'){
          deleteFirst();
        }
        else if(com[6] == 'L'){
          deleteLast();
        }
      }
      else{
        delete(key);
        nd++;
      }
      size--;
    }
  }

  printList();
  return 0;
}



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

int main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  rep(i,n) cin >> x[i] >> y[i];
  auto dist = [&](int i, int j) {
    double dx = x[i]-x[j];
    double dy = y[i]-y[j];
    return sqrt(dx*dx+dy*dy);
  };
  vector<int> p(n);
  rep(i,n) p[i] = i;
  double len = 0;
  int cnt = 0;
  do {
    rep(i,n-1) {
      len += dist(p[i],p[i+1]);
    }
    cnt++;
  } while (next_permutation(p.begin(), p.end()));
  double ans = len/cnt;
  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

vector<vector<int> >d;
vector<vector<int> >G;
int V,E;

void warshall_floyd(){
  rep(k,V) rep(i,V) rep(j,V) if(d[i][k]!=MAX_I && d[k][j] != MAX_I)d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  cin >> V >> E;
  d = vector<vector<int> > (V,vector<int>(V,MAX_I));
  G = vector<vector<int> > (V,vector<int>(V,MAX_I));
  rep(i,E){
    int f,t,c;cin >> f >> t >> c;
    --f;--t;
    d[f][t] = d[t][f] =  G[f][t] = G[t][f] = c;
  }
  rep(i,V) d[i][i] = 0;
  warshall_floyd();
  int count = 0;
  rep(i,V)repp(j,i+1,V) if(G[i][j] != MAX_I && G[i][j] != d[i][j])++count;
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;

namespace MyProgram{
    class AtCoder{
        static void Main(){
            int N = int.Parse(Console.ReadLine());
            long[] T = new long[N];
            for(var i=0;i<N;i++){
                T[i] = long.Parse(Console.ReadLine());
            }
            long gcd=T[0];
            for(var i=1;i<N;i++){
                gcd = T[i] * (gcd / Gcd(T[i],gcd));
            }
            Console.WriteLine(gcd);
        }
        static long Gcd(long m,long n){
           long temp;
            while(m%n!=0){
                temp =n;
                n = m%n;
                m = temp;
            }
            return n;
        }
    } 
}

Measured memory_bytes: 11092
def num():
    return int(input())
def nums():
    return list(map(int,input().split()))

import itertools as iter

N = num()
P = tuple(nums())
Q = tuple(nums())
pmts = list(iter.permutations(range(1,N+1)))
pmts.sort()
a = pmts.index(P)
b = pmts.index(Q)
print(abs(a-b))

Measured memory_bytes: 8052