akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>


using namespace std;
int main(){
  string s;
  stack<char> st;
  cin>>s;
  for(int i = 0,f = s.size();i<f;i++){
    if(s[i] == 'S')
      st.push(s[i]);
    else{
      if(st.empty()||st.top()=='T'){
	st.push(s[i]);
      }else{
	st.pop();
      }
    }
  }
 
  cout<<st.size()<<endl;
  return 0;
}


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

int yaku(int x, int y);
int bai(int n, int m);

int main(void){

	int n, m;
	while (cin >> n >> m){
	
		int gcd; //?????§??¬?´???°
		int lcm; //????°???¬?????°

		gcd = yaku(n, m);
		lcm = bai(n, m);

		cout << gcd << ' ' << lcm << endl;
	}
}

int yaku(int x, int y){

	if (x < y){
		int temp = x;
		x = y;
		y = temp;
	}

	while (y != 0){
		int temp = x % y;
		x = y;
		y = temp;
	}

	return x;
}

int bai(int n, int m){

	int x = n, y = m;

	while (x != y){
		if (x < y)
			x = x + n;
		else
			y = y + m;
	}

	return x;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll c=0,d=0,k=0,n,m,h,w,p,q,min,max,ans=0;
    string s,s1,s2;
    map<string,int> mp;
    cin >> n;
    rep(i,n){
        cin >> s;
        sort(ALL(s));
        auto itr = mp.find(s);
        if(itr!=mp.end()){
            ans += itr->second;
            mp[s]++;
        }
        else{
            mp[s] = 1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11136
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans = 0;
vl A;
int main() {
	cin >> n;
	ll sum = 0;
	rep(i, n) {
		cin >> a;
		A.push_back(a);
		sum += a;
	}

	k = 0;
	ans = INF;
	rep(i, n) {
		k += A[i];
		ans = min(ans, abs(k * 2 - sum));
	}
	cout << ans << endl;
}

Measured memory_bytes: 2420
//
//AtCoder Beginner Contest 148
//D - Brick Break
//

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define reAll(x) (x).rbegin(),(x).rend()

using ll = long long;

const double PI = 3.14159265358979323846;
const int MOD = 1000000007;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main()
{
    int n;

    cin >> n;

    int a[n];

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

    int brk = 0;
    int chk = 1;
    bool flag = false;

    rep(i, n){
        if (a[i] == chk) {
            chk++;
            flag = true;
        }else{
            brk++;
        }
    }

    if (flag) cout << brk << endl;
    else cout << -1 << endl;


    return 0;
}


Measured memory_bytes: 1024
import sys
N, M = map(int, input().split())
sys.setrecursionlimit(10**5)
E = [[] for _ in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    E[x-1].append(y-1)

dp = [-1]*N


def rec(v):
    if dp[v] != -1:
        return dp[v]
    if len(E[v]) == 0:
        dp[v] = 0
        return dp[v]

    for to in E[v]:
        dp[v] = max(dp[v], rec(to)+1)
    return dp[v]


for i in range(N):
    dp[i] = rec(i)
print(max(dp))

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

using namespace std;
typedef long long ll;

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

  ll n,a,b,res=0,pre;cin>>n>>a>>b;
  cin>>pre;
  for(int i=1;i<n;i++){
      int nex;cin>>nex;
      res+=min(b,a*(nex-pre));
      pre=nex;
  }
  cout<<res<<endl;
}


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

const int N = 100005;

int n, a[N], b[N];

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) b[i] = a[i] - a[(i + 1) % n];
	sort(b, b + n);
	long long cnt = 0, sum = 0;
	for (int i = 0; i < n; ++i) sum += a[i];
	for (int i = 1; i < n; ++i) {
		if ((b[i] - b[0]) % n) {
			cout << "NO"; return 0;
		}
		cnt += (b[i] - b[0]) / n;
	}
	if (cnt != abs(b[0])) {
		cout << "NO"; return 0;
	}
	long long tmp = 1LL * n * (n + 1) / 2;
	if (sum % tmp || (sum / tmp - cnt) % n || sum / tmp - cnt < 0) {
		cout << "NO"; return 0;
	}	
	cout << "YES"; 
}
	

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var hurui = Enumerable.Range(2, 100000).ToList();
            var primes = new int[200002];
            while (hurui.First() <= 320) {
                var first = hurui.First();
                primes[first]++;
                primes[first * 2 - 1]++;
                hurui = hurui.Where(x => x % first != 0).ToList();
            }

            foreach (var item in hurui) {
                primes[item]++;
                primes[item * 2 - 1]++;
            }

            var sums = new int[100001];
            for (int i = 1; i <= 100000; i++) {
                if (primes[i] == 2) sums[i]++;
                sums[i] += sums[i - 1];
            }

            var Q = NextInt();
            for (int i = 0; i < Q; i++) {
                var l = NextInt();
                var r = NextInt();
                Console.WriteLine(sums[r] - sums[l - 1]);
            }
        }
    }

    class MyMath {
        static long Gcd(long a, long b) {
            return b == 0 ? a : Gcd(b, a % b);
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 30404
#include<iostream>
#include<cmath>
#include<iomanip>
#include<algorithm>
using namespace std;
struct Point { long double px, py; };
struct Segment { Point p1, p2; };
Point Minus(Point a, Point b) { Point G; G.px = a.px - b.px; G.py = a.py - b.py; return G; }
long double Abs(Point a) { return sqrt(a.px*a.px + a.py*a.py); }
long double norm(Point a) { return a.px*a.px + a.py*a.py; }
long double dot(const Point& a, const Point& b) { return a.px * b.px + a.py * b.py; }
long double crs(const Point& a, const Point& b) { return a.px * b.py - a.py * b.px; }
int ccw(Point p0, Point p1, Point p2) {
	Point a = Minus(p1, p0), b = Minus(p2, p0);
	if (crs(a, b) > 1e-10) return 1;
	if (crs(a, b) < -1e-10) return -1;
	if (dot(a, b) < -1e-10) return 2;
	if (norm(a) < norm(b)) return -2;
	return 0;
}
bool its(Point p1, Point p2, Point p3, Point p4) {
	return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
bool its(Segment s1, Segment s2) {
	return its(s1.p1, s1.p2, s2.p1, s2.p2);
}
long double dst(const Segment& a, const Point& b) {
	if (dot(Minus(a.p2, a.p1), Minus(b, a.p1)) < 0.0) return Abs(Minus(b, a.p1));
	if (dot(Minus(a.p1, a.p2), Minus(b, a.p2)) < 0.0) return Abs(Minus(b, a.p2));
	return abs(crs(Minus(a.p2, a.p1), Minus(b, a.p1)) / Abs(Minus(a.p2, a.p1)));
}
int main() {
	Point P1, P2, P3, P4; Segment M1, M2;
	int T; cin >> T;
	for (int i = 0; i < T; i++) {
		cin >> P1.px >> P1.py >> P2.px >> P2.py;
		cin >> P3.px >> P3.py >> P4.px >> P4.py;
		M1.p1 = P1; M1.p2 = P2; M2.p1 = P3; M2.p2 = P4;
		long double res = min(dst(M1, P3), dst(M1, P4));
		res = min(res, min(dst(M2, P1), dst(M2, P2)));
		if (its(M1, M2) == true) { res = 0.0; }
		cout << fixed << setprecision(1919) << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1312
#include<stdio.h>
long long t,tt;
long long a[100001],s[100001];
int b[100001],flg[100001];
int main(void)
{
	int n,q,i,j,c[1000],x;
	scanf("%d %lld %d",&n,&t,&q);
	for(i=1;i<=n;i++){
		scanf("%lld %d",&a[i],&b[i]);
		flg[i]=0;
	}	
	for(i=1;i<=q;i++)	scanf("%d",&c[i]);
	for(i=1;i<n;i++){
		if(b[i]==1&&b[i+1]==2&&a[i+1]-a[i]<t*2){
			flg[i]=1; flg[i+1]=1;
			s[i]=s[i+1]=(a[i]+a[i+1])/2;
		}
	}
	x=0;
	for(i=n;i>=1;i--){
		if(flg[i]==1){
			tt=s[i];	x=1;
		}
		else{
			if(b[i]==1&&x==1&&a[i]+t>tt){
				s[i]=tt;	flg[i]=2;
			}
		}
	}
	x=0;
	for(i=1;i<=n;i++){
		if(flg[i]==1){
			tt=s[i];	x=1;
		}
		else{
			if(b[i]==2&&x==1&&a[i]-t<tt){
				s[i]=tt;	flg[i]=2;
			}
		}
	}
	for(i=1;i<=q;i++){
		if(flg[c[i]]==0){
			if(b[c[i]]==1) s[c[i]]=a[c[i]]+t;
			else s[c[i]]=a[c[i]]-t;
		}
	}	
	for(i=1;i<=q;i++) printf("%lld\n",s[c[i]]);
}

Measured memory_bytes: 5052
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main()
{
    map<char, int> dic;
    string S, s;
    getline(cin, S);
    while (true)
    {
        getline(cin, s);
        S += s;
        if (s == "")
        {
            break;
        }
    }

    for (int i = 0; i < S.size(); i++)
    {
        if ('A' <= S[i] && S[i] <= 'Z')
        {
            S[i] += 'a' - 'A';
        }
    }

    for (char c : S)
    {
        dic[c]++;
    }

    for (char c = 'a'; c <= 'z'; c++)
    {
        printf("%c : %d\n", c, dic[c]);
    }
}


Measured memory_bytes: 3236
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [a, b, x] <- getIntList
    putStrLn $ if a <= x && x <= (a + b) then "YES" else "NO"

Measured memory_bytes: 380
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n,d;cin >> n >> d;
  cout << (n+2*d)/(2*d+1) << "\n";
  return 0;
}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  ll b=mod, u=1, v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a, b);
    u-=t*v; swap(u, v);
  }
  u%=mod;
  if(u<0)u+=mod;
  return u;
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  ll h,w;
  cin >> h >> w;
  ll cnt=0;
  rep(i, N){
    ll a, b;
    cin >> a >>  b;
    if(a>=h and b>=w)cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = (LL)1e9+7;
const int SIZE = 2e5+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;
const LL MULT = 1e7;

deque<int> dp(LL x){
	if(x==1)return deque<int>();
	if(x%2){
		deque<int> h=dp(x-1);
		int mv=0;
		for(int i:h){mv=max(mv,i);}
		h.push_front(mv+1);
		return h;
	}
	else{
		deque<int> h=dp(x/2);
		int mv=0;
		for(int i:h){mv=max(mv,i);}
		h.PB(mv+1);
		return h;
	}
}

int main(){
	LL x;cin>> x;
	deque<int> v=dp(x+1);
	int mv=0;
	for(int i:v){mv=max(mv,i);}
	REP(i,mv){
		v.PB(i+1);
	}
	printf("%d\n",SZ(v));
	for(int i:v)printf("%d ",i);
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String args[]){
		try{
			new Main();
		}catch(IOException e){
			e.printStackTrace();
		}
	}
	
	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		List<Runner> Ans = new ArrayList<Runner>();
		String line;
		
		List<Runner> third = new ArrayList<Runner>();
		for(int n=0; n<3; n++){
			double[] times = new double[8];
			Runner[] runner = new Runner[8];
			for(int m=0; m<8; m++){
				line = in.readLine();
				String dst[] = line.split(" ");
				int id = Integer.parseInt(dst[0]);
				double time = Double.parseDouble(dst[1]);
				times[m] = time;
				runner[m] = new Runner(id, time);				
			}
			
			Arrays.sort(times);
			int a=0, b=0, c=0, d=0;
			for(int m=0; m<8; m++){
				if(runner[m].time == times[0]){
					a = m;
				}
				if(runner[m].time == times[1]){
					b = m;
				}
				if(runner[m].time == times[2]){
					c = m;
				}
				if(runner[m].time == times[3]){
					d = m;
				}
			}
			
			Ans.add(runner[a]);
			Ans.add(runner[b]);
			
			if(n==0){
				third.add(runner[c]);
				third.add(runner[d]);
			}
			else{
				if(runner[c].time < third.get(0).time){
					third.add(0, runner[c]);
					third.remove(2);
				}
				else if(runner[c].time < third.get(1).time){
					third.add(1, runner[c]);
					third.remove(2);
				}
				
				if(runner[d].time < third.get(0).time){
					third.add(0, runner[d]);
					third.remove(2);
				}
				else if(runner[d].time < third.get(1).time){
					third.add(1, runner[d]);
					third.remove(2);
				}
			}
		}
		
		Ans.add(third.get(0));
		Ans.add(third.get(1));
		
		for(int n=0; n<Ans.size(); n++){
			Runner r = Ans.get(n);
			System.out.printf("%d %2.2f\n", r.id, r.time);
		}
	}
}

class Runner{
	int id;
	double time;
	
	public Runner(int id, double time){
		this.id = id;
		this.time = time;
	}
}

Measured memory_bytes: 12000
n,k = map(int,input().split())
p = list(map(int,input().split()))

d = []
d.append(sum(p[:k]))

for i in range(1,n-k+1):
  d.append(d[i-1] - p[i-1] + p[i-1+k])

print(max(d)/2 + k/2)

Measured memory_bytes: 24548
#include<iostream>
#include<vector>
#define rep(i, n) for (int i=0;i<n;i++)
using namespace std;

int main(void){
    int a, b;
    cin>>a>>b;
    int ans;
    ans=max(a+b, a-b);
    ans=max(ans, a*b);
    cout<<ans<<endl;
}

Measured memory_bytes: 384
function Main(input) {
  input=input.split("\n");
  var array=input;
  array.shift();
  array.sort();
  console.log(array.join(""));
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  
  

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

int main()
{
	int n,x,t;
	cin>>n>>x>>t;

	if(n%x==0)
		cout<<(n/x)*t<<endl;
	else
		cout<<(n/x + 1)*t<<endl;

	
	return 0;
}

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

int main() {

  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A), b(B);
  int x, y, c;
  int minA =1000000;
  int minB =1000000;

  for(int i=0;i<A;i++){
    cin >> a.at(i);
    if(a.at(i)<minA){
      minA = a.at(i);
    }
  }

  for(int i=0;i<B;i++){
    cin >> b.at(i);
    if(b.at(i)<minB){
      minB = b.at(i);
    }
  }

  int min = minA + minB;

  for(int i=0;i<M;i++){
    cin >> x >> y >> c;
    int num = a.at(x-1) + b.at(y-1) - c;
    if(num < min){
      min = num;
    }
  }

   cout <<  min << endl;
}

Measured memory_bytes: 1024
options = [(0, 0), (0, 1), (1, 0), (1, 1)]


def judge(n, s):
    res = [None] * n
    for op in options:
        res[-1], res[0] = op
        s_num = list(map(lambda a: 0 if a == 'o' else 1, s))
        for i in range(n):
            res[(i + 1) % n] = res[i] ^ s_num[i] ^ res[i - 1]
        if (res[-1], res[0]) == op:
            print(''.join(map(lambda a: 'S' if a == 0 else 'W', res)))
            exit()

n = int(input())
s = input()
judge(n, s)
print(-1)


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

int n; ll s[1000005];
int main(){
	scanf("%d",&n);
	int i;
	for (i=1; i<=n; i++){
		int x; scanf("%d",&x);
		s[i]=s[i-1]+x;
	}
	ll ans=1000000000000000000ll;
	for (i=1; i<n; i++) ans=min(ans,abs(s[i]-(s[n]-s[i])));
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
#define mod 1e9 + 7;

int main()
{
	ios_base::sync_with_stdio(false);

	ll n,m,d;
	cin >> n;
	vi v(n);
	rep(i, n) {
		cin >> v[i];
	}
	ll ans = 0;
	rep(i, n-2) {
		if (v[i] == v[i + 1]) {
			if (v[i + 2] + 10 != v[i]) {
				v[i + 1] += 20;
			}
			else v[i + 1] += 10;
			ans++;
		}
	}
	if (v[n - 2] == v[n-1]) ans++;
	cout << ans << endl;
}
/*memo
	2 5 1  4-2 3-8 2-12 1-8 0-2
	2 4 1  3-2 2-6 1-6 0-2 24
	2 3 1      2-2 1-4 0-2 8
	2 3 0      2-2 1-4 0-2*/


Measured memory_bytes: 256
h, w = map(int, input().split())
s = ['.' + input() + '.' for i in range(h)]
s.insert(0, '.' * (w+2))
s.append('.' * (w+2))

def search(x, y):
    return sum((s[x + i][y + j] == '#') +0 for i in range(-1, 2) for j in range(-1, 2))

for i in range(1, h + 1):
    for j in range(1, w + 1):
        print(search(i, j) if s[i][j] == '.' else '#', end='')
    print()

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

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;

const int maxn = 2e5 + 5;
const int logn = log2(maxn) + 2;
const int mod = 1e9 + 7;
int lab[maxn];
int FindLab(int u){return lab[u] < 0 ? u : lab[u] = FindLab(lab[u]);}
int n , cost[maxn];
struct node{
    pair<ll,int> a,b;
    node(){a =  b = mp(1e18,-1);};
    void reset(){a = b = mp(1e18,-1);}
    void add(pair<ll,int> x , ll y = 0){
        x.first += y;
        if(a.second == x.second)a = min(a,x);
        else if(b.second == x.second)b = min(b,x);
        else if(a > x)b = a , a = x;
        else if(b > x)b = x;
        if(b<a)swap(a,b);
        assert(b.second != a.second || a.second == -1);
    }
}dp[maxn];
pair<ll,int> bezt[maxn];
vector<ii> adj[maxn];

node dfs(int u , int par){
    node a;
//    cout << u << endl;
    for(auto c : adj[u]){
        if(c.first == par)continue;
        auto tmp = dfs(c.first,u);
        a.add(tmp.a,c.second);
        a.add(tmp.b,c.second);
    }
    if(a.a.second != FindLab(u))bezt[FindLab(u)] = min(bezt[FindLab(u)],mp(a.a.first+cost[u],a.a.second));
    if(a.b.second != FindLab(u))bezt[FindLab(u)] = min(bezt[FindLab(u)],mp(a.b.first+cost[u],a.b.second));
    a.add(mp(cost[u],FindLab(u)));
    for(auto c : adj[u]){
        if(c.first == par)continue;
        dp[c.first].add(a.a);
        dp[c.first].add(a.b);
    }
    return a;
}

void dfs1(int u , int par , node a){
    if(a.a.second != FindLab(u))bezt[FindLab(u)] = min(bezt[FindLab(u)],mp(a.a.first+cost[u],a.a.second));
    if(a.b.second != FindLab(u))bezt[FindLab(u)] = min(bezt[FindLab(u)],mp(a.b.first+cost[u],a.b.second));
    for(auto c : adj[u]){
        if(c.first == par)continue;
        node b;
        b.add(a.a,c.second);b.add(a.b,c.second);
        b.add(dp[c.first].a,c.second);b.add(dp[c.first].b,c.second);
        dfs1(c.first,u,b);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    fill_n(lab,maxn,-1);
    cin >> n;
    for(int i = 1 ; i <= n ; ++i)cin >> cost[i];
    for(int i = 1 ; i < n ; ++i){
        int u , v , c;cin >> u >> v >> c;
        adj[u].pb(mp(v,c));adj[v].pb(mp(u,c));
    }
    ll res = 0;int cnt = n - 1;
    while(cnt > 0){
        for(int i = 1 ; i <= n ; ++i)dp[i].reset(),bezt[i] = mp(1e18,-1);
        dfs(1,0);
//        return 0;
        node tmp;tmp.reset();
        dfs1(1,0,tmp);
        vector<pair<ll,ii>> edge;
        for(int i = 1 ; i <= n ; ++i){
            if(lab[i] < 0){
                if(bezt[i].first < 1e18){
                    edge.pb(mp(bezt[i].first,mp(i,bezt[i].second)));
                    int u = FindLab(i),v = FindLab(bezt[i].second);
                    if(u==v)continue;
                    res += bezt[i].first;if(lab[u]>lab[v])swap(u,v);lab[u]+=lab[v];lab[v]=u;
                    --cnt;
                }
            }
        }
    }
    cout << res;
}


Measured memory_bytes: 68852
A, B, C, X, Y = map(int, input().split(' '))

if C * 2 <= A and C * 2 <= B:
    print(max(X, Y) * 2 * C)
    exit()

if C * 2 >= A + B:
    print(A * X + B * Y)
    exit()

result = 0
while True:
    if X <= 0 and Y <= 0:
        break

    if X == 0 and C * 2 >= B:
        print(result + Y * B)
        exit()
    elif Y == 0 and C * 2 >= A:
        print(result + X * A)
        exit()

    result += C * 2
    X -= 1
    Y -= 1

print(result)

Measured memory_bytes: 3064
// B - Small and Large Integers
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int A,B,K; cin>>A>>B>>K;
	int n = B-A+1;
	if(n > 2*K){
		rpz(i, K) cout<< A+i <<endl;
		rp(i, n-K, n) cout<< A+i <<endl;
	}
	else rpz(i, n) cout<< A+i <<endl;
}

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

#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(v,a,b) for(int v=(a); v<=(b); v++)
#define fr(v,a,b) for(int v=(a); v>=(b); v--)
#define rng(v,a,b) for(int v=(a); v<(b); v++)

using namespace std;
typedef long long ll;
template<typename T> T& chmax(T& a, T b) { a = a > b ? a : b; return a;}
template<typename T> T& chmin(T& a, T b) { a = a < b ? a : b; return a;}
const int maxn=10+1,maxd=10+1;
const double eps=1e-6;
int n,d;
int p[maxn][maxd];
double calc(int i, int j)
{
	ll res = 0;
	fo(k,1,d) {
		res += (p[i][k]-p[j][k])*(p[i][k]-p[j][k]);
	}
	return sqrt(res);
}
int main()
{
	boost;
	cin >> n >> d;
	fo(i,1,n) {
		fo(j,1,d) cin >> p[i][j];
	}
	int ans = 0;
	fo(i,1,n) {
		fo(j,i+1,n) {
			// if(i == j) continue;
			double res = calc(i, j);
			if(fabs((int)res - res) <= eps) ans++;
		}
	}
	cout << ans;
	return 0;
}


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

int main(void){
  string s;
  while(cin>>s){
    vector<int> row;
    for(int i=0;i<10;i++){
      row.push_back(s[i]-'0');
    }

    while(row.size()>1){
      vector<int> under;
      for(int i=0;i<row.size()-1;i++){
        under.push_back(row[i]+row[i+1]);
      }
      row=under;
    }
    cout<<row[0]%10<<endl;

  }
  return 0;
}



Measured memory_bytes: 3176
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] ar = new int[N+1];
        for(int i = 0; i<M; i++){
            int l = sc.nextInt()-1;
            int r = sc.nextInt();
            ar[l]++;
            ar[r]--;
        }
        int cnt  = 0;
        if(ar[0] == M) cnt++;
        for(int i = 1; i<N+1; i++){
            ar[i]+=ar[i-1];
            if(ar[i] == M) cnt++;
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 64908
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 2e5 + 10;
int H, W;
int N;
int X[MAX], Y[MAX];
VI v[MAX];

int main(void) {
    cin >> H >> W >> N;
    {
        set<PII> dame;
        REP(i, N) {
            cin >> X[i] >> Y[i];
            X[i]--;
            Y[i]--;
            if (X[i] == 1 && Y[i] == 0) {
                cout << 1 << endl;
                return 0;
            }
            dame.emplace(X[i], Y[i]);
        }
        FORE(e, dame) {
            v[e.first].EB(e.second);
        }
    }

    int w_movable = 0;
    FOR(i, 1, H) {
        w_movable += !count_if(ALL(v[i]), [&](int x) {
            return x == w_movable + 1;
        });
        FORE(e, v[i + 1]) {
            if (e <= w_movable) {
                cout << i + 1 << endl;
                return 0;
            }
        }
    }
    cout << H << endl;
}


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

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define REP(i,n) FOR(i,0,n)

int N, M, X, A;
int cost[101] = {0};

int main() {
  scanf("%d%d%d", &N, &M, &X);
  REP(i,M) {
    scanf("%d", &A);
    cost[A] = 1;
  }

  FOR(i,1,N+1) cost[i] += cost[i-1];

  int minval = cost[X] < cost[N] - cost[X] ? cost[X] : cost[N] - cost[X];
  printf("%d\n", minval);
  return 0;
}

Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
 
 
 
array=[a,b,c,d,e]
if(max(array)-min(array) <= k):
    print("Yay!")
else:
    print(":(")

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

int main(){
    int a,b;
    char op;
    while(cin >>a>>op>>b){

        if(op=='+'){        
        cout<<a+b<<endl;
        }else if(op=='-'){        
        cout<<a-b<<endl;
        }else if(op=='*'){        
        cout<<a*b<<endl;
        }else if(op=='/'){        
        cout<<a/b<<endl;
        }else if(op=='?'){        
            break;
        }
        
    }
    return 0;
}


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

#define MAX 100

int N;
int h[MAX];
int c[MAX + 1];

int main() {
	cin >> N;
	for( int i = 0; i < N; i++ ) {
		cin >> h[i];
	}

	int ans = 0;
	while( 1 ) {
		int i = max_element( h, h + N ) - h;
		int ma = h[i];
		if( ma <= 0 ) {
			break;
		}
		for( ; h[i] == ma; i++ ) {
			h[i]--;
		}
		ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
using System;
class Watch{
	public static void Main(){
		int h, m, s;
		int S = int.Parse(Console.ReadLine());
		m = S / 60;
		h = m / 60;
		m = m % 60;
		s = S % 60;
		Console.WriteLine("{0}:{1}:{2}", h, m, s);
	}
}

Measured memory_bytes: 9224
#include <cstdio>
#include <vector>

int n, m, d, p;

int main()
{
    while(true)
    {
        scanf("%d", &n);
        scanf("%d", &m);
        
        if(n == 0 && m == 0) { break; }
        
        std::vector<int> r(11);
        
        for(int i = 0; i < n; i++)
        {
            scanf("%d", &d);
            scanf("%d", &p);
            
            r[p] += d;
        }
        
        for(int i = 10; i >= 0; i--)
        {
            if(m >= r[i])
            {
                m -= r[i];
                
                r[i] = 0;
            }
            else
            {
                r[i] -= m;
                
                break;
            }
        }
        
        int sum = 0;
        
        for(int i = 0; i <= 10; i++)
        {
            sum += i * r[i];
        }
        
        printf("%d\n", sum);
    }
    
    return 0;
}

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

int Child_pos[100010] = { 0 };
string S;
int i, j;

int main(){
    cin >> S;

    i = 0;
    while(i < S.size()){
        char c = S[i];
        j = 0;
        while(S[i+j] == c) ++j;  //cの連続数
        if(c == 'R'){
            Child_pos[i+j-1] += (j+1)/2;
            Child_pos[i+j] += j/2;
        }else if(c == 'L'){
            Child_pos[i-1] += j/2;
            Child_pos[i] += (j+1)/2;
        }
        i += j;
    }

    for(i = 0; i < S.size(); i++) cout << Child_pos[i] << endl;

    return 0;
}

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

int main(){
  int N,M;
  cin>>N;
  M=N;
  
  int sum=0;
  
  while(N>0){
  	sum+=N%10;
    N/=10;
  }
  
  if(M%sum==0){
  	cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef long long int llint;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int,int>
#define pl pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
const ll DEP = (1LL << 50);
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
template<typename T>
T GCD(T x,T y){
    return y ? GCD(y,x%y) : x;
}
int main(){
    string s; cin >> s;
    map<char,int> mp;
    for(int i = 0; i < s.size(); i++){
        mp[s[i]]++;
    }
    int mx = 0;
    for(char t = 'a'; t <= 'z'; t++){
        if (mp[t] > mx){
            mx = mp[t];
        }
    }
    if (mx == s.size()){
        cout << 0 << endl;
        return 0;
    }
    bool ans = true;
    int cnt = 0;
    int res = MM;
    char ff;
    for(char i = 'a'; i <= 'z'; i++){
        cnt = 0;
        ff = i;
        string tmp1=s,tmp2="";
        while(true){
            ans = true;
            for(int i = 0; i < tmp1.size()-1; i++){
                if (tmp1[i] == ff && tmp1[i+1] == ff && i+1 < tmp1.size()) tmp2 += ff;
                else if (tmp1[i] == ff || tmp1[i+1] == ff){
                    tmp2 += ff;
                } else {
                    tmp2 += s[i];
                    ans = false;
                }
            }
            //cout << "tmp2=" << tmp2 << endl;
            tmp1 = tmp2;
            tmp2 = "";
            cnt++;
            if (ans){
                break;
            }
        }
        res = min(res,cnt);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void swap(int *a, int *b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}


int bubbleSort(int A[],int N) {
    int i,j;
    int sw = 0;
    unsigned short flag = 1;
    for(i=0;flag;i++) {
        flag = 0;
        for(j=N-1;j>=i+1;j--) {
            if(A[j]<A[j-1]) {
                swap(&A[j],&A[j-1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

int main(void) {
    int i, A[100], N, sw;
    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&A[i]);

    sw = bubbleSort(A,N);

    for(i=0;i<N;i++) {
        if (i) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n%d\n",sw);

    return 0;
}


Measured memory_bytes: 2104
from sys import stdin

def main():

    input = stdin.readline

    N,K = map(int,input().split())

    A = list(map(int,input().split()))

    itta_set = set()
    itta_list = []
    idou_num = 0

    pos = 0

    for i in range(K):
        # itta_list記憶
        if pos not in itta_set:
            itta_set.add(pos)
            itta_list.append(pos)
        else:
            idou_num = i
            break

        # 次の街へ
        pos = A[pos] - 1
    else:
        ans_num = pos + 1
        print(ans_num)
        return

    roop_list = itta_list[itta_list.index(pos):]

    amari = (K - idou_num) % len(roop_list)

    ans_pos = roop_list[amari] + 1

    print(ans_pos)

if __name__ == "__main__":
    main()

Measured memory_bytes: 114044
def main():
    cost = [[1e10 for j in range(10)]for i in range(10)]
    h,w = map(int,input().split())
    for i in range(10):
        tmp = list(map(int,input().split()))
        for j in range(10):
            if tmp[j] != -1:
                cost[i][j]=tmp[j]
    
    a = list()
    for i in range(h):
        tmp = list(map(int,input().split()))
        a.append(tmp)
    


    for k in range(10):
        for i in range(10):
            for j in range(10):
                cost[i][j] = min(cost[i][k]+cost[k][j],cost[i][j])
    
    ans = 0
    for i in range(h):
        for j in range(w):
            if a[i][j] != -1:
                ans += cost[a[i][j]][1]

    print(ans)
    return

if __name__ == "__main__":
    main()
    

Measured memory_bytes: 40284
/*********************************
*include
*********************************/
#include <stdio.h>
#include <stdlib.h>
#pragma warning (disable:4996)

/*********************************
*define
*********************************/

/*********************************
*function
*********************************/
int main(void)
{
	int array_number;
	int *array;
	int loop;

	scanf("%d", &array_number);
	array = (int *)malloc( sizeof(int) * array_number );

	for(loop = 0; loop < array_number; loop++){
		scanf("%d", array + loop);
	}

	for( loop = array_number - 1; loop >= 0; loop-- ){

		if(loop == 0){
			printf("%d\n", *(array + loop));
		}else{
			printf("%d ", *(array + loop));
		}
	}

	free(array);
	
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vii         vector<pair<int,int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define endl '\n'
#define int long long int
using namespace std;
vector<int> lps;
void lpsComp(string pat) 
{ 
    int len = 0; 
    lps.resize(pat.size());
    lps[0] = 0; 

    int i = 1; 
    while (i < pat.size()) { 
        if (pat[i] == pat[len]) { 
            lps[i] = ++len;
            i++; 
        } 
        else // (pat[i] != pat[len]) 
        { 
            if (len != 0) { 
                len = lps[len - 1]; 
            } 
            else // if (len == 0) 
            { 
                lps[i] = 0; 
                i++; 
            } 
        } 
    } 
}
const int lim = (int)6e5;
bool match[lim] = {0};
int len[lim] = {0};
int vis[lim] = {0};

string s, t;
int best= 0;
bool cycle =false;
// 0 is unvisited, 1 is currently visited, 2 is retired
int dfs(int i){
   if(vis[i] == 2)return len[i];
   if(vis[i] == 1){cycle = true; return len[i];}
   vis[i] = 1;
   int nex = (i + t.length())% s.length();
   int ans = 1;
   if(match[nex]){
    ans += dfs(nex); 
   }
   vis[i] = 2;
   len[i] =ans;
   best = max(ans, best);
   return ans;
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    //freopen("in", "r", stdin);
    cin >> s >> t;
    lpsComp(t);
    //matching loop
    int pre = 0; //matching at pre th position
    int cnt = 0;
    for(int i = 0; cnt < (s.length() + t.length()) * 2; cnt++, i++, i %= s.length()){
        //    cout << pre <<endl;
//        if(i == s.length())break;
        if(t[pre] == s[i]){ 
            pre++;
        }else if(pre != 0){
            pre = lps[pre - 1];
            i--;
        }
        if(pre == t.length()){
            // i th position is the ending
            int start  = (i - (int)t.length() + 1);
            start %= (int)s.length();
            while(start < 0)start += s.length();
            if(match[start])break;
            match[start] = true;
     //       debug(start + t.length());
            pre = lps[pre- 1];
        }
    }
    FOR(i, s.length()){
        if(match[i] && !vis[i]){
            dfs(i);
        }
    }
    if(cycle)cout << -1;
    else cout << best;


}




Measured memory_bytes: 22556
def solve():
    n,m=map(int,input().split())
    H=list(map(int,input().split()))
    A=[[0,0] for i in range(n)]
    for i in range(m):
        a,b=map(int,input().split())
        if(H[a-1]>H[b-1]):
            A[a-1][0]+=1
            A[a-1][1]+=1
            A[b-1][1]+=1
        elif(H[a-1]<H[b-1]):
            A[b-1][0]+=1
            A[a-1][1]+=1
            A[b-1][1]+=1
        else:
            A[a-1][1]+=1
            A[b-1][1]+=1
    count=0
    # print(A)
    for i in range(n):
        if(A[i][0]==A[i][1]):
            count+=1
    print(count)
solve()

Measured memory_bytes: 22648
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String s=sc.next();
    String t=sc.next();
    sc.close();
    String predict[]=new String[3];
    String real[]=new String[3];
    int cnt=0;
    for(int i=0;i<3;i++){
      predict[i]=s.substring(i,i+1);
      real[i]=t.substring(i,i+1);
      if(predict[i].equals(real[i])){
        cnt++;
      }
    }
    System.out.println(cnt);
  }
}

Measured memory_bytes: 21588
#include<iostream>
using namespace std;
int n,a[1<<17],G,F[31],res,R,i,j,cnt;
main(){
cin>>n;
for(i=0;i<n;i++){
cin>>a[i];res^=a[i];
R=a[i]^(a[i]-1);
for(j=1;j<31;j++){
if(R==(1<<j)-1)F[j-1]++;
}
}
for(i=29;i>=0;i--){
if(res>=(1<<i)){
if(F[i]==0){cout<<"-1\n";return 0;}
res^=(1<<(i+1))-1;
cnt++;
}
}
if(res==0)cout<<cnt<<endl;else cout<<"-1\n";
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

typedef pair<int,int> pint;
pint team[100];
int rk[100];

int main(){
    int n,a,b,c,d;
    cin>>n;
    for(int i=0;i<n;++i) team[i]=make_pair(0,i);
    for(int i=0;i<n*(n-1)/2;++i){
        cin>>a>>b>>c>>d;
        if(c>d) team[a-1].first +=3;
        else if(c<d) team[b-1].first +=3;
        else{
            ++team[a-1].first,++team[b-1].first;
        }
    }
    int r=0,t=334,t2=0;
    sort(team,team+n,greater<pint>());
    for(int i=0;i<n;++i){
        if(t==team[i].first){rk[team[i].second]=r;t2++;}
        else{r+=t2;rk[team[i].second]=++r;t2=0;}
        t=team[i].first;
    }
    for(int i=0;i<n;++i) cout<<rk[i]<<endl;
    return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <string.h>
#include <queue>
#include <limits.h>
#include <cstdio>
using namespace std;

struct Point
{
	int x;
	int y;
	Point(int x_,int y_):x(x_),y(y_){}
};

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

int main(void)
{
	while(1){
		int w,h;
		int field[105][105] = {};
		int costfield[105][105];
		Point gPoint(0,0);
		cin >> w >> h;

		for(int i=0;i<105;++i){
			for(int j=0;j<105;++j){
				costfield[i][j] = INT_MAX;
				if(i==0||j==0||i==h+3||j==w+3)
					costfield[i][j] = -1;
			}
		}

		if(w == 0 && h == 0)
			return 0;
		for(int y=1;y<=h+2;++y){
			for(int x=1;x<=w+2;++x){
				if(x==1 || y==1 || x==w+2 || y==h+2)
				{
					field[y][x] = '.';
				}
				else{
					scanf(" %c",&field[y][x]);
					if(field[y][x] == '&')
						gPoint = Point(x,y);
				}
			}
		}
		costfield[1][1] = 0;

		queue<Point> que;
		que.push(Point(1,1));
		while(!que.empty()){
			Point now = que.front();
			que.pop();
			for(int i=0;i<4;++i){
				Point next(now.x+dx[i],now.y+dy[i]);
				int c = costfield[now.y][now.x] + (field[now.y][now.x] == '.' && field[next.y][next.x] == '#' ? 1 : 0);
				if(c < costfield[next.y][next.x]){
					costfield[next.y][next.x] = c;
					que.push(next);
				}
			}
		}
		cout << costfield[gPoint.y][gPoint.x] << endl;
	}
	return 0;
}

Measured memory_bytes: 1340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
# define M_PI           3.14159265358979323846
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	double n;
	cin>>n;
	double x=2*M_PI*n;
	cout<<x;
	return 0;
}

Measured memory_bytes: 3804
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
#include "algorithm"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
const int INF=INT_MAX;

int main(){
  int n;
  cin>>n;
  vll a(n);
  ll m1=0,m2=0;
  int x=0;
  REP(i,n){
    cin>>a[i];
    if(m1<a[i]){x=0;m2=m1;m1=a[i];}
    else if(m1==a[i]){x++;}
    else if(m2<a[i]){m2=a[i];}
  }
  REP(i,n){
    if(x==0){
      if(a[i]==m1){
        cout<<m2<<endl;
      }
      else{
        cout<<m1<<endl;
      }
    }
    else{
      cout<<m1<<endl;
    }
  }
}



Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main(){

    string s;
    cin>>s;
    int n = (int)s.size();
    int c = 0;
    long long ans = 0;
    for ( int i= 0 ; i < n; i++ ){
        if( s[ i ] == 'B') c++;
        else ans += c;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;


const ll MOD = 1e9+7;

signed main(){
    ll n;
    cin >> n;
    string s[n];
    map<string,ll> m;
    rep(i,0,n){
        cin >> s[i];
        if(m.count(s[i]) == 0){
            m[s[i]] = 1;
        }
        else{
            m[s[i]]++;
        }
    }

    string t[4] = {"AC","WA","TLE","RE"};

    rep(i,0,4){
        if(m.count(t[i]) == 0){
            cout << t[i] << " x " << 0 << endl;
        }
        else{
            cout << t[i] << " x " << m[t[i]] << endl;
        }
    }
}


Measured memory_bytes: 6760
n, m = map(int, input().split())
p = list(range(n+1))
x = [0]*(n+1)
def find(i):
    if p[i] == i:
        return i
    p[i], x[i] = find(p[i]), x[i]+x[p[i]]
    return p[i]
for _ in range(m):
    l, r, d = map(int, input().split())
    pl = find(l)
    pr = find(r)
    if pl == pr and x[r]-x[l] != d:
        print('No')
        break
    else:
        p[pr] = pl 
        x[pr] = x[l] + d - x[r]
else:
    print('Yes')


Measured memory_bytes: 9972
#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;
}();
// freopen("input.txt", "r", stdin);

// case len2
//1~4
//0: 11 22 33 44
//1: 12 21 23 32 34 43
//2: 13 31 24 42
//3: 14 41

//n^2
//n, (n-1)*2, (n-2)*2 + (n-3)*2
//n(n-1)
int main() {
    ll n, m, d;
    cin >> n >> m >> d;

    ll cnt_between2 = (d == 0) ? n: (n-d) * 2;
    double acc = double(cnt_between2)/n * (m-1);
    acc /= n;
    cout << fixed << setprecision(12) << acc << endl;
    return 0;
}



Measured memory_bytes: 256