akhauriyash/Code-Regression huggingface dataset:
use proconio::input;
use std::cmp::{max, min};

const MAX_L: u32 = 100_000;
const BASE_SIZE: usize = 1 << 8;

fn main() {
    input! {
        n: usize,
        vw: [(u32, u32); n],
        q: usize,
        vl: [(usize, u32); q],
    }
    let dp = make_dp(&vw);
    for vlq in vl {
        println!("{}", calc(&vw, vlq.0 - 1, vlq.1, &dp));
    }
}

fn make_dp(vw: &Vec<(u32, u32)>) -> Vec<Vec<u32>> {
    let mut dp = Vec::<Vec<u32>>::new();

    dp.push(
        (0..=MAX_L)
        .map(|i| if i < vw[0].1 { 0 } else { vw[0].0 })
        .collect()
    );

    let n = min(vw.len(), BASE_SIZE - 1);
    for c in 1..n {
        let p = (c - 1) / 2;
        dp.push(
            (0..=MAX_L)
            .map(|i| {
                let w = vw[c].1;
                let v = if i < w { 0 } else { dp[p][(i - w) as usize] + vw[c].0 };
                max(dp[p][i as usize], v)
            })
            .collect()
        );
    }

    dp
}

fn calc(
    vw: &Vec<(u32, u32)>,
    u: usize, 
    l: u32,
    dp: &Vec<Vec<u32>>
) -> u32 {
    if u < dp.len() {
        dp[u][l as usize]
    } else {
        let p = (u - 1) / 2;
        let w = vw[u].1;
        let pv1 = calc(vw, p, l, dp);
        let pv2 = if l < w { 0 } else { calc(vw, p, l - w, dp) + vw[u].0 };
        max(pv1, pv2)
    }
}


Measured memory_bytes: 110008
import java.util.Scanner;

public class Main {
	public static boolean is(String s){
		char c[]=s.toCharArray();
		int n=c.length;
		for(int i=0;i<=n/2;i++){
			if(c[i]!=c[n-i-1]){
				return false;
			}
		}
		return true;
		
	}
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		System.out.println((is(s)&&is(s.substring(0,(s.length()-1)/2))&&is(s.substring((s.length()+1)/2))?"Yes":"No"));
	}
}


Measured memory_bytes: 21844
import sys

input = sys.stdin.readline
P = 10 ** 9 + 7


def main():
    N, K = map(int, input().split())

    ans = 0
    n_gcd = [0] * (K + 1)
    for k in reversed(range(1, K + 1)):
        n_gcd[k] = pow(K // k, N, mod=P)
        for m in range(2, K // k + 1):
            n_gcd[k] = (n_gcd[k] - n_gcd[k * m]) % P
        ans = (ans + k * n_gcd[k]) % P

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 11152
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int max = Math.max(Math.max(a, b), c);
    int tag = 0;

    if (((a + b + c) % 2) == 0) {
      if ((max % 2) == 0) {
        tag = max;
      } else {
        tag = max + 1;
      }
    } else {
      if ((max % 2) != 0) {
        tag = max;
      } else {
        tag = max + 1;
      }
    }

    int sum = (3 * tag) - (a + b + c);
    System.out.println((sum + 1) / 2);

  }
}

Measured memory_bytes: 35652
#include<bits/stdc++.h>
#define int long long
using namespace std;
int x;
signed main()
{
	cin>>x;
	x%=10;
	switch(x)
	{
		case 2:case 4:case 5:case 7:case 9:{printf("hon");break;}
		case 0:case 1:case 6:case 8:{printf("pon");break;}
		case 3:{printf("bon");break;}
	}
    return 0;
}

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

using ll = long long int;
using bigint = int64_t;

#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define bitcount __builtin_popcount
#define endl "\n"
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define deb(x) cout << #x << " = " << x << endl;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define ffi(i,a,b,c) for(ll i = a ; i <= b ; i += c)
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int MOD = 1000000007;

void io_set() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

bool pal(string s, ll l, ll r){
    ll j = 0;
    for(ll i = l; i <= (r+l)/2; i++){
        if(s[i] != s[r- j]){
            return false;
        }
        j++;
    }
    return true;
}

void solve() {
    string s;
    cin >> s;
    ll n = sz(s);
    cout << ((pal(s, 0, n - 1) && pal(s, 0, (((n - 1) / 2) - 1)) && pal(s, (((n + 3) / 2) - 1), n - 1)) ? "Yes\n" : "No\n");
}

int main() {
    IOS;
    //io_set();
    ll tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    int P[200010];
    for (int i = 0; i < N; i++) cin >> P[i];

    int minv = P[0], ans = 1;
    for (int i = 1; i < N; i++) {
        if (P[i] < minv) {
            ans++;
            minv = P[i];
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <fstream>
#include <bitset>
#include <cstdio>
#include <sstream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <cctype>
#include <iomanip>
#include <list>
#include <cstring>

#define INF 2000000000
#define ull unsigned long long int
#define vi vector<int>
#define vii vector<ii>

#define UNVISITED 0
#define OPENED 1
#define CLOSED 2

#define PI 3.14159


using namespace std;
    
vector <int> tab;

int main () {

    int n;
    scanf("%d", &n);
    

    for(int i = 0; i < n; i++) {
        
        int a;
        scanf("%d", &a); 
        tab.push_back(a);
    }

    long long int mini = INF;

    for(int j = -100; j <= 100; j++) {
        long long int sum = 0;
        for(int i= 0; i< n; i++) {
            sum += (tab[i]-j)*(tab[i]-j);
        }

        mini = min(sum, mini);
    }
    
    cout << mini << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import Counter
N,*A = map(int, open(0).read().split())
Cnt = Counter(A)
m = 2**31
ans = 0
for i in range(31):
  for k in Cnt.keys():
    if Cnt[k]==0:
      continue
    if k==m-k:
      ans += Cnt[k]//2
      Cnt[k] %= 2
    else:
      if Cnt[m-k]==0:
        continue
      if Cnt[k]<Cnt[m-k]:
        ans += Cnt[k]
        Cnt[m-k] -= Cnt[k]
        Cnt[k] = 0
      else:
        ans += Cnt[m-k]
        Cnt[k] -= Cnt[m-k]
        Cnt[m-k] = 0
  m >>= 1
print(ans)

Measured memory_bytes: 100764
#include<bits/stdc++.h>
using namespace std;
typedef vector <int> vi;
typedef set <int> se;
#define endl "\n"
#define rep(i,a,b) for(auto i = a;i<b;i++)

void solve(){
int n;
cin>>n;

string s = "ACL";
rep(i,0,n) cout<<s;


}
 
 
int main()
{
solve();
 
return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
using ll=long long;
using pint=pair<int,int>;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define el '\n'
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define ceil_div(a,b) (a+(b-1))/b
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
#define $in(v,n) ;rep(II,0,n)cin>>v[II]
inline void IN(void){return;}
template<typename F,typename... R>inline void IN(F& f, R&... r){cin>>f;IN(r...);}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}


int main(){
    int a, b, c; IN(a, b, c);
    puts(a+b+c >= 22 ? "bust" : "win");
    return 0;
}


Measured memory_bytes: 3024
#include<stdio.h>
int main()
{
  int i,n;
  double sum = 0;
  double x[100000];
  char u[3];
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%lf %s\n",&x[i],u);
    if(u[0]=='B')
      x[i] = x[i] * 380000.0;
    sum = sum + x[i];
  }
  
  printf("%lf",sum);
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
int cnt[114514];
int gcd(int x,int y){
	if( x < y ) return gcd( y, x );
	if( x % y == 0 ) return y;
	return gcd( y, x%y );
}
int lcm(int x,int y){
	return x*y/gcd(x,y);
}
signed main(){
	int n,m;
	cin>>n>>m;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		int c = a[i];
		while( c % 2 == 0 ){
			cnt[i]++;
			c /= 2;
		}
	}
	for(int i=0;i<n;i++){
		if( cnt[0] != cnt[i] ){
			cout<<0<<endl;
			return 0;
		}
	}
	int odr = cnt[0];
	int md = 1;
	for(int i=0;i<odr;i++){
		md *= 2;
	}
	for(int i=0;i<n;i++){
		a[i] /= md;
	}
	int cur = md;
	for(int i=0;i<n;i++){
		cur = lcm( cur, a[i] );
		if( cur > inf ){
			cout<<0<<endl;
			return 0;
		}
	}
	cur /= 2;
	cout<<( m/cur + 1 )/2<<endl;
	return 0;
}

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

int main() {
  vector<int> vec(3);
  for (int i = 0; i < 3; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end()); 
  reverse(vec.begin(), vec.end());
  cout << vec.at(0) - vec.at(2)<< endl;

}


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

using namespace std;

int main(int argc,char *argv[])
{
  int n=0;
  cin>>n;
  
  vector<int> ai;
  ai.resize(n-1);
  vector<int> bi;
  bi.resize(n);
  
  for(int i=0;i<n;i++){
    bi[i]=0;
  }
  
  for(int i=0;i<n-1;i++){
    cin>>ai[i];
  }
  
  for(int i=0;i<n-1;i++){
    bi[ai[i]-1]++;
  }
  
  for(int i=0;i<n;i++){
    cout<<bi[i]<<endl;
  }
}

Measured memory_bytes: 4788
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    int H=gi();
	    int W=gi();
	    int k=0;
        for (int i=0; i<H;i++) {
        	String s=gs();
        	for (int j=0; j<W;j++) {
        		char c=s.charAt(j);
        		if(c=='#')k++;
        	}
        }
	    //System.out.println(min);
        if(k==H+W-1) {
        	System.out.println("Possible");
        }else {
        	System.out.println("Impossible");
        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35620
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

#define MOD 1000000007;//1e9+7

void solve() {
    int N;
    cin >> N;
    vector<int>O(N),P(N), Q(N);
    for (int i = 0; i < N; i++)O[i] = i + 1;
    for (int i = 0; i < N; i++)cin >> P[i];
    for (int i = 0; i < N; i++)cin >> Q[i];

    int cnt = 1;
    int p = 0, q = 0;
    do {
        if (O == P)p = cnt;
        if (O == Q)q = cnt;
        if (p != 0 && q != 0)break;
        cnt++;
    } while (next_permutation(O.begin(), O.end()));

    cout << abs(p - q);
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

class UnionFind {
public:
    vector<int> parent;  //親ノード
    vector<int> Siz;  //集合の大きさ

    // コンストラクタ
    UnionFind(int n): parent(n), Siz(n, 1) {
        rep(i, n) {
            parent[i] = i;
        }
    }

    // n要素で初期化
    void init(int n) {
        parent.resize(n);
        Siz.assign(n, 1);
        rep(i, n) {
            parent[i] = i;
        }
    }

    // xの属する集合の根を求める
    int root(int x) {
        if(parent[x] == x) {
            return x;
        }
        else {
            return parent[x] = root(parent[x]);
        }
    }

    // xとyの属する集合を併合
    void unite(int x, int y) {

        x = root(x);
        y = root(y);
        if(x == y) {
            return;
        }

        if(Siz[x] < Siz[y]) {
            swap(x, y);
        }

        Siz[x] += Siz[y];
        parent[y] = x;
    }

    // xとyが同じ集合に属するかどうか
    bool same(int x, int y) {
        return root(x) == root(y);
    }

    // xの属する集合の要素数を求める
    int size(int x) {
        return Siz[root(x)];
    }
};

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

    UnionFind Uni(n);

    vector<int> a(m), b(m);
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--;  b[i]--;
    }

    int ans = 0;
    rep(i, m) {

        Uni.init(n);

        rep(j, m) {
            if(i == j) {
                continue;
            }
            Uni.unite(a[j], b[j]);
        }

        if(Uni.size(0) < n) {
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

vector<int> ans;

void solve(int N, int M) {
    int r; cin >> r;
    vector<vector<int>> imos(M+1, vector<int>(1261));
    for (int i = 0; i < r; i++) {
        int t, n, m, s; cin >> t >> n >> m >> s;
        if (s) imos[m][t]++;
        else imos[m][t]--; 
    }
    for (int i = 1; i <= M; i++) {
        for (int j = 1; j < 1261; j++) {
            imos[i][j] += imos[i][j-1];
        }
    }
    int q; cin >> q;
    for (int i = 0; i < q; i++) {
        int s, e, m; cin >> s >> e >> m;
        int cnt = 0;
        for (int j = s; j < e; j++) {
            if (imos[m][j]) cnt++;
        }
        ans.push_back(cnt);
    }
}

int solve(int N) {
    vector<int> imos(60*60*24+1);
    for (int i = 0; i < N; i++) {    
        string h, m, s;
        getline(cin, h, ':');
        getline(cin, m, ':');
        getline(cin, s, ' ');
        int H = stoi(h);
        int M = stoi(m);
        int S = stoi(s);
        imos[H*60*60+M*60+S]++;
        getline(cin, h, ':');
        getline(cin, m, ':');
        getline(cin, s);
        H = stoi(h);
        M = stoi(m);
        S = stoi(s);
        imos[H*60*60+M*60+S]--;
    }
    int ret = 0;
    for (int i = 1; i < imos.size(); i++) {
        imos[i] += imos[i-1];
        ret = max(imos[i], ret);
    }
    return ret;
}

int main(void) {
    int N;
    vector<int> ans;
    while (1) {
        cin >> N;
        if (!N) break;
        ans.push_back(solve(N));
    }
    for (auto &i : ans) {
        cout << i << endl;
    }
}   


Measured memory_bytes: 3472
program sample
    implicit none
    character(500000)::s
    integer(8) :: i,j,m,n,a,b,c
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) s
    n=len_trim(s)
    a=1
    m=0
    b=0
    do i=1,n-1
        
        if (s(i:i)==s(i+1:i+1))then
            a=a+1
            
        else
            m=m+a*(a-1)/2
            if (s(i:i) .eq. '<')then
                 !頂上はまだ
                b=a
            else
                if (a>b)then
                    m=m+a
                else
                    m=m+b
                end if
            end if
        a=1
        end if
    enddo
    if (s(n:n) .eq. '<')then
       m=m+a*(a+1)/2
    else
        m=m+a*(a-1)/2
       if (a>b)then
           m=m+a
       else
           m=m+b
       end if
   end if


    write(*,*) m
  
    stop
end program sample
  



Measured memory_bytes: 3976
import sys
from collections import deque
import copy
 
from math import *
 
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline
 
def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, K] =  [long(input_raw[0]), long(input_raw[1])]
    x_list = [0 for i in range(N)]
    y_list = [0 for i in range(N)]
    point_set = set([])
    for i in range(N):
        input_raw = read_func().strip().split()
        [x, y] =  [long(input_raw[0]), long(input_raw[1])]
        x_list[i] = x
        y_list[i] = y
        point_set.add((x, y))
    h = {}
    gx = {}
    gy = {}
    for x in x_list:
        for y in y_list:
            num = 0
            num_gx = 0
            num_gy = 0
            for i in range(N):
                if x <= x_list[i] and y <= y_list[i]:
                    num += 1
                if x == x_list[i] and y <= y_list[i]:
                    num_gx += 1
                if y == y_list[i] and x <= x_list[i]:
                    num_gy += 1
            h[(x, y)] = num
            gx[(x, y)] = num_gx
            gy[(y, x)] = num_gy
##    for point in point_set:
##        for y in y_list: #count x point num of more y
##            if (point[0], y) not in gx:
##                gx[(point[0], y)] = 0
##            if point[1] >= y:
##                gx[(point[0], y)] += 1L
##
##    for point in point_set:
##        for x in x_list: #count y point num of more x
##            if (point[1], x) not in gy:
##                gy[(point[1], x)] = 0
##            if point[0] >= x:
##                gy[(point[1], x)] += 1L
 
 
    min_S = long(sys.maxint) * long(sys.maxint)
    for i in range(N):
        for j in range(i + 1, N):
            for m in range(N):
                for n in range(m + 1, N):
                    x1 = min(x_list[i], x_list[j])
                    x2 = max(x_list[i], x_list[j])
                    y1 = min(y_list[m], y_list[n])
                    y2 = max(y_list[m], y_list[n])
                    in_num =  (h[(x1, y1)] - h[(x2, y1)] - h[(x1, y2)] + h[(x2, y2)] +
                                gx[(x2, y1)] - gx[(x2, y2)] + gy[(y2, x1)] - gy[(y2, x2)] +
                                  (1 if (x2, y2) in point_set else 0))
##                    in_num = 0
##                    for k in range(N):
##                        xk = x_list[k]
##                        yk = y_list[k]
##                        if (xk <= max(x1, x2) and xk >= min(x1, x2) and
##                            yk <= max(y1, y2) and yk >= min(y1, y2)):
##                                in_num += 1
##                        if in_num >= K:
##                            break
                    if in_num >= K:
                        S= abs(x1 - x2) * abs(y1 - y2)
                        if S < min_S:
                            min_S = S
    print min_S
 
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 35944
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main a = new Main();
        a.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int k = scan.nextInt();
        int max = Math.max(Math.max(a,b),c);
        int answer = a+b+c - max + max * (int) Math.pow(2, k);
        System.out.println(answer);
    }

}


Measured memory_bytes: 23124
using System;
public class Hello{
    public static void Main(){
        int a = int.Parse(Console.ReadLine());
        int b = int.Parse(Console.ReadLine());
        int c = int.Parse(Console.ReadLine());
        int d = int.Parse(Console.ReadLine());
        int ans = Math.Min(a,b) + Math.Min(c,d);
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13140
import java.util.*;
import java.io.*;
import java.util.Arrays;
public class Main {
	public static void main (String [] args) throws IOException

	{
		Scanner s=new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		StringBuilder sb=new StringBuilder();

		int n=s.nextInt();
		int d=s.nextInt();
		int c=0;
		for (int i=0; i<n;i++)
		{
			int x=s.nextInt();
			int y=s.nextInt();
			double ans=Math.pow(x,2)+Math.pow(y,2);
			double res=Math.sqrt(ans);
			if (res<=d)
				c++;
		}
		pw.println(c);
		pw.flush();

}

















	public static void shuffle(int[] a)
	{
		int n = a.length;
		for(int i = 0; i < n; i++)
		{
			int r = i + (int)(Math.random() * (n - i));
			int tmp = a[i];
			a[i] = a[r];
			a[r] = tmp;
		}
	}





	static class Scanner
{
	StringTokenizer st;
	BufferedReader br;

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

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

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

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

	public String nextLine() throws IOException {return br.readLine();}

	public double nextDouble() throws IOException
	{
		String x = next();
		StringBuilder sb = new StringBuilder("0");
		double res = 0, f = 1;
		boolean dec = false, neg = false;
		int start = 0;
		if(x.charAt(0) == '-')
		{
			neg = true;
			start++;
		}
		for(int i = start; i < x.length(); i++)
			if(x.charAt(i) == '.')
			{
				res = Long.parseLong(sb.toString());
				sb = new StringBuilder("0");
				dec = true;
			}
			else
			{
				sb.append(x.charAt(i));
				if(dec)
					f *= 10;
			}
		res += Long.parseLong(sb.toString()) / f;
		return res * (neg?-1:1);
	}

	public boolean ready() throws IOException {return br.ready();}


}
}

Measured memory_bytes: 46524
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    int n,m;
    cin>>n>>m;
    int ans=n*(n-1)/2+m*(m-1)/2;
    cout<<ans<<"\n";
}


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


def solve(N: int, M: int, s: "List[int]", c: "List[int]"):
    s = [x-1 for x in s]
    answer = 'x' * N
    head_flag = False
    for i in range(M):
        if list(answer)[s[i]] == 'x':
            answer = answer[:s[i]] + str(c[i]) + answer[s[i]+1:]
        else:
            if str(c[i]) != answer[s[i]]:
                print(-1)
                return
        if s[i] == 0 and c[i]==0:
            head_flag = True
    answer = ''.join(answer)
    answer = answer.replace('x', '0')
    answer = str(int(answer))
    if len(answer) != N and head_flag ==True:
        print(-1)
    elif len(answer) < N:
        answer = '1' + '0' * (N - len(answer) - 1) + answer
        print(answer)
    elif len(answer) == N:
        print(answer)
    else:
        print(-1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, s, c)

if __name__ == '__main__':
    main()


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

#define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
#define RIT(it,c) for(__typeof(c.begin()) it = c.begin();it!=c.end();it++)
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x).size()
#define MSET(m,v) memset(m,v,sizeof(m))


using namespace std;


typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<LL> vL;
typedef vector<bool> vb;
typedef pair<int,vi> iv;
typedef pair<LL,LL> pLL; 


int main(){
	int N,ans = 0, cnt = 0;
	cin>>N;
	for(int i=1;i<=N;++i){
		int p;
		cin>>p;
		if(p==i) ++cnt;
		else{
			ans += (cnt+1)/2;
			cnt = 0;
		}
	}
	ans += (cnt+1)/2;
	cout<<ans<<endl;
	return 0; 
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;
int main()
{
  int n;
  for(;cin>>n,n;)
    {
      map<int,int> data;
      bool no = true;
      int max_cnt =0;
      int max_num =-1;
      for(int i=0;i<n;i++)
	{
	  int tmp;
	  cin>>tmp;
	  data[tmp]++;
	  if(data[tmp]==max_cnt)
	    {
	      //	      no=true;
	    }
	  else if(data[tmp]>max_cnt)
	    {
	      //	      no=false;
	      max_cnt=data[tmp];
	      max_num=tmp;
	    }
	}
      if(max_cnt*2<=n)
	cout<<"NO COLOR"<<endl;
      else
	cout<<max_num<<endl;
    }
}

Measured memory_bytes: 2728
#include <iostream>

using namespace std;
int main() {
  string s;
  cin >> s;
  int i;
  if(s[0] == '1') ++i;
  if(s[1] == '1') ++i;
  if(s[2] == '1') ++i;
  cout << i << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define SIZE 100
int stack[SIZE];
int n=0;

void push(int x){
    stack[n]=x;
    n++;
}
int pop(){
    n--;
    return stack[n];
}

int main(void){
    char c;
    int x,a,b;
    
    while((c=getchar())!=EOF){
        if(isdigit(c)){
            ungetc(c,stdin);
            scanf("%d",&x);
            push(x);
        }else{
            switch(c){
                case '+':
                push(pop()+pop());
                break;
                case '-':
                b=pop();
                a=pop();
                push(a-b);
                break;
                case '*':
                push(pop()*pop());
                break;
                case ' ':
                break;
                default:
                break;
            }
        }
    }
    printf("%d\n",pop());
    return 0;
}


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

#define int long long

const int N = 2e5 + 10;
int n, ans = N, psum[2][N];
string s;

int32_t main() {
	cin >> n >> s;
	for (int i = 1; i <= n; i++) {
		if (s[i - 1] == '#') {
			psum[1][i] = psum[1][i - 1] + 1;
			psum[0][i] = psum[0][i - 1];
		}
		else {
			psum[1][i] = psum[1][i - 1];
			psum[0][i] = psum[0][i - 1] + 1;
		}
	}
	
	ans = min(psum[0][n], psum[1][n]);
	for (int i = 0; i < n; i++) 
		ans = min(ans, psum[1][i + 1] + psum[0][n] - psum[0][i + 1]);
	cout << ans;
}

Measured memory_bytes: 3716
float q;
A,B,C,D,E,F,R;
M(a,b,c,d,e,f){
	e=c-a;
	f=d-b;
	q=fabs(-f*a+e*b)/hypot(e,f);
	return a*e+b*f<0&c*e+d*f>0&q<=R?q<R?2:1:0;
}
I(){
	q=E*B-F*A;
	return(C*F-D*E)*q>0&q*(A*D-B*C)>0;
}
main(v,w,o,c){
	for(;scanf("%d%d%d%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F,&v,&w,&R),A;){
		A-=v,B-=w;
		C-=v,D-=w;
		E-=v,F-=w;
		o=(A*A+B*B>R*R)+(C*C+D*D>R*R)+(E*E+F*F>R*R);
		c=M(C,D,E,F)|M(E,F,A,B)|M(A,B,C,D);
		if(o){
			if(o-3|c&2){
				puts("c");
			}else{
				if(I())
					puts("a");
				else{
					if(c&1){
						puts("c");
					}else{
						puts("d");
					}
				}
			}
		}else{
			puts("b");
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <set>
#include <utility>
#include <functional>
#include<cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int,pii> P;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const int inf = 1e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

struct UnionFind{
    vector<int> par,rank;
    UnionFind(int n):par(n),rank(n){
        for(int i=0;i<n;++i) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        int rx=root(x),ry=root(y);
        if(rx==ry) return ;
        if(rank[ry]>rank[rx]) par[rx]=ry;
        else par[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};

vector<ll> fac,inv,finv;

void initcom(){
    fac=inv=finv=vector<ll>(1e6);
    fac[0]=fac[1]=1;
    inv[1]=1;
    finv[0]=finv[1]=1;
    for(ll i=2;i<1e6;++i){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll com(int n,int k){
    if(n<0||k<0) return 0;
    if(n<k) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
ll mopow(ll a,ll x,ll mod){
    ll res=1;
    while(x>0){
        if(x&1) res=res*a%mod;
        a=a*a%mod;
        x>>=1;
    }
    return res;
}

bool warp[5][5];
int maze[3010][3010];
int cnt[3010][3010];
int h,w;
vector<string> s;
int c;
void dfs(int y,int x){
    cnt[y][x]=c;
    for(int i=0;i<4;++i){
        int ny=y+dy[i],nx=x+dx[i];
        if(!(ny>=0&&ny<h&&nx>=0&&ny<w)) continue;
        if(s[ny][nx]=='#') continue;
        if(cnt[y][x]>0) continue;
        dfs(ny,nx);
    }
}
int main(){
    int n;cin>>n;
    vector<ll> a(n),s(n,0);
    for(int i=0;i<n;++i){
        cin>>a[i];
        if(i<n-1){
            s[i+1]=s[i]+a[i];
            s[i+1]%=MOD;
        }
    }
    ll ans=0;
    for(int i=1;i<n;++i){
        ans+=a[i]*s[i]%MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6368
N, M = gets.split.map(&:to_i)

Q, Ikr, FullBit = [], Hash.new{|h,k| h[k] = 100001 }, (1<<N)-1
master_key = 0
M.times{|i|
	a, c = gets.to_i, gets.split.map(&:to_i)
	tkrbit = c.inject(0){|bit, tkr|
		bit | (1<<(tkr-1))
	}
	next if Ikr[tkrbit] < a
	master_key |= tkrbit
	Ikr[tkrbit] = a
	Q << ((a<<N)|tkrbit)
}
if master_key != FullBit
	p -1
	exit
end

Q.sort!
while lowest = Q.shift
	low_cost, low_tkrbit = lowest>>N, lowest&FullBit
	next if Ikr[low_tkrbit] < low_cost
	break if low_tkrbit == FullBit

	q, r = [], []
	while kg = Q.shift
		cost, tkrbit = kg>>N, kg&FullBit
		next if Ikr[tkrbit] < cost
		q << kg

		cost, tkrbit = low_cost+cost, low_tkrbit|tkrbit
		next if Ikr[tkrbit] <= cost
		Ikr[tkrbit] = cost
		r << ((cost<<N)|tkrbit)
	end

	until q.empty?
		unless r.empty?
			Q << (q[0] < r[0] ? q : r).shift
		else
			Q.concat(q)
			q.clear
		end
	end
	Q.concat r
end
p Ikr[FullBit]


Measured memory_bytes: 3960
#!python3

iim = lambda: map(int, input().rstrip().split())

inf = 10**18 + 1

def cnt_val(a, b, x, cache):
    ans = 0
    la, lb = len(a), len(b)
    J = (i for i in range(lb)) if a == b else (-1 for i in range(la))

    if len(cache) == 0:
        ca = [x, 0]
        cb = [inf, lb-1]
        cache.append(ca)
        cache.append(cb)
    else:
        ca, cb = cache
        if x <= ca[0]:
            cache[0], cache[1] = ca, cb = cb, ca
        ca[0] = x

    j = cb[1]
    #for i in range(la):
    for i, k in enumerate(J):
        xa = a[i]

        for j in range(j, k, -1):
            x1 = b[j] * xa
            if x1 <= x:
                break
        else:
            break
        ans += j - k
        if i == 0:
            ca[1] = j

    return ans

def resolve():
    N, K = iim()
    A = [[] for i in range(3)]
    for x in input().split():
        x = int(x)
        if x < 0:
            i = 0
        elif x == 0:
            i = 1
        else:
            i = 2

        A[i].append(x)

    a0 = len(A[0]) * len(A[2])
    s1 = len(A[1])
    a1 = s1 * (2*N - s1 -1) // 2
    K1 = K - 1

    if a0 < K1 < a0 + a1:
        print(0)
        return

    if K1 < a0:
        A[0].sort()
        A[2].sort(reverse=True)
        #print(A[0], A[2])
        lo, hi = A[0][0]*A[2][0], A[0][-1] * A[2][-1] + 1
        cache1 = []
        #print((lo, hi), K1)
        while lo < hi:
            mid = (lo + hi) // 2
            k = cnt_val(A[0], A[2], mid, cache1)
            #print((lo, hi), mid, k, K1)
            if k <= K1:
                lo = mid + 1
            else:
                hi = mid
        print(lo)
        return

    A0 = list(map(lambda x: -x, A[0]))
    A0.sort()
    A[2].sort()
    K3 = K - a0 - a1 - 1
    #print(A[0], A[2], a0, a1, K3)
    lo, hi = 0, 10**18
    cache1, cache2 = [], []
    while lo < hi:
        mid = (lo + hi) // 2
        k3 = cnt_val(A0, A0, mid, cache1) + cnt_val(A[2], A[2], mid, cache2)
        #print((lo, hi), k3, K3)
        if k3 <= K3:
            lo = mid + 1
        else:
            hi = mid
    print(lo)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 97236
S=input()

b = S[0]
n=len(S)
res=10**9
if("1" not in S):
    print(n)
    exit()
if("0" not in S):
    print(n)
    exit()
for i in range(1,n):
    if S[i]!=b:
        res=min(res,max(i,n-(i)))
    b=S[i]

print(res)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <cstring>
#include <cctype>
using namespace std;
int main(int argc, char *argv[])
{
	string s;
	cin>>s;
	bool ok;
	if(s[0]=='A')
		ok=true;
	else
	{printf("WA\n");return 0;}
	int l=s.length();
	int cn=0;
	for(int i=1;i<l;i++)
	{
		if(isupper(s[i]))
		{
			if(s[i]!='C'||i==l-1||i==1||(cn==1&&s[i]=='C'))
			{printf("WA\n");return 0;}
			else if(s[i]=='C')
			cn++;
		}
	}
	if(cn==1&&ok)
		printf("AC\n");
	else
		printf("WA\n");
	return 0;
}

Measured memory_bytes: 384
def main(n, a_b):
    a_b.sort(key=lambda a_b: a_b[1])

    t = 0
    for a, b in a_b:
        t += a
        if t > b:
            print('No')
            return

    print('Yes')


if __name__ == "__main__":
    n = int(input())
    a_b = [list(map(int, input().split())) for _ in range(n)]

    main(n, a_b)


Measured memory_bytes: 53712
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<unordered_set>
#include<unordered_map>
#include<set>
#include<map>
#include<list>

using namespace std;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int gcd(int a, int b){
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
int main(){
    int K;
    cin >> K;
    ll ans = 0;
    rep(i, K) {
        rep(j, K) {
            rep(k, K) {
                ans += gcd(gcd(i+1, j+1), k+1);
            }
        }
    }
    cout << ans << endl;


	return 0;
}


Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(in.readLine());
      char[] ch = {'M','A','R','C','H'};
      long[] cnt = new long[5];
      char sf;
      for(int i=0; i<n; i++) {
        sf = in.readLine().charAt(0);
        for (int j=0; j<ch.length; j++) {
          if(sf == ch[j]) {
            cnt[j]++;
            break;
          }
        }
      }

      long ans=0;
      for (int i=0; i<5; i++) {
        for (int j=i+1; j<5; j++) {
          for (int k=j+1; k<5; k++) {
            ans += cnt[i] * cnt[j] * cnt[k];
          }
        }
      }

      System.out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 30036
# 高木さんが日付欄に書いた文字列 S を入力すると、
# S の先頭の 4 文字を 2018 に修正して出力するプログラムを書いてください
array = gets.chomp.split("/")
array[0] = '2018' if array[0] == '2017'
puts "#{array[0]}/#{array[1]}/#{array[2]}"

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9+7;
const int mod= 1e9 + 7;
typedef pair<int, int> P;


vector<P> A[15];

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

	int N; cin >> N;
	int ans = 0;
	FOR(i, 0, N) {
		int a; cin >> a;
		A[i].resize(a);
		FOR(j, 0, A[i].size()) {
			cin >> A[i][j].first>>A[i][j].second;
			A[i][j].first--;
		}
	}
	for (int i = 0; i < (1 << N); i++) {
		vector<int> f(N, 0);
		int cur = i;
		int cnt = 0;
		bool flag = false;

		FOR(i, 0, N) {
			if (cur % 2 == 1) {
				f[i] = 1;
				cnt++;
			}
			cur /= 2;
		}
		cur = i;

		FOR(i, 0, N) {
			if (cur % 2 == 1) {
				FOR(j, 0, A[i].size()) {
					P p = A[i][j];
					if (f[p.first] != p.second)flag = true;
				}
			}
			cur /= 2;
		}
		if(!flag)ans = max(ans, cnt);
	}
	cout<<ans<< endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int s1, t1;
string s, t;
int p=1;
string ans="";
int dp[3000+1][3000+1]={};
int dp1[3000+1][3000+1]={};
void Print_LCS ( int i, int j){
	//cout<<i<<" "<<j<<" "<<dp1[i][j]<<"\n";
if (i <= 0 or j <= 0 )
   return  ;

if (dp1[i][j]== 0){
	Print_LCS(i-1, j-1) ;
	cout<<s[i-1];
} 
else if (dp1[i][j]== 1) 
   Print_LCS( i-1, j) ;
else {
	Print_LCS(i, j-1) ;
}
   }
int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
// #ifndef ONLINE_JUDGE 
//     freopen("input.txt", "r", stdin); 
//     freopen("output.txt", "w", stdout); 
// #endif
   	
   	cin>> s>> t;
   	//cout<<s;
   	
   	s1=s.size();t1=t.size();
   	
   	for(int i=1;i<=s1;i++){
   		for (int j=1;j<=t1;j++){
   			if (s[i-1]==t[j-1]){
   				dp[i][j]=dp[i-1][j-1]+1;
   				dp1[i][j]=0;
   			}
   			else{
   				if (dp[i-1][j]>=dp[i][j-1]){
   					dp[i][j]=dp[i-1][j];
   					dp1[i][j]=1;
   				}
   				else{
   					dp[i][j]=dp[i][j-1];
   					dp1[i][j]=2;
   				}
   				//dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
   			}
   		}
   	}
   	
   	
   Print_LCS (s1,t1);
	return 0;

}
//aradara

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

int main(){
    int n;
    double x;
    string u;
    cin>>n;

    double s=0;
    for(int i=0;i<n;i++){
        cin>>x>>u;
        if(u=="JPY"){
            s+=x;
        }else{
            s+=x*380000.0;
        }
    }
    cout<<s<<endl;
}

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

int main() {
  int N,M,X,i,j,k;
  cin>>N>>M>>X;
  vector<int> C(N);
  vector<vector<int> > A(N, vector<int>(M));
  for (i=0;i<N;i++) {
      cin>>C[i];
    for (j=0;j<M;j++) {
      cin>>A[i][j];
    }
  }
  int ans=12e5+1,SC;
  vector<int> SA;
  for (i=0;i<(1<<N);i++) {
    SC=0;
    SA=vector<int>(M,0);
    for (j=0;j<N;j++) {
      if (i & (1<<j)) {
        SC+=C[j];
        for (k=0;k<M;k++) SA[k]+=A[j][k];
      }
    }
    for (k=0;k<M && SA[k]>=X;k++){}
    if (k==M) ans=min(ans, SC);
  }
  cout<<(ans < 12e5+1 ? ans : -1)<<endl;
  return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
void chmax(ll a, ll b) {if(a<b) a=b;}
void chmin(ll a, ll b) {if(a>b) a=b;}
ll max(ll a, ll b) {return a>b ? a:b;}
ll min(ll a, ll b) {return a<b ? a:b;}

int main(void) {
    ll N;
    cin >> N;
    ll a[MAX*2];
    ll i;
    
    for(i=0; i<N; i++) {
        cin >> a[i];
    }
    
    ll ans=0;
    ll l=0, r=0, s=0, xs=0;
    for(l=0; l<N; l++) {
        
        while(s+a[r]==(xs^a[r]) && r<N) {
            s+=a[r];
            xs^=a[r];
            r++;
        }
        
        ans+=r-l;
        
        if(l==r) r++;
        else {
            s-=a[l];
            xs^=a[l];
        }
        
    }
    
    pt(ans);
    
    
    
}


Measured memory_bytes: 1792
#include <iostream>
#include  <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#define rep(i,n) for (int i=0;i<(n);i++;)
using namespace std;

long long int ans(long long int);
long long int a, b, x;
int main(){
	cin >> a >> b >> x;
	cout << ans(b) - ans(a - 1) << endl;
}

long long int ans(long long int n){
	long long int an;
	n == -1 ? an = 0 : an = (n / x) + 1;
	return an;

}


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

int main(){
  int k; cin >> k;
  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};
  cout << a[k-1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    a[i]--;
  }
  int ans = 0;
  rep(i,n) {
    int b;
    cin >> b;
    ans += b;
  }
  vector<int> c(n-1);
  rep(i, n-1) {
    cin >> c[i];
  }
  rep(i, n-1) {
    if (a[i+1]-a[i]==1) ans += c[a[i]];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

int INF = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<vector<double>> dp(n, vector<double>(n));
    vi x(n), y(n);
    rep(i, n){
        cin >> x[i] >> y[i];
    }

    rep(i, n){
        rep(j, n){
            dp[i][j] = sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
        }
    }

    vector<vi> conb(1, vi(1));
    for (int i=1;i<n;i++){
        vector<vi> new_conb;
        for (auto t:conb){
            rep(j, t.size()+1){
                vi tmp = t;
                tmp.insert(tmp.begin() + j, i);
                new_conb.push_back(tmp);
            }
        }
        conb = new_conb;
    }
    
    double ans = 0;
    
    rep(i, conb.size()){
        for(int j=1;j<conb[i].size();j++){
            ans += dp[conb[i][j-1]][conb[i][j]];
        }
    }
    ans = ans / conb.size();
    printf("%.7f\n", ans);
}


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

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int k = std.nextInt();
        int[] a = new int[n];
        int[] dp = new int[k + 1];
        Arrays.fill(dp, -1);

        for (int i = 0; i < n; i++) {
            a[i] = std.nextInt();
        }
        dp[0] = 0;

        for (int i = 1; i <= k; i++) {
            boolean win = false;
            for (int j = 0; j < n; j++) {
                int to = i - a[j];
                if (to >= 0 && dp[to] == 0) {
                    win = true;
                }
            }

            if (win) {
                dp[i] = 1;
            } else {
                dp[i] = 0;
            }
        }

        if (dp[k] == 1) {
            System.out.println("First");
        } else {
            System.out.println("Second");
        }
    }
}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main ()
{
	ll a, b, c, x;
	cin>>a>>b>>c;
	x = min(b-1, c);
	cout<<floor(a*x/b)-a*floor(x/b)<<endl;
	return 0;
}

Measured memory_bytes: 3744
#!/usr/bin/env python3
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans,p=0,-1
for i in b:ans+=i
for i in a:
    if i-p==1:ans+=c[p-1]
    p=i
print(ans)


Measured memory_bytes: 3060
#include <stdio.h>

int main() {
	int a, b = 1200, c = 2800;
	scanf("%d", &a);
	if (a < b) {
		printf("ABC");
	}
	else if (a>=b && a<c) {
		printf("ARC");
	}
	else {
		printf("AGC");
	}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ll long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fr(i, a, b) for(int i=a; i>=b; i--)
#define l long int
#define endl '\n'
#define pb push_back
#define pf pop.front()
using namespace std;


void solve()
{
int n;
cin>>n;
if(n)
cout<<"0";
else
cout<<"1";
}


int32_t main()
{
FAST
l T=1;
//cin>>T;
while(T--)
{
solve();
}
}










Measured memory_bytes: 3604
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> // include pb_ds

using namespace std;
using namespace __gnu_pbds; // namespace for pb_ds

/* short forms */
#define Accelerate                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define mt make_tuple
#define cld(x, y) (((x) / (y)) + ((x) % (y) != 0)) //integer ceil division
#define tc(tt) \
    int tt;    \
    cin >> tt; \
    for (int _tt = 0; _tt < tt; _tt++) // testcase
#define all(cont) (cont).begin(), (cont).end()
#define sz(cont) (int)(cont).size()
#define endl '\n'
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl //print with precision
#define dbg(x) cerr << #x << "is" << (x) << endl
#define leadzero(a) __builtin_clz(a)      // count leading zeroes
#define trailzero(a) __builtin_ctz(a)     // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)

/* constants */
const double PI = 3.1415926535897932384626433832795;
const double EPS = 1e-9;

/* typedefs */
typedef pair<int,int> pii;
typedef priority_queue<int, vector<int>, greater<int> > min_heap;
typedef priority_queue<int, vector<int> > max_heap;
typedef tree<int,null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> 
    indexed_set; // integer set with indexing / pb_ds

/* main program */
int main() {
    Accelerate;
    int n;
    ll int k;
    cin >> n >>k;
    vector<ll int> a(n);
    ll int SUM = 0;
    for(int i=0;i<n;i++) {
        cin >> a[i];
        SUM += a[i];
    }
    vector<ll int> g;
    for(ll int i=1;i*i<=SUM;i++) {
        if(SUM%i==0) {
            g.pb(i);
            g.pb(SUM/i);
        }
    }
    sort(all(g));
    int tmp[n];
    for(int _gg=sz(g)-1;_gg>=0;_gg--) {
        ll int gg = g[_gg];
        ll int sum = 0;

        for(int i=0;i<n;i++) {
            tmp[i] = a[i]%gg;
            sum += tmp[i];
        }
        sum /= gg;
        int m = n - (int)sum;
        sort(tmp,tmp+n);
        sum = 0;
        for(int i=0;i<m;i++) {
            sum += tmp[i];
        }
        if(sum<=k) {
            cout << gg << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())

ans = 0
aEnd = 0
bStart = 0
abBoth = 0
for _ in range(N):
    s = input()
    if s[0] == "B":
        bStart += 1
    if s[-1] == "A":
        aEnd += 1
        if s[0] == "B":
            abBoth += 1

    for i in range(len(s) - 1):
        if s[i:i+2] == "AB":
            ans += 1

ans += min(aEnd, bStart)
if abBoth != 0 and abBoth == aEnd == bStart:
    ans -= 1

print(ans)






Measured memory_bytes: 46680