akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<char>> v(1001,vector<char>(1001));
vector<vector<ll>> dp(1001,vector<ll>(1001,-1));
ll solve(ll x,ll y){
    ll a,b;
    a=b=0;
    if(dp[x][y]!=-1)
        return dp[x][y];
    if((x==1 && y==2) || (y==1 && x==2))
        return 1;
    if(x>1 && v[x-1][y]=='.')
    {
        a=solve(x-1,y)%1000000007;
    }
    if(y>1 && v[x][y-1]=='.')
    {
        b=solve(x,y-1)%1000000007;
    }
    dp[x][y]=((a+b)%1000000007);
    return dp[x][y];
}

int main()
{
    ll ans,h,w;;
    cin>>h>>w;
    for(ll i=1;i<=h;++i)
    {
        for(ll j=1;j<=w;++j)
            cin>>v[i][j];
    }
    ans=solve(h,w);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 9216
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>

using int64 = long long;
using uint64 = unsigned long long;

using namespace std;

int GCD(int m, int n) {
    if (n == 0) return m;
    else return GCD(n, m % n);
}

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

    int k, ans = 0;
    cin >> k;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                ans += GCD(GCD(a, b), c);
            }
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3196
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <utility>
#include <vector>


int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); 
    std::cout << std::fixed << std::setprecision(16);
    int n; std::cin >> n; 
    long long int x = 7 % n; int cnt = 1;
    for(int i = 1; i <= 1000'000'0; ++i){
        if(x == 0){ std::cout << i << '\n'; return 0; }
        x = (10 * x + 7) % n;
        ++cnt;
    }
    std::cout << "-1\n";
    return 0;
}

Measured memory_bytes: 3640
import sys
def input(): return sys.stdin.readline().strip()

def main():
    W, H, N = map(int, input().split())
    mat = [[1] * W for _ in range(H)]
    for _ in range(N):
        x, y, a = map(int, input().split())
        if a == 1:
            for i in range(H):
                for j in range(x):
                    mat[i][j] = 0
        if a == 2:
            for i in range(H):
                for j in range(x, W):
                    mat[i][j] = 0
        if a == 3:
            for i in range(y):
                for j in range(W):
                    mat[i][j] = 0
        if a == 4:
            for i in range(y, H):
                for j in range(W):
                    mat[i][j] = 0
    ans = 0
    for i in range(H):
        for j in range(W):
            ans += mat[i][j]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 70480
import kotlin.math.max

fun main() {
    solve()
}

private fun solve() {

    val (N, M) = readInts()

    val unionFind = UnionFind(N+1)

    repeat(M) {
        val (A, B) = readInts()


        unionFind.union(A, B )
    }
    var ans = 0
    unionFind.size.forEach {
        ans = max(ans, it)
    }
    println(ans)

//    println("size arr "+unionFind.size.joinToString())
//    println("parent arr "+unionFind.parent.joinToString())
}


class UnionFind(private val n: Int) {
    val parent: IntArray = IntArray(n)
    val size = IntArray(n)

    init {
        parent.forEachIndexed { index, i ->
            parent[index] = index
            size[index] = 1
        }
    }

    fun find(element: Int): Int {
        if (parent[element] == element) {
            return element
        }
        parent[element] = find(parent[element])
        return parent[element]
    }

    fun union(a: Int, b: Int) {
        val rootA = find(a)
        val rootB = find(b)

//        println("rootA $rootA sizeA ${size[rootA]} rootB $rootB ${size[rootB]}")
        if (rootA == rootB) return

        if (size[rootA] >= size[rootB]) {
            size[rootA] += size[rootB]
            parent[rootB] = rootA
        } else {
            size[rootB] += size[rootA]
            parent[rootA] = rootB
        }

//        println("AFTER PROCESS rootA $rootA sizeA ${size[rootA]} rootB $rootB ${size[rootB]}")
    }
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

Measured memory_bytes: 66896
import java.util.Scanner;
import java.util.Random;

public class Main{
    public static void main(String[] args){
        Scanner sc =new Scanner(System.in);
        String a = sc.next();
        if(Character.isUpperCase(a.charAt(0))){
            System.out.println("A");
        } else{
            System.out.println("a");
        }
    }
}

Measured memory_bytes: 35644
R=list()
n=0
s=list()
p=list()
N=int(input())
for i in range(N):
  S,P=input().split()
  P=int(P)
  s.append([S,100-P,i+1])
  p.append(P)
  n=S
s=sorted(s)
for i in range(N):
  print(s[i][2])

Measured memory_bytes: 9108
ans = []
t = input()
s = 0
while s != t:
    n = input()
    step = map(int,raw_input().split())
    upMax = 0
    downMax = 0
    for i in range(n-1):
        if step[i+1] - step[i] > upMax:
            upMax = step[i+1] - step[i]
        if step[i] - step[i+1] > downMax:
            downMax = step[i] - step[i+1]
    temp = str(upMax)+' '+str(downMax)
    ans.append(temp)
    s += 1

for i in ans:
    print i

Measured memory_bytes: 4252
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int GCD(int a, int b){
    if(b == 0){
        return a;
    }else{
        return GCD(min(a, b), max(a, b) % min(a, b));
    }
}

struct solution{
    int type_A, type_B, cost;
};

int N, Ma, Mb;
vector<solution> solutions;

int dp[40][400][400];

int buy_solution(int now, int A_all, int B_all){
    if(now == N && A_all && B_all){
        return (A_all / GCD(A_all, B_all) != Ma || B_all / GCD(A_all, B_all) != Mb) * 1e5;
    }else if(now == N){
        return 1e5;
    }else if(dp[now][A_all][B_all] != -1){
        return dp[now][A_all][B_all];
    }else{
        return dp[now][A_all][B_all] = min(buy_solution(now + 1, A_all, B_all), solutions[now].cost + buy_solution(now + 1, A_all + solutions[now].type_A, B_all + solutions[now].type_B));
    }
}

int main(){
    cin >> N >> Ma >> Mb;
    solutions.resize(N);
    for(int i = 0; i < N; i++){
        cin >> solutions[i].type_A >> solutions[i].type_B >> solutions[i].cost;
    }
    for(int i = 0; i < 40; i++){
        for(int j = 0; j < 400; j++){
            for(int k = 0; k < 400; k++){
                dp[i][j][k] = -1;
            }
        }
    }
    if(buy_solution(0, 0, 0) > 1e4){
        cout << -1 << endl;
    }else{
        cout << buy_solution(0, 0, 0) << endl;
    }
}

Measured memory_bytes: 25216
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef pair<int, int> P1;
typedef pair<int, pair<int, int> > P2;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };
static const int mod = 1000000007;

signed main(){
    int N,A,B;
    cin>>N>>A>>B;
    int dist=abs(A-B);
    /*if(A==1&&B==2){
        cout<<"Draw"<<endl;
        exit(0);
    }*/
    if(dist&1)cout<<"Borys"<<endl;
    else cout<<"Alice"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int p = 1000000007;
int main()
{
  int n,i;
  long long a=1,b=1;
  string s;
  cin >> s;
  n=s.size();
  for(i=n-1;i>=0;i--){
    if(s[i]=='1'){
      a+=a+b;
      a%=p;
    }
    b*=3;
    b%=p;
  }
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second

typedef long long kkj;
typedef vector <kkj> vkkj;
typedef vector <vkkj> mat;
typedef pair <kkj, kkj> pkkj;
typedef vector <pkkj> vpkkj;

vpkkj item;
mat memo;

kkj dp(kkj n, kkj w){
    if (n < 0 || w <= 0) return 0;
    if (memo[n][w] != -1) return memo[n][w];
    kkj a = dp(n-1, w), b = 0;
    if (item[n].fi <= w){
        b = dp(n-1, w-item[n].fi)+ item[n].se;
    }
    memo[n][w] = max(a , b);
    // printf("%lld\n", max(a , b));
    return memo[n][w];
}

int main(){
    kkj n, w;
    cin >> n >> w;
    item.clear();
    memo.assign(n, vkkj(w+1, -1));
    // for (int = 0; i < n; i++){
    //
    // }

    for (int i = 0; i < n; i++){
        kkj a, b;
        scanf("%lld %lld", &a, &b);
        item.push_back(make_pair(a, b));
    }

    printf("%lld\n", dp(n-1, w));
    // for (int i = 0; i < n; i++)
    //     printf("%lld %lld\n", item[i].fi, item[i].se);
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n;
    cin >> n;
    vector<int> l(n);
    for (int i = 0; i < n; ++i) {
        cin >> l[i];
    }
    sort(all(l));

    int res = 0;
    for (int i = 0; i < n-2; ++i) {
        for (int j = i+1; j < n-1; ++j) {
            for (int k = j+1; k < n; ++k) {
                if (l[i] + l[j] > l[k]) res++;
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3580
import std.stdio,
       std.string,
       std.conv,
       std.algorithm;

int abs(int x) {
  return (x >= 0) ? x : -x;
}

void main() {
  int N = readln.chomp.to!(int);
  int[][] a;
  for (int i = 0; i < N; i++) {
    a ~= readln.chomp.split.to!(int[]);
  }

  bool f = true;
  int t = 0, x = 0, y = 0;
  for (int i = 0; i < N; i++) {
    int dt = abs(a[i][0] - x), dx = a[i][1] - x, dy = a[i][2] - y;
    int d = abs(dx) + abs(dy);
    f = d <= dt && (d - dt) % 2 == 0;
    if (!f) {
      break;
    }
  }
  writeln(f ? "Yes" : "No");
}


Measured memory_bytes: 14076
/* warshall_floyd.cpp
    ワーシャルフロイド法を用いて、全点間最短路を求める。

    初期化：dis[i][j] = iからjへの距離(辺がなければINF) (i≠j)
            dis[i][i] = 0
            prev[i][j] = i

    負閉路の検出：dis[i][i] < 0 となる i が存在するか

    verified:
        https://atcoder.jp/contests/abc143/tasks/abc143_e
*/

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e17;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

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

/* warshall_floyd(dis,prev)
    入力：初期化した dis, prev
    計算量：O(|V|^3)
    副作用：dis[i][j]にiからjへの最短路のコストを格納、prev[i][j]にiからjへの最短路でのjの1つ前の点を格納
*/
void warshall_floyd(vector<vector<long long>> &dis, vector<vector<long long>> &prev) {
    int V = dis.size();
    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                if (dis[i][k] + dis[k][j] < dis[i][j]) {
                    dis[i][j] = dis[i][k] + dis[k][j];
                    prev[i][j] = prev[k][j];
                }
            }
        }
    }
}

/* get_path(prev, s, t)
    入力：warshall_floyd で得た prev, スタート s, ゴール t
    出力：s から t への最短路のパス
*/
vector<int> get_path(const vector<vector<long long>> &prev, int s, int t) {
    vector<int> path;
    for (int cur = t; cur != s; cur = prev[s][cur]) {
        path.push_back(cur);
    }
    path.push_back(s);
    reverse(path.begin(), path.end());
    return path;
}

/* is_negative(dis)
    入力：warshall_floyd で得た dis
    出力：負の有向路を含むかどうか
*/
bool is_negative(const vector<vector<long long>> &dis) {
    int V = dis.size();
    for (int i = 0; i < V; i++) {
        if (dis[i][i] < 0) {
            return true;
        }
    }
    return false;
}

int main() {
    int H, W;
    cin >> H >> W;

    // initialization
    vector<vector<long long>> dis(10, vector<long long>(10, INF));
    vector<vector<long long>> prev(10);
    for (int i = 0; i < 10; ++i) {
        dis[i][i] = 0;
        prev[i] = vector<long long>(10, i);
    }

    // input
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            long long c;
            cin >> c;
            dis[i][j] = c;
            // dis[t][s] = c;
        }
    }
    warshall_floyd(dis, prev);

    long long ans = 0;

    auto A = make_vec<long long>(H, W);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> A[i][j];
            if (A[i][j] != -1) {
                ans += dis[A[i][j]][1];
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
N, K = map(int, input().split())
d_list = []
A_list = []
for i in range(K):
    d_list.append(int(input()))
    A_ = list(map(int, input().split()))
    A_list.extend(A_)

K_all = set(A_list)
N_all = set(range(1, N+1))

no_N = N_all - K_all

print(len(no_N))


Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>
#include <cstdint>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long ll;

const int INF = 1 << 30;
const int MOD = 1e9 + 7;

double dp[310][310][310];
int n;
double rec(int n1, int n2, int n3) {
    if (dp[n1][n2][n3] >= 0) return dp[n1][n2][n3];
    if (n1 == 0 && n2 == 0 && n3 == 0) return 0.0;

    double res = 0.0;
    if (n1 > 0) res += rec(n1-1, n2, n3) * n1;
    if (n2 > 0) res += rec(n1+1, n2-1, n3) * n2;
    if (n3 > 0) res += rec(n1, n2+1, n3-1) * n3;
    res += n;
    res *= 1.0 / (n1 + n2 + n3);
    return dp[n1][n2][n3] = res;
}

int main() {
    cin >> n;
    vector<int> a(n); rep(i,n) cin >> a[i];
    memset(dp, -1, sizeof(dp));
    int one = 0, two = 0, three = 0;
    rep(i, n) {
        if (a[i] == 1) one++;
        else if (a[i] == 2) two++;
        else three++;
    }

    cout << fixed << setprecision(10) << rec(one, two, three) << endl;



    return 0;
}

Measured memory_bytes: 233088
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    //int t=1 ; cin>>t ; while(t--)
    {
        string s;
        cin >> s;

        int x = ( s[0] -'0' ) * 10 + s[1] - '0';
        int y = ( s[2] -'0' ) * 10 + s[3] - '0';

        if(1<=x && x<=12)
        {
            if(1<=y && y<=12)
                cout << "AMBIGUOUS";
            else
                cout << "MMYY";
        }
        else if (1<=y && y<=12)
            cout << "YYMM";
        else
            cout << "NA";
    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long ll;
const int MAXN = 0;

int main()
{
	//freopen("input.in", "r", stdin);
    string s;
    cin >> s;
    for (int i = 0; i < s.length()-1; i++)
    {
        if (s[i] == 'A' && s[i+1] == 'C')
        {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

static const int MAX = 100;

int main () {
        int n, i, j, A[MAX], temp, c = 0;

        cin >> n;
        for (i = 0; i < n; i++)
                cin >> A[i];

        for (i = 0; i < n; i++) {
                for (j = n - 1; j > i; j--) {
                        if (A[j] < A[j - 1]) {
                                        temp = A[j - 1];
                                        A[j - 1] = A[j];
                                        A[j] = temp;
                                        c++;
                                }
                }
        }

        //print Array
//      printf("%d", A[0]);
        cout << A[0];
        for (j = 1; j < n; j++) {
//              printf(" %d", A[j]);
                cout << ' ' << A[j];
        }
        cout << endl;

        cout << c << endl;

        return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define UNVISITED -1
#define _ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);
using namespace std;

typedef long long int64;
typedef pair<int, int> ii;

int main(){ _
  int n, m; cin >> n >> m;
  vector< vector<int> > matrix(n, vector<int> (m, 0));
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < m; ++j)
      cin >> matrix[i][j];

  vector< vector<int> > ans;
  for(int i = 0; i < n; ++i) {
    for(int j = 0; j + 1 < m; ++j) {
      if(matrix[i][j] % 2) {
        matrix[i][j] -= 1;
        matrix[i][j + 1] += 1;
        vector<int> row;
        row.push_back(i + 1);
        row.push_back(j + 1);
        row.push_back(i + 1);
        row.push_back(j + 2);
        ans.push_back(row);
      }
    }
  }

  for(int i = 0; i + 1 < n; ++i) {
    if(matrix[i][m - 1] % 2) {
      matrix[i][m - 1] -= 1;
      matrix[i + 1][m - 1] -= 1;
      vector<int> row;
      row.push_back(i + 1);
      row.push_back(m);
      row.push_back(i + 2);
      row.push_back(m);
      ans.push_back(row);
    }
  }

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

  return 0;
}


Measured memory_bytes: 11440
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ll x, y, a, b, c; cin >> x >> y >> a >> b >> c;
  vector<ll> p(a), q(b), r(c);
  rep(i, a) cin >> p[i];
  rep(i, b) cin >> q[i];
  rep(i, c) cin >> r[i];
  sort(p); sort(q); sort(r);

  vector<ll> v(x + y + c);
  for (int i = 0; i < x; i++) v[i] = p[a-1-i];
  for (int i = 0; i < y; i++) v[i+x] = q[b-1-i];
  for (int i = 0; i < c; i++) v[i+x+y] = r[i];
  sort(v);

  ll ans = 0;
  for (int i = 0; i < x+y; i++)
    ans += v[x+y+c-i-1];
  outl(ans);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll ar[200009];
int main()
{
   ll n,k,i,sum=0;
   cin>>n>>k;
   for(i=0;i<n;i++)
   {
       cin>>ar[i];
   }
   sort(ar,ar+n);
   for(i=n-1-k;i>=0;i--)
   {
       sum+=ar[i];
   }
   printf("%lld\n",sum);
}


Measured memory_bytes: 1792
/******************************************
* AUTHOR : Lokesh goel*
* NICK : InsaneNerd *
* INSTITUTION : NIT Kurukshetra *
******************************************/
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 1000000000
#define N 100005
#define pii pair<int,int>
#define vp vector<pair<int,int > >
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define gsz(x) ((int)(x).size())
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cerr.tie(NULL);
#define endl "\n"
#define ms(x,v) memset(x,v,sizeof(x))

int main()
{
	fastio;
	ll n,i,j;
	cin>>n;
	string str;
	map<string,int>m1;
	for(i=0;i<n;i++){
		cin>>str;
		m1[str]++;
	}
	cout<<"AC x "<<m1["AC"]<<endl;
	cout<<"WA x "<<m1["WA"]<<endl;
	cout<<"TLE x "<<m1["TLE"]<<endl;
	cout<<"RE x "<<m1["RE"]<<endl;

	return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}


int main(){
    int n;cin>>n;
    int p[n+1];
    vector<int> v[n+1];
    rep(i,1,n+1){
        cin>>p[i];
        v[p[i]].push_back(i);
    }
    queue<int> q;
    int d[n+1];
    fill(d,d+n+1,-1);
    rep(i,1,n+1){
        if(v[i].size()==0){
            q.push(i);
        }
    }
    int cnt[n+1];
    fill(cnt,cnt+n+1,0);
    int su=0;
    while(q.size()>0){
        int now=q.front();q.pop();
        su++;
        set<int> st;
        rep(i,0,v[now].size()){
            int ne=v[now][i];
            st.insert(d[ne]);
        }
        d[now]=0;
        while(st.count(d[now]))d[now]++;
        cnt[p[now]]++;
        if(cnt[p[now]]==v[p[now]].size())q.push(p[now]);
    }
    int t=n-su;
    int num=-1;
    int cn=0;
    rep(i,1,n+1){
        if(d[i]==-1){
            set<int> st;
            num=i;
            rep(j,0,v[i].size())st.insert(d[v[i][j]]);
            int y=0;
            while(st.count(y))y++;
            cn=y;
            break;
        }
    }
    
    int ki=num;
    d[num]=cn;
    int c=0;
    for(;;){
        if(p[num]==ki){
            if(d[ki]!=d[num]){
                c=1;
            }
            break;
        }
            num=p[num];
        
            set<int> st;
            rep(k,0,v[num].size()){
                int ne=v[num][k];
                st.insert(d[ne]);
            }
            int y=0;
            while(st.count(y))y++;
            d[num]=y;
    }
    d[ki]=cn+1;
    num=ki;
    for(;;){
        if(p[num]==ki){
            if(d[ki]==d[num]+1){
                c=1;
            }
            break;
        }
        num=p[num];
        
        set<int> st;
        rep(k,0,v[num].size()){
            int ne=v[num][k];
            st.insert(d[ne]);
        }
        int y=0;
        while(st.count(y))y++;
        d[num]=y;
    }
    if(c==0){
        cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }
    
    cout<<"POSSIBLE"<<endl;
}


Measured memory_bytes: 12544
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(long long i=0; i<(int)n; i++)
#define rep2(i,a,n) for(long long i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}

int N, M, K, H, W, L, R, X;
//string S, T;

signed main(){
  int t;
  cin >> X >> t;
  int ans = X-t;
  if(ans<0) ans = 0;
  
  cout << ans << endl; 
  return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, a, b;
  scanf("%lld%lld", &a, &b);
  if(b != 100) printf("%lld", b);
  else printf("101");
  for(i = 0; i < a; ++i) printf("00");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n;
    ll m, a[55] = {1}, b[55] = {1}, z = 0;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) a[i] = a[i - 1] * 2 + 1, b[i] = b[i - 1] * 2 + 3;
    for (int i = n; i >= 0; i--) {
        if (!i) {
            if (m > 0) z++;
        } else if (m >= b[i - 1] + 1) {
            z += a[i - 1];
            if (m >= b[i - 1] + 2) z++;
            m -= b[i - 1] + 2;
        } else {
            m--;
        }
    }
    cout << z;
}


Measured memory_bytes: 256
'use strict'

const main = input => {
	const n = parseInt(input.split('\n')[0], 10)
	let t1 = n 
	let sum = 0

	while (t1 > 0) {
		sum += t1 % 10
		t1 = Math.floor(t1 / 10)
	}

	if (n % sum === 0) console.log('Yes')
	else console.log('No')
}

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


Measured memory_bytes: 7372
package main

import (
	"fmt"
	"sort"
)

var N, K, r int
var a []int

func main() {
	fmt.Scan(&N, &K)
	a = make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&a[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	for i := 0; i < K; i++ {
		r += a[i]
	}
	fmt.Println(r)
}

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

int main(){
    
    long int n, max=-1000000, min=1000000, total=0;
    cin >> n;
    int a[n];
    
    for (int i=0;i<n;i++){
        cin >> a[i];
    }
    
    for (int i=0;i<n;i++){
        if (a[i]>=max) max=a[i];
        if (a[i]<=min) min=a[i];
        
        total+=a[i];
    }
    
    cout << min << ' ' << max << ' ' << total << endl;
}


Measured memory_bytes: 3124
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>

using namespace std;

#define x first
#define y second
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define all(x) x.begin(),x.end()
#define SZ(x) int(x.size())
#define rep(i, a, b) for(int i = a; i < b; i++)
#define per(i, a, b) for(int i = b-1; i >= a; i--)
#define DBG(x) cerr << (#x) << "=" << x << "\n";
#define ll long long
#define inf 1000000007
#define mod 1000000007
#define N 45

template<typename U, typename V> void Min(U &a, const V & b){if(a > b)a = b;}
template<typename U, typename V> void Max(U &a, const V & b){if(a < b)a = b;}
template<typename U, typename V> void add(U &a, const V & b){a = (a + b) % mod;}
template<typename U> U gcd(U a, U b){
    if(a == 0)return b;
    if(b == 0)return a;
    if(a >= b)return gcd(a % b, b);
    else return gcd(a, b % a);
}
int pow(int a, int b){
    int ans = 1;
    while(b){
        if(b & 1)ans = 1LL * ans * a % mod;
        a = 1LL * a * a % mod;
        b >>= 1;
    }
    return ans;
}

vi v;
int main(){
    int T, m, n, i, j, k, K;
    ll a, b;
    scanf("%lld%lld", &a, &b);
    a = gcd(a, b);
    rep(i, 2, 1e6+1){
        if(1LL * i * i > a)break;
        if(a % i == 0){
            k = 0;
            while(a % i == 0)a /= i, k++;
            v.pb(k);
        }
    }
    if(a > 1)v.pb(1);
    m = SZ(v);
    printf("%d\n", m + 1);
}


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

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define Itr(i, c) for(typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main(){
	int n, m, x, y; cin >> n >> m >> x >> y;
	int _min = inf, _max = -inf;
	Rep(i, n){
		int t; cin >> t;
		_max = max(_max, t);
	}
	Rep(i, m){
		int t; cin >> t;
		_min = min(_min, t);
	}
	bool flag = true;
	if(_max < _min){
		For(z, _max + 1, _min + 1){
			if(z > x && z <= y){
				continue;
			}else{
				flag = false;
			}
		}
	}else{
		flag = false;
	}
	if(flag){
		cout << "No War" << endl;
	}else{
		cout << "War" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include<algorithm>
#include <queue>
#include <cmath>
#include <limits>
#include <map>
using namespace std;

int main(){
  int a,b;
  cin >> a >>b;
  int res[4];
    res[0] = a+b;
    res[1] =a-b;
    res[2] = a*b;
int max=res[0];
for(int i = 0;i<3;i++){
if(res[i]>max){
  max= res[i];
}
}
  cout << max<<endl;
  return 0;
}

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



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

Measured memory_bytes: 6752
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <sstream>
#include <cstdio>
#include <stack>
using namespace std;

// Integral(0014)
int main()
{
	int d;
	while (cin >> d) {
		long long int s = 0;
		for (int i = 0; i+d < 600+1; i += d)
			s += (d * i * i);
		cout << s << endl;
	}
	return 0;
}

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL(x) memset(x,0,sizeof(x))


using namespace std;

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

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

ll K;
int N;
vector<ll> A;

int main()
{
  cin >> K >> N;
  A.resize(N);
  rep(i, N)
    cin >> A[i];
  

  vector<ll> dist(N);
  rep(i, N-1)
    {
      dist[i]=A[i+1]-A[i];
    }
  dist[N-1]=K-A[N-1]+A[0];
    
  sort(dist.begin(), dist.end());

  cout << K-dist[N-1] << endl;
  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

template<int mod> struct ModInt{
    long long x=0; 
    constexpr ModInt(long long x=0):x((x%mod+mod)%mod){}
    constexpr ModInt operator+(const ModInt& r)const noexcept{return ModInt(*this)+=r;}
    constexpr ModInt operator-(const ModInt& r)const noexcept{return ModInt(*this)-=r;}
    constexpr ModInt operator*(const ModInt& r)const noexcept{return ModInt(*this)*=r;}
    constexpr ModInt operator/(const ModInt& r)const noexcept{return ModInt(*this)/=r;}
    constexpr ModInt& operator+=(const ModInt& r)noexcept{ if((x+=r.x)>=mod) x-=mod; return *this;}
    constexpr ModInt& operator-=(const ModInt& r)noexcept{ if((x-=r.x)<0) x+=mod; return *this;}
    constexpr ModInt& operator*=(const ModInt& r)noexcept{ if((x*=r.x)>=mod) x%=mod; return *this;}
    constexpr ModInt& operator/=(const ModInt& r)noexcept{ return *this*=r.inv();}
    ModInt inv()const noexcept{
        long long s=x,sx=1,sy=0,t=mod,tx=0,ty=1;
        while(s%t!=0){
            long long temp=s/t,u=s-t*temp,ux=sx-temp*tx,uy=sy-temp*ty;
            s=t;sx=tx;sy=ty;
            t=u;tx=ux;ty=uy;
        }
        return ModInt(tx);
    }
    ModInt pow(long long n)const noexcept{
        ModInt a=1;
        while(n>0){
            if(n&1) a*=*this;
            *this*=*this;
            n>>=1;
        }
        return a;
    }
    friend constexpr ostream& operator<<(ostream& os,const ModInt<mod>& a) {return os << a.x;}
    friend constexpr istream& operator>>(istream& is,ModInt<mod>& a) {return is >> a.x;}
};
using mint = ModInt<MOD>;

struct combination{
    int N;
    vector<mint> fac,finv,inverse;
    combination(int N=0):N(N){
        fac.resize(N+1);finv.resize(N+1);
        fac[0]=1;
        for(int i=1;i<=N;++i){fac[i]=fac[i-1]*i;}
        finv[N]=fac[N].inv();
        for(int i=N-1;i>=0;--i){finv[i]=finv[i+1]*(i+1);}
    }
    void inverse_build(){
        inverse.resize(N+1);
        inverse[1]=1;
        for(int i=2;i<=N;++i){inverse[i]=finv[i]*fac[i-1];}
    }
    mint c(const int& n,const int& k){
        if(n<k||n<0||k<0) return 0;
        return fac[n]*finv[n-k]*finv[k];
    }
    mint p(const int& n,const int& k){
        if(n<k||n<0||k<0) return 0;
        return fac[n]*finv[n-k];
    }
};

int main(){
    combination com(1000000);
    int x,y;
    cin >> x >> y;
    mint ans = 0;
    if(2*y-x<0||2*x-y<0);
    else if((2*y-x)%3 != 0 || (2*x-y)%3 != 0);
    else{
        int s = (2*x-y)/3;
        int t = (2*y-x)/3;
        ans = com.c(s+t,s);
    }
    cout << ans << endl;
    return 0;
}

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

#define long long long

using namespace std;

const int N = 1e5+5;
const int M = 1e9+7;

long modpow(long a, long b) {
    long ret = 1;
    for( ; b; b >>= 1) {
        if(b & 1) ret = (ret * a) % M;
        a = (a * a) % M;
    }
    return ret;
}

int n, l, m, r;
int A[N], pos[N];
long fac[N], inv[N];

long ncr(int a, int b) {
    if(a < b || a < 0 || b < 0) return 0;
    return fac[a] * inv[b] % M * inv[a - b] % M;
}

int main() {
    fac[0] = inv[0] = 1;
    for(int i = 1; i < N; i++) {
        fac[i] = (fac[i-1] * i) % M;
        inv[i] = modpow(fac[i], M-2);
    }

    scanf("%d", &n);
    for(int i = 1; i <= n + 1; i++) {
        scanf("%d", A + i);
        if(!pos[A[i]]) pos[A[i]] = i;
        else l = pos[A[i]] - 1, m = i - pos[A[i]] - 1, r = n + 1 - i;
    }
    for(int i = 1; i <= n + 1; i++) {
        if(i == 1) printf("%d\n", n);
        else {
            long now = ncr(n - 1, i); //Not include any dup
            now = (now + ncr(l + r, i - 1)) % M; //Include one dup but same
            now = (now + ncr(n - 1, i - 2)) % M; //Include both dup
            now = (now + (ncr(n - 1, i - 1) - ncr(l + r, i - 1) + M) % M) % M; //Include one dup but different
            now = (now + (ncr(n - 1, i - 1) - ncr(l + r, i - 1) + M) % M) % M; //Include one dup but different
            printf("%lld\n", now);
        }
    }

    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, n) for (int i = 1; i <= (n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
using Grid = vector<vector<int>>;
using vi = vector<int>;

int main() {
    int P, Q, R;
    cin >> P >> Q >> R;
    cout << min(P + Q, min(Q + R, R + P)) << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n;
  ll m;
  cin >> n >> m;
  vector<ll> a(n + 1, 0);
  FOR(i, 1, n + 1) {
    cin >> a[i];
    a[i] = (a[i] + a[i - 1]) % m;
  }

  map<ll, ll> cnt;
  rep(i, n + 1) cnt[a[i]]++;

  ll ans = 0;
  rep(i, n + 1) {
    ans += cnt[a[i]] * (cnt[a[i]] - 1) / 2;
    cnt[a[i]] = 0;
  }
  cout << ans << endl;




  
  return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
int main(){
    ll n, h, w; cin>> n >> h >> w;
    ll a[n], b[n];
    ll cnt = 0;
    for(ll i = 0; i < n; i++){
        cin >> a[i] >> b[i];
        if(a[i] >= h && b[i] >= w){
            cnt++;
        }
    }
    cout << cnt << endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll l, r, d, ans = 0;
  cin >> l >> r >> d;
  for (int i = l; i <= r; ++i) {
    if (i >= d && i % d == 0) ans++;
  }

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


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


int iabs(int x);
int imin(int x, int y);

int main(){
  
  /* read input */
  char S[11];
  scanf("%s", S);  // read string by line
  int n = strlen(S);
  //printf("%d\n", n);
  
  /*solve problem*/
  int ans = 753;
  int tmp;
  for(int i = 0; i < n-2; i++){
    tmp = 100*((int)(S[i]-'0')) + 10*(int)(S[i+1]-'0') + (int)(S[i+2]-'0');
    //printf("tmp:%d\n", tmp);
    ans = imin(ans, iabs(753 - tmp));
  }
  
  printf("%d", ans);
  
  return 0;
}

int iabs(int x){
  if(x > 0){
    return x;
  }
  else
    return -x;
}

int imin(int x, int y){
  if(x > y)
    return y;
  else
    return x;
}

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

typedef long long ll;

int main() {
    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    ll ans = 0;
    if (a[0] > x) {
        ans = a[0] - x;
        a[0] = x;
    }
    rep(i, N - 1) {
        int d = a[i] + a[i + 1] - x;
        if (d > 0) {
            a[i + 1] -= d;
            ans += d;
        }
    }
    cout << ans << endl;
}

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

int main(){
  int n,a,b,c,d,t=-1,nr=1,count=0;
  int pt[100]={};
  int rank[100]={};

  cin >> n;

  for (int i=0;i<n*(n-1)/2;i++){
    cin >> a >> b >> c >> d;
    if (c > d) pt[a-1]+=3;
    else if (c < d) pt[b-1]+=3;
    else {
      pt[a-1]++;
      pt[b-1]++;
    }
  }
  while (nr<=n){
    for (int i=0;i<n;i++){
      if (t<pt[i])t=pt[i];
    }
    for (int i=0;i<n;i++){
      if (t==pt[i]){
	rank[i]=nr;
	pt[i]=-1;
	count ++;
      }
    }
    nr+=count;
    count =0;
    t=-1;
  }

  for (int i=0;i<n;i++) cout << rank[i] <<endl;

  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,s;
int main()
{
    cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;i++)
      for(ll j=1;j<=n;j++)
        for(ll k=1;k<=n;k++)
          ans+=__gcd(i,__gcd(j,k));
    cout<<ans;
    return 0;
  }

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

using namespace std;

vector <vector <int> >g;

int calc(int pre, int u){
	int s=0;
	for(int i=0;i<g[u].size();++i){
		if(pre!=g[u][i]) s^=calc(u, g[u][i]);
	}
	return s+1;
}

int main(){
	int n;
	cin >> n;
	g=vector <vector <int> >(n);
	for(int i=0;i<n-1;++i){
		int x, y;
		cin >> x >> y;
		--x;
		--y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	int r=0;
	for(int i=0;i<g[0].size();++i){
		r^=calc(0, g[0][i]);
	}
	if(r==0) cout << "Bob" << endl;
	else cout << "Alice" << endl;
}

Measured memory_bytes: 12032
#include<bits/stdc++.h>
#define uLL unsigned long long
using namespace std;
#define LL long long
int a[55][55];
int n,d;
bool Check(int i,int j) {
	LL he = 0;
	for(int k=1; k<=d; k++) {
		he += (a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
	}
	int x = sqrt(he);
	if(x * x == he) return true;
	else return false;
}
int main() {
	cin >> n >> d;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=d; j++) scanf("%d",&a[i][j]);
	}
	int ans = 0;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<i; j++) {
			if(Check(i,j)) ans ++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};
const ll mod=1e9+7;
using modint = ModInt< mod >;

int N;
vector<vector<int>> G;
void input(){
  fast_io();
  #ifdef __LOCAL
      fs::path p = __FILE__;
      fs::path input,output;
      input = output = p.parent_path();
      input += string("/input/") + string(p.stem()) + string(".txt");
      output += string("/output/") + string(p.stem()) + string(".txt");
      freopen(input.c_str(), "r", stdin);
      freopen(output.c_str(), "w", stdout);
  #endif
  cin >> N;
  G.resize(N);
  for (int i = 0; i < N-1; i++){
    int x,y; cin >> x >> y;
    x--,y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
}

modint dp[100010][3];
bool used[100010][3];

modint dfs(int u, int c, int p=-1){
  if(used[u][c]) return dp[u][c];
  used[u][c] = true;
  modint ret = 1;
  for(int v:G[u]){
    if(v==p) continue;
    if(c) ret *= dfs(v,0,u);
    else ret *= (dfs(v,0,u)+dfs(v,1,u));
  }
  return dp[u][c] = ret;
}

int solve(){
  memset(dp,0,sizeof(dp));
  memset(used,false,sizeof(used));
  cout << (dfs(0,0)+dfs(0,1)) << endl;
  return 0;
}

int main()
{
  // maketestcase(400);
  input();
  solve();
  return 0;
}


Measured memory_bytes: 15488
def lcs(s1,s2):
    dp = [[0 for i in range(1+len(s1))] for j in range(1+len(s2))]
    for i in range(len(s1)):
        for j in range(len(s2)):
            lis = [dp[j][i+1],dp[j+1][i]]
            if s1[i] == s2[j]:
                lis.append(dp[j][i]+1)
            dp[j+1][i+1] = max(lis)
    ans=[]
    i=len(s1)
    j=len(s2)
    while i>0 and j>0:
        if s1[i-1]==s2[j-1]:
            ans.append(s1[i-1])
            i-=1
            j-=1
        elif dp[j][i]==dp[j-1][i]:
            j-=1
        else:
            i-=1
    print(''.join(ans[::-1]))

s=input()
t=input()

lcs(s,t)

Measured memory_bytes: 119644
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
 
int main(){
  cin >> n;
  cin >> s;
  int ans = 1;
  for(int i=0;i+1<n;i++){
     if (s[i] != s[i+1]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b



def solve():
    N = int(input())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))

    p = 0
    q = 0
    for i, v in enumerate(permutations(range(1, N + 1)), start=1):
        p_ok = True
        q_ok = True
        for j in range(N):
            p_ok &= v[j] == P[j]
            q_ok &= v[j] == Q[j]

        if p_ok:
            p = i
        if q_ok:
            q = i

    print(abs(p - q))


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 9920
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

public class Main {

  ArrayList<LinkedList<Edge>> tree;
  boolean[] visited ;
  int[] colors;

  public static void main(String[] args) {

    new Main().run();
  }
  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter out = new PrintWriter(System.out)) {

      int n = Integer.parseInt(in.readLine());
      tree = new ArrayList<>(n);
      for (int i = 0; i < n; i++) {
        tree.add(new LinkedList<Edge>());
      }
      String[] lines;
      for (int i = 0; i < n-1; i++) {
        lines = in.readLine().split(" ");
        int v = Integer.parseInt(lines[0]) - 1;
        int u = Integer.parseInt(lines[1]) - 1;
        int d = Integer.parseInt(lines[2]);
        tree.get(v).add(new Edge(u, d));
        tree.get(u).add(new Edge(v, d));
      }

      visited = new boolean[n];
      colors  = new int[n];
      Arrays.fill(colors, -1);

      bfs(0, 0);

      for (int c : colors) {
        out.println(c);
      }
      out.flush();
    }
    catch(IOException e) {

      System.err.println(e);
    }
  }

  void bfs(int fv, int fd) {
    Deque<Edge> stuck = new ArrayDeque<>();

    stuck.push(new Edge(fv, fd));

    while(!stuck.isEmpty()) {
      Edge v = stuck.pop();

      if(!visited[v.v]) {
        visited[v.v] = true;
        int d = colors[v.v] = v.d % 2 == 0 ? 0 : 1;
        for (Edge u : tree.get(v.v)) {
          stuck.push(new Edge(u.v, d + u.d));
        }
      }
    }
  }

  private class Edge {
    int v, d = -1;

    public Edge(int v, int d) {
      this.v = v;
      this.d = d;
    }
  }
}

Measured memory_bytes: 72084