akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

void era(vector<int> &v){
	v[1] = 1;
	for (int i = 2; i <= 1000; i++){
		if (v[i] == 0){
			for (int j = 2; j <= 1000/i; j++){
			v[i*j] = 1;
			}	
		}
	}
	return ;
}
int main(){
	int n; cin >> n;
	vector<int> yakusu(1001,0);
	vector<int> prime(1001);
	era(prime);
	for (int i = 1; i <= n; i++){
		int p=1;
		if (prime[i] == 0){
			while ( n / pow(i, p) >= 1){
				yakusu[i] += n / (int)pow(i,p);
				p++;
			}	
		}
	}
	long long int ans = 1;
	for (int i= 2; i <= n; i++){
		ans *= yakusu[i] + 1;
		ans = ans % 1000000007;
	}
	cout << ans % 1000000007 << endl;
return 0;
}


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

#define int long long

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	int n, q, x, y, sum = 0;
	cin >> n;
	
	unordered_map<int, int> mp;
	for (int i = 0; i < n; ++i) {
		cin >> x;
		sum += x;
		++mp[x];
	}

	cin >> q;
	while (q--) {
		cin >> x >> y;
		sum += (y - x) * mp[x];
		mp[y] += mp[x];
		mp[x] = 0;
		cout << sum << '\n';
	}

	return 0;
}

Measured memory_bytes: 7036
//package cf;

import java.util.*;
import java.io.*;
class Main {
    public static void main(String[] args) throws IOException {
        FastReader io = new FastReader(); 
        long n = io.nextLong(), k = io.nextLong();
        System.out.println(Math.min(n, Math.min(Math.abs(n-(n/k)*k), Math.abs(n-(n/k+1)*k))));
    }
    
    static class FastReader { 
        BufferedReader br; 
        StringTokenizer st; 

        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 

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

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

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

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

        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    
}




Measured memory_bytes: 23124
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int counter = scanner.nextInt();
        final Map<String, List<Integer>> map = new HashMap<>();
        final Map<Integer,Integer> indexMap = new HashMap<>();
        scanner.nextLine();

        for(int i = 0;i<counter;i++){
            final String[] split = scanner.nextLine().split("[\\s]");
            map.computeIfAbsent(split[0], v -> new ArrayList<>())
                    .add(Integer.parseInt(split[1]));
            indexMap.put(Integer.parseInt(split[1]), i + 1);
        }

        final List<String> cities = new ArrayList<>();
        for (final Map.Entry<String, List<Integer>> entry : map.entrySet()) {
            cities.add(entry.getKey());
            entry.getValue().sort(Comparator.reverseOrder());
        }

        cities.sort(Comparator.naturalOrder());

        for (final String city : cities) {
            for (final Integer integer : map.get(city)) {
                System.out.println(indexMap.get(integer));
            }
        }
    }
}


Measured memory_bytes: 26836
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}


int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  ll n,r;cin>>n>>r;
  cout<<r+max(0ll, 100*(10-n))<<endl;
  return 0;
}

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

int main() {
    int N;
    std::cin >> N;
    std::vector<int> h;
    h.resize(N);
    for (int &a : h) {
        std::cin >> a;
    }
    int v1 = 0, v2 = abs(h[1] - h[0]), mn;
    for (int i = 2; i < N; i++) {
        mn = std::min(v1 + abs(h[i] - h[i - 2]), v2 + abs(h[i] - h[i - 1]));
        v1 = v2;
        v2 = mn;
    }
    std::cout << v2;
    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
using namespace std;
#define MOD 1000000007
int fac[20000007];
#define f(_x) ((_x) < 0 ? 0 : fac[_x])
long long fastpow(register int a, register int n){
	if (n < 0) return 1;
	register long long t, p;
	for (t = 1, p = a; n; n >>= 1, p = p * p % MOD) if (n & 1) t = p * t % MOD;
	return t;
}
int main(){
	register int n, k, i, lim;
	scanf("%d %d", &n, &k);
	if (k == 1) {
		if (n == 1) puts("1");
		else printf("%lld", fastpow(2, n - 2));
		return 0;
	}
	else if (k == 2) {
		if (n == 2) puts("1");
		else printf("%lld", (n - 1) * fastpow(2, n - 3) % MOD);
		return 0;
	}
	--n, --k;
	fac[0] = 1;
	lim = n + k;
	for (i = 1; i <= lim; ++i) fac[i] = 1ll * fac[i - 1] * i % MOD;
	printf("%lld", ((f(lim) * fastpow(f(n), MOD - 2) % MOD * fastpow(f(k), MOD - 2) - f(lim) * fastpow(f(n + 1), MOD - 2) % MOD * fastpow(f(k - 1), MOD - 2)) % MOD + MOD) * fastpow(2, n - k - 1) % MOD);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
// #include <cassert>
#include <vector>
#include <algorithm>
#include <climits>

#include <stack>
#include <queue>
// #include <deque>
// #include <set>
// #include <map>
// #include <string>
// #include <unordered_set>
// #include <unordered_map>

#include <tuple>
// #include <cmath>
// #include <numeric>

using namespace std;


typedef long long ll;
typedef pair<long,long> pll;
typedef pair<int,int> pii;
typedef pair<int,long> pil;
typedef pair<long,int> pli;
typedef pair<long long, long long> pllll;
typedef pair<long long, int> plli;
typedef pair<int,long long> pill;
typedef vector<vector<long long>> vvll;
typedef vector<vector<long>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;

#define emplace_back pb
const char el = '\n';



/*
Edge cases:


*/

int main() {
    // ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int n,m; cin>>n>>m; cin.ignore();


    if (m==0) {
        if (n==1) {
            cout<<"0"<<el;
            return 0;
        }
        cout<<"1"<<string(n-1,'0')<<el;
        return 0;
    }
    vector<int> pref(n+1,-1);

    //pref[s]=c means we have already specified that sth digit from left should be c;


    for (int i = 0; i<m; ++i) {
        int s, c; cin>>s>>c;

        if (pref[s] != -1 && pref[s] != c) {
            cout<<-1<<el;
            return 0;
        }

        pref[s]=c;
    }


    if (pref[1]==0) {
        if (n>1) {
            cout<<-1<<el;
        } else {
            cout<<0<<el;
        }
        return 0;
    }


    int firstspecified = 1;
    while (pref[firstspecified] == -1) {
        ++firstspecified;
    }

    if (firstspecified>1) {
        cout<<"1";
    }
    for (int i = 2; i<firstspecified; ++i) {
        cout<<"0";
    }

    for (int i= firstspecified; i<=n; ++i) {
        if (pref[i]!=-1) {
            cout<<pref[i];
        } else {
            cout<<"0";
        }
    }
    cout<<el;

}

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

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}

int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

void solve()
{
   int x;
    cin >> x;
    x--;
    cout << a[x];
    
    
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

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

using namespace std;

const int Nmax = 1e5 + 5;

int ans, n, i, xor_sum, nr = 0, a[Nmax], b[Nmax];
map<int,int> cnt, ord;
bool ok = 1, used[Nmax];
vector<int> v[Nmax];

void add_edge(int x, int y)
{
    v[ord[x]].push_back(ord[y]);
}

void dfs(int node)
{
    used[node] = 1;
    for(auto x : v[node])
        if(!used[x]) dfs(x);
}

int main()
{
  //  freopen("input", "r", stdin);
    cin.sync_with_stdio(false);

    cin >> n;
    for(i=1; i<=n; ++i) cin >> a[i], xor_sum ^= a[i];
    for(i=1; i<=n; ++i) cin >> b[i];

    for(i=1; i<=n; ++i)
        if(a[i] == b[i])
        {
            swap(a[i], a[n]);
            swap(b[i], b[n]);
            --n; --i;
        }

    if(!n)
    {
        cout << 0 << '\n';
        return 0;
    }

    for(i=1; i<=n; ++i)
        ++cnt[a[i]], --cnt[b[i]];

    cnt[xor_sum]++;
    for(auto it : cnt) ord[it.first] = ++nr;

    for(auto it : cnt)
    {
        if(!it.second) continue;
        if(ok && it.second == 1) add_edge(xor_sum, it.first), ok = 0;
            else
            {
                cout << -1 << '\n';
                return 0;
            }
    }

    ans = n - 1;
    for(i=1; i<=n; ++i) add_edge(a[i], b[i]);

    for(i=1; i<=nr; ++i)
        if(!used[i])
        {
            dfs(i);
            ans++;
        }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 19072
using System;
using System.IO;
using System.Collections.Generic;

namespace ABC100B
{
    public class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var D = ss.Next(int.Parse);
            var N = ss.Next(int.Parse);
            if (N == 100) N++;
            sw.WriteLine((int)Math.Pow(100, D) * N);
            //---------------------------------
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }
}

Measured memory_bytes: 13268
k, n = list(map(int, input().split()))
a = list(map(int, input().split()))

tmp = 0

for i in range(1, len(a)):
    if a[i]-a[i-1] >=tmp:
        tmp = a[i] - a[i-1]

if a[0]+k-a[len(a)-1] > tmp:
    tmp = a[0]+k-a[len(a)-1]

print(k-tmp)

Measured memory_bytes: 26060
// cities to vapori-
// corner cases // int vs ll // cin vs scanf // clear structures // statement // doublesz // math is your friend
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define REP(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){
	
	fastio;
	string cad;
	cin >> cad;
	set<char> s;
	for(char ch : cad) s.insert(ch);
	cout << (sz(s) > 1 ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
ans = False
for pattern_h in range(n-m+1):
  for pattern_w in range(n-m+1):
    p = []
    for h in range(m):
      p.append(a[pattern_h+h][pattern_w:pattern_w+m])
    if p==b:
      ans = True
      break
  if ans: break
print('Yes' if ans else 'No')

Measured memory_bytes: 9120
#include<iostream>
#include<cstdio>
using namespace std;
int mas[100][100];
int dx[8]={1,1,0,-1,-1,-1,0,1},dy[8]={0,1,1,1,0,-1,-1,-1};
int sx,sy,gx,gy,w,h,cnt=0;
void dfs(int x,int y);
int main(){
  while(1){
    cnt=0;
  cin >> w >> h;
  if(w==0 && h==0) break;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> mas[i][j];
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(mas[i][j]==1){
        cnt++;
        dfs(j,i);
      }
    }
  }
  cout << cnt << endl;
  }
}
void dfs(int x,int y){
  mas[y][x]=0;
  for(int i=0;i<8;i++){
    int nx=x+dx[i];
    int ny=y+dy[i];
    if(nx >= 0&& nx < w && ny >= 0 && ny < h && mas[ny][nx]==1){
        dfs(nx,ny);
      }
  }
}


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

int main() {
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    
    int ans = 0,cnt = 0;
    rep(i,n-1){
        if(s[i]==s[i+1])ans++;
        else cnt++;
    }
    if(2*k<cnt) cout << ans + 2*k << endl;
    else cout << ans + cnt << endl;
    return 0;
}

Measured memory_bytes: 512
import sys

s = sys.stdin.readline().strip()
q = int(sys.stdin.readline().strip())

heads = []
tails = []
is_reverse = -1

for i in range(q):
    query = sys.stdin.readline().strip()

    if query[0] == '1':
        is_reverse *= -1
    else:
        t, f, c = query.split()
        if f == '1':  # to current head
            if is_reverse == 1:
                tails.append(c)
            else:
                heads.append(c)
        else:  # to current tail
            if is_reverse == 1:
                heads.append(c)
            else:
                tails.append(c)

if is_reverse == 1:
    print(''.join(tails[::-1]) + s[::-1] + ''.join(heads))
else:
    print(''.join(heads[::-1]) + s + ''.join(tails))

Measured memory_bytes: 6252
#include <bits/stdc++.h>
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const long double EPS = 1e-8;
using vi = vector <int>;
using vvi = vector <vi>;

signed main() {
	int n;
	cin >> n;
	char in;
	set <char> st;
	rep (i, n) {
		cin >> in;
		st.insert(in);
	}
	cout << (st.size() == 3 ? "Three" : "Four") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>

using namespace std;



int main()
{
	int H,W;

	cin >> H >> W;

	vector<string> stage;

	string s;
	for (int hi = 0; hi < H; hi++){
		cin >> s;
		stage.push_back(s+"#");
	}
	stage.push_back(string(W + 1, '#'));

	vector<vector<int>> yoko(H,vector<int>(W,0));
	vector<vector<int>> tate(H,vector<int>(W,0));

	int cnt = 0;
	int ws = -1;
	for(int hi = 0; hi <= H; hi++){
		cnt = 0;
		ws = -1;
		for(int wi = 0; wi <= W; wi++){
			if(ws == -1){
				if (stage[hi][wi] == '.'){
					ws = wi;
					cnt++;
				}
			}else{
				if (stage[hi][wi] == '.'){
					cnt++;
				}else{
					for (int ci = ws; ci < wi; ci++){
						yoko[hi][ci] = cnt;
					}
					cnt = 0;
					ws = -1;
				}
			}
		}
	}

	int hs = -1;
	for (int wi = 0; wi <= W; wi++) {
		cnt = 0;
		hs = -1;
		for (int hi = 0; hi <= H; hi++) {
			if (hs == -1) {
				if (stage[hi][wi] == '.') {
					hs = hi;
					cnt++;
				}
			}
			else {
				if (stage[hi][wi] == '.') {
					cnt++;
				}
				else {
					for (int ci = hs; ci < hi; ci++) {
						tate[ci][wi] = cnt;
					}
					cnt = 0;
					hs = -1;
				}
			}
		}
	}


	int ans = 0;
	for (int hi = 0; hi < H; hi++) {
		for (int wi = 0; wi < W; wi++) {
			if (yoko[hi][wi] + tate[hi][wi] > ans) {
				ans = yoko[hi][wi] + tate[hi][wi];
			}
		}
	}

	ans -= 1;



	printf("%d",ans);

	return 0;
}



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


int H, W;
matrix a;


void input() {
    cin >> H >> W;
    a = matrix(H, vector<int>(W));
    rep(i, H) rep(j, W) cin >> a[i][j];
}


int main() {
    input();
    matrix ans;
    rep(i, H) rep(j, W) {
        if (a[i][j] % 2 == 1) {
            if (j < W - 1) {
                a[i][j+1] += 1;
                ans.push_back({i + 1, j + 1, i + 1, j + 2});
            }
            else if (i < H - 1) {
                a[i+1][j] += 1;
                ans.push_back({i + 1, j + 1, i + 2, j + 1});
            }
        }
    }
    cout << ans.size() << endl;
    for (auto v : ans) {
        printf("%d %d %d %d\n", v[0], v[1], v[2], v[3]);
    }
}


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

const int MOD = 1e9 + 7;

void solve_test() {
	string s, t;
	cin >> s >> t;
	int n = s.length();
	int m = t.length();

	int min_diff = INT_MAX;
	for (int i = 0; i <= n - m; i++) {
		int diff = 0;
		for (int j = i; j < i + m; j++)
			if (s[j] != t[j - i])
				diff++;
		min_diff = min(min_diff, diff);
	}

	cout << min_diff << '\n';
}

int32_t main() {
	int T; 
	// cin >> T;
	T = 1;
	while (T--)
		solve_test();

	return 0;
}


Measured memory_bytes: 3604
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))

G = [[] for i in range(N)]

for i in range(M):
    A, B = list(map(int, input().split()))
    G[A - 1].append(B - 1)
    G[B - 1].append(A - 1)

ans = 0

for i in range(N):
    self_h = H[i]

    self_max_flag = True

    for to in G[i]:
        if (self_h <= H[to]):
            self_max_flag = False
        
    if (self_max_flag):
        ans += 1

print(ans)

Measured memory_bytes: 29452
/// 5:28 PM 17/05/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)
#include<bits/stdc++.h>

using namespace std;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define VARIABLE_ERROR(x) cout << #x << " = " << x << endl;
#define CONTAINER_ERROR(v) cout << "{";for (auto &x:v) { cout << x << ','; }cout << "}" << endl;
#define PI 3.14159265358979323846
#define M 1000000007
#define INF 1e15
typedef long long ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ld a, b, h, m;
    cin >> a >> b >> h >> m;
    ll min = 60.0*h + m;
    ld angle1 = 2.0 * PI * min / (60.0);
    ld angle2 = 2.0 * PI * min / (12.0 * 60.0);
    ld diff = fabs(angle1 - angle2);
    ld diff2 = 2.0 * PI - diff;
    if(diff2 < diff) {
        diff = diff2;
    }
    ld ans = a*a + b*b - 2.0*a*b*cos(diff);
    ans = sqrt(ans);
    cout << fixed << setprecision(10) << ans;
    return 0;
}

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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

int n, m, a, b;
char output[1005][1005];

void place_horizontal(int x, int y){
	assert(y < m);
	if(a == 0){
		return;
	}
	if(output[x][y] == '.' && output[x][y + 1] == '.'){
		output[x][y] = '<';
		output[x][y + 1] = '>';
		a--;
	}
}

void place_vertical(int x, int y){
	assert(x < n);
	if(b == 0){
		return;
	}
	if(output[x][y] == '.' && output[x + 1][y] == '.'){
		output[x][y] = '^';
		output[x + 1][y] = 'v';
		b--;
	}
}

void print_grid(){
	for(int i = 1; i <= n; i++){
		printf("%s\n", output[i] + 1);
	}
}

int main(){
	scanf("%d %d %d %d", &n, &m, &a, &b);
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			output[i][j] = '.';
		}
	}
	// minimize waste as possible
	int starting = 1;
	if(n & 1){
		for(int j = 1; j < m; j += 2){
			place_horizontal(1, j);
		}
		starting = 2;
	}
	int incomplete = -1, pos;
	for(int j = 1; j < m; j += 2){
		for(int i = starting; i < n; i += 2){
			place_horizontal(i, j);
			if(a == 0 && incomplete == -1){
				pos = i;
				incomplete = j;
			}
			place_horizontal(i + 1, j);
		}
	}
//	print_grid();
	if(a > 0){
		printf("NO\n");
		return 0;
	}
	// now, place vertical
	for(int i = starting; i < n; i += 2){
		for(int j = 1; j < m; j += 2){
			place_vertical(i, j);
			place_vertical(i, j + 1);
		}
	}
	if(m & 1){
		// final column
		for(int i = 1; i < n; i += 2){
			place_vertical(i, m);
		}
	}
	if(b > 0){
		// last resort..
		if(incomplete != -1 && (n & 1) && (m & 1)){
			output[pos][incomplete] = '.';
			output[pos][incomplete + 1] = '.';
			a++;
			if(output[n][m - 1] != '.'){
				output[n][m - 1] = output[n - 1][m - 1] = '.';
				b++;
			}
			place_horizontal(n, m - 1);
			place_vertical(pos, incomplete);
			place_vertical(pos, incomplete + 1);
		}
		if(b > 0){	
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	print_grid();
	return 0;
}

Measured memory_bytes: 2176
/* ex4_1 melo */
#include <stdio.h>
int main(void){
    int Num,Watchman,Min_WM;//整数の箱を３つ用意する
    scanf("%d %d",&Num,&Watchman);//木の本数と監視員の人数を代入する
    Min_WM=((Num+(2*Watchman+1)-1) / (2*Watchman+1));//最小の監視員の人数を求める（このとき、x/y+(y-1)/yで小数点の切り上げ(天井関数ceil()と同じ計算）が計算できることを利用する)
    printf("%d\n",Min_WM);//最小の監視員の人数を表示
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

char S[20],T[20];

int main()
{
	//変数宣言
	int can=0;
	int i=0;
	
	//初期入力
	scanf("%s",S);
	scanf("%s",T);
	
	while(can==0)
	{
		if(S[i] == '\0')
		{
			if(T[i]!='\0' && T[i+1]=='\0')
			{
				can = 1;
			}
			else
			{
				can = -1;
			}
		}
		else if(S[i] != T[i])
		{
			can = -1;
		}
		else
		{
			i++;
		}
	}
	
	
	//最終出力
	if(can == 1)
	{
		printf("Yes\n");
	}else
	{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 1644
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

static size_t A[100000];

int compare_f(const void *a, const void *b) {
	return *((size_t *)a) > *((size_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

int main(void) {
	size_t N;
	size_t d[100];

	scanf("%zu\n", &N);
	for (size_t idx = 0; idx < N; idx++) {
		scanf("%zu", &d[idx]);
		if (idx < N - 1) {
			scanf("\n");
		}
	}

	qsort(d, N, sizeof(size_t), compare_f);

	size_t count = 1;
	for (size_t idx = 1; idx < N; idx++) {
		if (d[idx] != d[idx - 1]) {
			count++;
		}
	}

	printf("%zu\n", count);

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
 using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 int main(){
   int a,b;
   cin >>a>>b;
   if((a+b)%2==0){
   cout<<(a+b)/2<<endl;
   }
   else{
   cout<<"IMPOSSIBLE"<<endl;
    
   }
 

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
ll n,s,mod=998244353,a[3005],dp[3005][3005];
int main(){
	n=read(),s=read();
	for(int i=0;i<n;i++)
		a[i]=read();
	dp[0][0]=1;
	for(int i=0;i<n;i++)
		for(int j=0;j<=s;j++){
			dp[i+1][j]+=2*dp[i][j];
			dp[i+1][j]%=mod;
			if(j+a[i]<=s){
				dp[i+1][j+a[i]]+=dp[i][j];
				dp[i+1][j+a[i]]%=mod;
			}
		}
	cout << dp[n][s];
	return 0;
}

Measured memory_bytes: 74080
#include <bits/stdc++.h>
using namespace std;
typedef long long Long;
int t;

int Sqrt(Long v) {
    int l = 0, r = 1e9, ans;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (1ll * mid * mid <= v) {
            l = mid + 1; ans = mid;
        } else r = mid - 1;
    }
    return ans;
}

int main() {
    scanf("%d", &t);
    while (t--) {
        int a, b; scanf("%d%d", &a, &b);
        if (a > b) swap(a, b);
        if (a == b) printf("%d\n", 2 * a - 2);
        else if (a + 1 == b) printf("%d\n", a * 2 - 2);
        else {
            int c = Sqrt(1ll * a * b - 1);
            if (1ll * c * (c + 1) >= 1ll * a * b) printf("%d\n", c * 2 - 2);
            else printf("%d\n", c * 2 - 1);
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<bool>dp(N,false);
  vector<int>A(N,1);
  dp[0]=true;
  int M;
  cin>>M;
  for(int i=0;i<M;i++){
  int x,y;
    cin>>x>>y; x--; y--;
    if(dp[x])dp[y]=true;
    A[x]--;A[y]++;if(A[x]==0)dp[x]=false;
  }int ans=0;
  for(int i=0;i<N;i++)
    if(dp[i])ans++;
  cout<<ans<<endl;
  return 0;
}

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

int main(){
  int N;
  string S;
  cin >> N >> S;
  int n = 0;
  for (int i = 0; i < N-2; i++){
    if (S.at(i) == 'A'){
      if (S.at(i+1) == 'B'){
        if (S.at(i+2) == 'C'){
          n++;
        }
      }
    }
  }
  cout << n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
const int maxN = 1000001;
string extractStringAtKey(string str, int key){
    char *s = strtok((char *)str.c_str(), " ");
    while(key > 1){
        s = strtok(NULL, " ");
        key--;
    }
    return (string)s;
}
int32_t main(){
    SPEED;
    string s;
    cin >> s;
    int w = 0, ans = 0;
    for(int i = len(s) - 1; i >= 0; --i){
        if(s[i] == 'W') w++;
        else{
            ans += w;
        } 
    }
    cout << ans << endl;
}

Measured memory_bytes: 3776
# -*- coding: utf-8 -*-
d, n = map(int,input().split())

tmp = []
if d == 0:
    for i in range(200):
        if i % 100 != 0:
            tmp.append(i)
    print(tmp[n - 1])
if d == 1:
    if n < 100:
        print(n * 100)
    if n == 100:
        print(10100)
if d == 2:
    if n < 100:
        print(n * 10000)
    if n == 100:
        print(1010000)


Measured memory_bytes: 3060
a, b = [int(n) for n in input().split()]

ans = 0
if a >= b:
    ans += a
    if a-1 >= b:
        ans += (a-1)
    else:
        ans += b
else:
    ans += b
    if b-1 >= a:
        ans += (b-1)
    else:
        ans += a

print(ans)

Measured memory_bytes: 3060
n = int(input())
h = list(map(int, input().split()))

flag = 'Yes'

for i in range(n-1,0,-1):
    if h[i] >= h[i-1]:
        next
    elif h[i] == h[i-1]-1:
        h[i-1] -= 1
    else:
        flag = 'No'
        break

print(flag)

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

typedef long long lint;

int main(){
    lint N;
    cin>>N;
    vector<lint> V(N),C(N);
    for(lint i=0;i<N;i++){
        cin>>V[i];
    }
    for(lint i=0;i<N;i++){
        cin>>C[i];
    }
    lint ans=0;
    for(lint i=0;i<N;i++){
        if(V[i]-C[i]>0){
            ans+=V[i]-C[i];
        }
    }
    cout<<ans;
}

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

using namespace std;

long long k, a, b;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> k >> a >> b;
    long long ans = 1;
    long long x = b - a;
    if (x > 2) {
        long long cnt = min(k, a - 1);
        ans += cnt;
        k -= cnt;
        ans += x * (k / 2);
        k %= 2;
        ans += k;
    } else {
        ans += k;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;



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

	vector<int>a(n);
	for (int i = 0;i < n;i++) {
		cin >> a.at(i);
		x -= a.at(i);
	}
	sort(a.begin(), a.end());
	cout << (x / a[0])+n << endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    int b=0;
    int w=0;
    for(int i=0;i<S.length();i++){
        if(S[i]=='0')w++;
        else b++;
    }
    cout << min(b,w)*2 << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
	ll x, y, z, k;
    cin >> x >> y >> z >> k;
    vll a(x), b(y), c(z);
    REP(i, x) cin >> a[i];
    REP(i, y) cin >> b[i];
    REP(i, z) cin >> c[i];

    vll ab(x * y);
    REP(i, x){
        REP(j, y){
            ab.push_back(a[i] + b[j]);
        }
    }
    sort(ab.rbegin(), ab.rend());
    sort(c.rbegin(), c.rend());

    vll ans;
    ll s = min(k, x * y), t = min(k, z);
    REP(i, s){
        REP(j, t){
            ans.push_back(ab[i] + c[j]);
        }
    }

    sort(ans.rbegin(), ans.rend());
    REP(i, k) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 58740
#pragma GCC optimize("O3")
#pragma G++ optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a, b) memset((a), (b), sizeof(a))
#define mp(a, b) make_pair(a, b)
#define pi acos(-1)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
const ll INF = 0x3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 4e3 + 7;
const int maxm = 1e5 + 7;
const int mod = 192600817;
#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int main()
{
    IO;
    string s;
    cin>>s;
    if (s[1]=='B')
    cout<<"ARC"<<endl;
    else
    cout<<"ABC"<<endl;
    return 0;
}

Measured memory_bytes: 3588
group_a = [1, 3, 5, 7, 8, 10, 12]
group_b = [4, 6, 9, 11]
group_c = [2]

x, y = map(int, input().split())

if (x in group_a and y in group_a) or (x in group_b and y in group_b) or (x in group_c and y in group_c):
    print('Yes')
else:
    print('No')


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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif

signed main() {
    
    int a; cin >>a;
    printf("ABC%03d\n", a);
    return 0;
}


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

int main() {
  ll l, r;
  cin >> l >> r;
  r = min(r, l+2020);
  int ans = 2018;//余りは2018以下になる(当たり前だけど)
  for (ll i = l; i <= r; i++) {
    for (ll j = i+1; j <= r; j++) {
      int x = i*j%2019;
      ans = min(ans, x);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
ll a,b,c;
int main() {
   cin>>a>>b>>c;

   for(int i=0;i<10;i++)
   {
       cout<<a*c-b<<endl;
       c=a*c-b;
   }
   return 0;
}


Measured memory_bytes: 256
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_2-C: Stable Sort

#include <cstring>
#include <algorithm>
#include <iostream>

struct Card {
  char suit;
  unsigned int rank;
  bool operator<(const Card& rhs) { return rank < rhs.rank; }
};

std::ostream& operator<<(std::ostream& os, const Card& card)
{
  return os << card.suit << card.rank;
}

std::istream& operator>>(std::istream& is, Card& card)
{
  return is >> card.suit >> card.rank;
}

static void print_cards(const Card cards[], const unsigned int n)
{
  const char* sep = "";
  for (auto i = 0u; i < n; ++i) {
    std::cout << sep << cards[i];
    sep = " ";
  }
  std::cout << std::endl;
}

static void copy_cards(Card card2[], const Card card1[], const unsigned int n)
{
  std::memcpy(card2, card1, sizeof(card2[0])*n);
}

static bool is_equal_cards(const Card cards1[], const Card cards2[], const unsigned int n)
{
  for (auto i = 0u; i < n; ++i) {
    if (cards1[i].rank != cards2[i].rank ||
        cards1[i].suit != cards2[i].suit) {
      return false;
    }
  }
  return true;
}

static void bubble_sort(Card cards[], const unsigned int n)
{
  for (auto j = 0u; j < n-1; ++j) {
    for (auto i = n-1; i > j; --i) {
      if (cards[i] < cards[i-1]) {
        std::swap(cards[i], cards[i-1]);
      }
    }
  }
}

static void selection_sort(Card cards[], const unsigned int n)
{
  for (auto i = 0u; i < n-1; ++i) {
    auto min_j = i;
    for (auto j = i+1; j < n; ++j) {
      if (cards[j] < cards[min_j]) {
        min_j = j;
      }
    }
    if (i != min_j) {
      std::swap(cards[i], cards[min_j]);
    }
  }
}

int main()
{
  unsigned int n;
  std::cin >> n;
  Card cards1[n], cards2[n];
  for (auto i = 0u; i < n; ++i) {
    std::cin >> cards1[i];
  }
  copy_cards(cards2, cards1, n);

  bubble_sort(cards1, n);
  print_cards(cards1, n);
  std::cout << "Stable" << std::endl; // bubble sort is stable

  selection_sort(cards2, n);
  print_cards(cards2, n);

  if (is_equal_cards(cards1, cards2, n)) {
    std::cout << "Stable" << std::endl;
  } else {
    std::cout << "Not stable" << std::endl;
  }
}

// eof

Measured memory_bytes: 3152
n,m,k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
 
sa = [0] * (n + 1)
sb = [0] * (m + 1)
for i in range(n):
  sa[i + 1] = sa[i] + a[i]
for i in range(m):
  sb[i + 1] = sb[i] + b[i]
ans = 0
r = m
for i in range(n+1):
  if sa[i] > k:
    break
  while sa[i] + sb[r] > k:
    r -= 1
  ans = max(ans, i+r)

print(ans)

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

r = 0
g = 0
b = 0
for i in s:
  if i == 'R':
    r += 1
  elif i == 'G':
    g += 1
  else:
    b += 1

all = r*g*b
ho = 0
for i in range(0,n):
  for j in range(i+1,n):
    if s[i] == s[j]:
      continue
    k = 2*j-i
    if k >= n:
      continue
    if s[i] == s[k] or s[j] == s[k]:
      continue
    ho += 1
print(all-ho)

Measured memory_bytes: 9120
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0118
"""
import sys



def solve(data):
    size = len(data[0])
    data.insert(0, ['0' for _ in range(size)])
    data.insert(len(data), ['0' for _ in range(size)])

    processing_area = []
    area_id = 0
    for y in range(1, len(data)):
        for x in range(1, len(data[0])):
            # print('y:{}, x:{}'.format(y, x))
            mark = data[y][x]
            data[y][x] = '0'
            if mark != '0':
                area_id += 1
                processing_area.append((y, x))

                while processing_area:
                    yy, xx = processing_area.pop()
                    if data[yy-1][xx] == mark:
                        data[yy-1][xx] = '0'
                        processing_area.append((yy-1, xx))
                    if data[yy+1][xx] == mark:
                        data[yy+1][xx] = '0'
                        processing_area.append((yy+1, xx))
                    if data[yy][xx-1] == mark:
                        data[yy][xx-1] = '0'
                        processing_area.append((yy, xx-1))
                    if data[yy][xx+1] == mark:
                        data[yy][xx+1] = '0'
                        processing_area.append((yy, xx+1))
                mark = '0'
    return area_id



def main(args):
    # data = []
    # data.append(['0', '#', '#', '#', '#', '*', '*', '*', '*', '*', '@', '0'])
    # data.append(['0', '@', '#', '@', '@', '@', '@', '#', '*', '#', '*', '0'])
    # data.append(['0', '@', '#', '#', '*', '*', '*', '@', '@', '@', '*', '0'])
    # data.append(['0', '#', '*', '*', '*', '*', '#', '*', '@', '*', '*', '0'])
    # data.append(['0', '#', '#', '@', '*', '#', '@', '@', '*', '#', '#', '0'])
    # data.append(['0', '*', '@', '@', '@', '@', '*', '@', '@', '@', '#', '0'])
    # data.append(['0', '*', '*', '*', '#', '@', '*', '@', '#', '#', '*', '0'])
    # data.append(['0', '*', '@', '@', '@', '*', '@', '@', '#', '#', '@', '0'])
    # data.append(['0', '*', '@', '*', '#', '*', '@', '#', '#', '*', '*', '0'])
    # data.append(['0', '@', '*', '*', '*', '*', '#', '@', '@', '#', '@', '0'])

    while True:
        h, w = [int(x) for x in input().split(' ')]
        if h == 0 and w == 0:
            break
        data = []
        for _ in range(h):
            temp = list(input())
            temp.insert(0, '0')
            temp.append('0')
            data.append(temp)

        result = solve(data)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 8080
#include <stdio.h>
int main(void) {
    long long int n1, n2, i, gcd, lcm;
    //printf("Enter two positive integers: ");
    scanf("%lld %lld", &n1, &n2);
    for (i = 1; i <= n1 && i <= n2; ++i) {
        
        // check if i is a factor of both integers
        if (n1 % i == 0 && n2 % i == 0)
            gcd = i;
    }
    lcm = (n1 * n2) / gcd;
    printf("%lld",lcm);
    return 0;
}

Measured memory_bytes: 128
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    k: usize,
    h: [i64; n],
  }
  let mut h = h;
  h.sort();
  let ans: i64 = if k >= n {
    0
  } else {
    h.iter().take(n - k).sum()
  };

  puts!("{}\n", ans);
}


Measured memory_bytes: 9464
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int t[10] = { 0 };
	t[a]++; t[b]++; t[c]++;
	if (t[5] == 2 && t[7] == 1) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

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

signed main()
{
    int n;
    cin >> n;
    for (int i=0; i < n; i++){
        int x;
        cin >> x;
        if (x % 2 != 0){
            cout << "first";
            return 0;
        }
    }
    cout << "second";
    return 0;
}


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

int main(){
    int a,b;
    while(true){
        cin >> a >> b;
        if(a==0&&b==0){
            break;
        }else if(a<b){
            cout << a << " " << b << endl;
        }else{
            cout << b << " " << a << endl;
        }
    }
}




Measured memory_bytes: 3068
using System;

namespace abc87_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int money = int.Parse(Console.ReadLine());
            int cake = int.Parse(Console.ReadLine());
            int donut = int.Parse(Console.ReadLine());
            money = money - cake;
            money = money % donut;
            Console.WriteLine(money);
        }
    }
}


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

int main(){
	int a,b,c,x;
	cin >> a >> b >> c >> x;
	
	int ans = 0;
	for(int i = 0; i <= a; i++){
		for(int j = 0; j <= b; j++){
			for(int k = 0; k <= c; k++){
				if(500*i + 100*j + 50*k == x)
					ans++;
			}
		}
	}
	cout << ans << endl;
}

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

def func(c, S):
    b = list(format(c, 'b'))
    b = list(reversed(b))
    flag = True
    for i in range(len(b)):
        if b[i] == '1' and S[i] == 1:
            flag = False
            break
    return flag

p = 0
q = 0
S = [0]*30
ans = 0
for p in range(n):
    while q < n and func(A[q], S):
        b = list(format(A[q], 'b'))
        b = list(reversed(b))
        for i in range(len(b)):
            if b[i] == '1':
                S[i] += 1
        q += 1
    ans += q-p
    if p == q:
        q += 1
    else:
        b = list(format(A[p], 'b'))
        b = list(reversed(b))
        for i in range(len(b)):
            if b[i] == '1':
                S[i] -= 1
print(ans)


Measured memory_bytes: 78796