akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=a;i<b;i++)

typedef set<string> ss;

map<string, ss> memo;

ss recursive(ss groupname, map<string, ss> group, string gname)
{
	if (memo.find(gname) != memo.end()) return memo[gname];

	ss ret;
	for (string name : group[gname])
	{
		if (groupname.find(name) != groupname.end())
		{
			ss tmp = recursive(groupname, group, name);
			for (string s : tmp) ret.insert(s);
		}
		else
		{
			ret.insert(name);
		}
	}
	return (memo[gname] = ret);
}

int main()
{
	while (1)
	{
		int n; cin >> n;
		if (n == 0) return 0;

		memo.clear();

		ss groupname;
		map<string, ss> group;
		string first_groupname;

		rep(i, 0, n)
		{
			string s; cin >> s;
			string gname;
			int index;

			index = s.find(":");
			gname = s.substr(0, index);
			groupname.insert(gname);
			group[gname] = ss();

			if (i == 0) first_groupname = gname;

			s = s.substr(index+1);

			while ((index = s.find(",")) != string::npos)
			{
				string name = s.substr(0, index);
				group[gname].insert(name);
				s = s.substr(index + 1);
			}

			index = s.find(".");
			string name = s.substr(0, index);
			group[gname].insert(name);
		}

		ss ans = recursive(groupname, group, first_groupname);
		cout << ans.size() << endl;
	}
}

Measured memory_bytes: 4892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(){
    int n; cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    sort(ALL(d));
    int mid = n/2;
    int ans = d[mid] - d[mid-1];
    cout << ans << endl;
}

Measured memory_bytes: 640
# 15-Character-Toggling_Cases.py

# ??§????????¨?°????????????\?????????
# ????????????????????????????°?????????¨??§???????????\????????????????????°????????????????????????????????????

# Input
# ????????????1???????????????????????????

# Output
# ????????????????????????????°?????????¨??§???????????\????????????????????????????????????????????????
# ??¢????????????????????\???????????????????????????????????????????????????

# Constraints
# ??\?????????????????????????????? < 1200
# Sample Input
# fAIR, LATER, OCCASIONALLY CLOUDY.
# Sample Output
# Fair, later, occasionally cloudy.

print( input().swapcase())

Measured memory_bytes: 7320
#include <iostream>
#include <algorithm>
using namespace std;
string next(string s){
	for(int i=1; i<s.size(); i++)
		if(s[i-1] <= s[i] && s[i-1] != '9'){
			s[i-1]++;
			for(int j=i-2; j>=0; j--)
				s[j] = max(s[j+1] - 1, 48);
			return s;
		}

	if(s.back() == '9')
		return string(s.size(), '0') + "1";
	(*s.rbegin())++;
	for(auto it = s.rbegin(); next(it) != s.rend(); ++it)
		*next(it) = max(*it-1, 48);
	return s;


}
int main(){
	int K;
	string s = "0";
	for(cin >> K; K; K--)
		s = next(s);
	reverse(s.begin(), s.end());
	cout << s << endl;
}




Measured memory_bytes: 256
A,B,C,D=input()
a = int(A)
b = int(B)
c = int(C)
d = int(D)
if (a+b+c+d) == 7:
         print(A+"+"+B+"+"+C+"+"+D+"=7")
elif (a-b+c+d) == 7:
         print(A+"-"+B +"+"+C +"+"+D+"=7")
elif (a+b-c+d) == 7:
         print(A+"+"+B +"-"+C +"+"+D+"=7")
elif (a+b+c-d) == 7:
         print(A+"+"+B +"+"+C +"-"+D+"=7")
elif (a-b-c+d) == 7:
         print(A+"-"+B +"-"+C +"+"+D+"=7")
elif (a-b+c-d) == 7:
         print(A+"-"+B +"+"+C +"-"+D+"=7")
elif (a+b-c-d) == 7:
         print(A+"+"+B +"-"+C +"-"+D+"=7")
else:
         print(A+"-"+B +"-"+C +"-"+D+"=7")


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

int main(){
    double x1,y1,x2,y2,x,y,dis;

    cin >> x1 >> y1 >> x2 >> y2;
    if(x1 > x2){
        x = x1 - x2;
    }else{
        x = x2 - x1;
    }
    if(y1 > y2){
        y = y1 - y2;
    }else{
        y = y2 - y1;
    }

    cout << fixed;
    cout.precision(8);
    dis = sqrt(pow(x,2)+pow(y,2));
    cout << dis << endl;

    return 0;

}



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

int main() {
  int S, W; cin >> S >> W;
  cout << (W >= S ? "unsafe" : "safe") << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
int main(void){
	
	while(1){
		int a,b;
		char op;
		scanf("%d %c %d",&a,&op,&b);
		
		if(op=='+'){
			printf("%d\n",a+b);
		}else if(op=='-'){
			printf("%d\n",a-b);
		}else if(op=='*'){
			printf("%d\n",a*b);
		}else if(op=='/'){
			printf("%d\n",a/b);
		}else{
			break;
		}
	}
	
	return 0;
}


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

typedef long long int ll;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD (ll)(1e9 + 7)
#define vi vector<int>
#define vii vector<vector<int> >
#define vl vector<ll>
#define vll vector<vector<ll> >
#define vc(T, nm) vector<T> nm
#define pb push_back
#define popb pop_back
#define si set<int>
#define sl set<ll>
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define ins insert
#define ers erase
#define endl "\n"
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define adr(a, b) ((a % MOD) + (b % MOD)) % MOD
#define FORA(x, s, e, inc) for(ll x = s; x != e; x += inc)
#define ROFA(x, s, e, inc) for(ll x = s; x != e; x -= inc)
#define FOR(x, s, e) FORA(x, s, e, 1)
#define ROF(x, s, e) ROFA(x, s, e, 1)
#define loop(x, n) FOR(x, 0, n)
#define rd1(t, a) 					t a; cin >> a;
#define rd2(t, a, b) 				rd1(t, a); rd1(t, b); 
#define rd3(t, a, b, c) 			rd2(t, a, b); rd1(t, c);
#define rd4(t, a, b, c, d) 			rd3(t, a, b, c); rd1(t, d);
#define rd5(t, a, b, c, d, e) 		rd4(t, a, b, c, d); rd1(t, e);
#define rd6(t, a, b, c, d, e, f) 	rd5(t, a, b, c, d, e); rd1(t, f);
#define rdA(t, nm, len)				t nm[len]; loop(i, len) {cin >> nm[i];}
#ifdef DEBUG
	#define deb(v) cout << endl << #v << ": " << v << endl
	#define db1(v) cout << endl << #v << ": " << "[ "; for(auto x: v) {cout << x << " ";}; cout << "]" << endl;
	#define db2(v) cout << endl << #v << ": " << endl; for(auto r: v) {cout << "[ "; for(auto x: r) {cout << x << " ";}; cout << "]" << endl;};
	#define dbl cout << "-------------------------------" << endl
#else
	#define deb(v)
	#define db1(v)
	#define db2(v)
	#define dbl
#endif

void solve() {
	rd1(ll, n);
	ll m = n % 10;
	if(m == 2 or m == 4 or m == 5 or m == 7 or m == 9) {
	    cout << "hon";
	} else if(m == 0 or m == 1 or m == 6 or m == 8) {
	    cout << "pon";
	} else {
	    cout << "bon";
	}
       
}

int main() {
	
	fastio;

// 	rd1(ll, t);
	ll t = 1;

    while(t--) {
        solve();
    }
    
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  int S = 0;
  for(int i = 0; i < N; i++) {
    cin >> P.at(i);
  }
  int m = N + 1;
  for(int i = 0; i < N; i++) {
    m = min(m, P.at(i));
    if(m == P.at(i)) S++;
  }
  cout << S << endl;
}

Measured memory_bytes: 1024
from collections import defaultdict, Counter
MOD = 10**9+7
n, K = map(int, input().split())
cnt = Counter(map(int, input().split()))
keys = sorted(cnt.keys())
key_to_idx = defaultdict(int)
for i, k in enumerate(keys):
    key_to_idx[k] = i

Acum = [0]
for k in keys:
    Acum.append(Acum[-1]+cnt[k])

U = n
fact = [0]*(U+1)
fact[0] = 1
for i in range(1, U+1):
    fact[i] = fact[i-1]*i % MOD


invfact = [0]*(U+1)
invfact[U] = pow(fact[U], MOD-2, MOD)
for i in reversed(range(U)):
    invfact[i] = invfact[i+1]*(i+1) % MOD


def nCr(n, r):
    if r < 0 or n < r:
        return 0
    return fact[n]*invfact[r]*invfact[n-r]


ans = 0
for k in keys:
    x = Acum[key_to_idx[k]+1]
    y = Acum[key_to_idx[k]]
    cmax = nCr(x, K) - nCr(y, K)
    cmin = nCr(n-y, K) - nCr(n-x, K)
    ans += k*(cmax-cmin)
    ans %= MOD

print(ans)


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

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            string s = ReadLine();
            bool ans = false;
            if ((s.Contains('N') && s.Contains('S')) || (!s.Contains('N') && !s.Contains('S')))
            {
                if (s.Contains('W') && s.Contains('E')||(!s.Contains('W') && !s.Contains('E')))
                {
                    ans = true;
                }
            }
            WriteLine(ans ? "Yes":"No");
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 5000+10;
const ll mod =   1e9+7;

int main()
{  fast
int x1,x2,x3,x4,x5;
cin>>x1>>x2>>x3>>x4>>x5;
int z=15;
z-=(x1+x2+x3+x4+x5);
cout<<z;



}

Measured memory_bytes: 3604
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#define rep(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
using namespace std;
int V, E, st, gl;//頂点数、辺数、始点、終点
#define E_M 401 
#define V_M 41
char INF[500];
struct edge{
	int from, to;
	char label[500];
};
edge es[E_M];
char d[V_M][2000];
int MAX_LEN = 0;

//aにbをコピー
void cp(char *a, char *b){
	int p = 0;
	while (b[p] != '\0'){
		a[p] = b[p];
		 p++;
		 if (p >= 400)break;
	}
	a[p] = '\0';
}
//aにx->y連結をコピー
void connect_str(char a[], char x[], char y[]){
	int p=0, q=0;
	while (x[p] != '\0'){
		a[p] = x[p], p++;
		if (p >= 400)break;
	}
	while (y[q] != '\0'){
		a[p] = y[q], q++, p++;
		if (p >=400)break;
	}
	a[p] = '\0';
}


bool shortest(int s,int g){
	rep(i, 0, V)cp(d[i], INF);
	d[g][0] = '\0';
	rep(i, 0, MAX_LEN*2+1){
		rep(j, 0, E){
			edge e = es[j];
			//cout << d[e.to] << endl;
			if (strcmp(d[e.to], INF) >= 0)continue;
			char target[2000] = { 0 };
			connect_str(target, e.label, d[e.to]);
			if ((strcmp(d[e.from], target) >0)){
			//	cout << d[e.to] << endl;
				cp(d[e.from], target);
				if (i == 2*MAX_LEN+1)return(true);
			}
		}
	}
	return(false);
}

int main(void){

	rep(i, 0, 300)INF[i] = 'z';
	INF[300] = '\0';
	while (true){
		cin >> V >> E >> st >> gl;
		if (V == 0)return(0);
		MAX_LEN = 6 * (V - 1);
		rep(i, 0, E)
			cin >> es[i].from >> es[i].to >> es[i].label;
		
		if (shortest(st, gl) || strcmp(d[st], INF) >= 0 || strlen(d[st])>MAX_LEN)cout << "NO" << endl;
		else cout << d[st] << endl;
	}
}
	

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

void main(){
    int k;
    char s[100];
    int sl;
    scanf("%d",&k);
    scanf("%s",s);
    sl=strlen(s);
    if(k >= sl){
        printf("%s",s);
    }else{
        int i;
        for(i=0;i<k;i++)
        printf("%c",s[i]);
        
        printf("...");
    }
    

}

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

using namespace std;
using ll = long long;

int main() {
  string S;
  cin >> S;
  int cnt=0,m=0;
  for (int i = 0; i < S.size(); ++i) {
    if(S[i]=='A' || S[i]=='T' || S[i]=='C' || S[i]=='G'){
      cnt++;
    }else{
      if (cnt>m){
        m=cnt;
      }
      cnt=0;
    }
  }
  if (cnt>m) {
    m = cnt;
  }
  cout << m << endl;
}


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

int main(){
  ll x;
  cin >> x;
  ll yen = 100;
  ll year = 0;
  while(1){
    yen = floor(yen * 1.01);
    year++;
    if(yen>=x) break;
  }
  cout << year << endl;
  return 0;
}

Measured memory_bytes: 3744
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;


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

ll LCM(ll a, ll b){
    return a * b /GCD(a,b);
}


int main(){
    ll A,B,C,D;
    cin >> A >> B >> C >> D;
    ll pb =  B / C;
    ll pa = (A-1) / C;
    ll qb = B / D;
    ll qa = (A-1) / D;
    ll x = LCM(C,D);
    ll rb = B / x;
    ll ra = (A-1) / x;

    ll ans = (B-A+1) - (pb-pa) - (qb-qa) + (rb-ra);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int table[3];
	int sum = 0,maximum = -1;

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

		scanf("%d",&table[i]);
		sum += table[i];
		maximum = max(maximum,table[i]);
	}

	printf("%d\n",sum-maximum);

	return 0;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int64 x;
    cin >> x;
    while(true){
        bool flg = true;
        for(int64 i = 2; i * i <= x; i++){
            if(x % i == 0){
                flg = false;
                break;
            }
        }
        if(flg){
            cout << x << endl;
            return 0;
        }
        x++;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int a[12],r=0;
  for(int i=0;i<12;i++) cin>>a[i];
  sort(a,a+12);
  for(int i=0;i<3;i++) for(int j=1;j<4;j++) if(!(a[i*4]==a[i*4+j])) r++;
  cout<<(r?"no":"yes")<<endl;
  return 0;
}

Measured memory_bytes: 3140
using System;

namespace ITP1_4_C
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                String[] inputs = Console.ReadLine().Split(' ');
                int a = Convert.ToInt32(inputs[0]);
                String op = inputs[1];
                int b = Convert.ToInt32(inputs[2]);

                if (op.Contains("?")) break;

                if (op.Contains("+"))       Console.WriteLine(a + b);
                else if (op.Contains("-"))  Console.WriteLine(a - b);
                else if (op.Contains("*"))  Console.WriteLine(a * b);
                else if (op.Contains("/"))  Console.WriteLine(a / b);
            }
        }
    }
}

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

int main(){
  int c1x,c1y,c1r;
  int c2x,c2y,c2r;
  int lr,sr;

  double dis;

  scanf("%d %d %d",&c1x,&c1y,&c1r);
  scanf("%d %d %d",&c2x,&c2y,&c2r);


  if(c1x>=c2x && c1y>=c2y){
    dis = sqrt((c1x-c2x)*(c1x-c2x)+(c1y-c2y)*(c1y-c2y));
  }
  else if(c1x>=c2x && c2y>=c1y){
    dis = sqrt((c1x-c2x)*(c1x-c2x)+(c2y-c1y)*(c2y-c1y));
  }
  else if(c2x>=c1x && c1y>=c2y){
    dis = sqrt((c2x-c1x)*(c2x-c1x)+(c1y-c2y)*(c1y-c2y));
  }else{
    dis = sqrt((c2x-c1x)*(c2x-c1x)+(c2y-c1y)*(c2y-c1y));
  }

  if(c1r>=c2r){
    lr = c1r;
    sr = c2r;
  }else{
  lr = c2r;
  sr = c1r;
}


  if(lr+sr < dis){
    printf("%d\n",4);
  }
  else if(lr+sr == dis){
    printf("%d\n",3);
  }
  else if(lr+sr > dis && lr-sr < dis){
    printf("%d\n",2);
  }
  else if(lr-sr == dis){
    printf("%d\n",1);
  }
  else if(lr-sr > dis)
    printf("%d\n",0);
  }



Measured memory_bytes: 2112
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<string.h>
#include<stack>
#define n 200000
#define loop(a) for(int i=0; i<a; i++)
using namespace std;
typedef pair<int, int> P;
struct edge{
	int from, to, weight;
	bool operator < (const edge& thing) const
	{
		return thing.weight < weight;
	}
};
bool cmp(int a, int b)
{
	return a > b;
}
vector<edge> V[n + 50];
bool visit[n + 50];
int arr[n + 50], a, b, c, d;
string str1, str2;
void addedge(int a, int b, int c)
{
	edge one, two;
	one.from = a; one.to = b; one.weight = c;
	two.from = b; two.to = a; two.weight = c;
	V[a].push_back(one);
	V[b].push_back(two);
}


//////////////////////////////////////////


void solve()
{
	cin >> a >> b >> c >> d;
	if(abs(c - a) <= d) printf("Yes");
	else if(abs(b - a) <= d && abs(c - b) <= d) printf("Yes");
	else printf("No");
}
int main()
{
	int times = 1;
//	cin << times;
	loop(times)
	{
		solve();
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 4992
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();
    List<int> ans = new List<int>();
    int N, A, B, C;
    int[] l;

    public void Solve() {
        N = sc.nextInt();
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();
        l = new int[N];
        for (int i = 0; i < N; i++) {
            l[i] = sc.nextInt();
        }

        dfs(0, 0, 0, 0, 0);
        WriteLine(ans.Min());
    }

    private void dfs(int i, int a, int b, int c, int cnt) {
        if (i == N) {
            if (a == 0 || b == 0 || c == 0) return;
            int sum = (cnt - 3) * 10;
            ans.Add(sum + Math.Abs(A - a) + Math.Abs(B - b) + Math.Abs(C - c));
            return;
        }
        dfs(i + 1, a + l[i], b, c, cnt + 1);
        dfs(i + 1, a, b + l[i], c, cnt + 1);
        dfs(i + 1, a, b, c + l[i], cnt + 1);
        dfs(i + 1, a, b, c, cnt);
    }
}


class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 13536
#include <bits/stdc++.h>
using namespace std;
 
int n, m, d[1001][1001], a[1001][1001], xs, ys, xf, yf;
bool inque[1001][1001];
deque<pair<int, int>> coada;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
 
bool in(int x, int y) {
    return x >= 1 && x <= n && y >= 1 && y <= m;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    cin >> xs >> ys;
    cin >> xf >> yf;
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        for(int j = 1; j <= m; j++) {
            d[i][j] = n * m;
            if(s[j - 1] == '.') {
                a[i][j] = 1;
            } else {
                a[i][j] = 0;
            }
        }
    }
    d[xs][ys] = 0;
    inque[xs][ys] = 1;
    coada.push_back(make_pair(xs, ys));
    while(!coada.empty()) {
        int x = coada.front().first;
        int y = coada.front().second;
        inque[x][y] = 0;
        coada.pop_front();
        for(int i = 0; i < 4; i++) {
            int newx = x + dx[i];
            int newy = y + dy[i];
            if(in(newx, newy) && a[newx][newy] && d[newx][newy] > d[x][y]) {
                d[newx][newy] = d[x][y];
                if(!inque[newx][newy]) {
                    inque[newx][newy] = 1;
                    coada.push_front(make_pair(newx, newy));
                }
            }
        }
        for(int i = max(x - 2, 1); i <= min(x + 2, n); i++) {
            for(int j = max(y - 2, 1); j <= min(y + 2, m); j++) {
                if(abs(i - x) + abs(j - y) > 1 && a[i][j] && d[i][j] > d[x][y] + 1) {
                    d[i][j] = d[x][y] + 1;
                    if(!inque[i][j]) {
                        inque[i][j] = 1;
                        coada.push_back(make_pair(i, j));
                    }
                }
            }
        }
    }
    if(d[xf][yf] == n * m) {
        cout << -1;
    } else {
        cout << d[xf][yf];
    }
    return 0;
}

Measured memory_bytes: 12444
# Transformation

string = input()
commandAmount = int(input())

for i in range(commandAmount):
    command = input().rstrip().split()
    start = int(command[1])
    end = int(command[2])
    if command[0] == 'print':
        print(string[start : end + 1]) # ここはコメントアウトしないこと
    elif command[0] == 'reverse':
        replacedString = list(string)
        # print(replacedString)
        for i in range(start, end + 1):
            replacedString[i] = list(string)[start + end - i]
        # print(replacedString)
        string = ''.join(replacedString)
    elif command[0] == 'replace':
        string = list(string)
        replace = list(command[3])
        for i in range(start, end + 1):
            string[i] = replace[i - start]
        string = ''.join(string)



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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int main() {
    char c;
    cin >> c;

    switch (c) {
        case 'a':
        case 'i':
        case 'u':
        case 'e':
        case 'o':
            cout << "vowel" << endl;
            break;
        default:
            cout << "consonant" << endl;
            break;
    }

    return 0;
}

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

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

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl

int main(){
    int t;
    cin>>t;
    while(t--){
        int y,m,d;
        cin>>y>>m>>d;
        int cnt = 0;
        while(y!=1000 || m!=1 || d!=1){
            cnt++;
            d++;
            if(y%3==0 || m%2==1){
                if(d>20){
                    m++;d=1;
                }
            }else{
                if(d>19){
                    m++;d=1;
                }
            }
            if(m>10){
                m=1;y++;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}


Measured memory_bytes: 3076
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.lang.Math;

public class Main {
	public static void main(String[] args) {
		FS reader = new FS();
		// write reader
		int A = reader.nextInt();
		int B = reader.nextInt();
		solver(A, B);
	}
	
	public static void solver(int A, int B) {
		// write logic
		System.out.println(Math.max(Math.max(A+B, A-B), A*B));
	}
	
	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
	
		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	
		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}


Measured memory_bytes: 21076
#include <iostream>
#include <string>
using namespace std;
int main(){
  string A,B;
  cin >> A >> B;
  if (A.size() == B.size()){
    for (int i = 0; i <= A.size(); i++){
      if(A == B){
        cout << "EQUAL" << endl;
        break;
      }
      if(A.at(i) == B.at(i)){
        continue;
      } else {
        if(A.at(i) > B.at(i)){
          cout << "GREATER" << endl;
          break;
        } else {
          cout << "LESS" << endl;
          break;
        }
      }
    }
    
  } else {
    if(A.size() > B.size()){
      cout << "GREATER" << endl;
    } else {
      cout << "LESS" << endl;
    }
  }
}

Measured memory_bytes: 256
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush

sys.setrecursionlimit(10**6)
INF = 10**20

def mint():
    return map(int,input().split())
def lint():
    return map(int,input().split())

N = int(input())
a = [int(input()) for _ in range(N)]

tmp = 1
for i in range(1,N+1):
    tmp = a[tmp-1]
    if tmp==2:
        print(i)
        exit()
print(-1)

Measured memory_bytes: 79724
#import bisect,collections,copy,heapq,itertools,math,numpy,string
#from operator import itemgetter
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
N,K = LI()
A = LI()

#方針
#ループ検知でmod演算に移行
hist = []
now = 0
chk = [-1] * N
while True:
	hist.append(now+1)
	if chk[now] != -1:
		# ループ検知
		break
	chk[now] = len(hist)-1
	now = A[now]-1
#print("histpos[town]:",chk)
#print("hist:",hist)
loopstart = chk[hist[len(hist)-1]-1]+1
if K >= len(hist):
	K-=loopstart
	K%=len(hist)-loopstart
	print(hist[loopstart+K])
else:
	print(hist[K])


Measured memory_bytes: 33332
def main():
    N = int(input())
    shougen = []
    for _ in range(N):
        A = int(input())
        shougen.append([list(map(int, input().split())) for _ in range(A)])
    
    ans = 0
    for i in range(2**N):
        state = [1]*N
        
        for j in range(N):
            if (i >> j) & 1:
                state[j] = 0
        
        flag = True
        for k in range(N):
            if not flag:
                break
            if state[k] == 1:
                for ele in shougen[k]:
                    if state[ele[0]-1] != ele[1]:
                        flag = False
                        break
                    
        if flag:
            ans = max(ans, sum(state))
    
    print(ans)
                
    
if __name__  == '__main__':
    main()

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

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int x;
    cin>>x;
    if(x>=30) cout<<"Yes\n";
    else cout<<"No\n";
	return 0;
}

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

using ll=long long;
ll dp[110][101000];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, W;
  cin >> n >> W;
  int w[n], v[n];
  rep(i,110)rep(j,101000) dp[i][j] = 1001001001;
  dp[0][0] = 0;
  rep(i,n) cin >> w[i] >> v[i];
  rep(i,n){
    rep(V,100100){
      if(V - v[i]>=0) dp[i+1][V] = min(dp[i+1][V], dp[i][V - v[i]] + w[i]);
      dp[i+1][V] = min(dp[i+1][V], dp[i][V]);
    }
  }
  ll ans = 0;
  rep(V,100010){
    if(dp[n][V] <= W)  ans = V;
  }
  cout << ans << endl;
}

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

#define ll long long
#define mod 1000000007
#define pi 2.0*acos(0.0)

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

    int arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    sort(arr, arr + n);

    int ctx = 1;
    for (int i = 1; i < n; i++) {
        if (arr[i] == arr[i-1]) continue;
        else ctx++;
    }
    cout << ctx << endl;
}


Measured memory_bytes: 256
from collections import defaultdict
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7


def prime_factorization(n):
    table = []
    for x in range(2, int(n ** 0.5) + 1):
        while n % x == 0:
            table.append(x)
            n //= x
    if n > 1:
        table.append(n)
    return table


prime_max_factors = defaultdict(int)
for a in A:
    prime_factors = Counter(prime_factorization(a))
    for k, v in prime_factors.items():
        prime_max_factors[k] = max(prime_max_factors[k], v)


LCM = 1
for k, v in prime_max_factors.items():
    LCM *= pow(k, v, MOD)
LCM %= MOD

ans = 0
for a in A:
    ans += LCM * pow(a, MOD - 2, MOD)
    ans %= MOD

print(ans % MOD)



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

int main()
{
    int a[3][3];
    for (int i = 0; i < 3; i++) {
        std::cin >> a[i][0]>> a[i][1]>> a[i][2];
    }
    int n;
    std::cin >> n;
    std::string ans = "No";
    for (int i = 0; i < n; i++) {
        int b;
        std::cin >> b;
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (a[k][j] == b){
                    a[k][j] = 0;
                }
            }
        }
    }

    for (int i = 0; i < 3; i++) {
        if(!a[0][i] && !a[1][i] && !a[2][i]) {
            ans = "Yes";
        }
    }
    for (int i = 0; i < 3; i++) {
        if(!a[i][0] && !a[i][1] && !a[i][2]) {
            ans = "Yes";
        }
    }
    if(!a[0][0] && !a[1][1] && !a[2][2]) {
        ans = "Yes";
    }
    if(!a[0][2] && !a[1][1] && !a[2][0]) {
        ans = "Yes";
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))

res = 0
for i in range(n):
  a1_sum = sum(a1[:i+1])
  a2_sum = sum(a2[i:])
  res = max(res, a1_sum + a2_sum)

print(res)

Measured memory_bytes: 9192
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

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

    int h, w, n;
    cin >> h >> w >> n;

    vector<pair<int, int>> c(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i].first >> c[i].second;
    }

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

    int64_t p[10] = {};

    for (int i = 0; i < n; i++) {
        for (int x = -2; x <= 0; x++) {
            for (int y = -2; y <= 0; y++) {
                int a = c[i].first + x;
                int b = c[i].second + y;
                if (a < 1 || b < 1) continue;
                if (a + 2 > h || b + 2 > w) continue;
                int l = 0;
                for (int k = 0; k < 3; k++) {
                    auto i0 = lower_bound(c.begin(), c.end(), pair<int, int>{ a + k, b });
                    auto i1 = upper_bound(c.begin(), c.end(), pair<int, int>{ a + k, b + 2 });
                    l += (int)(i1 - i0);
                }
                p[l]++;
            }
        }
    }

    int r = 0;
    for (int i = 1; i < 10; i++) {
        p[i] /= i;
        r += p[i];
    }
    p[0] = (int64_t)(h - 2) * (w - 2) - r;
    for (int i = 0; i < 10; i++) {
        cout << p[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

void solve()
{
	int i,j;
	int n,k;
	cin>>n>>k;

	vector<int>a(n);

	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	d(a);
	sort(all(a));

	d(a);

	int ans=0;

	for(i=0;i<k;i++)
	{
		ans+=a[i];
	}

	cout<<ans<<endl;

}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
    using namespace std;
    
    #define ll long long
    #define pb push_back
    #define printV(v) for(int i=0;i<v.size();i++){cout << v[i]<< " ";} cout << endl
    #define printRev(v) for(int i=v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
    #define sortV(v) sort(v.begin(),v.end())
    #define revV(v) reverse(v.begin(),v.end())
    #define FOR(i,from,n) for(int i=from;i<n;i++)
    #define FOL(i,from,n) for(int i=from;i >= n;i--)
        
        ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,q;
        ll mod = 998244353;

        
        void solve(){
            double R; cin >> R;
            cout << 3.14159265359 * R * 2.0 << endl;
        }
            
        int main(){
        ios_base::sync_with_stdio(false);
        
        int cases = 1;
        //cin >> cases;
    
        while(cases--){ 
            solve();
        }

        return 0;

        }

Measured memory_bytes: 3808
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define DBG(X) cout<<" "<<#X<<" : "<<X<<endl
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;

const int INF = 1e9;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;

struct Input
{
	int n;char c;char str[10010];string s;ll l;double d;
	int nextInt(){scanf("%d", &n);return n;}
	ll nextLong(){scanf("%lld", &l);return l;}
	double nextDouble(){scanf("%lf", &d);return d;}
	char nextChar(){scanf("%c", &c);return c;}
	string next(){scanf("%s", str);return string(str);}
	string nextLine(){getline(cin, s);return s;}
};
Input in;

int main(){
	int n = in.nextInt(), m = in.nextInt();
	vector<int> p(m);
	rep(i, m) p[i] = in.nextInt()-1;
	vector<int> a, b, c;
	rep(i, n -1){
		a.pb(in.nextInt());
		b.pb(in.nextInt());
		c.pb(in.nextInt());
	}
	vector<int> v(n + 1, 0);
	for(int i = 0; i < m-1; i++){
		int f = p[i], t = p[i+1];
		if(f > t) swap(f, t);
		v[f]++;
		v[t]--;
	}
	for(int i = 0; i < n; i++){
		v[i+1] += v[i];
	}
	ll ans = 0LL;
	for(int i = 0; i < n; i++){
		ll s = (ll)a[i]*v[i];
		ll t = (ll)b[i]*v[i]+c[i];
		ans += min(s, t);
	}
	cout<<ans<<endl;
}

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

typedef long long ll;

int A,B,C,X,Y;

ll sum = 0;

void solve(int x) {
  while(1) {
    sum += x;
    X--;
    Y--;
    if ( X == 0 || Y == 0 ) return;
  }
}

void solve1() {
  while(1) {
    if( A >= C*2 ) {
      sum += C*2;
      X--;
      if( X == 0 ) return;
    } else {
      sum += A;
      X--;
      if( X == 0 ) return;
    }
  }
}

void solve2() {
  while(1) {
    if( B >= C*2 ) {
      sum += C*2;
      Y--;
      if( Y == 0 ) return;
    } else {
      sum += B;
      Y--;
      if ( Y == 0 ) return;
    }
  }
}

int main() {
  cin >> A >> B >> C >> X >> Y;
  if ( A+B > C*2 ) solve(C*2);
  else if ( A+B < C*2 ) solve(A+B);
  else if ( A+B == C*2 ) solve(A+B);

  if ( X > Y ) solve1();
  else if ( X < Y ) solve2();
  
  cout << sum << endl;
  return 0;
}


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

int main() {

	double n,kisu = 0;
	scanf("%lf", &n);
	for (int i = 1; i <= n; i++) {
		if (i % 2 == 1) {
			kisu++;
		}
	}

	printf("%lf", kisu / n);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int N, M;
vector<int> G[210000];

int dir[210000];

bool isbi = true;
void dfs(int v, int d) {
	dir[v] = d;
	for (auto e : G[v]) {
		if (dir[e] == -1) {
			dfs(e, 1 - d);
		}
		else {
			if (dir[e] == 1 - d) continue;
			else isbi = false;
		}
	}
}

int main() {
	while (cin >> N >> M) {
		for (int i = 0; i < 210000; ++i) G[i].clear();
		for (int i = 0; i < M; ++i) {
			int a, b;
			cin >> a >> b;
			--a, --b;
			G[a].push_back(b);
			G[b].push_back(a);
		}
		memset(dir, -1, sizeof(dir));
		dfs(0, 0);

		if (N <= 3) cout << 0 << endl;
		else {
			if (isbi) {
				int left = 0, right = 0;
				for (int i = 0; i < N; ++i) {
					if (dir[i] == 0) ++left;
					else ++right;
				}
				cout << (long long)left * right - M << endl;
			}
			else {
				cout << (long long)N * (N - 1) / 2 - M << endl;
			}
		}
	}
}



Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <cstdio>
#define fol(i,n) for(int i=0;i<n;i++)
using namespace std;

void solve(){
    string s;cin>>s;
    int ans = 0;
    fol(i,6){
        if (s[i]=='1') ans++;
    }
    cout << ans <<endl;
}
int main(){
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
typedef struct{
  int maxi;
  int maxj;
  double menseki;
}L;
int main(){
  int i,j,n,m=0,sump=0,summ=0,min,SS[20001],k=0,sum=0;
  char S[20000];
  L LL[10000];
  scanf("%s",S);
  n=strlen(S);
  min=0;
  SS[0]=0;
  for(i=0;i<n;i++){
    if(S[i]=='/')sump++;
    if(S[i]=='\\')summ--;
    SS[i+1]=sump+summ;
    if(min>SS[i+1]){
      min=SS[i+1];
    }
  }
  for(i=0;i<n+1;i++){
    SS[i]-=min;
  }
  for(i=0;i<n+1;i++){
    if(S[i]=='\\'){
      j=i+1;
      while(1){
	if(SS[i]==SS[j]){
	  LL[m].maxi=i;
	  LL[m].maxj=j;
	  m++;
	  i=j-1;
	  break;
	};
	j++;
	if(j==n+1)break;
      }
    }
  }
  
  for(i=0;i<m;i++){
    for(j=LL[i].maxi;j<LL[i].maxj;j++){
      if(S[j]=='\\' || S[j]=='/'){
	LL[i].menseki+=(1/2+fabs(SS[LL[i].maxi]-SS[j]));
      }
      if(S[j]=='_'){
        LL[i].menseki+=SS[LL[i].maxi]-SS[j];
      }
    }
  }
  for(i=0;i<m;i++){
    sum+=LL[i].menseki;
  }

  printf("%d\n%d",sum,m);
  for(i=0;i<m;i++){
    printf(" %d",(int)LL[i].menseki);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 688
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<lint,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
lint mo=1000000007;
lint extgcd(lint a, lint b, lint &x, lint &y) {
  lint g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
lint invMod(lint a, lint m) {
  lint x, y;
  if (extgcd(a, m, x, y) == 1) return (x + m) % m;return 0;
}
lint inv[20010010];
lint zyo[20010010];
lint rz[20010010];
//vector<lint> zyo,rz;
lint p(int a,int b){
	if(a<0 || a-b<0) return 0;
	return zyo[a]*rz[a-b]%mo;
}
int main()
{
	int h,w,k;lint out=0;
	cin>>h>>w>>k;lint x=((lint)h*w)%mo;
	inv[1] = 1;
    //REP(i,2,h+w+10) inv[i] = inv[mo%i] * (mo - mo/i) % mo;
	zyo[0]=1;rep(i,h+w+5) zyo[i+1]=zyo[i]*(i+1)%mo;
	rz[h+w+5]=invMod(zyo[h+w+5],mo);
	for(int i=h+w+5;i>0;i--) rz[i-1]=rz[i]*i%mo;
	//rz[0]=1;rep(i,h+w+5) rz[i+1]=rz[i]*inv[i+1]%mo;
	//return 0;
	//切らない
	out+=p(h+w,k)*k;out%=mo;
	//cout<<out<<endl;
	//片方切ればいい
	lint sum=0;
	rep(i,k){
		//lint t=(p(h+w-1,i)*p(h+w-i-1,k-i-1))%mo;
		lint t=p(h+w-1,k-1);
		//cout<<i<<' '<<t<<endl;
		//t*=i+1;t%=mo;
		//out+=t*(h+w);out%=mo;
		sum+=t*(i+1);sum%=mo;
	}
	out+=sum*(h+w);out%=mo;
	//cout<<out<<endl;
	sum=0;
	//両方切る
	rep(i,k-1){
		//lint t=p(h+w-2,i)*p(h+w-i-2,k-i-2)%mo;
		lint t=p(h+w-2,k-2);
		t*=2;t*=k-i-1;t%=mo;
		t*=i+1;//t%=mo;
		sum+=t;sum%=mo;
		//out+=t*x;out%=mo;
	}
	out+=sum*x;out%=mo;
	cout<<out<<endl;
}


Measured memory_bytes: 313600
/*  -*- coding: utf-8 -*-
 *
 * a.cc: C: Traveling
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

inline int hdist(int dx, int dy) { return abs(dx) + abs(dy); }

/* main */

int main() {
  int n;
  scanf("%d", &n);

  int t = 0, x = 0, y = 0;
  for (int i = 0; i < n; i++) {
    int ti, xi, yi;
    scanf("%d%d%d", &ti, &xi, &yi);

    int dt = ti - t, hd = hdist(xi - x, yi - y);
    if (hd > dt || (hd & 1) != (dt & 1)) {
      puts("No");
      return 0;
    }

    t = ti, x = xi, y = yi;
  }

  puts("Yes");
  return 0;
}


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

#define   sz   10010
#define   ll    long long int
#define   mod   1000000007



char grid[sz][sz];
ll dp[sz][sz],h,w,c=0;

bool ok(int i,int j)
{
    if(i>=1 && i<=h && j>=1 && j<=w && grid[i][j]=='.')return true;
    return
        false;
}

ll solve(int i,int j)
{
    if(i==h && j==w)return 1;

    if(dp[i][j]!=-1)return dp[i][j];

    ll p=0,q=0;

    if(ok(i,j+1))p=solve(i,j+1);
    if(ok(i+1,j))q=solve(i+1,j);

    return dp[i][j]=((p%mod)+(q%mod))%mod;

}

int main()
{
    memset(dp,-1,sizeof(dp));

    ll m,i,j,k;

    cin>>h>>w;

    for(i=1; i<=h; i++)
    {
        for(j=1; j<=w; j++)
        {
            cin>>grid[i][j];
        }
    }

    solve(1,1);

    cout<<solve(1,1)<<endl;

    return 0;
}


Measured memory_bytes: 795008
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll inf = numeric_limits<ll>::max()/3;

int count_bit(int b){
  int cnt = 0;
  while(b > 0){
    if(b & 1)
      ++cnt;
    b >>= 1;
  }
  return cnt;
}


int main(void){
  int n,m;
  cin >> n >> m;
  vector< vector<int> > G(n);
  for(int i = 0;i < m;++i){
    int a,b;
    cin >> a >> b;
    --a;--b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  ll dp[10][300];
  fill(dp[0], dp[0]+10*300, 0LL);
  dp[0][1] = 1;
  for(int k = 1;k < n;++k){
    for(int i = 0;i < n;++i){
      for(int b = 0;b < (1 << n);++b){
        if(count_bit(b) == k){
          for(int j : G[i]){
            if(!(b & (1 << j))){
              dp[j][b | (1 << j)] += dp[i][b];
            }
          }
        }
      }
    }
  }
  ll res = 0;
  for(int i = 0;i < n;++i){
    res += dp[i][(1 << n)-1];
  }
  cout << res << endl;
  return 0;
}



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

int main() {
	int a, b;
	string s;

	cin >> a >> b >> s;

	int i = 0;
	while (s[i] != NULL) {
		if (i == a)
			if (s[i] != '-') break;
		if (s[i] == '-')
			if (i != a) break;
		i++;
	}
	if (i == a + b + 1) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

int main(){
  string w;
  cin >> w;
  vector<int> a(26);
  
  for (int i=0;i<w.size();i++){
    a[(int)w[i]-97]++;
  }
  
  int ans=0;
  for(int i=0;i<26;i++){
    if(a[i]%2 == 1){
      ans++;
    }
  }
  
  if(ans == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No"  << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front

using ll = long long;
using namespace std;

ll M = 1000000007;

int main()
{
    string s;
    cin>>s;
    int n=s.size();
    int cnt=0;
    rep(i,s.size()/2){
        if(s[i]==s[n-i-1]){

        }else{
            cnt++;
        }
    }
    cout<<cnt<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a + b > c + d) {
    cout << "Left" << endl;
  } else if (a + b == c + d) {
    cout << "Balanced" << endl;
  } else {
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 256