akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int N = ni();
        String S = ns();
        ArrayDeque<Integer> que = new ArrayDeque<>();
        int numL = 0;
        int numR = 0;
        int maxGap = 0;
        for (int i = 0; i < N; i++) {
            if(S.charAt(i) == '('){
                que.addLast(0);
                numL++;
            }else{
                que.addLast(1);
                numR++;
            }
            maxGap = Math.max(maxGap, numR-numL);
        }
        int gapLast = numL-numR+maxGap;
        // System.out.println(maxGap);
        // System.out.println(gapLast);
        for (int i = 0; i < maxGap; i++) {
            que.addFirst(0);
        }
        for (int i = 0; i < gapLast; i++) {
            que.addLast(1);
        }
        // System.out.println(que.toString());
        int ql = que.size();
        for (int i = 0; i < ql; i++) {
            int a = que.removeFirst();
            if(a == 0){
                out.print("(");
            }else{
                out.print(")");
            }
        }
        out.println("");
    }

 
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 21076
#include<iostream>
using namespace std;
int main() {
 int A, B;
 cin >> A >> B;
 if(A == 1){
  A = 14;
 }
 if(B == 1) {
  B = 14;
 }
 if((A - B) > 0) {
  cout << "Alice" << endl;
 }else if((A - B) < 0) {
  cout << "Bob" << endl;
 }else{
  cout << "Draw" << endl;
 }
 return 0;
}

Measured memory_bytes: 256
import collections

N = int(input())
l = [input() for _ in range(N)]
l = collections.Counter(l)
l = list(l.most_common())
sorted(l, key=lambda x: (-x[1], x[0]))
# print(l)
max_num = l[0][1]
values, counts = zip(*l)
ans = []
for i in range(len(l)):
    if l[i][1] != max_num:
        break
    # print(values[i])
    ans.append(l[i][0])
ans.sort()
for i in ans:
    print(i)


Measured memory_bytes: 48592
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N, K, sum; cin >> N >> K;
  vector<int> l(N);
  for(int i = 0; i < N; i++) cin >> l[i];
  sort(l.begin(), l.end(), greater<int>());
  for(int i = 0; i < K; i++) sum += l[i];
  cout << sum << endl;
}

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

int main(){
  int a, b;
  cin >> a >> b;
  int c, d, e;
  c = a+b;
  d = a*b;
  e = a-b;
  if(c > d && c > e) cout << c;
  else if(d > c && d > e) cout << d;
  else cout << e;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
 
#include <stdio.h>
#include <bits/stdc++.h>
 
using namespace std;
 
#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  
#define pb push_back
#define mp make_pair
#define in insert
#define f first
#define s second
#define ll long long
#define dd double
  
const int mod = 1e9 + 7;
const int N = 1e5 + 7;
const int inf = 2e9;
const ll INF = 1e18;

ll p[N], q[N], r[N];

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// freopen("*.in", "r", stdin);freopen("*.out", "w", stdout);
	ll x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	for (int i = 0; i < a; i++)
		cin >> p[i];
	for (int i = 0; i < b; i++)
		cin >> q[i];
	for (int i = 0; i < c; i++)
		cin >> r[i];

	sort(p, p + a);
	sort(q, q + b);
	sort(r, r + c);

	ll ans = 0;
	vector<ll> v;

	for (int i = a - x; i < a; i++) {
		v.pb(p[i]);
	}
	for (int i = b - y; i < b; i++) {
		v.pb(q[i]);
	}
	for (int i = 0; i < c; i++) {
		v.pb(r[i]);
	}

	sort(v.begin(), v.end());

	for (int i = v.size() - x - y; i < v.size(); i++) {
		ans += v[i];
	}

	cout << ans;
}

Measured memory_bytes: 8432
# 155_b
N=int(input())
A=input().split()
result=''
for i in range(N):
    A[i]=int(A[i])
    if A[i]%2==0:
        if A[i]%3!=0 and A[i]%5!=0:
            result = 'DENIED'
            break
    else:
        result='APPROVED'
print(result)

Measured memory_bytes: 9088
#include<stdio.h>
#include<limits.h>

#define INF INT_MAX

void mcorder(int);
int min(int, int);

int m[101][101];
int p[101];

int main()
{
  int n, i, a, b;

  scanf("%d", &n);
  for(i=0; i<n; i++)
    {
      scanf("%d%d",&a,&b);
      if(i==0)
	p[i]=a;
      p[i+1]=b;
    }
  
  mcorder(n);

  printf("%d\n", m[1][n]);
  
  return 0;
}

void mcorder(int n)
{
  int i, j, k, a, q;
  
  for(i=1; i<=n; i++)
    m[i][i]=0;
  
  for(a=2; a<=n; a++)
    {
      for(i=1; i<=n-a+1; i++)
	{
	  j=i+a-1;
	  m[i][j]=INF;
	  for(k=i; k<=j-1; k++)
	    {
	      q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	      m[i][j]=min(m[i][j],q);
	    }
	}
    }
}
int min(int a, int b)
{
  if(a<=b)
    return a;
  else
    return b;
}

Measured memory_bytes: 636
N, M = map(int, input().split())
X = []
for _ in range(N):
    a, b = map(int, input().split())
    X.append((a,b))

X = sorted(X, key = lambda x: x[0])
ans = 0
for i in range(N):
    if X[i][1] >= M:
        ans += M * X[i][0]
        break
    else:
        ans += X[i][1] * X[i][0]
        M -= X[i][1]

print(ans)

Measured memory_bytes: 57688
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, K: int):
    if A>=K:
        print(A-K,B)
    else:
        print(0,max(0,B-(K-A)))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#-swank
(unless (member :child-sbcl *features*)
  (quit
	:unix-status
	(process-exit-code
	  (run-program *runtime-pathname*
				   `("--control-stack-size" "128MB"
					 "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
					 "--eval" "(push :child-sbcl *features*)"
					 "--script" ,(namestring *load-pathname*))
				   :output t :error t :input t))))

(let* ((s (read-line)) 
	   (n (length s))
	   (ans 0))
  (loop for i from 1 to (1- (floor n 2)) do
		(when (string= (subseq s 0 i) (subseq s i (* i 2)))
		  (setf ans (ash i 1))))
  (princ ans))


Measured memory_bytes: 15288
N = int(input())
X = list(map(int, input().split(' ')))

# N = 2
# X = [1, 2]

# N = 6
# X = [5, 5, 4, 4, 3, 3]

# target = int((N-1)/2)
first_m = int(N/2)
second_m = first_m - 1
X_ = sorted(X)
for i in range(N):
    if X[i] <= X_[second_m]: print(X_[first_m])
    else: print(X_[second_m])

Measured memory_bytes: 26180
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

    class Program
    {
        static void Main(string[] args)
        {
            // 湖の距離と家の数
            var input = Console.ReadLine().Split(' ');
            var numArray = input.Select(x => int.Parse(x)).ToArray();

            // 家のそれぞれの距離
            var houseDistance = Console.ReadLine().Split(' ');
            var houseDistanceArray = houseDistance.Select(x => int.Parse(x)).ToArray();
            var houseDistanceList = new List<int>(houseDistanceArray);

            // 家間の距離を求める
            var distanceList = new List<int>();
            for (var i = 0; i < numArray[1]; i++)
            {
                if (i + 1 == numArray[1])
                {
                    distanceList.Add(numArray[0] + houseDistanceList[0] - houseDistanceList[i]);
                }
                else
                {
                    distanceList.Add(houseDistanceList[i + 1] - houseDistanceList[i]);
                }
            }

            // 並べ替え
            distanceList.Sort();

            // 全部の家を回る最短距離を求める
            var result = 0;
            for (var i = 0; i < numArray[1] - 1; i++)
            {
                result += distanceList[i];
            }

            Console.WriteLine(result);
        }
    }


Measured memory_bytes: 36580
/*
  author:   Ziel
  created:  05.07.2020 17:39:11
*/

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

#define fi first
#define se second
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define bpc __builtin_popcountl
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T>
using p_queue = priority_queue<T, vector<T>, greater<T>>;
struct chash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + RANDOM);
  }
};

const ll N = 1e5 + 123, MOD = 1e9 + 7, oo = 1e9 + 9, INF = 1e18 + 9;
const db EPS = 1e-9, PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

int32_t main() {
  // fre("");
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> a(h);
  for (auto& x: a)
    cin >> x;
  
  int sum = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      sum += (a[i][j] == '#');
    }
  }
  
  int ans = 0;
  for (int mask = 0; mask < (1 << h); mask++) {
    for (int msk = 0; msk < (1 << w); msk++) {
      int cnt = 0;
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          if (((1 << i) & mask) || ((1 << j) & msk)) {
            cnt += (a[i][j] == '#');
          }
        }
      }
      if (sum - cnt == k) {
        ans++;
      }
    }
  }
  
  cout << ans;
  
  return 0;
}

// uniform_int_distribution<int>(l, r)(rng) -> random in range [l, r]
// assert(condition) -> if (condition == false) Runtime Error
// order_of_key(x) -> number of elements smaller than x
// *find_by_order(k) -> k-th element in 0-based indexation
// gp_hash_table<T, U, chash> -> fast unordered_map
// m.count(x) <-> (m.find(x) != m.end())


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

int main() {
	// your code goes here
  int n;
  cin>>n;
  long long int ar[n];
  for(int i=0;i<n;i++)
   cin>>ar[i];
  //for(int i=1;i<n;i++)
   //ar[i]+=ar[i-1];
  long long int dp[n][n];
  for(int i=0;i<n;i++)
  {
  	for(int j=0;j<n;j++)
  	 dp[i][j]=1000000000000000000;
  }
  for(int i=n-1;i>=0;i--)
  {
  	for(int j=i;j<n;j++)
  	{
  	 if(i==j)
  	  dp[i][j]=0;
  	 else  if(j==i+1)
  	   dp[i][j]=ar[j]+ar[i];
  	 else 
  	 {
  	  long long int sum=0;
  	   for(int k=i;k<=j;k++)
  	    sum+=ar[k];
  	   for(int k=i;k<j;k++)//k is end point of first
  	    {
  	    	dp[i][j]=min(dp[i][k]+dp[k+1][j],dp[i][j]);
  	    }
  	   if(dp[i][j]!=INT_MAX) dp[i][j]+=sum; 
  	 }
  	}
  }
  cout<<dp[0][n-1]<<endl;
	return 0;
}

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

template <class T, class U>
inline bool chmin(T& t, const U& f) { return t > f ? t = f, true : false; }

struct UnionFind {
    vector<int> data;
    int g;
    UnionFind(int n) : data(n, -1), g(n) {}
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        g--;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }
    int groups() { return g; }
};

struct Edge {
    int src, dst, wt;
    Edge(int s, int d, int w) : src(s), dst(d), wt(w) {}
    bool operator<(const Edge& other) const { return wt < other.wt; }
};

using Edges = vector<Edge>;

bool possible(Edges::const_iterator first, Edges::const_iterator last, int n) {
    UnionFind uf(n);
    for (; first != last; ++first) if (!uf.unite(first->src, first->dst)) continue;
    return uf.groups() == 1;
}

int solve(int n, int m, const Edges& E) {
    if (!possible(all(E), n)) return -1;
    int small = E[m - 1].wt - E[0].wt;
    for (int l = 0; l < m - 1; ++l) {
        for (int r = l + 1; r <= m and small > E[r - 1].wt - E[l].wt; ++r) {
            while (r < m and E[r - 1].wt == E[r].wt) ++r;
            if (r - l < n - 1 or !possible(E.begin() + l, E.begin() + r, n)) continue;
            small = E[r - 1].wt - E[l].wt;
        }
        while (E[l].wt == E[l + 1].wt) ++l;
    }
    return small;
}

int main() {
    for (int n, m; cin >> n >> m, n | m;) {
        Edges E;
        rep(i, m) {
            int a, b, w; cin >> a >> b >> w; a--; b--;
            E.emplace_back(a, b, w);
        }
        sort(all(E));
        cout << solve(n, m, E) << endl;
    }
}

Measured memory_bytes: 3220
/*
* @Author Silviase(@silviasetitech)
* For ProCon
*/

import java.util.*;
import java.lang.*;
import java.math.*;
import java.awt.*;

public class Main{

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

        int                 n           = sc.nextInt();
        PriorityQueue<Long> pribig      = new PriorityQueue<>(Comparator.naturalOrder());
        PriorityQueue<Long> prismall    = new PriorityQueue<>(Comparator.reverseOrder());
        long                sum_big     = 0;
        long                sum_small   = 0;
        long                sum_b       = 0;
        long                median;

        for (int i = 0; i < n; i++) {
            /**
             * n - Queries
             */
            int query_type = sc.nextInt();
            if (query_type == 1) {
                // koushin
                long a_query    = sc.nextLong();
                long b_query    = sc.nextLong();
                sum_b           += b_query;

                if (prismall.isEmpty() || prismall.peek() >= a_query) {
                    // prismall.peek -> pribig, a -> prismall
                    prismall.add(a_query);
                    sum_small   +=  a_query;
                    if (!prismall.isEmpty() && prismall.size() > pribig.size() + 1 ) {
                        long change = prismall.poll();
                        sum_small   -= change;
                        sum_big     += change;
                        pribig.add(change);
                    }
                }else{
                    pribig.add(a_query);
                    sum_big += a_query;
                    if (pribig.size() > prismall.size()) {
                        long odsends    = pribig.poll();
                        sum_big         -= odsends;
                        sum_small       += odsends;
                        prismall.add(odsends);
                    }
                }
            }else if(query_type == 2){
                // hanbetsu
                // small = big or small = big + 1
                median = prismall.peek();
                System.out.println(median + " " + 
                                    (sum_big - sum_small + sum_b +(prismall.size() - pribig.size()) * median));
            }
            
        }

        sc.close();
    }

}




Measured memory_bytes: 154904
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

class Comb {
 public:
  Comb(int n) {
    fact[0] = fact[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < n; i++){
        fact[i] = fact[i-1] * i % kMod;
        inv[i] = kMod - inv[kMod%i] * (kMod / i) % kMod;
        finv[i] = finv[i-1] * inv[i] % kMod;
    }
  }

  LL nCr(int n, int r) const {
    LL numerator = fact[n];
    LL denominator = finv[r] * finv[n-r] % kMod;
    return (numerator * denominator) % kMod;
  }

 private :
  static constexpr int kMax = 1e5;
  LL fact[kMax];
  LL inv[kMax];
  LL finv[kMax];
};


int main() {
  int N, K; std::cin >> N >> K;
  Comb c(N);
  for (int k = 1; k <= K; ++k) {
    std::cout << c.nCr(N - K + 1, k) * c.nCr(K - 1,  k - 1) % kMod << std::endl;
  }
}


Measured memory_bytes: 2304
'''
Author:Fuad Ashraful Mehmet
University of Asia Pacific
Date:09 Feb 2020
'''

class Distinct:

    def __init__(self,n):
        self.n=n
        self.numbers=list(map(int,input().split()))
    
    def solve(self):
        if len(set(self.numbers))==self.n:
            return "YES"
        return "NO"

obj=Distinct(int(input()))

print(obj.solve())

Measured memory_bytes: 25932
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X,Y;
  cin>>X>>Y;
  
  int sw=0;
  for(int i=0;i<X+1;i++){
    if(i*2+(X-i)*4==Y){
      sw=1;
    }
  }
  
  if(sw==1){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}



  

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

typedef pair<int, int> P;

string str;

P expr(int);
P term(int);
P factor(int);
P number(int);

P expr(int idx)
{
  P res = term(idx);
  idx = res.first;
  int ans = res.second;
  
  while (idx < str.size() && (str[idx] == '+' || str[idx] == '-')) {
    res = term(idx + 1);
    bool plus = (str[idx] == '+');
    idx = res.first;
    
    if (plus) {
      ans += res.second;
    } else {
      ans -= res.second;
    }
  }
  return make_pair(idx, ans);
}

P term(int idx)
{
  P res = factor(idx);
  idx = res.first;
  int ans = res.second;
  
  while (idx < str.size() && (str[idx] == '*' || str[idx] == '/')) {
    res = factor(idx + 1);
    bool mult = (str[idx] == '*');
    idx = res.first;
    
    if (mult) {
      ans *= res.second;
    } else {
      ans /= res.second;
    }
  }
  return make_pair(idx, ans);
}

P factor(int idx)
{
  if (str[idx] == '(') {
    P res = expr(idx + 1);
    res.first++;
    return res;
  } else if (isdigit(str[idx])) {
    P res = number(idx);
    return res;
  }
}

P number(int idx)
{
  int N = 0;
  while (idx < str.size() && isdigit(str[idx])) {
    N *= 10;
    N += str[idx++] - '0';
  }
  return make_pair(idx, N);
}

void solve()
{
  int ans = expr(0).second;
  cout << ans << endl;
}

int main()
{
  int N;
  scanf("%d ", &N);
  
  for (int i = 0; i < N; i++) {
    getline(cin, str);
    str.erase(str.begin() + str.size() - 1);
    //cout << str << endl;
    solve();
  }
}

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

int main(){
  int n, count = 0;
  string copy;
  cin >> n;
  vector <string> v(n);
  rep(i, n) {
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  rep(i, n) {
    if(i == 0){
      copy = v.at(i);
      count++;
    }else if(copy != v.at(i)){
      copy = v.at(i);
      count++;
    }
  } 
  cout << count << endl;
}

Measured memory_bytes: 9592
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll read()
{
    char ch=getchar();
    ll x=0,f=1;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int main()
{
    int ans;
    int A,B,M,m1=1e6,m2=1e6;
    int a[100005],b[100005],c[100005];
    cin>>A>>B>>M;
    for(int i=0;i<A;i++)
    {
        cin>>a[i];
        if(m1>a[i])
            m1=a[i];
    }
    for(int i=0;i<B;i++)
    {
        cin>>b[i];
        if(m2>b[i])
            m2=b[i];
    }
    ans=m1+m2;
    for(int i=0;i<M;i++)
    {
        int x,y,c;
        cin>>x>>y>>c;
        if(ans>a[x-1]+b[y-1]-c)
            ans=a[x-1]+b[y-1]-c;
    }
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 1024
#include <stdio.h>
int main(){
	
	int n, m, l;
	
	scanf("%d", &n);
	scanf("%d", &m);
	scanf("%d", &l);
	
	int A[n][m];
	int B[m][l];
	double C[n][l];
	
	/*input matriz A*/
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			scanf("%d", &A[i][j]);
		}
	}
	
	/*input matriz B*/
	for(int i = 0; i < m; i++){
		for(int j = 0; j < l; j++){
			scanf("%d", &B[i][j]);
		}
	}
	
	/* initialize matriz C*/
	for(int i = 0; i < n; i++){
		for(int j = 0; j < l; j++){
			C[i][j] = 0;
		}
	}
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < l; j++){
			
			for(int k = 0; k < m; k++){
				C[i][j] += (double)A[i][k]*B[k][j];
			}
			
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < l; j++){
			printf("%.0lf", C[i][j]);
			if(j != l-1)
				printf(" ");
		}
		//if( i != n-1)
		printf("\n");
	}

  return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
string S, T;
string answer = "UNRESTORABLE";
bool exists = false;

int main() {
    cin >> S >> T;
    reverse(S.begin(), S.end());
    reverse(T.begin(), T.end());

    for (int i = 0; i < S.size(); i++) {
        for (int j = 0; j < T.size(); j++) {
            int count = 0;
            if (S.at(i) == T.at(j) || S.at(i) == '?') {
                count++;
                // Tのjより前の処理
                // 入りきらない場合
                if (i < j) break;
                for (int k = 1; k <= j; k++) {
                    if (S.at(i-k) == '?' || S.at(i-k) == T.at(j-k)) count++;
                }
                // Tのjより後の処理
                // 入りきらない場合
                if (S.size() - (i + 1) < T.size() - (j + 1)) break;
                
                for (int l = 1; l <= T.size() - (j+1); l++) {
                    if (S.at(i+l) == '?' || S.at(i+l) == T.at(j+l)) count++;
                }
                
                if (count == T.size()) {
                    for(int m = 0; m < T.size(); m++) {
                        S.at(i - j + m) = T.at(m);
                    }
                    exists = true;
                    break;
                }
            }
        }
        if (exists) break;
    }
    if (exists) {
        for(int i = 0; i < S.size(); i++) {
            if (S.at(i) == '?') S.at(i) = 'a';
        }
        reverse(S.begin(), S.end());
        answer = S;
    }

    cout << answer << endl;

    return 0;
}

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

using namespace std;

int main()
{   int k ,s;
    scanf("%d%d",&k,&s);

        long long ans=0;
        for(int x=0;x<k+1;x++){
            for(int y=0;y<k+1;y++){
                    int z = s-x-y;
                    if(z>=0 && z<=k)
                        ans++;

            }
        }
        printf("%I64d\n",ans);

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<tuple>
#include<iomanip>
#include<climits>
#define ll long long int
#define mod 1000000007
#define pi acos(-1)
using namespace std;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin>>n;
  int count=0;
  int min =10000000;
  for(int i=0;i<n;i++)
  {
    int tmp;
    cin>>tmp;
    if(tmp<=min)
    {
      min=tmp;
      count++;
    }

  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

const int mod = 1000000007;

struct mint {
    long long x;
    mint(long long x=0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n) : fact(n+1), ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i] * i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n-k];
    }
};
// combination c(max);
// mint c(n, k)

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

    int n, k;
    cin >> n >> k;
    combination c(n+k);
    cout << c(k, n) * c.fact[n] << endl;
}



Measured memory_bytes: 3248
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;


int main()
{
   FAST/**/
   
   ll n;
   cin>>n;
   
   string s;
   cin>>s;
   
   string s1 = "ABC";
   ll cnt = 0;
   for(ll i=0;i<n+1-3;i++)
   {
       string s2 = s.substr(i,3);
       if(s1 == s2)
            cnt++;
   }   
   
   cout<<cnt;
   
   return 0;        
}  
   

Measured memory_bytes: 256
/////////////////////////////////TEST CASES////////////////////////////////////
/*
*/
/////////////////////////////////////CODE//////////////////////////////////////		
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a ; i > b ; i--)
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll> 
#define IN(inp) ll inp;cin>>inp;
#define pb push_back
#define all(a) a.begin(),a.end()
#define FR(i,a) for(auto &i:a)
#define rvl(a,n) vl a;FOR(i,0,n){IN(in); a.pb(in);}
#define what(A) cout<<#A<<" is "<<A<<endl;
ll MAX = 100000000000;
ll MOD = 1000000007;
void solve()
{
	IN(n);
	ll cnt = 0,ans=0;
	FOR(i, 0, n)
	{
		IN(n1)IN(n2);
		if (n1 == n2)
			cnt++;
		else
		{
			ans = max(ans, cnt);
			cnt = 0;
		}
	}
	ans = max(ans, cnt);
	if (ans >= 3)
		cout << "Yes";
	else
		cout << "No";
}
int main()
{
	fastio
		//freopen("input.txt", "rt", stdin);
		//freopen("output.txt", "wt", stdout);
	ll test = 1;
	//cin >> test;
	while (test--)
	{
		solve();
	}
}

Measured memory_bytes: 3656
def orderN(N,L,ices):
    upPeak = L - ices[0]
    downPeak = L - ices[0]
    peaks = []
    for i in xrange(len(ices)):
        if i < N-1:
            if ices[i] < ices[i+1]:
                peaks.append(downPeak)
                downPeak = L - ices[i+1]
                upPeak += L - ices[i+1]
            else:
                peaks.append(upPeak)
                upPeak = L - ices[i+1]
                downPeak += L - ices[i+1]
        else:
            peaks.append(upPeak)
            peaks.append(downPeak)
    print(max(peaks))

N,L = map(int,raw_input().strip().split())
ices = [int(raw_input().strip()) for _ in xrange(N)]

orderN(N,L,ices)

Measured memory_bytes: 12496
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;

typedef pair<int, int> pii;

#define fst first
#define scd second
#define rep(i,x) for(int i=0;i<(x);++i)

template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

const int inf = 1e9;

int k[150];
vector<pii> stone[150];
int N, M;

int memo[150][150][10];

int rec(int n, int m, int i)
{
	if (n >= N - 1) return 0;

	if (~memo[n][m][i]) return memo[n][m][i];

	int res = inf;

	rep(j, k[n + 1]) {
		int dist = (stone[n][i].scd + stone[n + 1][j].scd) * abs(stone[n][i].fst - stone[n + 1][j].fst);
		chmin(res, dist + rec(n + 1, m, j));
	}

	if (m < M) {
		if (n + 2 >= N) return 0;
		rep(j, k[n + 2]) {
			int dist = (stone[n][i].scd + stone[n + 2][j].scd) * abs(stone[n][i].fst - stone[n + 2][j].fst);
			chmin(res, dist + rec(n + 2, m + 1, j));
		}
	}

	return memo[n][m][i] = res;
}

int main()
{
	while (scanf("%d %d", &N, &M), N || M) {
		rep(i, N) {
			scanf("%d", &k[i]);

			stone[i].resize(k[i]);

			rep(j, k[i]) {
				int x, d; scanf("%d %d", &x, &d);
				stone[i][j].fst = x, stone[i][j].scd = d;
			}
		}

		int ans = inf;

		memset(memo, -1, sizeof(memo));

		rep(i, k[0]) chmin(ans, rec(0, 0, i));

		if (M > 0) rep(i, k[1]) chmin(ans, rec(1, 1, i));

		printf("%d\n", ans);
	}
}

Measured memory_bytes: 1948
#include <iostream>
using namespace std;
typedef long long int ll;

int main()
{
    ll L, R;
    cin >> L >> R;
    ll m = 2018;
    for (ll i = L; i < R; ++i) {
        for (ll j = i + 1; j <= R; ++j) {
            if (j - i >= 2019) {
                cout << 0 << endl;
                return 0;
            }
            m = min(m, (i % 2019 * j % 2019) % 2019);
        }
    }

    cout << m << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    ll N; cin >> N;
    int ans = 0;
    FOR(i, 2, 1000010) {
        int cur = 0;
        while (N % i == 0) {
            cur++;
            N /= i;
        }
        FOR(j, 1, 10000) {
            if (cur < j) break;
            ans++; cur -= j;
        }
    }
    if (N > 1) ans++;
    cout << ans << nl;
	
	return 0;
}
 


Measured memory_bytes: 3632
N, M = map(int, input().split())
A = sorted([int(i) for i in input().split()])
BC = [tuple(map(int, input().split())) for _ in range(M)]
BC.sort(key=lambda x: x[1], reverse=True)

ans = 0
j = 0
b = 0
for i in range(N):
    if j < M and A[i] < BC[j][1]:
        ans += BC[j][1]
        b += 1
        if b == BC[j][0]:
            j += 1
            b = 0
    else:
        ans += A[i]
print(ans)


Measured memory_bytes: 22492
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<list>
#include<algorithm>
#include <ctype.h>
#include<deque>
using namespace std;
using ll = long long int;

constexpr char b = 'B';
constexpr char w = 'W';
string s;
int n;
map<int, int> bnext, wnext;

int main(void) {
	cin >> s;
	n = s.size();
	ll ret = 0;
	ll bnum = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == b)
			bnum++;
		else
			ret += bnum;
	}
	cout << ret << endl;
	return 0;

}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

#define ll long long

ll N;
char buff;
bool flag = false;

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> buff;
        if(buff == 'Y') flag = true;
    }

    if(flag)
        cout << "Four" << endl;
    else
        cout << "Three" << endl;
}


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

def resolve():
    def main():
        h,w=map(int, input().split())
        alphabets=list(chr(ord('A')+i) for i in range(26))
        l=[input().split() for i in range(h)]
        for i in range(h):
            for j in range(w):
                if l[i][j]=='snuke':
                    return alphabets[j]+str(i+1)
    print(main())
resolve()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS


string s;
bool check(int l, int r){
	while(l<r){
		if(s[l] != s[r]){
			return 0;
		}
		l++;
		r--;
	}
	return 1;
}

int main(){
	fastread;
	cin>>s;
	int n = s.size();
	s = "."+s;
	if(check(1,n) && check(1,(n-1)/2) && check((n+3)/2,n)){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}


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

int main() {
  int n;
  cin >> n;
  int hn[n];
  rep(i,n){
    cin >> hn[i];
  }
  int dp[n];
  dp[0] = 0;
  dp[1] = abs(hn[1] - hn[0]);
  rep(i,n) {
    if (i > 1) {
      dp[i] = min(dp[i-1] + abs(hn[i]-hn[i-1]),
                  dp[i-2] + abs(hn[i]-hn[i-2]));
    }
  }
  cout << dp[n-1] << endl;
  
}


Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <set>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
const ll mod = 1000000007;
const ll INF = 1000000000000000;
vector<P> vec[200010], peo[200010];
ll bit[100010], num;
ll par[100010], sz[100010];
ll n, m;
map<ll, ll> mp;
map<P, ll> NP;
vector<P> road[100010];
bool flg[100010];

struct edge { ll to, cost; };
ll V;
vector<edge> G[300010];
ll d[300010];

ll root(int x) { // �f�[�^x��������؂̍����ċA�œ���Froot(x) = {x�̖؂̍�}
	if (par[x] == x) return x;
	return par[x] = root(par[x]);
}

void unite(int x, int y) { // x��y�̖؂𕹍�
	int rx = root(x); //x�̍���rx
	int ry = root(y); //y�̍���ry
	if (rx == ry) return; //x��y�̍�������(=�����؂ɂ���)���͂��̂܂�
	par[rx] = ry; //x��y�̍��������łȂ�(=�����؂ɂȂ�)���Fx�̍�rx��y�̍�ry�ɂ���
}

bool same(int x, int y) { // 2�̃f�[�^x, y��������؂������Ȃ�true��Ԃ�
	int rx = root(x);
	int ry = root(y);
	return rx == ry;
}

void dijkstra(ll s)
{
	priority_queue<P, vector<P>, greater<P>> que;
	for (int i = 0; i <= 300010; i++)
	{
		d[i] = INF;
	}
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty())
	{
		P p = que.top(); que.pop();
		ll v = p.second;
		if (d[v] < p.first) continue;
		for (ll i = 0; i < G[v].size(); i++)
		{
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= num)
	{
		bit[i] += x;
		i += i & -i;
	}
}

ll po(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return po(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = po(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll pow_mod(ll x, ll y)
{
	ll res = 1;
	while (y > 0)
	{
		if (y % 2 == 1)
		{
			(res *= x) %= mod;
		}
		(x *= x) %= mod;
		y /= 2;
	}
	return res;
}

ll div(ll x)
{
	return po(x, mod - 2);
}

void dfs(ll x, ll y)
{
	flg[y] = true;
	for (int i = 0; i < road[y].size(); i++)
	{
		if (flg[road[y][i].first]) continue;
		dfs(y, road[y][i].first);
	}
	if (mp[y] % 2 == 1)
	{
		if (NP[P(x, y)] == 1)
		{
			NP[P(x, y)] = 2;
			NP[P(y, x)] = 1;
		}
		else
		{
			NP[P(x, y)] = 1;
			NP[P(y, x)] = 2;
		}
		mp[x]++;
		mp[y]++;
	}
}

int main(void)
{
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		ll a, b;
		cin >> a >> b;
		road[a].push_back(P(b, 1));
		road[b].push_back(P(a, 0));
		NP[P(a, b)] = 1;
		NP[P(b, a)] = 2;
		mp[a]++;
	}
	ll cnt = 0;
	for (auto itr = mp.begin(); itr != mp.end(); ++itr)
	{
		if (itr->second % 2 == 1)
		{
			cnt++;
		}
	}
	if (cnt % 2 == 0)
	{
		flg[1] = true;
		for (int i = 0; i < road[1].size(); i++)
		{
			flg[road[1][i].first] = true;
		}
		for (int i = 0; i < road[1].size(); i++)
		{
			dfs(1, road[1][i].first);
		}
		for (int i = 1; i <= n; i++)
		{
			for (int j = 0; j < road[i].size(); j++)
			{
				if (NP[P(i, road[i][j].first)] == 1)
				{
					cout << i << ' ' << road[i][j].first << endl;
				}
			}
		}
	}
	else
	{
		cout << -1 << endl;
	}
	int www;
	cin >> www;
}


Measured memory_bytes: 55680
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const int MOD = 1e9 + 7;



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

	vector<int> v;
	v.push_back(1);

	int temp_6=6;
	while (temp_6 <= n) {
		v.push_back(temp_6);
		temp_6 *= 6;
	}

	int temp_9 = 9;
	while (temp_9 <= n){
		v.push_back(temp_9);
		temp_9 *= 9;
	}
	int INF = 101010;

	//n円引き出す引き出し回数の最小値
	vector<int> dp(n+1);
	dp[0] = 0;

	rep(i,1,n+1) {
		int temp = INF;
		rep(j,0,v.size()) {
			if (i - v[j] >= 0) {
				temp = min(temp, dp[i - v[j]]);
			}
		}
		dp[i] = temp+1;
	}

	cout << dp[n] << endl;
	return 0;

}

Measured memory_bytes: 640
# coding: utf-8
# coding: Shift_JIS
# coding: EUC-JP
# coding: cp932
import math

while 1:
    m,f,r = map(int,input().split())
    if(m+f+r == -3):
        break
    if m == -1 or f == -1 or m+f < 30:
        print("F")
    else:
        sum = m + f
        if sum >= 80:
            print("A")
        elif sum >= 65:
            print("B")
        elif sum >= 50 or r >= 50:
            print("C")
        else:
            print("D")



Measured memory_bytes: 5660
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/*abc 134 B*/

int main(void)
{
  int N, D;
  int array[10][10] = {0};
  int count = 0;
  int length = 0;
  int sqrtNumber;

  scanf("%d%d", &N, &D);
  for (size_t i = 0; i < N; i++) {
    for (size_t j = 0; j < D; j++) {
      scanf("%d", &array[i][j]);
    }
  }
  /*長さチェック　平方数ならばcount++;*/
  for (size_t i = 0; i < N-1; i++) {
    for (size_t k = i+1; k < N; k++) {
      for (size_t j = 0; j < D; j++) {
          length += (array[i][j] - array[k][j])*(array[i][j] - array[k][j]);
        }
        sqrtNumber = (int)sqrt((double)length);
        if (length == sqrtNumber * sqrtNumber) count++;
        length = 0;
        sqrtNumber = 0;
    }
  }
  printf("%d\n", count);

  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#define MAX 100000
 
 typedef struct{
  int parent;
  int left;
  int right;
}Node;

Node Tree[MAX];

int getDepth(int i){
  int depth=0;
 
  while(Tree[i].parent!=-1){
    i=Tree[i].parent;
    depth++;
  }
  
  return depth;
}

int getSibling(int i){
  int t=Tree[i].parent;
  
  if(t==-1) return -1;
  if(Tree[t].left!=i && Tree[t].left!=-1) return Tree[t].left;
  if(Tree[t].right!=i && Tree[t].right!=-1) return Tree[t].right;
  
  return -1;
}

int getHeight(int i){
  int leftHeight=0,rightheight=0;
  
  if(Tree[i].left!=-1) leftHeight=getHeight(Tree[i].left)+1;
  if(Tree[i].right!=-1) rightheight=getHeight(Tree[i].right)+1;
  
  if(leftHeight>rightheight) return leftHeight;
  else return rightheight;
}

void print(int i){
  int degree=0;
  printf("node %d: parent = %d, ",i,Tree[i].parent);
  printf("sibling = %d, ",getSibling(i));
  
  degree = 0;
  if(Tree[i].left!=-1) degree++;
  if(Tree[i].right!=-1) degree++;
  
  printf("degree = %d, ", degree);
  printf("depth = %d, ", getDepth(i));
  printf("height = %d, ", getHeight(i));
  
  if(Tree[i].parent==-1) printf("root");
  else if(Tree[i].left==-1 && Tree[i].right==-1) printf("leaf");
  else printf("internal node");
  
  printf("\n");
}

int main(){
  
  int n,i,id,left,right,root;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++)
    Tree[i].parent = -1;
  
  for(i=0;i<n;i++){
    scanf("%d %d %d", &id, &left, &right);
    Tree[id].left=left;
    Tree[id].right=right;
  
    if(left != -1) Tree[left].parent=id;
    if(right != -1) Tree[right].parent=id;
  }
  
  for(i=0;i<n;i++)
    if(Tree[i].parent==-1) root=i;
  
  getHeight(root);
  
  for(i=0;i<n;i++)
    print(i);
 
  return 0;
}

Measured memory_bytes: 2732
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int N;
  int k[100];
  while(cin >> N && N){
    REP(i, N) cin >> k[i];
    string s;
    cin >> s;
    char cs[52];
    REP(i, 26) cs[i] = 'a' + i;
    REP(i, 26) cs[i + 26] = 'A' + i;
    string t = s;
    REP(i, s.size()){
      int idx;
      REP(j, 52) if(s[i] == cs[j]) idx = j;
      t[i] = cs[ (idx - k[i % N] + 52) % 52];
    }
    cout << t << endl;
  }
  return 0;
}

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

int a[9] = {111,222,333,444,555,666,777,888,999};

int main() {
  int n;
  cin >> n;
  int ans = 0;
  rep(i,8){
    if(n<=111) ans = 111;
    if(a[i]<n && n <= a[i+1]) ans = a[i+1];
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 2e5 + 5;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
 
int fac[MAX_N], inv[MAX_N];
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b, bool usemod = true) {ll c = 1LL; while (b > 0) {if (b & 1LL) {if(!usemod)c*=a;else c = a * c%mod;}if (!usemod) a*=a;else a = a * a%mod; b >>= 1LL;}return c;}
void _nCr() {fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) {fac[i] = fac[i - 1LL] * i%mod;}for (int i = 0; i < MAX_N; i++) {inv[i] = POW(fac[i], mod - 2);}}
ll nCr(ll n, ll r) {return (fac[n] * inv[r] % mod)*inv[n - r] % mod;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}


bool solve() {
	int n; cin >> n;
	int a[n]; REP (i,n) cin >> a[i];
	int cand[n]; cand[0] = 0;
	FOR (i,0,n-1) {
		cand[i+1] = a[i] - cand[i];
	}
	int dif = a[n-1]-cand[n-1];
	dif /= 2;
	REP (i,n) {
		if (i % 2 == 0) {
			cand[i] += dif;
		} else {
			cand[i] -= dif;
		}
	}
	REP (i,n) {
		cout << cand[i] * 2 << " ";
	} cout << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}

Measured memory_bytes: 2944
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

class Main {
	static List<Integer> list = new ArrayList<Integer>();
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		while (n != 0) {
			list.clear();
			Collections.addAll(list, scan.nextInt(),scan.nextInt(),scan.nextInt());
			list.sort(Comparator.reverseOrder());
			if ((list.get(0) * list.get(0)) == ((list.get(1) * list.get(1)) + (list.get(2) * list.get(2)))) {
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
			n--;
		}
	}
}

Measured memory_bytes: 33120