akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

struct UnionFind
{
    vector<int> par;
    vector<int> rank;
    vector<int> num;

    UnionFind(int N) : par(N), rank(N), num(N)
    {
        for (int i = 0; i < N; i++)
        {
            par[i] = i;
            rank[i] = 0;
            num[i] = 1;
        }
    }

    void init(int N)
    {
        for (int i = 0; i < N; i++)
        {
            par[i] = i;
            rank[i] = 0;
            num[i] = 1;
        }
    }

    int root(int x)
    {
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    int ranker(int x)
    {
        x = root(x);
        return rank[x];
    }

    int number(int x)
    {
        x = root(x);
        return num[x];
    }

    void unite(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
            return;
        if (rank[rx] < rank[ry])
        {
            par[rx] = ry;
            num[ry] += num[rx];
            num[rx] = 0;
        }
        else
        {
            par[ry] = rx;
            num[rx] += num[ry];
            num[ry] = 0;
            if (rank[rx] == rank[ry])
                rank[rx]++;
        }
    }

    bool same(int x, int y)
    {
        return root(x) == root(y);
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N, M, K;
    cin >> N >> M >> K;

    UnionFind F(N);
    map<ll, ll> df,db;

    rep(i,M){
        ll A, B;
        cin >> A >> B;
        --A, --B;
        F.unite(A, B);
        df[A]++;
        df[B]++;
    }

    rep(i,K){
        ll C, D;
        cin >> C >> D;
        --C, --D;
        if(F.same(C,D)){
            db[C]++;
            db[D]++;
        }
    }

    rep(i, N) cout << F.number(i) - df[i] - db[i] - 1 << " ";

    return 0;
}

Measured memory_bytes: 14720
def abc():
    players = dict()
    players['a'] = list(input().rstrip())
    players['b'] = list(input().rstrip())
    players['c'] = list(input().rstrip())

    p = 'a'
    while True:
        if len(players[p]) == 0:
            print(p.upper())
            return
        p = players[p].pop(0)


abc()


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

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << c << " "<< a << " "<< b;

    return 0;
}

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

using namespace std;

char ch[61][61]; 

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

int main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>ch[i][j];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{	
			if(ch[i][j]!='#'){
			int t=0;
				for(int k=1;k<=8;k++)
				{
					if(ch[i+dx[k]][j+dy[k]]=='#')
						t++;
				}	
				ch[i][j]=t+'0';
			}
		
		}
	for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
			cout<<ch[i][j];
			cout<<endl;
		}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a<=b&&b<=c){
		printf("%d %d %d",a,b,c);
	}
	else if(a<=c&&c<=b){
		printf("%d %d %d",a,c,b);
	}
	else if(b<=a&&a<=c){
		printf("%d %d %d",b,a,c);
	}
	else if(b<=c&&c<=a){
		printf("%d %d %d",b,c,a);
	}
	else if(c<=a&&a<=b){
		printf("%d %d %d",c,a,b);
	}
	else if(c<=b&&b<=a){
		printf("%d %d %d",c,b,a);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 600
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <queue>
#include <limits>
#include <deque>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <map>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>
#include <cwchar>
#include <cwctype>
#define mp make_pair
#define fs first
#define se second
#define memset(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define MN 0LL
#define Mx 2000000005
#define Mn -Mx
#define MX 20000000000000005
using namespace std;
int readint(){
	char c;
	while(c=getchar(),(c<'0'||c>'9')&&c!='-');
	bool flag=(c=='-');
	if(flag)c=getchar();
	int x=0;
	while(c>='0'&&c<='9'){
		x=x*10+c-48;
		c=getchar();
	}
	return flag?-x:x;
}
inline string tos(int x){
	string s;
	while(x) s=(char)(x%10+'0')+s,x/=10;
	return s;
}
inline int pt(int a[],int l,int r){
	int p,i,j;
	p=a[l];
	i=l;
	j=r+1;
	for(;;){
		while(a[++i]<p) if(i>=r) break;
		while(a[--j]>p) if(j<=l) break;
		if(i>=j) break;
		else swap(a[i],a[j]);
	}
	if(j==l) return j;
	swap(a[l],a[j]);
	return j;
}
inline void q_sort(int a[],int l,int r){
	int q;
	if(r>l){
		q=pt(a,l,r);
		q_sort(a,l,q-1);
		q_sort(a,q+1,r);
	}
}
int dist[100005];
priority_queue<pair<int,int> ,vector<pair<int,int> > ,greater<pair<int,int> > > pq;
int n;
int main(){
	cin>>n;
	int i,j;
	memset(dist,0x3f);
	for(i=1;i<10;i++){
		if(dist[i%n]>i){
			dist[i%n]=i;
			pq.push(mp(i,i%n));
		}
	}
	while(!pq.empty()){
		pair<int,int> x=pq.top();
		pq.pop();
		if(dist[x.second]!=x.first) continue;
		for(i=0;i<10;i++){
			int nxt=x.second*10+i;nxt%=n;
			if(dist[nxt]>dist[x.second]+i){
				dist[nxt]=dist[x.second]+i;
				pq.push(mp(dist[nxt],nxt));
			}
		}
	}
	cout<<dist[0]<<endl;
	return 0;
}


Measured memory_bytes: 2804
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

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

func solve(n int, a, b []int) int {
	ans := 0
	for i := 0; i < n; i++ {
		if a[i] >= b[i] {
			a[i] -= b[i]
			ans += b[i]
			b[i] = 0
		} else {
			b[i] -= a[i]
			ans += a[i]
			a[i] = 0
			if a[i+1] >= b[i] {
				a[i+1] -= b[i]
				ans += b[i]
				b[i] = 0
			} else {
				b[i] -= a[i+1]
				ans += a[i+1]
				a[i+1] = 0
			}
		}
	}

	return ans
}

func main() {
	n, _ := strconv.Atoi(input())
	a := make([]int, n+1)
	b := make([]int, n)
	for i := 0; i < n+1; i++ {
		a[i], _ = strconv.Atoi(input())
	}
	for i := 0; i < n; i++ {
		b[i], _ = strconv.Atoi(input())
	}

	fmt.Println(solve(n, a, b))
}


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

constexpr int M = 300;
bool a[M][M];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h, w; cin >> h >> w;
    for (int i = 0; i < h; i++) {
        string s; cin >> s;
        for (int j = 0; j < w; j++) {
            if (s[j] == '#') a[i][j] = 1;
        }
    }
    auto in = [&](const int &x, const int &y) {
        return 0 <= x && x < h && 0 <= y && y < w;
    };
    auto f = [&](const int &s, const int &t, const int &c) {
        int x, y;
        if (c == 0) x = (s + t) / 2, y = (s - t) / 2;
        else if (c == 1) x = (s - t) / 2, y = M - 1 - (s + t) / 2;
        else if (c == 2) x = M - 1 - (s + t) / 2, y = M - 1 - (s - t) / 2;
        else x = M - 1 - (s - t) / 2, y = (s + t) / 2;
        if (in(x, y)) return a[x][y];
        return false;
    };

    long long ans = 0, ans2 = 0;
    for (int c = 0; c < 4; c++) {
        for (int s = 0; s < 2*M-1; s++) {
            for (int d = 2; s+d < 2*M-1; d += 2) {
                int ss = s+d, curr = 0, yi = max(0, s-M+1);
                for (int i = 0; i < d/2; i++) {
                    if (f(ss, ss-2*(yi+i), c) && f(ss, ss-2*(yi+i)-d, c)) curr++;
                }
                for (int y = yi; y < M; y++) {
                    bool p = f(ss, ss-2*(y+d), c) && f(ss, ss-2*(y+d)+d, c);
                    bool q = f(ss, ss-2*y, c) && f(ss, ss-2*y-d, c);
                    if (p) curr++;
                    if (f(s, s-2*y, c)) {
                        ans += curr; ans2 += p; ans2 += q;
                        // if (curr) cout << c << " " << curr << " " << s << " " << d << "\n";
                    }
                    if (q) curr--;
                }
            }
        }
    }
    cout << ans - ans2 / 2 << "\n";
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, a, b;
  cin >> k >> a >> b;
  for(int i=a; i<=b; i++){
    if(i%k==0){
      cout << "OK"<< endl;
      exit(0);
    }
  }
  cout << "NG" << endl;
}

Measured memory_bytes: 3632
MOD = 10 ** 9 + 7

from operator import mul
from functools import reduce

def nCr(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under



S = int(input())
ans = 0
for i in range(1, S):
    if S - i * 3 < 0:
        break
    ans += nCr(S - i * 3 + i - 1, i - 1)
print(ans % MOD)

Measured memory_bytes: 9448
import numpy as np
import math
INF = float('inf')

def rec(k,und,ans):
	#print(k,ans)
	if(k==N):
		if(sum(und >= X) == len(und)):
			return ans
		else:
			return INF
	else:
		return min(rec(k+1,und+CA[k][1:],ans+CA[k][0]),rec(k+1,und,ans))	


N,M,X = map(int,input().split())

CA = [[None for i in range(M+1)] for j in range(N)] 
for i in range(N):
	CA[i] = list(map(int,input().split()))


und =  np.array([0 for i in range(M)])	
ans = rec(0,und,0)
print(-1 if ans==INF else ans)

Measured memory_bytes: 27268
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);

      int N =sc.nextInt();
      int A =sc.nextInt();
      int B =sc.nextInt();
      
      int train =A*N;
      int taxi =B;
      
      if(train<taxi){
      System.out.print(train);
      }
      else{
      System.out.print(taxi);
      }
    }
}

Measured memory_bytes: 22868
import java.util.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a<b) {
            System.out.println("a < b");
        } else if (a>b) {
            System.out.println("a > b");
        } else {
            System.out.println("a == b");
        }

    }
}



Measured memory_bytes: 26144
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 3e5 + 10;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
int h,w,m;
struct uzi{
  int x,y;
  bool operator < (const uzi & t)const{
    if(x==t.x)return y<t.y;
    return x<t.x;
  }
}p[N];
int L[N],R[N];
int t[N<<2];
#define mid (l+r>>1)
#define ls o<<1
#define rs o<<1|1
void build(int o,int l,int r){
  if(l==r){
    t[o]=R[l];
    return;
  }
  build(ls,l,mid);
  build(rs,mid+1,r);
  t[o]=max(t[ls],t[rs]);
}
void up(int o,int l,int r,int x,int y){
  if(l==r){
    t[o]+=y;
 //   cout<<l<<' '<<r<<' '<<t[o]<<endl;
    return;
  }
  if(x<=mid)up(ls,l,mid,x,y);
  else up(rs,mid+1,r,x,y);
  t[o]=max(t[ls],t[rs]);
}
int main() {
  ios::sync_with_stdio(false);
  cin>>h>>w>>m;
  for(int i=1;i<=m;i++){
    cin>>p[i].x>>p[i].y;
    L[p[i].x]++;
    R[p[i].y]++;
  }
  build(1,1,w);
  sort(p+1,p+1+m);
  int ans=0;
  for(int i=1;i<=m;i++){
    ans=max(ans,L[p[i].x]+R[p[i].y]-1);
  }
  int l=1;
  for(int i=1;i<=h;i++){
    int r=l;

    while(r+1<=m&&p[r+1].x==i)r++;
    if(p[r].x>i)
      continue;

   //cout<<"i=="<<i<<' '<<l<<' '<<r<<endl;
  ///  cout<<i<<' '<<L[i]<<' '<<t[1]<<endl;
    for(int j=l;j<=r;j++){
      up(1,1,w,p[j].y,-1);
    }
    //cout<<i<<' '<<L[i]<<' '<<t[1]<<endl;
    ans=max(ans,L[i]+t[1]);
    for(int j=l;j<=r;j++){
      up(1,1,w,p[j].y,1);
    }
    l=r+1;
  }
  cout<<ans<<'\n';
  return 0;
}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define fin(name) freopen(name, "r", stdin)
#define fout(name) freopen(name, "w", stdout)
#define I(x, a) for(auto x : a)
#define F(i, l, r) for(auto i = l; i < r; ++i)
#define E(i, l, r) for(auto i = l; i <= r; ++i)
#define DF(i, l, r) for(auto i = l; i >= r; --i)
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define sz(a) ((int)(a).size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double dbl;
typedef pair <int, int> pii;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)1e9 + 7;
const dbl eps = (dbl)1e-8;
const int maxn = (int)1e5 + 5;
const dbl pi = acos(-1);

int n;
int a[1111];

int main() {
//	fin("t.in");
	sync;
	cin >> n;
	F(i, 0, n) {
		cin >> a[i];
	}
	int cnt = 1;
	int ans = 0;
	a[n] = -1;
	F(i, 1, n + 1) {
		if (a[i] == a[i - 1])
			++cnt;
		else {
			ans += cnt / 2;
			cnt = 1;
		}
	}
	cout << ans << endl;
	return 0;
}

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

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

  int sum = 0;
  sum += b[a[0] - 1];
  for (int i = 1; i < n; i++) {
    sum += b[a[i] - 1];
    if (a[i] - a[i - 1] == 1) {
      sum += c[a[i - 1] - 1];
    }
  }

  cout << sum << endl;

  return 0;
}


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

int main()
{
  string N;
  cin >> N;

  int ans = N.size();

  for (int i = 0; i < 2; i++)
  {
    int cnt = 0;
    for (int j = 0; j < N.size(); j++)
    {
      if ((j % 2 == 0) ^ (N.at(j) == (char)(i + '0')))
        cnt++;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

int main(void)
{
        char A[11],B[11],C[11];
        int ae,be;

        scanf("%s%s%s",A,B,C);

        ae = strlen(A);
        be = strlen(B);

        if(A[ae-1]==B[0] && B[be-1]==C[0])
                printf("YES\n");
        else printf("NO\n");
        return 0;
}

Measured memory_bytes: 128
n=int(input())
input_str = input()
i = 0
count = 0
while True:
    if (n - i) <= 1:
        print(count)
        break
    if input_str[i:(i+2)] == 'OX' or input_str[i:(i+2)] == 'XO':
        count += 1
        i += 2
    else:
        i += 1


Measured memory_bytes: 5788
#include<iostream>
#include<vector>
#include<cstdio>

using namespace std;

long long cnt;
vector<int> G;
void insertionSort(int A[], int n, int g){
    int v,j;
    for(int i = g; i < n; i++){
        v = A[i];
        j = i - g;
        while (j >= 0 && A[j] > v){
            A[j+g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j+g] = v;
    }
}
void shellSort(int A[], int n){
    for (int h = 1; ;){
        if(h > n) break;
        G.push_back(h);
        h = 3*h + 1;
    
    }
    for( int j = G.size()-1; j >= 0; j--){
        insertionSort(A, n, G[j]);
    }
    
}
int main(){
    int n;
    int A[10000000];
    cin >>n;
    for (int i = 0; i < n; i++) scanf("%d", &A[i]);
    cnt = 0;
    
    shellSort(A, n);
    
    cout <<G.size()<<endl;
    
    for(int i = G.size() - 1; i>=0; i--){
        printf("%d",G[i]);
        if(i) cout<<" ";
        
    }
    cout <<endl;
    printf("%d\n", cnt);
    for(int i = 0; i < n; i++){
        printf("%d\n", A[i]);
        
    }
    return 0;
}


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

ll gcd(ll a ,ll b){
    return b?gcd(b,a%b):a;
}

int main(){
  int n;cin >> n;
  vector<ll> a(n);
  vector<ll> r(n,0),l(n,0);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }

  for(int i=0;i<(n-1);i++){
    l[i+1]=gcd(l[i],a[i]);
  }
  for(int i=n-1;i>0;i--){
    r[i-1]=gcd(r[i],a[i]);
  }
  ll ans=1;
  for(int i=0;i<n;i++){
    ans=max(ans,gcd(l[i],r[i]));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define int long long
#define rng(i, l, r) for (size_t i = (l); i < (r); ++i)
#define rep(i, n) rng(i, 0, n)
#define gnr(i, l, r) for (size_t i = (r)-1; i >= (l); i--)
#define per(i, b) gnr(i, 0, b)
#define ALL(obj) (obj).begin(), (obj).end()    //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend() //...,3,2,1
using namespace std;
const int INF = 1e18;
const int MOD = 1000000007;

int H;
vector<int> A(600000);

int left(int idx) { return idx * 2; }
int right(int idx) { return idx * 2 + 1; }

void maxHeapify(int idx)
{
    int largestIdx = idx;
    int leftIdx = left(idx);
    int rightIdx = right(idx);

    if (leftIdx <= H && A[leftIdx] > A[largestIdx])
        largestIdx = leftIdx;
    if (rightIdx <= H && A[rightIdx] > A[largestIdx])
        largestIdx = rightIdx;

    if (idx != largestIdx)
    {
        swap(A[idx], A[largestIdx]);
        maxHeapify(largestIdx);
    }
    return;
}

void buildMaxHeap()
{
    for (int idx = H / 2; 1 <= idx; idx--)
        maxHeapify(idx);
}

void solve()
{

    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

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

    int n;
    cin >> n;
    H = n;
    rep(i, n) cin >> A[i + 1];
    buildMaxHeap();
    rep(i, n)
            cout
        << " "
        << A[i + 1];
    cout << endl;
}

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


Measured memory_bytes: 7400
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin >> N;
    for(int i = 1;i < 10;i++){
        if(N % i == 0 && N / i <= 9){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve();
        }

        public void Solve()
        {
            var cin = new MyInputStream();

            var N = cin.r();
            if (N.Contains("9")) WriteLine("Yes");
            else WriteLine("No");
        }
    }

    public class MyInputStream
    {
        private char separator = ' ';
        private Queue<string> inputStream;
        public MyInputStream(char separator = ' ')
        {
            this.separator = separator;
            inputStream = new Queue<string>();
        }

        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = Console.ReadLine().Trim().Split(separator);
            for (int i = 0; i < tmp.Length; i++)
            {
                inputStream.Enqueue(tmp[i]);
            }
            return inputStream.Dequeue();
        }
        public string ReadLine() => Console.ReadLine();
        public int ReadInt() => int.Parse(Read());
        public long ReadLong() => long.Parse(Read());
        public double ReadDouble() => double.Parse(Read());
        public string r() => Read();
        public int ri() => ReadInt();
        public long rl() => ReadLong();
        public double rd() => ReadDouble();
    }
}


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

int main()
{
    int num = 0;
    char * pS = NULL;
    int i;
    char b = '\0';
    int count = 1;
    
    //memset(s, 0, sizeof(s));
        // スペース区切りの整数の入力
    scanf("%d",&num);
    
    pS = malloc(num);
    memset(pS, 0, num);
    
    scanf("%s",pS);
    
    for(i = 0;i < num; ++i){
        if(i == 0){
            b = pS[i];
            continue;
        }
        
        if( b!= pS[i]){
            ++count;
            b = pS[i];
        }

    }
    
    printf("%d", count);
        //printf("%d\n", sizeof(s));
    
    return 0;
    
}



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

int main(){
    int a;
    int b;
    int c;
    int y = 0;
    cin >> a >> b >> c;
    for (int x=a;x<=b;x++){
        if (c%x==0){
            y++;
        }
    }
    cout << y << endl;
    return 0;
}


Measured memory_bytes: 3104
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n,ans=1e7,sa,sb;
int a[1000];
int f[100001],t;
bool cmp(int a,int b)
{
	return a>b;
}
void dfs(int s,int cnt)
{
	if (f[s]<=cnt) return;
	if (!s)
	{
		ans=min(ans,cnt); return;
	}
	f[s]=cnt;
	for (int i=1;i<=t;i++)
	  if (s>=a[i]) dfs(s-a[i],cnt+1);
}
int main()
{
	cin>>n; 
	memset(f,127/3,sizeof(f));
	int aa=1;
	while (aa<=100000) a[++t]=aa,aa*=6;
	aa=9;
	while (aa<=100000) a[++t]=aa,aa*=9;
	sort(a+1,a+t+1,cmp);
	dfs(n,0);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
using System;

namespace ABC168B
{
    class Program
    {
        static void Main(string[] args)
        {
            var K = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();

            if (S.Length <= K)
            {
                Console.WriteLine(S);
                return;
            }

            Console.WriteLine(S.Substring(0, K) + "...");
        }
    }
}


Measured memory_bytes: 27400
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
using namespace std ;

typedef long long ll ;
#define rep (i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int N;
	string s;
	cin >> N >> s;

	map<char, int> dict;// = {{'E',0}, {'W',0}};
	dict['E'] = 0;
	dict['W'] = 0;
	
	int w[N];

	for (int i = 0; i < N; i++)
	{
		if (s[i] == 'E')
		{
			dict['E']++;
			w[i] = w[i-1];
		}
		else
		{
			dict['W']++;
			if ( i == 0)
			{
				w[i] = 1;
			}
			else
			{
				w[i] = w[i-1] + 1;
			}
			
		}
	}
	std::vector<int> v;
	v.pb(dict['E']);
	v.pb(dict['W']);
	for (int i = 0; i < N; i++)
	{
		if ((i == 0) && (s[i] == 'E'))
		{
			v.pb(dict['E'] - 1);
		}
		else
		{
			int turnE, turnW;
			if (s[i] == 'W')
			{
				turnE = w[i] - 1;
				turnW = dict['E'] - (i - turnE);
				//v.pb(turnE + turnW);
			}
			else
			{
				turnE = w[i];
				turnW = dict['E'] - (i+1 - turnE);
				//v.pb(turnW+turnE);
			}
			v.pb(turnW+turnE);

			//cout << i << ":" << "(turnE=" << turnE << "), (turnW=" << turnW << ")" << endl;
		}
	}

	sort(v.begin(), v.end());

	cout << v[0] << endl;
	
	return 0;
}

Measured memory_bytes: 3852
a, b = map(int, input().split())
d = [True] * (a+1)
for i in range(b):
    d[int(input())] = False
e = [0] * (a+1)
for i in range(0, a+1):
    if i < 2:
        if d[i]:
            e[i] = 1
        else:
            e[i] = 0
    elif not d[i] and not d[i-1]:
        print(0)
        exit()
    elif d[i]:
        e[i] = (e[i-2] + e[i-1]) % 1000000007
print(e[len(e)-1])


Measured memory_bytes: 7668
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL ans, base[22];
char s[4];
int num;
bool query(LL x){
    printf("? %lld\n", x);
    fflush(stdout);
    scanf("%s", s + 1);
    return s[1] == 'Y';
}
int main(){
    base[0] = 1;
    for(int i = 1;i <= 9; i++){
        base[i] = base[i-1] * 10ll;
        if(!num && !query(base[i])){
            num = i;
        }
    }
    if(!num){
        LL now = 9;
        for(int i = 0;i <= 9; i++){
            if(query(now)){
                printf("! %lld\n", base[i]);
                fflush(stdout);
                return 0;
            }
            now = now * 10ll;
        }
    }
    for(int i = num;i > 1; i--){
        int l = 0, r = 9, now = -1;
        while(l <= r){
            int mid = (l + r) >> 1;
            if(query(ans / base[i-1] + mid)){
                now = max(now, mid);
                l = mid + 1;
            }
            else r = mid - 1;
        }
        ans += 1LL * now * base[i-1];
    }
    for(int i = num == 1;i <= 9; i++){
        if(query((ans + i) * 10ll)){
            printf("! %lld\n", ans + i);
            fflush(stdout);
            break;
        }
    }
    return 0;
}


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

int main()
{
	int A, B;

	cin >> A>>B;

	int kirten = 2 * B;

	int ans;

	if (kirten >= A)
	{
		ans = 0;
	}
	else
	{
		ans = A - kirten;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int c1,c5,c10,c50,c100,c500,C;
    cin >>c1>>c5>>c10>>c50>>c100>>c500;
    C=c1*1+c5*5+c10*10+c50*50+c100*100+c500*500;
    if(1000<=C){
        cout <<"1"<<endl;
    }
    else{
        cout <<"0"<<endl;
    }
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> p(N);
  REP(i, N) cin >> p[i];
  int i = 0;
  int ans = 0;
  while(i < N) {
    if(p[i] == i + 1) {
      ans++;
      i += 2;
    } else {
      i++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: usize = read();
    let b: usize = read();

    if b % a == 0 {
        println!("{}", a + b);
    } else {
        println!("{}", b - a);
    }
}


Measured memory_bytes: 2136
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        long ans = (long)Math.ceil((double)(n-1)/(k-1));
        System.out.println(ans);
    
    }
}

Measured memory_bytes: 23252
import math
n,a,b=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
x.reverse()

j=a+1
moto=0
h=0
d=x[a-1]
asd=0
l=x.count(d)
for i in range(a):
  moto+=x[i]
  if x[i]==x[a-1]:
    h+=1
print(moto/a)
if moto/a==x[a-1]:
  for i in range(a,b+1):
    if l-i>=0:
      asd+=math.factorial(l)//(math.factorial(l-i)*math.factorial(i))
  print(asd)
else:
  print(math.factorial(l)//(math.factorial(l-h)*math.factorial(h))) 

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>
#include <set>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

#define max_n 100

int a;
string s;

int main() {

	cin >> a >> s;

	if(a>=3200)cout << s <<endl;
	else cout << "red" << endl;

	return 0;	
}

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

int main() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> b(m);
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  int xmax = x;
  int ymin = y;
  for (int i = 0; i < n; i++) {
    xmax = max(xmax, a[i]);
  }
  for (int i = 0; i < m; i++) {
    ymin = min(ymin, b[i]);
  }
  if (xmax < ymin) cout << "No War" << endl;
  else cout << "War" << endl;

  return 0;
}
  

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

int main() {
    int n, k;
    cin >> n >> k;

    int ans = 1;
    for (int i = 0; i < n; i++) {
        ans = min(ans * 2, ans + k);
    }

    cout << ans << endl;

    return 0;
}

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

int main(void) {
	double x1, y1, x2, y2;
	double dx, dy;
	scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
	
	printf("%f\n", hypot(x2 - x1, y2 - y1));
	
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w; cin>>h>>w;
    vector<string> t(h);
    rep(i,h) cin>>t[i];
    rep(i,2*h){
        cout<<t[i/2]<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin>>a;
  for(int i=9;i>0;i--){
    if(a%i==0){
        if((a/i)*i==a&&a/i<=9) cout<<"Yes\n";
        else cout<<"No\n";
        break;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using psi=pair<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD ((ll)1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
template<class T>void geti(T&a){for(auto&_:a)cin>>_;}
template<class T>void getii(T&a){for(auto&_:a)geti(_);}
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)
template<class F,class S>void add(map<F,S>&mp,F f,S s){if(mp.find(f)==mp.end())mp[f]=F();mp[f]+=s;}
 
constexpr int gcd(int a,int b){return b?gcd(b,a%b):a;}
constexpr int lcm(int a,int b){return a*b/gcd(a,b);}


int main(){
    dcl(n);
    ll ans=-1,m=1;
    ll cp=n;
    int in=0;
    while(cp){
        in++;
        cp/=10;
    }
    rep(i,in){
        ll tmp=i*9;
        cp=n-(m==1?0:m);
        rep(j,i)cp/=10;
        while(cp){
            tmp+=cp%10;
            cp/=10;
        }
        m*=10;
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
}


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

max_height = heights[0]
total_step = 0

for h in range(1, len(heights)):
    if max_height >= heights[h]:
        total_step = total_step + max_height - heights[h]
    else:
        max_height = heights[h]

print(total_step)

Measured memory_bytes: 32336
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n, q = map(int, input().split())
    s = input()

    ans = [0] * n
    pre = ''
    sum = 0
    for i, w in enumerate(s):
        if pre == 'A' and w == 'C':
            sum += 1
        ans[i] = sum
        pre = w
    
    for i in range(q):
        l, r = map(lambda x: int(x) - 1, input().split())
        print(ans[r] - ans[l])

if __name__ == '__main__':
    main()



Measured memory_bytes: 6276
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
    
#pragma endregion library

int main(){
    int n; cin >> n;
    vi a(3*n); rep(i,3*n) cin >> a[i];
    vll dp1(n+1); vll dp2(n+1);
    priority_queue<int> q1, q2;
    rep(i,n){
        dp1[0]+=a[i];
        q1.emplace(-a[i]);
    }
    rep(i,n){
        if(-q1.top()<a[n+i]){
            dp1[i+1]=dp1[i]+q1.top()+a[n+i];
            q1.pop();
            q1.emplace(-a[n+i]);
        } else {
            dp1[i+1]=dp1[i];
        }
    }    
    rrepi(i,2*n,3*n){
        dp2[n]+=a[i];
        q2.emplace(a[i]);
    }
    rrep(i,n){
        if(q2.top()>a[n+i]){
            dp2[i]=dp2[i+1]-q2.top()+a[n+i];
            q2.pop();
            q2.emplace(a[n+i]);
        } else {
            dp2[i]=dp2[i+1];
        }
    }
    ll ans = -LINF;
    rep(i,n+1){
        ans = max(ans, dp1[i]-dp2[i]);
        
    }
    cout << ans << '\n';
    
}

Measured memory_bytes: 4216
def func(amat, bmat, nm):
    ans = [[0 for i in range(nm[2])] for j in range(nm[0])]
    for i in range(nm[0]):
        for j in range(nm[1]):
            for l in range(nm[2]):
                ans[i][l] += amat[i][j] * bmat[j][l]
    for i in ans:
        print(' '.join(map(str, i)))


if __name__ == '__main__':
    nm = [int(i) for i in input().split(' ')]
    amat = [[0 for i in range(nm[1])] for j in range(nm[0])]
    bmat = [[0 for i in range(nm[2])] for i in range(nm[1])]

    for i in range(nm[0]):
        a = input().split(' ')
        for j in range(nm[1]):
            amat[i][j] = int(a[j])

    for i in range(nm[1]):
        b = input().split(' ')
        for j in range(nm[2]):
            bmat[i][j] = int(b[j])

    func(amat, bmat, nm)

Measured memory_bytes: 8708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const int MAXN = 1000010;
template <typename T> void read(T &x) {
	T f = 1;
	char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
	for (x = 0; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
	x *= f;
}
ll prime[MAXN], cnt;
ll mu[MAXN], sum[MAXN];
bool mark[MAXN];
int N;
ll A[MAXN], C[MAXN];
ll ans;
ll ksm(ll a, ll b) {
	ll ret = 1;
	while (b) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}
void sieve() {
	mu[1] = 1;
	for (int i = 2; i < MAXN; i++) {
		if (!mark[i]) {
			prime[++cnt] = i;
			mu[i] = -1;
		}
		for (int j = 1; j <= cnt && prime[j] * i < MAXN; j++) {
			mark[i * prime[j]] = 1;
			if (i % prime[j] == 0) {
				mu[i * prime[j]] = 0;
				break;
			} else {
				mu[i * prime[j]] = -mu[i];
			}
		}
	}
	for (ll i = 1; i < MAXN; i++) for (int j = i; j < MAXN; j += i) sum[j] = (sum[j] + mu[i] * i) % mod;
}
int main() {
	read(N);
	for (int i = 1; i <= N; i++) read(A[i]), C[A[i]]++, ans -= A[i];
	sieve();
	ans = (ans % mod + mod) % mod;
	for (ll T = 1; T <= 1000000; T++) {
		ll cur = 0;
		for (ll i = 1; i <= 1000000 / T; i++) cur = (cur + C[i * T] * i) % mod;
		ans = ((ans + T * sum[T] % mod * cur % mod * cur % mod) % mod + mod) % mod;
	}
	
	printf("%lld", (ans * ksm(2, mod - 2) % mod + mod) % mod);
	return 0;
}

Measured memory_bytes: 30352
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int h = sc.nextInt();
		int w = sc.nextInt();
		String[] s = new String[h];

		for (int i = 0; i < h; i++) {
			s[i] = sc.next();
		}

		int[][] l = new int[h][w];
		int[][] r = new int[h][w];
		int[][] u = new int[h][w];
		int[][] d = new int[h][w];

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {

				if (s[i].substring(j, j + 1).equals("#")) {
					l[i][j] = 0;
					u[i][j] = 0;
					continue;
				}

				if (i == 0) {
					u[i][j] = 1;
				} else {
					u[i][j] = u[i - 1][j] + 1;
				}

				if (j == 0) {
					l[i][j] = 1;
				} else {
					l[i][j] = l[i][j - 1] + 1;
				}
			}
		}

		for (int i = h - 1; i >= 0; i--) {
			for (int j = w - 1; j >= 0; j--) {

				if (s[i].substring(j, j + 1).equals("#")) {
					r[i][j] = 0;
					d[i][j] = 0;
					continue;
				}

				if (j == w - 1) {
					r[i][j] = 1;
				} else {
					r[i][j] = r[i][j + 1] + 1;
				}

				if (i == h - 1) {
					d[i][j] = 1;
				} else {
					d[i][j] = d[i + 1][j] + 1;
				}
			}
		}

		int max = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				max = Math.max(max, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3);
			}
		}
		System.out.println(max);

	}

}


Measured memory_bytes: 221844
n, x = map(int, input().split())
x -= 1
thick = [1]
for i in range(n):
    thick.append(thick[i] * 2 + 3)


def f(level, layer):
    if level == 0:
        return 1
    elif layer == 0:
        # print('start')
        return 0
    elif 1 <= layer <= thick[level-1]:
        # print('first')
        return f(level-1, layer-1)
    elif layer == thick[level-1]+1:
        # print('half')
        return f(level-1, thick[level-1]-1) + 1
    elif thick[level-1]+2 <= layer <= thick[level-1] * 2 + 1:
        # print('second')
        return f(level-1, thick[level-1]-1) + 1 + f(level-1, layer-thick[level-1]-2)
    elif layer == thick[level-1] * 2 + 2:
        # print('end')
        return f(level-1, thick[level-1]-1) * 2 + 1


print(f(n, x))


Measured memory_bytes: 3064
#create date: 2020-08-02 21:08

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def divisor(n):
    i = 1
    table = [7, ]
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(7*i)
            table.append(n // i)
            table.append((n//i)*7)
        i += 1
    table = set(table)
    return table


def main():
    k = ni()
    a = 0
    for i in range(1, 10**6+1):
        a = (10*a + 7) % k
        if a == 0:
            print(i)
            quit()
    print(-1)

if __name__ == "__main__":
    main()

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

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    string ans;
    string sorw;
    bool flag = true;
    
    for(int i = 1; i <=4  ; i++){
        if(i ==1){
            ans = "WW";
        }else if(i == 2){
            ans = "WS";
        }else if(i == 3){
            ans = "SW";
        }else if(i == 4){
            ans = "SS";
        }
        for(int j = 0 ; j < n ; j++){
            if(ans[j] == 'W' && ans[j+1] == 'W' && s[j] == 'o'){
                sorw = 'S';
            }else if(ans[j] == 'W' && ans[j+1] == 'W' && s[j] == 'x'){
                sorw = 'W';
            }else if(ans[j] == 'W' && ans[j+1] == 'S' && s[j] == 'o'){
                sorw = 'W';
            }else if(ans[j] == 'W' && ans[j+1] == 'S' && s[j] == 'x'){
                sorw = 'S';
            }else if(ans[j] == 'S' && ans[j+1] == 'W' && s[j] == 'o'){
                sorw = 'W';
            }else if(ans[j] == 'S' && ans[j+1] == 'W' && s[j] == 'x'){
                sorw = 'S';
            }else if(ans[j] == 'S' && ans[j+1] == 'S' && s[j] == 'o'){
                sorw = 'S';
            }else if(ans[j] == 'S' && ans[j+1] == 'S' && s[j] == 'x'){
                sorw = 'W';
            }
            
            ans += sorw;
            }
            if(ans[0] == ans[ans.size()-2] && ans[1] == ans[ans.size()-1]){
                //cout << "Break!" << endl;
                flag = false;
                ans = ans.substr(1);
                ans = ans.erase(ans.size()-1,1);
                break;
            }
    }
    if(flag){
        cout << "-1" << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 728
s = gets.chomp
n = s.length
c = [0, 0]
ans = Array.new(n, 0)
for i in 0...n do
  if s[i] == 'R'
    c[i % 2] += 1
  else
    if i % 2 == 0
      ans[i] += c[0]
      ans[i - 1] += c[1]
    else
      ans[i] += c[1]
      ans[i - 1] += c[0]
    end
    c[0] = c[1] = 0
  end
end
for i in 0...n do
  if s[-1 - i] == 'L'
    c[i % 2] += 1
  else
    if i % 2 == 0
      ans[-1 - i] += c[0]
      ans[-i] += c[1]
    else
      ans[-1 - i] += c[1]
      ans[-i] += c[0]
    end
    c[0] = c[1] = 0
  end
end
puts ans.join(" ")


Measured memory_bytes: 15396
//Code by ASIM FOIZE AIMON
//CSE'19;CUET
//avoid copy paste//Hit the frined button
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise cout.precision(10); cout << fixed;
#define endl "\n"
#define int int64_t
#define ll long long
#define yes printf("Yes\n")
#define no printf("No")
int32_t main()
{
    /*#ifndef ONLINE_JUDGE
        freopen("/media/AIMON/SSDVol/Progs/CodeForces/input.txt", "r", stdin);
        freopen("/media/AIMON/SSDVol/Progs/CodeForces/output.txt", "w", stdout);
    #endif*/
    int d,n,c=0;
    cin>>n>>d;
    for(int i=0;i<n;i++)
    {
        double a,b,m,p;
        cin>>a>>b;
        m=(sqrt(a*a+b*b));
        if(m<=d)
            c++;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3780
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define F first
#define S second
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
using ll = long long;
using pi = pair<int,int>;
int main()
{
  int n; cin >> n;
  int t; cin >> t;
  vector<int> a(n),b(n);
  rep(i,n) cin >> a[i] >> b[i];

  vector<vector<int>> dp1(n+1, vector<int>(t, 0)), dp2(n+1, vector<int>(t, 0));
  rep(i,n) {
    rep(j,t) {
      if(j - a[i] >= 0) dp1[i+1][j] = max(dp1[i][j], dp1[i][j-a[i]] + b[i]);
      else dp1[i+1][j] = dp1[i][j];
    }
  }
  for (int i = n; i > 0; --i) {
    rep(j,t) {
      if(j - a[i-1] >= 0) dp2[i-1][j] = max(dp2[i][j], dp2[i][j-a[i-1]] + b[i-1]);
      else dp2[i-1][j] = dp2[i][j];
    }
  }

  int res = 0;
  rep(i,n) {
    rep(j,t) {
      int idx = t - 1 - j;
      int tmp = dp1[i][j] + dp2[i+1][idx];
      chmax(res, tmp + b[i]);
    }
  }
  cout << res << "\n";
  
  return 0;
}


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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k <= a) {
    cout << k << endl;
  }else if (k <= a+b){
    cout << a << endl;
  }else cout << (a*2 + b - k) << endl;
return 0;
}

Measured memory_bytes: 3648
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.typecons;

alias Path = Tuple!(int, "from", int, "to", int, "weight");

auto make_node()
{
    int[100][100] ret;
    foreach (ref l; ret) foreach (ref e; l) e = int.max / 2;
    return ret;
}

auto NS = make_node();
Path[1000] PS;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];

    foreach (i; 0..M) {
        auto abc = readln.split.to!(int[]);
        auto a = abc[0] - 1;
        auto b = abc[1] - 1;
        auto c = abc[2];
        PS[i] = Path(a, b, c);
        NS[a][b] = c;
        NS[b][a] = c;
    }

    foreach (k; 0..N)
        foreach (i; 0..N)
            foreach (j; 0..N)
                if (NS[i][j] > NS[i][k] + NS[k][j])
                    NS[i][j] = NS[i][k] + NS[k][j];

    int cnt;
    foreach (p; PS[0..M]) if (p.weight != NS[p.from][p.to]) ++cnt;
    writeln(cnt);
}

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

int T, N, M, K;
int A, B, C, D;

int main()
{
	string s;
	cin >> K >> s;
	if (s.size() <= K) cout << s;
	else cout << string(s.begin(), s.begin()+K) << "...";
	return 0;
}

Measured memory_bytes: 3624
from collections import defaultdict
N = int(input())

SP = defaultdict(list)
for i in range(1, N + 1):
    S, P = input().split()
    SP[S].append((int(P), i))

items = list(SP.items())
items.sort()
for _, A in items:
    A.sort(reverse=True)
    for _, i in A:
        print(i)



Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <algorithm>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD (ll)(1e9+7)
#define MAX (ll)(1e5*2+200)
#define print(x) cout << x << endl;
#define length(arr) sizeof arr / sizeof arr[0];
#define printArr(arr) REP(i, (sizeof arr / sizeof arr[0])){print(arr[i])}
#define printVec(vec) REP(i, vec.size()){print(vec[i])}

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, h, w;
    cin >> H >>W >>h >>w;
    int ans = H*W - h*W - H*w + h*w;
    
    print(ans)
    
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<cstring>

using namespace std;

int  main(){
    int n;
    cin>>n;
    int  a[n];
    double b[n];
    
    for(int i=0;i<n;i++){
    	cin>>a[i];
	}
    sort(a,a+n);
    b[0]=a[0]*1.0;
    for(int i=1;i<n;i++)
    b[i]=(a[i]*1.0+b[i-1])/2;
    cout<<b[n-1];
    
    
    return 0;		
	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int a, b, c;

int main()
{
    cin >> a >> b >> c;
    if (a == b && b == c && c == a)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
N,M = map(int, raw_input().split())

if abs(N-M)>=2:
  print 0
else:
  mod = 10**9+7
  ans = 1
  for i in range(1, N+1):
    ans *= i
    ans %= mod
  for i in range(1, M+1):
    ans *= i
    ans %= mod
  if N==M:
    ans *= 2
    ans %= mod
  print ans


Measured memory_bytes: 5764
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cstring>
#include <cmath>

using namespace std;

typedef long long ll;

int digit(ll num){
    int count=0;
    if(num==0){
        return 1;
    }
    while(num!=0){
         ++count;
        num=num/10;
       
    }
    return count;
}

int max_d(long long N,long long n){
    return digit(N/n)>digit(n)?digit(N/n):digit(n);
}

int main(){
    
    ll  N,n;
    cin>>N;
    n=sqrt(N)+1;
    //cout<<n<<endl;
    ll i;
    for(i=n;i!=0;--i){
        if(N%i==0){
            break;
        }
    }
    //cout<<i<<endl;
    cout<<max_d(N,i)<<endl;
    
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	string a,b,c;
	std::cin >> a >> b >> c;
	if (a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) {
		std::cout << "YES" << '\n';
	}
	else {
		std::cout << "NO" << '\n';
	}
	return 0;
}


Measured memory_bytes: 256