akhauriyash/Code-Regression huggingface dataset:
#include <iostream> 
#include <cstdio> 
#include <fstream> 
#include <algorithm> 
#include <cmath> 
#include <deque> 
#include <vector> 
#include <queue> 
#include <string> 
#include <cstring> 
#include <map> 
#include <stack> 
#include <set> 
using namespace std;
typedef  long long ll;
const int maxn = 210000;
char a[maxn];
int main()
{
	scanf("%s", a+1);
	int len = strlen(a+1);
	int t=-1,ans=0,t1=0;
	for (int i = 1; i <= len; i++)
	{
		int now = a[i] - 'a'+1;
		if (now == t)
		{
			t = t * 100 + now;
			t1 = now;
		}
		else
		{
			ans++;
			
			if (t1)t = t1 * 100 + now;
			else t = now;
			t1 = 0;
		}
	}
	printf("%d\n", ans);
}

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

using namespace std;
const int N = 2000000 + 77;
int n , a[N] , t[N] , Mx;
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	cin >> n;
	for(int i = 1;i <= n;i++){cin >> a[i];}
	for(int i = 1;i <= n;i++){
		t[a[i]] = t[a[i] - 1] + 1;
		Mx = max(Mx , t[a[i]]);
	}
	cout << n - Mx;
 	return 0;
}	

Measured memory_bytes: 5120
from itertools import combinations

n = int(input())
li_l = list(map(int, input().split()))

answer = 0
for c in combinations(li_l, 3):
    so = sorted(list(c))

    if (so[0] + so[1]) > so[2] and len(set(so)) == 3:
        answer += 1
print(answer)


Measured memory_bytes: 9044
def main():
    S = input()
    u = 0
    H = [0] * 2019
    H[0] = 1
    m = 1
    r = 0
    for s in reversed(S):
        u = (u + m * int(s)) % 2019
        r += H[u]
        H[u] += 1
        m = (m * 10) % 2019
    return r


print(main())


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

int main() {
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    for(int i=0; i<n; i++) cin >> p[i];
    for(int i=0; i<n; i++) cin >> q[i];

    vector<int> a(n);
    for(int i=0; i<n; i++) a[i] = i+1;

    map<vector<int>, int> mp;
    do {
        mp[a] = mp.size();
    } while (next_permutation(a.begin(), a.end()));

    int ans = abs(mp[p] - mp[q]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5248
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < n; i++)

int main(void) {
	int k, a, b;
	scanf("%d%d%d", &k, &a, &b);
	for (; a <= b; a++)
		if (a % k == 0) {
			printf("OK\n");
			return 0;
		}
	printf("NG\n");
	return 0;
}


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

const lli mod = 1e9+7;

lli n;
string s;

lli modpow(lli a, lli x){
	lli ret = 1;
	while(x > 0){
		if(x&1){
			ret *= a;
			ret%=mod;
			x--;
		}else{
			a*=a;
			a%=mod;
			x >>= 1;
		}
	}
	return ret;
}

int main(void){
	cin >> n >> s;
	vector<lli> used(26);
	rep(i, n){
		used[s[i]-'a']++;
	}
	lli ans = 1;
	rep(i, 26){
		ans*=used[i]+1;
		ans%=mod;
	}
	ans--;
	if(ans < 0) ans*=mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3748
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
 
int main() {
    int a,b;cin>>a>>b;
    int hasi = b-(a-1);
    int migi = b+(a-1);
    for(int i = hasi;i<=migi;i++){
      if(i<1000001&&i>-1000001) cout<<i<<" ";
    }
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[n - 1 - i];
    rep(i, n) {
        cout << a[i];
        if(i < n - 1)
            cout << " ";
    }
    cout << endl;
}



Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int dp[10000];
vector<int> kane;
int n;
int main(){

  for(int i = 1 ; i*i <= 300 ; i++ )kane.push_back(i*i);
  dp[0] = 1;
  for(int j = 0 ; j < kane.size() ; j++ ){
    for(int k = kane[j] ; k <= 300 ; k++ ){
      dp[k] += dp[k-kane[j]];
    }
  }
  while(cin >> n,n){
    cout << dp[n] << endl;
  }
  return 0;
}

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

#define modn 1000000007
vector<int> count;
vector<int> primenum;

void findprime(int n); 
void primefac(int n);
int main(){
	int n;
	cin >> n;
	if(n==1){
		cout << "1" << endl;
		return 0;
	}
	findprime(n);
	primefac(n);
	long long a=1;
	for(int i=0; i<count.size(); i++){
		a *= (count[i]+1);
		a%=modn;
	}
	cout << a << endl;

	//cin >> a;
	return 0;
}

void findprime(int n){
	primenum.push_back(2);
	int s;
	bool flag;
	for(int i=3; i<=n; i+=2){
		flag=1;
		s=sqrt(i);
		for(int j=3; j<=s; j+=2){
			if(i%j==0){
				flag=0;
				break;
			}
		}
		if(flag){
			primenum.push_back(i);
			//cout << i << endl;
		}
	}
}

void primefac(int n){
	count.resize(primenum.size());
	int m=0;
	for(int i=0; i<primenum.size(); i++){
		m=0;
		for(int j=1; pow(primenum[i],j)<=n; j++){
			m += n / pow(primenum[i], j);
		}
		count.push_back(m);
		//cout << primenum[i] << " " << m << endl;
	}
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>
using namespace std;

int main()
{
    long long int arr[100001];
    long long int N, i, Q, q, a, b, sum=0;
    cin>>N;
    for(i=0;i<100001;i+=1)
    {
        arr[i]=0;
    }
    for(i=0;i<N;i+=1)
    {
        cin>>a;
        arr[a]+=1;
        sum+=a;
    }
    cin>>Q;
    for(q=0;q<Q;q+=1)
    {
        cin>>a>>b;
        sum = sum-(a)*arr[a];
        sum = sum+(b)*arr[a];
        arr[b]+=arr[a];
        arr[a]=0;
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 4376
#include<iostream>
#include<string>

using namespace std;

int main() {

	int N;
	cin >> N;
	string s;
	cin >> s;
	int ans = 0;

	for (int i = 1; i<N; i++) {
		int count = 0;
		for (char c = 'a'; c <= 'z'; c++) {
			bool right = false, left = false;
			for (int j = 0; j <= i; j++) {
				if (s[j] == c)left = true;
			}

			for (int j = i + 1; j<N; j++) {
				if (s[j] == c)right = true;
			}

			if (left&&right) count++;
		}
		if (ans<count)ans = count;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

#[allow(unused_macros)]
macro_rules! trace {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    };
    ($($args:expr),*) => { trace!(($($args),*)) }
}

#[allow(unused_macros)]
macro_rules! put {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stdout(), "{}", $var);
    };
    ($var:expr, $($args:expr),*) => {
        let _ = write!(&mut std::io::stdout(), "{} ", $var);
        put!($($args),*);
    };
}

fn main() {
    let mut sc = Scanner::new();

    let n: usize = sc.cin();
    let k: usize = sc.cin();
    let xs: Vec<usize> = (0..n).map(|_| sc.cin()).collect();

    let mut game = vec![false; k + k + 10];

    for i in 0..k+1 {
        let mut r = false;
        for &x in xs.iter() {
            if i >= x {
                if !game[i-x] {
                    r = true;
                    break;
                }
            }
        }
        game[i] = r;
    }

    // trace!(&game);
    put!(if game[k] { "First" } else { "Second" });
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
}


Measured memory_bytes: 4352
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


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

int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int H, W;

  std::cin >> H >> W;

  std::vector<std::string> board(H + 2, std::string('.', W + 2));

  for (int i = 1; i <= H; i ++) {
    std::cin >> board[i];

    board[i] = '.' + board[i] + '.';
  }

  for (int i = 1; i <= H; i ++)
    for (int j = 1; j <= W; j ++)
      if (board[i][j] == '.') {
        int c = 0;
      
        for (int k = 0; k < 8; k ++) {
          int jj = j + dx[k], ii = i + dy[k];

          if (board[ii][jj] == '#')
            c ++;
        }

        board[i][j] = c + '0';
      }

  for (int i = 1; i <= H; i ++) {
    for (int j = 1; j <= W; j ++)
      std::cout << board[i][j];
    std::cout << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int d,t,s;
	cin>>d>>t>>s;
	//cout<<d/s<<endl;
	if((d/s)<t)
	 cout<<"Yes"<<endl;
	else if((d/s)==t)
	 {
	    if(d%s==0)
	       cout<<"Yes"<<endl;
		else
		 cout<<"No"<<endl;
	   }
	 else
	 
	  cout<<"No"<<endl;
	  
	
	
	
	
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> left(M);
  vector<int> right(M); 
  
  for (int i = 1; i <= N; i++) { //都市iについて
    int sum = 0;
    
    for (int j = 0; j < M; j++) {
      cin >> left.at(j);
      cin >> right.at(j);
      
      if (left.at(j) == i) {
        sum += 1;
      }
      if ( right.at(j) == i) {
        sum += 1;
      }
      
    }
    
    cout << sum << endl;
    
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int k = sc.nextInt();
		sc.close();

		int mod = 1000000007;
		int[] line = new int[w + 1];
		int[] line0 = new int[w + 2];
		int end = (int) Math.pow(2, w - 1);
		for (int i = 0; i < end; i++) {
			String str = Integer.toBinaryString(i);
			StringBuilder sb = new StringBuilder(str);
			while (sb.length() < w - 1) {
				sb.insert(0, '0');
			}
			if (sb.indexOf("11") == -1) {
				for (int j = 0; j < sb.length(); j++) {
					line[j + 1] += sb.charAt(j) - '0';
					if (j == 0) {
						if (sb.charAt(j) == '0') {
							line0[j + 1]++;
						}
					}
					if (j == sb.length() - 1) {
						if (sb.charAt(j) == '0') {
							line0[j + 2]++;
						}
					} else {
						if (sb.charAt(j) == '0' && sb.charAt(j + 1) == '0') {
							line0[j + 2]++;
						}
					}
				}
			}
		}
//		for (int i = 0; i < line.length; i++) {
//			System.out.print(line[i] + " ");
//		}
//		System.out.println();
//		for (int i = 0; i < line0.length; i++) {
//			System.out.print(line0[i] + " ");
//		}
//		System.out.println();

		long[][] dp = new long[h + 1][w + 2];
		dp[0][1] = 1;
		for (int i = 0; i < h; i++) {
			for (int j = 1; j <= w; j++) {
				// →
				long sum = dp[i][j - 1] * line[j - 1] % mod;
				// ↓
				sum += dp[i][j] * line0[j] % mod;
				sum %= mod;
				// ←
				sum += dp[i][j + 1] * line[j] % mod;
				sum %= mod;
				dp[i + 1][j] = sum;
			}
		}
//		for (int i = 0; i <= h; i++) {
//			for (int j = 1; j <= w; j++) {
//				System.out.print(dp[i][j] + " ");
//			}
//			System.out.println();
//		}
		System.out.println(dp[h][k]);
	}
}


Measured memory_bytes: 23508
#include<iostream>
#include<vector>
#include<map>
#include<queue>
#include<cmath>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int main() {
  int n;
  cin >> n;
  int c[8][8];
  rep (i, n) rep (j, n) cin >> c[i][j];
  int v = 0;
  rep (i, n) v = v * 10 + i;
  map<int, int> mp;
  priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int > > > que;
  que.push(make_pair(0, v));
  while (!que.empty()) {
    pair<int, int> now = que.top();
    que.pop();
    if (mp.count(now.second) > 0 && mp[now.second] <= now.first) continue;
    mp[now.second] = now.first;
    rep (i, n) rep (j, n) {
      int vv = now.second;
      int a = now.second / (int)pow(10, i) % 10;
      int b = now.second / (int)pow(10, j) % 10;
      vv -= a * pow(10, i);
      vv += a * pow(10, j);
      vv -= b * pow(10, j);
      vv += b * pow(10, i);
      que.push(make_pair(now.first + c[i][j], vv));
    }
  }
  int res = 0;
  for (map<int, int>::iterator it = mp.begin(); it != mp.end(); ++it) {
      res = max(res, it->second);
    }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 20180
a,b,c,d,n=`dd`.split.map &:to_i;n*=4
h={1=>a,2=>b,4=>c,8=>d}
a=[0]
(1..8).each{|i|
	a[i]=Float::INFINITY
	h.each{|k,v|
		a[i]=[a[i],a[i-k]+v].min if i>=k
	}
}
d,r=n.divmod 8
p d*a[8]+a[r]

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

#define pb push_back
#define sp " "
#define sl "\n"
#define fi first
#define se second
#define mp make_pair
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define rev(a) reverse(a.begin(),a.end())

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef pair<int,ii> iii;

const int N=1000+5,mod=1000000007;
int a,b;

int main() {
	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);
	cin>>a>>b;
	if (b>=a) cout<<"un";
	cout<<"safe";
	return 0;

}


Measured memory_bytes: 3600
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.max
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    val aList = readLongList()
    val gcdListRight = LongArray(n)
    gcdListRight[0] = aList.first()
    val gcdListLeft = LongArray(n)
    gcdListLeft[0] = aList.last()
    for (i in 1 until n) {
        gcdListRight[i] = gcd(gcdListRight[i - 1], aList[i])
        gcdListLeft[i] = gcd(gcdListLeft[i - 1], aList[n - 1 - i])
    }

    var ans = gcdListLeft[n - 2]
    for (i in 1 until (n - 1)) {
        val a = gcdListRight[i - 1]
        val b = gcdListLeft[n - 2 - i]
        val tmp = gcd(a, b)
        ans = max(ans, tmp)
    }
    ans = max(ans, gcdListRight[n - 2])
    out.println(ans)
}

/** O(log(n)): n = min(a, b) */
tailrec fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)


fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 62536
#include<iostream>

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)
#define ll long long

ll x;
ll inte;
ll res;

int main(){
    cin >> x;

    inte = x/11;
    res = x%11;
    if(res==0){
        cout << inte*2 << endl;
    } else if (res <= 6){
        cout << inte*2 + 1 << endl;
    } else {
        cout << inte*2 + 2 << endl;
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (D, T, S) = Read3Longs();
            return (double)D / S <= T ? "Yes" : "No";
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


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

long long N;
string S;

int main(){
	cin >> N >> S;
	long long cur = 0;
	long long ans = 0;

	for(long long i = 0; i < S.size(); i++){
		if(S[i] == '('){
			cur++;
		}else {
			if(cur == 0){
				ans++;
			}else{
				cur--;
			}
		}
	}
	for(long long i = 0; i < ans; i++)
		cout << '(';
	cout << S;

	for(long long i = 0; i < cur; i++)
		cout << ')';
	cout << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;

namespace AOJ
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Trim().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long gcd(long x, long y) => y == 0 ? x : gcd(y, x % y);

        //https://qiita.com/drken/items/b97ff231e43bce50199a
        static long  extGCD(long a, long b, out long x, out long y)
        {
            if (b == 0)
            {
                x = 1;
                y = 0;
                return a;
            }
            long d = extGCD(b, a % b, out y, out x);
            y -= a / b * x;
            return d;
        }
        static void Main(string[] args)
        {
            var ab = Sarray();
            long x, y;
            extGCD(ab[0], ab[1],out x, out y);
            WriteLine($"{x} {y}");
        }
    }
}


Measured memory_bytes: 20428
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cctype>
#define INF 1000000000
using namespace std;
bool debug=false;

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


Measured memory_bytes: 256
unittest
{
	assert( [ "3 4 240", "60 90 120", "80 150 80 150" ].solve == 3 );
	assert( [ "3 4 730", "60 90 120", "80 150 80 150" ].solve == 7 );
	assert( [ "5 4 1", "1000000000 1000000000 1000000000 1000000000 1000000000", "1000000000 1000000000 1000000000 1000000000" ].solve == 0 );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto m = 0L;
	auto k = 0L;
	input.front.formattedRead!"%s %s %s"( n, m, k );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	input.popFront;
	auto bs = input.front.split.to!( long[] );
	
	auto ans = 0L;
	auto t = 0L;
	auto bc = 0L;
	auto ac = 0L;
	while( ac < as.length && t + as[ ac ] <= k )
	{
		t += as[ ac ];
		ac++;
	}
	while( true )
	{
		while( bc < bs.length && t + bs[ bc ] <= k )
		{
			t += bs[ bc ];
			bc++;
		}
		ans = max( ans, ac + bc );
		if( ac <= 0 ) break;
		ac--;
		t -= as[ ac ];
	}
	return ans;
}


Measured memory_bytes: 20740
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)

#define WHITE 1//（未訪問）
#define GRAY 2//（訪問）未だに訪問していない頂点への辺を持っている。スタックに退避。
#define BLACK 3//（訪問完了）未訪問への頂点への辺を持たない
#define N 100
#define INFTY (1 << 21) //10^21
int M[N][N];//隣接行列
int color[N];

//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {-1, 0, 1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;
int cnt;

//配列の表示
void printArray(int array[], int n){
    rep(i, n){
        if(i)   cout << " ";
        cout << array[i];
    }
    cout << endl;
}
//全部探索した
bool judge(){
    rep(i, 4){
        if(color[i] != BLACK){
            return false;
        }
    }
    return true;
}

bool flg = false;

void dfs_visit(int u){
    int cnt = 0;
    int v;
    
    color[u] = GRAY;
    
    rep(v, n){
        if(M[u][v] == 0)    continue;
        
        if(color[v] == WHITE){
            cnt++;
            dfs_visit(v);
        }
    
    }
    if(cnt > 1) flg = true;
    color[u] = BLACK;
}
bool flg2 = false;
void dfs(){
    int u;
    
    //初期化
    rep(u, n)   color[u] = WHITE;
    
    rep(u, n){
        //未訪問のuを始点として深さ優先探索
        cnt = 0;
        if(color[u] == WHITE)   dfs_visit(u);
        
        //cout << cnt << endl;
        if(!flg){
            cout << "YES" << endl;
            flg2 = true;
            break;
        }else{
            rep(u, n)   color[u] = WHITE;
        }
    }
    
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    //memset(M, 0, 1000);
    int a, b;
    rep(i, 3){
        cin >> a >> b;
        M[a - 1][b - 1] = M[b - 1][a - 1] = 1;
    }
    
    n = 4;
    
    dfs();
    /*
    printArray(color, 4);
    rep(i, n){
        rep(j, n){
            cout << M[i][j];
        }
        cout << endl;
    }
    */
    if(!flg2)    cout << "NO" << endl;
}

Measured memory_bytes: 256
#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 REP_(i,m,n) for(int i =m; i <n; ++i)

#define INF 2e9

#define ll long long

//const ll mod = 1000000007

using namespace std;

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

    bool f = true;

    REP(i,n/2){
        if(s[i] != s[i+n/2])f = false;
    }
    if(n%2 == 1)f = false;

    if(f)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

int main() {
    long long a,b,c, d, ans, remain;
    cin >> a >> b >> c;
    d = a/(b+c);
    ans = d*b;
    remain = a%(b+c);
    if(remain>=b){
    	ans += b;
    }else{
    	ans += remain;
    }
    cout << ans << endl;
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long llint;
typedef long double ldouble;
// 小大
int compare(const void *a, const void *b){return *(llint *)a - *(llint *)b;}
typedef struct{
    llint aa;
    llint bb;
}frequent;
// 小大
int cmp( const void *p, const void *q ) {
    return ((frequent*)p)->bb - ((frequent*)q)->bb;
}
/*2つのうち小さい数を返す*/
llint min2(llint a,llint b){return a>=b?b:a;}


int main(void){
    llint n,i,k,m=0,t=300000001;
    scanf("%lld%lld",&n,&k);
    llint x[n];
    for(i=0;i<n;i++){
        scanf("%lld",&x[i]);
        if(x[i]<0) m++;
    }
    if(m==0){
        printf("%lld\n",x[k-1]);
        return 0;
    }
    if(m==n){
        printf("%lld\n",-x[n-k]);
        return 0;
    }
    llint minus[m],plus[n-m];
    for(i=0;i<m;i++){
        minus[i]=-x[m-1-i];
        // printf("%lld ",minus[i]);
    }
    for(i=0;i<n-m;i++){
        plus[i]=x[m+i];
        // printf("%lld ",plus[i]);
    }
    for(i=0;i<=k/2+1;i++){
        if(i==0){
            if(k<=m){
                t=min2(minus[k-1],t);
            }
            if(k<=n-m){
                t=min2(plus[k-1],t);
            }
            // printf("%lld ",t);
            continue;
        }
        if(k-i<=m && n-m>=i){
            // printf("%lld ",t);
            t=min2(t,minus[k-1-i]+2*plus[i-1]);
            // printf("! ");
        }
        if(k-i<=n-m && m>=i){
            t=min2(t,plus[k-1-i]+2*minus[i-1]);
            // printf("? ");
        }
        // printf("%lld ",t);
    }


    printf("%lld\n",t);
    return 0;
}


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

public class Main {
	
	public void output(int[][] x){
		Set<Integer> wrong = new HashSet<Integer>();
		for(int i = 0; i < 9; i++){
			int[] save = new int[10];
			for(int j = 0; j < 9; j++){
				if( save[x[i][j]] == 0 ){
					save[x[i][j]] = j+1;
				} else {
					wrong.add(i*9+j);
					wrong.add(i*9+save[x[i][j]]-1);
				}
			}
		}
		for(int i = 0; i < 9; i++){
			int[] save = new int[10];
			for(int j = 0; j < 9; j++){
				if( save[x[j][i]] == 0 ){
					save[x[j][i]] = j+1;
				} else {
					wrong.add(j*9+i);
					wrong.add((save[x[j][i]]-1)*9+i);
				}
			}
		}
		for(int i = 0; i < 9; i += 3){
			for(int j = 0; j < 9; j += 3){
				int[] save = new int[10];
				for(int k = 0; k < 3; k++){
					for(int l = 0; l < 3; l++){
						if( save[x[i+k][j+l]] == 0 ){
							save[x[i+k][j+l]] = (i+k)*9+j+l+1;
						} else {
							wrong.add((i+k)*9+(j+l));
							wrong.add(save[x[i+k][j+l]]-1);
						}
					}
				}
			}
		}
		for(int i = 0; i < 9; i++){
			for(int j = 0; j < 9; j++){
				if( wrong.contains(i*9+j) ){
					writer.print("*");
					wrong.remove(i*9+j);
				} else {
					writer.print(" ");
				}
				writer.print(x[i][j]);
			}
			writer.println();
		}
	}						
			
	public void solve() throws IOException{
		int n = nextInt();
		int[][][] map = new int[n][9][9];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < 9; j++){
				for(int k = 0; k < 9; k++){
					map[i][j][k] = nextInt();
				}
			}
		}
		output(map[0]);
		for(int i = 1; i < n; i++){
			writer.println();
			output(map[i]);
		}
		writer.flush();
	}
		
	public static void main (String args[]) throws IOException{
		new Main().run();
	}
		
	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;
	
	public void run() throws IOException{
		try{
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (Exception e){
			e.printStackTrace();
			System.exit(1);
		}
	}
	public int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}
	public String nextToken() throws IOException{
		while( tokenizer == null || !tokenizer.hasMoreTokens() ){
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}

Measured memory_bytes: 9840
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int w = sc.nextInt();
		int beforeLastNum = 0, LastNum = 0;
		for (int i = 1; i <= n; i++) {
			int a = sc.nextInt();
			if (i == n - 1)
				beforeLastNum = a;
			else if (i == n)
				LastNum = a;
		}
		if (n == 1) {
			System.out.println(Math.abs(w - LastNum));
		} else {
			System.out.println(Math.max(Math.abs(LastNum-w), Math.abs(LastNum - beforeLastNum)));
		}
	}
}

Measured memory_bytes: 25804
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  string S, T;
  cin >> S >> T;
  int ret = 0;
  rep(i,S.size()){
    if(S[i] == T[i]) ret++;
  }
  cout << ret << endl;
  
  return 0;
}


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


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		

		String[] tmpArray = br.readLine().split(" ");
		
		int n = Integer.parseInt(tmpArray[0]);
		int c = Integer.parseInt(tmpArray[1]);
		
		int[][] d = new int[c][c];
		
		for(int i = 0; i < c; i++){
			tmpArray = br.readLine().split(" ");
			for(int j = 0; j < c; j++){
				d[i][j] = Integer.parseInt(tmpArray[j]);
			}
		}

		int[][] matrix = new int[n][n];
		
		int[][] cost = new int[3][c];
		for(int i = 0; i < n; i++){
			tmpArray = br.readLine().split(" ");
			for(int j = 0; j < n; j++){
				matrix[i][j] = Integer.parseInt(tmpArray[j]);
				
				//色変更コスト初期化
				for(int k = 0; k < c; k++){
					cost[(i+j)%3][k] += d[matrix[i][j] - 1][k];
				}
			}
		}
		
		//debug
//		for(int i = 0; i < 3 ;i++){
//			for(int j = 0; j < c; j++){
//				System.out.print(cost[i][j] + " ");
//			}
//			
//			System.out.println();
//		}

		//worst
		int result = Integer.MAX_VALUE;
		for(int i = 0; i < c; i++){
			for(int j = 0; j < c; j++){
				if(i == j){
					continue;
				}
				for(int k = 0; k < c; k++){
					if(i == k || j == k){
						continue;
					}
					
					int tmpResult = cost[0][i] + cost[1][j] + cost[2][k];
					
					result = Math.min(result, tmpResult);
				}
			}	
		}
		
		System.out.println(result);
	}

}


Measured memory_bytes: 46140
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;


const int N = (int) 1e5 + 100;
int n;

struct Perm
{
    int p[N];

    Perm() : p() 
    {
        for (int i = 0; i < N; i++)
            p[i] = i;
    }

    void read()
    {
        for (int i = 0; i < n; i++)
        {
            scanf("%d", &p[i]);
            p[i]--;
        }
    }

    Perm inv() const
    {
        Perm ans = Perm();
        for (int i = 0; i < n; i++)
            ans.p[p[i]] = i;
        return ans;
    }

    Perm operator * (const Perm &A) const
    {
        Perm ans = Perm();
        for (int i = 0; i < n; i++)
            ans.p[i] = A.p[p[i]];
        return ans;
    }

    Perm fpow(int d)
    {
        if (d == 0)
            return Perm();
        Perm A = fpow(d / 2);
        A = A * A;
        if (d & 1)
            A = A * *this;
        return A;
    }

    void print() const
    {
        for (int i = 0; i < n; i++)
            printf("%d ", p[i] + 1);
        printf("\n");
    }

};

Perm A, B, a, b, bABa;

Perm getPref(int pref)
{
    Perm ans = bABa.fpow(pref / 4);
    if (pref % 4 >= 1)
        ans = ans * b;
    if (pref % 4 >= 2)
        ans = ans * A;
    if (pref % 4 >= 3)
        ans = ans * B;
    return ans;
}

int getSufLen(int x)
{
    int ans = x - (x + 2) / 3;
    return ans;
}

int getPrefLen(int x)
{
    int ans = x - x / 3 - 2;
    return ans;
}

int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    int k;
    scanf("%d%d", &n, &k);
    A.read();
    B.read();

    if (k == 1)
    {
        A.print();
        return 0;
    }
    if (k == 2)
    {
        B.print();
        return 0;
    }
    int suff = getSufLen(k);
    int pref = getPrefLen(k);
    eprintf("%d : %d %d\n", k, pref, suff);

    a = A.inv();
    b = B.inv();

    bABa = b * A * B * a;
   
    Perm X = getPref(pref), y = getPref(suff);
    Perm Y = y.inv();

    Perm ans = X * Y;
    ans.print();

	return 0;
}




Measured memory_bytes: 30976
import java.io.*;
import java.util.*;
class Main{
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		String[] s = saori.nextHayami().split("");
		int ans = 0;
		for(int i = 0;i < s.length;i++){
			if(s[i].equals("1")){
				ans++;
			}
		}
		System.out.println(ans);
		
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 22228
#pragma GCC optimize(2)
#pragma GCC optimize(3)   
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector < ll > vl;
typedef vector < vl > vvl;
typedef pair < ll, ll > pll;
typedef vector < pair < ll, ll > > vpll;
#define kill freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define pb push_back
#define fo(i,n) for(ll i=0;i<n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define all(c) c.begin(), c.end()
#define go(c,it) for(auto it=(c).begin(); it!=(c).end(); it++)
#define fi first
#define se second
#define MOD 998244353
#define Boost() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MOD1 1000000007
ll power(ll a, ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;}a=(a*a)%MOD;b>>=1;}return res;}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
#define oo 100000000000000000
const ll dx[]={-1,0,1, 0,-1,1, 1,-1};
const ll dy[]={ 0,1,0,-1, 1,1,-1,-1};
void solve(){
    ll n,k;
    cin>>n>>k;
    ll a[n];
    fo(i,n)cin>>a[i];
    ll ans = oo;
    ll lo = 0,hi = 1e12;
    while(lo<=hi){
        ll mid = (lo+hi)>>1LL;
        if(mid==0){ans = 1;break;}
        ll val = 0;
        fo(i,n){
            if(a[i]>mid){
                ll cut = a[i]/mid;
                if(a[i]%mid==0)cut--;
                val+=cut;
            }
        }
        if(val<=k){
            ans = min(ans,mid);
            hi = mid-1;
        }else{
            lo = mid+1;
        }
    }
    cout<<ans;
}

int main(){
    Boost();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 5084
#include <bits/stdc++.h>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(2)<<(x)
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define inf std::numeric_limits<long long>::max();
#define highest_2_pow(n)  __builtin_clzll((long long)0)- __builtin_clzll((long long)n) - 1
//-----------------------------------------------------------------------------------------------------
#define lli long long int 
#define int long long
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define vi vector<int>
#define vlli vector<long long int>
#define si set<int>
#define slli set<long long int>
#define mt make_tuple
#define mp make_pair
#define eb emplace_back
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
//---------------------------------------------------
using namespace std;
// GCD and LCM are available
void err(istream_iterator<string> it) {cout<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << ";";
err(++it, args...);
}

void faster(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}
#define MAXN 18
int dp[MAXN+1][1<<MAXN];
void solve(){
    int n;
    cin>>n;
    vi a(n);
    vi b(n);
    rep(i,0,n) cin>>a[i];
    rep(i,0,n) cin>>b[i];
    rep(i,0,n) rep(j,0,1<<n) dp[i][j]=1e9;
    rep(i,0,n) dp[i][1<<i]=0;
    rep(mask,0,1<<n){
        rep(i,0,n){
            int p = __builtin_popcount(mask);
            int x = ((p-1)%2==i%2)?a[i]:b[i];
            rep(j,0,n){
                if(1 & (mask>>j)) continue;
                int y = ((p%2==j%2)?a[j]:b[j]);
                if(y<x) continue;
                int D = dp[i][mask] + __builtin_popcount(mask>>j);
                //if(!(((mask | (1<<j))>>3) & 1)) error(x,y,D,i,j,bitset<5>(mask | (1<<j)),p,j);
                if(dp[j][mask | (1<<j)] > D) dp[j][mask | (1<<j)] = D;

            }
            
        }
    }
    int ans=1e9;
    rep(i,0,n){
        ans=min(ans,dp[i][(1<<n)-1]);
        // error(ans,i);
    }
    if(ans>1e8) cout<<"-1"<<endl;
    else cout<<ans<<endl;

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

Measured memory_bytes: 39168
N = int(input())
my_list = []
for i in range(1,N+1):
    l = list((input().split()))
    l.append(i)
    my_list.append(l)
 
my_list2 = sorted(my_list, key=lambda x:(x[0],-int(x[1])))
for i in my_list2:
  print(i[2])
 

Measured memory_bytes: 9132
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 LN           PIC X(8).
01 N            PIC 9(3).
01 R            PIC 9(4).
01 ans          PIC Z(3)9.

PROCEDURE DIVISION.
ACCEPT LN.
UNSTRING LN DELIMITED BY SPACE INTO N R.
IF 10 <= N
    MOVE R TO ans
ELSE
    COMPUTE ans = R + 100 * (10 - N)
END-IF.
DISPLAY ans.
STOP RUN.


Measured memory_bytes: 384
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();
		//int Slen = 10;

		char[][] C = new char[N][10];
		String[] S = new String [N];
		boolean[] f = new boolean [N];//比較済みであり

		for(int i=0;i<N;i++) {
			C[i]=next().toCharArray();
			Arrays.sort(C[i]);
			S[i] = new String(C[i]);
		}
		Arrays.sort(S);

		long sum = 0;
		for(int i=0;i<N-1;i++) {
			if(f[i])continue; // 加算済みであれば次へ飛ばす
			long cnt = 0;
			for(int j=i+1;j<N;j++){
				if(S[i].equals(S[j])) {
					cnt++;
					f[j] = true;
				}else {
					break;
				}
			}
			while(cnt>0) {
				sum+=cnt;
				cnt--;
			}
		}
		out.println(sum);
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

}

Measured memory_bytes: 58476
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
struct tk
{
	ll x,id;
	bool operator<(const tk&y)const
	{
		return x<y.x;
	}
}cst[3],u;
priority_queue<tk> q[3][3];
ll x[3],i,j,k,jew[100005][3],cnt[3],h[3],mx,v,ans=0,vis[100005],seq[10][2],cntt=0,pos;
const ll inf=1e18;
ll check(ll a,ll b){while(vis[q[a][b].top().id]!=a)q[a][b].pop();return q[a][b].top().x;}
ll other(ll a,ll b){return (a!=0&&b!=0)?0:((a!=1&&b!=1)?1:2);}
ll find(ll a,ll b){return cnt[a]<x[a]?0:check(a,other(a,b));}
void add(ll a,ll b)
{
	ll i;
	for(i=0;i<3;i++)
	{
		if(i==b)continue;
		q[b][i].push((tk){jew[a][i]-jew[a][b],a});
	}
}
int main()
{
	scanf("%lld%lld%lld",&x[0],&x[1],&x[2]);
	for(i=0;i<3;i++)cst[i].id=i;
	for(i=1;i<=x[0]+x[1]+x[2];i++)scanf("%lld%lld%lld",&jew[i][0],&jew[i][1],&jew[i][2]);
	for(i=1;i<=x[0]+x[1]+x[2];i++)
	{
		h[0]=h[1]=h[2]=0;
		for(j=0;j<3;j++)
		{
			cst[j].x=jew[i][j];
			cst[j].id=j;mx=0;
			if(cnt[j]==x[j])
			{
				mx=-inf;
				for(k=0;k<3;k++)
				{
					if(k==j)continue;
					if((v=check(j,k)+find(k,j))>mx)mx=v,h[j]=k;
				}
			}
			cst[j].x+=mx;
		}
		if(cst[1].x<cst[2].x)swap(cst[1],cst[2]);
		if(cst[0].x<cst[1].x)swap(cst[0],cst[1]);
		ans+=cst[0].x;
		cntt=0;
		if(cnt[cst[0].id]<x[cst[0].id])cnt[cst[0].id]++;
		else
		{
			u=q[cst[0].id][h[cst[0].id]].top();
			vis[u.id]=h[cst[0].id];
			seq[++cntt][0]=h[cst[0].id];
			seq[cntt][1]=u.id;
			if(cnt[h[cst[0].id]]<x[h[cst[0].id]])cnt[h[cst[0].id]]++;
			else
			{
				pos=other(cst[0].id,h[cst[0].id]);
				u=q[h[cst[0].id]][pos].top();
				vis[u.id]=pos;
				seq[++cntt][0]=pos;
				seq[cntt][1]=u.id;
				cnt[pos]++;
			}
		}
		vis[i]=cst[0].id;seq[++cntt][0]=cst[0].id;seq[cntt][1]=i;
		for(j=1;j<=cntt;j++)add(seq[j][1],seq[j][0]);
	}
	printf("%lld\n",ans);
	return 0;
} 

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

int main(){
  int n,k;
  cin >> n >> k;
  while(n!=0 || k!=0){

    vector<int> a(n);
    for(int i=0;i<n;i++){
      cin >> a.at(i);
    }

    vector<int> s(n);
    s.at(0) = 0;
    for(int i=1;i<n;i++){
      s.at(i) = s.at(i-1)+a.at(i-1);
    }

    int ans=0;
    for(int i=0;i<n-k;i++){
      ans = max(s.at(i+k)-s.at(i),ans);
    }

    cout << ans << endl;

    cin >> n >> k;
  }
}



Measured memory_bytes: 3548
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>

using namespace std;

int main(){
	int h1,h2;
	int k1,k2;
	int a,b,c,d;
	int h_sum=0,k_sum=0;
	
	scanf("%d %d",&h1,&h2);
	scanf("%d %d",&k1,&k2);
	scanf("%d %d %d %d",&a,&b,&c,&d);
	h_sum+=h1*a;
	h_sum+=(h1/10)*c;
	h_sum+=h2*b;
	h_sum+=(h2/20)*d;
	k_sum+=k1*a;
	k_sum+=(k1/10)*c;
	k_sum+=k2*b;
	k_sum+=(k2/20)*d;
	if(h_sum>k_sum)
	printf("hiroshi\n");
	else{
		if(h_sum==k_sum)
		printf("even\n");
		else
		printf("kenjiro\n");
	}
}


Measured memory_bytes: 2680
# include "iostream"
# include "cstdio"

using namespace std;

const long long Inf=1ll<<60;

long long N,A[6];

int main(){
	register int i;
	register long long Min=Inf,Ans;
	scanf("%lld",&N);
	for(i=1;i<=5;i++){
		scanf("%lld",A+i);
		Min=min(Min,A[i]);
	}
	Ans=(N/Min)-(N%Min==0)+5;
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import io.StdIn.readLine
object Main extends App {
  val groupOf = Seq('A', 'C', 'A', 'B', 'A', 'B', 'A', 'A', 'B', 'A', 'B', 'A')
  val Array(x, y) = readLine.split(" ").map(_.toInt - 1)
  println(if (groupOf(x) == groupOf(y)) "Yes" else "No")
}


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

int cnt[45][45] = {0};
long double dis[45][45] = {0};
long double sum[45][45] = {0};
int m, n, x;
long double ans = 1;

long double solve();

int main() {
  cout << fixed << setprecision(12);
  int t;
  for(t = 0; t < 2; ++t) {
    cin >> m >> n >> x;
    ans *= solve();
    for(int i = 0; i < 44; ++i)
      for(int j = 0; j < 44; ++j)
        cnt[i][j] = dis[i][j] = sum[i][j] = 0;
  }
  cout << ans << endl;
  return 0;
}

long double solve() {
  long double nans = 0;
  int i, j;
  long double mn = (long double)(m + n);
  cnt[0][0] = sum[0][0] = 1;
  for(i = 0; i < 44; ++i) dis[0][i] = 1;
  for(i = 1; i <= x; ++i) {
    for(j = 0; j < i; ++j) {
      cnt[i][j] += cnt[i - 1][j];
      cnt[i][j + 1] += cnt[i - 1][j];
    }
    for(j = 0; j <= x; ++j) {
      if(j < i)
        dis[i][j] = dis[i - 1][j] * (long double)m / mn;
      else
        dis[i][j] = dis[i - 1][j] * (long double)n / mn;
    }
    for(j = 0; j < i; ++j) {
      sum[i][j] += sum[i - 1][j];
      sum[i][j + 1] +=
          sum[i - 1][j] -
          dis[i][j] * (long double)cnt[i - 1][j];
    }
  }
  for(i = 0; i <= x; ++i) nans += sum[x][i] * dis[x][i];
  return nans;
}


Measured memory_bytes: 3340
import java.util.Scanner;

public class Main {

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

		if((0<=r) &&( r<1200)) {
			System.out.println("ABC");
		}else if((1200<= r) && (r < 2800)) {
			System.out.println("ARC");
		}else{
			System.out.println("AGC");
		}

	}

}


Measured memory_bytes: 23892