akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int pop();
void push(int);
int Stack[200],top;

int pop(){
  top--;
  return Stack[top+1];
}
void push(int x){
  Stack[++top] = x;
}


main()
{
  int x,a,b;
  char s[100];
  top = 0;
  while(scanf("%s", s) != EOF)
    {
      if(s[0] == '+')
	{
	  a = pop();
	  b = pop();
	  push(a+b);
	}
      else if(s[0] == '-')
	{
	  b = pop();
	  a = pop();
	  push(a-b);
	}
      else if(s[0] == '*')
	{
	  a = pop();
	  b = pop();
	  push(a*b);
	}
      else
	{
	  x = atoi(s);
	  push(x);
	}
    }
  printf("%d\n", pop());
  return 0;
}

Measured memory_bytes: 548
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			int n=in.nextInt();
			int a[]=new int[n];
			ArrayList<Integer>AL=new ArrayList<Integer>();
			ArrayList<Integer>AL2=new ArrayList<Integer>();
			for(int i=0;i<n;i++)
				a[i]=in.nextInt();
			Arrays.sort(a);
			for(int i=0;i<a.length;i++)
			{
				AL.add(a[i]);
				if(i==3)
					break;
			}
			for(int i=0;i<AL.size();i++)
				for(int j=0;j<AL.size();j++)
				{
					if(i==j)
						continue;
					AL2.add(Integer.valueOf(AL.get(i)+""+AL.get(j)));
				}
			Collections.sort(AL2);
			System.out.println(AL2.get(2));
		}
	}
	
	static public void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 30092
function main(lines) {
  const x = +lines[0];

  const ans = x >= 30 ? 'Yes' : 'No';
  
  return ans;
}


const ans = main( require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n") );
console.log( ans );

function splitN(s) {
  return s.split(' ').map(Number);
}


Measured memory_bytes: 29668
#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;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }

int dp[305][305];
int cost[305][305];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int h, w;
  cin >> h >> w;
  char c[h][w];
  rep(i, h) rep(j, w) cin >> c[i][j];
  int ans = 0;
  rep(i, w - 1) {
    rep(j, h + 1) rep(k, h + 1) dp[j][k] = inf;
    dp[0][0] = 0;
    memset(cost, 0, sizeof(cost));
    repr(j, h - 1) {
      repr(k, h - 1) {
        cost[j][k] = cost[j + 1][k + 1] + (c[h - 1 - j][i] == c[h - 1 - k][i + 1]);
      }
    }
    rep(j, h + 1) {
      rep(k, h + 1) {
        if (j) chmin(dp[j][k], dp[j - 1][k] + cost[j - 1][k]); 
        if (k) chmin(dp[j][k], dp[j][k - 1] + cost[j][k - 1]);
      }
    }
    ans += dp[h][h];
  }
  cout << ans << '\n';




  




  
  return 0;
}

Measured memory_bytes: 4416
h,w,d=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
q=int(input())
lr=[list(map(int,input().split())) for _ in range(q)]

x=[[] for _ in range(h*w)]
for i in range(h):
    for j in range(w):
        x[a[i][j]-1]=[i,j]
z=[0 for _ in range(h*w)]
for i in range(d):
    for j in range(i+d,h*w,d):
        z[j]=z[j-d]+abs(x[j][0]-x[j-d][0])+abs(x[j][1]-x[j-d][1])
#print(x)
#print(z)
for t in lr:
    print(z[t[1]-1]-z[t[0]-1])

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

using namespace std;

int n, ans, h[(int)1e5];

int main(){
	cin >> n;
	for(int i = 0; i < n; ++i) cin >> h[i];
	
	int count = 0;
	for(int i = 0; i < n - 1; ++i){
		if(h[i] >= h[i+1]){
			count++;
			ans = max(ans, count);
		}else{
			count = 0;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define ssort(a) sort(a.begin(), a.end())
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  ll maxp=-INFll, minp=INFll, maxn=-INFll, minn=INFll;
  rep(i, n){
    ll x, y;
    cin >> x >> y;
    maxp=max(maxp, x+y);
    minp=min(minp, x+y);
    maxn=max(maxn, x-y);
    minn=min(minn, x-y);
  }
  ll ans=max(maxp-minp, maxn-minn);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
import java.io.*;
import java.util.StringTokenizer;

public class Main{

    static int n;
    static int m;
    static int L[][] = new int[m+1][n+1];
    static StringBuilder str = new StringBuilder("");
    static int[][] dp;
    static char[] X;
    static char[] Y;

    static void lcs() {

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

                if (i==0 || j==0)
                    dp[i][j]=0;
                else if (X[i-1]==Y[j-1])
                    dp[i][j]=dp[i-1][j-1]+1;
                else
                    dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]);
            }
        }

    }
    static void trace(){
        int i = m;
        int j = n;

        while (i>0&&j>0){

            if (X[i-1]==Y[j-1]){
                str.append(X[i-1]);
                i--;
                j--;
            }else {
                if (dp[i-1][j]>dp[i][j-1])
                    i--;
                else
                    j--;
            }
        }
    }

    public static void main(String[] args) throws IOException {
        Scanner scan = new Scanner(System.in);
        String s1 = scan.next();
        String s2 = scan.next();
        n=s2.length();
        m=s1.length();
        dp=new int[m+1][n+1];
        X=s1.toCharArray();
        Y=s2.toCharArray();

        lcs();
        trace();

        System.out.println(str.reverse());
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(String file) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(file));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }

}



Measured memory_bytes: 76148
#include <iostream>
#include <string>

using namespace std;

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

    for (int k = 0; k <= n; k++) {
        bool match = true;
        for (int i = k; i < n; i++) {
            if (s[i] != t[i - k]) {
                match = false;
                break;
            }
        }
        if (match) {
            cout << n + k << endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	map<string,int> m;
	map<string,vector<string> > l;
	vector<string> str;
	int n,v,t;
	string s,u;
	for(;;){
		cin >> n;
		if(!n)break;
		m.clear();
		l.clear();
		while(n--){
			cin >> s >> v;
			m[s]=v;
		}
		cin >> n;
		while(n--){
			cin >> s >> t;
			str.push_back(s);
			while(t--){
				cin >> u;
				l[s].push_back(u);
			}
		}
		t=1;
		while(t){
			t=0;
			rep(i,str.size()){
				v=0;
				rep(j,l[str[i]].size())v += m[l[str[i]][j]];
				if(m[str[i]]>v){
					m[str[i]]=v;
					t=1;
				}
			}
		}
		cin >> s;
		cout << m[s] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll long long
#define int long long
#define pb push_back
#define x first
#define ld long double
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) a.begin(),a.end()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
vector <int> t;
inline void upd (int i, int x) {
    for (; i < (int)t.size(); i = i | (i + 1)) t[i] += x;
}
inline int sum (int r) {
    int ans = 0;
    for (; r >= 0; r = (r & (r + 1)) - 1) ans += t[r];
    return ans;
}
inline int sum (int l, int r) {
    return sum(r) - sum(l - 1);
}
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, q;
    cin >> n >> q;
    vector <int> a(n);
    for (auto &i : a) cin >> i;
    vector <vector <pair<int, int> > > Q(n);
    int l, r;
    for (int i = 0; i < q; i++) {
        cin >> l >> r;
        --l, --r;
        Q[r].pb({l, i});
    }
    t.resize(n);
    map <int, int> have;
    vector <int> ans(q);
    for (int i = 0; i < n; i++) {
        if (have.count(a[i])) {
            upd(have[a[i]], -1);
        }
        have[a[i]] = i;
        upd(i, 1);
        for (auto &j : Q[i]) {
            ans[j.y] = sum(j.x, i);
        }
    }
    for (auto &i : ans) cout << i << '\n';
}


Measured memory_bytes: 71592
import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        for(int i=0; i<s.length(); i++){
            for(int j=0; j<s.length(); j++){
                if(s.charAt(i)==s.charAt(j) && i!=j){
                    System.out.println("no");
                    return;
                }
            }
        }
        System.out.println("yes");
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
// #define INPUT_OUTPUT { \
//     freopen("input.txt","r",stdin); \
//     freopen("output.txt","w",stdout); \
// }
void solve() {
    int n , ans = 0;
    cin >> n ; 
    if(n < 5) {
        cout << 0 ;
        return ;
    }
    if(n >= 5) {
        if(n>=500) {
             while(n >= 500) {
                n = n - 500 ;
                ans = ans + 1000 ;
             }
        }
        if(n < 500 and n >= 5){
            while(n > 5) {
                n = n - 5 ;
                ans = ans + 5 ;
            }
        }
        cout << ans ;
    }
}
int main(){
    // INPUT_OUTPUT ;
    int t=1 ;
    //cin >> t ;
    while(t--) solve() ;
    return 0 ;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <new>

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
typedef long long ll;
using namespace std;

// 桁数を数える
int digit_length( int num )
{
    int count = 0;
    while( num ) {
        num = num / 10;
        ++count;
    }
    return count;
}

// 各桁を配列要素に分解 その先頭ポインタを返す
int* slice_digit( int num )
{
    int mod = 0;
    int *parts = NULL;

    try {
        parts = new int[ digit_length( num ) ];
    }
    catch( bad_alloc ba ) {
        exit(EXIT_FAILURE);
    }
    catch(...) {
        cout << "something went wrong\n";
    }

    int i = 0;
    while( num >= 1 )   {
        mod = num % 10; // 一の位の余り
        num = num / 10; // 取得済みの余りを"num"から除去
        parts[i++] = mod;
    }
    return parts;
}


void solve(long long N){
    // ここをユーザスニペットにしていく
    vector<vector<int> > c(9+1, vector<int>(9+1));
    REP(i, 9+1) REP(j, 9+1) c[i][j] = 0;


    FOR(i, 1, N) {
        // 数値を文字列に変換する
        string str = to_string(i);
        // cout << str[i] < <endl;
        int* digits = slice_digit(i);
        int d_len = digit_length(i);
        int idx_i = digits[0];
        int idx_j = digits[d_len-1];
        c[idx_i][idx_j]++;
    }

    long long res = 0;
    FOR(i, 1, 9) {
        FOR(j, 1, 9) {
            res += c[i][j] * c[j][i];
        }
    }
    cout << res  << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
const long long INF = 1000000000000000000LL;
using namespace std;

int main() {
  int n, d;
  cin >> n >> d;
  vector<long long> t(n + 2), f(n + 2, 1);
  rep(i, n) cin >> t[i + 1] >> f[i + 1];
  rep(i, f.size()) f[i]--;
  t[n + 1] = INF;
  long long sumTime = 0LL, person = 0LL;
  rep(i, n + 1) {
    long long diffT = t[i + 1] - t[i], diffF = abs(f[i + 1] - f[i]);
    if (f[i + 1] + f[i] <= diffT) {
      sumTime += person * f[i];
      person = 1LL;
      continue;
    }
    if (diffF <= diffT && person < d) {
      sumTime += person * diffT;
      person++;
      continue;
    }
    goto IMPOSSIBLE;
  }
  cout << sumTime << endl;
  return 0;
IMPOSSIBLE:
  cout << -1 << endl;
}

Measured memory_bytes: 4396
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    set<string> st;
    rep(i, N) {
        string S; cin >> S;
        st.insert(S);
    }
    cout << st.size() << endl;

    return 0;
}


Measured memory_bytes: 19200
from collections import deque
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


V = int(input())

table = [['0']*V for i in range(V)]

for loop in range(V):
    tmp_array = list(map(int,input().split()))
    node_id = tmp_array[0]-1
    for i in range(tmp_array[1]):
        table[node_id][tmp_array[2+i]-1] = '1'

for row in range(V):
    print(' '.join(table[row]))




Measured memory_bytes: 6448
#include <iostream>
  #include <complex>
  #include <vector>
  #include <string>
  #include <algorithm>
  #include <cstdio>
  #include <numeric>
  #include <cstring>
  #include <ctime>
  #include <cstdlib>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <list>
  #include <cmath>
  #include <bitset>
  #include <cassert>
  #include <queue>
  #include <stack>
  #include <deque>
 #include <iomanip>
#include <fstream>
 
  using namespace std;
   
 
//abcdefghijklmnopqrstuvwxyz
//ABCDEFGHIJKLMNOPQRSTUVWXYZ

  typedef long long ll;
  typedef long double lld;
  typedef unsigned long long ull;
  ll INF = INT_MAX;
  // ll mod = 1000000007;
  // lld PI = 3.141592653;
 int n,m,k;
vector<vector<int> > good, bad;
vector<bool> visited;
 vector<set<int> > a;


void dfs(int v, int now){
  a[now].insert(v);
  visited[v] = true;
  for (int i = 0;i<good[v].size();i++){
    int u = good[v][i];
    if (!visited[u]){
      
      dfs(u, now);
    }
  }

}

  int main()
  {
      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
      // ifstream cin("input.txt");
      
      
      cin>>n>>m>>k;
      vector<int> h;
      good = vector<vector<int> > (n+1, h);
      bad = vector<vector<int> > (n+1, h);
      visited = vector<bool> (n+1);
      for (int tt = 0;tt<m;tt++){
        int x,y;
        cin>>x>>y;
        good[x].push_back(y);
        good[y].push_back(x);
      }
       for (int tt = 0;tt<k;tt++){
        int x,y;
        cin>>x>>y;
        bad[x].push_back(y);
        bad[y].push_back(x);
      }
      int now = 0;
      set<int> hh;
      for (int i = 1;i<=n;i++){
        if (!visited[i]){
          a.push_back(hh);
          dfs(i, now);
          now++;
        }
      }
      // for (int i = 0;i<a.size();i++){
      //     set<int>::iterator s = a[i].begin();
      //     while(s!=a[i].end()){
      //       cout<<*s<<" ";
      //       s++;
      //     }
      //     cout<<endl;
      // }
      vector<int> ans(n+1);
      set<int>::iterator it;
      for (int j = 0;j<a.size();j++){
        it = a[j].begin();
        
        
        while(it!=a[j].end()){
          int v = *it;
          int cnt = 0;
          for (int p = 0;p<good[v].size();p++) if(a[j].count(good[v][p])) cnt++;
            for (int p = 0;p<bad[v].size();p++) if(a[j].count(bad[v][p])) cnt++;
              ans[v] = a[j].size()-1-cnt;
            it++;
        }
      }
     
      for (int i = 1;i<=n;i++) cout<<ans[i]<<" ";
      cout<<"\n";


}

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

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

    int N;

    cin >> N;

    vector<int> C(N - 1);
    vector<int> S(N - 1);
    vector<int> F(N - 1);

    for(int i = 0; i < N - 1; i++) cin >> C[i] >> S[i] >> F[i];

    vector<int> A(N);

    for(int i = N - 2; i >= 0; i--) {
        int ans = S[i] + C[i];
        for(int j = i + 1; j < N - 1; j++) {
            if(ans <= S[j]) {
                ans = A[j];
                break;
            }
            if(ans % F[j] == 0) {
                ans += C[j];
            } else {
                ans += F[j] - ans % F[j] + C[j];
            }
        }
        A[i] = ans;
    }

    for(int i = 0; i < N; i++) cout << A[i] << endl;
}

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

int main(){
    int A,B;
    cin >> A >> B;
    if(A%3==0||B%3==0||(A+B)%3==0){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int ans=0;
  if(n==0)
  {
    cout<<1;
    return 0;
  }
  while(n)
  {
    ans++;
    n/=k;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct Node{
    int val;
    struct Node* next;
} Node;

typedef struct Graph{
    Node** tree;   
} Graph;

Node* newNode(int val){
    Node* newNode = (Node*) malloc(sizeof(Node));
    newNode->val = val;
    newNode->next = NULL;
    return newNode;
}

Graph* newGraph(int graphSize){
    Graph* G = (Graph*) malloc(sizeof(Graph));
    G->tree = (Node**) malloc(graphSize*sizeof(Node*));
    
    for(int i=0; i<graphSize; i++)
        G->tree[i] = newNode(i);  
    return G;
}

void DFS_preorder(Graph* G, int graphSize, int root){
    Node* temp = G->tree[root];
    printf(" %d",root);

    if(temp->next->val != -1)
        DFS_preorder(G,graphSize,temp->next->val);
    temp = temp->next;
    if(temp->next->val != -1)
        DFS_preorder(G,graphSize,temp->next->val);
}

void DFS_inorder(Graph* G, int graphSize, int root){
    Node* temp = G->tree[root];

    if(temp->next->val != -1)
        DFS_inorder(G,graphSize,temp->next->val);
    printf(" %d",root);
    temp = temp->next;
    if(temp->next->val != -1)
        DFS_inorder(G,graphSize,temp->next->val);
}

void DFS_postorder(Graph* G, int graphSize, int root){
    Node* temp = G->tree[root];

    if(temp->next->val != -1)
        DFS_postorder(G,graphSize,temp->next->val);
    temp = temp->next;
    if(temp->next->val != -1)
        DFS_postorder(G,graphSize,temp->next->val);
    printf(" %d",root);
}

int findRoot(Graph* G, int graphSize){
    for(int i=0; i<graphSize; i++){
        bool b = 0;
        for(int j=0; j<graphSize; j++){
            if(j!=i){
                Node* tmp = G->tree[j];
                while(tmp->next !=NULL){
                    tmp = tmp -> next;
                    if(tmp->val == i){
                        b = 1;
                        break;
                    }
                }
            }
        }
        if(b == 0) return i;
    }
}

int main(){
    int n;
    scanf("%d",&n);
    Graph* G = newGraph(n);

    // Input the other vertices into the graph
    for(int i=0; i<n; i++){
        int order;
        scanf("%d",&order);

        Node* temp = G->tree[order];
        for(int j=0; j<2; j++){
            int tmp;
            scanf("%d",&tmp);

            Node* N = newNode(tmp);
            temp->next = N;
            temp = N;
        }
    }
    int root = findRoot(G,n);
    G->tree[root]->val = root;
    
    printf("Preorder\n");
    DFS_preorder(G,n,root);
    printf("\nInorder\n");
    DFS_inorder(G,n,root);
    printf("\nPostorder\n");
    DFS_postorder(G,n,root);
    printf("\n");

    return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
typedef long long ll;
const int INF = 1e9+1;
const int MOD = 2e9 + 9;
const ll LINF = 1e18;
using namespace std;

int two(int n) {
	int cnt = 0;
	int m = n;
	for (int i = 0; i < m; i++) {
		if (n % 2 == 0) {
			cnt++;
			n = n / 2;
		}
		else return cnt;
		
	}
	return cnt;
}
int main() {
	int n;
	cin >> n;
	vector<int> a(n),b(n);
	for (int i = 0; i < n; i++)cin >> a.at(i);
	
	for (int i = 0; i < n; i++) {
		b.at(i) = two(a.at(i));
	}
	sort(b.begin(), b.end());
	cout << b.at(0) << endl;
	return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>
int main(void)
{
	long long n,k,a,b,x[100001]={0},i;
	scanf("%lld %lld", &n, &k);
	for(i=0; i<n; i++)
	{
		scanf("%lld %lld", &a, &b);
		x[a]+=b;
	}
	a=0;
	for(i=1; i<100001; i++)
	{
		a+=x[i];
		if(a>=k)
		{
			printf("%lld\n", i);
			break;
		}
	}
	
	return 0;
}

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

public class Main {

    public static void main(String[] args) {
	Main m = new Main();
	m.answer();
    }

    private Scanner scan = new Scanner(System.in);
    private final int N;
    private final int[] A;

    public Main() {
	N = Integer.parseInt(scan.next());
	A = new int[N];
	
	for (int i = 0; i < N; i++) {
	    A[i] = Integer.parseInt(scan.next());
	}

	scan.close();
    }

    public final void answer() {
	Arrays.sort(A);

	int h = 0;
	int w = 0;
	for (int i = N-1; i > 0; i--) {
	    if(A[i] == A[i-1]) {
		if(h == 0) {
		    h = A[i];
		    i--;
		} else if(w == 0) {
		    w = A[i];
		    break;
		}
	    }
	}
	System.out.println((long)h * w);
    }
}


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

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll n,ans,v[6];
    string s;
    while(cin >> n)
    {
        memset(v, 0, sizeof v);
        for(int i = 0; i < n; i++)
        {
            cin >> s;
            if(s[0] == 'M')
                v[0]++;
            else if(s[0] == 'A')
                v[1]++;
            else if(s[0] == 'R')
                v[2]++;
            else if(s[0] == 'C')
                v[3]++;
            else if(s[0] == 'H')
                v[4]++;
        }
        ans = 0;
        for(int mask = 1; mask < (1 << 5); mask++)
            if(__builtin_popcount(mask) == 3)
            {
                ll prod = 1;
                for(int i = 0; i < 5; i++)
                    if(mask & (1 << i))
                        prod *= v[i];
                ans += prod;
            }
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A.sort()

n = N // 2
c = N - 1
for _ in range(n):
  a, b = A.pop(), A.pop()
  if (a != c) or (b != c):
    print(0)
    exit()
  c -= 2
      
if N % 2 == 1 and A[0] != 0:
    print(0)
    exit()
  
print(pow(2, n, (10**9 + 7)))

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

using namespace std;

int a[3];
int main(){
    cin >> a[0] >>a[1] >>a[2];
    int ans=0;
    sort(a,a+3);
    int b =a[0];
    for(int i=1;i<3;i++){
        ans += a[i]-b;
        b=a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		while (true) {
			String[] lines = sc.nextLine().split(" ");
			int height = Integer.parseInt(lines[0]);
			int width = Integer.parseInt(lines[1]);

			if(height == 0 && width == 0) {
				break;
			} else {
				for(int i = 0;i <width;i++) {
					System.out.print("#");
				}
				System.out.println();
				//height??????????¨?????????¨?????????
				for(int i = 1;i < height - 1;i++) {
					for(int j = 0;j < width;j++) {
						if(j == 0 || j == width - 1) {
						System.out.print("#");
						} else {
							System.out.print(".");
						}
					}
					System.out.println();
				}
				for(int i = 0;i <width;i++) {
					System.out.print("#");
				}
				System.out.println("\n");
			}

		}
		sc.close();
	}
}

Measured memory_bytes: 37044
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
using namespace std;
unsigned long long int gcd(unsigned long long int x, unsigned long long int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(x % y, y);
}
int main() {
	int N;
	cin >> N;
	unsigned long long int T,ans=1;
	for (int i = 0; i < N; i++)
	{
		cin >> T;
		ans = ans / gcd(ans, T)* T ;
	}
	cout << ans;
}


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

typedef long long ll;
const int MAXN = 1e5 + 10;
multiset<pair<ll, ll> > S;
vector<ll> A;
ll n, m, sum[MAXN];

int main() {
	cin >> n >> m;
	A.push_back(n);
	for (int i = 0; i < m; i++) {
		ll a;
		cin >> a;
		while (!A.empty() && A.back() >= a)
			A.pop_back();
		A.push_back(a);
	}
	S.insert({ A.back(), 1 });
	A.pop_back();
	while (!A.empty()) {
		ll alph = A.back();
		pair<ll, ll> C = { alph, 0 };
		while (S.lower_bound({ alph + 1, 0 }) != S.end()) {
			set<pair<ll, ll> >::iterator it = S.lower_bound({ alph + 1, 0 });
			pair<ll, ll> t = *it;
			S.erase(it);
			C.second += (t.first / alph) * t.second;
			pair<ll, ll> nw = { t.first % alph, t.second };
			if (nw.first != 0 && nw.second > 0)
				S.insert(nw);
		}
		if (C.second > 0)
			S.insert(C);
		A.pop_back();
	}
	for (pair<ll, ll> a : S)
		sum[a.first] += a.second;
	for (int i = MAXN - 2; i >= 0; i--)
		sum[i] += sum[i + 1];
	for (int i = 1; i <= n; i++)
		cout << sum[i] << '\n';
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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 long long INF = 1LL << 60;

int main(){
  int N, T;
  cin >> N >> T;

  int start = 0;
  int stop = 0;
  int sum = 0;
  rep(i, N){
    int t;
    cin >> t;
    if(t > stop){
      sum += stop - start;
      start = t;
    }
    stop = t + T;
  }
  sum += stop -start;

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include <climits>

int main()
{
    int a;
    std::string b;
    std::cin>> a;
    std::cin>> b;

    if( 3200 <= a )
    {
        std::cout<< b;
    }
    else
    {
        std::cout<< "red";
    }
    
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int x;
    cin>>x;
    bool dp[x+1];
    for(int i=0;i<=x;i++)dp[i]=false;
    dp[0]=true;
    for(int i=0;i<x;i++){
        if(dp[i]){
            for(int j=0;j<=5;j++){
                if(i+100+j<=x)dp[i+100+j]=true;
            }
        }
    }
    cout<<dp[x]<<endl;
    return 0;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
"""
Created on Sat Apr  6 21:22:08 2019

@author: Tabe
"""

pos = list()
for i in range(5):
    pos.append(int(input()))

k = int(input())
hh = False

for index, val in  enumerate(pos):
    if hh == True:
        break;
    
    if index == 4:
        print("Yay!")
        break
    
    for i in  range(5):
        if abs(pos[index] - pos[i]) <= k:
            pass
        else:
            print(":(")
            hh = True
            break





Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = n;
        for(int a = 2; a <= n/2; a++) {
            int b = n - a;
            int sum = digit(a) + digit(b);
            ans = Math.min(sum,ans);
        }
        System.out.println(ans);
    }
    
    static int digit(int num) {
        int r = 0;
        while(true) {
            r += (num%10);
            num /= 10;
            if(num == 0) break;
        }
        return r;
    }
}

Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;

int checkBloodType(string str);

int main()
{
    string in_str;
    int num[4] = {};
    while(getline(cin, in_str))
    {
        istringstream stream(in_str);
        string field;
        vector<string> in_data;
        while (std::getline(stream, field, ',')) 
        {
            in_data.push_back(field);
        }
        num[checkBloodType(in_data[1])]++;
    }
    for(int i=0; i<4; i++)
    {
        cout << num[i] << endl;
    }
    return 0;
}

int checkBloodType(string str)
{
    int index = 0;

    if(str == "A")
    {
        index = 0;
    }
    else if(str == "B")
    {
        index = 1;
    }
    else if(str == "AB")
    {
        index = 2;
    }
    else if(str == "O")
    {
        index = 3;
    }
    else
    {
        /* Nop */
    }
    return index;
}



Measured memory_bytes: 3140
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
  
using namespace std;

#define pi 3.141592653589793

int Winner(int t, string c[4][13], int n, char s)
{
	int maxnum = 0;
	bool istheretrump = false;
	int ans;
	for(int i = 0; i < 4; i++){
		int rank;
		if(c[i][n][0] == 'T') rank = 10;
		else if(c[i][n][0] == 'J') rank = 11;
		else if(c[i][n][0] == 'Q') rank = 12;
		else if(c[i][n][0] == 'K') rank = 13;
		else if(c[i][n][0] == 'A') rank = 14;
		else rank = c[i][n][0] - '0';
		if(c[i][n][1] == t){
			if(!istheretrump){
				maxnum = rank;
				ans = i;
				istheretrump = true;
			} else if(rank > maxnum){
				maxnum = rank;
				ans = i;
			}			
		} else if(!istheretrump && c[i][n][1] == s && rank > maxnum){
			maxnum = rank;
			ans = i;
		}
	}
	// cout << ans << endl;
	return ans;
}

int main()
{
	char trump;
	string card[4][13];
	while(1){
		cin >> trump;
		if(trump == '#') break;
		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 13; j++){
				cin >> card[i][j];
			}
		}
		int score[4] = {};
		char suit = card[0][0][1];
		for(int i = 0; i < 13; i++){
			int w = Winner(trump, card, i, suit);
			score[w]++;
			if(i != 12) suit = card[w][i + 1][1];
		}
		int ns = score[0] + score[2], ew = score[1] + score[3];
		if(ns > ew){
			cout << "NS" << " " << ns - 6 << endl;
		} else {
			cout << "EW" << " " << ew - 6 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1188
#include<stdio.h>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std ;

typedef struct pair<double,int> Pid ;
#define F first
#define S second

vector<Pid> V1 ;
vector<Pid> V2 ;
vector<Pid> V3 ;
vector<Pid> V4 ;

int main(){
	
	int x ;
	double t ;
	for( int i=0 ; i<8 ; i++ ){
		cin >> x >> t ;
		V1.push_back( Pid(t,x) ) ;
	};
	for( int i=0 ; i<8 ; i++ ){
		cin >> x >> t ;
		V2.push_back( Pid(t,x) ) ;
	}
	for( int i=0 ; i<8 ; i++ ){
		cin >> x >> t ;
		V3.push_back( Pid(t,x) ) ;
	}
	
	sort( V1.begin() , V1.end() ) ;
	sort( V2.begin() , V2.end() ) ;
	sort( V3.begin() , V3.end() ) ;
	
	for( int i=2 ; i<8 ; i++ ){
		t = V1[i].F ; x = V1[i].S ;
		V4.push_back( Pid(t,x) ) ;
	}
	for( int i=2 ; i<8 ; i++ ){
		t = V2[i].F ; x = V2[i].S ;
		V4.push_back( Pid(t,x) ) ;
	}
	for( int i=2 ; i<8 ; i++ ){
		t = V3[i].F ; x = V3[i].S ;
		V4.push_back( Pid(t,x) ) ;
	}
	sort( V4.begin() , V4.end() ) ;
	
	for( int i=0 ; i<2 ; i++ ) printf("%d %.2lf\n",V1[i].S ,V1[i].F) ; 
	for( int i=0 ; i<2 ; i++ ) printf("%d %.2lf\n",V2[i].S ,V2[i].F) ;
	for( int i=0 ; i<2 ; i++ ) printf("%d %.2lf\n",V3[i].S ,V3[i].F) ;
	for( int i=0 ; i<2 ; i++ ) printf("%d %.2lf\n",V4[i].S ,V4[i].F) ;
	
return 0 ;
}

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

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } 
template <typename A>
string to_string(A v) {
    bool first = true; 
    string res = "{";
    for (const auto &x : v) {
        if (!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}"; 
    return res;
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    dbg_out(T...);
}
#ifdef LOCAL
    #define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", dbg_out(__VA_ARGS__)
#else
    #define dbg(...) 42
#endif

#define int long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define MP make_pair
#define sz(v) ((int)(v).size())  
#define fr(i, j, k) for(int i = j; i < k; i++)
#define nl "\n"
typedef pair<int, int> pii;
typedef vector <int> vi;

pii dir[8] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {1, 1}, {-1, -1} , {-1, 1}, {1, -1} };

const int inf = (1LL << 60), mod = 1e9+7, nn = 2e5+5;

void solve(){
	int h, a;
	cin >> h >> a;
	cout << (h/a) + (h % a != 0);
}

int32_t main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}

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

using namespace std;

long long f[100005];
long long MOD = 1000000007;

int main() {
	f[0] = 1;
	long long N;
	scanf("%lld", &N);
	for (long long i = 1; i <= N; i++) {
		f[i] = (i * f[i - 1]) % MOD;
	}
	printf("%lld\n", f[N]);
}

Measured memory_bytes: 1024
#include <iostream>


int leap_year(int y) {
	if( y % 400 == 0) {
		return 1;/*???????????´*/
	} else if (y % 100 == 0 && y % 400 != 0) {
		return 0;/*???????????´??§??????*/
	} else if (y % 4 == 0 && y % 100 != 0) {
		return 1;
	} else {
		return 0;
	}
}
int main()
{
	int a, b;
	int n =0;/*???????????°-1*/
	while (true) {
		std::cin >> a >> b;
		if (a == 0 && b == 0) {
			break;
		} else {
			if (n >0) {
				std::cout << std::endl;/*1?????????????????\?????§??????????????????*/
			}
			int sum = 0;
			for (int k = a; k <= b; k++) {
				sum = sum + leap_year(k);
			}
			if (sum == 0 /*????????????????????´?????????*/) {
				std::cout << "NA" << std::endl;
			} else {
			    for (int i =a; i <= b; i++) {
					if (leap_year(i) == 1) {
						std::cout << i << std::endl;
					}
				}
			}
		}
	n++;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    //suiheihoukou
    if ((x-r)<0||(x+r)>W) cout <<"No"<<endl;
    else if((y-r)<0 || (y+r)>H){
        cout << "No" <<endl;
    }else{
        cout<<"Yes"<< endl;
    }
    return 0;
}


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

int main()
{
    
    int n;
    cin>>n;
    while(n!=0)
    {
        if(n%10==9)break;
        n=n/10;
    }
    if(n!=0)cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


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

int main(){
  int N, D;
  cin >> N >> D;
  
  int b = 2*D+1;
  D = 2*D+1;
  int cnt = 1;
  while(true){
    if(N <= D){
      break;
    }
    D = D + b;
    cnt++;
  }
  
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 256
N = int(input())
dia = [0]*(N-1)
for i in range(N-1):
    c,s,f = map(int,input().split())
    dia[i] = (c,s,f)
for i in range(N-1):
    time = 0
    for j in range(i,N-1):
        c,s,f = dia[j]
        if time > s:
            if time % f == 0:
                s = time
            else:
                s = time + f - time % f
        time =  s + c
    print(time)
print(0)










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

int main() {
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    ll ans = INFINITY;
    rep(i,max(2*X,2*Y)+1) {
        ll price = max(0LL, X - i / 2) * A + max(0LL, Y - i / 2) * B + i * C;
        ans = min(ans, price);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    u64 r;
    cin >> r;

    cout << r * r << "\n";
    return 0;
}



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

typedef long long int lli;
#define pb push_back
#define gcd __gcd
#define MOD 1000000007
#define mod2 998244353
#define forz(i,n) for(long long int i=0;i<n;i++)
char A[51][51];
set<pair<lli,lli>> s1,s2;
set<pair<lli,lli>>::iterator i1,i2;

lli mod(lli a){
    if(a<0) return -1*a;
    return a;
}

bool comp(pair<lli,lli> a,pair<lli,lli> b){
    return 0;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli t=1,u,j;
    //cin>>t;
    for(u=1;u<=t;u++){
        lli n,m,i,j,p=0,c,q=0,k,a,b,x,y,ne=0,p1=0,p2=0,p3=0,p4=0,q1=0,k1,k2,a1,a2;
        cin>>n>>m>>k;
        string A[n];
        for(i=0;i<n;i++) cin>>A[i];

        for(i=0;i<n;i++){
            for(j=0;j<m;j++){
                for(k1=0;k1<pow(2,n);k1++){
                    for(k2=0;k2<pow(2,m);k2++){
                        if(__builtin_popcount(k1)==i & __builtin_popcount(k2)==j){
                            vector<bool> A1(n,1),A2(m,1);
                            a1=k1,a2=k2;
                            for(p1=0;p1<n;p1++){
                                if(a1%2!=0) A1[p1]=0;
                                a1/=2;
                            }
                            for(p2=0;p2<m;p2++){
                                if(a2%2!=0) A2[p2]=0;
                                a2/=2;
                            }
                            q=0;
                            for(p1=0;p1<n;p1++){
                                for(p2=0;p2<m;p2++){
                                    if(A[p1][p2]=='#' & A1[p1] & A2[p2]){
                                        q++;
                                    }
                                }
                            }
                            if(q==k) p++;
                        }
                        
                    }
                }
            }
        }
        cout<<p<<endl;
    }
}

Measured memory_bytes: 4088
#include <bits/stdc++.h>
using namespace std;
int arr[15][15];
int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        int last = i % 10;
        int first = to_string(i)[0] - '0';
        arr[first][last]++;
    }
    int cnt = 0;
    for(int i = 0; i <= 9; ++i) {
        for(int j = 0; j <= 9; ++j) {
            cnt += arr[i][j] * arr[j][i];
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	//数値の入力
		long n = sc.nextLong();
      	long count = 0;
      	
        for(long i = 1; i <= n; i++){
        	if(i*i<=n){
              count++;
            }
        }
              System.out.println(count*count);
     }
}

Measured memory_bytes: 35768
s = list(str(input()))
import itertools
for p in itertools.product(('+', '-'), repeat=3):
    temp = [0]*7
    for i in range(4):
        temp[2*i] = s[i]
    for i in range(3):
        temp[2*i+1] = p[i]
    #print(temp)
    temp = ''.join(temp)
    if eval(temp) == 7:
        print(temp+'=7')
        exit()


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

const int MAX = 998244353;
 
 



signed main(){
    int n,q;
    cin>>n>>q;
    vector<int> hen[n];
    int used[n]={},po[n]={};
    int a,b,p,x;
    for(int i=0;i<n-1;i++){
        cin>>a>>b;
        hen[a-1].push_back(b-1);
        hen[b-1].push_back(a-1);
    }
    for(int i=0;i<q;i++){
        cin>>p>>x;
        po[p-1]+=x;
    }
    queue<int> que;
    que.push(0);
    
    while(!que.empty()){
        a=que.front();
        que.pop();
        used[a]=1;
        for(int i=0;i<hen[a].size();i++){
           if(used[hen[a][i]]!=1){
                que.push(hen[a][i]);
                po[hen[a][i]]+=po[a];
              
           }
            
        }
    }
    for(int i=0;i<n;i++)cout<<po[i]<<' ';
    
    return 0;
}

Measured memory_bytes: 19440
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

t = gets.chomp.split("").map &:to_i
kk = inp[0]
l = t.size
zerop = na(l)
nonzeros = 0
t.each.with_index do |d,i|
  zerop[i] = nonzeros
  nonzeros += 1 if(d!=0)
end
ans = na(3)
(0...l).each do |i|
  if(zerop[i] == 0)
    ans[0] += t[i]
  else
    ans[0] += 9
  end
end
(0...(l-1)).each do |i|
  ((i+1)...l).each do |j|
    if(zerop[i] == 0)
      if(zerop[j] <= 1)
        ans[1] += big((t[i]-1),0) * 9 + t[j]
      else
        ans[1] += big((t[i]-1), 0) * 9 + 9
      end
    else
      ans[1] += 81
    end
  end
end
(0...(l-2)).each do |i|
  ((i+1)...(l-1)).each do |j|
    ((j+1)...l).each do |k|
      if(zerop[i] != 0)
        ans[2] += 729
      else
        ans[2] += (t[i]-1) * 81
        if(zerop[j] <= 1)

          if(zerop[k]> 2)

            ans[2] += big((t[j]-1),0) * 9 + 9
          else
            ans[2] += big((t[j]-1),0) * 9 + t[k] if (t[j]-1>0)
          end
        else
          ans[2] +=  81
        end
      end
    end
  end
end

p ans[kk-1]


Measured memory_bytes: 3836
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
sumc = 0

for count in range(N-1):
    if A[count+1] - A[count] == 1:
        sumc = sumc + C[A[count]-1]

print(sumc + sum(B))


Measured memory_bytes: 3060
import scala.io.StdIn._

object Main extends App{
  val count = readLine.toInt
  val words = readLine

  var current = 0
  var max = 0

  words.foreach {
    case 'I' => {
      current = current + 1
      if(current > max) { max = current }
    }
    case 'D' => {
      current = current - 1
    }
   }

  println(max)
}

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

const long long mod = 1e9 + 7;

int main() {
  int h, w, k;
  cin >> h >> w >> k;

  vector<vector<long long>> dp(h+1, vector<long long>(w, 0));
  dp[0][0] = 1;
  for ( int i = 0; i < h; i++ ) {
    for ( int j = 0; j < w; j++ ) {
      for ( int bit = 0; bit < (1<<(w-1)); bit++ ) {
        bool not_connect = true;
        for ( int line = 0; line < w-2; line++ ) {
          if ( (bit>>line)&1 && (bit>>(line+1))&1 ) {
            not_connect = false;
            break;
          }
        }
        if ( !not_connect ) { continue; }

        if ( j >= 1 && (bit>>(j-1))&1 ) {
          dp[i+1][j-1] += dp[i][j];
          dp[i+1][j-1] %= mod;
        } else if ( j <= w-2 && (bit>>j)&1 ) {
          dp[i+1][j+1] += dp[i][j];
          dp[i+1][j+1] %= mod;
        } else {
          dp[i+1][j] += dp[i][j];
          dp[i+1][j] %= mod;
        }
      }
    }
  }

  cout << dp[h][k-1] << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {  
  return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) { 
   return a * b / gcd(a, b);
   }
//MIN

 main() {
int a,b;
cin >> a >> b;
cout << a%b<<endl;
 }


Measured memory_bytes: 256