akhauriyash/Code-Regression huggingface dataset:
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      ArrayList<String> s = nextCharArray();
      if(s.size() == 3){
        String tmp = s.get(0);
        s.set(0, s.get(2));
        s.set(2, tmp);
      }
      myout(myconv(s, 0));
	}
	//Method addition frame start


  
	//Method addition frame end
}


Measured memory_bytes: 33084
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

const long long modi=1000000007;

int main()
{
    long long n,i,j,x,h,w;
    cin>>h>>w;
    char ch[h][w];
    long long dp[h][w];
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {cin>>ch[i][j];dp[i][j]=0;}
    }
    if(ch[h-1][w-1]=='.'){dp[h-1][w-1]=1;}
    for(i=h-1;i>=0;i--)
    {
        for(j=w-1;j>=0;j--)
        {
            if(i+1<h&&ch[i][j]=='.'&&ch[i+1][j]=='.'){dp[i][j]=dp[i][j]%modi+dp[i+1][j]%modi;dp[i][j]%=modi;}
            if(j+1<w&&ch[i][j]=='.'&&ch[i][j+1]=='.'){dp[i][j]=dp[i][j]%modi+dp[i][j+1]%modi;dp[i][j]%=modi;}
        }
    }
    cout<<dp[0][0];
    return 0;
}


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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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 pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

int main(){
	summon_tourist;

	int H, W, K; string C[6]; cin >> H >> W >> K;
	REP(i, H) cin >> C[i];

	int ans = 0;
	REP(i, (1<<H)){
		REP(j, (1<<W)){
			int cnt = 0;
			bool red[6][6];
			REP(p, 6) REP(q, 6) red[p][q] = 0;
			REP(p, H){
				if((i>>p) & 1){
					REP(q, W) red[p][q] = 1;
				}
			}
			REP(q, W){
				if((j>>q) & 1){
					REP(p, H) red[p][q] = 1;
				}
			}
			REP(p, H) REP(q, W){
				if(!red[p][q] and C[p][q] == '#') cnt++;
			}
			if(cnt == K) ans++;
		}
	}
	cout << ans << ln;
}

Measured memory_bytes: 3616
use proconio::input;
use proconio::marker::Usize1;

fn main() {
    input! {
        n: usize,
        k: usize,
    };
    let mut ss = vec![false; n];
    for _ in 0..k {
        input! {
            d: usize,
            a: [Usize1; d],
        };
        for ai in a {
            ss[ai] = true;
        }
    }
    let ans = ss.iter().filter(|&s| !s).count();
    println!("{}", ans);
}


Measured memory_bytes: 2152
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define test long long int t; cin>>t; while(t-->0)
#define fIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define loop(i,n) for (ll i = 0; i < n; i++)
 
#define sz(x) int(x.size())
#define F first
#define S second
 
#define mii map<ll,ll>
#define vi vector<ll>
#define seti set<ll>
#define pii pair<ll,ll>
 
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a/gcd(a,b))*b

#define endl '\n'
using namespace std;
const int N=1e6;
int main()
    {
        fIO
        ll a,b;
        cin>>a>>b;
        cout<<a*b;   
    }

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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define C(x) cout << (x) << endl;
ll powmod(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
} 
 
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll a;cin>>a;
ll ans = powmod(10,a)-powmod(9,a)-powmod(9,a)+powmod(8,a);
ans%=MOD;
ans=(ans+MOD)%MOD;
cout << (ans%MOD);
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

struct Edge {
    int from, to;
};

lint choose2(int n) {
    return (n) * (n-1) / 2;
}

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

    if (k > choose2(n-1)) {
        cout << "-1" << endl;
        exit(0);
    }

    vector<Edge> res;

    for (int i = 2; i <= n; i++) {
        res.push_back((Edge){1, i});
    }

    int cur_l = 2, cur_r = 3;

    for (int i = 0; i < choose2(n-1)-k; i++) {
        res.push_back((Edge){cur_l, cur_r});
        cur_r++;
        if (cur_r > n) {
            cur_l++;
            cur_r = cur_l+1;
        }
    }

    cout << res.size() << endl;
    rep(i, res.size()) {
        printf("%d %d\n", res[i].from, res[i].to);
    }
    return 0;
}

Measured memory_bytes: 384
C = [list(map(int,input().split())) for i in range(3)]
A = [0] * 3
B = [0] * 3

for j in range(3):
  B[j] = C[0][j] -A[0]
A[1] = C[1][0] -B[0]
A[2] = C[2][0] -B[0]

for k in range(3):
  for l in range(3):
    if C[k][l] != A[k] + B[l]:
      print('No')
      exit()
      
print('Yes')

Measured memory_bytes: 3064
//╔╗───────────╔╗────────────────────╔╗─
//║║──────────╔╝╚╗──────────────────╔╝╚╗
//║╚═╗╔══╗╔══╗╚╗╔╝╔══╗╔═╗╔╗╔╗╔══╗ ╔╗╚╗╔╝
//║╔╗║║╔╗║║╔╗║─║║─║║═╣║╔╝║╚╝║║╔╗║─╣║─║║─
//║╚╝║║╔╗║║║║║─║╚╗║║═╣║║─║║║║║╚╝║─║║─║╚╗
//╚══╝╚╝╚╝╚╝╚╝─╚═╝╚══╝╚╝─╚╩╩╝╚══╝─╚╝─╚═╝ 

#include <bits/stdc++.h>

#define pb push_back
#define ff first
#define ss second
#define sz size()
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define mod 1000000007
#define forn(i, n) for (int i = 0; i < (int) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

int main() {
    IO;
    unsigned long long int x;
    cin >> x;
    int r  = ((x%11>6)?2:(x%11 == 0 ? 0:1));
    cout << 2*(x/11) + r;

}

Measured memory_bytes: 256
/* 解答時間→ 39:09         */
/* 何故か審査を通らない…… */
#include <algorithm>	//sort, binary_search等々
#include <iostream>		//基本入出力
#include <vector>		//STLの花形vector
using namespace std;

int main(){
	int a, L;

	while(1){
		cin >> a >> L;
		if((a == 0) && (L == 0))
			break;
		int a_[21];
		for(int i = 0; i < 21;i++){
			a_[i] = a;
			vector<int> b_;
			for(int k = 0; k < L; k++){
				b_.push_back(a % 10);
				a /= 10;
			}
			int p = 0, q = 0;
			sort(b_.begin(), b_.end());
			for(int k = L - 1; k >= 0; k--){
				p += b_[k];
				if(k != 0)
					p *= 10;
			}
			for(int k = 0; k < L; k++){
				q += b_[k];
				if(k != L - 1)
					q *= 10;
			}
			a = p - q;
			int flg = 0;
			for(int j = i; j >= 0; j--){
				if(a == a_[j]){
					cout << j << " " << a << " " << (i - j + 1) << "\n";
					flg = 1;
					break;
				}
			}
			if(flg == 1)
				break;
		}
	}
	cout << flush;

	return 0;
}

Measured memory_bytes: 1216
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	mapa := map[int]int{}
	s := nextStr()
	for _, v := range s {
		mapa[int(v)]++
	}

	if len(mapa) != 2 {
		fmt.Println("No")
		return
	}
	for _, va := range mapa {
		if va != 2 {
			fmt.Println("No")
			return
		}
	}

	fmt.Println("Yes")
	return
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}
func nextIntMat(a int, b int) [][]int {
	mat := make([][]int, a)
	for i := 0; i < a; i++ {
		mat[i] = make([]int, b)
		for j := 0; j < b; j++ {
			mat[i][j] = nextInt()
		}
	}
	return mat
}


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

int N, K, M = 0;
vector<vector<int>> G(110);

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

  if((N-1)*(N-2)/2 < K){ cout << -1 << endl; return 0; }  //中心頂点考慮

  int pair_n = (N-1)*(N-2)/2;

  for(int i = 2; i <= N; i++){ G[1].push_back(i); ++M; }

  for(int i = 2; i <= N; i++){
    for(int j = i+1; j <=N; j++){
      if(pair_n == K) break;
      G[i].push_back(j);
      pair_n -= 1;
      M += 1;
    }
    if(pair_n == K) break;
  }


  cout << M << endl;
  for(int i = 1; i <= N; i++){
    for(int j = 0; j < G[i].size(); j++) cout << i << " " << G[i][j] << endl;
  }

  return 0;

}


Measured memory_bytes: 256
import sys

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


P = str(input()).upper()
line = []

while True:
    tmp_line = str(input())
    if tmp_line == 'END_OF_TEXT':
        break
    line += tmp_line.upper().split()

ans = 0

for tmp_word in line:
    if tmp_word == P:
        ans += 1

print("%d"%(ans))



Measured memory_bytes: 5576
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

ll S(ll n){
  ll m = n;
  ll sum = 0;
  while(m > 0){
    sum += m % 10;
    m /= 10;
  }
  return sum;
}
double calc(ll x){
  return 1.0 * x / S(x);
}

int main(){
  ll K;
  cin >> K;
  ll N = 1;
  while(K > 0){
    ll next = N;
    if(N < 9){
      next = N + 1;
    } else {
      ll min = 1e+15;
      for(int d=0; d<=log(N)/log(10)+1; d++){
	if(calc((ll)pow(10, d+1) * ceil(N / pow(10, d+1) + 1) - 1) < calc(min))
	  min = (ll)pow(10, d+1) * ceil(N / pow(10, d+1) + 1) - 1;
      }
      next = min;
    }
    cout << N << endl;
    N = next;
    K--;
  }
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define H_MAX 50
#define W_MAX 50

int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int H,W;

namespace patch {
  template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
}

int main() {
	int n,q;
	cin >> n >> q;
	string s;
	cin >> s;
	vector<int> l,r;
	int lt,rt;
	rep(i,q) {
		cin >> lt >> rt;
		l.pb(lt);
		r.pb(rt);
	}

	int ruisekiwa[n];
	bool check[n];
	rep(i,n) {
		check[i] = false;
		ruisekiwa[i] = 0;
	}
	rep(i,n) {
		if(i==0)
			continue;
		if(s[i] == 'C' && s[i-1] == 'A') {
			ruisekiwa[i] = ruisekiwa[i-1] + 1;
			check[i] = true;
		}
		else {
			ruisekiwa[i] = ruisekiwa[i-1];
		}
	}
	rep(i,q) {
		int ans;
		if(l[i] == 1) {
			ans = ruisekiwa[r[i]-1];
		}
		else {
			ans = ruisekiwa[r[i]-1] - ruisekiwa[l[i] - 2];
		}
		if(check[l[i] - 1] == true)
			ans--;
		cout << ans << endl;
	}

  return 0;
}
 


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
  int N, M;
  cin >> N >> M;
  ll a[N], b[N];
  ll c[M], d[M];
  for(int i=0; i<N; i++) cin >> a[i] >> b[i];
  for(int i=0; i<M; i++) cin >> c[i] >> d[i];
  
  for(int i=0; i<N; i++){
    //学生iについて
    ll dis = 1e10;
    int idx;
    for(int j=0; j<M; j++){
      ll tmp;
      tmp = (ll)abs(a[i]-c[j]);
      tmp += (ll)abs(b[i]-d[j]);
      if(tmp < dis){
        idx = j;
        dis = tmp;
      }
    }
    cout << idx + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n,l = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n-1):
    if a[i]+a[i+1]>=l:
        print('Possible')
        ans = list(range(1,i+1))+list(range(i+2,n))[::-1]
        ans.append(i+1)
        for i in ans:
            print(i)
        exit()
print('Impossible')


Measured memory_bytes: 14300
n, a, b = map(int, input().split())
c = a-b
h = sorted([int(input()) for _i in range(n)], reverse=True)
left, right = 0, 10**9
while left < right:
    middle = (left+right)//2
    counter = 0
    checker = middle*b
    i = 0
    while checker < h[i]:
        counter -= (-h[i]+checker)//c
        i += 1
        if i >= n:
            break
    if counter <= middle:
        right = middle
    else:
        left = middle + 1
print(right)

Measured memory_bytes: 8280
let arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}

let div = ( arr[1] - arr[0] ) / 2
if ( ( abs( arr[1] - arr[0] ) % 2 ) > 0 ) {
  print( "IMPOSSIBLE" )
} else {
  print( arr[0] + div ) 
}

Measured memory_bytes: 4208
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>

using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
template<typename T>void max_self(T &a,T b){a=max(a,b);}
template<typename T>void min_self(T &a,T b){a=min(a,b);}
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=4e5+10,oo=0x3f3f3f3f,MOD=1e9+7;
const long double PI = acos(-1),eps=1.0e-14;

void solve(){
    ll a,b,n;
    cin>>a>>b>>n;
    min_self(n,b-1);
    cout<<(a*n)/b-a*(n/b)<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              3.14159265358979323844
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

void solve() {
    ll n;
    cin>>n;
    ll arr[n];
    rep(i,0,n)cin>>arr[i];
    ll freq[200005]={0};
    rep(i,0,n){
    	freq[arr[i]]++;
    }
    ll final=0;
    rep(i,0,200005){
    	final+=(freq[i]*(freq[i]-1))/2;
    }
    //cout<<final<<endl;
    rep(i,0,n){
    	ll temp=arr[i];
    	if (freq[temp]>1)
    		cout<<final-freq[temp]+1<<endl;
    	else cout<<final<<endl;
    }
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,x=0,y=0;
	char a;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		if(a=='I') x++;
		if(a=='D') x--;
		y=max(y,x);
	}
	cout<<y<<endl;
	return 0;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;
	int f = 1;
	for(int i = 0; i < s.size(); i++){
		if((i != a && !isdigit(s[i])) || (i == a && s[i] != '-')){
			f = 0;
		}
	}
	if(f == 0) cout << "No" << endl;
	if(f == 1) cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool A[105][105],vist[105]={0};
int d[105],f[105],n,t=0;

void dfs(int v){
	d[v] = ++t;
	vist[v] = 1;
	for(int i=1;i<=n;i++)
		if(A[v][i] && !vist[i])		
			dfs(i);
	f[v] = ++t;  
}
int main()
{	
	memset(A,0,sizeof(A));
	int v,u,du;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>v>>du;
		while(du--)
			cin>>u,
			A[v][u] = 1;
	}
	for(int i=1;i<=n;i++)
		if(!vist[i]) dfs(i);
	for(int i=1;i<=n;i++)
		printf("%d %d %d\n",i,d[i],f[i]);
	return 0;
}


Measured memory_bytes: 3224
/** 
 *  Author : Parth Prajapati aka (PARTH_4399, hungry_chef)
 *  Institute : Pandit Deendayal Petroleum University
 **/
#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    double r;
    cin>>r;
    cout<<fixed<<setprecision(15)<<2*(3.141592653589793238)*r;
    return 0;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(a) (a).begin(),(a).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=10000000000000000;

int main() {
    int Q;
    cin >> Q;
    priority_queue<ll> q;
    priority_queue<ll,vector<ll>,greater<ll>> qq;
    ll aa,bb,cc;
    cin >> aa >> bb >> cc;
    ll u=bb,o=cc,si=1,b=0,a=0;
    rep(i,Q-1){
        int f;
        cin >> f;
        if (f==1){
            ll g,h;
            cin >> g >> h;
            o+=h;
            if (si%2==1){
                if (g>=u){
                    qq.push(g);
                    b+=g;
                }
                else{
                    q.push(g);
                    a+=g;
                    qq.push(u);
                    b+=u;
                    u=q.top();
                    q.pop();
                    a-=u;
                }
            }
            else{
                if (g>=u){
                    qq.push(g);
                    b+=g;
                    q.push(u);
                    a+=u;
                    u=qq.top();
                    qq.pop();
                    b-=u;
                }
                else {
                    q.push(g);
                    a+=g;
                }
            }
            si++;
        }
        else{
            cout << u << " " << o+b-u*(si/2)+u*(si/2-1+si%2)-a << endl;
        }
    }
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define ld long double
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef vector <pll> vi;
#define out(x) return cout<<x,0;
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define lc(n) 2*n+1
#define rc(n) 2*n+2
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

int main() {
    FAST;
    ll n, k, m, z = 0, x = 0, y = 0, ans = 0, j, t = 0, c = 0,i;
    cin >> n >> k >> m;
    if ( m != 1e9 ){
    	for ( i = 0 ; i < k ; i ++ )
    		cout << m << " ";
    	for ( i ; i < n ; i ++ )
    		cout << m + 1 << " ";
    }
    else{
    	for ( i = 0 ; i < k ; i ++ )
    	   	cout << m << " ";
    	for ( i ; i < n ; i ++ )
    		cout << 1 << " ";
    }
}

Measured memory_bytes: 1280
x,y,u;
p(a,b){for(;b--;)putchar(a+68);}
main(v){
scanf("%d%d%d%d",&u,&v,&x,&y);
x-=u;y-=v;
p(17,y++);p(14,++x);p(0,y);p(8,x);p(17,1);p(8,1);p(17,y);p(14,x);p(0,y);p(8,--x);
}

Measured memory_bytes: 1620
import java.util.Scanner;

public class Main{
    public static void main(String[]arg){
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H==0 && W==0) break;
            else{
                for(int i=0;i<H;i++){
                    for(int j=0;j<W;j++){
                        System.out.printf("#");
                    }
                    System.out.printf("\n");
                }
                System.out.printf("\n");
            }
        }
    }
}


Measured memory_bytes: 62732
#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline ll read() {
    ll x=0,f=1; char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())
        if(ch=='-')f=-f;
    for(;ch>='0'&&ch<='9';ch=getchar())
        x=x*10+ch-'0';
    return x*f;
}
inline void chkmin( int &a,int b ) { if(a>b) a=b; }
inline void chkmax( int &a,int b ) { if(a<b) a=b; }
#define _ read()
int main() {
	int a=_,b=_;
	if(b%a) cout<<b-a;
	else cout<<a+b;
	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
      using namespace std;
      #define ll  int
      #define ii pair<ll ,ll >
      #define pb push_back
      #define range 
      #define vi vector <ll >
      #define mod 1000000007
      #define eps 1e-9
      #define fi first
      #define se second
      #define _ <<" "<<
      #define forn(x, n) for(int x = 0; x < n ;++ x) 
      #define forn2(x, n) for(long long ll x = 1; x < n ;++ x) 
      #define forn1(x,n) for(ll x = 1; x <= n ;++ x)
      #define IOS ios_base::sync_with_stdio(0 );cin.tie(0);cout.tie(0);
  vi graph[1005];
  int vis[1005][1005];
    ll gcd(ll a,ll b)
    {
      if(b==0) {return a;}
     return gcd(b,a%b);
    }

  


void solve(){
  string s;
  cin >> s;
  int zcount = 0, ans = 0;
  for (int i = 0; i < s.size(); i++){
    if (s[i] == '0'){
      zcount++;
    }else{
      int t = 1;
      ans++;
      for (int j = i + 1; j < s.size(); j++){
        t *= 2;
        t += s[j] - '0';
        if (zcount + j - i + 1 < t){
          break;
        }
        ans++;
      }
      zcount = 0;
    }
  }
  printf("%d\n", ans);
}
int main(){
   // freopen ("test.txt","r",stdin);
  int n;
cin>>n;
int a[n],b[n],c[n-1];
int sum=0;
forn(i,n)
{
  cin>>a[i];
}
forn(i,n)
{
  cin>>b[i];
  sum+=b[i];

}
forn(i,n-1)
{
  cin>>c[i];
}

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



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


int main(){
	int x,y,z;
	cin >> x >> y >> z;
	
	int answer=0;
	x -= z;
	answer = x/(y+z);
	x %= (y+z);
//	if(x >= y){
//		answer ++;
//	}
	
	cout << answer << endl;
//	x-=y;
//	if(x > 0){
//		cout << x/(y+z)+1 << endl;
//	}else{
//		cout << "0" << endl;
//	}
//	cout << x/(y+z) + 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
//#define int ll
typedef long long ll;

const int md = 1000000007;
const int INF = 1<<30;
using namespace std;

int main(){
    double a,b; cin >> a >> b;
    double ans = (1/a) + (1/b);
    
    printf("%.12f\n" , (1/ans));
}

Measured memory_bytes: 256
#include <stdio.h>

int isPrime(int x){
    int i;
    if(x < 2) return 0;
    else if(x == 2) return 1;
    if(x % 2 == 0) return 0;
    for(i = 3; i*i <= x; i+=2){
        if(x%i == 0) return 0;
    }
    return 1;
}

int main(){
    int n, x, i;
    int cnt = 0;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &x);
        if(isPrime(x)) cnt++;
    }
    printf("%d\n",cnt);
   
    return 0;
}  

Measured memory_bytes: 1824
solve()
    func solve() {
        let AV = readLine()!.split(separator: " ")
        let A = Int64(AV[0])!
        let V = Int64(AV[1])!
        let BW = readLine()!.split(separator: " ")
        let B = Int64(BW[0])!
        let W = Int64(BW[1])!
        let T = Int64(readLine()!)!

        let diff = abs(B - A)
        let diffPerSec = V - W
        if A == B {
            print("YES")
            return
        }
        if diffPerSec <= 0  {
            print("NO")
            return
        }

        if diff <= diffPerSec * T {
            print("YES")
        } else {
            print("NO")
        }
    }

Measured memory_bytes: 8356
// B Between a and b
#include <bits/stdc++.h>
using namespace std;

// overflow....

int not_good_main(){
    long a,b,x; // 0 < a<= b, 0<x  10^18
    cin >> a >> b >> x;
    long num = b- a +1;
    long div = num / x;
    long res = num % x;
    long count = div;
    for (long i = 0; i < res ; i ++){
        if ((i + a) % x == 0)
            count ++;
    }
    
    cout << count << endl;
}

long func(long n, long x){
    if (n >= 0){
        return  n/x + 1;
    }
    else{
        return 0;
    }
}

int main(){
    long a,b,x; // 0 < a<= b, 0<x  10^18
    cin >> a >> b >> x;
    long count = func(b, x) - func(a-1,x);
    cout << count << endl;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using ll = long long;
constexpr ll mod = 1000000007;

ll N, M, K;
ll ans;
ll fact[200010], inv[200010];

ll powMod( ll x, ll y, ll m )
{
  ll ret = 1;

  while( y > 0 )
  {
    if( y&1 )
      ret = (ret*x) % mod;

    x = x*x%m;

    y >>= 1;
  }

  return ret;
}

ll comb( ll n, ll r )
{ return fact[n]*inv[r]%mod*inv[n-r]%mod; }

int main()
{
  scanf( "%lld%lld%lld", &N, &M, &K );

  fact[0] = 1;
  rep( i, N*M )
    fact[i+1] = fact[i]*(i+1)%mod;
  rep( i, N*M+1 )
    inv[i] = powMod( fact[i], mod-2, mod );

  for( int d = 1; d <= N; ++d )
    ans = (ans+d*comb(N*M-2, K-2)%mod*(N-d)%mod*M%mod*M%mod) % mod;
  for( int d = 1; d <= M; ++d )
    ans = (ans+d*comb(N*M-2, K-2)%mod*(M-d)%mod*N%mod*N%mod) % mod;

  printf( "%lld\n", ans );

  return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;

// Write From This Line
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	// a - b まで入れることが出来る
	c -= min(a - b, c);
	cout << c << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")


long long mul_inv(long long a, long long b)
{
	long long b0 = b, t, q;
	long long x0 = 0, x1 = 1;
	if (b == 1) return 1;
	while (a > 1) {
		q = a / b;
		t = b, b = a % b, a = t;
		t = x0, x0 = x1 - q * x0, x1 = t;
	}
	if (x1 < 0) x1 += b0;
	return x1;
}

long long division(long long a, long long b, long long p) {		// (a / b) mod p = ((a mod p) * (b^(-1) mod p)) mod p
	long long ans, inv;
	inv = mul_inv(b, p);
	ans = ((a % p) * inv) % p;
	return ans;
}


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

	long long n, i, j, k, MOD = 1000000007, ans, jj, nn, x, MAXX = 2010, c;
	cin >> n;

	vector<long long> fact(MAXX);
	fact[0] = 1;
	for (i = 1; i < MAXX; i++) fact[i] = (fact[i - 1] * i) % MOD;

	if (n < 3) ans = 0;
	else {
		ans = 0;
		for (i = 1; i * 3 <= n; i++) {
			x = n - i * 2 - 1;
			c = division(fact[x], fact[i - 1], MOD);
			c = division(c, fact[x - (i - 1)], MOD);
			ans = (ans + c) % MOD;
		}
	}
	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 3668
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define F first
#define S second
#define SHN 1e9
#define lSHN 1e18
using namespace std;
int t1,t2,t4;
int n;
int main()
{
	cin >>n;
	for (int i=0;i<n;i++)
	{
		int x;
		cin >>x;
		if (x%4==0) t4++;
		else if (x%2==0) t2++;
		else t1++;
	}
	if (t1+t2<=t4+1)
	{
		cout <<"Yes";
		return 0;
	}
	else if (t1<=t4)
	{
		cout <<"Yes";
		return 0;
	}
	cout <<"No";
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(register int i=a;i<=b;++i)
#define Rep(i,a,b) for(register int i=a;i>=b;--i)
inline int read()
{
    bool f=0;int x=0;char ch;
    do{ch=getchar();f|=(ch=='-');}while(!isdigit(ch));
    do{x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}while(isdigit(ch));
    return f?-x:x;
}
inline void write(int x)
{
    if(x<0)x=-x,putchar('-');
    if(x>9)write(x/10);putchar(x%10+'0');
}
inline void writesp(int x)
{
	write(x);putchar(' ');
}
inline void writeln(int x)
{
	write(x);puts("");
}
int a[4];
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;++i)
	{
		string s;cin>>s;
		if(s=="AC")++a[0];
		if(s=="WA")++a[1];
		if(s=="TLE")++a[2];
		if(s=="RE")++a[3];
	}
	cout<<"AC x "<<a[0]<<endl;
	cout<<"WA x "<<a[1]<<endl;
	cout<<"TLE x "<<a[2]<<endl;
	cout<<"RE x "<<a[3]<<endl;
	return 0;
}


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

struct lrtyp {long l; long r;};

int asbc(const void *x, const void *y) {
  return (*(struct lrtyp *)x).l - (*(struct lrtyp *)y).l;
}

int main(){
   int n,i,a;
   long x,w;
   struct lrtyp lr[100000];
 
   scanf("%d",&n);
   for (i=0;i<n;i++) {
      scanf("%ld %ld",&x,&w);
      lr[i].l=x-w;
      lr[i].r=x+w;
   }
   qsort(lr,n,sizeof(struct lrtyp),asbc);
   for (a=i=0;i<n-1;i++)
      if (lr[i].r<=lr[i+1].l) {
         a++;
      } else if (lr[i].r<lr[i+1].r) {
         lr[i+1]=lr[i];
      }  
   printf("%d\n",a+1);
   return 0;
}


Measured memory_bytes: 3324
import java.io.IOException;
import java.util.Scanner;

public class Main {

	private static char[][] grid;
	private static String[][] dp;

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int N = scanner.nextInt();
			if (N == 0) {
				scanner.close();
				break;
			}
			int M = scanner.nextInt();

			grid = new char[M][N];
			dp = new String[M][N];
			for (int i = 0; i < grid.length; i++) {
				String line = scanner.next();
				for (int j = 0; j < grid[i].length; j++) {
					grid[i][j] = line.charAt(j);
					dp[i][j] = String.valueOf(grid[i][j]);
				}
			}

			String ans = "";
			for (int i = 0; i < grid.length; i++) {
				for (int j = 0; j < grid[i].length; j++) {
					if (Character.getNumericValue(grid[i][j]) < 10) {
						ans = strMax(ans, dp[i][j]);
						if (i + 1 < grid.length
								&& Character.getNumericValue(grid[i + 1][j]) < 10) {
							dp[i + 1][j] = strMax(dp[i + 1][j], dp[i][j]
									+ String.valueOf(grid[i + 1][j]));
							ans = strMax(ans, dp[i + 1][j]);
						}
						if (j + 1 < grid[i].length
								&& Character.getNumericValue(grid[i][j + 1]) < 10) {
							dp[i][j + 1] = strMax(dp[i][j + 1], dp[i][j]
									+ String.valueOf(grid[i][j + 1]));
							ans = strMax(ans, dp[i][j + 1]);
						}
					}
				}
			}
			System.out.println(ans);
		}

	}

	static String strMax(String a, String b) {
		// 行頭の0を全て削除
		a = a.replaceAll("^0*", "");
		b = b.replaceAll("^0*", "");

		if (b.length() > a.length()
				|| (b.length() == a.length() && b.compareTo(a) > 0)) {
			// 桁数が大きいか、桁数が一緒でも辞書順で後ろならば、
			// その数字を採用する
			return b;
		} else {
			return a;
		}

	}

}

Measured memory_bytes: 164664
#include <iostream>
#include <vector>
using namespace std;
typedef vector<int> vint;
#define range(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) range(i,0,n)

int main(){
    int n;
    cin >> n;
    vector<vint> A(n,vint(n,0));
    rep(i,n){
        int u,k;
        cin >> u >> k;
        rep(j,k){
            int v;
            cin >> v;
            A[u-1][v-1]=1;
        }
    }
    rep(i,n){
        rep(j,n){
            cout << A[i][j];
            if(j<n-1) cout << ' ';
        }
        cout << endl;
    }
}



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

using namespace std;
using ll = long long;

static const ll MODN = 1;
static const ll P = 321;

vector<ll> mod = {76543, 346072};

vector<vector<ll>> deg;
vector<vector<vector<ll>>> hor, vert;

int main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<string> ar(n);
	for (int i = 0; i < n; ++i) {
		cin >> ar[i];
	}
	deg.assign(MODN, vector<ll>(n + 1));
	hor.assign(MODN, vector<vector<ll>>(n, vector<ll>(n + 1)));
	vert.assign(MODN, vector<vector<ll>>(n, vector<ll>(n + 1)));
	for (int m = 0; m < MODN; ++m) {
		deg[m][0] = 1;
		for (int i = 0; i < n; ++i) {
			deg[m][i + 1] = (deg[m][i] * P) % mod[m];
		}
	}
	for (int m = 0; m < MODN; ++m) {
		for (int i = 0; i < n; ++i) {
			deg[m][i + 1] = (deg[m][i] * P) % mod[m];
		}
	}
	for (int m = 0; m < MODN; ++m) {
		for (int j = 0; j < n; ++j) {
			for (int i = 0; i < n; ++i) {
				hor[m][j][i + 1] = (hor[m][j][i] * P + ar[j][i]) % mod[m];
				vert[m][j][i + 1] = (vert[m][j][i] * P + ar[i][j]) % mod[m];
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			bool ok = true;
			for (int k = 0; k < n; ++k) {
				int hid = (i + k) % n;
				int vid = (j + k) % n;
				for (int m = 0; m < MODN; ++m) {
					ll hh = (((hor[m][hid][n] - hor[m][hid][j] * deg[m][n - j]) % mod[m] + mod[m]) * deg[m][j]
							+ hor[m][hid][j]) % mod[m];
					ll vv = (((vert[m][vid][n] - vert[m][vid][i] * deg[m][n - i]) % mod[m] + mod[m]) * deg[m][i]
							+ vert[m][vid][i]) % mod[m];
					if (hh != vv) {
						ok = false;
						break;
					}
				}
				if (!ok) break;
			}
			if (ok) {
				ans++;
			}
		}
	}
	cout << ans << endl;
}


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


int main() {
  string s;
  cin >> s;
  int a;
  if(s=="RRR") a = 3;
  else if(s=="RRS"||s=="SRR") a = 2;
  else if(s=="SSS") a = 0;
  else a = 1;
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int cnt = 0;
    while(a>=b){
        b*=2;
        cnt++;
        if(cnt > k){
            cout << "No" << endl;
            return 0;
        }
    }
    while(b>=c){
        c*=2;
        cnt++;
        if(cnt> k){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3636
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func updateHappiness(loc int) {
	if loc == 0 {
		happiness_table[0][loc] = happiness_map[0][loc]
		happiness_table[1][loc] = happiness_map[1][loc]
		happiness_table[2][loc] = happiness_map[2][loc]
		return
	}
	happiness_table[0][loc] = MaxIn2Values(happiness_table[1][loc-1]+happiness_map[0][loc], happiness_table[2][loc-1]+happiness_map[0][loc])
	happiness_table[1][loc] = MaxIn2Values(happiness_table[0][loc-1]+happiness_map[1][loc], happiness_table[2][loc-1]+happiness_map[1][loc])
	happiness_table[2][loc] = MaxIn2Values(happiness_table[0][loc-1]+happiness_map[2][loc], happiness_table[1][loc-1]+happiness_map[2][loc])
	return
}

var N int
var happiness_map [][]int
var happiness_table [][]int

func main() {
	N = nextInt()
	happiness_map = make([][]int, 3)
	happiness_a := make([]int, N)
	happiness_b := make([]int, N)
	happiness_c := make([]int, N)
	for i := 0; i < N; i++ {
		r := nextInts(3)
		happiness_a[i] = r[0]
		happiness_b[i] = r[1]
		happiness_c[i] = r[2]
	}
	happiness_map[0] = happiness_a
	happiness_map[1] = happiness_b
	happiness_map[2] = happiness_c

	happiness_table = make([][]int, 3)
	happiness_table[0] = make([]int, N)
	happiness_table[1] = make([]int, N)
	happiness_table[2] = make([]int, N)

	for i := 0; i < N; i++ {
		updateHappiness(i)
	}
	fmt.Println(MaxIn3Values(happiness_table[0][N-1], happiness_table[1][N-1], happiness_table[2][N-1]))
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func MaxIn3Values(a int, b int, c int) int {
	if a > b {
		if a > c {
			return a
		}
		return c
	} else {
		if b > c {
			return b
		}
		return c
	}
}

func MaxIn2Values(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


Measured memory_bytes: 8704
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())

# スペース区切りの整数の入力
ar = []
for i in range(N):
  l = list(input())
  l.sort()
  ar.append("".join(l).__hash__())

# 数を数える
list = {}
for i in ar:
  if i in list:
    list[i] = list[i] + 1
  else:
    list[i] = 1
  
count = 0
for i in list.values():
  n = i - 1
  count = count + int(((n * (n + 1)) / 2))

print(count)

Measured memory_bytes: 17000
#include<stdio.h>

struct Node{
  int Parent;
  int L;
  int R;
};
void preParse(int);
void inParse(int);
void postParse(int);
int n;
struct Node Tree[100001];

int main()
{
  int id,left,right,i,root;

  scanf("%d",&n);

  for(i=0; i<n; i++){
    Tree[i].Parent = -1;
  }

  for(i=0; i<n; i++){
    scanf("%d %d %d",&id,&left,&right);
    if(left != -1){
      Tree[left].Parent = id;
      Tree[id].L = left;
    }
    else
      Tree[id].L = left;

    if(right != -1){
      Tree[right].Parent = id;
      Tree[id].R = right;
    }
    else
      Tree[id].R = right;

  }

  for(i=0; i<n; i++){
   if(Tree[i].Parent == -1)
     root = i;
  }

  printf("Preorder\n");
  preParse(root);
  printf("\nInorder\n");
  inParse(root);
  printf("\nPostorder\n");
  postParse(root);
  printf("\n");

  return 0;
}

void preParse(int u){
  if(u == -1)
    return;
  printf(" %d",u);
  preParse(Tree[u].L);
  preParse(Tree[u].R);
}

void inParse(int u){
  if(u == -1)
    return;
  inParse(Tree[u].L);
  printf(" %d",u);
  inParse(Tree[u].R);
}

void postParse(int u){
  if(u == -1)
    return;
  postParse(Tree[u].L);
  postParse(Tree[u].R);
  printf(" %d",u);
}
  



Measured memory_bytes: 2040
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int a,b,k;
    cin >> a >> b >> k;
    int count = 0;

    for(int i = 100; 0 < i; i--){
        if(a%i == 0 && b%i == 0){            
            count++;
            if(count == k){
                cout << i << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 256
n = int(input())
l = [input().split() for i in range(n)]
for i in range(n):
    l[i].append(i+1)
    l[i][1] = -int(l[i][1])
l.sort(key = lambda x: x[1])
l.sort(key = lambda x: x[0])
for i in range(n):
    print(l[i][2])

Measured memory_bytes: 3060
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<complex>
#include<iomanip>
#include<unordered_map>
#define deg(x) cerr<<#x<<"="<<x<<endl;
#define fd(x) for(int i=0;i<x;i++)
#define fdd(a,x) for(int i=a;i<x;i++)
#define fx(x,n) for(int i=n-1;i>=x;i--)
#define mst(x) memset(x,0,sizeof(x));
#define fi first
#define se second
#define TB ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define ok "ok"
#define HH puts("");
#define ls rt<<1
#define rs rt<<1|1
#define pb(a,b) a.push_back(b);
#define FIN  freopen("1.in","r",stdin);
#define FOUT freopen("1.out","w",stdout);
using namespace std;
typedef long long ll;typedef long long LL;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,string> pss;
typedef unsigned long long ull;
const ll mod=998244353;
const ll inf=1e16+7;
const double eps=1e-8;
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return (r+m)%m;}
//const double pi=acos(-1);

const int maxn=3e5+2;

ll tree[4*maxn+5];
ll n,k;
ll a[maxn];
void tes(ll k,ll l,ll r,ll x,ll val){
    if(l==r){
        tree[k]=val;
        return;
    }
    ll mid=(l+r)/2;
    if(x<=mid) tes(k*2+1,l,mid,x,val);
    else tes(k*2+2,mid+1,r,x,val);
    tree[k]=max(tree[k*2+1],tree[k*2+2]);
    return ;
}
ll cal(ll k,ll l,ll r,ll l1,ll r1){
    if(l1<=l&&r<=r1) return tree[k];
    else if(l1<=r&&l<=r1){
        ll m=(l+r)/2;
        return max(cal(k*2+1,l,m,l1,r1),cal(k*2+2,m+1,r,l1,r1));
    }else return 0;
}
int main()
{
    TB
    ll N=300000;
    cin>>n>>k;
    fdd(1,n+1) cin>>a[i];
    tes(0,0,N,a[1],1);
    fdd(2,n+1){
        ll m=cal(0,0,N,max(a[i]-k,0ll),min(a[i]+k,N));
        tes(0,0,N,a[i],m+1);
    }
    cout<<cal(0,0,N,0,N)<<'\n';
    return 0;

}

Measured memory_bytes: 14180
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy


def odd(n): return n & 1


def even(n): return not odd(n)


def comb(n, m):
    r = 1
    m = min({n - m, m})
    for i in range(1, n+1):
        r *= i
    for i in range(1, m+1):
        r //= i
    for i in range(1, n-m+1):
        r //= i
    return r


N, P = map(int, input().split())
A = [int(n) % 2 for n in input().split()]
cnt0 = len([a for a in A if a == 0])
cnt1 = len([a for a in A if a == 1])
ans = 0
if odd(P):
    for i in range(cnt1 + 1):
        if odd(i):
            ans += comb(cnt1, i)
else:
    for i in range(cnt1 + 1):
        if even(i):
            ans += comb(cnt1, i)
ans *= pow(2, cnt0)
print(ans)


Measured memory_bytes: 9928