akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.io.InputStream;

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

    static class DRainFlowsIntoDams {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] A = new int[n];
            long tot = 0;
            for (int i = 0; i < n; i++) {
                int a = in.nextInt();
                A[i] = a;
                tot += a;
            }
            tot /= 2;
            long tempTot = 0;
            for (int i = 0; i < n; i += 2) {
                tempTot += A[i];
            }
            long[] res = new long[n];
            res[0] = tempTot - tot;
            for (int i = 0; i < n - 1; i++) {
                res[i + 1] = A[i] - res[i];
            }
            StringBuilder sb = new StringBuilder();
            for (long i : res) {
                sb.append(2 * i).append(" ");
            }
            out.println(sb);
        }

    }

    static class Scanner {
        private StringTokenizer st;
        private BufferedReader br;

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

        public Scanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

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

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

    }
}



Measured memory_bytes: 42684
using System;
using System.Linq;
using System.Collections.Generic;
class c
{
    static void Main()
    {
        var inp = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var L = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var list = new List<int>();
        list.Add(0);
        int temp = 0;
        for (int i = 0; i < inp[0]; i++)
        {
            temp += L[i];
            list.Add(temp);
        }
        Console.WriteLine(list.Count(f => f <= inp[1]));
    }
}

Measured memory_bytes: 13268
//  SMOKE SHISHA PLAY FIFA  // 
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pll pair<ll,ll>
#define MP make_pair
#define ff first
#define ss second
#define PB push_back
#define mod 1000000007
#define lp(i,start,end) for(ll i=start;i<=end;i++) 
#define deb1(a) cout<<#a<<" = "<<(a)<<endl;
#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;


ll modu(ll a, ll b)
{
	ll ans =1;
	while(b>0)
	{
		if(b&1)
		ans = (ans*a)%mod;
		b/=2;
		a = (a*a)%mod;
	}
	return ans;
}

int main()
{
	fastio
	ll x;
	cin>>x;
	if(x>=400 && x<600)
		cout<<"8"<<endl;
	else if(x>=600 && x<800 )
		cout<<"7"<<endl;
	else if(x>=800 && x<1000 )
		cout<<"6"<<endl;
	else if(x>=1000 && x<1200 )
		cout<<"5"<<endl;
	else if(x>=1200 && x<1400 )
		cout<<"4"<<endl;
	else if(x>=1400 && x<1600 )
		cout<<"3"<<endl;
	else if(x>=1600 && x<1800 )
		cout<<"2"<<endl;
	else
		cout<<"1"<<endl;
	return 0;	
}


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

using namespace std;

int main() {
    int N, H;
    cin >> N >> H;
    vector<long long> a(N);
    vector<long long> b(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i] >> b[i];
    }
    sort(a.begin(), a.end(), greater<int>());
    sort(b.begin(), b.end(), greater<int>());
    int i = 0, count = 0;
    while (H > 0) {
        if (a[0] <= b[i] && i < N) {
            H -= b[i];
            ++i;
            ++count;
        }else {
         count += H / a[0] + ((H % a[0]) != 0 ? 1 : 0);
         break;
        }
    }
    cout << count;
}

/*
*
 */







Measured memory_bytes: 1792
void main()
{
    long[] tmp = rdRow;
    long k = tmp[0], x = tmp[1];

    writeln(500 * k >= x ? "Yes" : "No");
}

T rdElem(T = long)()
{
    //import std.stdio : readln;
    //import std.string : chomp;
    //import std.conv : to;

    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;

dchar[] rdDchar()
{
    //import std.conv : to;

    return rdStr.to!(dchar[]);
}

T[] rdRow(T = long)()
{
    //import std.stdio : readln;
    //import std.array : split;
    //import std.conv : to;

    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    //import std.stdio : write, writeln;

    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

int main ( )
{
  int N, i, min, cnt;
  long sum;
  long A[ 100000 ];
  scanf ( "%d", &N );
  sum = 0;
  min = 1000000000;
  cnt = 0;
  for ( i = 0 ; i < N ; i++ )
    {
      scanf ( "%ld", &A[ i ] );
      if ( A[ i ] < 0 )
	{
	  cnt++;
	  A[ i ] = abs ( A[ i ] );
	}
      if ( min > A[ i ] )
	min = A[ i ];
      sum += A[ i ];
    }
  if ( cnt % 2 )
    sum -= min * 2;
  printf ( "%ld\n", sum );
  return 0;
}


Measured memory_bytes: 896
#include <stdio.h>
#include <math.h>
 
double stddev(int s[],size_t n){
    int i,v;
    double sum=0,sqsum=0;
    for(i=0;i<n;i++){
        v = s[i];
        sum += v;
        sqsum += v*v;
    }
    return sqrt(sqsum/n - (sum/n)*(sum/n));
}
 
int main(){
    int i,n,s[1000];
    while(1){
        scanf("%d",&n);
        if(!n)break;
        for(i=0;i<n;i++){
            scanf("%d",&s[i]);
        }
        printf("%f\n",stddev(s,n));
    }
    return 0;
}

Measured memory_bytes: 636
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int r = sc.nextInt();
		int c = sc.nextInt();

		int rc[][] = new int[r+1][c+1];

		for (int i=0; i<r; i++) {
			int sum = 0;
			for (int j=0; j<c; j++) {
				int a = sc.nextInt();
				sum += a;
				rc[i][j] = a;
			}
			rc[i][c] = sum;
		}

		for (int i=0; i<c+1; i++) {
			int sum = 0;
			for (int j=0; j<r; j++) {
				sum += rc[j][i];
			}
			rc[r][i] = sum;
		}

		for (int i=0; i<r+1; i++) {
			for (int j=0; j<c; j++) {
                    System.out.print(rc[i][j] + " ");
			}
            System.out.println(rc[i][c]);
		}
	}
}

//途中


Measured memory_bytes: 41588
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int> > v(m);
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a >> b;
        if(a>m) continue;
        v[m-a].push_back(b);
    }
    priority_queue<int> q;
    ll ans=0;
    for(int i=m-1;i>=0;i--){
        for(int c : v[i]){
            q.push(c);
        }
        if(!q.empty()){
            ans += q.top(); q.pop();
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 5504
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

class Graph {
   private:
    struct edge {
        int to;
        int cost;
        edge(int i, int c = 1) : to(i), cost(c) {}
    };
    vector<vector<edge>> edges;
    vector<int> max_depthes;
    vector<int> reached_nodes;

   public:
    vector<int> path_u_v;
    Graph(int n) { edges.resize(n); };
    int size() const { return edges.size(); };
    int countEdge() const {
        int count = 0;
        for (auto &&i : edges)
            for (auto &&j : i) count++;
        return count;
    }
    void addDirectedEdge(int from, int to, int cost = 1) {
        edges[from].push_back(edge(to, cost));
    }
    void addEdge(int from, int to, int cost = 1) {
        addDirectedEdge(from, to, cost);
        addDirectedEdge(to, from, cost);
    }

    int searchMaxDepths(int hn, int pn, int depth = 0) {
        if (depth == 0) max_depthes.assign(edges.size(), 0);

        int max_depth = depth;

        for (auto &&edge : edges[hn]) {
            const int nn = edge.to;
            if (nn == pn) continue;
            max_depth = max(searchMaxDepths(nn, hn, depth + 1), max_depth);
        }

        return max_depthes[hn] = max_depth;
    }

    void searchPath(int hn, int goal, int pn = -1, int depth = 0) {
        if (depth == 0) reached_nodes.clear();
        reached_nodes.push_back(hn);

        if (hn == goal) path_u_v = reached_nodes;

        for (auto &&edge : edges[hn]) {
            const int nn = edge.to;
            if (nn == pn) continue;
            searchPath(nn, goal, hn, depth + 1);
        }

        reached_nodes.pop_back();
    }

    int answer(int u, int v) {
        searchMaxDepths(v, -1, 0);
        searchPath(v, u);

        int use_max_depth = 0;

        const int d = path_u_v.size();
        for (int i = 0; i < d / 2; i++) {
            use_max_depth =
                max(max_depthes[path_u_v[d - i - 1]], use_max_depth);
        }

        return use_max_depth - 1;
    }
};

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

    int n, u, v;  // u: takahashi, v: aoki
    cin >> n >> u >> v;
    u--, v--;  // transform to 0-based
    vector<int> a(n), b(n);
    for (int i = 0; i < n - 1; i++) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;  // transform to 0-based
    }

    Graph g(n);
    for (int i = 0; i < n - 1; i++) {
        g.addEdge(a[i], b[i]);
    }

    const int ans = g.answer(u, v);

    cout << ans << endl;
}


Measured memory_bytes: 15228
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

ll powmod(ll n, ll k) {
    ll r = 1, t = n % P;
    for (; k != 0; k /= 2) {
        if (k & 1) r = r * t % P;
        t = t * t % P;
    }
    return r;
}
ll inv(ll n) {
    return powmod(n, P - 2);
}

ll r;
vector<int> a;

struct Graph {
    struct Vertex { int n; };
    struct Edge { int i, n; };
    Graph(int n, int m) : v(n, { -1 }), e(m), n(n), m(0) {}
    void add_edge(int i, int j) {
        e[m] = { j, v[i].n };
        v[i].n = m;
        m++;
    }
    int dfs(int i, int p) {
        int c = 1;
        for (int j = v[i].n; j >= 0; j = e[j].n) {
            Edge& o = e[j];
            if (o.i == p) continue;
            int t = dfs(o.i, i);
            c += t;
            r += a[n] - a[t] - a[n - t] + 1;
        }
        return c;
    }
    void solve() {
        r = 0;
        a = vector<int>(n + 1);
        a[0] = 1;
        for (int i = 0; i < n; i++) {
            a[i + 1] = a[i] * 2 % P;
        }
        dfs(0, -1);
        r += a[n] - 1;
        r -= (ll)a[n - 1] * n;
        r %= P;
        if (r < 0) r += P;
        r = r * inv(a[n]) % P;
        cout << r << endl;
    }
    vector<Vertex> v;
    vector<Edge> e;
    int n, m;
};

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

    int n;
    cin >> n;

    Graph g(n, (n - 1) * 2);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        g.add_edge(a, b);
        g.add_edge(b, a);
    }

    g.solve();

    return 0;
}

Measured memory_bytes: 7936
import java.util.*;

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

        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = b+(a-1);
        if(c>=0&&b<=0){
            System.out.println(a*(b+c)/2);
        }else if(c<0&&b<0){
            System.out.println(a*(b+c)/2-c);
        }else{
            System.out.println(a*(b+c)/2-b);
        }
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define endl '\n'
#define forn(i, n) for(int i=0;i<n;i++)
#define lli long long int
#define pii pair<int,int>
#define fi first
#define se second
#define psi pair<int,pii>
#define pb push_back
#define vi vector<int>
#define vii vector< vi >

using namespace std;

const int MAXN = 1000001;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m,k;
	cin>>n>>m>>k;
	forn(i, n + 1)
	forn(j, m + 1) {
		if(k == i * m + j * n - i * j * 2) {
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}


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

int main(void)
{
    int n;
    scanf("%d", &n);

    int *A = malloc(sizeof(int) * n);
    int i;
    for (i = 0; i < n; i++) scanf("%d", A + i);

    int q;
    scanf("%d", &q);
    
    int b, e, j, x;
    while (q--) {
        scanf("%d %d", &b, &e);
        for (i = b, j = e - 1; i < j; i++, j--) {
            x = A[i];
            A[i] = A[j];
            A[j] = x;
        }
    }
    
    n--;
    for (i = 0; i < n; i++) printf("%d ", A[i]);
    printf("%d\n", A[n]);

    free(A);

    return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;

int main(){
  int A,B;
  cin>>A>>B;
  int ans=0;
  for(int i=A;i<=B;i++){
    vector<int> a(5);
    int res=i;
    for(int i=0;i<5;i++){
      a.at(i)=res%10;
      res/=10;
    }
    if(a.at(0)==a.at(4)&&a.at(1)==a.at(3)){
      ans++;
    }
  }
  cout<<ans<<endl;
}


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

int main(){
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    for(int i=1;i<v.size();i++){
        if(v[i-1]>v[i]){
            cout<<"No"<<endl;
            return 0;
        }
        else if(v[i]!=v[i-1]){
            v[i]--;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            long[] nk = ReadLine().Split(' ').Select(long.Parse).ToArray();
            var sortedDic = new SortedDictionary<int,long>();
            for (int i = 0; i < nk[0]; i++)
            {
                long[] s = ReadLine().Split(' ').Select(long.Parse).ToArray();
                try
                {
                    sortedDic.Add((int)s[0],s[1]);
                }
                catch (Exception)
                {
                    sortedDic[(int)s[0]] += s[1];
                }
            }
            long tmp = 0;
            int j = 0;
            foreach (var item in sortedDic)
            {
                j++;
                tmp += item.Value;
                if (tmp >= nk[1])
                {
                    WriteLine(item.Key);
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 21572
#include "bits/stdc++.h"
using namespace std;

int main() {
    string A, B, C;
    cin >> A >> B >> C;
    if (A.at(A.size()-1) == B.at(0) && B.at(B.size()-1) == C.at(0)){
    cout << "YES" << endl;
}
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int DP[110000] = {};
vector<int> E[110000];

int func(int pos){
	if(DP[pos] != 0){
		return DP[pos];
	}
	int S = 0;
	for(int i = 0; i < E[pos].size(); i++){
		S = max(S, func(E[pos][i]));
	}
	DP[pos] = S + 1;
	return DP[pos];
}

int main(){
	
	int N, M;
	cin >> N >> M;
	
	for(int i = 0; i < M; i++){
		int x, y;
		cin >> x >> y;
		E[x].push_back(y);
	}
	
	int ans = 0;
	for(int i = 1; i <= N; i++){
		ans = max(ans, func(i));
	}
	
	cout << ans - 1 << endl;
	
	return 0;
}


Measured memory_bytes: 8448
from sys import stdin

class Node(object):
    def __init__(self, parent=None, left=None, right=None):
        self.parent = parent
        self.left = left
        self.right = right

def print_nodes(nodes, n):
    A = []
    B = []
    C = []
    def walk_tree(nodes, u):
        if u == -1:
            return
        r = nodes[u].right
        l = nodes[u].left
        A.append(u)
        walk_tree(nodes, l)
        B.append(u)
        walk_tree(nodes, r)
        C.append(u)

    for i in range(n):
        if nodes[i].parent == None:
            walk_tree(nodes, i)
            print("Preorder", end="\n ")
            print(*A, sep=" ")
            print("Inorder", end="\n ")
            print(*B, sep=" ")
            print("Postorder", end="\n ")
            print(*C, sep=" ")

def read_binary_tree(nodes, n):
    for _ in range(n):
        i = [int(i) for i in stdin.readline().strip().split()]
        nodes[i[0]].left = i[1]
        nodes[i[0]].right = i[2]
        if i[1] != -1:
            nodes[i[1]].parent = i[0]
        if i[2] != -1:
            nodes[i[2]].parent = i[0]

n = int(input())
nodes = [Node() for _ in range(n)]
read_binary_tree(nodes, n)
print_nodes(nodes, n)


Measured memory_bytes: 5628
#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()
{
  int K;
  string S;
  cin >> K >> S;
  
  int s_size = S.size();
  
  rep(i, min(s_size, K))
  {
    cout << S[i];
  }
  
  if (s_size > K)
  {
    cout << "...";
  }
  
  cout << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin >> s;
  int cnt1=0;
  int cnt0=0;
  for(int i=0;i<s.size();i++) {
    if(s[i] == '1') cnt1++;
    else cnt0++;
    }
  int res = s.size()-abs(cnt0-cnt1);
  cout << res << endl;
}


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


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

    char c;
    cin >> c;

    c++;
    cout << c << endl;
}




Measured memory_bytes: 764
from collections import deque

h, w = map(int, input().split())
s = ['#' * (w + 2)] + ['#' + input() + '#' for i in range(h)] + ['#' * (w + 2)]
# print(*s, sep='\n')

di = [1, 0, -1, 0]
dj = [0, 1, 0, -1]


def bfs(si, sj):
    queue = deque([(si, sj, 0)])
    cost = [[-1] * (w + 2) for _ in range(h + 2)]
    cost[si][sj] = 0
    while queue:
        ci, cj, cc = queue.popleft()
        for k in range(4):
            ni = ci + di[k]
            nj = cj + dj[k]
            if s[ni][nj] == '#':
                continue
            if cost[ni][nj] != -1:
                continue
            queue.append((ni, nj, cc + 1))
            cost[ni][nj] = cc + 1

    return max(map(lambda x: max(x), cost))


ans = 0
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s[i][j] == '.':
            ans = max(ans, bfs(i, j))
print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n, m;
    cin >> n >> m;

    ll res = n * (n - 1) / 2 + m * (m - 1) / 2;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int dx[]={1,0,-1,0};
int dy[]={0,-1,0,1};
typedef struct data_{
    int x,y;
}data_t;
typedef struct queue_{
    int n,f,t;
    data_t data[100000];
    int (*size)();
    int (*front)();
    int (*tail)();
    void (*enqueue)(data_t);
    data_t (*dequeue)(); 
    void (*init)();
    int (*isEmpty)();
}queue_t;
queue_t queue;
int size(){return queue.n;}
int front(){return queue.f;}
int tail(){return queue.t;}
void enqueue(data_t data){queue.n++;queue.data[queue.t++]=data;}
data_t dequeue(){queue.n--;return queue.data[queue.f++];}
void init(){queue.f=queue.t=queue.n=0;}
int isEmpty(){return queue.n?1:0;}
void setQueue(){
    queue.size=size;
    queue.front=front;
    queue.tail=tail;
    queue.enqueue=enqueue;
    queue.dequeue=dequeue;
    queue.init=init;   
    queue.isEmpty=isEmpty;
}
int h,w;
char s[100][100];
int dist[100][100];
void bfs(int x,int y){
    data_t data;
    data.x=x;data.y=y;
    dist[y][x]=0;
    queue.enqueue(data);
    while(queue.isEmpty()){
        data=queue.dequeue();
        for(int i=0;i<4;i++){
            data_t now;
            now.x=data.x+dx[i];
            now.y=data.y+dy[i];
            if(dist[now.y][now.x]!=-1)continue;
            if(now.x<0||w<=now.x||now.y<0||h<=now.y)continue;
            if(s[now.y][now.x]=='#')continue;
            dist[now.y][now.x]=dist[data.y][data.x]+1;
            queue.enqueue(now);
        }
    }
}

int main(){
    setQueue();

    scanf("%d %d",&h,&w);
    for(int i=0;i<h;i++){
        scanf("%s",s[i]);
    }

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            dist[i][j]=-1;
        }
    }

    int cnt=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#')cnt++;
        }
    }

    bfs(0,0);

    printf("%d\n",dist[h-1][w-1]!=-1?h*w-(dist[h-1][w-1]+1)-cnt:-1);
}

Measured memory_bytes: 256
k = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
z = [int(i) for i in input().split()]

x.sort(reverse=True)
y.sort(reverse=True)
z.sort(reverse=True)

SUM = []

for i in range(len(x)):
  for j in range(len(y)):
    for l in range(len(z)):
      if (i+1)*(j+1)*(l+1) <= k[3]:
        SUM.append(x[i]+y[j]+z[l])
      else:
        break

SUM.sort(reverse=True)

for i in range(k[3]):
  print(SUM[i])


Measured memory_bytes: 8708
<?php

    fscanf(STDIN, "%d %d", $K, $T);
    $a = explode(" ", trim(fgets(STDIN)));
    $mmax = max($a);
    $rest = $K - $mmax;
    $ans = $mmax - $rest - 1;
    if ($ans < 0) {
        $ans = 0;
    }

    echo $ans . PHP_EOL;


Measured memory_bytes: 3064
N = int(input())
H = [int (i) for i in input().split()]
flag = 1

if N == 1:
    flag = 1
else:
    for i in range(1,N):
        if H[i-1] > H[i]:
            H[i] += 1
    for i in range(N-1):
        if H[i] > H[i+1]:
            flag = 0

if flag == 0:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 63984
#include<iostream>
#include<sstream>
#include<string>
#include<utility>
#include<unordered_map>
#include<iterator>
#include<vector>
#include<math.h>
#include<algorithm>
#define ll long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
int main(void)
{
	IOS
		int n , k;
	const int inf = 1e9 + 5;
	cin >> n >> k;
	vector <int> a(n);
	for (int &i : a)
		cin >> i;
	vector <int> dp(n , inf);
	dp[n - 1] = 0;
	dp[n - 2] = abs(a[n - 1] - a[n - 2]);
	for (int i = n - 3; i >= 0; --i)
	{
		for (int j = i + 1 ; j <= i + k ; ++j)
		{
			if (j < n)
			{
				dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
			}
			else
				break;
		}
	}
	cout << dp[0] << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    vector<int> a(n),b(n+1),c(n+1);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
        b[i+1]=MAX(b[i], a[i]);
    }

    for(i=n-1; i>=0; i--) {
        c[i]=MAX(c[i+1],a[i]);
    }

    for(i=0; i<n; i++) {
        printf("%d\n", MAX(b[i], c[i+1]));
    }

    
    return 0;
}



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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int k; cin >> k;
  int ma = max(a, b);
  ma = max(ma, c);
  int ans = a + b + c - ma;
  for(int i=0; i<k; i++) ma*=2;
  ans += ma;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys


def get_ints():
    return map(int, sys.stdin.readline().strip().split())


def mul(x, y, mod):
    x %= mod
    y %= mod
    return x * y % mod


def div(x, y, mod):
    x %= mod
    y %= mod
    return x * mod_pow(y, mod - 2, mod) % mod


def mod_pow(a, p, mod):
    if p == 0:
        return 1
    if p % 2 == 0:
        root = mod_pow(a, p / 2, mod)
        return root * root % mod
    else:
        return a * mod_pow(a, p - 1, mod) % mod


def pre_factorial_divs(n, mod, factorials):
    factorial_divs = [0] * (n + 1)

    factorial_divs[n] = div(1, factorials, mod)
    for i in reversed(range(n)):
        factorial_divs[i] = mul(factorial_divs[i+1], i+1, mod)
    return factorial_divs


def pre_factorials(n, mod):
    factorials = [0] * (n + 1)
    factorials[0] = 1
    for i in range(n):
        factorials[i + 1] = (i + 1) * factorials[i] % mod
    return factorials


def fast_fast_fermat_comb(a, b, mod, factorials, factorial_divs):
    if len(factorials) == 0:
        raise
    af = factorials[a]
    bf = factorial_divs[b]
    abf = factorial_divs[a - b]
    return mul(mul(af, bf, mod), abf, mod)


def main():
    h, w, a, b = get_ints()

    ans = 0
    mod = 10 ** 9 + 7

    factorials = pre_factorials(h+w-2, mod)
    factorial_divs = pre_factorial_divs(h+w-2, mod, factorials[h+w-2])

    for i in range(h-a):
        x = fast_fast_fermat_comb(b-1+i, b-1, mod, factorials, factorial_divs)
        y = fast_fast_fermat_comb(h+w-3-(b-1+i), w-b-1, mod, factorials, factorial_divs)
        ans += x * y % mod
        ans %= mod

    print(ans)


if __name__ == "__main__":
    main()


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

int main(){

vector<int> a;
int n;

cin >> n;

a.resize(n);

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

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

cout << a[0];
for(int i=1; i<n; i++)cout << ' ' << a[i];
cout << endl;


return 0;
}

Measured memory_bytes: 8984
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  int ans =C-(A-B);
  if(ans <0) ans=0;
  cout << ans << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i,n,s) for (int i= (int)(n); i >= (int)(s); i--)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> a(n);
    ll sum = 0;
    rep(i,0,n){
        cin>>a[i];
        sum += a[i];
    } 
    sum /= 2;
    for (int i=0;i<n-1;i+=2){
        sum-=a[i];
    }
    vector<ll> ans(n);
    ans[n-1] = sum*2;
    ans[0] = (a[n-1]-ans[n-1]/2)*2;
    rep(i,1,n-1){
        ans[i] = (a[i-1] - ans[i-1]/2)*2;
    }
    rep(i,0,n){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 4484
#include <iostream>

using namespace std;

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

  long long int n = H*W;

  if(H == 1 || W == 1)
    cout << 1 << endl;
  else{
    if(n%2 == 0)
      cout << n/2 << endl;
    else
      cout << n/2+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N, K;
  cin >> N >> K;
  int64_t result = 0;
  result = (N / K) * (N / K) * (N / K);
  if (K % 2 == 0) {
    const int64_t temp = N / (K / 2) - N / K;
    result += temp * temp * temp;
  }
  cout << result << endl;
  return 0;
}


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

int main()
{
    ll arr[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll k;
    cin>>k;
    cout<<arr[k-1];
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
    def sum(self, i):  # 区間 [1, i]の和
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
    def add(self, i, x):  # iにxを加算
        while i <= self.size:
            self.tree[i] += x
            i += i & -i  
    def pos(self, idx):  # idxの値を取得
        return self.sum(idx) - self.sum(idx-1)
    def lower_bound(self, w):  # w以上の値を持つ最小のidxを検索
        if w <= 0:
            return 0
        idx = 0
        k = 1
        while k*2 <= self.size:
            k *= 2
        while k > 0:
            if idx+k <= self.size and self.tree[idx+k] < w:
                w -= self.tree[idx+k]
                idx += k
            k //= 2
        return idx+1

N, Q = MAP()
c = LIST()
ilr = [[i]+LIST() for i, _ in enumerate(range(Q))]
ilr.sort(key=lambda x:x[2])
bit = Bit(N)
rtmp = ilr[0][2]
last = [None]*(N+1)
for i in range(rtmp):
    last[c[i]] = i+1
for i in range(1, N+1):
    if last[i]:
        bit.add(last[i], 1)

ans = [0]*Q
for i, l, r in ilr:
    if rtmp < r:
        for j in range(rtmp+1, r+1):
            if last[c[j-1]]:
                bit.add(last[c[j-1]], -1)
            last[c[j-1]] = j
            bit.add(j, 1)
        rtmp = r
    ans[i] = bit.sum(r)-bit.sum(l-1)

print(*ans, sep="\n")


Measured memory_bytes: 205876
#include <bits/stdc++.h>
using namespace std;
#define push_back pb
#define make_pair mp
using ll =  long long;
const int INF = 0x3f3f3f3f;
const int MAX_N = 1e5+15;
int N, M;
ll A[MAX_N];
ll B[MAX_N],C[MAX_N];

void solve()
{
	vector<pair<ll, ll>> v;
	for(int i=0;i<M;++i) v.emplace_back(C[i],B[i]);
	sort(v.begin(), v.end(), greater<pair<ll, ll>>());
	sort(A,A+N);
	int idx = 0;
	for(int i=0;idx<v.size() && i<N;++i){
		if(A[i] > v[idx].first) break;
		A[i] = v[idx].first;
		if(--v[idx].second == 0) idx++;
	}
	ll ans = accumulate(A, A+N, 0LL);
	cout << ans << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N >> M;
	for(int i=0;i<N;++i)cin >> A[i];
	for(int i=0;i<M;++i)cin >> B[i] >> C[i];
	solve();
	return 0;
}

Measured memory_bytes: 4852
a,n = map(int,input().split())
point = []
for i in range(a):
  linea = list(map(int,input().split()))
  point.append(linea)

counta = 0
for j in range(a):
  for k in range(j+1,a):
    dist = 0
    for l in range(n):
      dist += (point[j][l] - point[k][l])**2

    if dist**0.5 == int(dist**0.5):
      counta += 1

print(counta)

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

#define pb push_back
#define mk make_pair
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(S) (S).begin(), (S).end()
#define debug(a) cout << #a << " = " << a << endl;
#define debug2(a,b) cout << #a << " = " << a << " --- " << #b << " = " << b << endl;
#define debugM(M, l, c ) rep( i, 0, l ){ rep( j, 0, c ){ cout << M[i][j] << " "; } cout << endl; }
#define debugP(p) cout << #p << " = " << p.x << " --- " << #p << " = " << p.y << endl;
#define MAXN 100010

using namespace std;

typedef long long int ll;
typedef pair<int, int> ii;
const int INF = 0x3f3f3f3f;

int main(void) {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << min(a, b) + min(c, d) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string s;
  for(int i = 0; i < N; i++){
  	cin >> s;
    if(s == "Y"){
      cout << "Four" << endl;
      break;
    }
  }
  if(s != "Y"){
  	cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main(void){
      int n;
      cin >> n;
    int a[6] = {100,101,102,103,104,105};
    vector<bool> x(1e5 + 1,false);
    x[0] = true;
    for(int i = 0;i < 6;i++){
          for(int j = 0;j <= 1e5;j++){
                if(x[j] && j + a[i] <= 1e5){
                      x[j + a[i]] = true;
                }
          }
    }
    cout << ((x[n]) ? 1 : 0) << endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const long long INF = 10000000000;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

signed main(){
  int N,K;
  cin >> N >> K;
  int h[100000+10];
  for(int i=0;i<N;i++) cin >> h[i];
  int dp[100000+10];
  for(int i=0;i<100000+10;i++) dp[i]=INF;//初期化の際のiの範囲は配列の要素数！
  dp[0]=0;//初期タッ君
  for(int i=0;i<N;i++){
    for(int j=1;j<=K;j++){
      chmin(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
      if(i+j>=N) break;
    }
  }
  cout << dp[N-1] << endl;
  return 0;
}


Measured memory_bytes: 1792
lx,ly = [4,2],[2,4]
dx = [-1,0,1,0]
dy = [0,-1,0,1]
while 1:
    w,h = map(int, raw_input().split())
    if w==0 and h==0: break
    xs,ys = map(int, raw_input().split())
    xg,yg = map(int, raw_input().split())
    f = [[0 for i in range(102)] for j in range(102)]
    s = []
    n = input()
    for i in range(n):
        c,d,x,y = map(int, raw_input().split())
        for p in range(lx[d]):
            for q in range(ly[d]):
                f[y+q][x+p] = c
    ans = 0
    if f[ys][xs]>0 and f[ys][xs]==f[yg][xg]:
        c = f[ys][xs]
        s.append([xs,ys])
        while len(s)>0:
            x,y = s.pop()
            if x==xg and y==yg:
                ans = 1; break;
            for k in range(4):
                if f[y+dy[k]][x+dx[k]]==c:
                    s.append([x+dx[k],y+dy[k]])
                    f[y+dy[k]][x+dx[k]] = 0
    print ("OK" if ans==1 else "NG")

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

int main()
{

int n ,m;
cin >> n >> m; int k=0;
for(int i=1 ;i<1009 ;i++)
{  if((i *8)/100 == n  && (i*1)/10==m ){ cout << i;k++;  break;}  }

if(k==0) cout <<-1;

return 0;}


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

public class P
{
    public int w { get; set; }
    public int L { get; set; }
}

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var k = int.Parse(line[1]);
            if (n == 0 && k == 0) break;
            var aa = new List<int>();
            var zero = false;
            for (int i = 0; i < k; i++)
            {
                var wa = int.Parse(Console.ReadLine().Trim());
                if (wa == 0) zero = true;
                else  aa.Add(wa);
            }
            var a = aa.ToArray();
            Array.Sort(a);
            Console.WriteLine(zero ?  getAns2(a): getAns1(a));
        }
    }
    public static int getAns2 (int [] a)
    {
        var ps = new List<P>();
        var tmax = 1;       var pre = a[0];   var pres = 0;
        for (int i = 1; i < a.Length; i++)
        {
            if (a[i] == pre + 1) { tmax++; }
            else
            {
                ps.Add(new P { w = a[ pres] - 1,L = tmax });
                ps.Add(new P { w =a[ i -1] + 1, L = tmax });
                pres = i;
                tmax = 1;
            }
            pre = a[i];
        }
        ps.Add(new P { w = a[pres] - 1, L = tmax });
        ps.Add(new P { w = a[a.Length-1] + 1, L = tmax });
        var dret = new Dictionary<int, int>();
        foreach (var x in ps)
        {
            if (dret.ContainsKey(x.w)) dret[x.w] += x.L;
            else dret[x.w] = x.L + 1;
        }
        return dret.Max(x => x.Value);
    }
    public static int getAns1(int[] a)
    {
        var tmax = 1; var pre = a[0]; var ret = tmax;
        for (int i = 1; i < a.Length; i++)
        {
            if (a[i] == pre + 1) { tmax++; }
            else { ret = Math.Max(ret, tmax); tmax = 1; }
            pre = a[i];
        }
        ret = Math.Max(ret, tmax);
        return ret;
    }
}



Measured memory_bytes: 12856
import java.util.*;

 class Main
 {
   public static void main(String args[])
   { 
    Scanner sc = new Scanner(System.in);
    
    int s = sc.nextInt();//Second
    
    int h = s / 3600;
    
    int m = s % 3600 / 60;
    
    s = s % 3600 % 60;
    
    System.out.println(h + ":" + m + ":" + s);
   }
   
 }
    


Measured memory_bytes: 26236
import sys
input = sys.stdin.readline
import collections

# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
    s = input().strip()
    q = int(input())
    flg = True
    deq = collections.deque(s)
    for i in range(q):
        t = input_list_str()
        if len(t) == 1:
            n = t[0]
            flg = False if flg is True else True
        else:
            n, f, c = t
            c = str(c).strip()
            if f == '1':
                if flg:
                    deq.appendleft(c)
                else:
                    deq.append(c)
            else:
                if flg:
                    deq.append(c)
                else:
                    deq.appendleft(c)
    if flg is False:
        deq.reverse()
    print(''.join(deq))


def bi(num, a, b, x):
    print((a * num) + (b * len(str(b))))
    if (a * num) + (b * len(str(b))) <= x:
        return False
    return True

def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()


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

int main() {
	int n;
	cin >> n;
	int x;
	int m4=0, m2=0, m1=0;
	for (int i=0; i<n; i++){
		cin >> x;
		if (x%4==0) m4++;
		else if (x%2==0) m2++;
		else m1++;
	}
	//cout << m4 << m2 << m1;
	if (m2==0){
		if (m4+1>=m1) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else{
		if (m4 >= m1) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <list>
#include <sys/timeb.h>
#include <fstream>
#include <set>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


bool pairCompare(const Pi& firstElof, const Pi& secondElof)
{
	return firstElof.second > secondElof.second;
}

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

	int n, m;
	cin >> n >> m;
	int ans = 0;
	vvi a(n+3);
	rep(i, n) {
		int t;
		cin >> t;
		rep(j, t) {
			int x;
			cin >> x;
			a[i].push_back(x);
		}
	}

	repr(i,1, 31) {
		bool f = true;
		rep(j, n) {
			if (find(all(a[j]), i) == a[j].end()) {
				f = false;
			}
		}
		if (f) {
			ans++;
		}
	}
	cout << ans << endl;


	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 53;
bool g[N][N];
int a[N], b[N];
bool vis[N];
int n, m;

void dfs(int u)
{
    vis[u]  = 1;
    for(int i=0; i<n; i++)
        if(g[u][i] && !vis[i])
            dfs(i);


}

int main()
{
    cin>> n >> m;
    for(int i=0; i<m; ++i)
    {
        cin>> a[i] >> b[i];
        a[i]--, b[i]--;
        g[a[i]][b[i]] = g[b[i] ][a[i] ] = 1;
    }
    int ans = 0;
    for(int i=0; i<m; ++i)
    {
        g[a[i]][b[i]] = g[b[i] ][a[i] ] = 0;

        memset(vis, false, sizeof vis);

        dfs(1);
        bool bridge = false;
        for(int i=0; i<n; ++i)
            if(!vis[i])
                bridge = 1;

        if(bridge)
            ans++;
        g[a[i]][b[i]] = g[b[i] ][a[i] ] = 1;
    }

    cout<<ans<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
signed main(){
	int a;
	cin>>a;
	cout<<(a-1)*a/2<<endl;
}


Measured memory_bytes: 256
// date: July 27 2020

#include <bits/stdc++.h>

using namespace std;
#define endl "\n"
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> pii;
map<string,int> m;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        ++m[s];
    }
    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;
    return 0;
}


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

void kock(int n, double p1x, double p1y, double p2x, double p2y);

int main(void)
{
  int n;
  double p1x = 0, p1y = 0, p2x = 100, p2y = 0;
  scanf("%d", &n);
  printf("%f %f\n", p1x, p1y);
  kock(n, p1x, p1y, p2x, p2y);
  printf("%f %f\n", p2x, p2y);

  return 0;
}

void kock(int n, double p1x, double p1y, double p2x, double p2y)
{
  double sx, sy, tx, ty, ux, uy, rad = M_PI/3;
  if (n == 0)  {
    return;
  }
  sx = (2*p1x + p2x) / 3;
  sy = (2*p1y + p2y) / 3;
  tx = (p1x + 2*p2x) / 3;
  ty = (p1y + 2*p2y) / 3;
  ux = (tx - sx)*cos(rad) - (ty - sy)*sin(rad) + sx;
  uy = (tx - sx)*sin(rad) + (ty - sy)*cos(rad) + sy;

  kock(n - 1, p1x, p1y, sx, sy);
  printf("%f %f\n", sx, sy);
  kock(n - 1, sx, sy, ux, uy);
  printf("%f %f\n", ux, uy);
  kock(n - 1, ux, uy, tx, ty);
  printf("%f %f\n", tx, ty);
  kock(n - 1, tx, ty, p2x, p2y);
}

Measured memory_bytes: 636
def gcd(a,b):
    if b>a:
        a,b=b,a
    while b:
        a,b=b, a%b
    return a

def inv(a):
    m=10**9+7
    b=m
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return lastx % m


def main():
    MOD=10**9+7
    n,a,b,c=map(int,input().split())

    frac=[1]
    for i in range(1,2*n):
        frac.append(frac[-1]*i%MOD)
    
    fracinv=[inv(frac[i]) for i in range(2*n)]
    powa,powb,pow100=[1],[1],[1]

    for i in range(n):
        powa.append(powa[-1]*a%MOD)
        powb.append(powb[-1]*b%MOD)
    for i in range(2*n):
        pow100.append(pow100[-1]*(100-c)%MOD)

    ans=0
    
    for m in range(n,2*n):
        tmpp=frac[m-1]*fracinv[n-1]*fracinv[m-n]%MOD*(powa[n]*powb[m-n]+powa[m-n]*powb[n])*m%MOD
        tmpq=pow100[m+1]
        ans=(ans+tmpp*inv(tmpq))%MOD
        
    print(ans*100%MOD)     

if __name__ == "__main__":
    main()

Measured memory_bytes: 71920
#include <stdio.h>

int main(void) {
	int n, q;
	char s[100001];
	scanf("%d%d%s", &n, &q, s);

	int c[100001] = {0};
	for (int i = 1; i < n; i++) {
		c[i] = c[i-1];
		if (s[i-1] == 'A' && s[i] == 'C') c[i]++;
	}

	while (q--) {
		int l, r;
		scanf("%d%d", &l, &r);
		l--; r--;
		printf("%d\n", c[r]-c[l]);
	}
}


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

int main() {
    int a,b,c,d;
    d=0;
    
    cin>>a>>b>>c;
    
    for(int i=a; i<=b;i++){
        if(c%i==0)d++;
    }
    cout<<d<<endl;
       
    
    
 return 0; 
}

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

int main() {
    int A, B;
    cin >> A >> B;

    int ans = ceil(A / 0.08);
    while (1) {
        if (ans >= (A + 1) / 0.08) {
            ans = -1;
            break;
        }
        if (ans >= ceil(B / 0.1) && ans < ceil((B + 1) / 0.1)) break;
        ++ans;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256