akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var H, W, M int
	fmt.Scanf("%d%d%d", &H, &W, &M)
	h := make([]int, M)
	w := make([]int, M)
	rsum := make([]int, H)
	rsummax := 0
	csum := make([]int, W)
	csummax := 0
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < M; i++ {
		str, _ := reader.ReadString('\n')
		fmt.Sscanf(str, "%d%d", &h[i], &w[i])
		h[i]--
		w[i]--
		rsum[h[i]]++
		csum[w[i]]++
		if rsummax < rsum[h[i]] {
			rsummax = rsum[h[i]]
		}
		if csummax < csum[w[i]] {
			csummax = csum[w[i]]
		}
	}
	nrsummaxarg := 0
	for i := 0; i < H; i++ {
		if rsum[i] == rsummax {
			nrsummaxarg++
		}
	}
	ncsummaxarg := 0
	for i := 0; i < W; i++ {
		if csum[i] == csummax {
			ncsummaxarg++
		}
	}
	nb := 0
	for i := 0; i < M; i++ {
		if rsum[h[i]] == rsummax && csum[w[i]] == csummax {
			nb++
		}
	}
	if nrsummaxarg*ncsummaxarg == nb {
		fmt.Printf("%d\n", rsummax+csummax-1)
	} else {
		fmt.Printf("%d\n", rsummax+csummax)
	}
	return
}


Measured memory_bytes: 21332
#include<stdio.h>
#include<string.h>

int main(void)
{
	char s[100005];
	int K,i=0,len;

	scanf("%s", s);
	scanf("%d", &K);

	len = strlen(s);

	
	for (i = 0; i < len; i++) {
		if ('z' - s[i] +1<=K&&'z'-s[i]+1!=26) {
			K -= 'z' - s[i] + 1;
			s[i] = 'a';
		}
		else {
			K -= 0;
		}
		if (K == 0)break;
	}
	if (K != 0) {
		s[len - 1] += K % 26;
	}
	printf("%s\n", s);
}

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

using namespace std;

typedef long long ll;


int n;
void solve() {
   cin>>n;
   
   int k = n % 10;
   
   if(k == 2 || k == 4 || k == 5 || k == 7 || k == 9) {
       cout<<"hon"<<endl;
   }
   else if(k == 0 || k == 1 || k == 6 || k == 8) {
       cout<<"pon"<<endl;
   }
   else if(k == 3) {
       cout<<"bon"<<endl;
   }
}



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


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;


int main(){
    char t;
    cin>>t;
    if(t=='A')cout<<"T"<<endl;
    if(t=='T')cout<<"A"<<endl;
    if(t=='C')cout<<"G";
    if(t=='G')cout<<"C";
    return 0;
}

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

using namespace std;

int main() {
	string S;
	cin >> S;
	string rS = S;
	reverse(rS.begin(),rS.end());
	string S1 = S.substr(0,(S.size()-1)/2);
	string rS1 = S1;
	reverse(rS1.begin(), rS1.end());
	string S2 = S.substr((S.size() + 1) / 2, (S.size() - 1) / 2);
	string rS2 = S2;
	reverse(rS2.begin(), rS2.end());
	if (S != rS) {
		cout << "No" << endl;
		return 0;
	}
	if (S1 != rS1) {
		cout << "No" << endl;
		return 0;
	}
	if (S2 !=rS2) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

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

    vector<int> a(m);

    rep(i,m)
    {
        scanf(" %d", &a[i]);
        --a[i];
    }

    vector<int> s(n,0);

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

        rep(j,n)
        {
            int b;
            scanf(" %d", &b);
            --b;

            if(b==a[i])
            {
                ++s[j];
                ++ct;
            }
        }
        s[a[i]]+=n-ct;
    }

    rep(i,n) printf("%d\n", s[i]);
    return 0;
}

Measured memory_bytes: 3204
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main(int argc, char* argv[]) {
	int n, rank;
	char str;
	int a[4][13] = {0};
	cin >> n;



	for(int i = 0; i < n; i++){
		cin >> str >> rank;

		switch(str){
			case 'S': a[0][rank-1] = 1; break;
			case 'H': a[1][rank-1] = 1; break;
			case 'C': a[2][rank-1] = 1; break;
			case 'D': a[3][rank-1] = 1; break;
			default : break;
		}
	}

	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 13; j++){
			if(a[i][j] == 0){
				switch(i){
					case 0: printf("S %d", j + 1); break;
					case 1: printf("H %d", j + 1); break;
					case 2: printf("C %d", j + 1); break;
					case 3: printf("D %d", j + 1); break;
				}
				printf("\n");
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1148
#![allow(unused_imports)]

use std::{i32, i64, u32, u64, usize, f64};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};
use maplit::*;
use proconio::marker::{Isize1, Usize1, Bytes, Chars};

#[proconio::fastout]
fn main() {
    proconio::input!{
        n: usize,
        ss: [Chars; n],
    }
    let ss: Vec<_> = ss.into_iter().map(|mut s| {
        s.sort();
        let mut s2 = String::new();
        for c in s { s2.push(c); }
        s2
    }).collect();
    let mut counter = HashMap::new();
    for s in ss { *counter.entry(s).or_insert(0) += 1i64; }
    println!("{}", counter.values().map(|c| c * (c - 1) / 2).sum::<i64>());
}


Measured memory_bytes: 21588
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
function Z_Algorithm(s){
  var l=s.length,a=Array(l);
  a[0]=l;
  for(var i=1,j=0;i<l;){
    while(i+j<l && s[j]===s[i+j])++j;
    a[i]=j;
    if(j === 0){++i; continue;}
    var k=1;
    while(i+k<l && k+a[k]<j)a[i+k]=a[k], ++k;
    i += k; j -= k;
  }
  return a;
}

console.log(main());
function main(){
  var n = o.a();
  var s = o.a(1);
  var ans = 0;
  for(var i = 0; i < n-ans*2; i++){
    var a = Z_Algorithm(s.slice(i));
    for(var j = ans+1; j < a.length; j++){
      var t = Math.min(j,a[j]);
      if(ans < t)ans = t;
    }
  }
  return ans;
}

Measured memory_bytes: 12108
public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		while(true){
			int n = scan.nextInt();
			int x = scan.nextInt();
			int a,b,c = 1;
			int count = 0;

			if(n == 0 && x == 0){
				break;
			}
			for(a = 1;a<=n;a++){
				for(b = a;b<=n;b++){
					for(c = b;c<=n;c++){
						if(x == (a+b+c) && (a!=b) && (b!=c) && (c!=a)){
							count ++;
							break;
						}
					}
				}
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 26792
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    S = input()
    N = len(S)
    base = 1
    remainders = [0]*13
    remainders[0] = 1
    number = 0
    modulo = 10**9+7
    for i in range(N-1, -1, -1):
        new_remainders = [0]*13
        if S[i] == '?':
            for digit in range(10):
                for r in range(len(remainders)):
                    new_remainders[(base*digit+r)%13] += remainders[r]
        else:
            digit = int(S[i])
            for r in range(13):
                new_remainders[(base*digit+r)%13] = remainders[r]
        base = (base*10)%13
        remainders = [r%modulo for r in new_remainders]
    return remainders[5]


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 74276
#include <iostream>
#define rep(i, n)   for(int i = 0; i < (n); i++) 
using namespace std;

int main(){
    int a,b,c,d;    cin >> a >> b >> c >> d;
    if(a<c){
	if(b<c){
	    cout << 0 << endl;
	}else if(b >= c && b <= d){
	    cout << b-c << endl;
	}else{
	    cout << d-c << endl;
	}
    }else if(a>=c&&a<=d){
	if(b<=d){
	    cout << b-a << endl;
	}else{
	    cout << d-a << endl;
	}
    }else{
	cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
fun main(arg: Array<String>) {
    val (N, K) = listOfInt()
    val XY = Array(N) { listOfLong() }
    val X = XY.map { it[0] }.sorted().toLongArray()
    val Y = XY.map { it[1] }.sorted().toLongArray()
    var ans = (X.last() - X.first()) * (Y.last() - Y.first())
    for (xi in 0 until N) for (xj in xi + 1 until N)
        for (yi in 0 until N) for (yj in yi + 1 until N) {
            var count = 0
            val lx = X[xi]
            val rx = X[xj]
            val by = Y[yi]
            val uy = Y[yj]
            for (i in 0 until N) {
                if (lx <= XY[i][0] && XY[i][0] <= rx && by <= XY[i][1] && XY[i][1] <= uy) count += 1
            }
            if (count >= K) ans = Math.min(ans, (rx - lx) * (uy - by))
        }
    println(ans)
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt(d: Int = 0) = listOfString().map { Integer.parseInt(it) + d }
fun listOfLong() = listOfString().map(String::toLong)
fun listOfDouble() = listOfString().map { it.toDouble() }


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

using namespace std;

#define maxn 100005
#define ll long long int
#define db(x) cout<<#x<<" -> "<<x<<endl
#define db2(x,y) cout<<#x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<endl
#define db3(x,y,z) cout<<#x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<" , "<<#z<<" -> "<<z<<endl
#define prt(x) for(auto it = x.begin(); it!=x.end(); it++){cout<<*it<<" " ;}cout<<endl
#define IN freopen("input.txt","r",stdin)

ll dp[105][maxn];
int weight[ maxn ] , value[ maxn ];
int W ;
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
//    IN ;
    int n ;
    cin>>n>>W ;
    for(int i=1; i<=n; i++){
        cin>>weight[i]>>value[i];
    }
    for(int i=1; i<=n; i++){
        for(int w=0; w<=W; w++){
            dp[i][w] = dp[i-1][w];
            if( w < weight[ i ] ){ continue ; }
            dp[i][w] = max(dp[i][w],dp[i-1][w-weight[i]]+value[i]);
//            db3(i,w,dp[i][w]);
        }
    }
    ll ans = -1;
    for(int i=0; i<=W; i++){
        ans = max(ans,dp[n][i]);
//        db2(i,dp[n][i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 78592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  //freopen("data.in", "r", stdin);
  ll k;
  vector<ll> f = {1, 0, -1};
  vector<ll> ff (3);
  cin >> ff[0] >> ff[1] >> ff[2] >> k;
  ll tot = 0;
  int i = 0;
  while (k && i<3) {
    if (ff[i] <= k) tot += ff[i]*f[i], k-=ff[i];
    else tot += f[i]*k, k=0;
    i++;
  }
  cout << tot << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b;
    cin>>a;
    b=a;
    reverse(a.begin(),a.end());
    for(register int i=0;i<a.size();++i)
    {
        if(a[i]=='b')
            a[i]='d';
        else if(a[i]=='d')
            a[i]='b';
        else if(a[i]=='p')
            a[i]='q';
        else if(a[i]=='q')
            a[i]='p';
    }
    if(a==b)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    string s; cin >> s;
    int ans = 0, cnt = 0;
    each(c, s) {
        if (c == 'S')++cnt;
        else {
            if (0 < cnt)--cnt;
            else ++ans;
        }
    }
    cout << ans + cnt << "\n";
}

Measured memory_bytes: 720
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {

    int n, m, p, c, ans;
    string str;
    for (; ;) {
        scanf("%d %d", &n, &m);
        if (n == 0 && m == 0) break;
        str = "";
        for (int i = n; i >= 1; i--) {
            if (i < 10) str+='0';
            str+= to_string(i);
        }
        for (int i = 0; i < m; i++) {
            scanf("%d %d", &p, &c);
            str = str.substr(p*2-2, c*2)+str.substr(0,p*2-2)+str.substr(p*2-2+c*2);
        }
        printf("%d\n", stoi(str.substr(0, 2)));
    }
    return 0;
}



Measured memory_bytes: 3160
#include <stdio.h>
#include <stdlib.h>

#define MAX 2000001
#define VMAX 10000
 
int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;
 
  scanf("%d", &n);
 
  A = (unsigned short *)malloc(sizeof(short)*n+1);
  B = (unsigned short *)malloc(sizeof(short)*n+1);
 
  for(i=1;i<=n;i++){
    scanf("%hu",&A[i]);
  }
   
  for(i=0;i<=VMAX;i++){
    C[i]=0;
  }
 
  for(j=1;j<=n;j++){
    C[A[j]]++;
  }
  for(i=1;i<=VMAX;i++){
    C[i]=C[i]+C[i-1];
  }
 
  for(j=n;j>0;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
   
  for(i=1;i<=n;i++){
    printf("%u",B[i]);
    if(i!=n){
      printf(" ");
    }
  }
  printf("\n");
  free(A);
  free(B);
  return 0;
}


Measured memory_bytes: 9116
import sys
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
time = 0
if a < 0 and b < 0:
    time += (b - a) * c
    print(time)
    sys.exit()
if b == 0:
    time += (-a) * c + d
    print(time)
    sys.exit()
if b > 0:
    if a < 0:
        time += (-a) * c + d + b * e
        print(time)
    else:
        time += (b - a) * e
        print(time)
        sys.exit()

Measured memory_bytes: 7584
import java.io.*;
import java.util.*;

public class Main {
    static int[] factorCnts;
    static boolean checkCoprime = true;

    public static void factorise(int num) {
        if (!checkCoprime)
            return;
        for (int fact = 1; fact * fact <= num; fact++) {
            if (num % fact == 0) {
                int div = num / fact;
                if (fact == div)
                    div = 1;
                if (fact != 1) {
                    if (factorCnts[fact] == 1) {
                        checkCoprime = false;
                        return;
                    }
                    factorCnts[fact]++;
                }
                if (div != 1) {
                    if (factorCnts[div] == 1) {
                        checkCoprime = false;
                        return;
                    }
                    factorCnts[div]++;
                }
            }
        }
    }

    public static int gcd(int a, int b) {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }

    public static void main(String[] args) throws Exception {
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(buffer.readLine());
        String[] inp = buffer.readLine().split(" ");
        int[] arr = new int[n];
        arr[0] = Integer.parseInt(inp[0]);
        factorCnts = new int[1000001];
        int gcdRes = arr[0];
        for (int pos = 1; pos < n; pos++) {
            arr[pos] = Integer.parseInt(inp[pos]);
            gcdRes = gcd(gcdRes, arr[pos]);
        }
        for (int pos = 0; pos < n; pos++) {
            factorise(arr[pos]);
        }
        if (checkCoprime) {
            System.out.println("pairwise coprime");
        } else if (gcdRes == 1)
            System.out.println("setwise coprime");
        else
            System.out.println("not coprime");
    }
}


Measured memory_bytes: 114796
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Debug = System.Diagnostics.Debug;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

static class P
{
    static void Main()
    {
        var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nk[0];
        long k = nk[1];
        long res = 0;
        var perm = ((k - 1) * k / 2) % 1000000007;
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        res += a.Sum(x => (a.Count(y => y > x) * perm) % 1000000007) % 1000000007;
        res += (a.Select((x, y) => a.Take(y).Count(z => z > x) % 1000000007).Sum() % 1000000007) * k;
        res %= 1000000007;
        Console.WriteLine(res);
    }

    static readonly TextReader In = Console.In;
    static int NextInt
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            int res = 0;
            int next = In.Read();
            int rev = 1;
            while (45 > next || next > 57) next = In.Read();
            if (next == 45) { next = In.Read(); rev = -1; }
            while (48 <= next && next <= 57)
            {
                res = res * 10 + next - 48;
                next = In.Read();
            }
            return res * rev;
        }
    }
}


Measured memory_bytes: 13396
#include <cstdio>
#include <cmath>
 
#define MAX 100000

bool prime[MAX + 1];
int count[MAX + 1];
int N, L, R;

int main() {
  // 素数配列をエラトステネスの篩を使って生成
  // 素数であれば false, 素数でなければ true
  for (int i = 2; i < sqrt(MAX); ++i)
    if (!prime[i])
      for (int j = i + i; j <= MAX; j += i)
        prime[j] = true;

  // N と (N + 1) / 2 が素数である要素配列を生成
  // 条件が成立すれば 1、成立しなければ 0
  for (int i = 3; i<= MAX; i += 2)
    if (!prime[i] && !prime[(i + 1) >> 1])
      count[i] = 1;

  // 累積和を生成
  for (int i = 3; i<= MAX; ++ i)
    count[i] += count[i - 1];

  scanf("%d", &N);
  while (N --) {
    scanf("%d%d", &L, &R);
    printf("%d\n", count[R] - count[L - 1]);
  }

  fflush(stdout);
  return 0;
}


Measured memory_bytes: 2224
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

ll pw_2[60];
int main() {
	for (int i = 0; i < 60; i++)pw_2[i] = pow(2, i);
	ll A, B;
	cin >> A >> B;
	vector<ll> ans(60,0);
	for (int i = 59; i >= 0; i--) {
		ll a, b;
		ll div = pw_2[i] * 2;
		a = A / div + 1;
		if (A % div >= pw_2[i])ans[i] += div - (A % div);
		else ans[i] += pw_2[i];
		b = B / div;
		if (B % div >= pw_2[i])ans[i] += (B % div) - pw_2[i] + 1;
		ans[i] += (b - a)*pw_2[i];
	}
	ll f = 0;
	for (int i = 0; i < 60; i++)f += (ans[i] % 2)*pw_2[i];
	cout << f << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

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();

        if (a < b && b < c) {
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 26280
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;

ll cnt = 0;
void dfs(ll a, ll b, ll check, ll m){
  a = 10*a + b;
  if(a > m) return;
  
  if(b == 3) check = (check | 0b100);
  if(b == 5) check = (check | 0b010);
  if(b == 7) check = (check | 0b001);
  
  if(check == 0b111) cnt++;
  
  dfs(a, 3, check, m);
  dfs(a, 5, check, m);
  dfs(a, 7, check, m);
}

int main() {
  ll n;
  cin >> n;
  dfs(0, 0, 0b000, n);
  cout << cnt;
  
 return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
class Program
{     
    const int MOD = 1000000007;
    public void Slove()
    {
        int n = int.Parse(Console.ReadLine());
        int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[] hist = new int[n + 1];
        if((n & 1) == 1)
            hist[0]++;
        foreach(int i in array)
            hist[i]++;
        if(hist.Where((x, i) => (i & 1) != (n & 1)).All(x => x == 2))
        {
            int exp = n / 2;
            long result = 1;
            while(exp >= 32)
            {
                result = (result << 32) % MOD;
                exp -= 32;
            }
            result = (result << exp) % MOD;
            System.Console.WriteLine(result);
        }
        else
        {
            System.Console.WriteLine(0);
        }
    }
    
    static void Main(string[] args)
    {
        new Program().Slove();
    }
}


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

typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<bool> > vvb;
typedef map<int, bool> mib;

typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vpll;

typedef vector<string> vs;

typedef long double ld;

#define _GLIBCXX_DEBUG

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n-1); i >= 0; --i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << '\n'
#define debug3(x, y, z) cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << '\n'
#define debugs(s) cerr << s << "\n"
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

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

#define fst first
#define snd second
#define pb push_back
#define mk(x,y) make_pair((x),(y))

// http://ehafib.hatenablog.com/entry/2015/12/23/164137
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qpm(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a, int b) { return a / gcd(a, b) * b; }

#define sz(v) int(v.size())

// x1, x2ライブラリとの被りを避ける
#define x1 x192837465
#define x2 x123456789
#define y1 y192837465
#define y2 y123456789

// typo
#define itn int
#define reutrn return
#define reutnr return
#define srting string

#define make(type, x) type x; cin>>x;
#define make2(type, x, y) type x, y; cin>>x>>y;
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
#define make4(type, x, y, z, t) type x, y, z, t; cin>>x>>y>>z>>t;

const int MOD = (int)1e9 + 7;
const int INF = numeric_limits<int>::max();

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

signed main() {
    make(srting, S);

    int ans = INF;
    FORE(start, 0, S.size()-3) {
        int n = ctoi(S.at(start)) * 100 + ctoi(S.at(start+1)) * 10 + ctoi(S.at(start+2));

        int diff = abs(753-n);

        ans = min(ans, diff);
    }

    cout << ans << endl;
}


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

ll tmp;

int koya(ll a, ll b) {
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main(void) {
    int N;
    cin >> N;
    ll A[N];
    for(int i=0; i<N; i++) cin >> A[i];
    ll ko = A[0];
    for(int i=1; i<N; i++) ko = koya(ko, A[i]);
    cout << ko << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
vector<int>pat[202020];
vector<int>rpat[202020];
bool flag[202020];
int fin[202020];
int pt = 0;
int deg[202020];
int ans[202020];
void dfs(int node)
{
	if (flag[node])return;
	flag[node] = true;
	for (int i = 0; i < pat[node].size(); i++)dfs(pat[node][i]);
	fin[node] = pt++;
}
int main()
{
	int num, way;
	scanf("%d%d", &num, &way);
	way += num - 1;
	for (int i = 0; i < way; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		pat[za].push_back(zb);
		rpat[zb].push_back(za);
		deg[zb]++;
	}
	int r;
	for (int i = 0; i < num; i++)if (deg[i] == 0)r = i;
	dfs(r);
	for (int i = 0; i < num; i++)
	{
		if (r == i)ans[i] = 0;
		else
		{
			int mini = 1000000000, rr = -1;
			for (int j = 0; j < rpat[i].size(); j++)
			{
				if (mini > fin[rpat[i][j]])mini = fin[rpat[i][j]], rr = rpat[i][j];
			}
			ans[i] = rr + 1;
		}
	}
	for (int i = 0; i < num; i++)printf("%d\n", ans[i]);
}

Measured memory_bytes: 22912
/* AtCoder Beginner Contest abc139
 * Problem B
 * Au: SJoshua
 */
#include <bits/stdc++.h>

using namespace std;

int main(void) {
	int A, B;
	cin >> A >> B;
	cout << (B - 1 + A - 2) / (A - 1) << endl;
	return 0;
}


Measured memory_bytes: 256
//55

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
using namespace std;
typedef vector<int> NODE;
#define rep(i,n) for(int i=0;i<n;i++)

int ctoi(char c){
	switch(c){
	case 'R':return 0;
	case 'G':return 1;
	case 'B':return 2;
	};
	return -1;
}

bool isable(vector<int> data){
	/* q */
	sort(data.begin(),data.end());
	vector<int> check = data;
	vector< vector<int> > can;
	check.erase(unique(check.begin(),check.end()),check.end());
	//rep(i,data.size())cout << data[i] << " ";cout << endl;
	if(check.size()>=3){ 
		rep(i,check.size()-2){
			if(check[i+1] == check[i]+1 && check[i+2] == check[i]+2){
				vector<int> tmp;
				rep(j,3)tmp.push_back(check[i+j]);
				can.push_back(tmp);
			}
		}
	}
	rep(i,check.size()){
		int t = count(data.begin(),data.end(),check[i]);
		if(t>=3){
			vector<int> tmp;
			rep(j,3)tmp.push_back(check[i]);
			can.push_back(tmp);
		}
	}
	queue<NODE> Q;
	/*rep(i,can.size()){
		rep(j,can[i].size())cout << can[i][j] << " ";
		cout << endl;
	}*/
	
	map<vector<int>,bool> done;
	NODE empty;
	Q.push(empty);
	while(Q.size()){
		NODE q = Q.front(); Q.pop();
		if(q.size()>9)continue;

		sort(q.begin(),q.end());
		if(done[q])continue;
		done[q] = true;

		if(q.size() == data.size()){
			if(q == data){
				return true;
			}
		}
		rep(i,can.size()){
			NODE next = q;
			rep(j,3)next.push_back(can[i][j]);
			Q.push(next);
		}
	}
	return false;
	
}
int main(){
	int n;
	cin >> n;
	while(n--){
		bool ret = true;
		vector< vector<int> > co(3);
		int tmp[9];char c;
		rep(i,9)cin >> tmp[i];
		rep(i,9){
			cin >> c;
			co[ctoi(c)].push_back(tmp[i]);
		}
		rep(i,3)if(co[i].size()%3!=0)ret = false;
		
		if(ret){
			rep(i,3){
				if(co[i].size()>=3)ret &= isable(co[i]);
			}
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 0
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	ll K;
	ll A[100001];
	int ketawa[50]={};
	ll nownum=0;
	scan(N);
	scan(K);
	rep(i,N){
		scan(A[i]);
		ll tmp=A[i];
		rep(k,INF){
			if(tmp==0) break;
			ketawa[k]+=(tmp&1);
			tmp>>=1;
		}
	}
	for(int i=41;i>=0;i--){
		if(nownum+(1LL<<i)<=K){
			if(ketawa[i]<=N/2) nownum+=(1LL<<i);
		}
	}
	ll ans=0;
	rep(i,N) ans+=(nownum^A[i]);
	prin(ans);
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i;
	cin>>n;
	char a[n],b[n],c[n+n];
	for(i=0;i<n;i++)
	cin>>a[i];
	for(i=0;i<n;i++)
	cin>>b[i];
	for(i=0;i<n;i++)
	cout<<a[i]<<b[i];
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left

inf = (10 ** 10) * 2 + 10

a, b, q = map(int, input().split())

s = [-inf]
for _ in range(a):
    s.append(int(input()))
s.append(inf)
s.sort()

t = [-inf]
for _ in range(b):
    t.append(int(input()))
t.append(inf)
t.sort()

for _ in range(q):
    x = int(input())

    si = bisect_left(s, x) - 1
    ti = bisect_left(t, x) - 1

    ret = inf
    for sx in s[si:si + 2]:
        for tx in t[ti:ti + 2]:
            ret = min(ret, min(abs(x - sx), abs(x - tx)) + abs(sx - tx))
    print(ret)


Measured memory_bytes: 78584
#include <algorithm>
#include <cassert>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

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

    vector<long> A(N), B(N), C(N);
    for (long& a : A)
        cin >> a;
    for (long& b : B)
        cin >> b;
    for (long& c : C)
        cin >> c;

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    vector<long> bt;
    for (int i = 0; i < N; ++i) {
        long b = B[i];
        auto it = upper_bound(C.begin(), C.end(), b);
        bt.push_back(C.end() - it);
    }

    vector<long> bs(N + 1);
    for (int i = N - 1; i >= 0; --i) {
        bs[i] = bs[i + 1] + bt[i];
    }

    long ans = 0;
    for (int i = 0; i < N; ++i) {
        long a = A[i];
        auto it = upper_bound(B.begin(), B.end(), a);
        long j = it - B.begin();
        if (j < N) {
            ans += bs[j];
        }
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 4340
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const double PI=3.14159265358979323846;

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

int main()
{
	double r;
	cin >> r;
	double S = PI * r * r;
	double L = 2 * PI * r;

	printf("%.6f %.6f\n", S, L);

	return 0;
}




Measured memory_bytes: 3208
N, C, K = [int(x) for x in input().split()]

times = [int(input()) for x in range(N)]
times.sort()

count = 0
minimum = None
passenger = 0

for t in times:
    passenger += 1
    if minimum  and (t - minimum) > K:
        count += 1
        minimum = t
        passenger = 1
    elif passenger == C:
        count += 1
        minimum = None
        passenger = 0
    elif minimum is None:
        minimum = t

if passenger:
    count += 1

print(count)


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

int main()
{
	int n;
	setprecision(5);
	long double x[4], y[4],d1,d2,d3,d4;
	int ans[100];
	cin >> n;
	for (int a = 0; a < n; a++) {
		cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2] >> x[3] >> y[3];
		if (x[0] > x[1]) {
			d1 = x[0] - x[1];
			d3 = y[0] - y[1];
		}
		else {
			d1 = x[1] - x[0];
			d3 = y[1] - y[0];
		}
		if (x[2] > x[3]) {
			d2 = x[2] - x[3];
			d4 = y[2] - y[3];
		}
		else {
			d2 = x[3] - x[2];
			d4 = y[3] - y[2];
		}

		if (d3 / d1 == d4 / d2)
			ans[a] = 0;
		else
			ans[a] = 1;
	}
	for (int b = 0; b < n; b++) {
		if (ans[b] == 0)
			cout << "YES" << endl;
		else if (ans[b] == 1)
			cout << "NO" << endl;
	}
}

Measured memory_bytes: 3160
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.next();

        boolean b = true;
        for(int i=1; i<n.length(); i++){
            if(n.charAt(i) != '9') b = false;
        }


        if(b){
            System.out.println((int)n.charAt(0) - 48 + (n.length()-1)*9);
        }else{
            System.out.println((int)n.charAt(0) - 48 + (n.length()-1)*9 - 1);
            
        }
    }
}

Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;
typedef unsigned long long ull;

int cnt = 0;
int S[500000];

void merge(int* A, int left, int mid, int right)
{
	int i = 0, j = 0;

	int n1 = mid - left;
	int n2 = right - mid;

	int* L = new int[n1 + 1];
	int* R = new int[n2 + 1];

	rep(i, n1) L[i] = A[left + i];
	rep(i, n2) R[i] = A[mid + i];
	L[n1] = 1000000001;
	R[n2] = 1000000001;

	rep1(k, left, right - 1) {
		if (L[i] <= R[j]) {
			A[k] = L[i];
			i++;
		}
		else {
			A[k] = R[j];
			j++;
		}
		cnt++;
	}

	delete[] L, R;
}

void mergeSort(int* A, int left, int right)
{
	int mid;

	if (left + 1 < right) {
		mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}

int main()
{
	int N;

	cin >> N;
	rep(i, N) cin >> S[i];

	mergeSort(S, 0, N);

	cout << S[0];
	rep1(i, 1, N - 1) cout << ' ' << S[i];
	cout << endl << cnt << endl;

	return 0;
}



Measured memory_bytes: 37256
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;

int main()
{
	char map[55][55];
	int n,m;
	scanf("%d %d",&n,&m);
	memset(map,'0',sizeof(map));
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
	    cin >>map[i][j];
	 }
	/* for(int i=1;i<=n;i++)
	 {
	 	for(int j=1;j<=m;j++)
	 	printf("%c",map[i][j]);
	 }*/
	 int ans=0;
	 for(int i=1;i<=n;i++)
	 {
	 	
	 	for(int j=1;j<=m;j++)
	 	{
	 		if(map[i][j]=='.')
	 		{
	 		
	 			while(map[i][j-1]=='#')
	 			{
	 				ans++;
	 				break;
				 }
	 			
	 			while(map[i-1][j-1]=='#')
	 			{
	 				ans++;
	 				break;
				 }
	 			
	 			while(map[i-1][j]=='#')
	 			{
	 				ans++;
	 				break;
				 }
	 			
	 			while(map[i-1][j+1]=='#')
	 			{
	 				ans++;
	 				break;
				 }
	 			
	 			while(map[i][j+1]=='#')
	 			{
	 				ans++;
	 				break;
				 }
	 			
	 			while(map[i+1][j+1]=='#')
	 			{
	 				ans++;
	 				break;
				 }
	 			
				while(map[i+1][j]=='#')
	 			{
	 				ans++;
	 				break;
				 }
	 			
	 			while(map[i+1][j-1]=='#')
	 			{
	 				ans++;
	 				break;
				 }
	 			
			 map[i][j]=ans+'0';
			 ans=0;
		}
		else
		continue;
		 }
		 
	  } 
	  for(int i=1;i<=n;i++)
	  {
	  	for(int j=1;j<=m;j++)
	  	{
	  		printf("%c",map[i][j]);
		  }
		  printf("\n");
	  }
	
	return 0;
 } 

Measured memory_bytes: 256
#include <iostream>
#include <cstdio> 
#include <cstring>
#include <cmath>
#include <string>
using namespace std;
int a[100005];
int main()
{
	int n,x;
	cin>>n>>x;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	long long ans=0;
	for(int i=0;i<n-1;i++)
	{
		if(a[i]+a[i+1]>x)
		{
			if(a[i]<=x)
			{	
				ans=ans+(a[i+1]+a[i]-x);
				a[i+1]=x-a[i];
			}
			else
			{
				ans+=(a[i+1]+a[i]-x);
				a[i+1]=0; 
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

vector<int> g[100005];
int n, m, pre[100005];

void bfs() {
    queue<pair<int, int> > q;
    q.push({1, 0});
    while(!q.empty()) {
        int x = q.front().first;
        int pr = q.front().second;
        q.pop();
        if(pre[x]) continue;

        pre[x] = pr;
        for(auto next: g[x])
            if(!pre[next])
                q.push({next, x});
    }
}

int main() {
    cin >> n >> m;
    while(m--) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    bfs();
    for(int i = 2; i <= n; i++)
        if(!pre[i]) {
            cout << "No";
            return 0;
        }
    cout << "Yes\n";
    for(int i = 2; i <= n; i++)
        cout << pre[i] << '\n';
}


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

int main(void){
    int n, m;
    cin >> n >> m;
    int wa_sum = 0;
    map<int, bool> ac;
    map<int, int> wa;
    int ac_count = 0;
    rep(i,m){
        int p;
        string s;
        cin >> p >> s;
        if (s == "WA" && !ac[p]) {
            wa[p]++;
        } else if (s == "AC" && !ac[p]) {
            ac[p] = true;
            ac_count++;
        }
    }
    for(auto itr : wa){
        int p = itr.first;
        if(ac[p]) wa_sum += wa[p];
    }
    cout << ac_count << " " << wa_sum << endl;
    return 0;
}


Measured memory_bytes: 6144
#include<cstdio>
#include<cstring>
char s[100005];
int main()
{
	scanf("%s",s);
	int len=strlen(s);
	for(int i=0;i<len-2;i++)
		if(s[i]==s[i+1]||s[i+1]==s[i+2]||s[i+2]==s[i])
		{
			printf("%d %d",i+1,i+3);
			return 0;
		}
	printf("%s",len==2&&s[0]==s[1]?"1 2":"-1 -1");
}

Measured memory_bytes: 256
import java.util.*;
 class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int size=sc.nextInt();
        int num=sc.nextInt();
        int arr[]=new int[size];
        for(int i=0;i<size;i++){
            arr[i]=sc.nextInt();
        }
        Arrays.sort(arr);
        int sum=0;
        for(int j=0;j<num;j++){
            sum=sum+arr[j];

        }
        System.out.println(sum);
    }
    
}

Measured memory_bytes: 38920
from sys import stdin
input = stdin.readline


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

  SR = []
  for i in range(N-1):
    SR.append(A[i+1]-A[i])
  SR.append(K-A[N-1]+A[0])

  SL = [A[0]+K-A[N-1]]
  for i in range(N-1, 0, -1):
    SL.append(A[i]-A[i-1])

  print(min(sum(SR)-max(SR), sum(SL)-max(SL)))


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 114468
//Fractional Knapsack
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct Material{
	int w, v;
	bool operator<(const Material& val)const{ return 1.0*v*val.w < 1.0*val.v*w; };
};

int main(){
	cout.precision(16);
	int N, W;
	vector<Material> M;
	M.reserve(100000);
	double CurW = 0.0;//現在のW値
	double Max = 0.0;//求める最大値
	//入力
	cin >> N >> W;
	{
		Material temp;
		for (int i = 0; i < N; ++i){
			cin >> temp.w >> temp.v;
			if (temp.w < 0){
				if (temp.v >= 0){//w- && v0+ -> 必ず使用(x=1)
					CurW += temp.w;
					Max += temp.v;
				} else{//w- && v- -> 使用したことにして符号合わせ
					CurW += temp.w;
					Max += temp.v;
					temp.w *= -1; temp.v *= -1;
					M.push_back(temp);
				}
			} else if (temp.v > 0){//w0+ && v+ -> v/w大の順に使用
				M.push_back(temp);
			}
			//w0+ && v0- -> 必ず不使用(x=0)/無視
		}
	}
	sort(M.begin(), M.end());
	//w,v同符号 -> v/w大の順に使用
	for (vector<Material>::reverse_iterator it = M.rbegin(); it != M.rend(); ++it){
		if (CurW + it->w <= W){//W超えない -> x=1.
			CurW += it->w;
			Max += it->v;
		} else{//W超える1つめ -> x=適正値.break.
			Max += double(W - CurW) / it->w * it->v;
			break;
		}
	}
	//出力
	cout << Max << endl;

	return 0;
}

Measured memory_bytes: 1272
n=int(input())
a=list(map(int,input().split()))
a.sort()
for i in range(n//2):
	if a[i*2]<=0 and a[i*2+1]<=0:
		a[i*2]*=-1
		a[i*2+1]*=-1
for i in range(n-1):
	if a[i]<0 and a[i+1]<-a[i]:
		a[i]*=-1
		a[i+1]*=-1
print(sum(a))


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

const int N = 2e6 + 5;
typedef long long LL;

int n, a[N], ans, vis[N];

int main() {
	cin>>n;
	ans = n;
	for(int i = 1; i <= n; i++) {
		cin>>a[i];
		vis[a[i]]++;
	}
	for(int i = 1; i <= n; i++) {
		int ok = 0;
		for(int j = 2; j <= sqrt(a[i]); j++)
			if(a[i]%j == 0) 
				if(vis[a[i]/j] || vis[j]) {
					ans--;
					ok = 1;
					break;
				}
		if(!ok && (vis[a[i]] > 1 || (vis[1] && a[i] != 1))) ans--;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8252
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

ll dp[22][1ll<<21];

int main(){
  int n; cin >> n;
  vector<vector<int> > a(n,vector<int>(n));
  rep(i,n)rep(j,n) cin >> a[i][j];
  dp[0][0]=1;
  rep(i,n){
    rep(s,1ll<<n){
      if(__builtin_popcount(s)!=i) continue;
      rep(j,n){
        if(a[i][j]&&(((1ll<<j)&s)==0)){
          dp[i+1][s|(1ll<<j)]+=dp[i][s];
          dp[i+1][s|(1ll<<j)]%=mod;
        }
      }
    }
  }
  ll ans=0;
  rep(s,1ll<<n){
    ans+=dp[n][s];
    ans%=mod;
  }
  cout << ans << endl;
  /*
  rep(i,n+1){
    rep(j,1ll<<n){
      cout << dp[i][j];
    }cout << endl;
  }*/
}

Measured memory_bytes: 309504
#![allow(unused_imports)]

use std::{i32, i64, u32, u64, usize, f64};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};
use maplit::*;
use proconio::marker::{Isize1, Usize1, Bytes, Chars};

#[proconio::fastout]
fn main() {
    proconio::input!(
        w: i32,
        h: i32,
        n: usize,
        xya: [(i32, i32, i32); n],
    );
    let (mut xl, mut xr, mut yb, mut ya) = (0, w, 0, h);
    for (x, y, a) in xya {
        match a {
            1 => { xl = max(xl, x); },
            2 => { xr = min(xr, x); },
            3 => { yb = max(yb, y); },
            _ => { ya = min(ya, y); },
        };
    };
    println!("{}", max(0, xr - xl) * max(0, ya - yb));
}


Measured memory_bytes: 2200
////////////////////////////////////////////
///                                      ///
///        Template ver. 1.2. rapel      ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
#include <chrono>
#include <random>

#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define F first
#define S second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define endl '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

void hora(int tc) {
	int k, a, b;
	cin>>k>>a>>b;
	int r = b / k - (a - 1) / k;
	if(r != 0) cout<<"OK"<<endl;
	else cout<<"NG"<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}

Measured memory_bytes: 3640
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	static  int H;
	static  int W;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		H = sc.nextInt();
		W = sc.nextInt();
		char[][] S = new char[H][W];
		int[][] dist = new int[H][W];
		for(int i=0;i<H;i++) {
			String tmpS=sc.next();
			for(int j=0;j<W;j++) {
				S[i][j]=tmpS.charAt(j);
				dist[i][j] = -1;
			}
		}
		
		int maxdist=0;
		for(int i=0;i<H;i++) {
			for(int j=0;j<W;j++) {
				if(S[i][j]=='.') {
					Coordinate start = new Coordinate(i,j);
					maxdist = Math.max(maxdist, getMaxDist(start,dist,S));
				}
			}
		}
		System.out.println(maxdist);
		
	}
	static int getMaxDist(Coordinate start,int[][] dist1,char[][] S) {
		ArrayDeque<Coordinate> queue = new ArrayDeque<>();
		int[][]dist = new int[H][W];
		for(int i=0;i<H;i++) {
			for(int j=0;j<W;j++) {
				dist[i][j]=dist1[i][j];
			}
		}
		
		int[] directionX= {1,0,-1,0};
		int[] directionY= {0,1,0,-1};
		//スタート地点をキューに入れ、対応する距離をゼロとする。
		queue.addLast(start);
		dist[start.x][start.y]=0;

		while(!queue.isEmpty()) {
			//キューから要素を取り出し、対応する距離を
			Coordinate nowCoordinate=queue.removeFirst();
			//隣接行列や隣接リスト等に基づき、近くでまだ訪問していない要素をキューに追加する。その際、対応する距離は現在の要素の距離+1
			for(int i=0;i<4;i++) {
				int newX =directionX[i]+nowCoordinate.x;
				int newY = directionY[i]+nowCoordinate.y;
				int nowdist = dist[nowCoordinate.x][nowCoordinate.y];
				if(0<=(newX) && (newX)<=H-1 && 0<=(newY) && (newY)<=W-1) {
					if(dist[newX][newY]==-1) {
						if(S[newX][newY]=='.') {
							dist[newX][newY]=nowdist+1;
							Coordinate newCoordinate = new Coordinate(newX,newY);
							queue.addLast(newCoordinate);
						}
					}
				}
			}
		}
		int maxdist=0;
		for(int i=0;i<H;i++) {
			for(int j=0;j<W;j++) {
				maxdist = Math.max(maxdist, dist[i][j]);
			}
		}
		return maxdist;
	}
}

class Direction{
	int x;
	int y;
	public Direction(int x,int y){
		this.x=x;
		this.y=y;
	}
}

class Coordinate{
	int x;
	int y;
	public Coordinate(int x,int y) {
		this.x = x;
		this.y = y;
	}
	
	public boolean equals(Coordinate c) {
		if(c.x==this.x && c.y==this.y) {
			return true;
		}else {
			return false;
		}
	}
}

Measured memory_bytes: 27604
// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^31.
// NOTE: This function does not handle error cases.
fun fastReadInts(n: Int): IntArray {
  val xs = IntArray(n)
  val s = readLine()!!
  var currentValue = 0
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1 else 1
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1 else 1
  return xs
}

fun solve(n: Int, xs: IntArray): IntArray? {
  val ys = IntArray(n, { -1 })
  for (i in n - 1 downTo 0) {
    val index = xs[i] - 1
    var currentIndex = -1
    var isValid = false
    for (k in 0 until n) {
      // println(ys.joinToString(","))
      if (ys[k] == -1) {
        currentIndex++
        if (currentIndex == index) {
          // println("$index $currentIndex")
          ys[k] = xs[i]
          isValid = true
          break
        }
      }
    }
    if (!isValid) {
      return null
    }
  }
  return ys
}

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val xs = fastReadInts(n)
  val ys = solve(n, xs)
  if (ys == null) {
    println(-1)
  } else {
    for (y in ys) {
      println(y)
    }
  }
}


Measured memory_bytes: 33756