akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var hEnumerable = Console.ReadLine().Split(' ').Select(s => int.Parse(s));

            var max = 0;
            var current = 0;
            var left = 0;
            foreach (var h in hEnumerable)
            {
                if (left >= h)
                {
                    current++;
                }
                else
                {
                    if (max < current)
                    {
                        max = current;
                    }
                    current = 0;
                }
                left = h;
            }

            if (max < current)
            {
                max = current;
            }

            //出力
            Console.WriteLine(max.ToString());

            Console.ReadLine();
        }
    }
}

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

using namespace std;

typedef long long ll;

const int N = 100003;

int n;
vector <ll> pr;
bitset <N> vis;
map <ll, int> f;
map <ll, ll> rev;

int main() {
  for (int i = 2; i * i < N; ++i) if (!vis[i]) {
    for (int j = i * i; j < N; j += i) vis[j] = 1;
  }
  for (int i = 2; i < N; ++i) if (!vis[i]) pr.emplace_back(i);
  cin >> n;
  int ans = 0, one = 0;
  for (int i = 1; i <= n; ++i) {
    ll x, cur = 1, oth = 1;
    scanf("%lld", &x);
    for (ll p : pr) {
      if (p * p > x) break;
      if (x % p) continue;
      int e = 0;
      while (x % p == 0) x /= p, ++e;
      e %= 3;
      if (!e) continue;
      for (int j = 0; j < e; ++j) cur *= p;
      e = 3 - e;
      while (e--) oth *= p;
    }
    if (x >= N) ++ans;
    else {
      if (x > 1) cur *= x, oth *= x * x;
      if (cur == 1) ++one;
      else ++f[cur], f[oth], rev[cur] = oth, rev[oth] = cur;
    }
  }
  ans <<= 1;
  for (auto it : f) {
    ll x = it.first;
    int cnt = it.second;
    // cout << x << " " << cnt << " " << f[rev[x]] << endl;
    ans += max(cnt, f[rev[x]]);
  }
  ans >>= 1, ans += !!one;
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 24016
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;


    void calc()
    {
        cin = new Scanner();
        int[] n=new int[5];
        int[] nmod=new int[5];
        int ans=0;
        for(int i=0;i<5;i++)
        {
          n[i]=int.Parse(Console.ReadLine());
          nmod[i]=n[i]%10;
          
          ans+=(n[i]);
          if(nmod[i]!=0)ans+=(10-nmod[i]);
          if(nmod[i]==0)nmod[i]=10;
          
        }
        Array.Sort(nmod);
        ans-=(10-nmod[0]);
        
        
      Console.WriteLine(ans);
    }


}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 11220
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,k;
    std::cin >> n >>k;
    int a=n-k;
    if(k==1){
        std::cout << 0 << std::endl;
    }else{
        std::cout << a << std::endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

#define INF 1000000000

using namespace std;

vector<vector<pair<int, long long>>> g;
vector<bool> visited;
vector<long long> dist;
queue<int> q;

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

    g = vector<vector<pair<int, long long>>>(N + 100);
    visited = vector<bool>(N + 100, false);
    dist = vector<long long>(N + 100, INF);

    REP(i, M) {
        int s, t;
        cin >> s >> t;

        s--;
        t--;

        int w;
        cin >> w;

        g[s].emplace_back(t, w);
        g[t].emplace_back(s, -w);
    }

    REP(i, N) {
        if (visited[i] == false) {
            q.push(i);

            while (!q.empty()) {
                int p = q.front();
                q.pop();

                for (auto& e : g[p]) {
                    long long next_dist = dist[p] + e.second;
                    if (visited[e.first]) {
                        if (dist[e.first] != next_dist) {
                            cout << "No" << endl;
                            return 0;
                        }
                    } else {
                        dist[e.first] = next_dist;
                        visited[e.first] = true;
                        q.push(e.first);
                    }
                }
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 13952
#include <stdio.h>
int main(void){
  int a;
  char buf[100];
  
  fgets(buf, sizeof(buf), stdin);
  sscanf(buf, "%d\n", &a);
  
  if (a%10==7 || a/100==7 || (a/10)%10==7){
    printf("Yes");
  }else{
    printf("No");
  }
  
  return 0;
}

Measured memory_bytes: 1704
#include<stdio.h>
#define MAX 1000000

int insertionSort(int A[], int n, int m) {
  int cnt = 0, i = m;
  for ( int i = m; i < n; i++ ) {
    int v = A[i];
    int j = i - m;
    while ( j >= 0 && A[j] > v ) {
      A[j + m] = A[j];
      j -= m;
      cnt++;
    }
    A[j + m] = v;
  }
  return cnt;
}

void shellSort(int A[], int n) {
  int M[100], m = 0, h = 0, cnt = 0;
  for ( int i = 0; i < 100; i++ ) {
    h = 3 * h + 1;
    if (h > n) break;
    M[i] = h;
    m++;
  }
  printf("%d\n", m);
  for (int i = m - 1; i >= 0; i-- ) {
    if (i != m - 1) printf(" ");
    printf("%d", M[i]);
    cnt += insertionSort(A, n, M[i]);
  }
  printf("\n%d\n", cnt);
}

int main() {
  int n, A[MAX];

  scanf("%d", &n);
  for ( int i = 0; i < n; i++ ) scanf("%d", &A[i]);
  shellSort(A, n);

  for ( int i = 0; i < n; i++ ) printf("%d\n", A[i]);
  return 0;
}


Measured memory_bytes: 6512
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using str = string;
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;
using vc = vector<char>;
using vcc = vector<vc>;

int main() {
    int H, W;
    cin >> H >> W;
    vcc C(H, vc(W));
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cin >> C[i][j];
        }
    }
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cout << C[i][j];
        }
        cout << endl;
        for(int j = 0; j < W; j++) {
            cout << C[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	double s,l;
	while(cin>>s>>l){
		if(s<35.5&&l<71) o("AAA");
		else if(s<37.5&&l<77) o("AA");
		else if(s<40&&l<83) o("A");
		else if(s<43&&l<89) o("B");
		else if(s<50&&l<105) o("C");
		else if(s<55&&l<116) o("D");
		else if(s<70&&l<148) o("E");
		else o("NA");
	}
}

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

int main(){
    int D,E;
    cout<<fixed;
    cout.precision(10);
    while(cin>>D>>E,D){
        double ans = 1e9;
        for(int i=0;i<=D;i++){
            ans = min(ans , abs(E-hypot(i,D-i)));
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3272
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
int w,h,p;
char f[111][111];
int c[111][111];
int d[111][111];
int mx[11],my[111];
int e[11][11];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};

int dp[11][1<<6];
int solve(int n,int bit){
  if(bit == (1<<p)-1){
    return e[n][p];
  }
  if(dp[n][bit]) return dp[n][bit];
  
  int res = 1<<28;
  for(int i = 1; i < p; i++){
    if(bit & 1<<i) continue;
    res = min(res,solve(i,bit | 1<<i) + e[n][i]);
  }
  return dp[n][bit] = res;
}

int main(void){
  cin >> w >> h;
  p = 1;
  int gx,gy;
  queue< pair<int,int> > que;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      c[j][i] = 1;
      cin >> f[j][i];
      switch(f[j][i]){
      case 'S': f[j][i] = '0'; mx[0] = j; my[0] = i; break;
      case 'M': f[j][i] = p + '0'; mx[p] = j; my[p] = i; p++; break;
      case 'G': gx = j; gy = i; break;
      case '#': que.push( make_pair(j,i) ); break;
      }
    }
  }
  mx[p] = gx; 
  my[p] = gy; 
  f[gx][gy] = '0' + p;

  while(!que.empty()){
    int x = que.front().first;
    int y = que.front().second;
    que.pop();
    for(int i = x - 2; i <= x + 2; i++){
      for(int j = y - 2; j <= y + 2; j++){
	c[i][j] = max(c[i][j],4-max(abs(x-i),abs(y-j)));
      }
    }
  }

  for(int i = 0; i < p; i++){
    priority_queue< pair<int, pair<int,int> >,vector< pair<int, pair<int,int> > >,
		    greater< pair<int, pair<int,int> > > > pque;
    for(int j = 0; j < w; j++) fill(d[j],d[j]+h,1<<28);
    d[mx[i]][my[i]] = 0;
    pque.push( make_pair(0,make_pair(mx[i],my[i])) );
    while(!pque.empty()){
      int l = pque.top().first;
      int x = pque.top().second.first;
      int y = pque.top().second.second;
      pque.pop();
      if(d[x][y] < l) continue;
      for(int j = 0; j < 4; j++){
	int nx = x + dx[j];
	int ny = y + dy[j];
	if(nx < 0 || w <= nx || ny < 0 || h <= ny || c[x][y] > 3 || d[nx][ny] <= d[x][y]+c[x][y]) continue;
	d[nx][ny] = d[x][y] + c[x][y];
	pque.push( make_pair(d[nx][ny],make_pair(nx,ny)) );
      }
    }
    for(int j = 0; j <= p; j++){
      e[i][j] = d[mx[j]][my[j]];
    }
  }
  memset(dp,0,sizeof(dp));
  cout << solve(0,1) << endl;
}

Measured memory_bytes: 1336
import java.util.*;

class Main{
  static int from(int n){
    if(n==1){
      return 0;
    }else if(n==2){
      return 10;
    }
    return 100;
  }
  static int to(int n){
    if(n==1){
      return 9;
    }else if(n==2){
      return 99;
    }
    return 999;
  }
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int m=sc.nextInt();
    int[] s=new int[m];
    int[] c=new int[m];
    for(int i=0;i<m;i++){
      s[i]=sc.nextInt()-1;
      c[i]=sc.nextInt()+'0';
    }
    for(int i=from(n);i<=to(n);i++){
      boolean flag=true;
      for(int j=0;j<m;j++){
        if(String.valueOf(i).charAt(s[j])!=c[j]){
          flag=false;
        }
      }
      if(flag){
        System.out.println(i);
        return;
      }
    }
    System.out.println(-1);
  }
}

Measured memory_bytes: 23764
# Wrote in 2020-03-01 08:44:39 by reetok
require 'time'
def inp(type=:to_i,spst=" ")
  return eval("gets.chomp.split(#{spst}).map(&:#{type})")
end
def inpf() return self.inp(:to_f," ") end
def inps() return self.inp(:to_s," ") end
def r_up(a, b) (a/b).ceil end
def r_down(a, b) (a/b).floor 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
def minp(n,datatype=:to_i)
  t = []
  n.times do
    t.push(eval("gets.chomp.#{datatype.to_s}"))
  end
end
def yes() puts "Yes" end
def no() puts "No" end
def ynju(bool,yes="Yes",no="No") puts (bool ? yes : no) end
#---------------

array = []

loop do
  a = inp
  if a==[0,0]
    break
  else
    array.push(a)
  end
end

array.each do |a|
  puts a.sort.join(" ")
end


Measured memory_bytes: 7484
#include<stdio.h>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<cstdlib>
#include<ctime>
#define rep(i,j,k) for(register int i = j; i <= k; i++)
#define dow(i,j,k) for(register int i = j; i >= k; i--)
#define ll long long
using namespace std;
 
inline int read() {
	int s = 0, t = 1; char c = getchar();
	while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); }
	while( isdigit(c) ) s = s * 10 + c - 48, c = getchar();
	return s * t;	
} 

const int N = 1e5+5, p = 1e9+7;
inline void Min(int &x,int v) { if( x > v ) x = v; }
ll fac[N] = {1};

int main() {
	int n = read(), m = read();
	rep(i,1,max(n,m)) fac[i] = fac[i-1] * i % p;
	if( n == m ) cout<<2 * fac[n] * fac[m] % p<<endl;
	else if( abs(n-m) == 1 ) { 
		cout<<fac[n] * fac[m] % p<<endl;
	} else cout<<0<<endl;
    return 0;
} 

Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var s string
	t := "MARCH"
	cnt := make([]int, len(t))
	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		for j := 0; j < len(t); j++ {
			if t[j] == s[0] {
				cnt[j]++
				break
			}
		}
	}
	var ans int
	for i := 0; i < len(t); i++ {
		for j := i + 1; j < len(t); j++ {
			for k := j + 1; k < len(t); k++ {
				ans += cnt[i] * cnt[j] * cnt[k]
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 6300
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	vector<vector<int> > v;
	vector<int> vec;
	v.insert(v.begin(),n+3,vec);

	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	vector<int> visi(n+1,0);
	for(int i=0;i<v[1].size();i++)
	{
		visi[v[1][i]]++;
	}
	for(int i=0;i<v[n].size();i++)
	{
		visi[v[n][i]]++;
	}
	for(int i=2;i<n;i++)
	{
		if(visi[i]==2){
			cout<<"POSSIBLE"<<endl;
		return 0;}
	}
	cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 12784
sum = 0
A,B,C,X,Y = map(int,input().split())
AB = C*2
ans = float("inf")

for i in range(10**5+1):
    sum = AB*i + A*max(0,X-i) + B*max(0,Y-i)
    if sum < ans:
        ans = sum

print(ans)


Measured memory_bytes: 2940
#!/usr/bin/env python3 ## -*- python -*-

t = input().split()
a = int(t[0])
b = int(t[1])

def judge(a, b):
    a_min = a / 0.08
    a_max = (a+1) / 0.08

    b_min = b / 0.1
    b_max = (b+1) / 0.1

    for c in range(int(a_min), int(a_max)):
        if c < a_min:
            continue
        for d in range(int(b_min), int(b_max)):
            if d < b_min:
                continue
            if c == d:
                return c
    return -1

print(judge(a,b))

Measured memory_bytes: 3064
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

class Prime {
public:
  vector<ll> prime_list;
  const ll MAX_N = 100000;

  Prime() {
    bool checked[MAX_N + 1];
    memset(checked, false, sizeof(checked));

    for (ll i = 2; i <= MAX_N; ++i) {
      if (!checked[i]) {
        prime_list.push_back(i);

        for (ll j = 2 * i; j <= MAX_N; j += i) {
          checked[j] = true;
        }
      }
    }
  }

  map<ll, int> prime_division(ll n) {
    map<ll, int> res;

    for (ll i = 0; prime_list[i] <= sqrt(n); ++i) {
      ll p = prime_list[i];

      while (n % p == 0) {
        ++res[p];
        n /= p;
      }
    }

    if (n != 1) {
      res[n] = 1;
    }

    return res;
  }

  bool is_prime(ll n) {
    if (n <= 1) return false;

    for (int i = 0; i < prime_list.size(); ++i) {
      if (n % prime_list[i]) return false;
    }

    return true;
  }
};

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

  Prime prime;

  map<ll, int> res = prime.prime_division(N);
  vector<int> ans;

  for (map<ll, int>::iterator it = res.begin(); it != res.end(); ++it) {
    for (int i = 0; i < it->second; ++i) {
      ans.push_back(it->first);
    }
  }

  cout << N << ": ";
  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i];

    if (i == ans.size() - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }

  return 0;
}



Measured memory_bytes: 3384
import java.util.Scanner;

public class Main {

    private static Scanner sc = new Scanner(System.in);
    private static int n, q;
    private static int[] A = new int[20];
    private static int[] M = new int[200];

    public static void main(String[] args) {
        input();

        for (int i = 0; i < q; i++) {
            int m = M[i];
            String ans = solve(m, 0, 0) ? "yes" : "no";
            System.out.println(ans);
        }
    }

    private static boolean solve(int m, int depth, int s) {
        if (depth == n) {
            return m == s;
        }

        return solve(m, depth + 1, s + A[depth]) || solve(m, depth + 1, s);
    }

    private static void input() {
        n = sc.nextInt();
            for (int i = 0; i < n; i++) {
            A[i] = sc.nextInt();
        }
        q = sc.nextInt();
            for (int i = 0; i < q; i++) {
            M[i] = sc.nextInt();
        }
    }
}

Measured memory_bytes: 26804
N,K = map(int,input().split())
MOD = 10**9+7
ans = 0
for k in range(K,N+2):
    mx = (N+N-k+1)*k // 2
    mn = (k-1)*k // 2
    ans += mx - mn + 1
    ans %= MOD
print(ans)

Measured memory_bytes: 9128
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;

ll x;
ll xHappyLevel_5=0;
ll xHappyLevel_500=0;

int main(){
    cin >> x;

    while(x>=500){
        x -= 500;
        xHappyLevel_500 += 1000;
    }
    while(x>=5){
        x -= 5;
        xHappyLevel_5 += 5;
    }
    cout << xHappyLevel_500 + xHappyLevel_5;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
name=["" for _ in range(N+1)]
time=[0 for _ in range(N+1)]
for i in range(N):
    n,t=input().split()
    name[i+1]=n
    time[i+1]=time[i]+int(t)
print(time[N]-time[name.index(input())])

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



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

using namespace std;
int n;

int main(){
  cin >> n;
  while(n%111!=0 && n%1111!=0){
    n++;
  }
  cout << n << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
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;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef __APPLE__
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int MX = 5e5;

int n,q,c[MX],ft[MX+1],ans[MX]; 
vector<array<int,2>>v[MX];

void upd(int i, int x){
  for(++i;i<=n; i+=i&-i) ft[i]+=x;
}
int qry(int i){
  int s= 0;
  for(;i;i-=i&-i) s+=ft[i];
  return s;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> q;
  for(int i = 0; i<n; ++i){
    cin >> c[i];
  }
  for(int i = 0; i<q; ++i){
    int l,r; 
    cin >> l >> r,--l,--r;
    v[r].push_back({l,i});
  }
  map<int,int>m;
  for(int i = 0; i<n; ++i){
    if(m.find(c[i])!=m.end()) upd(m[c[i]],-1);
    upd(i,1);
    for(auto a: v[i]){
      ans[a[1]]=qry(n)-qry(a[0]);
    }
    m[c[i]]=i;
  }
  for(int i = 0; i<q; ++i){
    cout << ans[i] << '\n';
  }
}
 

Measured memory_bytes: 54764
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    static final double eps = 1.0e-8;
    static final int X = 0;
    static final int Y = 1;
    
    public static void main( String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	while ( stdin.hasNextDouble() ) {
	    final double[][] ps = new double[4][2];
	    for ( int i = 0; i < 4; i++ ){
		ps[i][X] = stdin.nextDouble();
		ps[i][Y] = stdin.nextDouble();
	    }

	    if ( intersect( ps[0][X], ps[1][X], ps[2][X], ps[3][X] ) &&
		 intersect( ps[0][Y], ps[1][Y], ps[2][Y], ps[3][Y] ) ) {
		
		System.out.println( "YES" );
	    } else {
		System.out.println( "NO" );
	    }
	}
    }

    static boolean intersect( double a1, double a2, double b1, double b2 ) {
	return min( a1, a2 ) <= max( b1, b2 ) &&
	    min( b1, b2 ) <= max( a1, a2 );
    }
}

Measured memory_bytes: 20856
import java.util.Scanner;

/**
 * Created by Irka on 10.06.2017.
 */
public class Main {
    public static void main(String[] args) {
        Scanner a = new Scanner(System.in);

        char r = a.next().charAt(0);
        char g = a.next().charAt(0);
        char b = a.next().charAt(0);

        String l =""+ r + g+ b ;
        int w = Integer.valueOf(l);
        if (w % 4 == 0 ){
            System.out.println("YES");
        }
        else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 21844
void main() {
	auto N = ri;
	auto L = readAs!(int[]);
	if(L.reduce!max < L.sum - L.reduce!max) {
		writeln("Yes");
	} else writeln("No");
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
import scala.util.control.Breaks

object Main extends App {
  def isPrime(n: Int): Boolean = {
    if (n < 2 || (n > 2 && n % 2 == 0)) {
      return false
    } else if (n == 2) {
      return true
    }
    for (i <- 3 to Math.sqrt(n).toInt by 2 ) {
      if (n % i == 0) {
        return false
      }
    }
    return true
  }

  var x = scala.io.StdIn.readInt()
  val b = new Breaks
  b.breakable {
    while(true) {
      if(isPrime(x)) {
        b.break()
      } else {
        x = x + 1
      }
    }
  }
  println(x)
}


Measured memory_bytes: 27584
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<map>
#define ll long long
#define inf 0x3f3f3f3f
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
ll d[maxn];
std::map<ll,int>mp;
int id[maxn],fa[maxn],size[maxn],dep[maxn];
int n,rt;
bool cmp(int x,int y){return d[x]>d[y];}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		d[i]=read(),mp[d[i]]=i;
	for(int i=1;i<=n;i++)
		id[i]=i,size[i]=1;
	std::sort(id+1,id+n+1,cmp);
	for(int i=1;i<n;i++){
		fa[id[i]]=mp[d[id[i]]-(n-2*size[id[i]])];
		if(!fa[id[i]]||size[id[i]]*2>=n){
			puts("-1"); return 0;
		}
		size[fa[id[i]]]+=size[id[i]];
	}
	dep[id[n]]=0;
	for(int i=n-1;i;i--)
		dep[id[i]]=dep[fa[id[i]]]+1;
	ll sum=0;
	for(int i=1;i<=n;i++)
		sum+=dep[i];
	if(sum!=d[id[n]]){
		puts("-1"); return 0;
	}
	for(int i=1;i<n;i++)
		writesp(id[i]),writeln(fa[id[i]]);
	return 0;
}

Measured memory_bytes: 10880
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;

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

const int MAXT = 11, MAXN = 45, INF = 10000;

int cost[MAXT][MAXT];
int d[MAXT];
bool used[MAXT];
int a, b, c, t, n, anst, ansc, tcost;

int main()
{
    while(cin >> n && n)
    {
        memset(cost, INF, sizeof(cost));
        t = 0;

        REP(n)
        {
            cin >> a >> b >> c;
            cost[a][b] = cost[b][a] = c;
            t = max(t, a+1);
            t = max(t, b+1);
        }
        anst = MAXT, ansc =INF;

        rep(k,t)
        {
            memset(d, INF, sizeof(d));
            memset(used, false, sizeof(used));

            d[k] = 0;
            tcost = 0;
            
            while(true)
            {
                int v = -1;
                rep(i,t)if(!used[i] && (v == -1 || d[i] < d[v])) v = i;
                
                if(v == -1) break;

                used[v] = true;

                rep(i,t) d[i] = min(d[i], d[v] + cost[v][i]);

            }
            REP(t) tcost += d[i];
            if(tcost < ansc) { anst = k; ansc = tcost;}
        }
        cout << anst <<" " << ansc << endl;

    }

    return 0;
}

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


def solve(K: int, S: str):
    if len(S) <= K:
        return S
    else:
        return S[:K] + '...'


# 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)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    print(solve(K, S))


if __name__ == '__main__':
    main()


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

signed main(){
    int n;cin>>n;
    int a[n];
    int l=0;
    rep(i,n){
        cin>>a[i];
        l+=a[i];
    }
    int ll=0,rr=0;
    rep(i,n){
        rr+=a[i];
        if((l/2)<=rr){ll=rr;rr=l-ll;break;}
    }
    int ans=abs(rr-ll);
    reverse(a,a+n);
    ll=0,rr=0;
    rep(i,n){
        rr+=a[i];
        if((l/2)<=rr){ll=rr;rr=l-ll;break;}
    }
    ans=min(ans,abs(rr-ll));
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
// Your code here!

use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main(){
    let n: usize = read();
    let hs: Vec<i32> = read_vec();
    
    let mut cnt:i32 = 0;
    let mut mx:i32 = 0;
    
    for i in 0..n{
        if mx<=hs[i]{
            cnt+=1;
            mx=hs[i];
        }
    }
    println!("{}",cnt)
    
    
}




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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

#define M 10000

int main()
{
    ll H, N;
    cin >> H >> N;
    vec A(N), B(N);
    REP(i,0,N) cin >> A[i] >> B[i];

    mat dp(N+1, vec(H+1, INF));
    dp[0][0] = 0;
    REP(i,0,N) {
        REP(j,0,H+1) {
            dp[i+1][j] = MIN(dp[i+1][j],dp[i][j]);
            dp[i+1][MIN(j+A[i],H)] = MIN(dp[i+1][MIN(j+A[i],H)],dp[i+1][j]+B[i]);
        }
    }

    PR(dp[N][H]);

    return 0;
}

/*



*/

Measured memory_bytes: 81648
#include<iostream>
#include<cstdio>
#include<stdio.h>
using namespace std;
int main() {
	char ch,x;
	int ans,  num, counter[100] = {}, i, j;
	while(cin >> ch) {
		if (ch>='A' && ch<='Z') {
			ch += 'a' - 'A';
		}
		num = ch - 'a';
		counter[num]++;
	}
	for (i = 0; i < 26; i++) {
		x = i + 'a';
		ans = counter[i];
		cout << x << " : " << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int L = 1e7;
const int M = 30;

bool p[L];

void make_p(){
  REP(i, L) p[i] = true;
  p[0] = p[1] = false;
  for(int i = 2; i * i <= L; ++i){
    if(!p[i]) continue;
    for(int j = i + i; j < L; j += i) p[j] = false;
  }
}

int main() {
  make_p();
  int N, P;
  while(cin >>N >>P && N != -1){
    vector<int> _p(M), v;
    for(int i = N + 1, cnt = 0; cnt < M; ++i) if(p[i]) _p[cnt++] = i;
    REP(i, M) FOR(j, i, M) v.push_back(_p[i] + _p[j]);
    SORT(v);
    cout <<v[P - 1] <<endl;
  }
  return 0;
}

Measured memory_bytes: 10988
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}



template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WG = vector< Edges< T > >;
using UG = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n,m;
  cin>>n>>m;
  UG es(n);
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    es[a].PB(b);
  }

  int ans=inf;
  vi res;
  rep(s,n){
    vi dist(n,-1);
    vi prev(n,-1);
    queue<int> q;
    q.push(s);
    dist[s]=0;
    while(!q.empty()){
      int v=q.front(); q.pop();
      for(int e:es[v]){
        if(dist[e]!=-1) continue;
        dist[e]=dist[v]+1;
        prev[e]=v;
        q.push(e);
      }
    }

    rep(t,n){
      if(t==s||dist[t]==-1) continue;
      for(int e:es[t]){
        if(e!=s) continue;
        vi tmp;
        tmp.PB(s);
        int cur=t;
        while(cur!=s){
          tmp.PB(cur);
          cur=prev[cur];
        }
        if(ans>tmp.size()){
          ans=tmp.size();
          res=tmp;
        }
      }
    }
  }

  if(ans==inf) cout<<-1<<endl;
  else{
    cout<<ans<<endl;
    rep(i,res.size()){
      cout<<res[i]+1<<endl;
    }
  }


}

Measured memory_bytes: 384
import java.util.*;

public class Main {

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

	public void execute() {
		Scanner sc = new Scanner(System.in);

		final int N = sc.nextInt();
		final int A = sc.nextInt();
		final int B = sc.nextInt();
		final int C = sc.nextInt();

		int[] l = new int[N];
		for (int i = 0; i < N; i++) {
			l[i] = sc.nextInt();
		}

		int minMp = 100000;
		for (int ptn = 1, bound = 1 << (N * 2); ptn < bound; ptn++) {
			int mp = 0;
			int a, b, c;
			a = b = c = 0;
			int ac, bc, cc;
			ac = bc = cc = 0;
			for (int i = 0; i < N; i++) {
				int mask = 3 << i*2;
				int usage = (ptn & mask) >> i*2;
				switch (usage) {
				case 0:
					break;
				case 1:
					a += l[i];
					if (ac++ > 0) {
						mp += 10;
					}
					break;
				case 2:
					b += l[i];
					if (bc++ > 0) {
						mp += 10;
					}
					break;
				case 3:
					c += l[i];
					if (cc++ > 0) {
						mp += 10;
					}
					break;
				}
			}
			if (ac > 0 && bc > 0 && cc > 0) {
				mp += Math.abs(a - A) + Math.abs(b - B) + Math.abs(c - C);
				minMp = Math.min(mp, minMp);
			}
		}

		System.out.println(minMp);
		sc.close();
	}

}

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

using namespace std;

int H,W;
bool tab[501][501], rt[501][501], bt[501][501];


int main()
{
    scanf("%d %d",&H,&W);
    getchar();
    for(int i = 0; i<H; ++i)
    {
        for(int j = 0; j<W; ++j)
        {
            if( getchar() == '#' )
                tab[i][j] = rt[i][j] = bt[i][j] = 1;
        }
        getchar();
    }

    for(int i = 0; i<H; i += 2 ) for(int j = 0; j<W-1; ++j)
        rt[i][j] = 1;
    for(int i = 0; i<H; ++i) rt[i][0] = 1;

    for(int i = 1; i<H; i += 2 ) for(int j = 1; j<W; ++j)
        bt[i][j] = 1;
    for(int i = 0; i<H; ++i) bt[i][W-1] = 1;

    for(int i = 0; i<H; ++i)
    {
        for(int j = 0; j<W; ++j)
            putchar(rt[i][j]?'#':'.');
        puts( "" );
    }

    puts( "" );

    for(int i = 0; i<H; ++i)
    {
        for(int j = 0; j<W; ++j)
            putchar(bt[i][j]?'#':'.');
        puts( "" );
    }
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <stdlib.h>
using namespace std;

int main()
{
  int a, b, c, d;

  cin >> a >> b >> c >> d;

  if (abs(a-c) <= d) cout << "Yes" << endl;
  else if (abs(a-b) <= d && abs(b-c) <= d) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

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

using namespace std;

#define int long long

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

const int mod = 1e9 + 7;

int N, C;
int A[405], B[405];
int Sum[405][405];

int dp[405][405];

signed main()
{
    cin >> N >> C;

    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];

    for (int i = 0; i < N; ++i) {
        for (int k = A[i]; k <= B[i]; ++k) {
            int v = 1;

            for (int j = 0; j <= C; ++j) {
                (Sum[i][j] += v) %= mod;
                (v *= k) %= mod;
            }
        }
    }

    for (int i = 0; i <= C; ++i) {
        dp[0][i] = Sum[0][i];
    }

    for (int i = 1; i < N; ++i) {
        for (int j = 0; j <= C; ++j) {
            for (int k = 0; k <= C - j; ++k) {
                (dp[i][j + k] += dp[i - 1][j] * Sum[i][k]) %= mod;
            }
        }
    }

    cout << dp[N - 1][C] << endl;
}


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

int main() {
	int n;
	cin >> n;
	string arr[n];
	int c1 = 0, c2 = 0, c3 = 0, c4 = 0;

	std::map<string, int> map;
	while (n--) {
		string input;
		cin >> input;
		if (input == "AC")
			c1++;
		if (input == "WA")
			c2++;
		if (input == "TLE")
			c3++;
		if (input == "RE")
			c4++;


	}
	cout << "AC " << "x " << c1 << endl;
	cout << "WA " << "x " << c2 << endl;
	cout << "TLE " << "x " << c3 << endl;
	cout << "RE " << "x " << c4 << endl;


}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

const int MOD = 1000000007;

inline void add(int &a, int b) {
    a += b;
    if (a >= MOD) {
       a -= MOD;
   }
}

inline void sub(int &a, int b) {
    a -= b;
    if (a < 0) {
       a += MOD;
   }
}

inline int mul(int a, int b) {
    return (long long) a * b % MOD;
}

inline int power(int a, int b) {
    int res = 1;

    while (b > 0) {
        if (b & 1) res = mul(res, a);
        b >>= 1;
        a = mul(a, a);
    }

    return res;
}

inline int inverse(int x) {
    return power(x, MOD - 2);
}

int way[1010][1010];
string s[1010];

int main() {
    int h, w; cin >> h >> w;
    rep(i, h) cin >> s[i];

    way[0][0] = 1;
    rep(i, h) {
        rep(j, w) {
            if (s[i][j] == '.' && i + 1 < h && s[i+1][j] == '.') {
                add(way[i+1][j], way[i][j]);
            }
            if (s[i][j] == '.' && j + 1 < w && s[i][j+1] == '.') {
                add(way[i][j+1], way[i][j]);
            }
        }
    }
    cout << way[h-1][w-1] << endl;
	return 0;
}

Measured memory_bytes: 5248
import java.util.*

fun main(args: Array<String>) {
    val N = nextInt()
    nextLine()
    val A = IntArray(N) { nextInt() }
    val C = IntArray(N + 1)
    var total = 0L
    A.forEach { a ->
        total += C[a]
        C[a]++
    }
    println(buildString {
        A.forEach { a ->
            append(total - (C[a] - 1)).append("\n") // - nC2 + (n-1)C2 = -(n-1)
        }
    })
}

val scanner = Scanner(System.`in`)
fun next(): String = scanner.next()
fun nextInt() = scanner.nextInt()
fun nextLong() = scanner.nextLong()
fun nextLine() = scanner.nextLine()
fun nextList() = nextLine().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun printYesNo(isYes: Boolean) = println(if (isYes) "Yes" else "No")

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

namespace Algo
{
    class Program
    {
        static void Main()
        {
            var n = long.Parse(Console.ReadLine()!);
            var count = new long[10, 10];
            for (var i = 1L; i <= n; i++)
            {
                var (top, bottom) = (0L, 0L);
                var tmp = i.ToString();
                foreach (var c in tmp.Where(c => c != '0'))
                {
                    top = c - '0';
                    break;
                }

                bottom = i % 10;
                count[top, bottom]++;
            }
            var ans = 0L;
            for (var i = 1L; i <= n; i++)
            {
                var (top, bottom) = (0L, 0L);
                var tmp = i.ToString();
                top = i % 10;
                foreach (var c in tmp.Where(c => c != '0'))
                {
                    bottom = c - '0';
                    break;
                }
                ans += count[top, bottom];
            }
            Console.WriteLine(ans);
        }
    }
}

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

int main() {
int  K,N;
cin >> K >> N;
  int A[N];
  int max = 0;
  for(int i = 0;i < N;i++)cin >> A[i];
  for(int i = 1;i < N;i++){
   if(A[i] - A[i-1] > max){
    max = A[i] - A[i-1];
   }
  }
  
  if(A[0] + K - A[N-1] > max){
   max = A[0] + K - A[N-1];
  }
  
  
cout<< K - max <<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int aa[200001], bb[200001];
int main() {
	long long n, a, b, ans = 0; cin >> n;
	for (int h = 0; h <= n; h++) {
		cin >> a;
		aa[h] = a;
	}
	for (int h = 0; h < n; h++) {
		cin >> b;
		bb[h] = b;
	}
	for (int h = 0; h < n; h++) {
		if (bb[h] >= aa[h] + aa[h + 1]) {
			ans += aa[h] + aa[h + 1];
			aa[h + 1] = 0;
		}
		else if (bb[h] < aa[h]) {
			ans += bb[h];
		}
		else {
			ans += bb[h];
			aa[h + 1] = aa[h + 1] - (bb[h] - aa[h]);
		}
	}
	cout << ans << endl;
	cin >> n;
}


Measured memory_bytes: 1024
A11, A12, A13 = map(int, input().split())
A21, A22, A23 = map(int, input().split())
A31, A32, A33 = map(int, input().split())
N = int(input())
B = [int(input()) for _ in range(N)]

if (A11 in B and A12 in B and A13 in B) or \
    (A21 in B and A22 in B and A23 in B) or \
    (A31 in B and A32 in B and A33 in B) or \
    (A11 in B and A21 in B and A31 in B) or \
    (A12 in B and A22 in B and A32 in B) or \
    (A13 in B and A23 in B and A33 in B) or \
    (A11 in B and A22 in B and A33 in B) or \
        (A13 in B and A22 in B and A31 in B):
    print("Yes")
else:
    print("No")


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

int main() {
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  int total = 0;

  for (int i = 0; i < n; i++) {
    if (i < k)
      total += x;
    else
      total += y;
  }

  cout << total << endl;
}

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

int main() {
  int A, B, C, D ;
  cin >> A >>B >> C >> D ;
  if (A+B >C+D ){
    cout << "Left" <<endl;
  }
  else if (A + B == C + D ){
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
 
   
    
   
  }

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

ll f(ll a, ll b) {
  if (a > b) swap(a, b);
  if (b % a == 0) {
    return 2 * a * (b / a) - a;
  } else {
    return 2 * a * (b / a) + f(b % a, a);
  }
}

int main() {
  ll n, x;
  cin >> n >> x;
  ll ans = n + f(x, n - x);
  cout << ans << endl;
  return 0;
}

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

void init(int n_){
	n = 1;
	while(n < n_) n *= 2;
	node.resize(2*n-1, 0);
}

void add(int x, int val) {
    x += (n - 1);
    node[x] += val;
    while(x > 0) {
        x = (x - 1) / 2;
        node[x] = node[2*x+1] + node[2*x+2];
    }
}

int getsum(int a, int b, int k=0, int l=0, int r=-1) {
    if(r < 0) r = n;
    if(r <= a || b <= l) return 0;
    if(a <= l && r <= b) return node[k];
    int vl = getsum(a, b, 2*k+1, l, (l+r)/2);
    int vr = getsum(a, b, 2*k+2, (l+r)/2, r);
    return (vl + vr);
}

int main(){
	int N, q; cin >> N >> q;
	init(N);
	rep(i, q){
		int c; cin >> c;
		int x, y; cin >> x >> y;
		if(c==0) add(x-1, y);
		else cout << getsum(x-1, y) << endl;
	}
}


Measured memory_bytes: 4872
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int N;
	cin >> N;
	for(int i=0;i<N;i++){
		int cnt[8];
		for(int j=0;j<8;j++){
			cnt[j]=0;
		}
		int cnt0=0;
		cin >> cnt0;
		cnt[0]=cnt0/10000000;
		cnt0=cnt0-cnt[0]*10000000;
		cnt[1]=cnt0/1000000;
		cnt0=cnt0-cnt[1]*1000000;
		cnt[2]=cnt0/100000;
		cnt0=cnt0-cnt[2]*100000;
		cnt[3]=cnt0/10000;
		cnt0=cnt0-cnt[3]*10000;
		cnt[4]=cnt0/1000;
		cnt0=cnt0-cnt[4]*1000;
		cnt[5]=cnt0/100;
		cnt0=cnt0-cnt[5]*100;
		cnt[6]=cnt0/10;
		cnt0=cnt0-cnt[6]*10;
		cnt[7]=cnt0;				//配列に格納
		sort(cnt,cnt+8);			//ソート
		int cntH,cntL;
		cntH=0;cntL=0;
		cntH=cnt[0];
		cntH=cnt[1]*10+cntH;
		cntH=cnt[2]*100+cntH;
		cntH=cnt[3]*1000+cntH;
		cntH=cnt[4]*10000+cntH;
		cntH=cnt[5]*100000+cntH;
		cntH=cnt[6]*1000000+cntH;
		cntH=cnt[7]*10000000+cntH;

		cntL=cnt[7];
		cntL=cnt[6]*10+cntL;
		cntL=cnt[5]*100+cntL;
		cntL=cnt[4]*1000+cntL;
		cntL=cnt[3]*10000+cntL;
		cntL=cnt[2]*100000+cntL;
		cntL=cnt[1]*1000000+cntL;
		cntL=cnt[0]*10000000+cntL;
		cout << cntH-cntL<<endl;
	}
}

Measured memory_bytes: 1176
import java.util.Scanner;

public class Main {

    public static void main (String[] args) {

        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        boolean isPossible = false;

        for (int i = 0; i < b; i++) {
            if ( (i*a % b) == c) {
                isPossible = true;
                break;
            }
        }

        if (isPossible){
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }



    }

}





Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 1e9
typedef long long ll;

int main()
{
    int n;
    cin>>n;
    vector<pair<int,pair<int,int> > > p(n+1);
    REP(i,n+1){
        if(i==0){
            p[i]=make_pair(0,make_pair(0,0));
            continue;
        }
        int a,b,c;
        cin>>a>>b>>c;
        p[i]=make_pair(a,make_pair(b,c));
    }

    bool f=1;
    REP2(i,1,n+1){
        int l=abs(p[i].second.first-p[i-1].second.first)+abs(p[i].second.second-p[i-1].second.second),t=p[i
        ].first-p[i-1].first;
        if(l>t){
            f=0;
            break;
        }else if((t-l)%2){
            f=0;
            break;
        }
    }

    cout<<(f? "Yes":"No")<<endl;

	return 0; 
}


Measured memory_bytes: 1408