akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    std::cout<<std::fixed<<std::setprecision(10);
    
    int N;
    ll K;
    cin >> N >> K;
    vector<int> A(N);
    vector<int> F(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> F[i];

    sort(A.begin(), A.end());
    sort(F.rbegin(), F.rend());

    ll l=-1, r=1e12+2;

    while (l+1<r) {
        ll c = (l+r)/2;

        // cが可能かどうか
        bool ok = [&] {
            // iに対して何回操作すればc以下になるか
            // 操作数をカウント 
            ll s = 0;
            rep(i, N) {
                s += max(0ll, (A[i]-c/F[i]));
            }
            return s <= K;
        }();
        if (ok) {
            r = c;
        } else {
            l = c;
        }
    }
    cout << r << endl;
    return 0;
}

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


def count_combination(n: int, r: int, mod: int = 10 ** 9 + 7) -> int:
    '''Count the total number of combinations.
        nCr % mod.
        nHr % mod = (n + r - 1)Cr % mod.

    Args:
        n   : Elements. Int of number (greater than 1).
        r   : The number of r-th combinations. Int of number (greater than 0).
        mod : Modulo. The default is 10 ** 9 + 7.

    Returns:
        The total number of combinations.

    Landau notation: O(n)

    See:
    https://qiita.com/derodero24/items/91b6468e66923a87f39f
    '''

    if (r > n) or (n < 0) or (r < 0):
        return 0

    if r > (n - r):
        return count_combination(n, n - r, mod)

    if r == 0 or r == n:
        return 1

    if r == 1:
        return n

    multiple = 1
    division = 1

    for i in range(r):
        multiple *= n - i
        division *= i + 1
        multiple %= mod
        division %= mod

    return multiple * pow(division, mod - 2, mod) % mod


def main():
    n, k = map(int, input().split())
    mod = 10 ** 9 + 7
    ans = 0

    for i in range(1, k + 1):
        blue_count = count_combination(k - 1, i - 1)
        remain_red = n - k - (i - 1)

        red_count = count_combination(remain_red + i, remain_red)
        ans = blue_count * red_count
        ans %= mod
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
import java.util.Scanner;

class Main {

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

        int date=stdIn.nextInt();
        int homework=stdIn.nextInt();
        System.out.println();

        int [] a=new int[homework];
        for(int i=0; i<homework; i++){
            a[i]=stdIn.nextInt();
        }
        int sum=0;
        for(int i=0; i<a.length; i++){
            sum+=a[i];
        }
        int free=date-sum;
        if(free>=0){
        System.out.print(free);
        }
        else{
            System.out.print(-1);
            
        }
    }

}

Measured memory_bytes: 46264
arr = gets.chomp.split(" ")

operator = ['+', '-', '*']
stack = []
num = 0

arr.each do |val|
  if operator.include?(val)
    right = stack.pop.to_i
    left = stack.pop.to_i
    result = case val
             when '+'
               left + right
             when '-'
               left - right
             when '*'
               left * right
             end
    stack.push(result)
  else
    stack.push(val)
  end
end

puts stack.pop


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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1000000007;
const ll INFLL = 1000000000000000007LL;

void solve() {
  int N;
  cin >> N;
  vector<vector<int>> dp(N + 1, vector<int>(3, 0));
  for (int i = 0; i < N; i++) {
    vector<int> p(3, 0);
    for (int j = 0; j < 3; j++) {
      cin >> p[j];
    }
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
          if (j == k) continue;
        dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + p[k]);
      }
    }
  }
  cout << max(max(dp[N][0], dp[N][1]), dp[N][2]) << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // cout << fixed << setprecision(12);

  solve();

  return 0;
}


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

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

    int A[M];
    long long sum = 0;
    for (int i = 0; i < M; i++) {
        cin >> A[i];
        sum += A[i];
    }

    if (N - sum < 0) {
        cout << -1 << endl;
    }
    else {
        cout << N - sum << endl;
    }
    return 0;
}

Measured memory_bytes: 3676
// AOJ 2413: Tree Planting
// 2017.12.8 bal4u@uu

#include <stdio.h>

char m[1001][2005];
char sr[1001], sc[1001];

int main()
{
	int h, w, r, c;
	char buf[12], *p;

	fgets(buf, 12, stdin);
	sscanf(buf, "%d%d", &h, &w);
	for (r = 0; r < h; r++) {
		fgets(p=m[r], 2005, stdin);
		for (c = 0; c < w; c++, p+=2) {
			if (!(*p & 1)) sr[c] = !sr[c], sc[r] = !sc[r];
		}
	}
	for (r = 0; r < h; r++) {
		p = m[r];
		if (*p & 1) putchar('0'+(sc[r]^sr[0]));
		else        putchar('1'-(sc[r]^sr[0]));
		for (c = 1; c < w; c++) {
			putchar(' ');
			p += 2;
			if (*p & 1) putchar('0'+(sc[r]^sr[c]));
			else 		putchar('1'-(sc[r]^sr[c]));
		}
		putchar('\n');
	}
	return 0;
}

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

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


Measured memory_bytes: 3596
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
//#include <random>
#include <map>
#include <set>
//#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <time.h>
//#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
//#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
double pi = 3.141592653589793;
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }


int main() {
	
	int n, ans = 0;
	cin >> n;
	FOR(i, 1, n + 1) {
		int a;
		cin >> a;
		if (i*a % 2 == 1)ans++;
	}
	cout << ans << endl;
}








Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
    cin>>s;
    int size=s.size();
    for(int i=0;i<size;i++){
        if(s[i]=='A'){
            s.erase(s.begin(),s.begin()+i);
            break;
        }
    }
    for(int j=0;j<size;j++){
        if(s[s.size()-1-j]=='Z'){
            s.erase(s.begin()+s.size()-j,s.end());
            break;
        }
    }
    cout<<s.size()<<endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

class Main{
	public static void main(String[]$){
		Scanner s=new Scanner(System.in);
		String c=s.next();
		int max=c.length();
		for(int i=1;i<c.length();++i)
			if(c.charAt(i)!=c.charAt(i-1))
				max=Math.min(max,Math.max(i,c.length()-i));
		System.out.println(max);
	}
}


Measured memory_bytes: 24704
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
signed main(){
	string s;
	int sum=0;
	cin>>s;
	f(i,s.size()){
		if(s[i]=='x')sum++;
	}
	if(sum>=8)puts("NO");
	else puts("YES");
}


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

int main() {
	char c;

	for (int i = 0; i < 9; i++) {
		cin >> c;
		if (i == 0 || i == 4 || i == 8) cout << c;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        int[][] a = new int[4][13];
        
        int n = sc.nextInt();
        
        for(int i = 0; i < n; i++){
            String mark = sc.next();
            int number = sc.nextInt();
            
            if(mark.equals("S"))
                a[0][number - 1] = 1;
            else if(mark.equals("H"))
                a[1][number - 1] = 1;
            else if(mark.equals("C"))
                a[2][number - 1] = 1;
            else
                a[3][number - 1] = 1;
        }
                

        for(int i = 0;i < 4;i++){
            for(int j = 0; j < 13; j++){
                if(a[i][j] == 0){
                    if(i == 0){
                        System.out.println("S" + " " + (j + 1));
                    }
                    else if(i == 1){
                        System.out.println("H" + " " + (j + 1));
                    }
                    else if(i == 2){
                        System.out.println("C" + " " + (j + 1));
                    }
                    else{
                        System.out.println("D" + " " + (j + 1));
                    }
                }
            }
        }
    }
}



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


void solve(long long N, long long K, std::vector<long long> h){
    ll ans = 0;
    rep (i, N) {
        if(h[i] >= K)
            ans++;
    }
    cout << ans << endl;
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> h(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&h[i]);
    }
    solve(N, K, std::move(h));
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;//
int a[100000005];//
int main(){
    int n;
    long long ans=0;
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i]%=10;
        ans+=a[i];
        ans%=10;
    }
    if (ans%2==0) cout<<"YES";
    else cout<<"NO";
    return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

int main(void)
{
	int i,j,cnt;
	long long n,x;
	scanf("%lld",&n);
	for(i=1;(long long)i*i<=n;i++)	{
		if(n%i==0)	x=n/i;
	}
	cnt=0;
	while(x>0)	{
		x/=10;
		cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 128
//abc128_e.cpp
//Mon Sep 30 22:13:59 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	ll n,q;
	cin >> n >> q;

	vector<tuple<int,int,int>> stx;
	for (int i=0;i<n;i++){
		int s,t,x;
		cin >> s >> t >> x;
		stx.push_back(make_tuple(s-x,1,x));
		stx.push_back(make_tuple(t-x,-1,x));
	}

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

	set<int> st;
	int d[q];
	for (int i=0;i<q;i++){
		cin >> d[i];
	}

	int count = 0;
	int prevx = -1;
	for (int i=0;i<stx.size();i++){
		int temp1 = get<0>(stx[i]);
		int temp2 = get<1>(stx[i]);
		int temp3 = get<2>(stx[i]);
		if (temp2 == 1){
			st.insert(temp3);
		}else if (temp2 == -1){
			st.erase(temp3);
		}
		while (count < q && d[count]<temp1){
			cout << prevx << endl;
			count++;
		}

		auto itr = st.begin();
		if (st.size()>0){
			prevx = *itr;
//			cout << temp1 << " " << *itr << endl;
		}else {
			prevx = -1;
//			cout << temp1 << " " << -1 << endl;
		}
	}
	while (count < q){
		cout << -1 << endl;
		count++;
	}

}

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,inf=mod*mod*3ll;;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll X;
ll pw(ll x,ll y){
    ll ret=1;
    for(ll i=0; i<y; i++){
       ret*=x;
    }
    return ret;
}
ll check(ll a5){
	rep1(a,1000){
		ll cc=pw(a,5);
		if(cc==a5){
			return a;
		}
	}
	return 0;
}

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>X;

for(ll B=-1000; B<1000; B++){
	ll A5=X+pw(B,5);
	ll aa=check(A5);
	if(aa){
		cout<<aa<<" "<<B<<endl;
		return 0;
	}
}

}
	


Measured memory_bytes: 3644
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7


def run():
    N = int(sysread())
    lis1 = []
    lis2 = []
    lis3 = []
    lis4 = []
    for i in range(N):
        x, y = map(int, sysread().split())
        lis1.append((x+y, x, y))
        lis2.append((x-y, x, y))
        lis3.append((-x+y, x, y))
        lis4.append((-x-y, x, y))
    lis1.sort()
    lis2.sort()
    lis3.sort()
    lis4.sort()
    ans = 0
    # pattern1
    val1, x1, y1 = lis1[-1]
    val2, x2, y2 = lis1[0]
    if x1 >= x2 and y1 >= y2:
        ans = max(val1-val2, ans)
    # pattern 2
    val1, x1, y1 = lis2[-1]
    val2, x2, y2 = lis2[0]
    if x1 >= x2 and y1 <= y2:
        ans = max(val1 - val2, ans)
    # pattern3
    val1, x1, y1 = lis3[-1]
    val2, x2, y2 = lis3[0]
    if x1 <= x2 and y1 >= y2:
        ans = max(val1 - val2, ans)
    # patten 4
    val1, x1, y1 = lis1[-1]
    val2, x2, y2 = lis1[0]
    if x1 <= x2 and y1 <= y2:
        ans = max(val1 - val2, ans)
    print(ans)
if __name__ == "__main__":
    run()


Measured memory_bytes: 104836
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "YES";
string no = "NO";

int main(){
  ll n; cin >> n;
  ll ans = 0;
  vector<ll> a(n,0);
  vector<ll> b(n+1,0);
  vector<ll> c(n+1,0);
  ll prev=-1;
  rep(i,n){
    cin >> a[i];
  }
  rep(i,n){
    cin >> b[i+1];
  }
  rep(i,n-1){
    cin >> c[i+1];
  }
  for(auto t:a){
    ans+=b[t];
    if(prev==t-1) ans+=c[t-1];
    prev=t;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import bisect

line=[i*(i+1)//2 for i in range(10**6+1)]

N=int(input())


do=[0 for i in range(10**6+1)]

for i in range(2,int(N**0.5)+1):
    while N%i==0:
        N/=i
        do[i]+=1

ans=0 if N==1 else 1

for _,item in enumerate(do):
    index=(bisect.bisect_right(line,item))-1
    ans+=index

print(ans)




Measured memory_bytes: 56560
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, int> LP;
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 main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	if(b%a == 0) cout << a+b << endl;
	else cout << b-a << endl;
	return 0;
}

Measured memory_bytes: 3600
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	N := readLineInt()[0]
	var Count, Result float64
	for i := 1; i <= N; i++ {
		Count++
		if (i % 2) != 0 {
			Result++
		}
	}
	fmt.Println(Result / Count)
}

/////////////////////////////////////////
var scanner = bufio.NewScanner(os.Stdin)

func init() {
	//scanner.Split(bufio.ScanWords)
}
func readLine() string {
	scanner.Scan()
	return scanner.Text()
}
func readLineInt() []int {
	result := make([]int, 0)
	for _, v := range strings.Split(readLine(), " ") {
		r, _ := strconv.Atoi(v)
		result = append(result, r)
	}
	return result
}

Measured memory_bytes: 640
length,change = gets.chomp.split(" ").map(&:to_i)
number = gets.chomp.split(" ").map(&:to_i)
sum = 0

sum = ((length - change) / (change - 1)) + 1

if ((length - change) % (change - 1)) != 0 && length > change
  sum += 1
end

print sum


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/****** define constant end ********/
/****** define variable start ******/
ll s, w;
/******* define variable end *******/
int solve() {
	cin >> s >> w;
	if(w >= s){
		cout << "unsafe" << endl;
	}else{
		cout << "safe" << endl;
	}
	return 0;
}

int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 3644
use io::*;
use std::*;

// 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)
fn main() {
    let con = read_string();
    let mut scanner = Scanner::new(&con);
    let S: String;
    let Q: i64;
    S = scanner.next();
    Q = scanner.next();
    let mut q: collections::VecDeque<char> = S.chars().collect();
    let mut order = true;
    for _ in 0..Q {
        let qType: i64 = scanner.next();
        if qType == 1 {
            order = !order;
        } else {
            let f: i64 = scanner.next();
            let mut c: String = scanner.next();
            let c = c.as_bytes()[0] as char;
            if f == 1 {
                if order {
                    q.push_front(c);
                } else {
                    q.push_back(c);
                }
            } else {
                if order {
                    q.push_back(c);
                } else {
                    q.push_front(c);
                }
            }
        }
    }
    let mut res: String = String::new();
    if !order {
        for mut x in q.iter().rev().cloned() {
            res.push(x);
        }
    } else {
        for mut x in q.iter().cloned() {
            res.push(x);
        }
    }
    println!("{}", res);
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 10492
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
        string str = ReadLine();
        int leng = str.Length;
        if(leng%2 == 0){
            int check = 0;
            while(leng>0){
                string a = str[0].ToString();
//                WriteLine(a);
                str = str.Replace(a,"");
                leng = str.Length;
                if(leng %2 == 1){
                    check++;
                }
            }
            if(check == 0){
                WriteLine("Yes");
            }else{
                WriteLine("No");
            }
        }else{
            WriteLine("No");
        }
    }
}


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

using DD = double;
const DD INF = 1LL<<60;      // to be set appropriately
const DD EPS = 1e-10;        // to be set appropriately
const DD PI = acosl(-1.0);
DD torad(int deg) {return (DD)(deg) * PI / 180;}
DD todeg(DD ang) {return ang * 180 / PI;}

/* Point */
struct Point {
    DD x, y;
    Point(DD x = 0.0, DD y = 0.0) : x(x), y(y) {}
    friend ostream& operator << (ostream &s, const Point &p) {return s << '(' << p.x << ", " << p.y << ')';}
};
inline Point operator + (const Point &p, const Point &q) {return Point(p.x + q.x, p.y + q.y);}
inline Point operator - (const Point &p, const Point &q) {return Point(p.x - q.x, p.y - q.y);}
inline Point operator * (const Point &p, DD a) {return Point(p.x * a, p.y * a);}
inline Point operator * (DD a, const Point &p) {return Point(a * p.x, a * p.y);}
inline Point operator * (const Point &p, const Point &q) {return Point(p.x * q.x - p.y * q.y, p.x * q.y + p.y * q.x);}
inline Point operator / (const Point &p, DD a) {return Point(p.x / a, p.y / a);}
inline Point conj(const Point &p) {return Point(p.x, -p.y);}
inline Point rot(const Point &p, DD ang) {return Point(cos(ang) * p.x - sin(ang) * p.y, sin(ang) * p.x + cos(ang) * p.y);}
inline Point rot90(const Point &p) {return Point(-p.y, p.x);}
inline DD cross(const Point &p, const Point &q) {return p.x * q.y - p.y * q.x;}
inline DD dot(const Point &p, const Point &q) {return p.x * q.x + p.y * q.y;}
inline DD norm(const Point &p) {return dot(p, p);}
inline DD abs(const Point &p) {return sqrt(dot(p, p));}
inline DD amp(const Point &p) {DD res = atan2(p.y, p.x); if (res < 0) res += PI*2; return res;}
inline bool eq(const Point &p, const Point &q) {return abs(p - q) < EPS;}
inline bool operator < (const Point &p, const Point &q) {return (abs(p.x - q.x) > EPS ? p.x < q.x : p.y < q.y);}
inline bool operator > (const Point &p, const Point &q) {return (abs(p.x - q.x) > EPS ? p.x > q.x : p.y > q.y);}
inline Point operator / (const Point &p, const Point &q) {return p * conj(q) / norm(q);}


const int ITER = 100;

int N;
vector<Point> v;

DD f(DD x, DD y) {
    DD res = 0;
    for (int i = 0; i < N; ++i) res = max(res, abs(v[i] - Point(x, y)));
    return res;
}

DD g(DD x) {
    DD left = -1000, right = 1000;
    for (int _ = 0; _ < ITER; ++_) {
        DD m1 = (left * 2 + right) / 3;
        DD m2 = (left + right * 2) / 3;
        if (f(x, m1) > f(x, m2)) left = m1;
        else right = m2;
    }
    return f(x, left);
}

DD solve() {
    DD left = -1000, right = 1000;
    for (int _ = 0; _ < ITER; ++_) {
        DD m1 = (left * 2 + right) / 3;
        DD m2 = (left + right * 2) / 3;
        if (g(m1) > g(m2)) left = m1;
        else right = m2;
    }
    return g(left);
}

int main() {
    cin >> N;
    v.resize(N);
    for (int i = 0; i < N; ++i) cin >> v[i].x >> v[i].y;
    cout << fixed << setprecision(10) << solve() << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {

int n[10000], x[10000], a, i, k, anc, dn;

for (a = 0; a < 10000; a++) {

scanf ("%d" "%d", &n[a], &x[a]);

if (n[a] == 0 && x[a] == 0)
break;

anc = 0;
dn = x[a];

for (i = 1; i < n[a]; i++) {
x[a] = x[a] - i;

k = 1 + i;

if (k >= n[a])
break;

do {

x[a] = x[a] - k;

if (k >= n[a])
break;

if (x[a] > k && x[a] <= n[a])
anc++;

x[a] = x[a] + k;

k++;
} while (x[a] > k);

x[a] = dn;
}

printf ("%d\n",anc);
}

return 0;
}

Measured memory_bytes: 612
#include<stdio.h>
int main(void)
{
  int N,i;
  scanf("%d",&N);
  int A[N],boss[N];
  for(i=0;i<N;i++){
    boss[i]=0;
    A[i]=0;
  }
  for(i=1;i<N;i++){
    scanf("%d",&A[i]);
    boss[A[i]-1]++;
  }
  for(i=0;i<N;i++)
    printf("%d\n",boss[i]);
  return 0;
}

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

int n , i ,u;

vector<int> v  , f ;

int delta(int a,int b,int c)
{
    int d ,x1,x2;

    d = b*b - 4*a*c ;

    x1 = (-1*b - sqrt(d))/(2*a);
    x2 = (-1*b + sqrt(d))/(2*a);

    if(x1 > 0)
        return x1 ;
    return x2 ;
}

int N,M,K,a[100003];

pair <int,vector<int> > p[100004];

int main()
{
    ios_base :: sync_with_stdio(false) ;
    u = 2;
    for(i=0; ; i++)
    {
        if(u > 4472)
            break;
        v.push_back(u*(u+1)/2);
        u++;
    }
    cin >> n ;
    if(binary_search(v.begin() , v.end() , n))
    {
        int ans = delta(1,1,-2*n);
        for(i=1; i<=ans; i++)
            cout << i << endl ;
    }
    else
    {
        int index = upper_bound(v.begin(),v.end(),n) - v.begin() , sum = 0 ;
        for(i=0; i<=index; i++)
            f.push_back(i+1);
        for(i=0; i<f.size(); i++)
            sum += f[i] ;
        sum = n - sum ;
        for(i=f.size()-1 ; i > -1 && sum; i--)
        {
            sum--;
            f[i]++;
        }
        for(i=0; i<f.size(); i++)
            cout << f[i] << endl ;
    }
    return 0;
}


Measured memory_bytes: 3456
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int N,M;
vector<int> G[8];
bool used[8];
int cnt = 0;

void dfs(int v){
  bool allused = true;
  for(int i=0;i<N;i++){
    if(used[i] == false) allused = false;
  }
  if(allused){
    cnt++;
    return;
  }

  //--------------------------
  for(int i=0;i<(int)G[v].size();i++){
    if(!used[G[v][i]]){
      used[G[v][i]] = true;
      dfs(G[v][i]);
      used[G[v][i]] = false;
    }
  }

  return;
}

int main(){
  cin >> N >> M;
  for(int i=0;i<M;i++){
    int a,b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  fill(used,used+8,false);
  used[0] = true;
  dfs(0);

  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

a = int(arr_data[0][0])
b = int(arr_data[0][1])
c = int(arr_data[0][2])
d = int(arr_data[0][3])


if a+b<c+d:
    
    print("Right")
    
elif a+b>c+d:
    
    print("Left")

else:
    
    print("Balanced")

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_H = 1410;
const int MAX_W = 1410;
int A[MAX_H][MAX_W];
int B[MAX_H][MAX_W];

ll largestRectangleInHistogram(vector<ll> hist) {
  hist.push_back(0); // 番兵
  vector<pair<int,ll>> stack;
  stack.push_back({-1, 0});
  ll res = 0;
  REP(i, hist.size()) {
    while (stack.back().first != -1 && stack.back().second > hist[i]) {
      auto b = stack.back();
      stack.pop_back();
      auto c = stack.back();
      chmax(res, (i - c.first - 1) * (b.second));
    }
    stack.push_back({i, hist[i]});
  }
  return res;
}

int main2() {
  int H = nextInt();
  int W = nextInt();
  REP(h, H) REP(w, W) A[h][w] = nextInt();

  CLR(B, 0);

  for (int w = 0; w < W; w++) {
    int L = 0;
    for (int h = 0; h < H; h++) {
      if (A[h][w] == 0) {
        L++;
      } else {
        L = 0;
      }
      B[h][w] = L;
    }
  }


  ll ans = 0;
  REP(h, H) {
    vector<ll> hist(W);
    REP(w, W) hist[w] = B[h][w];
    ll val = largestRectangleInHistogram(hist);
    chmax(ans, val);
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 18788
#include <iostream>
#include <set>
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
    int n ;
	cin >> n ;
	set<string> str ;
	for (int i = 0 ; i < n ; ++i) {
		string s ;
		cin >> s ;
		str.insert(s) ;
	}
	cout << str.size() << "\n";
	return 0 ;
}

Measured memory_bytes: 19204
// ~/SolverToBe/Developers/Corvus
// ~/sudo apt-get verdict Accpeted

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>
#include <assert.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 21, M = 1000005;
const ll MOD = 1e9 + 7;
const double eps = 1e-9;

int n,a[N][N],dp[N][(1<<21)+1];

int calc(int i,int m) {
    if(i==n)
        return 1;
    int &r = dp[i][m];
    if(r!=-1)
        return r;
    r = 0;
    for(int j=0; j<n; j++)
        if(!(m & (1<<j)) && a[i][j])
            r = (r + calc(i+1, m | (1<<j)))%MOD;
    return r; 
}

int main() {
    scanf("%d",&n);
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
            scanf("%d",&a[i][j]);
    memset(dp,-1,sizeof dp);
    printf("%d\n", calc(0,0));
    return 0;
}

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

ll choose2(ll n) {
        return n * (n - 1) / 2;
}

int main()
{
        int n;
        cin >> n;
        vector<int> a(n);
        rep(i,n) cin >> a[i];
        rep(i,n) a[i]--;
        vector<int> cnt(n);
        rep(i,n) cnt[a[i]]++;
        ll tot = 0;
        rep(i,n) {
                tot += choose2(cnt[i]);
        }
        rep(i,n) {
                ll ans = tot;
                ans -= choose2(cnt[a[i]]);
                cnt[a[i]]--;
                ans += choose2(cnt[a[i]]);
                cout << ans << endl;
                cnt[a[i]]++;
        }

        return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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


  int x,y;
  cin >> x >> y;
  int ans=0;
  if(x==1 && y==1) ans+=400000;
  ans += (max(4-x,0)+max(4-y,0))*100000;
  cout << ans << endl;
  
  
  return 0;
    

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const ll MOD = 1e9+7;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s-1);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

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

    vector<bool> a(n+1, true);
    REP(i,m) {
        int x;
        cin >> x;
        a[x] = false;
    }

    vector<int> dp(n+1, 0);
    dp[0] = 1;
    if (a[1]) {
        dp[1] = dp[0];
    }
    REP2(i, 1, n+1) {
        if (a[i]) {
            dp[i] = (dp[i-1] + dp[i-2]) % MOD;
        }
    }

    cout << dp[n] << endl;
    return 0;
}


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

int n, q;
long long a[100010];
long long rui_kg[100010] = {};
long long rui[100010] = {};

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

  for(int i = 0;i < n;i++){
    cin >> a[i];
    rui_kg[i+1] = a[i];
    rui[i+1] = a[i];
  }

  for(int i = 1;i <= n;i++){
    rui[i] += rui[i-1];
    if(i >= 2) rui_kg[i] += rui_kg[i-2];
  }

  long long x;
  for(int z = 0;z < q;z++){
    cin >> x;

    int x_i = lower_bound(a, a+n, x) - a;
    if(x_i > 0){
      if(abs(a[x_i]-x) >= abs(a[x_i-1]-x)){
        x_i--;
      }
    }

    int l = x_i, r = n;
    while(r-l > 1){
      int mid = l + (r-l)/2;

      int num = a[mid] - x;
      int se = x - num;
      int s_i = lower_bound(a, a+n, se) - a;
      int mas = mid-s_i+1;

      if(mas <= n-mid-1) l = mid;
      else r = mid;
    }

    if(x_i < n-1){
      int s_i;
      if(l != x_i){
        int num = a[l] - x;
        int se = x - num;
        s_i = lower_bound(a, a+n, se) - a;
      }else{
        s_i = l;
      }

      while(s_i > 0 && n-r > l-s_i+1){
        s_i--;
      }


      cout << rui[n]-rui[r] + rui_kg[s_i] << endl;
    }else{
      cout << rui_kg[n] << endl;
    }
  }

  return 0;
}






Measured memory_bytes: 4096
/*
    Bismillahir Rahmanir Raheem
    Think Twice Code Once
    author : reaziii
*/
#include<bits/stdc++.h>
#define sc(x)        scanf("%lld",&x)
#define pcase(x)     printf("Case %d: ",x++)
#define pn           printf("\n")
#define fri(f)       for(int i=0;i<f;i++)
#define frj(f)       for(int j=0;j<f;j++)
#define reset(x,e)   memset(x,e,sizeof(x))
#define all(x)       x.begin(),x.end()
#define input        freopen("input.txt","r",stdin);
#define output       freopen("output.txt","w",stdout)
#define infi         INT_MAX
#define m_v          3000000
#define pii          pair<int,int>
#define pch          pair<char,char>
#define pll          pair<ll,ll>
#define mgraph       map<int,set<int> >
#define mp           make_pair
#define pb           push_back
#define clr(x)       memset(x,0,sizeof(x))
#define frx(x,y)     for(int x=0;x<y;x++)
#define deb(x)       cout<<x
#define ideb(i,x)    cout<<i<<" "<<x
#define F            first
#define S            second
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
bool checkbitt(ll num,int pos);
ll setbitt(ll num,ll pos);
ll resetbitt(ll num,int pos);
 //.................___Start from here___.................//
//.................._____________________................//
 
 
int setbitcount(ll n){
    int ans = 0;
    for(int i=0;i<32;i++){
        ans+=(n>>i)&1;
    }

    return ans;
}
void solve(){
    int n;
    cin>>n;
    int mask = 1<<n;
    mask--;
 
    int a[n+1],x[n+1][n+1],y[n+1][n+1];
 
    for(int u = 1 ; u <= n ; u++ ){
        cin>>a[u];
        for(int v = 1;v<=a[u];v++){
            cin>>x[u][v]>>y[u][v];
        }
    }
 
    int ans = 0;
 
    for(int i=1;i<=mask;i++){
        bool f =true;
 
        for(int j=1;j<=n;j++){
            if(checkbitt(i,j-1)){
                for(int k=1;k<=a[j];k++){
                    if(y[j][k]^checkbitt(i,(x[j][k]-1))) f = false;
                }
            }
        }
 
        if(f) ans = max(ans,setbitcount(i));
    }
 
    cout<<ans<<endl;
 
}
 
 
int main(){
    // input;
    // output;
 
    int cs=1;
    int cn=1;
    // cin>>cs;
    while(cs--){
        solve();
    }
}
 
 
 
 
 
 
bool checkbitt(ll num,int pos){
    return (num>>pos) & 1;
}
 
ll setbitt(ll num,ll pos){
    return (1<<pos) | num;
}
 
ll resetbitt(ll num,int pos){
    if(!checkbitt(num,pos)) {
        return num;
    }
    else{
        return (1<<pos)^num;
    }
}

Measured memory_bytes: 3644
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
        int n,d,x,y;
        int ans = 0;

        cin >> n >> d;
        for (int i = 0; i < n; ++i){
                cin >> x >> y;
                if (sqrt(pow((double)x,2) + pow((double)y,2)) <= d){
                        ans += 1;
                }
        }
        cout << ans << endl;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main()
{
    string s;
    cin>>s;
    int front=0;
    int end=0;

    for(int i=s.size()-1; i>=0; i--)
    {
        if (s[i] == 'Z')
        {
            end = i + 1;
            break;
        }
    }
    for(int j=0; j<s.size(); j++)
    {
        if(s[j]=='A')
        {
            front=j;
            break;
        }
    }

    cout<<end-front<<endl;
}

Measured memory_bytes: 640
r, c = map(int, input().split())

dataset = []
for i in range(r):
     dataset.append(list(map(int, input().split())))

for data in dataset:
    data.append(sum(data))

total_data = []
for row in range(c+1):
    total_data.append(sum([data[row] for data in dataset]))
dataset.append(total_data)

for data in dataset:
    print(" ".join(map(str, data)))


Measured memory_bytes: 5704
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,i)for(typename make_signed<decltype(i.second)>::type t=i.first,_l##t=i.second;t<_l##t;t++)
#define RREP(t,i)for(typename make_signed<decltype(i.second)>::type t=i.second-1,_l##t=i.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(i)begin(i),end(i)
#define rall(i)i.rbegin(),i.rend()
#define var(t, ...) t __VA_ARGS__;in,__VA_ARGS__;

void Calc();
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
template<class A>int comp(A a, A b) { return a < b ? 1 : b < a ? -1 : 0; }
struct Scanner {
  template<class A = string>A Next() { A a; Next(a); return a; }
  template<class A, class B>void Next(pair<A, B>& a) { cin >> a.first >> a.second; }
  template<class A>void Next(A& a) { cin >> a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) (*this), i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;
/*---------------------------------------------------------------------*/
template<class T>class SlideMin {
  vector<T> v;
  int k;
  int n;
  deque<int> d;
  int slide_cnt = 0;
public:
  SlideMin(const vector<T>& a, int k, bool loop = false) :v(a), k(k), n(a.size()) {
    if (loop == false) return;
    slide_cnt = n;
    rep(j, k) {
      int index = j + n - k;
      while (d.size() && a[d.back()] >= a[index]) {
        d.pop_back();
      }
      d.push_back(index);
    }
  }

  int index() const { return d.front() % n; }
  int value() const { return v[index()]; }

  void slide() {
    while (d.size() && v[d.back() % n] >= v[slide_cnt % n]) {
      d.pop_back();
    }
    while (d.size() && d.front() < slide_cnt - k) {
      d.pop_front();
    }
    d.push_back(slide_cnt);
    slide_cnt++;
  }
};
void Calc() {

  var(ll, n, x);
  auto a = in.Array(n);
  const ll INFL = 1e18 - 1;
  ll ans = INFL;
  rep(i, n + 1) {
    SlideMin<int> smin(a, i, true);

    ll tmp = 0;
    rep(j, n) {
      smin.slide();
      tmp += smin.value();
    }
    tmp += x * i;
    amin(ans, tmp);
  }
  cout << (ans) << endl;
}


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
abs = n.times.map { gets.split.map(&:to_i) }.sort!

ans = 0
rest = m

abs.each do |a, b|
  if b >= rest
    ans += a * rest
    rest = 0
  else
    ans += a * b
    rest -= b
  end

  break if rest == 0
end

puts ans


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

int main() {
  string S;
  cin>>S;
  int conditions=0;
  if (S[0]=='A') {
    conditions++;
    int count_C=0;
    for (int i=2; i<=S.length()-2; i++) {
      if (S[i]=='C') {
        count_C++;
      }
    }
    if (count_C==1) {
      conditions++;
    }
    int count_smallalpha=0;
    for (int i=0; i<S.length(); i++) {
      if (S[i]=='A' or S[i]=='C') {
        continue;
      }
      if (S[i]>='a' and S[i]<='z') {
        count_smallalpha++;
      }
    }
    if (count_smallalpha==S.length()-2) {
      conditions++;
    }
  }
  cout<<(conditions==3?"AC":"WA")<<endl;
  return 0;
}


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

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        String s = scan.next();
        char[] data = s.toCharArray();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < s.length(); i++) {
            char x = data[i];
            int org = x - 'A';
            int next = (org + N) % 26;
            char n = (char)((int)next + 'A');
            sb.append(n);
        }
        System.out.println(sb.toString());
    }
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int mINF = 1e9;
const int MOD = 1e9+7;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(){
    int m,d;cin >> m >> d;
    int cnt = 0;
    for(int i=1;i<=m;i++){
        for(int j=2;j<=9;j++){
            for(int k=2;k<=9;k++){
                if(k * j == i && k + j*10 <= d){
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int zyo[200100][2];
int dp[200100];
int out[200100];
int cal(int x){
	if(x==0) return 0;
	if(dp[x]>=0) return dp[x];
	return dp[x]=1+cal(x%__builtin_popcount(x));
}
int main()
{
	memset(dp,-1,sizeof(dp));
	int n,m=0;string s;cin>>n;cin>>s;reverse(All(s));
	rep(i,n) m+=(s[i]-'0');
	int mo[2]={m+1,max(1,m-1)};
	zyo[0][0]=zyo[0][1]=1;
	rep(i,n+10) rep(j,2){
		zyo[i+1][j]=zyo[i][j]*2;
		zyo[i+1][j]%=mo[j];
	}
	int sum[2]={0,0};
	rep(i,n) rep(j,2){
		sum[j]+=zyo[i][j]*(s[i]-'0');
		sum[j]%=mo[j];
	}
	rep(i,n){
		if(s[i]=='1'){
			if(m==1){
				out[i]=0;continue;
			}
			int su=sum[1]-zyo[i][1];su%=mo[1];su+=mo[1];su%=mo[1];
			out[i]=1+cal(su);
		}
		else{
			int su=sum[0]+zyo[i][0];su%=mo[0];
			out[i]=1+cal(su);
		}
	}
	rep(i,n) cout<<out[n-1-i]<<endl;
}


Measured memory_bytes: 6840
// 69

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <iomanip>
#include <climits>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

#define _USE_MATH_DEFINES

int main(){
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    long double rad, ans;
    rad = abs(h*M_PI/6 + m*M_PI/360 - m*M_PI/30);
    ans = sqrt(pow(abs(a*cos(rad)-b), 2) + pow(a*sin(rad), 2));
    cout << fixed << setprecision(11) << ans << endl;
    return 0;
}


Measured memory_bytes: 4100
n=gets.to_i

s=gets.chomp
h={}
s.chars.each{|c| h.key?(c) ? h[c]+=1 : h[c]=1}
(n-1).times do
  t=gets.chomp
  hh={}
  t.chars.each{|c| hh.key?(c) ? hh[c]+=1 : hh[c]=1}
  h.each_key do |key|
    if hh.key?(key)
      h[key]=[h[key], hh[key]].min
    else
      h[key]=0
    end
  end
end

ans=''
h.sort.each do |c, k|
  k.times{ans<< c}
end

puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main(void){
    double ans,n;
    bool a=false;
    cin>>n;
    for(int i=1;i<=50000;i++){
        if((floor(i*1.08))==n){
            ans=i;
            a=true;
            break;
        }
    }
    if(a) cout<<ans;
    else cout<<":(";
}

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

int main() {
  ll n,k;cin>>n>>k;
  ll ans=min(n%k,abs(k-n%k));
  cout<<ans<<endl;
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int max1 = 0;
        int max2 = 0;
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = scanner.nextInt();
        }
        max1 = Math.max(a[0], a[1]);
        max2 = Math.min(a[0], a[1]);
        for (int i = 2; i < n; ++i) {
            if (a[i] >= max1) {
                max2 = max1;
                max1 = a[i];
            } else if (a[i] > max2) {
                max2 = a[i];
            }
        }
        for (int i = 0; i < n; ++i) {
            if (max1 == a[i]) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        }
    }

}


Measured memory_bytes: 107500