akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
using P = pair<ll,ll>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
/////////

// h w iが作れる？
bool dp[100][100][20000];

void solve(){
  ini(H , W);
  vvi a(H , vi(W , 0)) , b(H , vi(W , 0));
  in(a); in(b);
  rep(i , H) rep(j , W) a[i][j] = abs(a[i][j] - b[i][j]);

  rep(i , H) rep(j , W){
    if(i == 0 && j == 0) dp[i][j][a[i][j]] = 1;
    else{
      rep(k , 19000){
        int cur = a[i][j];
        if(i != 0){
          dp[i][j][k] |= dp[i-1][j][abs(cur - k)];
          dp[i][j][k] |= dp[i-1][j][abs(cur + k)];
        }
        if(j != 0){
          dp[i][j][k] |= dp[i][j-1][abs(cur - k)];
          dp[i][j][k] |= dp[i][j-1][abs(cur + k)];
        }
      }
    }
  }

  rep(i , 81){
    if(dp[H-1][W-1][i]) die(i);
  }
  exit(1);
  
}

Measured memory_bytes: 157568
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

X = int(input())

s = set([1])
for i in range(min(2, X), X):
    cnt = 2
    while i**cnt<=X:
        s.add(i**cnt)
        cnt += 1

print(max(s))

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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int N = 200005;

int n, k, a[N];
int sum[N];
int h, t, Q[N];
bool flag[N];

int main() {
	read(n), read(k);
	for (int i = 1; i <= n; ++i) {
		read(a[i]);
	}
	for (int i = 2; i <= n; ++i) {
		sum[i] = sum[i - 1] + (a[i] > a[i - 1]);
	}
	for (int i = k + 1; i <= n; ++i) {
		flag[i] = 1;
	}
	h = 1, t = 0;
	for (int i = 1; i <= n; ++i) {
		while (h <= t && a[Q[t]] < a[i]) {
			--t;
		}
		Q[++t] = i;
		while (h <= t && Q[h] <= i - k) {
			++h;
		}
		if (i > k) {
			flag[i] &= Q[h] == i;
		}
	}
	h = 1, t = 0;
	for (int i = 1; i <= n; ++i) {
		while (h <= t && a[Q[t]] > a[i]) {
			--t;
		}
		Q[++t] = i;
		while (h <= t && Q[h] <= i - k) {
			++h;
		}
		if (i >= k && i < n) {
			flag[i + 1] &= Q[h] == i - k + 1;
		}
	}
	int ans = 0;
	for (int i = k; i <= n; ++i) {
		if (!flag[i] && sum[i] - sum[i - k + 1] != k - 1) {
			++ans;
		}
	}
	for (int i = k; i <= n; ++i) {
		if (sum[i] - sum[i - k + 1] == k - 1) {
			++ans;
			break;
		}
	}
	print(ans);
}


Measured memory_bytes: 7384
#include <stdio.h>
#include <stdlib.h>

#define N 1000000
#define INT(X) \
  ( *( (const int *)(X) ) )

int comparator (
  const void  * a,
  const void  * b
  )
{
  return ( INT( a ) - INT( b ) );
}

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i;

  for ( ; ; )
  {
    int d[ N ];
    int n;

    scanf ( "%d", &n );
    if ( !( n ) ) break ;
    for ( i = 0; i < n; ++i )
    {
      scanf ( "%d", d + i );
    }
    qsort ( d, n, sizeof ( int ), comparator );

    for ( i = 0; i < n; ++i )
    {
      int c;

      for ( c = i; c < n && d[ i ] == d[ c ]; ++c ) ;
      if ( c - i > n / 2 )
      {
        printf ( "%d\n", d[ i ] );
        goto CONTT;
      }
    }
    puts ( "NO COLOR" );
CONTT: ;
  }

  return ( 0 );
}

Measured memory_bytes: 7568
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <math.h>
#include <string.h>
#define mp make_pair
#define pb push_back
#define pm %1000000007
#define llc (long long)
#define ldc (long double)
#define poc __builtin_popcount
using namespace std;

int modex(int b, int e){
	int h = 1;
	while(e){
		if(e&1)h=llc h*b pm;
		b=llc b*b pm;
		e>>=1;
	}
	return h;
}
int main(){
	long long n, p, res=1;
	int ctr;
	cin>>n>>p;
	for(int i = 2;llc i*i <= p;i ++){
		if(p%i==0){
			ctr=0;
			while(p%i==0){
				ctr++;
				p/=i;
			}
			ctr/=n;
			while(ctr--){
				res*=i;
			}
		}
	}
	if(p!=1&&n==1)res*=p;
	printf("%lld\n", res);
}


Measured memory_bytes: 256
"use strict";
const main = arg => {
  let water = arg.split(" ").map(x=> x*1);
  let ans = water[2] + water[1] - water[0] >= 0? water[2] + water[1] - water[0]:0;
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
#include<bits/stdc++.h>                                                                          
using namespace std;
int main()
{
  string A,B;
  cin >> A >> B;
  if(A.size()>B.size()){
    cout << "GREATER" << endl;
  }
  else if(A.size()<B.size()){
    cout << "LESS" << endl;
  }
  if(A.size()==B.size()){
    if(A>B){
      cout << "GREATER" << endl;
    }
    else if(A<B){
      cout << "LESS" << endl;
    }
    else if(A==B){
      cout << "EQUAL" << endl;
    }
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
	public static final MyScanner in = new MyScanner();
	public static int[][][][] memo;
 
	public static void main(String[] args) {
 
		long N = in.nextLong();
		long K = in.nextLong();
		int cnt = 1;
		N += 1;
		while(N > Math.pow(K, cnt)) cnt++;
 
		System.out.println(cnt);
 
	}
 
 
	public static class MyScanner{
		Scanner sc = new Scanner(System.in);
		String nextLine() {return sc.nextLine();}
		String next() {return sc.next();}
		int nextInt() {return Integer.valueOf(sc.next());}
		long nextLong() { return Long.valueOf(sc.next());}
	}
}

Measured memory_bytes: 23764
#!/usr/bin/python

import re

def clean(t):
    res = re.sub(r'[A-Z]0', '', t)
    res = re.sub(r'([A-Z])(\d+)\1(\d+)', lambda m: m.group(1)+str(int(m.group(2))+int(m.group(3))), res)
    res = re.sub(r'([A-Z])(\d+)\1(\d+)', lambda m: m.group(1)+str(int(m.group(2))+int(m.group(3))), res)
    res = re.sub(r'([A-Z])(\d+)\1(\d+)', lambda m: m.group(1)+str(int(m.group(2))+int(m.group(3))), res)

    res = re.sub(r'([A-Z])(\d+)', r'\1 \2 ', res) + '$'

    return res

def main():
    A = raw_input()
    B = raw_input()
    C = raw_input()

    dele = re.compile(r' |\$')
    a = dele.sub('', A)
    b = dele.sub('', B)
    c = dele.sub('', C)

    num = re.findall(r'^\w(\d+)|(\d+)$', b)

    if len(num) == 1:
        ch1 = b[0]
        int1 = int(b[1:])
        res = ''
        repled = False
        for s in re.findall(r'([A-Z])(\d+)', a):
            if s[0] != ch1 or repled:
                res += s[0] + s[1]
            elif int(s[1]) >= int1:
                res += c + s[0] + str(int(s[1])-int1)
                repled = True
            else:
                res += s[0] + s[1]

        print clean(res)
        return

    L = int(num[0][0])
    R = int(num[1][1])

    b = re.sub(r'\d+', r'(\\d+)', b, 1)
    b = re.sub(r'\d+$', r'(\\d+)', b)

    #print 'str:', a
    #print 're:', b
    #print 'repl:', c

    key = re.compile(b)
    m = key.search(a)
    while m is not None:
        int1 = int(m.group(1))
        int2 = int(m.group(2))
        #print int1, int2
        if L <= int1 and R <= int2:
            ch1 = m.group()[0]
            ch2 = re.search(r'([A-Z])\d+$', m.group()).group(1)
            a = a[:m.start()] + key.sub(ch1+str(int1-L)+c+ch2+str(int2-R), a[m.start():], 1)
            break

        m = key.search(a, pos=m.end())

    print clean(a)

if __name__ == '__main__':
    main()

Measured memory_bytes: 7240
# coding: utf-8
# Your code here!
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[10000000000]*n
dp[0]=0
for i in range(n):
    if i==0:
        continue
    dp[i]=min(dp[i],abs(h[i]-h[i-1])+dp[i-1])        
    if i>1:
        for K in range(k+1):
            if i-K<0:
                break
            else:
                dp[i]=min(dp[i],abs(h[i]-h[i-K])+dp[i-K])
    #print(dp)
print(dp[n-1])
#print(dp)

Measured memory_bytes: 52448
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll int,ll int>
#define pb push_back
#define sbit __builtin_popcount
#define vec vector <int>
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define bg begin()
#define en end()
#define endl "\n"
#define ff first
#define ss second
#define all(x) x.bg,x.en
#define sz(a) (int)a.size()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define sp(x) setprecision(x)
#define fill(a,b) memset(a,b,sizeof(a))
#define fr(i,n) for(int i=0;i<n;i++)
#define rp(i,a,b) for(int i=a;i<b;i++)
#define rr(i,a,b) for(int i=a;i>=b;i--)
#define ft(it,x) for(auto it : x)
#define dbg(x) cerr<<#x<<" "<<x<<endl;
#define dbga(arr,n) cerr<<#arr<<": "; rep(tt,0,n)cerr<<arr[tt]<<" "; cerr<<endl;
#define mapi map<int,int>
#define mapl map<ll int,ll int>
#define val_at(x) find_by_order(x)
#define idx_of(x) order_of_key(x)
#define scni(x) scanf("%d",&x)
#define prt(x) printf("%d\n",x)
#define test(t) int t;cin>>t;while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define val_at(x) find_by_order(x)
#define idx_of(x) order_of_key(x)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> myset;
const int mod=1e9+7;
const int mex=1e6+1;
inline ll power(ll a,ll b)
{
    ll ans=1,temp=a;
    while(b!=0)
    {
        if(b&1)
        ans=ans*temp;
        ans=ans%mod;
        temp=temp*temp;
        temp=temp%mod;
        b/=2;
    }
    return ans;
}
int pr[mex];
vec prime;
inline void seive()
{
    rp(i,2,mex) pr[i]=1;
    for(int i=2;i*i<mex;i++)
    {
        if(pr[i])
        for(int j=i*i;j<mex;j+=i)
        pr[j]=0;
    }
    vec prime;
    rp(i,2,mex)
    {
        if(pr[i]) prime.pb(i);
    }
}
ll int xx,xy,d1;
void exeu(ll int a1,ll int b1)
{
    if(b1==0)
    {
        xx=1;
        xy=0;
        d1=a1;
    }
    else
    {
        exeu(b1,a1%b1);
        ll int temp=xx;
        xx=xy;
        xy=temp-(a1/b1)*xy;
    }
}
ll int modinv(ll int A,ll int M)
{
    exeu(A,M);
    return (xx%M+M)%M;
}
int main()
{
    fast
    int m,n;
    cin>>m>>n;
    if(m==n) cout<<"Yes\n";
    else cout<<"No\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;


void weather_predicition()
{
  string s;
  cin >> s;

  if (s == "Sunny") cout << "Cloudy\n";
  else if (s == "Cloudy") cout << "Rainy\n";
  else if (s == "Rainy") cout << "Sunny\n";
}


void odds_of_oddness()
{
  int n;
  cin >> n;

  int cnt = 0;
  for (int i = 1; i <= n; ++i)
  {
    if (i % 2 != 0) ++cnt;
  }

  cout << (float)cnt / (float)n << "\n";
}


void curtain()
{
  int a, b;
  cin >> a >> b;

  if (a - 2 * b > 0) cout << a - 2 * b << "\n";
  else cout << 0 << "\n";
}


void cant_wait_for_holiday()
{
  string s;
  cin >> s;

  vector<string> S{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

  int cnt = 7;
  for (int i = 0; i < 7; ++i)
  {
    if (s == S[i]) cout << cnt << "\n"; 
    --cnt;
  }

}


void blackjack()
{
  vector<int> a(3);
  for (int i = 0; i < 3; ++i) cin >> a[i];

  if (accumulate(a.begin(), a.end(), 0) >= 22) cout << "bust\n";
  else cout << "win\n";
}


void round_one()
{
  int a, b;
  cin >> a >> b;

  cout << 6 - a - b;
}


void strings()
{
  string s, t;
  cin >> s >> t;

  cout << t + s << "\n";
}


void yen_conins()
{
  int k, x;
  cin >> k >> x;

  if (k * 500 - x >= 0) cout << "Yes\n";
  else cout << "No\n";
}


void tap_dance() 
{
  string s;
  cin >> s;

  int flag = 1;
  for (int i = 1; i <= s.size(); ++i)
  {
    if (i % 2 == 0)
    {
      if (s[i] == 'L') flag = 0;
    }
    else
    {
      if (s[i] == 'R' ) flag = 0;
    }
  }
  if (flag) cout << "Yes\n";
  else cout << "No\n";
}


void roller_coaster()
{
  int n, k;
  cin >> n >> k;

  int cnt = 0;
  for (int i = 0; i < n; ++i)
  {
    int h;
    cin >> h;
    if (h >= k) ++cnt;
  }
  cout << cnt << "\n";
}


void takoyaki_festival2019()
{
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; ++i) cin >> d[i];

  int v_sum = 0;
  for (int i = 0; i < n; ++i)
  {
    for (int j = i + 1; j < n; ++j)
    {
      v_sum += d[i] * d[j];
    }
  }
  cout << v_sum << "\n";
}


void echo()
{
  int n;
  string s;
  cin >> n >> s;

  if (n % 2 != 0)
  {
    cout << "No\n";
    return;
  }

  for (int i = 0; i < n / 2; ++i)
  {
    if (s[i] != s[i + n / 2])
    {
      cout << "No\n";
      return;
    }
  }
  cout << "Yes\n";
}


void rot_n()
{
  int n;
  string s;
  cin >> n >> s;

  for (int i = 0; i < s.size(); ++i)
  {
    s[i] = 'A' + (s[i] - 'A' + n) % 26;
  }
  cout << s << "\n";
}


void palindrom_philia()
{
  string s;
  cin >> s;

  int cnt = 0;
  for (int i = 0; i < s.size() / 2; ++i)
  {
    if (s[i] != s[s.size() - i - 1]) ++cnt;
  }
  cout << cnt << "\n";
}


void strings_with_the_same_length()
{
  int n;
  string s, t;
  cin >> n >> s >> t;

  string ans = "";
  for (int i = 0; i < n; ++i)
  {
    ans += s[i];
    ans += t[i];
  }
  cout << ans << "\n";
}



int main()
{
  //weather_predicition();
  //odds_of_oddness();
  //curtain();
  //cant_wait_for_holiday();
  //blackjack();
  //round_one();
  //strings();
  //yen_conins();

  //tap_dance();
  //roller_coaster();
  //takoyaki_festival2019();
  //echo();
  //rot_n();
  //palindrom_philia();
  strings_with_the_same_length();
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cctype>
#define INF 1000000000
using namespace std;
bool debug=false;

int main(){
  string a,b,c;
  cin>>a>>b>>c;
  char cc=a[0];
  reverse(a.begin(),a.end());
  reverse(b.begin(),b.end());
  reverse(c.begin(),c.end());
  a.pop_back();

  while(1){

    if(cc=='a'&&a.size()==0){
      cout<<'A'<<endl;
      break;
    }else if(cc=='b'&&b.size()==0){
      cout<<'B'<<endl;
      break;
    }else if(cc=='c'&&c.size()==0){
      cout<<'C'<<endl;
      break;
    }

    if(cc=='a'){
      cc=a[a.size()-1];a.pop_back();
    }else if(cc=='b'){
      cc=b[b.size()-1];b.pop_back();
    }else if(cc=='c'){
      cc=c[c.size()-1];c.pop_back();
    }
    //cout<<a<<" "<<b<<" "<<c<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<ll,int> P;

int main() {
	ll n,m;
	cin>>n>>m;
	ll r=0;
	if(2*n>=m){
		r=m/2;
	}else{
		r=n+(m-2*n)/4;
	}
	cout<<r<<endl;
	return 0;
}


Measured memory_bytes: 256
nim,mike = map(int,input().split())
array = list(map(int,input().split()))

dp = [-1 for i in range(nim+10)]
l = [0,2,5,5,4,5,6,3,7,6]
dp[0] = 0
for i in range(nim-1):
    for s in array:
        if dp[i] == -1 and i!=0:
            continue
        if dp[i + l[s]] < dp[i]*10+s:
            dp[i + l[s]] = dp[i]*10+s
print(dp[nim])

Measured memory_bytes: 14668
N, L = map(int, input().split())

val = range(L, L+N, 1)
total = sum(val)
top = float("inf")

for i in range(len(val)):
    if top > abs(total-(total-val[i])):
        top = abs(total-(total-val[i]))
if total<0:
    print(int(abs(total)-top)*-1)
else:
    print(int(total-top))

Measured memory_bytes: 3064
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.List.Split
import Data.Char

readInt = read :: String -> Int
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
-- end of templete



f :: [Double] -> Int
f [xa,ya,ra,xb,yb,rb]
  | ra > rb && dr2 > d2 = 2
  | ra < rb && dr2 > d2 = -2
  | (ra + rb) ** 2 < d2 = 0
  | otherwise = 1
  
  where
    dr = rb - ra
    dr2 = dr ** 2
    dx = xb - xa
    dy = yb - ya
    d2 = dx ** 2 + dy ** 2
  

main = readLn >>= flip replicateM getLine >>= mapM_ (print . f . map read . words)

Measured memory_bytes: 4372
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ll n, d; cin >> n >> d;
    ll x[n],y[n];
    rep(i, n){
        cin >> x[i] >> y[i];
    }
    int ans=0;
    rep(i, n){
        if(x[i]*x[i]+y[i]*y[i] <= d*d) ans++;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 6744
n = int(input())
A = list(map(int,input().split()))

A.sort(reverse = True)

ans = 0
can = 1
last = 0
for i in range(n-1):
    ans += A[last]
    can -= 1
    if can == 0:
        can = 2
        last += 1
print(ans)


Measured memory_bytes: 31780
#include <iostream>

using namespace std;

const int INF = 1 << 29;
int N, M;
int D[1001];
int C[1001];
int dp[1001][1001];

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

    for (int i = 1; i <= N; i++) cin >> D[i];
    for (int i = 1; i <= M; i++) cin >> C[i];

    fill(dp[0], dp[1001], INF);
    dp[0][0] = 0;

    for (int i = 0; i < M; i++) {
        for (int j = 0; j < N; j++) {
            if (dp[i][j] != INF) {
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
                dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + C[i + 1] * D[j + 1]);
            }
        }
    }

    int ans = INF;
    for (int i = 0; i <= M; i++)
        ans = min(ans, dp[i][N]);

    cout << ans << endl;
}


Measured memory_bytes: 7012
#include <iostream>
#include <queue>
#include <vector>
#include <utility>
//#include <list>
using namespace std;

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

    vector<int> graph[n+1];//配列の配列的なもの
    for(int i=0;i<n-1;i++){
        int a=0,b=0;
        cin >> a;
        cin >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
//    cout <<"OK" <<endl;
    int mini[n+1];
    for(int i=0;i<n+1;i++){
        mini[i]=2147483647;
    }
    int s=1;
    queue< pair<int,int> > que;
    mini[s]=0;
    que.push(make_pair(s,0));
    while(!que.empty()){
        pair<int,int> curr = que.front();
        que.pop();
        for(int to : graph[curr.first]){
            if(mini[to]>curr.second+1){
                que.push(make_pair(to,curr.second+1));
                mini[to]=curr.second+1;
            }
        }
    }
//        cout <<"OK" <<endl;

    int mini2[n+1];
    for(int i=0;i<n+1;i++){
        mini2[i]=2147483647;
    }
    int e=n;
//    queue<pair<int,int>> que;
    mini2[e]=0;
    que.push(make_pair(e,0));
    while(!que.empty()){
        pair<int,int> curr = que.front();
        que.pop();
        for(int to : graph[curr.first]){
            if(mini2[to]>curr.second+1){
                que.push(make_pair(to,curr.second+1));
                mini2[to]=curr.second+1;
            }
        }
    }
//        cout <<"OK" <<endl;

    int cntF=0;
    int cntS=0;
    for(int i=1;i<=n;i++){
//        cout <<mini[i] << " " <<mini2[i] <<endl;
        if(mini[i]<=mini2[i]){
            cntF++;
        }else{
            cntS++;
        }
    }
//    cout <<cntF << " " <<cntS <<endl;
    if(cntF>cntS){
        cout << "Fennec" << endl;
    }else{
        cout << "Snuke" << endl;
    }
    return 0;
}

Measured memory_bytes: 6656
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        String message = "";
        if ((a * b * c) == (5 * 7 * 5)) {
            message = "YES";
        } else {
            message = "NO";
        }
        
        System.out.println(message);
    }
}

Measured memory_bytes: 21712
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
  int N;
  while (scanf("%d ", &N) == 1) {
    if (N == 0) {
      break;
    }
    int s = 5, sum = 0;
    while (N / s > 0) {
      sum += N / s;
      s *= 5;
    }
    printf("%d\n", sum);
  }
  return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    int r=0,sum=0;
    ll ans=0;
    rep(l,n){
        while(r<n&&(sum^a[r])==(sum+a[r])){
            sum+=a[r];
            r++;
        }
        ans+=r-l;
        sum-=a[l];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ft first
#define sd second
#define maxn 1000005
#define mod
#define PI 3.14159265
#define MP make_pair
#define PB push_back
#define heap priority_queue
#define Bjerg ""
using namespace std;

void read()
{

}
void solve()
{

}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen(Bjerg".inp","r",stdin);
    int n;
    cin >> n;
    int cnt=0;
    for(int i=1;i<=n;++i)
    {
        int x , y;
        cin >> x >> y;
        if(x==y) cnt++;
        else cnt=0;
        if(cnt==3)
        {
            cout <<"Yes";
            return 0;
        }
    }
    cout <<"No";
    return 0;
}


Measured memory_bytes: 3648
N = int(input())
A = list(map(int, input().split()))
import fractions
ans = A[0]
for i in range(1, N):
    ans = ans * A[i] // fractions.gcd(ans, A[i])
# print(ans)
count = 0
for a in A:
    count += (ans-1) % a
print(count)

Measured memory_bytes: 66792
#include <bits/stdc++.h>
using namespace std;
#define fastIO                        \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
// g++ -std=c++11 -O2 -Wall *.cpp -o *
#define eps 1e-9
#define MAX 10000010
#define MOD 1000000007
#define PI 3.14159265358979323846
#define Fi first
#define Se second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(), a.end()
#define maxof(a) *max_element(all(a))
#define rep(i, n) for (i = 0; i < n; ++i)
#define REP(i, k, n) for (i = k; i < n; ++i)
#define REPR(i, k, n) for (i = k; i > n; --i)
typedef long long ll;
typedef pair<int, int> pr_int;

bool isPrime[MAX] = {0};
ll f[MAX];

int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.out", "w", stdout);
	// fastIO

	int n;
	cin >> n;
	isPrime[0] = isPrime[1] = 0;
	f[1] = 1;
	for (int i = 2; i <= n; ++i){
		isPrime[i] = 1;
		f[i] = 1;
	}
	for (int i = 2; i*i <= n; ++i) if (isPrime[i]) 
		for (int j = i*i; j <= n; j += i) 
			isPrime[j] = 0;
	vector<int> primes;
	primes.PB(2);
	f[2] = 2;
	for (int k = 3; k <= n; k += 2)
		if (isPrime[k]){
			f[k] = 2;
			primes.PB(k);
		}
	for(int p : primes){
		for (int x = 2 * p; x <= n; x += p) {
			int c = 0, t = x;
			while (t > 1 && t % p == 0)
				t /= p, c++;
			f[x] *= c + 1;
			c++;
		}
	}
	ll s = 0;
	for (int k = 1; k <= n; ++k){
		// cout << "K = " << k << ", " << f[k] << "\n";
		s += f[k] * k;
	}
	cout << s;

	printf("\n");
}


Measured memory_bytes: 95348
#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     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/














int A, P;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> A >> P;

	P += A * 3;
	int ans = P / 2;
	cout << ans << endl;
}















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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    string n; cin >> n;
    REP(i,3){
        if(n[i]=='7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3580
S = str(input())

S_10 = '10' * (len(S) // 2)
if len(S) % 2 == 1:
  S_10 += '1'
S_01 = '01' * (len(S) // 2)
if len(S) % 2 == 1:
  S_01 += '0'
  
s_10 = sum([x != y for (x, y) in zip(list(S), list(S_10))])
s_01 = sum([x != y for (x, y) in zip(list(S), list(S_01))])
print(min(s_10, s_01))

Measured memory_bytes: 5748
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= m; ++j) {
            int now = i * (m-j) + j * (n-i);
            if (now == k) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3596
//


#include <iostream>
#include <stack>
#include <vector>

using namespace std;

int n;
int G[105][105];
vector<int> d(105,0),f(105,0);
int t=0;

void dfs(int x){
    bool p = false;
    if(d[x]!=0) p = true;
    if(d[x]==0){
        t++;
        d[x]=t;
    }
    for (int j=1; j<=n; j++) {
        if (G[x-1][j-1]==1 and d[j]==0) {
            dfs(j);
        }
    }
    t++;
    if(p) t--;
    if(f[x]==0) f[x]=t;
}


int main(){
    cin >> n;
    for (int i =0; i<n; i++) {
        for (int j =0; j<n; j++) {
            G[i][j] = 0;
        }
    }
    for (int i=0;i<n;i++) {
        int p,m;
        cin >>p >> m;
        for (int j=0; j<m; j++) {
            int q;
            cin >> q;
            G[p-1][q-1]=1;
        }
    }
    for(int i=0;i<n;i++) {
        dfs(i+1);
    }
    for (int i=0; i<n; i++) {
        cout << i+1 << " "<<d[i+1]<<" "<<f[i+1]<<endl;
    }
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

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

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int N;
    cin >> N;

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

    vector<int> cumsum(N);
    cumsum[0] = W[0];
    for (int i = 1; i < N; i++) {
        cumsum[i] = cumsum[i-1] + W[i];
    }

    int ans = 1000000;
    for (int i = 0; i < N-1; i++) {
        ans = min(ans, abs(cumsum[N-1] - 2 * cumsum[i]));
    }
    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int n,m,t,a;
  cin >> n >> m >> t;
  vector<int> used(1000000,0);
  rep(i,n){
    cin >> a;
    used[a] = 1;
    rep(i,m){
      used[a+i+1]= 1;
      used[a-i-1]= 1;
    }
  }
  int cnt = 0;
  rep(i,t){
    if(used[i] != used[i+1]) cnt++;
  }
  //rep(i,t+10) cout << used[i] << " ";
  //cout << endl;
  cnt /= 2;
  rep(i,t){
    if(used[i]==0) cnt++;
  }
  cout << cnt << endl;
  return 0;
}



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

template <typename T>
void print(const T &v);

int main()
{
    // 約数までしか作れない
    int n, k;
    cin >> n >> k;
    set<int> nums;
    int gcd;
    rep(i, n)
    {
        int a;
        cin >> a;
        nums.insert(a);
        if (i == 0)
        {
            gcd = a;
            continue;
        }
        if (a == k)
        {
            cout << "POSSIBLE" << endl;
            return 0;
        }
        gcd = __gcd(n, a);
    }
    if (gcd == 1 || k % gcd == 0)
    {
        if (*rbegin(nums) >= k)
        {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 8112
def resolve():
    def check(pos):
        for t, d in TD:
            if S[pos] != t:
                continue
            if d == "L":
                pos -= 1
            else:
                pos += 1
            # 左に落ちる
            if pos < 0:
                return -1
            # 右に落ちる
            if pos >= N:
                return 1
        return 0

    N, Q = map(int, input().split())
    S = input()
    TD = [list(input().split()) for _ in range(Q)]

    # 左側の境目: 左橋から最も離れた位置
    ok = -1
    ng = N
    while ng - ok > 1:
        mid = (ok + ng) // 2
        if check(mid) == -1:
            ok = mid
        else:
            ng = mid
    left = ok + 1

    # 右側の境目: 右橋から最も離れた位置
    ok = N
    ng = -1
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if check(mid) == 1:
            ok = mid
        else:
            ng = mid
    right = N - ok

    ans = N - (right + left)
    print(ans)


if __name__ == "__main__":
    resolve()


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

def digSum(n):
  return sum(map(int, str(n)))

A = list(range(1,N//2+1))
B = list(range(N-1,N//2-1,-1))
ans = 1e9
for a, b in zip(A, B):
  #a, b
  ans = min(ans, digSum(a)+digSum(b))
print(ans)

Measured memory_bytes: 6900
# coding: utf-8
import math
#a, b, c = map(int,input().split())
N = int(input())
K = int(input())
#S = input()
ans = 1
#l = list(map(int,input().split()))

for i in range(N):
    ans = min(ans*2, ans+K)

print(ans)

Measured memory_bytes: 9076
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }

struct Tmp
{
public:
  int N;
  vector<int> input;
  Tmp(int N)
  : N(N)
  , input(N)
  {}
};

void solve(void)
{
  ll X; cin >> X;
  auto gohyaku = X / 500;
  auto go = (X % 500) / 5;
  auto ans = gohyaku * 1000 + go * 5;
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    int n;
    cin >> n;
    char c[n];
    int countR = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> c[i];
        if (c[i]=='R')
        {
            countR++;
        }
        
    }
    
    if (countR==0 or countR==n)
    {
        cout << 0 << endl;
        return 0;
    }
    
    int ans = 0;
    for (int i = 0; i < countR; i++)
    {
        if (c[i]=='W')
        {
            ans++;
        }
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 3808
using System;
using System.Linq;

namespace AGC021
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var N = Console.ReadLine().ToCharArray();

            var ans = N.Sum(c => c - '0');
            for (var i = N.Length - 2; i >= 0; i--)
            {
                N[i]--;
                N[i + 1] = '9';
                ans = Math.Max(ans, N.Sum(c => c - '0'));
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main(){
  int N;
  cin >> N;
  bool E[N+1];
  fill(E,E+N+1,true);
  E[0] = false;
  E[1] = false;
  map<int,int> M;
  vector<int> P;
  for(int i = 2; i*i <= N; ++i){
    if(!E[i]) continue;
    M[i] = 0;
    for(int j = i; j*i <= N; ++j){
      E[i*j] = false;
    }
  }
  for(int i = 0; i < N+1; ++i)
    if(E[i]) P.push_back(i);
  for(int i = 2; i <= N; ++i){
    if(E[i]) ++M[i];
    else{
      int t = i;
      for(int j = 0; P[j]*P[j] <= i; ++j){
	while(!(t%P[j])){
	  ++M[P[j]];
	  t /= P[j];
	}
	if(t == 1 || P[j]*P[j] > t) break;
      }
      if(t != 1){
	++M[t];
      }
    }
  }
  long long int ans = 1LL, mod = 1000000007LL;
  for(int i = 0; i < (int)P.size(); ++i){
    //cout << P[i] << " " << M[P[i]] << endl;
    ans *= (long long int)(M[P[i]]+1)%mod;
    ans %= mod;
  }
  cout << ans%mod << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
ss = {}
for _ in range(n):
  s = ''.join(sorted(input()))
  ss[s] = ss.setdefault(s, 0) + 1
count = sum([
  c*(c-1)//2
  for c in ss.values()
  if c > 1
] or [0])
print(count)


Measured memory_bytes: 17852
#include <iostream>
#include <map>
int main(){
 int s;
  std::cin >> s;
  std::map<int,bool> a;
  a[s] = true;
  int ans = 1;
  while(a.find(s=s%2?s*3+1:s/2)==a.end()){
    a[s] = true;
    ++ans;
  }
  printf("%d",ans+1);
}

Measured memory_bytes: 256
N = int(input())
W = [input() for i in range(N)]
dic = {W[0]:1}
rev = W[0][len(W[0])-1:]
for w in W[1:]:
    if w not in dic:
        dic[w] = 1
        if rev != w[0]:
            print("No")
            exit()
        rev = w[len(w)-1:]
        continue
    print("No")
    exit()
print('Yes')

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;

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

	if (S == "RRR") {
		cout << "3";
	}
	if (S == "RRS") {
		cout << "2";
	}
	if (S == "RSR") {
		cout << "1";
	}
	if (S == "RSS") {
		cout << "1";
	}
	if (S == "SRR") {
		cout << "2";
	}
	if (S == "SRS") {
		cout << "1";
	}
	if (S == "SSR") {
		cout << "1";
	}
	if (S == "SSS") {
		cout << "0";
	}


	return 0;
}


Measured memory_bytes: 3620
N,M = map(int,input().rstrip().split(" "))
ans_min = 0
ans_max = N
for i in range(M):
    L,R = map(int,input().rstrip().split(" "))
    ans_min = max(L,ans_min)
    ans_max = min(R,ans_max)
print(max(0,ans_max-ans_min + 1))

Measured memory_bytes: 73852
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = Integer.parseInt(sc.next());
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        int[] b = new int[n];
        long[][] dp = new long[n + 1][h + 1];
        int max = 0;
        for (int i = 0; i < n; i++) {
            int aa = Integer.parseInt(sc.next());
            max = Math.max(max, aa);
            a[i] = aa;
            b[i] = Integer.parseInt(sc.next());
        }
        for (int i = 0; i <= n; i++) {
            Arrays.fill(dp[i], 1_000_000_000);
        }
        dp[0][0] = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= h; j++) {
                dp[i + 1][j] = Math.min(dp[i + 1][j], dp[i][j]);
                dp[i + 1][Math.min(j + a[i], h)] = Math.min(dp[i + 1][Math.min(j + a[i], h)], dp[i + 1][j] + b[i]);
            }
        }
        System.out.println(dp[n][h]);
    }
}


Measured memory_bytes: 131876
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int h,w;
  cin>>h>>w;
  string s;
  getline(cin,s);
  rep(i,h){
    getline(cin,s);
    cout<<s<<endl<<s<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> ii;

int main() {
    int n, m, p;
    cin >> n >> m >> p;
    vector<pair<int, ll>> adjList[n], rAdjList[n];
    int a, b, c;
    for (int ctr1 = 0; ctr1 < m; ++ctr1)
        cin >> a >> b >> c, adjList[a - 1].push_back(make_pair(b - 1, p - c)), rAdjList[b - 1].push_back(make_pair(a - 1, p - c));
    
    ll sp[n];
    int negativeLoop[n], visited[n];
    memset(negativeLoop, 0, sizeof(negativeLoop));
    memset(visited, 0, sizeof(visited));

    for (int ctr1 = 0; ctr1 < n; ++ctr1)
        sp[ctr1] = 10000000000000LL;

    sp[0] = 0;
    ll rez = 0;
    for (int ctr1 = 0; ctr1 <= n; ++ctr1) {
        for (int ctr2 = 0; ctr2 < n; ++ctr2)
            for (auto edge : adjList[ctr2])
                if (sp[ctr2] + edge.second < sp[edge.first]) {
                    sp[edge.first] = sp[ctr2] + edge.second;
                    if (ctr1 == n && sp[edge.first] <= 100000000000LL)
                        negativeLoop[edge.first] = 1;
                }
        rez = min(rez, sp[n - 1]);
    }
    queue<int> bfs;
    bfs.push(n - 1);
    visited[n - 1] = 1;
    while(!bfs.empty()) {
        int cur = bfs.front();
        bfs.pop();
        if (negativeLoop[cur]) {
            cout << -1 << "\n";
            return 0;
        }
        for (auto edge : rAdjList[cur])
            if (!visited[edge.first])
                bfs.push(edge.first), visited[edge.first] = 1;
        
    }
    cout << -rez << "\n";
    return 0;
}

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

#define INF 100000
 
int main(){
  vector<vector<int>> table(500, vector<int>(500, INF));
  int n, ma, mb;
  cin >> n >> ma >> mb;
  int a[n], b[n], c[n];
  int asum = 0, bsum = 0;
  table[0][0] = 0;
  for(int i=0; i<n; i++){
    cin >> a[i] >> b[i] >> c[i];
    asum += a[i];
    bsum += b[i];
    for(int j=asum; j>=0; j--){
      for(int k=bsum; k>=0; k--){
        if(table[j][k]==INF) continue;
        table[j+a[i]][k+b[i]] = min(table[j][k]+c[i], table[j+a[i]][k+b[i]]);
      }
    }
  }
  int ans = INF;
  for(int i=1; i<500; i++){
    for(int j=1; j<500; j++){
      if(ma*j==mb*i) ans = min(ans, table[i][j]);
    }
  }
  if(ans==INF) ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1280
from collections import deque

N,u,v = map(int,input().split())
edges = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b = map(int,input().split())
    edges[a].append(b)
    edges[b].append(a)

distA = {}
que = deque([(u,0)])
while que:
    n,step = que.popleft()
    if n not in distA:
        distA[n] = step
        for nx in edges[n]:
            que.append((nx,step+1))

distB = {}
que = deque([(v,0)])
while que:
    n,step = que.popleft()
    if n not in distB:
        distB[n] = step
        for nx in edges[n]:
            que.append((nx,step+1))
ans = 0
for i in range(1,N+1):
    dist = distB[i]-distA[i]
    if dist > 0:
        ans = max(ans,distB[i]-1)
print(ans)


Measured memory_bytes: 108748
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;


namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = int.Parse(s[0]);
            long K = long.Parse(s[1]);

            int[] c = new int[64];
            long[] v = new long[N];

            s = Console.ReadLine().Split(' ');
            for (int i = 0; i < N; i++)
            {
                v[i] = long.Parse(s[i]);

                long f = 1;

                for (int j = 0; j < 48; j++, f <<= 1)
                {
                    if ( 0 != (v[i] & f))
                    {
                        c[j]++;
                    }
                }
            }

            long ans = 0;
            for (int i = 48; i >= 0; i--)
            {
                if ( c[i] <= (N-1) / 2) {

                    long or = ((long)1 << i);

                    if ( (ans | or) <= K)
                    {
                        ans |= or;
                    }
                }
            }

            long sum = 0;
            for (int i = 0; i < N; i++)
            {
                sum += (v[i] ^ ans);
            }

            Console.WriteLine(sum);
        }
    }
}




Measured memory_bytes: 30176