akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace ITP1_6_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] size = Console.ReadLine().Split(' ');
            var n = int.Parse(size[0]);
            var m = int.Parse(size[1]);
            int i = 0;
            int[][] matrix = new int[n][];
            int[] vector = new int[m];
            for(i = 0; i < n; i++)
                matrix[i] = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            for (i = 0; i < m; i++)
                vector[i] = int.Parse(Console.ReadLine()); 
            foreach(var mat in matrix)
            {
                int result = 0;
                for (i = 0; i < m; i++)
                    result += mat[i] * vector[i];
                Console.WriteLine(result);
            }
        }
    }
}

Measured memory_bytes: 9812
package main

import (
	"fmt"
)

func main() {
	var w, h, x, y, flag int
	var res float64
	fmt.Scanf("%d %d %d %d", &w, &h, &x, &y)

	res = float64(w) * float64(h) / 2

	if x+x == w && y+y == h {
		flag = 1
	} else {
		flag = 0
	}

	fmt.Printf("%f %d", res, flag)
}


Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)


int main() {
	int n, m;
	cin >> n >> m;
	if (n == m)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 888
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
		}
		
		sc.close();
		
		int[] dp = new int[100010];
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		dp[0] = 0;
		dp[1] = Math.abs(h[0]-h[1]);
		for(int i=2;i<N;i++) {
			chmin(dp, i, dp[i-2]+(Math.abs(h[i]-h[i-2])));
			chmin(dp, i, dp[i-1]+(Math.abs(h[i]-h[i-1])));
		}
		
		out.println(dp[N-1]);

	}
	
	private boolean chmin(int[] arr, int i, int b) {
		if(arr[i] > b) {
			arr[i] = b;
			return true;
		}
		return false;
	}

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

}


Measured memory_bytes: 49000
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#define mod 1777777777
using namespace std;
typedef long long ll;
typedef string::iterator itr;
ll conbi(ll, ll);
ll gcd(ll, ll);
ll kkrn(ll);
int solve(itr,itr);

string s;


int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n;i++) {
		cin >> s;

		int ans = solve(s.begin(),s.end());
		cout << ans << endl;
	}	
	return 0;	
}
int solve(itr head, itr tail) {
	vector<int> cost;
	int n = 0;
	itr a, b;
	int k = 0;
	for (itr i = head+1; i != tail-1; i++) {
		if (*i=='[') {
			if (n == 0) {
				a = i;
			}
			n++;
		}
		else if (*i == ']') {
			n--;
			if (n == 0) {
				int x = solve(a, i+1);
				cost.push_back(x);
			}
		}
		else if(n==0){
			
			k = k * 10 + (int)(*i - '0');

		}
	}
	if (k != 0)return 1+k/2;
	sort(cost.begin(), cost.end());
	int ans = 0;
	for (int i = 0; i <= (cost.size() / 2); i++)ans += cost[i];
	return ans;
}
/*




ll conbi(ll a, ll b) {
	if (b % 2 == 0) {

	}
}
ll gcd(ll a, ll b) {
	while (true) {
		if (a == b) return a;
		ll c;
		if (a > b) {
			c = a;
			a = b;
			b = c;
		}
		b = b % a;
		if (b == 0)return a;
	}
}

vector<ll> dp(1000000,-1);

ll kkrn(ll x) {
	if (dp[x] != -1)return dp[x];
	if (x < 2)return 0;
	if (x == 2)return 1;
	ll ans = ((x - 1)*kkrn(x - 1)) % mod + ((x - 1)*kkrn(x - 2)) % mod;
	dp[x] = ans;
	return ans;
}*/

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	//input
	int N, K;
	cin >> N >> K;
	vector<ll> x(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}

	ll tmp, min_t = INF;
	for (int i = 0; i < N - K + 1; i++) {
		tmp = min(abs(x[K + i - 1]), abs(x[i])) + x[K + i - 1] - x[i];
		if (min_t > tmp) {
			min_t = tmp;
		}
	}
	cout << min_t;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define int ll
#define JMD ios_base::sync_with_stdio(0),cin.tie(0)
using namespace std;

const ll N = 3e5+100;
const ll MOD = 1e9+7;
const ll INF = 1e10;
ll dp[52][2505][52];
// dp[idx][sum][indexes]
signed main()
{	
	JMD;
	ll n,k;
	cin>>n>>k;

	ll a[n+1];
	ll maxsum=0;
	vll aa;
	set<ll> se;
	for(int i = 1;i<=n;i++){
		cin>>a[i];
	//	se.insert(a[i]);
		maxsum+=a[i];
		aa.pb(a[i]);
	}		

		
	dp[0][0][0] = 1;	
	for(int i =1;i<=n;i++)dp[i][0][0]=1;
	for(int i =1;i<=n;i++){
		for(int j = 1;j<=maxsum;j++){
			for(int k = 1;k<=n;k++){
					if(j >= a[i])
						dp[i][j][k] += dp[i-1][j-a[i]][k-1];
					dp[i][j][k] += dp[i-1][j][k];
					//dp[i][j][k] = dp[i][j][k][0];dp[i][j][k][2] += dp[i][j][k][1];
				
				
			}
		}}
	

	ll ans =0;
	for(int s=0;s<=maxsum;s++){
	for(int i =1;i<=n;i++){
		ll xd = s;
		if(xd%i!=0)continue;
		xd/=(ll)i;

		if(xd != k)continue;
	//	cout<<s<<' '<<i<<" "<<dp[n][s][i]<<endl;
		ans+=dp[n][s][i];
	}}

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

Measured memory_bytes: 51200
# input() to take in input
n, m = map(int, input().split())
hs = list(map(int, input().split()))
 
edge = [[] for _ in range(n)]
 
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)
 
cnt = 0
 
for node in range(n):
    good = True
    for neighbor in edge[node]:
        if hs[node] <= hs[neighbor]:
            good = False
    if good:
        cnt += 1
 
print(cnt)

Measured memory_bytes: 29476
#include <stdio.h>
#define limit 1000000

int top = 0;
int bottom = 0;

int que[limit];

void push(int x){
  que[bottom++] = x;
}

int pop(){
  if(bottom <= top) return -1;
  return que[top++];
}

int max(int a,int b){
  if(a > b){
    return a;
  }
  return b;
}

int vx[4] = {0,0,-1,1};
int vy[4] = {1,-1,0,0};

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

  char S[H][W+1];
  int visited[H][W];
  for(int i = 0;i < H;i++) scanf("%s",S[i]);

  int ans = 0;
  for(int i = 0;i < H;i++){
    for(int j = 0;j < W;j++){
      if(S[i][j] == '#'){
        visited[i][j] = 1;
        push(i*1000+j);
      }else{
        visited[i][j] = 0;
      }
    }
  }

  while(1){
    int data = pop();
    if(data == -1) break;
    int x = data/1000;
    int y = data%1000;

    for(int i = 0;i < 4;i++){
      int xx = x+vx[i];
      int yy = y+vy[i];
      if(0 <= xx && xx < H && 0 <= yy && yy < W){
        if(visited[xx][yy] == 0){
          push(xx*1000+yy);
          visited[xx][yy] = visited[x][y]+1;
        }
      }
    }
  }

  for(int i = 0;i < H;i++){
    for(int j = 0;j < W;j++){
      ans = max(ans,visited[i][j]);
    }
  }

  printf("%d\n",ans-1);

  return 0;
}

Measured memory_bytes: 8960
#include <iostream>
#include <map>
#include <cstdio>
#include <utility>
using namespace std;

int main(){
	int n;	
	for(;cin >> n, n;){
		int mn, d, h, m, id;
		char io;
		int pmn, pd, ph, pm, pio, pid;
		bool p[1000];
		int tt[1000];
		for(int x = 0; x < 1000; x++){
			p[x] = false;
			tt[x] = 0;
		}
		scanf(" %d/%d %d:%d %c %d",
			&pmn, &pd, &ph, &pm, &pio, &pid);
		p[pid] = true;
		for(int x = 1; x < n; x++){
			scanf(" %d/%d %d:%d %c %d",
				&mn, &d, &h, &m, &io, &id);
			if( p[0] ){
				for(int y = 1; y < 1000; y++){
					if( p[y] ){
						tt[y] += (h-ph)*60+(m-pm);
					}
				}
			}
			if(io == 'I'){
				p[id] = true;
			}
			if(io == 'O'){
				p[id] = false;
			}
			pmn = mn; pd = d; ph = h; pm = m; pio = io; pid = id;
		}
		int m_t = 0;
		for(int x = 1; x < 1000; x++){
			if( tt[x] > m_t ){
				m_t = tt[x];
			}
		}
		printf("%d\n", m_t);
	}
	return 0;
}

Measured memory_bytes: 1232
n = int(input())
s = input()

ruiseki_r = [0] * (n + 1)
ruiseki_g = [0] * (n + 1)
ruiseki_b = [0] * (n + 1)

for i in range(n):
    ruiseki_r[i + 1] = ruiseki_r[i]
    ruiseki_g[i + 1] = ruiseki_g[i]
    ruiseki_b[i + 1] = ruiseki_b[i]
    if s[i] == "R":
        ruiseki_r[i + 1] += 1
    if s[i] == "G":
        ruiseki_g[i + 1] += 1
    if s[i] == "B":
        ruiseki_b[i + 1] += 1
  
ans = 0
for i in range(n):
    if s[i] == "R":
        ans += ruiseki_g[i] * (ruiseki_b[n] - ruiseki_b[i + 1])
        ans += ruiseki_b[i] * (ruiseki_g[n] - ruiseki_g[i + 1])
    if s[i] == "G":
        ans += ruiseki_r[i] * (ruiseki_b[n] - ruiseki_b[i + 1])
        ans += ruiseki_b[i] * (ruiseki_r[n] - ruiseki_r[i + 1])
    if s[i] == "B":
        ans += ruiseki_r[i] * (ruiseki_g[n] - ruiseki_g[i + 1])
        ans += ruiseki_g[i] * (ruiseki_r[n] - ruiseki_r[i + 1])
for i in range(n):
    if s[i] == "R":
        for length in range(1, n + 10):
            if i - length < 0 or i + length >= n:
                break
            elif s[i - length] == "G" and s[i + length] == "B":
                ans -= 1
            elif s[i - length] == "B" and s[i + length] == "G":
                ans -= 1
                
    if s[i] == "B":
        for length in range(1, n + 10):
            if i - length < 0 or i + length >= n:
                break
            elif s[i - length] == "R" and s[i + length] == "G":
                ans -= 1
            elif s[i - length] == "G" and s[i + length] == "R":
                ans -= 1
                
    if s[i] == "G":
        for length in range(1, n + 10):
            if i - length < 0 or i + length >= n:
                break
            elif s[i - length] == "B" and s[i + length] == "R":
                ans -= 1
            elif s[i - length] == "R" and s[i + length] == "B":
                ans -= 1
print(ans)

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

#define fi first
#define se second

const int N = 1001;
const int Q = 10000010;

using namespace std;

int main()
{
        ios_base::sync_with_stdio(0);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        int n;
        cin >> n;
        vector < int > a(n);
        for(int i = 0; i < n; i++){
                cin >> a[i];
        }
        sort(a.begin(), a.end());
        long long res = 0;
        vector < int > v;
        for(int i = 0; i < n; i++){
                if(i + 1 < n && a[i] == a[i + 1]){
                        v.push_back(a[i]);
                        i += 1;
                }
        }
        if(v.size() > 1){
                res = 1ll * v[v.size() - 1] * v[v.size() - 2];
        }
        cout << res << "\n";
}


Measured memory_bytes: 1024
// not finished triangles triangles triangles triangles triangles triangles 

#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>

#define nl '\n'

using namespace std;

int a, b, c;

int main(){

    cin >> a >> b >> c;

    if(b-a == c-b){
        cout << "YES";
        return 0;
    }

    cout << "NO";







}

//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out

Measured memory_bytes: 256
def prim(s)
	mst = [s]
	sum = 0
	while mst.size != $n
		list = []
		mst.each do |u|
			list.push($m[u].map.with_index{|val,ix|mst.include?(ix) ? Float::INFINITY : val})
		end
		min = Float::INFINITY; min_i = nil
		list.each do |wv|
			wv.each_with_index do |w,i|
				if w < min
					min = w; min_i = i;
				end
			end
		end
		mst.push(min_i)
		sum += min
	end
	return sum
end

$n = gets.chomp.to_i
$m = []
$n.times do |i|
	$m[i] = gets.chomp.split(" ").map{|val|val.to_i == -1 ? Float::INFINITY : val.to_i}
end

puts prim(0)


Measured memory_bytes: 9564
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<double> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  double cu=0;
  for(int i=0;i<n;i++){
    cu+=1/a[i];
  }
  cout<<fixed<<setprecision(10);
  cout<<1/cu<<endl;
}

Measured memory_bytes: 256
#include <iostream>

int gcd( int a, int b )
{
  if( a < b ) { return gcd( b, a ); }
  if( b > 0 ) { return gcd( b, a % b ); }
  return a;
}

int main()
{
  std::ios::sync_with_stdio( false );
  int a = 0, b = 0;
  std::cin >> a; std::cin.ignore();
  std::cin >> b;

  std::cout << gcd( a, b ) << std::endl;
}

Measured memory_bytes: 1192
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n, m, q;
ll l;
ll g[305][305];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m >> l;

  REP(i, n) REP(j, n) {
    if(i == j) g[i][j] = 0;
    else g[i][j] = LLINF;
  }

  REP(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    g[a][b] = c;
    g[b][a] = c;
  }

  vector<vector<PLL>> d(305, vector<PLL>(305, make_pair(LLINF, LLINF)));

  REP(s, n) {
    priority_queue<pair<PLL, int>, vector<pair<PLL, int>>, greater<pair<PLL, int>>> que;
    d[s][s] = {0, 0};
    que.push({{0, 0}, s});

    while (!que.empty()) {
      pair<PLL, int> p = que.top(); que.pop();
      int v = p.second;
      ll kaisu = p.first.first;
      ll used = p.first.second;
      if(d[s][v] < p.first) continue;

      REP(nv, n) if(v != nv) {
        if (g[v][nv] > l) continue;
        ll nused = used + g[v][nv];

        PLL np = {0, 0};
        if(nused > l) {
          np = {kaisu + 1, g[v][nv]};
        } else {
          np = {kaisu, nused};
        }

        if(d[s][nv] > np) {
          d[s][nv] = np;
          que.push({np, nv});
        }
      }
    }
  }

  cin >> q;
  REP(i, q) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    ll res = d[a][b].first;
    if(res == LLINF) cout << -1 << endl;
    else cout << res << endl;
  }
}


Measured memory_bytes: 6920
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef pair<int,int>   ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef set<int>        si;
typedef set<ii>         sii;

#define all(x) x.begin(),x.end()
#define clr(x,v) memset(x,v,sizeof x)
#define sz(x) (int)x.size()
#define re return


template<typename T> T sgn (T x)      {re x<0? -1:(x>0? 1:0); }
template<typename T> T gcd (T a, T b) {re a ? gcd (b % a, a) : b; }
template<typename T> T abs (T x)      {re x < 0 ? -x : x; }
template<typename T> T sqr (T x)      {re x*x;}

#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define ins insert
#define y second
#define x first
#define endl "\n"
#define MOD (int)1e9+7
#define N (int)2e5+123



void solve(){
	
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    vector<int> mh(n, 0);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        mh[a-1] = max(mh[a-1], h[b-1]);
        mh[b-1] = max(mh[b-1], h[a-1]);
    }
    
    int n_good = 0;
    for (int i = 0; i < n; i++)
    {
        if(h[i] > mh[i]){
            n_good++;
        }
    }
    
    cout << n_good << endl;
}
int main(){_
    solve();
}

Measured memory_bytes: 3988
#include<stdio.h>
int main()
{
    long long int x1,x2,x3,x4,x5;
    scanf("%lld %lld %lld %lld %lld",&x1,&x2,&x3,&x4,&x5);
    if(x1==0)
        printf("1");
    else if(x2==0)
        printf("2");
    else if(x3==0)
        printf("3");
    else if(x4==0)
        printf("4");
    else
        printf("5");
    return 0;
}

Measured memory_bytes: 1624
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
main(){
  int n,sum=0;
  cin>>n;
  int a[n];
  r(i,n)cin>>a[i];
  sort(a,a+n);
  int p;
  cin>>p;
  while(p--){
    int x;
    cin>>x;
    int l=0,r=n;
    while(l<r){
      int mid=(l+r)/2;
      if(a[mid]==x){sum++;break;}
      if(a[mid]>x)r=mid;
      else l=mid+1;
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3156
# -*- coding utf-8 -*-

MOD = 10 ** 9 + 7

n, k = map(int, input().split())

ans = 0
for i in range(1, n + 1):
    p = 1 / n
    while i <= k - 1:
        i *= 2
        p *= 1/2
    ans += p

print(ans)



Measured memory_bytes: 2940
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int n;
    cin>>n;
    priority_queue<int> hoge;
    int ans=0;
    
    for(int i=0;i<n;i++){
        int fuga;
        cin>>fuga;
        hoge.push(fuga);
    }
    
    ans+=hoge.top()/2;
    hoge.pop();
    
    while(!hoge.empty()){
        ans+=hoge.top();
        hoge.pop();
    }
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import collections
while True:
    c = int(input())
    if c == 0:
        break
    n = list(map(str, input().split()))
    count = collections.Counter(n)
    rank = count.most_common()
    canditate1 = rank[0][0]
    vote1 = rank[0][1]
    if len(count) == 1:
        answer = int(c / 2) + 1
        print(canditate1, answer)
    elif vote1 == rank[1][1]:
        print("TIE")
    else:
        number = 0
        answer = 0
        while True:
            if len(collections.Counter(n[0:answer]).most_common()) < 2:
                if number > c / 2:
                    break
            else:
                if number > c - answer + collections.Counter(n[0:answer]).most_common()[1][1]:
                    break
            answer += 1
            if n[answer - 1] == canditate1:
                number += 1
        print(canditate1, int(answer))


Measured memory_bytes: 6004
N, K, Q, *A = map(int, open(0).read().split())

ans = float("inf")
for Y in A:
    C = []
    tmp = []
    for a in A:
        if a >= Y:
            tmp.append(a)
        else:
            if len(tmp) >= K:
                C += sorted(tmp)[:len(tmp) - K + 1]
            tmp = []
    if len(tmp) >= K:
        C += sorted(tmp)[:len(tmp) - K + 1]

    if len(C) >= Q:
        C.sort()
        X = C[Q - 1]
        ans = min(ans, X - Y)

print(ans)


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

//ARC003-A-Wanna go back home
//http://agc003.contest.atcoder.jp/tasks/agc003_a
class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("SENW");
            //Yes
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("NSNNSNSN");
            //Yes
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("NNEW");
            //No
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("W");
            //No
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string S = InputList[0];

        bool HasN = S.Contains('N');
        bool HasW = S.Contains('W');
        bool HasS = S.Contains('S');
        bool HasE = S.Contains('E');

        bool IsYes = true;

        if (HasN && HasS == false) IsYes = false;
        if (HasN == false && HasS) IsYes = false;

        if (HasW && HasE == false) IsYes = false;
        if (HasW == false && HasE) IsYes = false;

        Console.WriteLine(IsYes ? "Yes" : "No");
    }
}


Measured memory_bytes: 2904
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

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

int main(void){
  int n;
  while(cin>>n){
    if(n==0)break;
    vector<P> data;
    REP(i,n){
      int a,b;
      cin>>a>>b;
      data.push_back(P(b,a));
    }
    sort(data.begin(),data.end());
    int s=0;
    bool f= false;
    REP(i,data.size()){
      s+=data[i].second;
      if(s>data[i].first){
        f=true;
        break;
      }
    }
    if(f) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
  }

  return 0;
}

Measured memory_bytes: 0
K = int(input())
a = [i+1 for i in range(9) ] # 生成後の値を列挙する
old_a = []

while True:
    a = list(set(a))
    if K <= len(a):
        a = sorted(a)
        break
    
    old_a = a.copy()
    for x in old_a:
        for i in range(-1,2):
            d = int(x%10) + i
            if (d < 0) or (d > 9):
                continue
            nx = x*10 + d
            a.append(nx)

print(a[K-1])


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

int l, r, d;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> l >> r >> d;
    int ans = 0;
    for(int i = 1; i <= 100; i++)
        ans += (d * i >= l && d * i <= r);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3588
import java.util.*;

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

        String S = sc.nextLine();
        long K = sc.nextLong();

        for (int i = 0; i <= K - 1; i++) {
            if (S.charAt(i) != '1') {
                System.out.println(S.charAt(i));
                return;
            }
        }

        System.out.println('1');
    }
}

Measured memory_bytes: 21844
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int N;
  scanf("%d", &N);
  static int H[200001];
  for (auto i = 1; i <= N; ++i)
    scanf("%d", &H[i]);
  static int A[200001];
  for (auto i = 1; i <= N; ++i)
    scanf("%d", &A[i]);
  static long long F[200001];
  auto fupd = [&](int k, long long v) {
    while (k <= N) {
      F[k] = max(F[k], v);
      k += k & -k;
    }
  };
  auto fqry = [&](int k) {
    auto res = 0ll;
    while (k) {
      res = max(res, F[k]);
      k -= k & -k;
    }
    return res;
  };
  auto res = 0ll;
  for (auto i = 1; i <= N; ++i) {
    auto tmp = fqry(H[i]) + A[i];
    fupd(H[i], tmp);
    res = max(res, tmp);
  }
  printf("%lld\n", res);
  return 0;
}


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

int main(){
	int N,P,x = 0;
	cin >> N;
	P = N;
	
	while (N > 0){
		x = x + (N % 10);
		N = N / 10;
	}
	
	if ((P % x) == 0){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}


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

using namespace std;

int main() {
    int n, p;
    while (cin >> n >> p, n | p) {
        vector<int> stones(n, 0);
        int cur = 0, bowl = p;
        while (1) {
            if (!bowl) {
                swap(bowl, stones[cur]);
                cur = (cur < n - 1) ? cur + 1 : 0;
                continue;
            }
            bowl--;
            stones[cur]++;
            if (!bowl && stones[cur] == p) {
                cout << cur << endl;
                break;
            }
            cur = (cur < n - 1) ? cur + 1 : 0;
        }
    }
    return 0;
}

Measured memory_bytes: 1196
#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 x;
    cin >> x;
    while(1){
        bool ok = true;
        for(int i=2;i<x;++i){
            if(x%i==0){
                ok = false;
                break;
            }
        }
        if(ok) break;
        ++x;
    }
    cout << x << endl;
    return 0;
}


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

int main()
{
  int n, k; cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  sort(h.begin(),h.end());

  int ans = 1001001001;
  for (int i=0; i<n-k+1; i++) {
    ans = min(ans, h[i+k-1]-h[i]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
inp = input().split()

A = int(inp[0])
B=''
for b in inp[1]:
    if b!='.':
        B+=b
B=int(B)


ans_mat_100 = str(A*B)
if len(ans_mat_100)<3:
    print(0)
else:
    print(int(str(A*B)[:-2]))


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

int main() {
    int N, M, cnt = 0;
    long long int sum = 0;

    cin >> N >> M;
    vector <int> a(N);
    vector < pair<int, int> > m;

    for (int i = 0; i < N; i++) {
        cin >> a[i];
        sum += a[i];
    }

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

    for (int i = 0; i < M; i++) {
        int b, c;
        cin >> b >> c;
        m.push_back(make_pair(c, b));
    } 

    sort (m.begin(), m.end(), greater<pair<int,int> >());

    int k = 0;
    for (int i = 0; i < N; i++) {
        int cnt = 0;
        if (k >= m.size()) {
            break;
        }

        for(int j = i; j < i + m[k].second; j++) {
            if (j >= N) {
                break;
            }
            if (a[j] < m[k].first) {
                sum += m[k].first - a[j];
                cnt++;
            }
        }

        if (cnt < m[k].second) {
            break;
        }

        i += m[k].second - 1;
        k++;
    }

    cout << sum << endl;
}

Measured memory_bytes: 1784
#include "bits/stdc++.h"

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

using namespace std;
const int INF = 1 << 30;
const long long MOD = 1000000000 + 7;
const double PI = acos(-1);

int main() {
	int H, W; cin >> H >> W;
	vector<vector<char>> S(H, vector<char>(W));
	rep(i, H) {
		rep(j, W)cin >> S[i][j];
	}

	// 縦横それぞれで照らせるマスの数を保存
	vector<vector<int>> yoko(H, vector<int>(W));
	rep(i, H) {
		int head = 0;
		rep(j, W) {
			if (S[i][j] == '#') {
				rep2(k, head, j)yoko[i][k] = (j - head);
				head = j + 1;
			}
			else if (j == W - 1) {
				rep2(k, head, j + 1)yoko[i][k] = (j + 1 - head);
			}
		}
	}
	/*rep(i, H) {
		rep(j, W) {
			cout << yoko[i][j] << " ";
		}
		cout << endl;
	}*/

	vector<vector<int>> tate(H, vector<int>(W));
	rep(j, W) {
		int head = 0;
		rep(i, H) {
			if (S[i][j] == '#') {
				rep2(k, head, i)tate[k][j] = (i - head);
				head = i + 1;
			}
			else if (i == H - 1) {
				rep2(k, head, i + 1)tate[k][j] = (i + 1 - head);
			}
		}
	}
	/*cout << endl;
	rep(i, H) {
		rep(j, W) {
			cout << tate[i][j] << " ";
		}
		cout << endl;
	}*/
	int ans = 0;
	rep(i, H) {
		rep(j, W) {
			int num = yoko[i][j] + tate[i][j] - 1;
			if (ans < num)ans = num;
		}
	}
	cout << ans;
}

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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pii pair<ll, ll>
#define sz size()
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>void __f(const char* name, Arg1&& arg1){cout<<name<<" : "<<arg1<<"\n";}
template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args)
{const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" , ";__f(comma+1, args...);} 
#define traceloop(x,a) { cerr<<#a<<": "; for(ll ix=0;ix<x;ix++) cerr<<a[ix]<<" "; cerr<<endl; }
int main()
{
	ios::sync_with_stdio(0);
	int i, n, j;
	cin>>n;
	int a[n];
	vector<int> dp(n, 1e9+7);
	for(i=0;i<n;++i)
		cin>>a[i];

	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	for(i=2;i<n;++i)
	{
		dp[i] = min(dp[i-1] + abs(a[i]-a[i-1]), dp[i-2] + abs(a[i]-a[i-2]));
	}

	cout << dp[n-1] << "\n";

	return 0;
}

Measured memory_bytes: 1024
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [tuple(map(int, l.split())) for l in sys.stdin]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    x,y,z,k = LI()
    a = sorted(LI(), reverse=True)
    b = sorted(LI(), reverse=True)
    c = sorted(LI(), reverse=True)
    u = set()
    q = []
    heapq.heappush(q, (-(a[0]+b[0]+c[0]), 0,0,0))
    u.add((0,0,0))
    r = []
    for _ in range(k):
        t,ai,bi,ci = heapq.heappop(q)
        r.append(-t)
        if ai < x-1:
            nk = (ai+1,bi,ci)
            if nk not in u:
                heapq.heappush(q, (-(a[ai+1]+b[bi]+c[ci]), ai+1,bi,ci))
                u.add(nk)
        if bi < y-1:
            nk = (ai,bi+1,ci)
            if nk not in u:
                heapq.heappush(q, (-(a[ai]+b[bi+1]+c[ci]), ai,bi+1,ci))
                u.add(nk)
        if ci < z-1:
            nk = (ai,bi,ci+1)
            if nk not in u:
                heapq.heappush(q, (-(a[ai]+b[bi]+c[ci+1]), ai,bi,ci+1))
                u.add(nk)

    return '\n'.join(map(str, r))

print(main())




Measured memory_bytes: 7244
import java.util.Scanner;
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 = scan.nextInt();
		int K = scan.nextInt();
		int ans = 0;
		
		if(A < K) {
			for(int i=0;i<A;i++) {
				ans++;
			}
		}else {
			for(int j=0;j<K;j++) {
				ans++;
			}
		}
		if(B < K-A) {
			for(int i=0;i<K-A-B;i++) {
				ans--;
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 35704
#include<stdio.h>
int main()
{
	long long int n,i,count=0;
	scanf("%lld",&n);
        long long int p[n];
	for(i=0;i<n;i++)
	{
		scanf("%lld",&p[i]);
	}
	for(i=0;i<n-2;i++)
	{
		if((p[i]<p[i+1] && p[i+1]<p[i+2]) || (p[i]>p[i+1] && p[i+1]>p[i+2]))
		{
			count=count+1;
		}
	}
	printf("%lld\n",count);
	return 0;
}



Measured memory_bytes: 128
import java.io._
import scala.collection.mutable.{Map => MMap}
object Main extends App {
  val in = new StdinReader
  val N = in.nextInt
  val map = MMap[String, Int]().withDefault(_ => 0)
  (1 to N).foreach{i =>
    val s = in.next
    map.put(s, map(s) + 1)
  }

  val list = map.toList.sortWith((l, r) => if (l._2 == r._2) l._1 < r._1 else l._2 > r._2)
  val max = list.head._2
  val out = new PrintWriter(new BufferedOutputStream(System.out))
  list.takeWhile(_._2 == max).foreach(t => out.println(t._1))
  out.flush()
}

class StdinReader {
  val is = System.in
  val buffer = new Array[Byte](1024 * 1024)
  var size = 0
  var pos = 0

  private def readByte: Byte = {
    if (pos >= size) {
      pos = 0;
      size = is.read(buffer);
    }
    if (size < 0) -1
    else {
      val ret = buffer(pos)
      pos += 1
      ret
    }
  }

  // support single byte char only
  def next: String = {
    @scala.annotation.tailrec
    def r(sb: StringBuilder, reading: Boolean): String = {
      readByte match {
        case b if ('!' <= b && b <= '~') => r(sb.append(b.asInstanceOf[Char]), true)
        case _ => if (reading) sb.toString else r(sb, false)
      }
    }
    r(new StringBuilder, false)
  }

  def nextInt: Int = {
    @scala.annotation.tailrec
    def r(i: Int, reading: Boolean): Int = {
      readByte match {
        case '-' => r(i * -1, true)
        case b if '0' <= b && b <= '9' => r(i * 10 + (b - '0'), true)
        case _ => if (reading) i else r(i, false)
      }
    }
    r(0, false)
  }
}

Measured memory_bytes: 96640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);

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

  int ans = 3 * r * r;

  cout << ans << endl;

  return 0;
}

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

const int INF = 2e9;

int main(){
    ll n,k;
    cin >> n >> k;
    vector<pii> x(n);
    rep(i,n){
        int a,b;
        cin >> a >> b;
        x[i].first = a;
        x[i].second = b;
    }
    sort(x.begin(),x.end());
    rep(i,n){
        k -= x[i].second;
        if(k <= 0){
            cout << x[i].first << endl;
            return 0;
        }
    }
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

template<class graph_type> class bridge_and_articulation{
private:
    void dfs(int v,int p,int &k){ //vが根のときp=-1
        used[v]=true;
        ord[v]=low[v]=k++;

        int count=0;
        for(const auto &edge:graph[v]){
            const int u=edge.to;
            if(!used[u]){
                ++count;
                dfs(u,v,k);
                low[v]=min(low[v],low[u]);

                if(ord[v]<low[u]) bridges.push_back(make_pair(min(v,u),max(v,u)));
                if(p!=-1 and ord[v]<=low[u]) is_art[v]=true;
            }else if(u!=p) low[v]=min(low[v],ord[u]);
        }

        if(p==-1 and count>1) is_art[v]=true;
        if(is_art[v]) articulations.push_back(v);
    }

public:
    const int size;
    graph_type graph;
    vector<bool> used,is_art;
    vector<int> ord,low,articulations;
    vector<pair<int,int>> bridges;

    bridge_and_articulation(const graph_type &graph):graph(graph),size(graph.size()),used(size),is_art(size),ord(size),low(size){
        int k=0;
        for(int i=0; i<size; ++i) if(!used[i]) dfs(i,-1,k);
    }
    bool is_articulation(int v)const{
        return is_art[v];
    }
    bool is_bridge(int u,int v)const{ //辺(u,v)がグラフに含まれることを仮定する
        if(ord[u]>ord[v]) swap(u,v);
        return ord[u]<low[v];
    }
};

struct edge{
    int to;
    edge(int to):to(to){}
};

void solve(){
    int N,M;
    cin >> N >> M;

    vector<vector<edge>> graph(N);
    vector<pair<int,int>> edges;
    rep(i,0,M){
        int a,b;
        cin >> a >> b;
        --a;
        --b;
        graph[a].push_back(edge(b));
        graph[b].push_back(edge(a));
        edges.push_back(make_pair(a,b));
    }

    bridge_and_articulation<vector<vector<edge>>> ba(graph);
    
    int ans=0;
    rep(i,0,M) if(ba.is_bridge(edges[i].first,edges[i].second)) ++ans;
    
    cout << ans << endl;

}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(auto i = 0; i < n; i++)
#define rep1(i, n) for(auto i = 1; i <= n; i++)
#define INF 100000000000
#define ll long long

int N, K, H[305];

int main() {
  cin >> N >> K;
  rep1(i, N) cin >> H[i];
  H[0] = H[N + 1] = 0;
  ll dp[N + 2][N + 1];
  rep(i, N + 2) rep(j, N + 1) dp[i][j] = INF;
  dp[0][0] = 0;
  for(auto i = 0; i <= N + 1; i++) {
    rep(j, i) {
      int p = i - j - 1;
      for(auto s = 0; s + p <= K; s++) {
        dp[i][s + p] = min(dp[i][s + p], dp[j][s] + (H[i] > H[j] ? H[i] - H[j] : 0));
      }
    }
  }
  ll ans = INF;
  rep(i, N + 1) ans = min(ans, dp[N + 1][i]);
  cout << ans << endl;
}

Measured memory_bytes: 896
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, x int
	fmt.Scan(&n, &x)
	ar := make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Scan(&ar[i])
	}
	ar[n] = x
	sort.Ints(ar)
	b := ar[1]
	ans := ar[1] - ar[0]
	for i := 2; i < n+1; i++ {
		ans = gcd(ans, ar[i]-b)
		b = ar[i]
	}
	fmt.Println(ans)
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}


Measured memory_bytes: 5504
local mmi, mma = math.min, math.max
a, b, m = io.read("*n", "*n", "*n")
x = {}
y = {}
xmin, ymin = 1000000007, 1000000007
for i = 1, a do
  x[i] = io.read("*n")
  xmin = mmi(xmin, x[i])
end
for i = 1, b do
  y[i] = io.read("*n")
  ymin = mmi(ymin, y[i])
end
ret = xmin + ymin
for i = 1, m do
  xi, yi, c = io.read("*n", "*n", "*n")
  ret = mmi(ret, x[xi] + y[yi] - c)
end
print(ret)

Measured memory_bytes: 4472
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	int A[N];
	for (int i = 0; i< N; i++) {
		cin >> A[i];
	}
	double ave=0;
	for (int i = 0; i< N; i++) {
		ave += A[i];
	}
	ave = ave / N;
	double D[N];
	for (int i = 0; i< N; i++) {
		D[i] = abs(A[i] - ave);
	}
	int ans = 0;
	double min = D[0];
	for (int i = 0; i<N; i++) {
		if (D[i] < min) {
			min = D[i];
			ans =i;
		}
	}
	cout << ans<< endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    sc.close();
    switch(n%10) {
      case 3:
        System.out.println("bon");
        break;
      case 0:
      case 1:
      case 6:
      case 8:
        System.out.println("pon");
        break;
      default:
        System.out.println("hon");
    }
  }
}

Measured memory_bytes: 35644
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int a, b;
    cin >> a >> b;
    if(a==1) a = 14;
    if(b==1) b = 14;
    if(a>b) cout << "Alice" << endl;
    else if(a<b) cout << "Bob" << endl;
    else cout << "Draw" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// e.g. sort(all(a), [](int a1, int a2) { return a1 < a2; });
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

vector<ll> a(200010);
vector<ll> b(200010);

int main() {
  ll n;
  cin >> n;
  a.resize(n);
  rep(i,n) cin >> a[i];

  // とりあえず、現状で選び出すパターン数を求める
  // 1. 数字A が N個あるかをまとめる
  rep(i,n){
    b[a[i]]++;
  }
  ll ans = 0;
  for (auto &bb : b) {
    ans += (bb*(bb-1))/2;
  }
  

  rep(i,n) {
    // i番目を除いたときに、いくつ減るかを見る
    // e.g. 1=3個、 2=2個、 3=5個のとき
    // i番目が 1 なら、 パターンが 3パターン→ 1パターン なので 2減る
    // i番目が 2 なら、 パターンが 1パターン→ 0パターン なので 1減る
    // i番目が 3 なら、 パターンが 10パターン→ 6パターン なので 4減る

    ll count = b[a[i]];
    ll new_c = count -1;
    ll minus = ((count*(count-1)) / 2) - (new_c*(new_c-1)) / 2;
    if (new_c == 0) {
      minus = 0;
    }

    cout << ans-minus << endl;
  }

  return 0;
}


Measured memory_bytes: 5760
import java.util.*

fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map {it.toLong()}
    val A = readLine()!!.split(" ").map {it.toLong()}
    val mp = TreeMap<Long, Long>()

    mp[0] = 1
    var s = ModInt(0, M)
    for (a in A) {
        s += a

        mp[s.value] = (mp[s.value] ?: 0) + 1L
    }

    val res = mp.map { it.value * (it.value - 1) / 2L }.sum()
    println(res)
}

class ModInt (value: Long, val mod: Long) {
    init {
        if (mod <= 0) {
            throw IllegalArgumentException("ModInt cannot be created for non-positive modulus: $mod")
        }
    }

    val value = (value % mod + mod) % mod

    private fun assertSameMod(other: ModInt) {
        if (mod != other.mod) {
            throw IllegalArgumentException(
                "You cannot operate summation, subtraction and multiplication for ModInts with different moduli: $mod, ${other.mod}"
            )
        }
    }

    operator fun unaryMinus() = ModInt(mod - value, mod)

    operator fun plus(other: ModInt): ModInt {
        assertSameMod(other)

        return ModInt((value + other.value) % mod, mod)
    }

    operator fun plus(other: Long) = plus(ModInt(other, mod))

    operator fun minus(other: ModInt): ModInt {
        assertSameMod(other)

        return plus(-other)
    }

    operator fun minus(other: Long) = minus(ModInt(other, mod))

    operator fun times(other: ModInt): ModInt {
        assertSameMod(other)

        return ModInt((value * other.value) % mod, mod)
    }

    operator fun times(other: Long) = times(ModInt(other, mod))

    fun pow(k: Long): ModInt {
        var res = 1L
        var a = value
        var l = k

        while (l > 0) {
            if ((l and 1L) == 1L) {
                res = (res * a) % mod
            }

            a = a * a % mod
            l /= 2L
        }

        return ModInt(res, mod)
    }

    /**
     * Returns an inverse element of the value.
     * To ensure `m * m.inv() = 1`, the modulus should be prime, since it uses Fermat's little theorem.
     */
    fun inv() = pow(mod - 2)

    operator fun div(other: ModInt): ModInt {
        assertSameMod(other)
        if (other.value == 0L) {
            throw ArithmeticException()
        }

        return times(other.inv())
    }

    operator fun div(other: Long) = div(ModInt(other, mod))
}


Measured memory_bytes: 58084
def gi() gets.to_i end
def gs() gets.chomp end
def gim() gets.split.map(&:to_i) end
def gsm() gets.split.map(&:chomp) end
def YesNo1(bool, yes="Yes", no="No") puts (bool ? yes : no) end
def YESNO2(bool, yes="YES", no="NO") puts (bool ? yes : no) end
def sqrt(i) i ** (1.0/2) end

def comb(n,k)
  return 0 if k > n
  result = 1
  1.upto(k) do |d|
    result *= n
    result /= d
    n -= 1
  end
  result
end

require "bigdecimal"
#####
n = gi
nums = gim
countDic = {}
nums.each do |num| #O(N)
  if countDic[num] != nil
    countDic[num] = countDic[num] + 1
  else
    countDic[num] = 1
  end
end
#print countDic

combDic = {}
countDic.each do |k,v| #O(N)
  combDic[k] = comb(v,2)
end
#print combDic

resDic = {}
totalSum = combDic.values.inject(:+)
combDic.each do |k,v|
  otherSum = totalSum - combDic[k]
  otherSum = 0 if otherSum == nil
  resDic[k] = otherSum + comb(countDic[k]-1,2)
end
#print resDic

nums.each do |num|
  puts resDic[num]
end

Measured memory_bytes: 46108
n = int(input())
s = input()

left = [set() for _ in range(n)]
right = [set() for _ in range(n)]

for i in range(1, n):
    x = left[i - 1].copy()
    x.add(s[i - 1])
    left[i] = x

for i in range(n - 2, -1, -1):
    x = right[i + 1].copy()
    x.add(s[i + 1])
    right[i] = x

t = [False for _ in range(1000)]
for i in range(1, n - 1):
    for c in left[i]:
        for d in right[i]:
            t[int(c + s[i] + d)] = True

print(t.count(True))


Measured memory_bytes: 47732
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

  int main(){
      lint n,q;
      string s;
      cin>>s;
      lint ans=0;
      lint count=0;
      rep(i,s.size()){
          if(s[i]=='R')count++;
          else{ ans=max(ans,count);
          count=0;
          }
      }
      ans=max(ans,count);
      cout<<ans<<endl;


    }
      
    
  

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

ll N, K;
string s;
set<int> set_;

int main(){
    cin >> N >> K;
    cout << min((N % K), K - (N % K) );
	return 0;
}

Measured memory_bytes: 3628