akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <deque>
#include <bitset>
#include <climits>
#include <cstdio>
#include <list>
#include <iomanip>
using namespace std;

#define ll long long int
#define mp make_pair
#define pb push_back
#define fi first
#define si second
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define F1(a,n) for(int i=1;i<=n;i++){cin>>a[i];}
#define P(a,n) for( int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;
#define P1(a,n) for(int i=1;i<=n;i++){cout<<a[i]<<' ';}cout<<endl;
#define NF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>a[i][j];}}
#define NF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}
#define PNF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
#define PNF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
#define AS 200001
#define mod 1000000007
double dp[301][301][301];
double solve(int x, int y, int z, int &n) {
	if (x < 0 || y < 0 || z < 0)
		return 0;
	if (x == 0 and y == 0 and z == 0)
		return 0;
	if (dp[x][y][z] > -0.9)
		return dp[x][y][z];
	double exp = n + x * solve(x - 1, y, z, n) + y * solve(x + 1, y - 1, z, n) + z * solve(x, y + 1, z - 1, n);
	return dp[x][y][z] = exp / (x + y + z);
}
int main() {
	fastIO
	int n, x;
	cin >> n;
	memset(dp, -1, sizeof(dp));
	int one = 0, two = 0, three = 0;
	for (int i = 1; i <= n; i++) {
		cin >> x;
		if (x == 1)
			one++;
		else if (x == 2)
			two++;
		else
			three++;
	}
	cout << fixed << setprecision(10) << solve(one, two, three, n);
}

Measured memory_bytes: 213376
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, K, S = map(int, readline().split())
    ans = [S]*K
    if S == 10**9:
        ans += [1]*(N-K)
    else:
        ans += [S+1]*(N-K)
    print(' '.join(map(str, ans)))

if __name__ == '__main__':
    main()


Measured memory_bytes: 18112
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


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

ll n;
cin >> n;
ll ans = 0;
for(ll i = 1; i * i <= n; ++i) {
    if(n % i == 0) {
        if(i < n/i - 1) {
            ans += n/i - 1;
        }
    }
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rgi register int
#define ll long long
class fastin{
	private: int _ch,_f;
	public: template<typename _Tp> inline fastin& operator>>(_Tp&_x){
		_x=0; while(!isdigit(_ch)) _f|=(_ch==45),_ch=getchar();
		while(isdigit(_ch)) _x=(_x<<1)+(_x<<3)+(_ch^48),_ch=getchar();
		_f&&(_x=-_x,_f=0); return *this;}
	fastin() {_ch=_f=0;}
}fin;
class fastout{
	private: int _num[32],_head;
	public: int SUF; template<typename _Tp> inline fastout& operator<<(_Tp _x){
		_Tp _k; if(_x==0) {putchar('0'),putchar(SUF);return *this;} if(_x<0) putchar('-'),_x=-_x;
		while(_x>0) _k=_x/10,++_head,_num[_head]=(_x-(_k<<1)-(_k<<3))^48,_x=_k;
		while(_head>0) putchar(_num[_head]),--_head; putchar(SUF); return *this;}
	fastout() {_head=0,SUF=' ';}
}fout;
// ----------------------------
// #define int ll
// using namespace std;
const int oo = 0x3f3f3f3f;
const int H = 10 + 5;
const int W = 1e3 + 5;

int h, w, k, ans = oo;
char s[H][W];
int state, pre[H][W], cut[W];

int main()
{
    fin>>h>>w>>k;
    for(int i = 1; i <= h; ++i) scanf("%s", s[i] + 1);
    for(int i = 1; i <= h; ++i)
        for(int j = 1; j <= w; ++j)
            pre[i][j] = pre[i][j - 1] + (s[i][j] - '0');
    for(int state = 0; state < 1 << h - 1; ++state) {
        // pos[i] = state & (1 << i - 1)
        int finish = 1, last = 0, now = 0, cur = 0;
        for(int j = 1; j <= w; ++j) { // 第 j 列右边切 
            for(int i = 1; i <= h; ++i) {
                now += pre[i][j] - pre[i][last];
                if(i == h || state & (1 << i - 1)) { // 第 i 行下面切 
                    if(now > k) cut[j - 1] = 1, last = j - 1;
                    now = 0;
                }
            }
        }
        last = now = 0;
        for(int j = 1; j <= w; ++j) if(cut[j]) {
            for(int i = 1; i <= h; ++i) {
                now += pre[i][j] - pre[i][last];
                if(i == h || state & (1 << i - 1)) { // 第 i 行下面切 
                    if(now > k) finish = 0;
                    now = 0;
                }
            }
            last = j;
        }
        for(int i = 1; i <= w - 1; ++i) if(cut[i]) cur++, cut[i] = 0;
        if(finish)
          ans = std::min(ans, __builtin_popcountl(state) + cur);
    }
    fout<<ans;
    return 0;
}

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

void solve(long long X, long long K, long long D) {
    if (X < 0) {
        X *= -1;
    }
    ll s = min(K, X / D);
    K -= s;
    X -= s * D;

    if (K % 2 == 0) {
        cout << X << endl;
    } else {
        cout << D - X << endl;
    }
}

int main() {
    long long X;
    scanf("%lld", &X);
    long long K;
    scanf("%lld", &K);
    long long D;
    scanf("%lld", &D);
    solve(X, K, D);
    return 0;
}


Measured memory_bytes: 3720
N = gets.to_i
A = []
sum = 0
line = gets.split(' ').map(&:to_i)

for num in 0..N-1 do
    n = line[num]
    A[n] ||= 0
    A[n] += 1
    sum += n
end

Q = gets.to_i
q_lines = []
for num in 0..Q-1 do
    line = gets
    q_lines << line.chomp.split(' ').map(&:to_i)
end

for num in 0..Q-1 do
    B = q_lines[num][0].to_i
    C = q_lines[num][1].to_i
    b = A[B].to_i
    A[B] = 0
    sum += b * (C - B) 
    A[C] ||= 0
    A[C] += b
    puts sum
end

Measured memory_bytes: 43312
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskA {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			String S = in.next();
			long ans = 0;
			long tmp = 0;
			for(int i = 0; i < S.length(); i++) {
				if(S.charAt(i) == 'W') {
					ans += tmp;
				}else {
					tmp += 1;
				}
			}
			out.println(ans);
		}

	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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

	}
}



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

int dfs(int v, int prev, const Graph& G) {
	int g = 0;
	for (auto to : G[v]) {
		if (to != prev) {
			g ^= dfs(to, v, G);
		}
	}
	return g + 1;
}

int main()
{
	int N;
	cin >> N;
	Graph G(N);
	for (int i = 0, x, y; i < N - 1; i++) {
		cin >> x >> y; x--; y--;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	cout << (dfs(0, -1, G) - 1 ? "Alice" : "Bob") << endl;
	return 0;
}


Measured memory_bytes: 11904
d,n=map(int,input().split())
if d==0:
    if n==100:
        print(101)
    else:
        print(n)
elif d==1:
    if n==100:
        print(n*101)
    else:
        print(n*100)
else:
    if n==100:
        print(n*10100)
    else:
        print(n*10000)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
using ll = long long;

int main() {
	int N;
	ll D;
	cin >> N >> D;
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		ll X, Y;
		cin >> X >> Y;
		if (X * X + Y * Y <= D * D) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;
using pis = std::pair<int, std::string>;

const long long INF = 1000000000000000001;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
namespace mp = boost::multiprecision;

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

	int n;
	cin >> n;
	string* s = new string[n];
	rep(i, n) cin >> s[i];

	ll* a = new ll[n];
	rep(i, n) {
		int counter = 0;
		bool flag = true;

		a[i] = 0;
		rep(j, s[i].length()) {
			if (s[i][j] == '.') {
				counter = 0;
				flag = false;
			}
			else {
				a[i] *= 10;
				a[i] += s[i][j] - '0';
				++counter;
			}
		}

		if (flag) counter = 0;
		rep(j, 9 - counter) a[i] *= 10;
	}

	ll ans = 0;
	map<pii, ll> tf;
	rep(i, n) {
		if (a[i] == 0) continue;
		pii two_five = pii(0, 0);

		while (a[i] % 2 == 0) {
			++two_five.first;
			a[i] /= 2;
		}
		while (a[i] % 5 == 0) {
			++two_five.second;
			a[i] /= 5;
		}
		ans += tf[pii(max(0, 18 - two_five.first), max(0, 18 - two_five.second))];

		rep(j, two_five.first + 1) {
			rep(k, two_five.second + 1) {
				tf[pii(j, k)] += 1;
			}
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 11492
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
   ll l,r;
   cin>>l>>r;
   if(r-l>2019)
   {
    cout<<0<<endl;
   } 
   else 
   {ll mn=LONG_MAX;
    for(int i=l;i<=r;i++)
    {
      for(int j=i+1;j<=r;j++)
      {
        ll temp=(1ll*i * 1ll*j)%2019;
        mn=min(temp,mn);

      }
      
    }
       cout<<mn<<endl;
   }
   
}
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  string s;
  cin >> n >> s;
  ll count = 1;
  for(ll i=1;i<sz(s);i++){
    if(s[i]!=s[i-1]){
      count++;
    }
  }
  print(count);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <math.h>
typedef long long ll;
using namespace std;

int main() {
	string s,s1,s2;
	cin>>s;
	ll n=s.length();
	for(int i=1;i<n/2;i++){
		s1=s.substr(0,n/2-i);
		s2=s.substr(n/2-i,n/2-i);
		if(s1==s2){
			cout <<n-i*2<<endl;
			return 0;
		}
	}
	return 0;
}

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

// @@ !! LIM()

bool parlindrome(string s, ll b, ll l) {
  for (ll i = 0; i < l / 2; i++) {
    if (s.at(b + i) != s.at(b + l - 1 - i)) return false;
  }
  return true;
}

bool solve() {
  string S; cin >> S;
  ll N = S.size();
  if (! parlindrome(S, 0, S.size())) return false;
  if (! parlindrome(S, 0, (N-1)/2)) return false;
  if (! parlindrome(S, (N+1)/2, (N-1)/2)) return false;
  return true;
}

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);
  cout << (solve() ? "Yes\n" : "No\n");
  

  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by Reopard on 2014/05/06.
 */
public class Main {
    public static void main(String args[]){
        int n, p, max_p, token;
        int candidate[] = new int[50];
        Scanner sc = new Scanner(System.in);
        while(true){
            n = sc.nextInt();
            p = sc.nextInt();
            max_p = p;
            token = 0;
            if(n == 0 && p == 0) break;
            for(int i = 0; i < n; i++) candidate[i] = 0;
            while(true){
                if(p == 0){
                    p = candidate[token];
                    candidate[token] = 0;
                } else {
                    candidate[token]++;
                    p--;
                }
                if(candidate[token] == max_p) break;
                token++;
                token %= n;
            }
            System.out.println(token);
        }
    }
}

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

int main(void) {
  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, 0, N) cin >> A[i];

  REP(i, 0, N - 1) A[i + 1] += A[i];
  sort(A.begin(), A.end());

  // REP(i, 0, N) cerr << A[i] << " ";
  // cerr << endl;

  ll ans = 0;
  REP(i, 0, N) if(A[i] == 0) ans++;

  REP(i, 0, N) {
    ll j = i;
    while(j < N && A[i] == A[j]) j++;
    ans += (j - i) * (j - i - 1) / 2;
    i = j - 1;
  }

  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	string s1, s2;
	cin >> s1 >> s2;
	int n = stoi(s1 + s2);
	int x = sqrt(n) + 0.5;
	if (x * x == n) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define ll long long
using namespace std;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll n,k,cur=1,t=1; cin>>n>>k;
	vector<int> port(n+1),use(n+1,-1);
	for(int i=1;i<=n;i++) cin>>port[i];
	while(t<=k){
		if(use[cur] != -1) break;
		use[cur] = t++;
		cur = port[cur];
	}
	if(t < k){
		k -= (use[cur]-1);
		k %= (t - use[cur]);
		for(int i=0;i<k;i++){
			cur = port[cur];
		}
	}	
	cout<<cur;
}

Measured memory_bytes: 4784
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]

sum = 0
for i in 1..N do
  sum += lines[1][i-1]
end

def abs(x)
  if x > 0 then
    return x
  else
    return -x
  end
end

submin = 10 ** 20
sub1 = 0
for i in 1..N-1 do
  sub1 += lines[1][i-1]
  sub2 = sum - sub1
  sub = abs(sub1 - sub2)
  if sub < submin then
    submin = sub
  end
end
  
print submin

Measured memory_bytes: 14264
"use strict";
function main(input) {
    let X = parseInt(input.replace("\n", ""));
    let rm = X % 500;
    console.log((X / 500 | 0) * 1000 + (rm / 5 | 0) * 5);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int N;
    cin >> N;
    int px = 0, py = 0, tm = 0;
    bool ok = true;
    rep(i, N) {
        int t, x, y;
        cin >> t >> x >> y;
        int dist = abs(x - px) + abs(y - py);
        if (((t - tm) - dist) < 0 or ((t-tm)-dist)%2 != 0) {
            ok = false;
        }
        tm = t;
        px = x, py = y;
    }
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const double pi=acos(-1);
int main()
{
    int n;cin>>n;
    n%=10;
    if(n==3) cout<<"bon";
    else if(n==0||n==1||n==6||n==8) cout<<"pon";
    else cout<<"hon";
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<pii,ll> piii;
typedef pair<ll,pii> ipii;
#define MOD 998244353 
#define mod(a) ((a)%MOD)
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define dbg(x) cout<<#x<<" = "<<x<<"\n"
#define dbg2(x,y) cout<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<"\n"
#define dbg3(x,y,z) cout<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<" , "<<#z<<" = "<<z<<"\n"
#define INF (1LL<<60)
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;*/
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(v) v.begin(),v.end()
#define endl '\n'
ll gcd(ll a,ll b){if(a==0) return b; return gcd(b%a,a);}
ll powm(ll base,ll exp,ll mod=MOD) {base%=mod;ll ans=1;while(exp){if(exp&1LL) ans=(ans*base)%mod;exp>>=1LL,base=(base*base)%mod;}return ans;}


vector<pii> p;
ll dp[101][100005];
int main(){
      sync;
      ll n,w;
      cin>>n>>w;
      for(ll i=1; i<=n; i++){
            ll w,v;
            cin>>w>>v;
            p.pb({v,w}); 
      }
      for(int i=0;i<=n;i++)
      	for(ll j=0; j<100001; j++){
      	      dp[i][j]=INF;
      	}
      dp[0][p[0].ft]=p[0].sd;
      dp[0][0]=0;
      
      for(int i=1;i<n;i++){
      	 for(int j=0;j<=100000;j++){
               dp[i][j]=dp[i-1][j];
               if(j>=p[i].ft)
                   dp[i][j]=min(dp[i][j],dp[i-1][j-p[i].ft]+p[i].sd);
      	 }
      }
      for(int i=100000;i>=0;i--){
      	if(dp[n-1][i]<=w){
      		cout<<i<<endl;
      		break;
      	}
      }
      
} 



Measured memory_bytes: 79360
#include <iostream>
#define CROSS_MAX 100
using namespace std;

int main() {
  int a, b;
  int data[CROSS_MAX][CROSS_MAX];
  for(int i = 0; i < CROSS_MAX; i++) {
    for(int j = 0; j < CROSS_MAX; j++) {
      data[i][j] = 0;
    }
  }
  while(cin >> a >> b) {
    if(a == 0 && b == 0) {
      bool flag = true;
      for(int i = 0; i < CROSS_MAX; i++) {
	int count = 0;
	for(int j = 0; j < CROSS_MAX; j++) {
	  count += data[i][j];
	}
	if(i == 0 && count % 2 == 0 || i == 1 && count % 2 == 0) flag = false;
	if(i != 0 && i != 1 && count % 2 != 0) flag = false;
      }
      if(flag) cout << "OK" << endl;
      else     cout << "NG" << endl;

      for(int i = 0; i < CROSS_MAX; i++) {
	for(int j = 0; j < CROSS_MAX; j++) {
	  data[i][j] = 0;
	}
      }
    } else {
      data[a-1][b-1]++;
      data[b-1][a-1]++;
    }
  }
  return 0;
}

Measured memory_bytes: 0
N = int(input())
X = list(map(int, input().split()))

dp = [[0, 0] for _ in range(N + 1)]
dp[0][1] = -10**9
for i in range(N):
    dp[i + 1][0] = max(dp[i][0] + X[i], dp[i][1] - X[i])
    dp[i + 1][1] = max(dp[i][0] - X[i], dp[i][1] + X[i])

print(dp[-1][0])


Measured memory_bytes: 99048
N = int(input())
Vs = list(map(int,input().split()))
Cs = list(map(int,input().split()))

Ss = []
for i in range(N):
	Ss.append([Vs[i],Cs[i],Vs[i]-Cs[i]])
	
Ss = sorted(Ss,key=lambda x: x[2],reverse=True)

ans = 0
for s in Ss:
	if s[2] < 0:
		break
	
	ans += s[2]
	
print(ans)

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

typedef long long int LL;
typedef unsigned long long uLL;
typedef pair < int , int > ii;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 1e5 + 5;
const int mod = 1000000007;
const double eps = 1e-8;
const double pi = acos( -1.0 );

int main( int argc , char const *argv[] ) {
        ios_base :: sync_with_stdio(false); cin.tie(NULL);
        int a[5];
        cin >> a[1] >> a[2] >> a[3];
        sort( a+1 , a+4 );
        int ans = inf;
        do {
                ans = min( ans , abs(a[2]-a[1])+abs(a[3]-a[2] ) );
        } while( next_permutation( a+1 , a+4 ) );
        cout << ans << endl;
        return 0;
}








Measured memory_bytes: 256
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def _euclid(x, y):
    if x > y:
        large = x
        small = y
    else:
        large = y
        small = x

    if small == 0:
        return large

    return _euclid(small, large % small)


def euclid_multi(nums):
    if len(nums) == 1:
        return nums[0]

    e = -1
    for i in range(1, len(nums)):
        if e == -1:
            e = _euclid(nums[0], nums[1])
        else:
            e = _euclid(e, nums[i])
    return e


def solve(inputs):
    [N, X] = string_to_int(inputs[0])
    x = string_to_int(inputs[1])
    x.append(X)
    x.sort()
    diffs = []
    for i in range(len(x)-1):
        diffs.append(x[i+1] - x[i])

    e = euclid_multi(diffs)
    return e


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)


Measured memory_bytes: 15396
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
 
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,a[200000],b[200000];
	cin >> n;
	for(int i = 0;i < n;i++) cin >> a[i];
	for(int i = 0;i < n;i++){
		if(i % 2 == 0) b[i / 2] = a[n - i - 1];
		else b[n - i / 2 - 1] = a[n - i - 1];
	}
	for(int i = 0;i < n;i++) cout << (i ? " " : "") << b[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
//for(int i = 0; i < n; i++)
 
int main() {
  int n, a, b, ans = 0;
  long long x;
  string s;
  cin >> a >> b;
  //vector<int> v(n), c(n);
  //for(int i = 0; i < n; i++) cin >> .at(i);
  if(a <= 9 && b <= 9) ans = a * b;
  else ans = -1;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
static const int N = 20;

int main() {
    int n; cin >> n;
    int a[N], b[N], c[N - 1];

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n - 1; i++) cin >> c[i];

    int sum = b[a[0]];
    for (int i = 1; i < n; i++) {
        sum += b[a[i]] + (a[i] - a[i - 1] == 1 ? c[a[i] - 1] : 0);
    }

    cout << sum << endl;
 
    return 0;
}

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

int main(){
    ll n;
    cin >> n;
    ll ac=0,wa=0,tle=0,re=0;
    for(ll i=0;i<n;i++){
        string s;
        cin >> s;
        if(s=="AC") ac++;
        if(s=="WA") wa++;
        if(s=="TLE") tle++;
        if(s=="RE") re++;
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}


Measured memory_bytes: 3628
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  cout << (abs(x - a) < abs(x - b) ? 'A' : 'B') << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int H,W,N;
  cin>>H>>W>>N;
  int c[H*W];
  int ic=0;
  REP(i,N){
    int a;
    cin>>a;
    REP(j,a){
      c[ic]=i+1;
      ic++;
    }
  }
  REP(i,H/2){
    reverse(c+W*(2*i+1),c+W*(2*i+2));
  }
  REP(i,H){
    REP(j,W)cout<<c[i*W+j]<<" ";
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
vector<char> S;
vector<string> calc(vector<string> s){
    vector<string> ret;
    for(auto t:s){
        int x=0;
        For(i,0,t.size()){
            x=max(x,t[i]-'a');
        }
        For(i,0,x+2){
            ret.push_back(t+S[i]);
        }
    }
    return ret;
}
void Main(){
    int n;cin>>n;
    For(i,0,n) S.push_back('a'+i);
    vector<string> A;
    A.push_back("a");
    For(i,0,n-1){
        A=calc(A);
    }
    for(auto t:A){
        cout<<t<<endl;
    }
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

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

typedef long long ll;

int main()
{
    int N,a;
    ll d;
    scanf("%d",&N);
    int cnt1=0,cnt2=0,cnt4=0;
    for(int i=0;i<N;i++)
    {
        scanf("%lld",&d);
        if(d%4==0)  cnt4++;
        else if(d%2==0) cnt2++;
        else cnt1++;
    }
    if(cnt1<=cnt4) cout<<"Yes"<<endl;
    else if(cnt2==0&&cnt1<=cnt4+1)  cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
N=int(input())
P=list(map(int,input().split()))
s=0
for i in range(N-1):
  if P[i]==i+1:
    P[i],P[i+1]=P[i+1],P[i]
    s+=1
if P[-1]==N:
  s+=1 
print(s)    

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

int main() {
    int N;
    cin >> N;
    int r = 0;
    for(int i = 0; i < N; i++){
        int j, k;
        cin >> j >> k;
        r += k - j + 1;
    }
    cout << r << endl;
  // ここにプログラムを追記
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <algorithm>
using namespace std;

int N, A, B;
string ranklist;
int cntA, cntB;

int main() {
	cin >> N >> A >> B;
	cin >> ranklist;

	for (int i = 0; i < N; i++) {
		if (ranklist[i] == 'a') {
			cntA++;
			if (cntA + cntB <= A + B) puts("Yes");
			else {
				puts("No");
				cntA--;
			}
		} else if (ranklist[i] == 'b') {
			cntB++;
			if (cntA + cntB <= A + B && cntB <= B) puts("Yes");
			else {
				puts("No");
				cntB--;
			}
		} else puts("No");
	}

	return 0;
}


Measured memory_bytes: 896
using System;

class quiz
{
    public int[] solve(int N, int M, int[] A)
    {
        int[] Aprime = new int[N];

        for (int i = 0; i < N; i++)
        {
            Aprime[i] = A[i];
        }

        for (int i = 2; i < M + 1; i++)
        {
            for (int j = 0; j < N - 1; j++)
            {
                if (Aprime[j] % i > Aprime[j + 1] % i)
                {
                    Aprime[j] ^= Aprime[j + 1];
                    Aprime[j + 1] ^= Aprime[j];
                    Aprime[j] ^= Aprime[j + 1];
                }
            }
        }

        return Aprime;
    }

    public int[] ParseIntBySpace(string str)
    {
        int[] array = new int[str.Length];
        int lastloc = 0, spaceloc = -1;

        for (int i = 0; i < str.Length; i++)
        {
            if (str[i] == ' ')
            {
                array[lastloc++] = int.Parse(str.Substring(spaceloc + 1, i - spaceloc - 1));
                spaceloc = i;
            }
            else if (i == str.Length - 1)
            {
                array[lastloc++] = int.Parse(str.Substring(spaceloc + 1, i - spaceloc));
            }
        }

        Array.Resize(ref array, lastloc);

        return array;
    }
}

class Example
{
    static void Main()
    {
        quiz ex = new quiz();

        int[] NM = ex.ParseIntBySpace(Console.ReadLine());

        int[] A = new int[NM[0]];

        for (int i = 0; i < NM[0]; i++)
        {
            A[i] = int.Parse(Console.ReadLine());
        }

        int[] ans = ex.solve(NM[0], NM[1], A);

        for (int i = 0; i < NM[0]; i++)
        {
            Console.WriteLine(ans[i]);
        }
    }
}


Measured memory_bytes: 15988
#ifndef DEBUG
#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i <= i##_len; ++i)
#define rep3(i, l, r) for (int i = l, i##_len = (r); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = l, i##_len = (r); i <= i##_len; ++i)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 62;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

template <class T>
inline bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
inline T Gcd(T a, T b) {
    T c;
    while (b) {
        c = b;
        b = a % b;
        a = c;
    }
    return a;
}

Int Lcm(Int a, Int b) {
    if (a < b) {
        swap(a, b);
    }

    return a / Gcd(a, b) * b;
}

vector<Int> prime_factor(Int n) {
    map<Int, int> r;
    for (Int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            r[i]++;
            n /= i;
        }
    }
    if (n != 1) {
        r[n] = 1;
    }

    vector<Int> ret(r.size());
    Int ind = 0;
    for (auto [x, y] : r) {
        ret[ind] = x;
        ind++;
    }
    return ret;
}

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

    Int n;
    cin >> n;
    vector<Int> a(n), l(n + 1);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for (Int i = 0; i < n; i++) {
        l[i + 1] = Gcd(l[i], a[i]);
    }

    set<Int> s;
    for (Int i = 0; i < n; i++) {
        vector<Int> pf = prime_factor(a[i]);
        bool flag = true;

        for (auto e : pf) {
            if (s.find(e) != s.end()) {
                flag = false;
                break;
            } else {
                s.insert(e);
            }
        }

        if (!flag) {
            if (l.back() == 1) {
                cout << "setwise coprime" << endl;
            } else {
                cout << "not coprime" << endl;
            }

            return 0;
        }
    }

    cout << "pairwise coprime" << endl;

    return 0;
}


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

using namespace std;
typedef long long int ll;

#define ALL(v) v.begin(),v.end()

map<ll, ll> prime_factor(ll n) {
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

int main(int argc, char const *argv[])
{
    ll n, p;
    cin >> n >> p;
    auto m = prime_factor(p);
    ll ans = 1;
    for (auto x : m)
    {
        while(x.second >= n)
        {
            ans *= x.first;
            x.second -= n;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;


int main(){
    long long n;
    long long k;

    

    cin >> n >> k;

    long long minv = n;

    if(n >= k){
        if(n % k == 0){
            printf("0\n");
        }
        else{
            n = n % k;
            minv = n;
            minv = min(n , abs(minv - k));
            printf("%lld\n", minv);
        }
    }
    else{
        minv = min(n , abs(minv - k));

        printf("%lld\n", minv);

    }

    return 0;

 
}

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

struct Data{
    int pos;
    int num;
};

bool cmp(const Data &a, const Data &b)
{
    return a.num > b.num;
}

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

    vector<Data> a(n);
    for(int i = 0; i<n; i++){
        a[i].pos = i;
        cin>>a[i].num;
    }

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

    for(int i = 0; i<n; i++){
        if(i == a[0].pos){
            cout << a[1].num << endl;
        }else{
            cout << a[0].num << endl;
        }       
    }
    
}

Measured memory_bytes: 3200
# import math
# from fractions import gcd

import numpy as np
# import scipy as scp

# 入力の受け取り
n,m = map(int,input().split())
# 列ベクトルとかの受け取り
times = m
table = []
for _ in range(times):
    table.append(list(input().split()))

statusAC = {}
answer_status = {}

for question_num , ACorWA in table:
    question_num = int(question_num)
    if question_num in statusAC:
        continue
    else:
        if ACorWA == "AC":
            statusAC[question_num] = "AC"
            if question_num in answer_status:
                answer_status[question_num] += ACorWA
            else:
                answer_status[question_num] = ACorWA
        else:
            if question_num in answer_status:
                answer_status[question_num] += ACorWA
            else:
                answer_status[question_num] = ACorWA

def penalty_count(dic):
    penalty_count = 0
    for num in dic:
        if "AC" in dic[num]:
            penalty_count  += (len(dic[num])-2)//2
        else:
            continue
    return penalty_count

# print(answer_status)
ans = len(statusAC)
penalty = penalty_count(answer_status)

print(ans,penalty)

Measured memory_bytes: 53356
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    
    let mut iter = buf.split_whitespace();
    
    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut a = iter.next().unwrap().to_string();
    let mut b = iter.next().unwrap().to_string();
    let mut c = iter.next().unwrap().to_string();
    
    let mut count = 0;
    
    for i in 0..n {
        let t1 = a.pop().unwrap();
        let t2 = b.pop().unwrap();
        let t3 = c.pop().unwrap();
        
        match (t1 == t2, t2 == t3, t3 == t1) {
            (false, false, false) => count += 2,
            (true, false, false) |
            (false, true, false) |
            (false, false, true) => count += 1,
            _ => ()
        }
    }
    
    println!("{}", count);
}

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

int main()
{
	int A,B,C;
	cin >> A >> B >> C;
	if (A + B >= C)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);



int n , m;


void solve(int testCase){

    scanf("%d" , &n);
    cout << 1 - n << endl;


}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


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

int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	map<char,vector<int> > ma;
	for(int i=0;i<n;i++) ma[s[i]].push_back(i);
	long long ans=1;
	ans=1ll*ma['R'].size()*ma['G'].size()*ma['B'].size();
	// cout<<ans;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
		{
			if(s[i]!=s[j])
			{
				if((i+j)%2 == 0)
				{
					if(s[(i+j)/2] !=s[i] and s[(i+j)/2] !=s[j]) ans--;
				}
			}
		}	
	cout<<ans;	
	return 0;
}


Measured memory_bytes: 3672
import itertools
import math

N =int(input())
X = []
Y = []
for i in range(N):
  x, y = map(int, input().split())
  X += [x]
  Y += [y]

ans = []
for v in itertools.permutations(range(N)):
  curr = 0
  for i in range(N-1):
    curr += ((X[v[i]] - X[v[i+1]])**2 + (Y[v[i]] - Y[v[i+1]])**2 )**.5
  ans += [curr]

print(sum(ans)/math.factorial(N))

Measured memory_bytes: 4400
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int a[10000];

int main() {
    int n;
    cin >> n;
    VI d(n);
    REP(i,n) cin >> d[i];

    REP(k,4){
        REP(i,n-k){
            int s = 0;
            FOR(j,i,i+k){
                s = 10 * s + d[j];
            }
            a[s] = 1;
        }
    }

    REP(i,10000){
        if (!a[i]){
            cout << i << endl;
            break;
        }
    }


    return 0;
}

Measured memory_bytes: 3088
#include <stdio.h>

int main(void){
   int n,i,w3,w5;
   long int total=0;
   scanf("%d",&n);

   for(i=1;i<=n;i++){
      w3=0; w5=0;
      if(i%3==0) w3=1;
      if(i%5==0) w5=1;

      if(w3+w5==0) total+=i;
   }

   printf("%ld\n",total);
   return 0;
}

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

#define endl "\n"

int main ()
{
	
	
    #define int long long
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   	string s;
   	cin >> s;

   	cout << s.substr(0, 3) << endl; 

   
	
	return 0;
}

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

int main() {
  long long int x=100,z,count=0;
  cin>>z;
  int i=1;
while(i)
{   x+=x/100;
  count++;
    if(x>=z)
    i=0;
  }
  cout<<count<<endl;
}


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

public class Main{
  public static void main(String[] args){
    String[] sX = null;
    String[] sY = null;
    String[] sZ;
    int[][] LCS = null;
    String temp;
    int q;
    
    Scanner sc = new Scanner(System.in);
    q = sc.nextInt();
    int[] ans = new int[q];
    sc.nextLine();
    
    for(int i = 0; i < q; i++){
      temp = sc.nextLine() + " ";
      sX = temp.split("");
      temp = sc.nextLine() + " ";
      sY = temp.split("");
      
      LCS = new int[sX.length+1][sY.length+1];
      
      for(int k = 0; k <= sX.length; k++){
        for(int j = 0; j <= sY.length; j++){
          if(j == 0 || k == 0){
            LCS[k][j] = 0;
          }
          else if(sX[k-1].equals(sY[j-1])){
            LCS[k][j] = 1 + LCS[k-1][j-1];
          }
          else{
            LCS[k][j] = Math.max(LCS[k-1][j],LCS[k][j-1]);
          }
        }
      }
      ans[i] = LCS[sX.length-1][sY.length-1];
    }
    
    for(int i = 0; i < ans.length; i++){
      System.out.println(ans[i]);
    }
  }
}


Measured memory_bytes: 65112
import java.util.Scanner;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String str = scan.nextLine();
    var N = Integer.parseInt(str);
    int ans[] = new int[10050];
    double x,y,z;
    int a;
    double b;

    for (x = 1; x <= 105; x++){
      for (y = 1; y <= 105; y++){
        for (z = 1; z <= 105; z++){
           b = Math.pow(x,2)+Math.pow(y,2)+Math.pow(z,2)+(x*y)+(y*z)+(z*x);
           if( (int)b < 10050 ){
      	     ans[(int)b-1]++;
           }
        }
      }
    }

    for (var i = 0;i < N;i++) {
      System.out.println(ans[i]);
    }

    scan.close();
  }
}

Measured memory_bytes: 39080
N, M = map(int, input().split())
shop_list = []
for i in range(N):
    A, B = map(int, input().split())
    shop_list.append([A,B])
shop_list.sort()    
sum_money = 0
bought_m = 0

for shop in shop_list:
    for i in range(shop[1]):
        if bought_m == M:
            print(sum_money)
            exit()
        bought_m += 1
        sum_money += shop[0]
if bought_m == M:
	print(sum_money)

Measured memory_bytes: 20080
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int h = sc.nextInt();
    int m = sc.nextInt();
    double d = 0;
    int x = 6*m;
    double y = 0.5*m + 30*h;
    double z = Math.abs(x-y);
    // System.out.println(z);
    if(z<=180){
      d = z;
    }else{
      d= 360-z;
    }
    double rad = Math.toRadians(z);
    double A = a*a;
    double B = b*b;
    double C = 2*a*b*Math.cos(rad);
    System.out.println(Math.sqrt(A+B-C));
  }
}


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

int getnum() {
    char C; int s = 0, t = 1;
    while (!isdigit(C = getchar())) if(C=='-') t=-1;
    do {s = s * 10 + C - '0'; } while( isdigit(C = getchar()));
    return s * t;
}   

int main() {
  int N = getnum();
  int K = getnum();
  vector<int> A(200000, 0);
  int maxint = 0, minint = 2000000;
  for (int i = 0; i < N; i++) {
    int a = getnum();
    A[a]++;
    maxint = max(maxint, a);
    minint = min(minint, a);
  }
  if (maxint-minint+1<= K) printf("%d\n", 0);
  else {
    sort(A.begin()+minint, A.begin()+maxint+1);
    int cnt = 0, i = 1;
    while(i<=maxint-K) {
    cnt += A[i];
    i++;
    }
    printf("%d\n", cnt);
  }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long int dp[100005];
long long int call(int p,int ar[])
{
	if(p==1)
		return fabs(ar[p]-ar[p-1]);
	if(p==2)
		return min(call(1,ar)+fabs(ar[2]-ar[1]),fabs(ar[2]-ar[0]));
	if(dp[p]==-1)
	{
		dp[p]=min(call(p-1,ar)+fabs(ar[p-1]-ar[p]),call(p-2,ar)+fabs(ar[p-2]-ar[p]));
	}
	return dp[p];
}
int main()
{
	int n;
	cin>>n;
	int ar[n];
	for(int i=0;i<n;i++)
		cin>>ar[i];
	for(int i=0;i<n;i++)
		dp[i]=-1;
	long long int ans=call(n-1,ar);
	cout<<ans<<endl;

}



Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
const int maxn=100000+10;
int x[maxn],xx[maxn],w[maxn];
int k,l,r,s,t,n,m;
long long c;
inline int read(){
	int r=0,w=1;
	char ch=getchar();
	while(ch>'9'||ch<'0'){ if(ch=='-') w=-1;ch=getchar(); }
	while(ch>='0'&&ch<='9'){ r=r*10+ch-'0'; ch=getchar(); }
	return r*w;
}
int main(){
    n=read(),l=read(),t=read();
    for(int i=1;i<=n;i++)
        x[i]=read(),w[i]=read();
	for(int i=1;i<=n;i++){
        if (w[i]==2) w[i]=-1;
        r=x[i]+w[i]*t;
        if (r>0) (c+=r/l)%=n;
        else if (r<0) (c+=(r+1)/l-1)%=n;
        xx[i]=(r%l+l)%l;
    }
    sort(xx+1,xx+n+1);
    c=(c+n)%n;
    for(int i=c+1;i<=n;i++)
        printf("%d\n",xx[i]);
    for(int i=1;i<=c;i++) printf("%d\n",xx[i]);
}

Measured memory_bytes: 2304