akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

class Main {

	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);

		int x = scan.nextInt();
		int y = scan.nextInt();
		int d;
		int e;
		if (x >= y) {
			d = x % y;
			e = y;
		} else {
			d = y % x;
			e = x;
		}
		if (d == 0) {
			System.out.println(e);
		} else {
			for (int i = d; d > 0; i--) {
				if (d % i == 0 && e % i == 0) {
					System.out.println(i);
					break;
				}
			}
		}
		scan.close();

	}

}


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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf (1 << 21)
#define mod 1000000007

int main() {
    double N, T, A; cin >> N >> T >> A;
    vector<double> H(N);
    double moderate = inf;
    int ans;
    for (int i = 0; i < N; i++) {
        cin >> H.at(i);
        moderate = min(moderate, (double)abs(A - T + H.at(i) * 0.006));
        if ((double)abs(A - T + H.at(i) * 0.006) == moderate) {
            ans = i;
        }
    }
    ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        a: i64,
        b: i64,
        c: i64,
        x: i64,
        y: i64,
    }

    let mut ans = 1 << 32;
    for aa in 0..x+1 {
        let cc = 2*x - 2*aa;
        let bb = max(0, y - cc/2);
        let p = aa*a + bb*b + cc*c;
        ans = min(ans, p);
    }

    for bb in 0..y+1 {
        let cc = 2*y - 2*bb;
        let aa = max(0, x - cc/2);
        let p = aa*a + bb*b + cc*c;
        ans = min(ans, p);
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
q=[]
n=int(input())
l=[]
for i in range(n):
  l.append(int(input()))
l.sort()
for a in l:
  if len(q)==0:
    q.append(a)
  else:
    b=q.pop()
    if a==b:
      pass
    else:
      q.append(b)
      q.append(a)
print(len(q))

Measured memory_bytes: 8008
#include <iostream>
#include <string>
#include <vector>
#include <set>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define mp(a, b) make_pair(a, b)

int h, w;

string solve(vector<string>& patterns){
    auto comp = [](const string& s, const string& t){return mp(s.size(), t) < mp(t.size(), s);};
    set<string, decltype(comp)> spells(comp), magicSpells(comp);
    magicSpells.insert("0");
    rep(x, h)rep(y, w){
        for(int dx=-1; dx<=1; ++dx){
            for(int dy=-1; dy<=1; ++dy){
                string spell = "";  spell += patterns[x][y];
                for(int nx=(x+dx+h)%h, ny=(y+dy+w)%w; nx!=x || ny!=y; (nx+=(dx+h))%=h, (ny+=(dy+w))%=w){
                    spell += patterns[nx][ny];
                    (spells.count(spell)? magicSpells: spells).insert(spell);
                }
            }
        }
    }
    return *(--magicSpells.end());
}

int main(){
    while(cin >> h >> w, h|w){
        vector<string> patterns(h);
        rep(i, h)cin >> patterns[i];
        cout << solve(patterns) << '\n';
    }
    return 0;
}

Measured memory_bytes: 35200
#include<bits/stdc++.h>
#define ll long long
using namespace std;
signed main() {
  ll a,b,n;
  ll cun = 0;
  cin >> a >> b >> n;
  for (int i = a; i <= b; i++) {
    if (i % n == 0) {
      cun++;
    }
  }

  cout << cun << "\n";
  
  return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
int main(void)
{
	int n,i,j;
	char str[1024];

	scanf("%d\n",&n);
	for(i=0; i<n; i++){
	  fgets(str,1024,stdin);
		for (j = 0; str[j] != '\n'; j++) {
			if (strncmp(&str[j], "Hoshino",7) == 0)
				strncpy(&str[j], "Hoshina",7);
		}
		printf("%s",str);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    vector<ll> march(5);
    ll m=0,a=0,r=0,c=0,h=0;
    string s;
    rep(i,n){
        cin>>s;
        if(s[0]=='M') m++;
        if(s[0]=='A') a++;
        if(s[0]=='R') r++;
        if(s[0]=='C') c++;
        if(s[0]=='H') h++;
    }
    march[0]=m,march[1]=a,march[2]=r,march[3]=c,march[4]=h;
    ll ans=0;
    rep(i,3){
        repi(j,i+1,4){
            repi(k,j+1,5){
                ans+=march[i]*march[j]*march[k];
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3580
import java.util.Scanner;
import java.util.stream.IntStream;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] a = new int[M];
        int[] b = new int[M];
        for (int i = 0; i < M; ++i) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }
 
        System.out.println(solve(N, a, b));
 
        sc.close();
    }
 
    static int solve(int N, int[] a, int[] b) {
        int[] sortedIndices = IntStream.range(0, a.length).boxed().sorted((i1, i2) -> Integer.compare(b[i1], b[i2]))
                .mapToInt(x -> x).toArray();
 
        int result = 0;
        int prevEnd = -1;
        for (int index : sortedIndices) {
            if (a[index] >= prevEnd) {
                ++result;
                prevEnd = b[index];
            }
        }
 
        return result;
    }
}

Measured memory_bytes: 93884
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder.Question
{
    public class QuestionB
    {
        public static void Main(string[] args)
        {
            var (n, k) = ReadHelper.ReadValue<int, int>();
            var ps = ReadHelper.ReadValues<int>();
            var p = ps.OrderBy(p => p).Take(k).Sum();
            Console.WriteLine(p);
        }

        static class ReadHelper
        {
            internal static T ReadValue<T>()
            {
                return (T)Convert.ChangeType(Console.ReadLine(), typeof(T));
            }
            internal static (T1, T2) ReadValue<T1, T2>()
            {
                var input = Console.ReadLine().Split(' ');
                return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)));
            }
            internal static (T1, T2, T3) ReadValue<T1, T2, T3>()
            {
                var input = Console.ReadLine().Split(' ');
                return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)));
            }
            internal static (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>()
            {
                var input = Console.ReadLine().Split(' ');
                return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)), (T4)Convert.ChangeType(input[3], typeof(T4)));
            }
            internal static T[] ReadValues<T>()
            {
                var input = Console.ReadLine().Split(' ');
                return input.Select(x => (T)Convert.ChangeType(x, typeof(T))).ToArray();
            }
        }

        static class MathAlgorithm
        {
            internal static bool IsPrime(long n)
            {
                if (n == 2) return true;
                if (n < 2 || n % 2 == 0) return false;
                var sqrt = Math.Sqrt(n);
                for (int i = 3; i <= sqrt; i += 2) if (n % i == 0) return false;
                return true;
            }
            internal static IEnumerable<long> EnumeratePrimes(long n)
            {
                var i = 2L;
                while (i * i <= n)
                {
                    if (n % i == 0)
                    {
                        n /= i;
                        yield return i;
                    }
                    else
                    {
                        i += i == 2 ? 1 : 2;
                    }
                }
                if (n != 1) yield return n;
            }
        }
    }
}


Measured memory_bytes: 28868
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
if n == 1:
  for i in range(10):
    t = str(i)
    for s, c in sc:
      if s<=n and t[s-1] == str(c):
        continue
      break
    else:
      print(i)
      break
  else:
    print(-1)
else:
  for i in range(10**(n-1), 10**n):
    t = str(i)
    for s, c in sc:
      if s<=n and t[s-1] == str(c):
        continue
      break
    else:
      print(i)
      break
  else:
    print(-1)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ff first
#define ss second
#define input(a) scanf("%lld",&a)
#define M 1000000007
#define inf 1<<30

using namespace std;

typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ll,ii> iii;

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

ll bigMod(ll base,ll power)
{
    if(power==0)
        return 1;
    ll x=bigMod(base,power/2);
    x=(x*x)%M;
    if(power&1)
        x=(x*base)%M;
    return x;
}

ll h,w,dp[110][110];
char grid[110][110];

ll res(ll i,ll j)
{
    if(i==h||j==w)
        return 1<<30;
    if(dp[i][j]!=-1)
        return dp[i][j];
    if(i==h-1&&j==w-1)
        return dp[i][j]=(grid[i][j]=='#');
    if(grid[i][j]=='#')
        return dp[i][j]=min((grid[i+1][j]=='.')+res(i+1,j),(grid[i][j+1]=='.')+res(i,j+1));
    return dp[i][j]=min(res(i+1,j),res(i,j+1));
}

int main()
{
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            dp[i][j]=-1;
            cin>>grid[i][j];
        }
    }
    cout<<res(0,0)<<endl;
//    for(int i=0;i<h;i++){
//        for(int j=0;j<w;j++){
//            cout<<dp[i][j]<<"\t";
//        }
//        cout<<endl;
//    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n ;
	ll h;
	ll ans=0LL;
	cin >>n>>h;
	Vi a(n), b(n);
	rep(i, n) {
	cin >> a[i] >> b[i];
	}
	sort(all(a), greater<int>());
	sort(all(b), greater<int>());
	int ter = a[0];
	for (auto itr = b.begin(); itr != b.end() and *itr >= ter and h>0;itr++){
		h -= *itr;
		ans++;
	}
//	clog << h << " "<<ans << endl;
	ans += (max(0LL,h) + ter - 1LL) / ter;
	cout << ans << endl;
}

Measured memory_bytes: 3952
n=gets.to_i
a=gets.split.map(&:to_i)
b=gets.split.map(&:to_i)

minus=[]
plus=[]
flag=0
sum=0
for i in 0..n-1
    v=a[i]-b[i]
    if v<0
        flag=1
    end
    sum+=v
    if v>0
        plus<<v
    elsif v<0
        minus<<v
    end
    
end

if flag==0
    p 0
    exit
elsif sum<0
    p -1
    exit
end
count=0
count+=minus.length
plus.sort!
plus=plus.reverse

minus_all=minus.inject(&:+)
plus_all=0
i=0
while minus_all<0
    if i>=plus.length
        p -1
        exit
    end
    minus_all+=plus[i]
    count+=1
    i+=1
end

p count
    

Measured memory_bytes: 25948
#include <iostream>
using namespace std;
struct point{
    int x,y;
};
point rot(int x, int y){
    point ans;
    ans.x = -y;
    ans.y = x;
    return ans;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    point a,b;
    cin >> a.x >> a.y >> b.x >> b.y;
    point p = rot(b.x - a.x, b.y - a.y);
    cout << b.x + p.x << " " << b.y + p.y << " " << a.x + p.x << " " << a.y + p.y << endl;
    return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
int main()
{
    int W, H, N;
    cin >> W >> H >> N;
    int ans = 0;
    vint x(N), y(N), a(N);
    vector<vector<bool>> painted(W, vector<bool>(H));
    rep(i, N)
    {
        cin >> x[i] >> y[i] >> a[i];

        rep(j, W)
        {
            rep(k, H)
            {
                if (a[i] == 1)
                {
                    if (j < x[i])
                    {
                        painted[j][k] = true;
                    }
                }
                if (a[i] == 2)
                {
                    if (j >= x[i])
                    {
                        painted[j][k] = true;
                    }
                }
                if (a[i] == 3)
                {
                    if (k < y[i])
                    {
                        painted[j][k] = true;
                    }
                }
                if (a[i] == 4)
                {
                    if (k >= y[i])
                    {
                        painted[j][k] = true;
                    }
                }
            }
        }
    }
    rep(i, W)
    {
        rep(j, H)
        {
            if (!painted[i][j])
            {
                ans++;
            }
        }
    }
    cout << ans;
    return 0;
}

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

int main(){

  int n,m;
  cin >> n >> m;
  int t[110]={};
  for(int i = 1;i <= m;i++){
    cin >> t[i]; //1~
  }
  int p[110]={};
  for(int i = 1;i <= m;i++){ //iテ・ツ崢榲ァツ崢ョテ」ツ?ョテ」ツつイテ」ツδシテ」ツδ?
    int b[110]={};
    for(int j = 1;j <= n;j++){//jテァツ閉ェテァツ崢ョテ」ツ?ョテ、ツコツコ
      cin >> b[j];
      //      b[j]++;
      if(b[j] == t[i]){
	p[j]++;
      }
      else p[t[i]]++;
    }
  }

  for(int i = 1; i <= n; i++){
    cout << p[i] << endl;
  }

  return 0;

}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl


signed main(){
    int N,K;
    int a[104];
    cin >> N >> K;
    REP(i,N){cin >> a[i];}
    int dp[128][256][128]={};//i どこまで見たか j Xorの値　k 数列の長さ
    dp[0][0][0]=1;
    OREP(i,N){
        REP(k,108){
        	REP(j,256){
                dp[i][j][k]=(dp[i][j][k]+dp[i-1][j][k])%MOD;
                dp[i][j][k]=(dp[i][j][k]+dp[i-1][j^a[i-1]][k-1])%MOD;
            }
        }
    }
    int Ans=0;
    int fact[104]={};
    fact[0]=1;
    REP(i,100){
        fact[i+1]=(fact[i]*(i+1))%MOD;
    }
    ZREP(i,N+1){
        Ans=(Ans+dp[N][K][i]*fact[i])%MOD;
    }
    cout << Ans << endl;
  
  	REP(i,N+1){
      	cerr << i << endl;
		REP(k,N+1){
          REP(j,16){
			cerr << dp[i][j][k] << " ";
          	}cerr << endl;
        }cerr << endl << endl;
    }
    return 0;
}   

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

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

string pat[24] =
{
    "123","135","154","142",
    "231","214","246","263",
    "326","365","351","312",
    "421","415","456","462",
    "513","536","564","541",
    "624","645","653","632"
};

string dice[8];
bool used[8];
int sel[8];
int num[8];

bool check(int d1, int pos1, int d2, int pos2) {
    char c1 = dice[sel[d1]][pat[num[d1]][pos1 - 1] - '1'];
    char c2 = dice[sel[d2]][pat[num[d2]][pos2 - 1] - '1'];
    return c1 != c2 && (c1 - 32 == c2 || c2 - 32 == c1);
}

bool dfs(int p) {
    if (p == 8) return true;

    REP(i, 8) if (!used[i]) {
        used[i] = true;
        sel[p] = i;
        REP(j, 24) {
            num[p] = j;
            bool flag = false;
            switch (p) {
                case 0: flag = true; break;
                case 1: if (check(0, 3, 1, 4)) flag = true; break;
                case 2: if (check(0, 2, 2, 5)) flag = true; break;
                case 3: if (check(1, 2, 3, 5) && check(2, 3, 3, 4)) flag = true; break;
                case 4: if (check(0, 6, 4, 1)) flag = true; break;
                case 5: if (check(1, 6, 5, 1) && check(4, 3, 5, 4)) flag = true; break;
                case 6: if (check(4, 2, 6, 5) && check(2, 6, 6, 1)) flag = true; break;
                case 7: if (check(6, 3, 7, 4) && check(5, 2, 7, 5) && check(3, 6, 7, 1)) flag = true; break;
            }
            if (flag && dfs(p + 1)) return true;
        }
        used[i] = false;
    }
    return false;
}

int main() {
/*	123456
	135246
	154326
	142536
	231645
	214365
	246135
	263415
	326154
	365214
	351624
	312564
	421653
	415263
	456123
	462513
	513462
	536142
	564312
	541632
	624351
	645231
	653421
	632541*/ 
	
    REP(i, 24) {
        for (int j = 2; j >= 0; j--) pat[i] += (7 - (pat[i][j] - '0')) + '0';
    }


    while (cin >> dice[0]) {
        if (dice[0] == "0") break;

        FOR(i, 1, 8) cin >> dice[i];

        memset(used, 0, sizeof(used));

        if (dfs(0)) puts("YES");
        else puts("NO");
    }
    return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n;
    while(cin >> n, n){
        vector<int> x(n), y(n);
        int dy[] {0, 1, 0, -1}, dx[] {-1, 0, 1, 0};
        for (int i = 1; i < n; ++i) {
            int p, q;
            cin >> p >> q;
            y[i] = y[p]+dy[q];
            x[i] = x[p]+dx[q];
        }
        sort(x.begin(), x.end());
        sort(y.begin(), y.end());
        cout << x.back()-x.front()+1 << " " << y.back()-y.front()+1 << "\n";
    }
    return 0;
}



Measured memory_bytes: 3116
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction

def Com(n, k):
    p, q = 1, 1
    for i in range(n-k+1, n+1):
        p *= i
    for i in range(2, k+1):
        q *= i
    return p//q

N = int(input())
dic = defaultdict(int)
for i in range(N):
    s = input()
    cnt = [0] * 26
    for c in s:
        cnt[ord(c)-97] += 1
    dic[tuple(cnt)] += 1
ans = 0
for key in dic:
    if dic[key] > 1:
        ans += Com(dic[key], 2)
print(ans)

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

int main() {
	string s; cin >> s;
	ll n = s.size();
	vector<int> sa = suffix_array(s);
	vector<int> lcp = lcp_array(s, sa);
	ll ans = n * (n+1) / 2;
	for (int l : lcp) ans -= l;
	cout << ans << endl;
	return 0;
}

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

int dp[2001][2001];
// data[i][j] wのi -> bのj なら，1
// data[i][j] bのj -> wのi なら，0

int main(){
	int N;
	cin >> N;
	int a[2*N], data[N+1][N+1], da[N+1][N+1];
	char c[2*N];
	vector<pair<int, int>> w, b;
	for(int i=0; i<2*N; i++){
		cin >> c[i] >> a[i];
		if(c[i] == 'W') w.push_back({i, a[i]});
		else b.push_back({i, a[i]});
	}
	int cnt = 0;
	for(int i=0; i<N; i++){
		for(int j=i+1; j<N; j++){
			if(b[i].second > b[j].second) cnt++;
			if(w[i].second > w[j].second) cnt++;
		}
	}
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++){
			if(w[i].first < b[j].first){
				data[w[i].second][b[j].second] = 1;
			}else{
				data[w[i].second][b[j].second] = 0;
			}
		}
	}
	for(int i=1; i<=N; i++){
		int x = 0;
		for(int j=1; j<=N; j++){
			x += data[j][i];
		}
		da[0][i] = x;
	}
	for(int i=1; i<=N; i++){
		for(int j=1; j<=N; j++){
			if(data[j][i] == 1){
				da[j][i] = da[j-1][i] - 1;
			}else{
				da[j][i] = da[j-1][i] + 1;
			}
		}
	}
	dp[0][1] = da[0][1];
	for(int i=2; i<=N; i++){
		dp[0][i] = dp[0][i-1] + da[0][i];
	}
	for(int i=1; i<=N; i++){
		dp[i][1] = da[i][1];
	}
	for(int i=1; i<=N; i++){
		for(int j=2; j<=N; j++){
			dp[i][j] = min(dp[i-1][j] - da[i-1][j], dp[i][j-1]) + da[i][j];
		}
	}
	int ans = 1e9;
	for(int i=0; i<=N; i++){
		if(ans > dp[i][N]) ans = dp[i][N];
	}
	cout << ans + cnt << endl;
	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int A, B, K; cin >> A >> B >> K;
  int k = 0;
  for (int i = max(A,B); ; i--) {
    if (A % i == 0 && B % i == 0) {
      k++;
      if (k == K) { cout << i << endl; break; }
    }
  }
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

void Main() {
    int n, mi, ans, r;
    ans = -1e9;
    cin >> n >> mi;
    rep(i, n - 1) {
        cin >> r;
        ans = max(ans, r - mi);
        mi = min(mi, r);
    }
    cout << ans << "\n";
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


Measured memory_bytes: 3216
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    a = S()
    b = S()

    def f(s):
        if not s:
            return None
        if s[0] != '(':
            return int(s)
        c = 1
        mi = -1
        for i in range(1, len(s)):
            if s[i] == '(':
                c += 1
            elif s[i] == ')':
                c -= 1
                if c == 0:
                    mi = i
                    break

        c = 1
        ki = -1
        for i in range(mi+2, len(s)):
            if s[i] == '[':
                c += 1
            elif s[i] == ']':
                c -= 1
                if c == 0:
                    ki = i
                    break

        return [f(s[mi+2:ki]), f(s[1:mi]), f(s[ki+2:-1])]

    fa = f(a)
    fb = f(b)
    def g(a, b):
        if a is None or b is None:
            return None
        if isinstance(a, int) or isinstance(b, int):
            ai = a
            while not isinstance(ai, int):
                ai = ai[0]

            bi = b
            while not isinstance(bi, int):
                bi = bi[0]

            return ai + bi

        return [g(a[i],b[i]) for i in range(3)]

    def h(a):
        if a is None:
            return ''
        if isinstance(a, int):
            return str(a)
        return '({})[{}]({})'.format(h(a[1]),h(a[0]),h(a[2]))


    return h(g(fa, fb))


print(main())



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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long N, X, M; cin >> N >> X >> M;
    vector<bool> B(M, 0);
    long long Cur = X;
    long long Ans = 0;
    vector<long long> S;
    while (N-- && Cur != 0) {
        Ans += Cur;
        if (B[Cur]) {
            vector<long long> Loop = {Cur};
            long long LoopSum = Cur;
            while (Cur != S.back()) {
                Loop.emplace_back(S.back());
                LoopSum += S.back();
                S.pop_back();
            }
            Ans += LoopSum * (N / Loop.size());
            N %= Loop.size();
            reverse(Loop.begin(), Loop.end());
            for (int i = 0; i < N; i++) Ans += Loop[i];
            break;
        } else {
            B[Cur] = 1;
            S.emplace_back(Cur);
            Cur = Cur * Cur % M;
        }
    }
    cout << Ans << "\n";
    return 0;
}

Measured memory_bytes: 4216
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c; cin>>a>>b>>c;
  bool ans=false;
  for(int i=1; i<=b; i++){
    if(a*i%b==c){
      ans=true;
      break;
    }
  }
  cout<<(ans?"YES":"NO");
}

Measured memory_bytes: 256
import java.util.Scanner;
 
class Main
{
    public static void main(String args[])
    {
        Scanner stdln = new Scanner(System.in);
        int a = stdln.nextInt();
        int b = stdln.nextInt();
        int c = a*b;
        int d = 2*(a+b);
        System.out.println( c + " " + d );
    }
}

Measured memory_bytes: 26176
use std::env;
use std::io::*;
use std::str::*;
use std::mem;
use std::collections::HashMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}
fn read_char() -> char {
    let c = read::<String>();
    let c = c.chars().collect::<Vec<char>>();
    c[0]
}
fn read_String_Vec() -> Vec<char> {
    let S = read::<String>();
    S.chars().collect::<Vec<char>>()
}

fn vecchar_to_String(Vs: Vec<char>) -> String {
    let mut S = String::new();
    for i in 0..Vs.len() {
        S.push(Vs[i]);
    }
    S
}

/*
A : 65
Z : 90
a : 97
z : 122
*/

/*
let N = read::<i32>();
let S = read::<String>();
let S = read_String_Vec();
let C = read_char();
*/

/*
 .to_string() : * -> String
 &*S          : String -> &str
*/

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let S = read_String_Vec();
    let mut firstA = 0;
    let mut lastZ = 0;

    for (iter, s) in S.iter().enumerate() {
        if *s == 'A' {
            firstA = iter;
            break;
        }
    }
    for (iter, s) in S.iter().enumerate() {
        if *s == 'Z' {
            lastZ = iter;
        }
    }
    println!("{}", lastZ - firstA + 1);
}


Measured memory_bytes: 4352
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

int main() {
    ll N;
    cin >> N;
    cout << N/2 + (N%2!=0) << endl;
}


Measured memory_bytes: 888
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	q := getNextInt(scanner)

	for i := 0; i < q; i++ {
		a := getNextInt64(scanner)
		b := getNextInt64(scanner)

		ans := int64(0)
		max := a * b

		x := maxRoot(a+1, max)
		if x > 0 {
			ans += x - 1

			y := max / x
			if max%x == 0 {
				y--
			}
			if y > b {
				ans += y - b
			}
		}

		a, b = b, a

		x = maxRoot(a+1, max)
		if x > 0 {
			ans += x - 1

			y := max / x
			if max%x == 0 {
				y--
			}
			if y > b {
				ans += y - b
			}
		}

		fmt.Fprintln(writer, ans)
	}
	writer.Flush()
}
func maxRoot(r, x int64) int64 {
	var l int64
	l = -1
	for l+1 < r {
		m := (l + r) >> 1
		if m*m <= x {
			l = m
			continue
		}
		r = m
	}
	return l
}


Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main(){

    long long int i,l,r,j,a,b,c,res,n,m,t;
    cin >> n;
    for(i=1;i<10;i++){
        if(n%i==0 and n/i<10){
            break;
        }
    }
    if(i<10) cout << "Yes";
    else cout << "No";
}


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

int main() {
    string str;
    cin >> str;
    int i = 1;
    int ans = 1;
    int size = 1;
    string prev = str.substr(0, 1);
    while(i < str.size()) {
        if(str.substr(i, size) == prev) {
            if(i == str.size() - 1)
                break;
            size++;
        } else {
            prev = str.substr(i, size);
            ans++;
            i += size;
            size = 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3728
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let x = read::<usize>();
    let a = read::<usize>();
    let b = read::<usize>();
    let x = x - a;
    let x = x - (x / b) * b;
    println!("{}", x);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<climits>
using namespace std;

int main() {
    int count, A[1000];
    cin >> count;
    for (int i = 0; i < count; i++) {
        cin >> A[i];
    }

    int tradeCount = 0;
    for (int i = 0; i < count; i++) {
        int minJ = i;
        for (int j = i; j < count; j++) {
            if (minJ == -1 || A[minJ] > A[j]) {
                minJ = j;
            }
        }

        if (minJ != i) {
            swap(A[minJ], A[i]);
            tradeCount++;
        }
    }

    for (int j = 0; j < count; j++) {
        if (j > 0) cout << " ";
        cout << A[j];
    }
    cout << endl;
    cout << tradeCount << endl;


 

    /***
    int tradeCount = 0;
    for (int i = 0; i < count; i++) {
        for (int j = count - 1; j > i; j--) {
            if (A[j] < A[j - 1]) {
                int swap = A[j - 1];
                A[j - 1] = A[j];
                A[j] = swap;
                tradeCount++;
            }
        }
    }

    for (int j = 0; j < count; j++) {
        if (j > 0) cout << " ";
        cout << A[j];
    }
    cout << endl;
    cout << tradeCount << endl;
    ***/

   
    /***
    for (int i = 0; i < count; i++) {
        int v = A[i];
        int j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;

        for (int j = 0; j < count; j++) {
            if (j > 0) cout << " ";
            cout << A[j];
        }
        cout << endl;
    }
    ***/
}

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

lint a[2000010],n;

int main(){
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	lint result=0,cur=0,r=0;
	for(int i=0;i<n;i++){
		while(r<n&&(cur&a[r])==0){
			cur^=a[r];r++;
		}
		cur^=a[i];
		result+=r-i;
	}
	printf("%lld",result);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
 
const int MOD = 1000000007;

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

    long long res = 0;
    for(int i=N+1; i>=K; i--){
        res += (long long)(N-i+1)*i+1;
        res %= MOD;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3636
// AOJ Volume 0 Problem 0083

#include <stdio.h>

int main(void)
{
    int year, month, day;
	int date;
	
	while (scanf("%d%d%d", &year, &month, &day) != EOF){
		date = year * 10000 + month * 100 + day;
		
		if (date < 18680908){
			printf("pre-meiji\n");
		}
		else if (date <= 19120729){
			printf("meiji %d %d %d\n", year - 1867, month, day);
		}
		else if (date <= 19261224){
			printf("taisho %d %d %d\n", year - 1911, month, day);
		}
		else if (date <= 19890107){
			printf("showa %d %d %d\n", year - 1925, month, day);
		}
		else {
			printf("heisei %d %d %d\n", year - 1988, month, day);
		}
	}
	return (0);
}

Measured memory_bytes: 0
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(cin.hasNext()){
			int[] guest=new int[8];
			for(int i = 0; i < 8;i++){
				guest[i]=cin.nextInt();
			}
			ArrayList<Integer> list = new ArrayList<Integer>();
			list.add(4);
			list.add(1);
			list.add(4);
			list.add(1);
			list.add(2);
			list.add(1);
			list.add(2);
			list.add(1);
			int sum=0;
			int minList = 999999999;
			int minSum = 999999999;
			ArrayList<Integer> ans=new ArrayList<Integer>();
			for(int j = 0; j < 8;j++){
				sum=0;
				for(int i =0; i<8;i++){
					//System.out.print(list.get(i)+" " );
				}
				for(int i =0; i<8;i++){
					int c = guest[i]-list.get(i);
					//System.out.println(guest[i]+" " + list.get(i) + " " + c);
					if(c<=0){
						continue;
					}
					sum+=c;
				}
				//System.out.println(sum);
				if(minSum>sum){
					ans=(ArrayList<Integer>) list.clone();
					minSum=sum;
					minList=listToInt(list);
				}
				else if(minSum==sum){
					if(minList>listToInt(list)){
						ans=(ArrayList<Integer>) list.clone();
						minSum=sum;
						minList=listToInt(list);
					}
				}
				int tmp=list.remove(0);
				list.add(tmp);
			}
			System.out.print(ans.get(0));
			for(int i =1; i<8;i++){
				System.out.print(" "+ans.get(i));
			}
			System.out.println();
		}
	}
	static int listToInt(ArrayList<Integer> list){
		int ans=0;
		for(int i= 0; i < 7;i++){
			ans = ans*10 + list.get(i);
		}
		return ans;
	}
}

Measured memory_bytes: 12000
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AApplePie solver = new AApplePie();
        solver.solve(1, in, out);
        out.close();
    }

    static class AApplePie {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            out.println((3 * in.nextInt() + in.nextInt()) / 2);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 22484
# AOJ ITP1_7_C

def numinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def main():
    a = numinput()
    r = a[0]; c = a[1]
    M = []
    for i in range(r):
        M.append(numinput())  # あ、そうか。。
        sum = 0
        for j in range(c): sum += M[i][j]
        M[i].append(sum)
    list = []
    for j in range(c + 1):
        sum = 0
        for i in range(r): sum += M[i][j]
        list.append(sum)
    M.append(list)

    for i in range(r + 1):
        _str_ = ""
        for j in range(c):
            _str_ += str(M[i][j]) + " "
        _str_ += str(M[i][c])
        print(_str_)

if __name__ == "__main__":
    main()


Measured memory_bytes: 5708
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    L = [0] * (N + 3)
    if N == 0:
        print(2)
        exit()
    L[0] = 2
    if N == 1:
        print(1)
        exit()
    L[1] = 1
    for n in range(2, N+1):
        L[n] = L[n - 1] + L[n - 2]
    print(L[n])


if __name__ == '__main__':
    main()


Measured memory_bytes: 10048
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 read . words <$> getLine :: IO [Int]
cond t f c = if c then t else f
-- end of templete

f x = x ^ 2

int d = sum [f (t*d) * d | t <- [0..(div 600 d)-1]]

main = map readInt . lines <$> getContents >>= mapM_ (print . int)

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

vector<int> to[10005];
vector<int> ans_index;
void dfs(int v, int p=-1) {
  ans_index.push_back(v);
  for (int u : to[v]) {
    if (u == p) continue;
    dfs(u,v);
  }
}

int main() {
  int n;
  cin >> n;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  vector<int>c(n);
  rep(i,n)cin>>c[i];
  sort(c.rbegin(),c.rend());
  dfs(0);
  ll ansv=0;
  rep(i,n-1)ansv+=c[i+1];
  cout << ansv << endl;
  vector<int> ans(n);
  rep(i,n){
    ans[ans_index[i]]=c[i];
  }
  rep(i,n) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}


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

int main()
{
	std::set<long> s1, s;
	long n, m;

	cin >> n;

	for (long i = 0; i < n; i++) {
		long t;
		cin >> t;
		s1.insert(t);
	}

	cin >> m;

	for (long i = 0; i < m; i++) {
		long t;
		cin >> t;
		if (s1.find(t) != s1.end())
			s.insert(t);
	}

	for (std::set<long>::iterator itr = s.begin(); itr != s.end(); itr++)
		cout << *itr << endl;

	return 0;
}



Measured memory_bytes: 14260
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2010;
int n,m,ans,a[N][N],up[N],L[N],R[N];
char s[N];
int main(){
    scanf("%d%d",&n,&m);ans=max(n,m);
    for(int i=1;i<=n;i++){
        scanf("%s",s+1);
        for(int j=1;j<=m;j++)
            a[i][j]=s[j]=='.'?0:1;
    }
    --n;--m;
    for(int i=1;i<=m;i++)L[i]=1,R[i]=m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            a[i][j]^=a[i+1][j]^a[i][j+1]^a[i+1][j+1];
    for(int i=1;i<=n;i++){
        int l=0,r=m+1;
        for(int j=1;j<=m;j++)
            if(a[i][j])up[j]=0,l=j,L[j]=1;
            else ++up[j],L[j]=max(L[j],l+1);
        for(int j=m;j;j--)
            if(a[i][j])r=j,R[j]=m;
            else {
                R[j]=min(R[j],r-1);
                ans=max((R[j]-L[j]+2)*(up[j]+1),ans);
            }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 17460
#include<cstdio>
#include <algorithm>
using namespace std;

int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a==b&&b==c)printf("No");
    else if(a!=b&&b!=c&&a!=c)printf("No");
    else printf("Yes");
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

class Main {
  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();

    if(n < 4){
      System.out.println("No");
      return;
    }
      
    
    for(int i = 0; i < 26; i++){
      for(int j = 0; j < 15; j++){
        if(4 * i + 7 * j == n){
          System.out.println("Yes");
          return;
        }
        if(4 * i + 7 * j > 100)
          break;
      }
    }
      System.out.println("No"); 
  }
  
}

Measured memory_bytes: 22228
#include<iostream>


using namespace std;
#define ll long long 


bool ke(int x,int y){


    if((x&(1<<y)))return 1;
    return 0;
}

template <class T> inline T BM(T p, T e, T M) {
    ll ret = 0;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret + p) % M;
        p = (p + p) % M;
    }
    return (T)ret;
}


int dp[81][81];
int n,m;
int ar[81][81];
int br[81][81];



int main(){

    cin>>n;
    int res=0;
    pair<int,int> ar[n+2][n+2];
    int br[n+2];
    for(int i=1;i<=n;i++){
        int x;
        cin>>br[i];
        for(int j=1;j<=br[i];j++){
            cin>>ar[i][j].first>>ar[i][j].second;
        }
    }

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

        bool fl =0;
        int ko=0;
        for(int j=0;j<n;j++){
            if(ke(i,j)){
                ko++;
                for(int k=1;k<=br[j+1];k++){
                    int ch = ar[j+1][k].first;
                    int bl=ar[j+1][k].second;
                    if(ke(i,ch-1)!=bl)fl=1;
                }
            }

        }
        if(!fl)
        res=max(res,ko);
    }

    cout<<res<<endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define tcase int _; cin >> _; while(_--)
const int MAX = 1e6;

int n, k;
ll v[MAX];

// 1 2 3 4 5 6

void solve() {
	cin >> k >> n;
	for(int i=0; i<n; i++) cin >> v[i];
	sort(v, v+n);
	ll ans = v[n-1] - v[0];
	for(int i=1; i<n; i++) {
		ans = min(ans, v[i-1]+k-v[i]);
	}
	cout << ans;	
}

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

 	solve();

  	return 0;
}



Measured memory_bytes: 5168
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ul>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 4e18
#define EPS 1e-3
#define PI 3.1415926535897932385
#define display(v) f(v.size())cout << v[i]<<" "
const double h = 1e-6;
const int MAX_  = 200005;
#define all(v) v.begin(),v.end()

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
ll sqr(ll x)
{
    return x*x;
}
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
     int n;  cin>>n;
        int arr[n+1] = {0};

    f(n-1)
    {
        int val; cin>>val;
        arr[val]++;

    }
    for(int i =1;i<=n;i++)cout << arr[i] << "\n";
}
    


Measured memory_bytes: 4428