akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const long double PI = 3.14159265358979323846264;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 200010
ll i1, j1, i2, j2, si, sj, n;
vector<P> x;

ll sgn(ll x){
	return x<0?-1:1;
}

int main(){
	cin>>i1>>j1>>i2>>j2;
	i2 -= i1; j2 -= j1;
	si = sgn(i2); sj = sgn(j2);
	i2 *= si; j2 *= sj;
	cin>>n;
	rep(i, n){
		ll a, b;
		cin>>a>>b;
		a -= i1; b -= j1;
		a *= si; b *= sj;
		if(a<0||a>i2||b<0||b>j2) continue;
		x.push_back(P(a, b));
	}
	n = x.size();
	sort(all(x));
	long double res = 100LL*(i2+j2);
	cout.precision(35);
	if(i2*j2==0 && false){
		if(!x.empty()) res += -20 + 10*PI;
		cout<<res<<endl;
		return 0;
	}
	vector<ll> lis;
	rep(i, n){
		ll t = x[i].snd;
		auto it = lower_bound(lis.begin(), lis.end(), t);
		if(it>=lis.end()) lis.push_back(t);
		else *it = t;
	}
	ll cnt = lis.size();
	if(cnt>=min(i2, j2)+1) res += 5*PI;
	res += (-20+5*PI)*cnt;
	cout<<res<<endl;

	return 0;
}


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

#define FOR(i,k,n)  for(int i=(k);i<(int)(n);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(x)  begin(x),end(x)

using namespace std;

bool subset_sum(const vector<int> &v, int s) {
  if (s < 0 || s > 16000) return false;
  vector<vector<bool>> dp(v.size()+1, vector<bool>(16001, false));
  dp[0][0] = true;
  REP(i,v.size()) {
    REP(j,16001) {
      dp[i+1][j] = dp[i][j];
      if (j >= v[i]) {
        dp[i+1][j] = dp[i+1][j] || dp[i][j-v[i]];
      }
    }
  }
  return dp.back()[s];
}

int main() {
  string s;
  cin>>s;
  int x, y;
  cin>>x>>y;
  vector<int> hl, vl;
  int vs = 0, hs = 0;
  int l = 0;
  bool v = false;
  bool first = true;
  for (char c : s) {
    if (c == 'F') {
      ++l;
    } else {
      if (l) {
        if (first) {
          x -= l;
        } else if (v) {
          vl.push_back(2*l);
          vs += l;
        } else {
          hl.push_back(2*l);
          hs += l;
        }
      }
      first = false;
      l = 0;
      v = !v;
    }
  }
  if (l) {
    if (first) {
      x -= l;
    } else if (v) {
      vl.push_back(2*l);
      vs += l;
    } else {
      hl.push_back(2*l);
      hs += l;
    }
  }
  if (subset_sum(hl, x + hs) && subset_sum(vl, y + vs)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 5632
import scala.io.StdIn

object Main extends App {
  val input = StdIn.readLine().toCharArray()
  var count = 0
  check(input, 0, false)
  println(count)
  def check(i: Array[Char], idx: Int, isPW: Boolean): Unit = {
    if (idx >= i.length)
      return
    var isNW = if (i(idx) == "0".toCharArray()(0)) true else false
    if (idx != 0 && isPW == isNW) {
      count += 1
      isNW = !isNW
    }

    val nIdx = idx + 1
    check(i, nIdx, isNW)
  }
}

Measured memory_bytes: 31224
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef pair<int, int> P;
typedef long long ll;

const int INF = 1 << 30;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool leap(int y)
{
	return ((y%4==0&&y%100!=0)||y%400==0);
}

#define debug(a, b, c) for(int i = 0; i < b; i++){for(int j = 0; j < c; j++){printf("%3d", a[i][j]);}puts("");}puts("-----------------------------------------");

int main()
{
	int len, squ[16][16];

	while(cin >> len)
	{
		if(!(len%2) || len == 0) break;

		for(int i = 0; i < 16; i++)
		{
			for(int j = 0; j < 16; j++)
			{
				squ[i][j] = -1;
			}
		}

		int ny = (len / 2) + 0.5;
		int nx = ny - 1;
		int num = 0;

		squ[len][len-1] = num;
		++num;

		for(int i = 0; i < len*len; i++)
		{
			int dx = nx+1, dy = ny+1;
			while(1)
			{
				if(dx >= len) dx = 0;
				if(dx < 0) dx = len - 1;
				if(dy > len-1) dy = 0;

				if(squ[dy][dx] == -1)
				{
					squ[dy][dx] = num;
					++num;
					nx = dx; ny = dy;
					break;
				}
				dx -= 1; dy += 1;
			}
		}

		for(int i = 0; i < len; i++)
		{
			for(int j = 0; j < len; j++)
			{
				printf("%4d", squ[i][j]);
			}
			puts("");
		}

	}
}

Measured memory_bytes: 1160
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	int N;
	int[][][] f;
	int[] counts;

	Main(BufferedReader in) throws IOException {
		N = Integer.parseInt(in.readLine());
		f = new int[101][101][101];

	}

	int f(int x, int y, int z) {
		return x * x + y * y + z * z + x * y + y * z + z * x;
	}

	void calc() {
		for (int x = 1; x <= 100; ++x) {
			for (int y = 1; y <= 100; ++y) {
				for (int z = 1; z <= 100; ++z) {
					f[z][y][x] = f(x, y, z);
				}
			}
		}
		counts = new int[N + 1];
		Arrays.fill(counts, 0);
		for (int x = 1; x <= 100; ++x) {
			for (int y = 1; y <= 100; ++y) {
				for (int z = 1; z <= 100; ++z) {
					int val = f[z][y][x];
					if (val <= N) {
						counts[val]++;
					}
				}
			}
		}

	}

	void showResult() {
		for (int i = 1; i <= N; ++i) {
			System.out.println(counts[i]);
		}
	}
}


Measured memory_bytes: 33308
t = input()

list_t = list(t)

n = len(list_t)

for i in range(n):
    if n == 1:
        list_t[i] = 'D'
        break
    if list_t[i] == '?':
        if i > 0 and i < n - 1:
            if list_t[i - 1] == 'P' and list_t[i + 1] == 'P':
                list_t[i] = 'D'
            if list_t[i - 1] == 'P' and list_t[i + 1] == 'D':
                list_t[i] = 'D'
            if list_t[i - 1] == 'P' and list_t[i + 1] == '?':
                list_t[i] = 'D'
            if list_t[i - 1] == 'D' and list_t[i + 1] == 'P':
                list_t[i] = 'D'
            if list_t[i - 1] == 'D' and list_t[i + 1] == 'D':
                list_t[i] = 'P'
            if list_t[i - 1] == 'D' and list_t[i + 1] == '?':
                list_t[i] = 'P'
        elif i > 0:
            if list_t[i - 1] == 'P':
                list_t[i] = 'D'
            if list_t[i - 1] == 'D':
                list_t[i] = 'D'
        elif i < n - 1:
            if list_t[i + 1] == 'P':
                list_t[i] = 'D'
            if list_t[i + 1] == 'D':
                list_t[i] = 'P'
            if list_t[i + 1] == '?':
                list_t[i] = 'D'


print(''.join(list_t))

Measured memory_bytes: 10876
N = int(input())

l1 = 2 ** 30
p6 = [1] * 7
p9 = [1] * 6
for i in range(1,7):
    p6[i] = p6[i-1] * 6
    if i < 6 : p9[i] = p9[i-1] * 9

dp = [l1] * (N+1)
dp[0] = 0

for i in range(1,N+1):
    for j in p6:
        if j>i: break
        dp[i] = min(dp[i],dp[i-j]+1)
        
    for j in p9:
        if j>i: break
        dp[i] = min(dp[i],dp[i-j]+1)
        
print(dp[N])

Measured memory_bytes: 3828
#include <iostream>
#include <map>
#include <string>

int main()
{
    std::map<std::string, int> m;
    int n;

    scanf("%d", &n);

    for (int i = 0; i < n; i++)
    {
        std::string temp;
        std::cin >> temp;

        if (m.find(temp) == m.end())
            m.insert(make_pair(temp, 1));
        else
            m[temp]++;
    }

    std::cout << m.size() << std::endl;
    return 0;
}

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

class Program {
    static Scanner cin = new Scanner();

    internal static void Main(string[] args) {
        int N, M;
        N = cin.nextInt();
        M = cin.nextInt();
        var first = new List<int>();
        var last = new List<int>();

        for (int i = 0; i < M; i++) {
            var a = cin.nextInt();
            var b = cin.nextInt();
            if (a == 1) { first.Add(b); }
            if (b == N) { last.Add(a); }
        }

        if (first.Intersect(last).Any()) {
            WriteLine("POSSIBLE");
        } else {
            WriteLine("IMPOSSIBLE");
        }
    }
}




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;
    }
}

Measured memory_bytes: 21172
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,sum,a[500001],b[500001],c[500001],sz[500001],id[500001];
vector<ll>zh[150001];
map<ll,ll>mp;
bool cmp(ll x,ll y){
	return a[x]>a[y];
}
void dfs(ll x,ll fa,ll now){
	ll i;
	sum+=now;
	for(i=0;i<zh[x].size();i++)if(zh[x][i]!=fa)dfs(zh[x][i],x,now+1);
}
int main(){
	ll i,x,y,w;
	scanf("%lld",&n);
	for(i=1;i<=n;i++)scanf("%lld",&a[i]),mp[a[i]]=i;
	for(i=1;i<=n;i++)sz[i]=1,id[i]=i;
	sort(id+1,id+n+1,cmp);
	for(i=1;i<n;i++){
		x=id[i];
		w=a[x]-(n-sz[x])+sz[x];
		//prllf("%d %d %d %d\n",x,a[x],sz[x],w);
		if(!mp[w]||w>=a[x])return puts("-1"),0;
		y=mp[w];
		b[i]=x;c[i]=y;
		zh[x].push_back(y);
		zh[y].push_back(x);
		sz[y]+=sz[x];
	}
	dfs(id[n],0,0);
	if(sum!=a[id[n]])return puts("-1"),0;
	for(i=1;i<n;i++)printf("%lld %lld\n",b[i],c[i]);
}
/*
*/

Measured memory_bytes: 30208
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

#define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

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

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

template <typename T> T gcd(T m, T n) { return n == 0 ? m : gcd(n, m % n); }
template <typename T> T lcm(T m, T n) { return n * m / gcd(n, m); }

signed main(void)
{
  int n; cin >> n;
  priority_queue<double, vector<double>, greater<double>> q;
  for (int i = 0; i < n; ++i) {
    double v; cin >> v;
    q.push(v);
  }

  for (int i = 1; i < n; ++i) {
    double x = q.top(); q.pop();
    double y = q.top(); q.pop();
    double z = (x + y) / 2.;
    q.push(z);
  }
  cout << q.top() << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <cctype>
//小文字を大文字 c-0x20;


#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define vvll(z,a,b) vector<vector<ll>>z(a,vector<ll>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
#define fix(k) fixed<<setprecision(k)
#define PI 3.141592653589793
using namespace std;



int main(){
    string s;cin>>s;
    size_t sin=s.length();
    
    int hu=0;
    rep(j,sin){
        int flag=0;
    for(int i=j;i<sin;i++){
        if((s[i]=='A')||(s[i]=='C')||(s[i]=='G')||(s[i]=='T')){
                flag++;
                continue;
        }else{
            break;
        }
    }
    if(hu<flag)hu=flag;
    }
    cout<<hu<<endl;

}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, 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 1; } return 0; }
const int INF = 1000000000;

int calc_distance(string s, string t){
    if (s.size() != t.size())return INF;

    int ret = 0;
    for (int i=0; i<s.size(); i++){
        if (s[i] != t[i])ret++;
    }
    return ret;
}

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

    int ts = t.size();
    int ans = INF;
    for (int i=0; i<s.size(); i++){
        chmin(ans, calc_distance(s.substr(i,ts), t));
    }
    cout << ans << endl;

}

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

int main(){
  int a,b,c,d,k;
  cin >> a >> b >> c >>k;
  d=max(a,max(b,c));
  r(i,k)d*=2;
  cout << a+b+c+d-max(a,max(b,c))<<endl;
}

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

int main(){
    int n;
    cin >> n;
    int a[n];
    int avg=0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        avg+=a[i];
    }
    avg/=n;
    int b=0;
    int c=0;
    for(int i=0; i<n; i++){
        b+=(a[i]-avg)*(a[i]-avg);
        c+=(a[i]-avg-1)*(a[i]-avg-1);
    }
    cout << min(b, c) << endl;
    return 0;
}

Measured memory_bytes: 3580
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    s = [0] * (N + 1)
    for i in range(0, N):
        s[i+1] = s[i] + A[i]
    ans = (1 << 63) - 1
    for j in range(1, N):
        left = s[j] - s[0]
        right = s[N] - s[j]
        ans = min(ans, abs(right - left))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 89296
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int a, b, n; cin >> a >> b >> n;

  int x = b-1;
  if(n < b-1) x = n;
  int ans = a * (x%b) / b;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3644
def decHand(hand)
  case hand
  when GU then PA
  when CHOKI then GU
  when PA then CHOKI
  end
end

GU = 'r'
CHOKI = 's'
PA = 'p'
all_hand = [GU, CHOKI, PA]

n, k = gets.split.map(&:to_i)
p_r, p_s, p_p = gets.split.map(&:to_i)
T = gets.chomp.split('')
point = 0
hands = []
T.each_with_index do |t, i|
  x = i - k
  y = i + k
  hand = decHand(t)

  if x >= 0
    if hands[x] == hand

      if y < n
        y_hand = decHand(T[y])
        a = all_hand - [hands[x], y_hand]
        hand = a.first
      else
        hand = begin
          case hand
          when GU then CHOKI
          when CHOKI then PA
          when PA then GU
          end
        end
      end

    end
  end

  hands << hand
  if (hand == GU) && (t == CHOKI)
    point += p_r
  elsif (hand == CHOKI) && (t == PA)
    point += p_s
  elsif (hand == PA) && (t == GU)
    point += p_p
  end
end
puts point

Measured memory_bytes: 22164
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
using namespace std;
int n, m;
vector<int> t;
vector<int> p, x;
int main() {
  cin>>n;
  t.resize(n+1);
  for (int i = 0;i  < n; ++i) {
  	cin>>t[i+1];
  }
  cin>>m;
  p.resize(m);
  x.resize(m);
  for (int i = 0; i < m; ++i) {
  	cin>>p[i]>>x[i];
  }
  for (int i = 0; i < m; ++i) {
  	int tot=0;
    for (int j = 1; j <= n; ++j) {
    	if (j == p[i]) tot+=x[i];
      else tot+=t[j];
    }
    cout<<tot<<endl;
  }
  
	return 0;
}

Measured memory_bytes: 256
import bisect


def solve(n, nums):
    nums.sort()
    i = bisect.bisect(nums, 0)
    if i == n:
        i -= 1
    elif i == 0:
        i += 1
    tmp1 = nums[0]
    tmp2 = nums[-1]
    buf = []
    for m in nums[1:i]:
        buf.append('{} {}'.format(tmp2, m))
        tmp2 -= m
    for m in nums[i:-1]:
        buf.append('{} {}'.format(tmp1, m))
        tmp1 -= m
    buf.append('{} {}'.format(tmp2, tmp1))
    print(tmp2 - tmp1)
    print('\n'.join(buf))


n = int(input())
nums = list(map(int, input().split()))
solve(n, nums)


Measured memory_bytes: 21068
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

double p1 (vector<int> x, vector<int> y) {
  double d = 0;
  int len = x.size();
  for (int i = 0; i < len; i++) {
    d += abs(x[i]-y[i]);
  }
  return d;
}

double p2 (vector<int> x, vector<int> y) {
  double d = 0;
  int len = x.size();
  for (int i = 0; i < len; i++) {
    d += pow(x[i]-y[i], 2);
  }
  return sqrt(d);
}

double p3 (vector<int> x, vector<int> y) {
  double d = 0;
  int len = x.size();
  for (int i = 0; i < len; i++) {
    d += pow(abs(x[i]-y[i]), 3);
  }
  return pow(d, 1.0/3.0);
}

double p_unlimited (vector<int> x, vector<int> y) {
  double d = 0.0;
  int len = x.size();
  for (int i = 0; i < len; i++) {
    d = max(d, abs(x[i]-y[i]));
  }
  return d;
}

int main(int argc, char* argv[]) {
  int n; cin >> n;
  vector<int> x, y;

  for (int i = 0; i < n; i++) {
    int in; cin >> in;
    x.push_back(in);
  }

  for (int i = 0; i < n; i++) {
    int in; cin >> in;
    y.push_back(in);
  }

  cout << fixed << setprecision(6);
  cout << p1(x, y) << endl;
  cout << p2(x, y) << endl;
  cout << p3(x, y) << endl;
  cout << p_unlimited(x, y) << endl;
  return 0;
}

Measured memory_bytes: 1328
#include <stdio.h>
#define NUM (8)

int VALUE[NUM] = {
	12121414, 21214141, 12141412, 21414121,
	14141212, 41412121, 14121214, 41212141
};
int RIDE[NUM][NUM] = {
	{1, 2, 1, 2, 1, 4, 1, 4}, {2, 1, 2, 1, 4, 1, 4, 1},
	{1, 2, 1, 4, 1, 4, 1, 2}, {2, 1, 4, 1, 4, 1, 2, 1},
	{1, 4, 1, 4, 1, 2, 1, 2}, {4, 1, 4, 1, 2, 1, 2, 1},
	{1, 4, 1, 2, 1, 2, 1, 4}, {4, 1, 2, 1, 2, 1, 4, 1}
};

int main(void) {
	int gast[NUM], remain, value, index, i, r, k, diff;

	while (scanf(
			"%d %d %d %d %d %d %d %d ", gast, gast+1, gast+2,
			gast+3, gast+4, gast+5, gast+6, gast+7) != EOF) {
		for (remain = i = 0; i < NUM; i++) {
			remain += gast[i];
		}
		value = 41412121;
		for (i = 0; i < NUM; i++) {
			for (r = k = 0; k < NUM; k++) {
				diff = gast[k] - RIDE[i][k];
				if (diff > 0) {
					r += diff;
				}
			}
			if (remain > r || (remain == r && value > VALUE[i])) {
				remain = r;
				index = i;
				value = VALUE[i];
			}
		}
		for (i = 0; i < (NUM-1); i++) {
			printf("%d ", RIDE[index][i]);
		}
		printf("%d\n", RIDE[index][i]);
	}
	return 0;
}

Measured memory_bytes: 600
//    _____ _     _                _           _     _ _     _     
//    \_   \ |_  (_)___  __      _| |__   __ _| |_  (_) |_  (_)___ 
//     / /\/ __| | / __| \ \ /\ / / '_ \ / _` | __| | | __| | / __|
//  /\/ /_ | |_  | \__ \  \ V  V /| | | | (_| | |_  | | |_  | \__ \
//  \____/  \__| |_|___/   \_/\_/ |_| |_|\__,_|\__| |_|\__| |_|___/
//                                                                 
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll div_floor(ll a, ll b) {
	// use when ret <= a/b, (a and b can be -ve)
	return a / b - (((a ^ b) < 0) and a % b);
}
ll div_ceil(ll a, ll b) { 
	// use when ret >= a/b, (a and b can be -ve)
	return a / b + (((a ^ b) >= 0) and a % b);
}
const int sz=1e3+9;
ll dp[sz][4][3];
string s;
int k;

ll solve(int idx,int rem,int can){
	ll &ret=dp[idx][rem][can];
	if(!idx) return ret=!rem;
	if(~ret) return ret;
	int val=s[idx]-'0';
	if(!rem) return ret=solve(idx-1,rem,can);
	ret=0;
	if(can) ret=9*solve(idx-1,rem-1,1)+solve(idx-1,rem,1);
	else{
		if(val) ret=solve(idx-1,rem-1,can);
		else ret=solve(idx-1,rem,can);
		for(int i=0;i<val;i++) ret+=solve(idx-1,rem-(i>0),can|1);
	}
	return ret;
}


int main(){
	cin>>s>>k;
	reverse(all(s));
	s="0"+s;
	memset(dp,-1,sizeof(dp));
	cout<<solve(s.size()-1,k,0);
	return 0;
}

Measured memory_bytes: 384
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
        
n, m = map(int,input().split())
A=[list(map(int,input().split())) for i in range(m)]
uf = UnionFind(n)
ans = [n*(n-1)//2]*m
for i in range(m-1,0,-1):
    a,b=A[i]
    a-=1
    b-=1
    ans[i-1]=ans[i]-(0 if uf.same(a,b) else uf.size(a)*uf.size(b))
    uf.union(a,b)
for r in ans:
    print(r)

Measured memory_bytes: 105560
n=int(input())
s=input()
def chk(x):
  x=str(x).zfill(3)
  res=False
  cur=0
  xx=x[0]
  for i in range(n):
    ss=s[i]
    if cur<2 and xx==ss:
      cur+=1
      xx=x[cur]
    elif xx==ss:
      res=True
      break
  return res

ans=0
for i in range(1000):
  if chk(i):
    ans+=1
print(ans)  


Measured memory_bytes: 42392
#include <iostream>
#include <bits/stdc++.h>
#define rawan ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define ll long long
using namespace std;
const int N = 1e5 + 5;
int main()
{
    rawan;
    int n,k;
    cin >> n >> k;
    ll arr[N],dp[N],ans;
    for(int i=0; i<n; i++)
    {
        cin >> arr[i];
    }
    for(int r=1; r<=k; r++)
        dp[r]=abs(arr[0]-arr[r]);
    for(int c=1; c<n; c++)
    {
        for(int r=1; r<=k; r++)
        {
            if(c-r<0)
            {
                break;
            }
            dp[c]=abs(arr[c]-arr[c-r])+dp[c-r];
            if(r==1)
                ans=dp[c];
            else
                ans=min(ans, dp[c]);
        }
        dp[c]=ans;
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long n, Min, Max, Sum;
    cin >> n;
    vector<long long> vec(n);
    for ( long long i =0 ; i<n;++i){
        cin >> vec[i];
    }
    Min = vec[0];
    Max = vec[0];
    Sum = 0;
    for (long long i=0;i<n;++i){
        Min = min(Min,vec[i]);
        Max = max(Max,vec[i]);
        Sum = Sum + vec[i];
    }
    cout << Min << " " << Max << " " << Sum << endl;
}


Measured memory_bytes: 3188
class UnionFind:
    def __init__(self,n):
        super().__init__()
        self.par = [-1]*n
        self.rank = [0]*n
        self.tsize = [1]*n

    
    def root(self,x):
        if self.par[x] == -1:
            return x 
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x_r = self.root(x)
        y_r = self.root(y)
        
        if self.rank[x_r]>self.rank[y_r]:
            self.par[y_r] = x_r

        elif self.rank[x_r]<self.rank[y_r]:
            self.par[x_r] = y_r

        elif x_r != y_r:
            self.par[y_r] = x_r
            self.rank[x_r] += 1

        if x_r != y_r:
            size = self.tsize[x_r]+self.tsize[y_r]
            self.tsize[x_r] = size
            self.tsize[y_r] = size

    def isSame(self,x,y):
        return self.root(x) == self.root(y)

    def size(self,x):
        return self.tsize[self.root(x)]

def main():
    n,m = tuple([int(t)for t in input().split()])

    t = [tuple([int(t)-1 for t in input().split()])for _ in [0]*m]

    ans = 0
    for k in range(m):
        uf = UnionFind(n)
        for i in range(m):
            if k!=i:
                uf.unite(t[i][0],t[i][1])
        if uf.size(0) !=n :ans+=1
    
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>
#include <math.h>
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define RREP(i,n) for(ll i=(n)-1; i>=0; --i)
#define SREP(i,s,n) for(ll i=(s), i##_len=(n); i<i##_len; ++i)


using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

bool comp(pair<ll, ll> a, pair<ll, ll> b) {
    return (a.first*a.first + a.second*a.second) > (b.first*b.first + b.second*b.second);
}

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    
    UnionFind(int n = 1) {
        init(n);
    }
    
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

#define MOD (1000000007)

int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    double a, b, x;
    cin >> a >> b >> x;
    if (x > a*a*b/2) {
        double trad = atan2(2*a*a*b - 2*x, a*a*a);
        cout << setprecision(9) << trad/M_PI*180.0 << endl;
    } else {
        double trad = atan2(a*b*b, 2*x);
        cout << setprecision(9) << trad/M_PI*180.0 << endl;
    }

}


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

int mod = 1000000007;

int main()
{
    int N, M, p, q, L = 0, R = 100000;
    cin >> N >> M;

    for (int i = 0; i < N; i++)
    {
        cin >> p >> q;
        L = max(L, p);
        R = min(R, q);
    }
    cout << max(0, R - L + 1);
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
#define int128 __int128
using namespace std;
const int128 mod=1e9+7;
const int maxn=2048;
int nums[maxn];
long long N,K;
int main()
{
    int128 ans=0;
    // freopen("in.txt","r",stdin);
    scanf("%lld %lld",&N,&K);
    int128 time14=K*(K+1)/2;
    int128 time23=K*(K-1)/2;
    for(int i=1;i<=N;i++) scanf("%d",&nums[i]);
    for(int i=1;i<=N;i++)
    {
        int128 time1=0,time2=0,time3=0,time4=0;
        for(int x=1;x<i;x++)
        {
            if(nums[x]>nums[i]) time1+=1;
            else if(nums[x]<nums[i]) time3+=1;
        }
        for(int x=i+1;x<=N;x++)
        {
            if(nums[x]>nums[i]) time2+=1;
            else if(nums[x]<nums[i]) time4+=1;
        }
        ans+=((time1+time4)*time14);
        ans+=((time2+time3)*time23);
    }
    ans/=(int128)2;ans%=mod;
    printf("%lld",(long long)ans);
    return 0;
}

Measured memory_bytes: 256
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    N = Number(input.split(" ")[0]);
    A = Number(input.split(" ")[1]);
    B = Number(input.split(" ")[2]);
    sum=0;
    
    for(n = 0; n<= N ; n++){
        tmpsum = 0;
        for(i=0;i<String(n).length;i++){
            tmpsum +=Number(String(n).slice(i,i+1));
        }

        if(tmpsum <= B && tmpsum >= A){
            sum += n;
        }
    }
    console.log(sum);
}
    


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


Measured memory_bytes: 12344
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------

bool check(ll len){
    unordered_map<string,ll> mp;
    bool ok=false;
    rep(i,n-len+1){
        tmp=mp[s.substr(i,len)];
        if(tmp==0)mp[s.substr(i,len)]=i+len;
        else{
            if(i<=tmp-1)continue;
            ok=true;
        }
    }
    return ok;
}
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n>>s;
    ll le=0,ri=n,mid;
    while(ri-le>1){
        mid=(le+ri)/2;
        if(check(mid))le=mid;
        else ri=mid;
    }
    rrrep(i,min(ri+5,n),max(le-5,1LL)){
        if(check(i)){
            ans=i;
            break;
        }
    }
    //Cout(s.substr(0,2));
    Cout(ans);
    return 0;
}

Measured memory_bytes: 6688
N, K = map(int, input().split())
count = 0
m_list = []
for i in range(N):
    m_list.append(list(map(int, input().split())))

m_list.sort(key=lambda x: x[0])

for m in m_list:
    count += m[1]
    if count >= K:
        print(m[0])
        break


Measured memory_bytes: 29144
#![allow(unused_macros)]

// cf. [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita](https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8)
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        N: usize,
        A: [i64; N],
    }
    use std::collections::{HashSet, BinaryHeap};
    let mut once = HashSet::new();
    let mut twice = BinaryHeap::new();
    for i in 0..A.len() {
        if !once.contains(&A[i]) {
            once.insert(A[i]);
        } else {
            once.remove(&A[i]);
            twice.push(A[i]);
        }
    }
    if twice.len() <= 1 {
        println!("0");
    } else {
        let x =  twice.pop().unwrap();
        let y = twice.pop().unwrap();
        println!("{}", x * y);
    }
}


Measured memory_bytes: 8444
#include <utility>
#include <algorithm>
#include <cstdio>

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define a first
#define b second

static const int MAXN = 200100;

static pll pnts[MAXN];
struct CHT
{
	int ptr = 0, sz = 0;

	bool bad(pll p0, pll p1, pll p2) { return (p1.a - p0.a) * (p2.b - p0.b) - (p2.a - p0.a) * (p1.b - p0.b) > 0; }
	void add(pll p)
	{
		while (sz > 1 && bad(pnts[sz - 2], pnts[sz - 1], p)) --sz;
		pnts[sz++] = p;
	}
	ll val(int i, ll x) { return pnts[i].a * x + pnts[i].b; }
	ll get(ll x)
	{
		ptr = min(ptr, sz - 1);
		while (ptr < sz - 1 && val(ptr, x) > val(ptr + 1, x)) ++ptr;
		return val(ptr, x);
	}
} cht;

int N;
ll h, c, f;

int main()
{
	scanf("%d %lld", &N, &c);
	for (int i = 0; i < N; ++i) {
		scanf("%lld", &h);
		f = (i == 0 ? 0 : cht.get(h) + h * h + c);
		cht.add(pll(-2 * h, h * h + f));
	}
	printf("%lld\n", f);
}

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

int main(void){
    char s[11], t[11]; 

    scanf("%s%s", s, t);
    if(strlen(s) + 1 == strlen(t)){
        for(int i = 0; i < strlen(s); i++){
            if(s[i] == t[i]){
                if(i  == (strlen(s) - 1)){
                    printf("Yes\n");
                }
            }else{
                printf("No\n");
                return 0;
            }
        }
    }else{
        printf("No\n");
    }

    return 0;

} 


Measured memory_bytes: 3760
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

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

int n;
int c[10000];


int solve(int l) {
	int r = l + 1, res = n;

	while (l >= 0 && r < n) {
		int color = c[l];
		int count = 0;
		for (; l >= 0 && c[l] == color; l--, count++);
		for (; r < n && c[r] == color; r++, count++);

		if (count < 4) break;
		res -= count;
	}
	return res;
}

int main() {
	while (true) {
		int ans;
		cin >> n;
		if (n == 0) break;

		REP(i, n) scanf("%d", &c[i]);

		ans = n;
		REP(i, n) {
			int tmp = c[i];
			REP(j, 3) {
				c[i] = j + 1;
				ans = min(ans, solve(i));
			}
			c[i] = tmp;
		}

		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e14;
const ll mod = 1e9+7;
// __uint128_t


ll N, M;
ll MAX = 1e5+5;
vector<ll> DP(MAX), DP2(MAX);
vector<vector<ll>> G(MAX);


int dfs(ll x, ll p){
    ll res = 1;
    for(auto v : G[x]){
        if(v == p) continue;
        res *= (dfs(v, x)+1);
        res %= M;
    }
    DP[x] = res;
    return DP[x];
}

void dfs2(ll x, ll p = -1){
    vector<ll> pt;
    for(auto v : G[x]) if(v != p) pt.push_back(v);
    vector<ll> Acc1(pt.size()+2, 1), Acc2(pt.size()+2, 1);
    for(int i = 0; i < pt.size(); i++) Acc1[i+1] = Acc2[i+1] = DP[pt[i]]+1;

    for(int i = 0; i < Acc1.size()-1; i++) {Acc1[i+1] *= Acc1[i]; Acc1[i+1] %=M;}
    for(int i = Acc2.size()-1; i > 0; i--) {Acc2[i-1] *= Acc2[i]; Acc2[i-1] %=M;}

    for(int i = 0; i < pt.size(); i++){
        ll idx = i+1;
        ll v = pt[i];
        DP2[v] = (((Acc1[idx-1] * Acc2[idx+1])%M) * DP2[x])%M + 1;
    }
    for(auto v : G[x]){
        if(p != v)dfs2(v, x);
    }
}

int main(){
    cin >> N >> M;
    DP.resize(N);
    DP2.resize(N);
    G.resize(N);
    for(int i = 0; i < N-1; i++){
        ll a, b; cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0, -1);
    DP2[0] = 1;

    dfs2(0);

    for(int i = 0; i < N; i++) cout << (DP[i]*DP2[i])%M << endl;

}

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

void dfs(const vector<vector<int>> &graph, vector<int> &dist, int v, int d){
    dist[v] = d;
    for(auto next : graph[v]){
        if (dist[next] < 0) {
            dfs(graph, dist, next, d + 1);
        }
    }
}

int main(){
    int N, u, v;

    cin >> N >> u >> v;
    vector<vector<int>> tree(N);
    vector<int> dist_u;
    vector<int> dist_v;

    u--; v--;

    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        tree[a - 1].push_back(b - 1);
        tree[b - 1].push_back(a - 1);
    }

    dist_u.assign(N, -1);
    dist_v.assign(N, -1);

    dfs(tree, dist_u, u, 0);
    dfs(tree, dist_v, v, 0);

    int d_max = 0;
    for (int i = 0; i < N; i++) {
        if (dist_u[i] < dist_v[i]) {
            if (d_max <= dist_v[i]) {
                d_max = dist_v[i];
            }
        }
    }
    cout << d_max - 1 << endl;

    return 0;
}

Measured memory_bytes: 13172
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
//using Graph = vector<vector<int>>;


const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
ll gcd(ll a,ll b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
ll lcm(ll a,ll b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}









int main() {
ll a,b,c,d;
cin >> a >> b >> c >> d;
ll ans1 = a * c;
ll ans2 = a * d;
ll ans3 = b * c;
ll ans4 = b * d;

ll ma = max(ans1,ans2);
ma = max(ma,ans3);
ma = max(ma,ans4);
cout << ma << endl;

}


Measured memory_bytes: 3716
object Main extends App {
  def rotate(chars:Array[Char]) = {
    chars.last +: chars.init
  }
  def isEqual(chars1:Array[Char],chars2:Array[Char]) = {
    (0 until chars1.length).map(i=>{
      chars1(i)==chars2(i)
    }).forall(f=>f)
  }
  val scanner = new java.util.Scanner(System.in)
  var s = scanner.next().toCharArray
  val t = scanner.next().toCharArray
  var flag = false
  (0 until s.length).foreach(_ => {
    if (isEqual(s,t)){
      flag = true
    }
    s = rotate(s)
  })
  if (flag){
    println("Yes")
  } else {
    println("No")
  }
}

Measured memory_bytes: 25992
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int H1, M1, H2, M2, K;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> H1 >> M1 >> H2 >> M2 >> K;

	int st = H1 * 60 + M1;
	int gl = H2 * 60 + M2;

	int len = gl - st;
	int ans = len - K;
	cout << ans << endl;
}







Measured memory_bytes: 3684
import sys

sys.setrecursionlimit(2**31-1)#ループ回数

def paint(point, color):
    colors[point] = color

    # その点とつながる点で、まだ色が塗られていない点にルールに従い色を塗る
    for friend, w in reration[point]:
        if not colors[friend]:  # 塗られてない点
            # print(str(i)+"塗る")
            nextcolor = color*(-1)**w
            paint(friend, nextcolor)


N = int(input())
reration = [[] for i in range(N)]  # その点がつながる点
colors = ["" for i in range(N)]  # 色(作業中は簡単のため1,-1の2つに塗り分ける)
for i in range(N-1):
    U, V, W = map(int, input().split())
    reration[U-1].append((V-1, W % 2))
    reration[V-1].append((U-1, W % 2))

# print(hen)
# print(reration)
for i in range(N):
    if not colors[i]:
        paint(i, 1)
for co in colors:
    print((co+1)//2)


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

int main(){
    int n, m, x, ans=0;
    cin >> n >> m;
    vector<int> X, size;
    for(int i=0;i<m;i++){
      cin >> x;
      X.push_back(x);
    }
    sort(X.begin(), X.end());
    for(int i=1;i<m;i++){
      size.push_back(X[i] - X[i-1]);
    }
    sort(size.begin(), size.end(), greater<int>());
    for(int i=0;i<m;i++){
      if(i+1>n-1){
        ans += size[i];
      }
    }
    cout << ans << endl;
    return 0;
 
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

/* Tutorial:
  Notice that we can always make a valid state with min(n - 1, k) empty positions
  Why?
    0 empty positions (k >= 2 and n >= 3 are important):
      if k is even:
        move a person back and forth (i -> j -> ... -> j -> i)
      if k is odd:
        move a person back and forth,
        until there are 3 movements left, (i -> j -> ... -> i -> j -> k -> i)
    1 empty positions:
      use (0 empty positions) until there are only 1 movement
      then move any person anywhere
    m empty positions:
      use (0 emtpy positions) until there are only m movements
      then move m people anywhere

  ans = 0
  for m in [0, min(n - 1, k)]:
    ans += f(m)
  Where f(m) is the number of ways to make a valid state with m empty positions
  That can be decomposed into:
    (the number of ways to place those m empty positions)
      = choose(n, m)
    times
    (the number of ways to populate (n - m) non-empty positions with m people)
      = m stars and n - m - 1 bars
      = StarsAndBars(m, n - m - 1) = choose(m + (n - m - 1), n - m - 1) = choose(n - 1, n - m - 1)
  So, f(m) = choose(n, m) * choose(n - 1, n - m - 1)
*/

const int maxN = 2e5; int n; lli k;
const lli mod = 1e9 + 7;

lli fat[maxN + 2], invFat[maxN + 2];
lli modPow(lli x, lli y)
{
  lli ans = 1;
  while (y)
  {
    if (y & 1LL) ans = ans * x % mod;
    x = x * x % mod, y >>= 1LL;
  }
  return ans;
}
lli inv(lli x)
{
  return modPow(x, mod - 2);
}
lli choose(lli nn, lli kk)
{
  if (nn < kk) return 0;
  if (nn < mod) return fat[nn] * invFat[kk] % mod * invFat[nn - kk] % mod;
  lli ans = 1;
  while (nn || kk)
  {
    lli nnn = nn % mod, kkk = kk % mod;
    nn /= mod, kk /= mod;
    ans = ans * choose(nnn, kkk) % mod;
  }
  return ans;
}
// nn = stars, kk = bars
lli starsAndBars(lli nn, lli kk)
{
  return choose(nn + kk, kk);
}

int main()
{
  fat[0] = 1;
  for (lli i = 1; i <= maxN; i++)
    fat[i] = i * fat[i - 1] % mod;
  for (int i = 0; i <= maxN; i++)
    invFat[i] = inv(fat[i]);

  while (scanf("%d %lld", &n, &k) != EOF)
  {
    lli ans = 0;
    for (int m = 0, end = min((lli)n - 1, k); m <= end; m++)
      ans = (ans + choose(n, m) * starsAndBars(m, n - m - 1) % mod) % mod;
    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    ll h, w;
    cin >> h >> w;

    if (h == 1 || w == 1) {
        cout << 1 << endl;
    } else {
        cout << (h*w+1)/2 << endl;
        
    }


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int days[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string week[] = {"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"};

void solve()
{
	int m, d;
	while(cin >> m >> d, m || d)
	{
		int sum = 0;
		for(int i = 1; i < m; ++i)
		{
			sum += days[i - 1];
		}
		sum += d - 1;
		cout << week[sum % 7] << endl;
	}
}

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

Measured memory_bytes: 1192
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc= new Scanner(System.in);
		
		String S= sc.nextLine();
		sc.close();
		
		char[]s= S.toCharArray();
		
		int  size= s.length;
		String ans;
		if(s[size-1] != 's')ans= S+ "s";
		else ans= S+ "es";
		
		System.out.println(ans);
				
	}

}


Measured memory_bytes: 38576
#include <stdio.h>

int main(void)
{
	int S, h, m, s;

	scanf("%d", &S);

	h = S / 3600;
	S = S - (h * 3600);
	m = S / 60;
	S = S - (m * 60);
	s = S;

	printf("%d:%d:%d\n", h, m, s);

	return(0);
}

Measured memory_bytes: 1860
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = Integer.parseInt(in.nextLine());
		long power = 1;
		long mod = (long) Math.pow(10, 9) + 7;
		
		for (int j = 1; j <= n; j++) {
			power = (long) ((power * j) % mod);
		}
		System.out.println(power);
	}

}

Measured memory_bytes: 21844