akhauriyash/Code-Regression huggingface dataset:
from collections import Counter

N, A = list(map(int, input().split()))
x = [int(i) - A for i in input().split()]

sums = Counter([0])

for i in x:
    sums2 = Counter()
    for sm, cnt in sums.items():
        sums2[sm + i] += cnt
    sums += sums2
        
print(sums[0] - 1)

Measured memory_bytes: 3564
#include<iostream>
using namespace std;
      
int main(){
	int sum=0,i;
	for(int j=0;j<2;j++){
		cin>>i;
		if(i==1){
			if(sum==300000) sum+=400000;
			sum+=300000;
		}
		else if(i==2) sum+=200000;
		else if(i==3) sum+=100000;
	}
	cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		LL N; cin >> N;
		vector<LL> A(N); rep(i, N) cin >> A[i];
		ULL S = 0; rep(i, N) S += A[i];
		if (S % (N * (N + 1) / 2) != 0) { cout << "NO" << endl; return; }
		vector<LL> dA(N); rep(i, N - 1) dA[i] = A[i + 1] - A[i]; dA[N - 1] = A[0] - A[N - 1];
		LL moves = S / (N * (N + 1) / 2);
		rep(i, N) dA[i] -= moves;
		//rep(i, N) cout << dA[i] << " "; cout << endl;
		rep(i, N) {
			if (dA[i] > 0) { cout << "NO" << endl; return; }
			if (-dA[i] % N) { cout << "NO" << endl; return; }
			dA[i] = (-dA[i]) / N;
		}
		cout << "YES" << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 1792
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#include<queue>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#define rep(i,n) for (int i=0;i<(n);++i)
using ll = long long;
using namespace std;
using P = pair<int,int>;

int main(){
    int n;
    cin>>n;
    vector<int> L(n);
    rep(i,n){
        cin>>L[i];
    }
    sort(L.begin(),L.end());
    int ans = 0;
    for(int i = 0;i < n;i++){
        for(int j = 0; j < i;j++){
            for(int k  = 0; k < j;k++){
                if(L[i]!=L[j] and L[j]!=L[k] and L[k]+L[j]>L[i]){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define oo 2000000000
const double PI = acos(-1);
const int N = 100010;
int n , m , arr[N] , ans = 0 , root = -1;
vector < int > g[N];

int DFS(int node,int prnt){
    int num1 = 0 , num2 = 0;
    for(int i=0;i<g[node].size();i++){
        if(g[node][i] == prnt) continue;
        int cur = DFS(g[node][i],node);
        if(cur == 1) num1++; else num2++; 
    }
    if(num2 > 0) num2--;
    ans += num2;
    num1 += num2;
    return (num1 > 0);
}

int main(){
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        int u , v;
        scanf("%d%d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int mx = 1;
    for(int i=0;i<n;i++){
        if((int)g[i].size() > mx){
            root = i;
            mx = g[i].size();
        }
    }
    if(root == -1){
        cout << 1 << endl;
        return 0;
    }
    DFS(root,-1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13440
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
using namespace std;

int main(){
	int n, m;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
	}
	cin >> m;
	vector<string> t(m);
	for (int i = 0; i < m; ++i) {
		cin >> t[i];
	}
	int mx = 0, counter;
	for (int i = 0; i < n; ++i) {
		counter = 0;
		for (int j = 0; j < n; ++j) {
			if (s[i] == s[j]) ++counter;
		}
		for (int k = 0; k < m; ++k) {
			if (s[i] == t[k]) --counter;
		}
		mx = max(mx, counter);
	}
	cout << mx << endl;
}

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

const int N = 1e5 + 10;
const int M = 2e5 + 10;
const int INF = 0x3f3f3f3f;

int n, m;
int edges[M];
vector<int> g[N];

void bfs(int s, bool t, vector<int> &d) {
	if (t) {
		vector<bool> used(n+1, false);
		queue<int> q;
		q.push(s);
		used[s] = true;
		while(!q.empty()) {
			int v = q.front(); q.pop();
			for (int u : g[v]) {
				if (used[u]) continue;
				edges[u] = v;
				used[u] = true;
				q.push(u);
			}
		}
		return;
	}

	queue<int> q;
	d[s] = 0;
	q.push(s);
	while(!q.empty()) {
		int v = q.front(); q.pop();
		for (int u : g[v]) {
			if (d[u] != INF) continue;
			d[u] = d[v] + 1;
			q.push(u);
		}
	}
}

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

	for (int i = 0; i < m; ++i) {
		int a, b; cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	vector<int> d(n+1, INF);
	bfs(1, 0, d);
	
	for (int i = 1; i <= n; ++i) {
		if (d[i] == INF) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	bfs(1, 1, d);

	for (int i = 2; i <= n; ++i) {
		cout << edges[i] << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 10568
#include<stdio.h>
typedef struct{
  char form;
  int num;
}card;
int main()
{
  int n,m,i,j,k=0,wr=0;
  scanf("%d",&n);
  card a[n];
  card tmp;
  card b[n];
  for(i=0;i<n;i++){
    scanf(" %c",&a[i].form);
    scanf("%d",&a[i].num);
    if(i!=n-1)scanf(" ");
    b[i]=a[i];
  }
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(a[j].num<a[j-1].num){
        tmp=a[j-1];
        a[j-1]=a[j];
        a[j]=tmp;
      }
    }
    }
  for(i=0;i<n;i++){
    printf("%c%d",a[i].form,a[i].num);
    if(i!=n-1)printf(" ");
    }
    printf("\n");
  printf("Stable\n");
  for(i=0;i<n;i++){
    int minj=i;
    for(j=i;j<n;j++){
      if(b[j].num<b[minj].num){
        minj=j;
      }
    }
    tmp=b[i];
    b[i]=b[minj];
    b[minj]=tmp;
  }
  for(i=0;i<n;i++){
    printf("%c%d",b[i].form,b[i].num);
    if(a[i].num!=b[i].num || a[i].form!=b[i].form)wr++;
    if(i!=n-1)printf(" ");
  }
  printf("\n");
  if(wr!=0){
    printf("Not stable\n");
  }else{
    printf("Stable\n");
  }
  return 0;
}


Measured memory_bytes: 2144
#include<bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n;i>=0;i++)
using namespace std;
signed main(){
  ll a,b,k,cun=0;
  cin>>a>>b>>k;
  for(int i=max(a,b);i>=0;i--){
    if(a%i==0 && b%i==0){
      if(k-1==cun){
        cout<<i<<"\n";
        break;
      }else{
        cun++;
      }
    }
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;

bool prime[1000010];
void furui() {
	int i = 2;
	while (i <= 1000000) {
		int j = 2;
		while (j*j <= i && !prime[i]) {
			if (i%j == 0) {
				prime[i] = true;
				break;
			}
			else j++;
		}
		int z = 2;
		while (!prime[i]) {
			if (i*z <= 1000000) {
				prime[i*z] = true;
				z++;
			}
			else break;
		}
		i++;
	}
}

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

int main(){
    furui();
    int n;
    cin>>n;
    vector<int>a,p;
    int one = 0;
    for(int i=2;i<=1000000;i++){
        if(!prime[i]){
            p.push_back(i);
        }
    }
    int g = 0;
    for(int i=0;i<n;i++){
        int b;
        cin>>b;
        if(i==0)g=b;
        else g = gcd(g,b);
        if(b==1)one++;
        else a.push_back(b);
    }
    if(g!=1)cout<<"not coprime"<<endl;
    else{
        n = n-one;
        if(p.size()<n)cout<<"setwise coprime"<<endl;
        else{
            set<int>s;
            bool flag = false;
            for(int i=0;i<n;i++){
                int t = a[i];
                int L = t;
                for(int j=2;j*j<=L;j++){
                    if(t%j==0){
                        while(t%j==0){
                            t/=j;
                        }
                        if(s.count(j)==0){
                            s.insert(j);
                        }
                        else{
                            flag = true;
                            break;
                        }
                    }
                }
                if(t>1){
                    if(s.count(t)==1){
                        flag = true;
                        break;
                    }
                    else s.insert(t);
                }
                if(flag)break;
            }
            if(flag)cout<<"setwise coprime"<<endl;
            else cout<<"pairwise coprime"<<endl;
        }
    }
}

Measured memory_bytes: 8728
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		long x=sc.nextLong();
		for(int i=0; i<=1000; i++){
			for(int j=-1000; j<=1000; j++){
				if(pow(i,5)-pow(j,5)==x){
					System.out.println(i+" "+j);
					return;
				}
			}
		}
	}
	static long pow(long left,long right){
		long ans=1;
		while(right>0){
			if((right&1)==1){
				ans*=left;
			}
			right>>=1;
			left*=left;
		}
		return ans;
	}
}

Measured memory_bytes: 38940
from scipy.sparse.csgraph import shortest_path
import numpy as np

H, W = map(int, input().split(" "))

M = np.zeros((H * W, H * W))

maiz = []

for _ in range(H):
    maiz.append(input())

move = [
    (1, 0),
    (0, 1),
    (-1, 0),
    (0, -1)
]

def is_valid_move(r, c, dr, dc):
    nr = r + dr
    if not (nr >= 0 and nr < H):
        return False
    
    nc = c + dc

    if not (nc >= 0 and nc < W):
        return False

    if maiz[nr][nc] == '.':
        return True

    return False

for row, row_elem in enumerate(maiz):
    for col, col_elem in enumerate(row_elem):
        if col_elem == "#":
            continue
        for drow, dcol in move:
            if not (is_valid_move(row, col, drow, dcol)):
                continue

            M[row * W + col][(drow + row) * W + col + dcol] = 1
            M[(drow + row) * W + col + dcol][row * W + col] = 1


res = shortest_path(M)
res[res > 10000000000000000000000000] = 0

print(int(np.max(res)))



Measured memory_bytes: 22552
#include<stdio.h>
#include<stdbool.h>
#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N],col[N],dpos[2*N-1],dneg[2*N-1];

bool X[N][N];

void ini(){
int i;
  for(i=0;i<N;i++){
    row[i]=FREE;
    col[i]=FREE;
  }
for(i=0;i<2*N-1;i++){
  dpos[i]=FREE;
  dneg[i]=FREE;
}
}
void pB(){
int i,j;
for(i=0;i<N;i++){
  for(j=0;j<N;j++){
    if(X[i][j]){
      if(row[i]!=j)return;
    }
  }
}
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void recursive(int i){
  if(i==N){
    pB();
    return;
  }
  int j;
for(j=0;j<N;j++){
  if(NOT_FREE==col[j]||
    NOT_FREE==dpos[i+j]||
    NOT_FREE==dneg[i-j+N-1])continue;
row[i]=j;
col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
recursive(i+1);
row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
}
}

int main(){
  ini();
int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++)X[i][j]=false;
  }
int k;
scanf("%d",&k);
for(i=0;i<k;i++){
  int r,c;
  scanf("%d%d",&r,&c);
  X[r][c]=true;
}
recursive(0);
return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=998244353;

#define MAX_N 300020
ll inv[MAX_N+10],fac[MAX_N+10],ifac[MAX_N+10];

void setComb(){
  inv[0]=1;inv[1]=1;fac[1]=1;ifac[1]=1;fac[0]=1;ifac[0]=1;
  for(int i=2;i<MAX_N;i++){
    inv[i]=(-MOD/i)*inv[MOD%i]%MOD;
    fac[i]=fac[i-1]*i%MOD;
    ifac[i]=ifac[i-1]*inv[i]%MOD;

    inv[i]=(inv[i]+MOD)%MOD;
    fac[i]=(fac[i]+MOD)%MOD;
    ifac[i]=(ifac[i]+MOD)%MOD;
  }
  return;
}

ll comb(ll n,ll k){
  if(n<k||n<0||k<0) return 0;
  else return ((fac[n]*ifac[k]%MOD*ifac[n-k]%MOD+MOD)%MOD);
}

ll hcomb(ll n,ll r){
  if(n==0&&r==0) return 1;
  else if(n<0||r<0) return 0;
  else return comb(n+r-1,r-1);
}

int main(){
  int N;
  ll A,B,K;
  cin>>N>>A>>B>>K;

  setComb();

  ll ans=0;
  for(int i=0;i<=N;i++){
      ll rest=K-A*i;
      if(rest<0||rest%B!=0||(rest/B)>N) continue;
      int k=rest/B;

      ll res=comb(N,i)*comb(N,k)%MOD;
      ans=(ans+res)%MOD;
  }
  cout<<ans<<endl;

  return 0;
}


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

D f(D d) {
	D ret = d;
	for(int i = 0; i < 3; i++) {
		d.push_back(d[0]);
		d.pop_front();
		ret = min(ret, d);
	}
	return ret;
}

int overlap(D d) {
	int ret = 1;
	D t = d;
	for(int i = 0; i < 3; i++) {
		d.push_back(d[0]);
		d.pop_front();
		if(t == d) ret++;
	}
	return ret;
}


ll P(int n, int k) {
	ll ret = 1;
	for(int i = n - k + 1; i <= n; i++) {
		ret *= i;
	}
	return ret;
}

D C[400];

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

	map<D, int> m;
	map<D, int> cnt;
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < 4; j++) {
			int c;
			cin >> c;
			C[i].push_back(c);
		}
		C[i] = f(C[i]);
		m[C[i]]++;
	}

	for(auto p : m) {
		cnt[p.first] = overlap(p.first);
	}

	ll ans = 0;
	for(int i = 0; i < N; i++) {
		D d1 = C[i];
		m[d1]--;
		for(int j = i + 1; j < N; j++) {
			D d2 = C[j];
			m[d2]--;
			for(int r1 = 0; r1 < 4; r1++) {
				map<D, int> t;
				t[f(D({ d1[1], d1[0], d2[1], d2[0] }))]++;
				t[f(D({ d1[0], d1[3], d2[2], d2[1] }))]++;
				t[f(D({ d1[3], d1[2], d2[3], d2[2] }))]++;
				t[f(D({ d1[2], d1[1], d2[0], d2[3] }))]++;
				ll k = 1;
				for(auto p : t) {
					if(!m.count(p.first) || m[p.first] < p.second) {
						k = 0;
						break;
					}
					k *= P(m[p.first], p.second);
					for(int loop = 0; loop < p.second; loop++) {
						k *= cnt[p.first];
					}
				}
				ans += k;
				d1.push_back(d1[0]);
				d1.pop_front();
			}
			m[d2]++;
		}
		m[d1]++;
	}

	cout << ans / 3 << endl;
}

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

int main() {
	int d;
	cin >> d;
	string ans;
	if(d == 25) ans = "Christmas";
	else if(d == 24) ans = "Christmas Eve";
	else if(d == 23) ans = "Christmas Eve Eve";
	else ans = "Christmas Eve Eve Eve";
	cout << ans << endl;
}


Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn main(){
    let mut n = read_as_vec::<u32>()[0];

    println!("{}", (n+110)/111*111);
}


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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const double eps = 1e-8;

inline int dcmp(double x){if(-eps<x && x<eps)return 0;return x>0?1:-1;}

struct points
{
	double x,y;
	points(double _x=0,double _y=0){x=_x,y=_y;}

	inline friend points operator + (points a,points b){return points(a.x+b.x,a.y+b.y);}
	inline friend points operator - (points a,points b){return points(a.x-b.x,a.y-b.y);}
	inline friend points operator * (points a,double b){return points(a.x*b,a.y*b);}
	inline friend points operator / (points a,double b){return points(a.x/b,a.y/b);}

	inline friend int operator == (points a,points b){return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0;}

	void takein(){x=ty(),y=ty();}
	void print(char ends='\n'){printf("%.12lf %.12lf",x,y),putchar(ends);}
};

inline double dox(points a,points b){return a.x*b.x+a.y*b.y;}
inline double cox(points a,points b){return a.x*b.y-a.y*b.x;}
inline double length(points a){return sqrt(dox(a,a));}
inline double distan(points a,points b){return length(a-b);}

inline points pervec(points a){if(dcmp(length(a))<=0)return points(0,0);return a/length(a);}

inline int isponl(points p,points a,points b)
{
	return dcmp(cox(p-a,p-b))==0 && distan(a,p)<=distan(a,b) && distan(b,p)<=distan(a,b);
}

inline int iscrashed(points al,points ar,points bl,points br)
{
	double amix=min(al.x,ar.x),amxx=max(al.x,ar.x),amiy=min(al.y,ar.y),amxy=max(al.y,ar.y);
	double bmix=min(bl.x,br.x),bmxx=max(bl.x,br.x),bmiy=min(bl.y,br.y),bmxy=max(bl.y,br.y);
	
	if(amxx<bmix || bmxx<amix || amxy<bmiy || bmxy<amiy)return 0;
	if(isponl(al,bl,br) || isponl(ar,bl,br) || isponl(bl,al,ar) || isponl(br,al,ar))return 1;

	if(dcmp(cox(al-bl,br-bl))!=dcmp(cox(ar-bl,br-bl))
		&& dcmp(cox(bl-al,ar-al))!=dcmp(cox(br-al,ar-al)))return 1;
	return 0;
}

inline points crash(points al,points ar,points bl,points br)
{
	points a=ar-al,b=br-bl;
	double bas=cox(al-bl,b)/cox(b,a);
	return al+a*bas;
}

inline points ortho(points p,points a,points b)
{
	points c=a+pervec(b-a);
	double dis=dox(p-a,c-a);
	points tar=a+(c-a)*dis;
	return tar;
}

inline double distanpl(points p,points a,points b)
{
	if(isponl(p,a,b))return 0;
	points ort=ortho(p,a,b);
	if(isponl(ort,a,b))return distan(p,ort);
	return min(distan(p,a),distan(p,b));
}

const int _ = 107;

int n;
points p[_];

int main()
{
	n=ty();
	for(int i=1;i<=n;i++)p[i].takein();
	p[0]=p[n],p[n+1]=p[1],p[n+2]=p[2];

	for(int i=1;i<=n;i++)
		if(dcmp(cox(p[i+1]-p[i],p[i+2]-p[i]))<0){puts("0");return 0;}
	puts("1");
	
	return 0;
}



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

int main() {
  int n;
  int cnt=0;
  cin >> n;
  vector<int> d(n);
  for(int i=0;i<n;i++) cin >> d.at(i);
  
  sort(d.begin(),d.end());
  for(int i=0;i<n;i++){
    if(i+1<n){
      if(d.at(i)==d.at(i+1)) continue;
    }
    cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        HashSet<Integer> hs = new HashSet<Integer>();
        hs.add(sc.nextInt());
        hs.add(sc.nextInt());
        hs.add(sc.nextInt());
        if(hs.size() == 2){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <string>
#include <cmath>
#include <stdlib.h>
using namespace std;

int main() {
	string S; cin >> S;
	int p=S.size();
	long sum=0;
	for(int i=0; i<p; ++i){
	    int t=S[i]-'0';
	    for(int j=i; j<p; ++j){
	        if(p-j<3) sum += t*pow(10, j-i)*pow(2, i);
	        else sum += t*pow(10, j-i)*pow(2, p-j-2)*pow(2, i);
	    }
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(' ').map { it.toInt() }
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(' ').map { it.toInt() }

    val ans = Array(h) { IntArray(w) }

    var cur = 0
    var cnt = 0

    for (i in 0 until h) {
        val range = if (i % 2 == 0) {
            0 until w
        } else {
            w - 1 downTo 0
        }
        for (j in range) {
            if (a[cur] == cnt) {
                cur++
                cnt = 0
            }
            ans[i][j] = cur + 1
            cnt++
        }
    }

    ans.forEach { println(it.joinToString(" ")) }
}


Measured memory_bytes: 41588
#include<vector>
#include<iostream>
using namespace std;
int main() {
	vector<int> map;
	map.push_back(0);
	char code;
	while (cin >> code) {
		if (code == '\\')map.push_back(map.back() - 1);
		else if(code=='/') map.push_back(map.back() + 1);
		else map.push_back(map.back());
	}
	vector<int>water;
	int answer=0;
	vector<int>::iterator he,he2;
	for (he = map.begin(); he != map.end()-1; ++he) {
		if (*he > *(he + 1)) {
			for (he2 = he+1; he2 != map.end()&&*he2 != *he; ++he2);
			if (he2 == map.end())continue;
			water.push_back(0);
			for (; he != he2; ++he) {
				water.back() += *he2 - *he;
			}
			answer += water.back();
			--he;
		}
	}
	cout << answer << endl<<water.size();
	for (he = water.begin(); he != water.end(); ++he) {
		cout << ' ' << *he;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1332
#include <bits/stdc++.h>
using namespace std;
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
 

int main() {
  string N;cin>>N;
  
  int size = N.size();
  long long ans=0;
  for(int i=0;i<size;i++){
    ans+=ctoi(N[i]);
  }
  if(ans%9==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
 

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define sz(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()

vi mult (const vi &p, const vi &q)
{
    const int n = sz(p);
    assert(n == sz(q));
    vi ans(n);
    for (int i = 0; i < n; i++)
        ans[i] = p[q[i]];
    return ans;
}

vi power (vi p, ll k)
{
    const int n = sz(p);
    vi ans(n);
    iota(ALL(ans), 0);

    while (k > 0)
    {
        if (k & 1)
            ans = mult(ans, p);
        p = mult(p, p);
        k >>= 1;
    }
    return ans;
}

void solve (int n)
{
    vi x(n);
    for (int i = 0; i < n; i++)
        cin >> x[i];

    int m;
    ll k;
    cin >> m >> k;

    vi a(m);
    for (int i = 0; i < m; i++)
    {
        cin >> a[i];
        --a[i];
    }

    vi df(n - 1);
    for (int i = 0; i < n - 1; i++)
        df[i] = x[i + 1] - x[i];

//    copy(ALL(df), ostream_iterator<int>(cerr, " "));
//    cerr << endl;

    vi perm(n - 1);
    iota(ALL(perm), 0);

    for (int i = 0; i < m; i++)
        swap(perm[a[i] - 1], perm[a[i]]);

    perm = power(perm, k);

//    copy(ALL(perm), ostream_iterator<int>(cerr, " "));
//    cerr << endl;

    vector<ll> ans(n);
    ans[0] = x[0];
    for (int i = 0; i < n - 1; i++)
        ans[i + 1] = ans[i] + df[perm[i]];

    for (int i = 0; i < n; i++)
        cout << ans[i] << '\n';
}

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

    int n;
    while (cin >> n)
        solve(n);
}


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

int main(){
  int h,w;
  int i,j;
  int root;
  int tmp;
  int tmp_1,tmp_2;
  while(1){
    cin >> h >> w;
    if(h == 0 && w == 0){
      break;
    }
    root=h*h+w*w;
    int max_h=100;
    int max_w=100;
    int max;
    for(i = 1 ; i < 151 ; i++){
      for(j = 1 + i ; j < 151 ; j++){
	tmp=i*i+j*j; 
	max = max_h*max_h+max_w*max_w;
	if((max>tmp||(tmp==max&&i<max_h))&&((tmp==root&&i>h)||tmp > root)){
	  max_h=i;
	  max_w=j;
	}
      }
    }
    cout << max_h << ' ' << max_w << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
import           Control.Exception (assert)

main :: IO ()
main = do
  n <- readLn
  vs <- map read . words <$> getLine
  cs <- map read . words <$> getLine
  assert (length vs == n && length cs == n) $
    print $ solve vs cs

solve :: [Int] -> [Int] -> Int
solve vs cs = sum $ filter (> 0) $ zipWith (-) vs cs


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

int main(){
    int n; cin>>n;
  //8＝2*4 2*2*2 しか無い　つまり素因数分解で2つの素数or3つの素数が必要
  //13以下の素数で素因数分解（ 3 5 7 11 13)
  //5C2＝10通り＋27*7or 27*5 12通りでモウラする
    int count =0;
   for(int i=105;i<=n;i++){
     if(i==105||i==165||i==195||i==135||i==189)count++;
   }  
  cout<<count<<endl;

}

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

struct Node{
  int num,f;
};

struct Graph{
  int finish;
  vector< vector<int> > edge;
  vector< vector<int> > edge_inv;
  vector< Node > node;
  vector< bool > used;
  vector< int > group;
  Graph(int n)
  : finish(0),
    edge(n),
    edge_inv(n),
    node(n, {-1, -1}),
    used(n, false),
    group(n, -1)
    {
      for(int i = 0; i < n; i++){
        node[i] = {i, -1};
      }
    };
};

int dfs(int now, Graph& G){
  G.used[now] = true;
  for(auto next:G.edge[now]){
    if(!G.used[next]){
      dfs(next, G);
    }
  }
  G.node[now].f = G.finish;
  G.finish++;
  return 0;
}

int dfs_inv(int now, int g_id, Graph& G){
  G.group[now] = g_id;
  for(auto next : G.edge_inv[now]){
    if(G.group[next] < 0){
      // cout << now << " " << next << " " << g_id << endl;
      dfs_inv(next, g_id, G);
    }
  }
  return 0;
}

int main(int argc, char* argv[]){
  int v,e; cin >> v >> e;
  Graph G(v);
  for(int i = 0; i < e ; i++){
    int a,b; cin >> a >> b;
    G.edge[a].push_back(b);
    G.edge_inv[b].push_back(a);
  }

  for(int i = 0; i < v; i++){
    if(!G.used[i]) dfs(i, G);
  }
  sort(G.node.begin(), G.node.end(), [](const Node& a, const Node& b){
    return a.f > b.f;
  });
  int g_id = 0;
  for(int i = 0; i < v; i++){
    if(G.group[G.node[i].num] < 0){
      dfs_inv(G.node[i].num, g_id, G);
      g_id++;
    }
  }
  // cout << endl;
  // for(int i = 0; i < v; i++){
  //   cout << G.node[i].num << " " << G.node[i].f << endl;
  // }
  // for(int i = 0; i < v; i++){
  //   cout << G.group[i] << endl;
  // }
  int q; cin >> q;
  for(int i = 0; i < q; i++){
    int a,b; cin >> a >> b;
    if(G.group[a] == G.group[b]) cout << 1 << endl;
    else cout << 0 << endl;
  }

  return 0;
}



Measured memory_bytes: 4424
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  string s;
  int k;
  cin>>s>>k;

  vector<string> sub;
  map<string,bool> mp;
  REP2(i,1,min(k,int(s.size()))+1){
    REP(j,s.size()){
      string temp=s.substr(j,i);
      if(mp[temp]) continue;
      sub.emplace_back(temp);
      mp[temp]=1;
    }
  }
  sort(ALL(sub));
  cout<<sub[k-1]<<endl;

  return 0;
}

Measured memory_bytes: 2048
sa = input()
sb = input()
sc = input()
i = len(sa)
j = len(sb)
k = len(sc)
pi = 0
pj = pk = 0
turn = "a"
while True:
    if turn == "a":
        if pi == len(sa):
            print("A")
            exit()
        turn = sa[pi]
        pi += 1
    elif turn == "b":
        if pj == len(sb):
            print("B")
            exit()
        turn = sb[pj]
        pj += 1
    else:
        if pk == len(sc):
            print("C")
            exit()
        turn = sc[pk]
        pk += 1


Measured memory_bytes: 3064
#!/usr/bin/env python3

import itertools
import copy

H, W, k = map(int, input().split())
c = [list(input()) for _ in range(H)]

wlist = list(itertools.product([0, 1], repeat=W))
hlist = list(itertools.product([0, 1], repeat=H))

ans = 0 
for h in hlist:
    for w in wlist:
        black = 0 
        for i in range(H):
            for j in range(W):
                if h[i] == w[j] == 1 and c[i][j] == '#':
                    black += 1
        if black == k:
            ans += 1

print(ans)


Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[100008];
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    sort(a,a+n);
    int l=a[n/2];
    int x=a[n/2]-a[(n/2)-1];
    printf("%d",x);
    return 0;
}


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

int l[300];

int main () {
	int n;
	cin >> n;
	for (int i = 0; i < 2 * n; ++i) {
		cin >> l[i];
	}
	sort(l, l + 2 * n);
	int sum = 0;
	for (int i = 0; i < 2 * n; i += 2) {
		sum += l[i];
	}
	cout << sum << endl;
	return 0;	
}

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

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

using namespace std;

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

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

  vector<int> up(s.size() + 1, 0);
  rep(i, s.size()) {
    if (s[i] == '<') {
      if (i == 0 || s[i - 1] == '>') {
        up[i] = 0;
      }
      up[i + 1] = up[i] + 1;
    }
  }

  vector<int> down(s.size() + 1, 0);
  for (int i = s.size() - 1; i >= 0; --i) {
    if (s[i] == '>') {
      if (i == s.size() - 1 || s[i + 1] == '<') {
        down[i + 1] = 0;
      }
      down[i] = down[i + 1] + 1;
    }
  }
  vector<ll> ss(s.size() + 1, 0);
  for (int i = 0; i < ss.size(); i++) {
    ss[i] = max(up[i], down[i]);
  }
  ll res = 0;
  rep(i, ss.size()) {
    res += ss[i];
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 8708
import math
n = int(input())
nc = n
result = []
i = 2
while i <= math.sqrt(n):
    if n%i == 0:
        n //= i
        result.append(str(i))
    else:
        i += 1
if n != 1:
    result.append(str(n))
print(str(nc) + ": " + " ".join(result))


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

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int64_t> A(N+1);
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }

    int64_t cash = 1000;
    int64_t kabu = 0;
    for(int i=0; i<N; i++) {
        cash += kabu * A[i];
        kabu = 0;
        if(A[i+1] > A[i]) {
            kabu = cash / A[i];
            cash -= kabu * A[i];
        }
    }

    cout << cash << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>    
#include <unordered_map>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cerr<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define endl "\n"
#define fo(i,n) for(int i=0;i<n;i++)
#define foo(i,x,n) for(int i=x;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define w(x) int x;cin>>x;while(x--)
#define display(a,n) {fo(i,n) {cout<<a[i]<<" ";}cout<<endl;}
#define fil(a,n,val) {fo(i,n) a[i]=val; }
const ll MOD   = 1000*1000*1000+7;
const ll MOD2  = 998244353;
const ll N = 1000*1000+5;
const double PI  = 3.14159265;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
ll search(vl arr, ll l, ll r, ll x){if (r >= l) {ll mid = l + (r - l) / 2;if (arr[mid] == x)return mid;if (arr[mid] > x)return search(arr, l, mid - 1, x);return search(arr, mid + 1, r, x);} return -1;}
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll lcm(ll a , ll b){return (a*b)/ gcd(a,b);}
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){ if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p; } return res; }
ll modInverse(ll n, ll p){return power(n, p-2, p);}
const int maxn=3e5+5;

int dp[maxn]={0};

int main(){
	fastio();
	int n,k;
	cin>>n>>k;
	int a[n+1];
	foo(i,1,n+1) cin>>a[i];

	foo(i,2,n+1){
		int best=INT_MAX;
		for(int j=i-1;j>=max(1,i-k);j--){
			best=min(best,dp[j]+abs(a[j]-a[i]));
		}
		dp[i]=best;
	}

	cout<<dp[n]<<endl;

}

Measured memory_bytes: 4396
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<int> L(N);
    for(int i=0; i<N; i++){
        cin >> L[i];
    }
    std::sort(L.begin(), L.end());
    
    int count=0;
    for(int i=0; i<N-2; i++){
        for(int j=i+1; j<N-1; j++){
            for(int k=j+1; k<N; k++){
                if(L[i] + L[j] > L[k]){
                    count++;
                }else{
                    break;
                }
            }
        }
    }
    
    cout << count << endl;
    
}

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

#define N_MAX 5

typedef struct {
    int num;
	int room;
} ver;

int cmp( const void *p, const void *q ) {
    return ((ver*)p)->room - ((ver*)q)->room;
}


int main(void){
	int a;

	scanf("%d",&a);

	printf("%d\n",a+a*a+a*a*a);

	
	return 0;
}

Measured memory_bytes: 1728
#pragma GCC optimize(3, "Ofast", "inline")

#include <bits/stdc++.h>

#define start ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define int ll
#define ls st<<1
#define rs st<<1|1
#define pii pair<int,int>
#define rep(z, x, y) for(int z=x;z<=y;++z)
#define com bool operator<(const node &b)
using namespace std;
const int maxn = (ll) 3e5 + 5;
const int mod = 1000000007;
const int inf = 0x3f3f3f3f;
int T = 1;
int cntb, cnta, cntab;
int fac[maxn];

void solve() {
    fac[0] = 1;
    rep(i, 1, 2e5 + 5)fac[i] = fac[i - 1] * 2 % mod;
    map<pii, int> mp;
    int n;
    cin >> n;
    rep(i, 1, n) {
        int a, b;
        cin >> a >> b;
        if (a * b == 0) {
            if (a == 0 && b == 0)
                ++cntab;
            else if (a == 0)
                ++cnta;
            else if (b == 0)
                ++cntb;
            continue;
        }
//        if (a * b > 0) {
//            a = abs(a), b = abs(b);
//            int gcd = __gcd(a, b);
//            ++mp[pii(a / gcd, b / gcd)];
//        } else {
//            a = abs(a), b = abs(b);
//            int gcd = __gcd(a, b);
//            ++mp[pii(-a / gcd, b / gcd)];
//        }

        int gcd = __gcd(a, b);
        a /= gcd, b /= gcd;
        if (a * b > 0) {
            a = abs(a), b = abs(b);
            ++mp[pii(a, b)];
        } else {
            a = abs(a), b = abs(b);
            int gcd = __gcd(a, b);
            ++mp[pii(-a, b)];
        }

    }
    int ans = (fac[cnta] + fac[cntb] - 1 + mod) % mod;
    for (auto &to:mp) {
        if (to.second == 0)
            continue;
        int a = to.first.first, b = to.first.second;
        int num = to.second;
        pii j = a > 0 ? pii(-b, a) : pii(b, -a);
        if (mp[j] == 0)
            ans = ans * fac[num] % mod;
        else
            ans = ans * (fac[num] + fac[mp[j]] - 1 + mod) % mod;
        //cout << a << ' ' << b << ' ' << ans << ' ' << mp[j] << endl;
        mp[j] = to.second = 0;
    }
    cout << (ans - 1 + cntab + mod) % mod;
}

signed main() {
    start;
    while (T--)
        solve();
    return 0;
}


Measured memory_bytes: 29956
input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
line = lines.shift().split(' ')
N = line[0] * 1
K = line[1] * 1 
lines.pop()
lines = lines.map(x => x * 1).sort((a, b) => a - b)
min = Infinity
for (i=0; i<= N - K; i++) {
    if (min > lines[i + K - 1] - lines[i]) {
        min = lines[i + K - 1] - lines[i]
    }
}
console.log(min)

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


vector<int> v;

int getid(int x){
	return lower_bound(v.begin(),v.end(),x)-v.begin()+1;
}
int H[300000],X[300000];
struct aa{
	int x,h;
	bool operator<(const aa b){
		return x<b.x; 
	}
}f[300000];

int tr[500000];
int tot;
int Add(int x,int v){
	for(int i=x;i<=tot;i+=((-i)&(i)))tr[i] += v;
}
int add(int l,int r,int v){
	Add(l,v);
	Add(r+1,-v);
}
int Que(int x){
	int ans=0;
	for(int i=x;i>0;i-=(i&(-i)))ans+=tr[i];
	return ans;
}
int que(int x){
	return Que(x);
}
signed main()
{

	int n,d,a;cin>>n>>d>>a;
	for(int i=1;i<=n;i++){
		cin>>f[i].x>>f[i].h;
		v.push_back(f[i].x);
		v.push_back(f[i].x+2*d);
	}
	sort(f+1,f+1+n);
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	tot=v.size();
	int ans=0;
	for(int i=1;i<=n;i++){
		int pos=getid(f[i].x);
		H[i]=f[i].h;
		X[i]=f[i].x;
		int now=que(pos);
		if(now>=H[i])continue;
		H[i]-=now;
		int cnt=H[i]/a + (H[i]%a != 0);
		int r=getid(X[i]+2*d);
		add(pos,r,cnt*a);
	///	cout<<pos<<" "<<r<<" "<<cnt*2<<endl;
		ans += cnt;
	//	cout<<i<<" "<<now<<" "<<ans<<endl;
	}
	cout<<ans<<endl;
	getchar();getchar();
	
}

Measured memory_bytes: 15980
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

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


int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n,k;
    cin >> n >> k;

    ll ans = 0;
    for(ll i = k; i <= n+1; i++){
        /*ll tmp = modinv((((0 + i - 1) % MOD) * i % MOD) , 2);
        ll tmp2 = modinv((((n + n - i + 1 ) % MOD) * i % MOD) , 2);*/
        ll tmp = (0 + i - 1) * i / 2;
        ll tmp2 = (n + n - i + 1) * i / 2;
        ans += (tmp2 - tmp + 1) % MOD;
    }

    cout << ans % MOD<< endl;



}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif
vector<int> IntegerToVector(int bit, int N)
{
    vector<int> S;
    for (int i = 0; i < N; ++i)
    {
        if (bit & (1 << i))
        {
            S.push_back(i);
        }
    }
    return S;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);


    lint n, m, x;
    cin >> n >> m >> x;

    lint ans=10000000;

    vector<lint> c(n);
    vector<vector<lint>> a(n,vector<lint>(m));
    REP(i, n) {
        cin >> c[i];
        REP(j, m)
            cin >> a[i][j];
    }
    for (int bit = 0; bit < (1 << n); ++bit)
    {
        vector<lint> alg(m);
        // どれを選ぶか
        vector<int> S = IntegerToVector(bit, n);

        // 部分集合に対応する総和
        int sum = 0;
        lint cc = 0;
        for (int i : S){
            REP(j,m){
                alg[j] += a[i][j];
            }
            //sum += a[i];
            cc += c[i];
        }

        // 判定        
        REP(i,m){
            if(alg[i] < x){
                break;
            }
            if(i==m-1){
                ans = min(ans, cc);
            }
        }
    }
    if (ans == 10000000){
        cout << -1 << "\n";
    }else{
        cout << ans << "\n";
    }

    return 0;
}

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

int main(){
    std::string S;
    std::cin >> S;
    
    int max = 0;
    int tmp = 0;
    for(int i=0; i<S.size(); i++){
        if(S[i] == 'S'){
            if(max < tmp){
                max = tmp;
                tmp = 0;
            }
        }else{
            tmp++;
        }
    }
    if(max < tmp){
        max = tmp;
    }
    
    std::cout << max << std::endl;
    
    
    return 0;
    
}


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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    string s;
    cin >> n >> k >> s;
    VI s_cnt = {0, 0, 1};
    FOR(i, 1, s.size() - 1) {
        if(s[i] != s[i - 1]) s_cnt.push_back(1);
        else s_cnt.back()++;
    }
    s_cnt.push_back(0);

    REP(i, s_cnt.size() - 1) s_cnt[i + 1] += s_cnt[i];
    
    if((s_cnt.size() - 3) / 2 < k) {
        cout << n << ln;
        return 0;
    }

    int ans = 0;
    int i_st = s.front() == '0' ? 0 : 1;
    for(int i = i_st; i < s_cnt.size() - k * 2 - 1; i += 2)
        ans = max(ans, s_cnt[i + k * 2 + 1] - s_cnt[i]);
    cout << ans << ln;
    return 0;
}


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

#define INF (2e9)
#define FOR(i, a, b) for (ll (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)

using namespace std;

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

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

using ll = long long;
using ld = long double;

#define ALL(x) (x).begin(), (x).end()
template<class T>
using vc = vector<T>;
using vi = vc<ll>;
using vvi = vc<vi>;

template<class T>
using va = valarray<T>;
using vad = va<ld>;
using vai = va<ll>;

vi Read(ll n) {
    auto      v = vi(n);
    for (auto i = std::size_t(0); i < n; ++i) {
        cin >> v[i];
    }
    return v;
}

template<class T>
void DumpRow(const T& A) {
    for (const auto& value : A)
        cout << value << "\n";
}

template<class T>
void DumpColumn(const T& A) {
    auto isFirst = true;
    for (const auto& value : A) {
        if (isFirst) {
            cout << value;
            isFirst = false;
        } else {
            cout << " " << value;
        }

    }
    cout << endl;
}

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

    ll n;
    cin >> n;
    auto v = Read(n);

    ll q;
    cin >> q;

    REP(i, q) {
        ll b, e;
        cin >> b >> e;
        reverse(v.begin() + b, v.begin() + e);
    }

    DumpColumn(v);
    return 0;
}



Measured memory_bytes: 3216
N = int(raw_input())
S = raw_input()

v1 = 0
v = 0
for s in S:
    if s == "(":
        v -= 1
    if s == ")":
        v += 1
    v1 = max(v1, v)

v2 = v1 + S.count("(") - S.count(")")

print "(" * v1 + S + ")" * v2


Measured memory_bytes: 2568
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i=0; i<n; i++) {
        cin >> a[i];
    }
    if (n%2 == 1) {
        for (int i=n-1; i>=0; i-=2) {
            cout << a[i] << " ";
        }
        for (int i=1; i<=n-2; i+=2) {
            cout << a[i] << " ";
        }
        cout << endl;
    } else {
        for (int i=n-1; i>=1; i-=2) {
            cout << a[i] << " ";
        }
        for (int i=0; i<=n-2; i+=2) {
            cout << a[i] << " ";
        }
        cout << endl;
    }
}

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


#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define abs(x) ((x)>0?(x):-(x))

void sort(char *x[100],int n,int P[100],int ans[100])
{
	char *tmp;
	int tmp2;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n-i-1; j++)
		{
			if (strcmp(x[j], x[j + 1]) > 0)
			{
				tmp = x[j];
				tmp2 = P[j];
				x[j] = x[j + 1];
				P[j] = P[j + 1];
				x[j + 1] = tmp;
				P[j + 1] = tmp2;

				tmp2 = ans[j];
				ans[j] = ans[j + 1];
				ans[j + 1] = tmp2;
			}

			if (strcmp(x[j], x[j + 1]) == 0)
			{
				if (P[j] < P[j + 1])
				{
					tmp2 = P[j];
					P[j] = P[j + 1];
					P[j + 1] = tmp2;

					tmp2 = ans[j];
					ans[j] = ans[j + 1];
					ans[j + 1] = tmp2;
				}
			}
		}
	}
}

int main()
{
	int N;
	char *S[100];
	char str[100][20];
	int P[100];
	int ans[100];

	scanf("%d", &N);

	for (int i = 0; i < N; i++)
	{
		scanf("%s%d", str[i], &P[i]);
		S[i] = str[i];
	}

	for (int i = 0; i < N; i++)
		ans[i] = i+1;

	sort(S, N,P,ans);

	//printf("---------------------------\n");
	//for (int i = 0; i < N; i++)
	//{
	//	for(int j = 0; S[i][j]!=NULL; j++)
	//		printf("%c", S[i][j]);

	//	printf("%d", P[i]);
	//	printf("\n\n");
	//}
	

	for (int i = 0; i < N; i++)
		printf("%d\n", ans[i]);

	//for (int i = 0; i < N; i++)
	//{
	//	for (int j = 0; j < N; j++)
	//	{
	//		if (S2[i] == S[j])
	//			printf("%d\n", j);
	//	}
	//}
}

Measured memory_bytes: 128
open Scanf
open Printf

let flip f x y = f y x

let rec range a b = if a >= b then [] else a :: range (a+1) b

let read_int () = scanf " %d" (fun x -> x)
let rec read_ints n = if n = 0 then [] else let i = read_int () in i :: read_ints (n-1)

let rec for_iter a b f = if a >= b then [] else let x = f a in x :: for_iter (a+1) b f
let rec for_iter_ a b f = if a >= b then () else (f a; for_iter_ (a+1) b f)

let arrange xs =
  let rec f c i xs =
    match xs with
    | [] -> c
    | [x] -> if x = i then c+1 else c
    | (x::y::ys) ->
        if x = i then f (c+1) (i+1) (x::ys)
        else f c (i+1) (y::ys) in
  f 0 1 xs

let () =
  let n = read_int () in
  read_ints n |> arrange |> printf "%d\n"



Measured memory_bytes: 8960
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int h = sc.nextInt();
		int n = sc.nextInt();//塗りつぶす点の個数
		int x = 0;
		int y = 0;

		for(int i=0; i<n; i++){
			int x1 = sc.nextInt();
			int y1 = sc.nextInt();
			int a = sc.nextInt();
			if(a==1&&x<x1){
				x = x1;
			}else if(a==2&&w>x1){
				w = x1;
			}else if(a==3&&y<y1){
				y = y1;
			}else if(a==4&&h>y1){
				h = y1;
			}
		}

		if(x<w&&y<h){
			System.out.println((w-x)*(h-y));
		}else{
			System.out.println("0");
		}


	}

}

Measured memory_bytes: 10440
n=int(input())
def dfs(s):
    if int(s)>n:
        return 0
    ret=1 if all(s.count(c)>0 for c in '753') else 0 #s自体が７５３数
    for c in '753':
        ret+=dfs(s+c)
    return ret    
print(dfs('0'))

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

#define STACK_SIZE  100   /* ??????????????????????????¨?????§???????????????????????§?????° */
#define SUCCESS     1     /* ?????? */
#define FAILURE     0     /* ??±??? */

typedef int data_t;       /* ??????????????????????????????????????? */

data_t stack_data[STACK_SIZE];  /* ??????????????¬??? */
int stack_num;                  /* ????????????????????????????????° */

//push??¨?????¢??°
int push(data_t push_data)
{
    if (stack_num < STACK_SIZE) {
        stack_data[stack_num] = push_data;
        stack_num ++;
        return SUCCESS;
    } else {
        return FAILURE;
    }
}

//pop??¨?????¢??°
int pop(data_t *pop_data)
{
    if (stack_num > 0) {
        stack_num --;
        *pop_data = stack_data[stack_num];
        return SUCCESS;
    } else {
        return FAILURE;
    }
}

//??¨?????¨?????¢??°
void stackPrint()
{
    int i;

    printf("stack [");
    for (i = 0; i < stack_num; i++) {
        printf("%3d", stack_data[i]);
    }
    printf("]\n");
}

int main(void){
    char input[1000000];
	int i,result,ope1,ope2;
	
	stack_num = 0;
	
    while(scanf("%s", input) == 1){	
	
	for(i = 0; i < strlen(input); i++){
		if(input[i]=='*'){
			pop(&ope1); pop(&ope2);
			result = ope2 * ope1;
			push(result);
		}else if(input[i]=='+'){
			pop(&ope1); pop(&ope2);
			result = ope2 + ope1;
			push(result);
		}else if(input[i]=='-'){
			pop(&ope1); pop(&ope2);
			result = ope2 - ope1;
			push(result);
		}else{
			int number = input[i] - '0';
			
			//?¬??????????????????????????????????
			while('0' <= input[i+1] && input[i+1] <= '9'){
				number *= 10;
				number += input[i+1] - '0';
				i++;
			}
			
			push(number);
		}
			
		//stackPrint();
	}
	
    }
	pop(&result);
	printf("%d\n", result);
	
	return 0;
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int DigitCount(int x) {
	int count = 0;
	while (x) {
		x /= 10;
		count++;
	}
	return count;
}

signed main() {
	int a, b;
	while (cin >> a >> b) {
		cout << DigitCount(a + b) << endl;
	}
	return 0;
}


Measured memory_bytes: 2976
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	pre, _ := strconv.Atoi(sc.Text())
	sum := pre
	for i := 1; i < n-1; i++ {
		sc.Scan()
		bn, _ := strconv.Atoi(sc.Text())
		if bn < pre {
			sum += bn
		} else {
			sum += pre
		}
		pre = bn
	}
	sum += pre
	writer := bufio.NewWriter(os.Stdout)
	writer.WriteString(strconv.Itoa(sum))
	writer.Flush()
}

Measured memory_bytes: 640