akhauriyash/Code-Regression huggingface dataset:
// Last Change: 03/24/2019 17:15:51.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (abs(a - c) <= d or (abs(a - b) <= d and abs(b - c) <= d)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

from collections import deque

N,Q = map(int,input().split())

L = [deque([]) for _ in range(N)]

for _ in range(Q):
    q = list(map(int,input().split()))
    if q[0] == 0:
        L[q[1]].append(q[2])
    elif q[0] == 1:
        if L[q[1]]:
            print(' '.join(map(str,L[q[1]])))
        else:
            print()
    else:
        if L[q[1]]:
            if L[q[2]]:
                if len(L[q[1]]) == 1:
                    L[q[2]].append(L[q[1]][0])
                elif len(L[q[2]]) == 1:
                    L[q[1]].appendleft(L[q[2]][0])
                    L[q[2]] = L[q[1]]
                else:
                    L[q[2]].extend(L[q[1]])
            else:
                L[q[2]] = L[q[1]]
        L[q[1]] = deque([])


Measured memory_bytes: 61776
#![allow(unused)]

use std::{cmp, collections, fmt, io, iter, ops, str};
use cmp::Ordering::{Equal, Greater, Less};
use collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
use io::{Read, Write};

#[cfg(feature = "debug")]
macro_rules! debug {
    ($fmt: expr) => { eprintln!($fmt) };
    ($fmt: expr, $($arg: tt)*) => { eprintln!($fmt, $($arg)*) };
}

#[cfg(not(feature = "debug"))]
macro_rules! debug {
    ($fmt: expr) => {};
    ($fmt: expr, $($arg: tt)*) => {};
}

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().to_owned()
}

fn read_word() -> String {
    const CAPACITY: usize = 16;

    let mut stdin = io::stdin();
    let mut byte: [u8; 1] = [0];

    loop {
        let mut buf = Vec::with_capacity(CAPACITY);

        loop {
            let res = stdin.read(&mut byte);

            if res.unwrap_or(0) == 0 || byte[0] <= b' ' {
                break;
            } else {
                buf.push(byte[0]);
            }
        }

        if buf.len() > 0 {
            return String::from_utf8(buf).unwrap();
        }
    }
}

fn parse_line<T: str::FromStr>() -> T {
    read_line().parse().ok().unwrap()
}

fn parse_word<T: str::FromStr>() -> T {
    read_word().parse().ok().unwrap()
}

fn parse_vec<T: str::FromStr>() -> Vec<T> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn flush() {
    io::stdout().flush();
}

fn main() {
    let s = read_line();
    let price = 700 + 100 * s.chars().filter(|c| *c == 'o').count();
    println!("{}", price);
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        //
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

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

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, k; cin >> h >> w >> k;
    ll ans = 0;
    vector<string> s(h); rep (i, h) cin >> s[i];
    // rep (i, h) cout << s[i];
    rep (i, (1 << h)) {
        rep (j, (1 << w)) {
            int bl = 0;
            rep (y, h) {
                rep (x, w) {
                    // eprintf("%d %d\n", (i & (1 << y)), (j & (1 << x)));
                    if ((i & (1 << y)) == 0 && (j & (1 << x)) == 0) {
                        if (i == 0 && j == 0) eprintf(".");
                        if(s[y][x] == '#') bl++;
                    }
                }
            }
            // eprintf("%d\n", bl);
            if (bl == k) {
                ans++;
                // eprintf("%d, %d\n", i, j);
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3656
n = input()

c = 0
co = 0
nn = len(n)

mmm = [1 for i in range(nn+1)]
mm = [1 for i in range(nn+1)]

for i in range(1,nn+1):
	mmm[i] = mmm[i-1]*2 
	mmm[i] %= (10**9+7)
	mm[i] = mm[i-1]*3 
	mm[i] %= (10**9+7)


for i in range(0,nn):
	if n[i] == "1":
		co += (mm[nn - i - 1])*(mmm[c])
		co %=  (10**9+7)
		c += 1
print((co + mmm[c])%(10**9+7))



Measured memory_bytes: 46496
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    string s;
    int q;
    cin>>s>>q;
    deque<char> dq;
    for(auto c:s){
        dq.push_back(c);
    }
    int sum=0;
    rep(i,q){
        int num;
        cin>>num;
        if(num==1){
            ++sum;
        }
        else{
            int f;
            char c;
            cin>>f>>c;
            if((f+sum)&1)dq.push_front(c);
            else dq.push_back(c);
        }
    }
    if(sum&1){
        for(auto i=dq.rbegin();i!=dq.rend();++i){
            cout<<*i;
        }
    }
    else{
        for(auto c:dq){
            cout<<c;
        }
    }
    cout<<endl;
}


Measured memory_bytes: 896
/* 
	Author: ankrypt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 15
#define PI 3.141592653589793
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fi(a, b, c, d) for(int a = b; a < c; a += d)
#define fl(a, b, c, d) for(ll a = b; a < c; a += d)
#define fei(a, b, c, d) for(int a = b; a <= c; a += d)
#define fel(a, b, c, d) for(ll a = b; a <= c; a += d)
#define quit exit(0)
#define mem(x, a) memset(x, a, sizeof x)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pcl pair<char, ll>
#define psl pair<string, ll>


ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;
unordered_map<ll, ll> mp;
set<ll> s;
string S = "";
ll cases;

int main() {
	go;
    cin >> N;
    ll  X = 1000;
    ll ans;
    fi(i, 0, 11, 1) {
    	if(X * i >= N) {
    		ans = X * i - N;
    		break;
    	}
    }
    cout << ans << "\n";
    
	return 0;
}
/*
	Powered by Buggy Plugin
*/




Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

int dp[9]={};
int main(){
    fast_io
    
    int n;
    cin>>n;
    int a;
    rep(i,n) {
        cin>>a;
        if(a/400>=8) dp[8]++;
        else dp[a/400]=1;
    }
    int cnt=0;
    rep(i,8){
        if(dp[i]==1) cnt++;
    }
    if(cnt==0) cout<<1<<" "<<dp[8]<<endl;
    else cout<<cnt<<" "<<cnt+dp[8]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define SUM(n) ((n)+1)*(n)/2
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = (1e9)+7;
#define all(v) v.begin(),v.end()
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

  int a[5][5];
  rep(i,3){
    rep(j,3){
      cin >> a[i][j];
    }
  }

  int n, b;
  cin >> n;
  rep(i,n){
    cin >> b;
    rep(j,3){
      rep(z,3){
	if(a[j][z] == b){
	  a[j][z] = 0;
	}
      }
    }
  }

  rep(i,3){
    if(!a[i][0] && !a[i][1] && !a[i][2]){
      cout << "Yes\n";
      return 0;
    }
    if(!a[0][i] && !a[1][i] && !a[2][i]){
      cout << "Yes\n";
      return 0;
    }
   
  }
    
  if(!a[0][0] && !a[1][1] && !a[2][2]){
    cout << "Yes\n";
    return 0;
  }
  if(!a[0][2] && !a[1][1] && !a[2][0]){
    cout << "Yes\n";
    return 0;
  }
  cout << "No\n";
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
main(){
  string a,b,c;
  int a_num,b_num;
  
  cin >> a >> b;
  cin >>a_num>>b_num;
  cin >> c;
  
  if(a==c){
    a_num--;
  }else{
    b_num--;
  }
  
  cout << a_num << " " <<b_num << endl;


}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		int H, W, i, j;
		
		Scanner scan = new Scanner(System.in);
		
		while(true) {
			
			H = scan.nextInt();
			W = scan.nextInt();
			
			for(i = 0; i < H; i++) {
				if(i == 0 || i == H - 1){
					for(j = 0; j < W; j++) {
						System.out.print("#");
					}
				} else {
					System.out.printf("#");
					for(j = 0; j < W - 2; j++) {
						System.out.printf(".");
					}
					System.out.printf("#");
				}
				
				System.out.println();
			}
			
			if(H == 0 && W == 0) break;
			
			System.out.println();
			
		}
		
	}

}


Measured memory_bytes: 53844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS=1e-10;
const ll INF=1000000000;
int main(){
    string s;
    while(1){
        getline(cin,s);
        if(s=="."){
            break;
        }
        stack<char> st;
        bool f=true;
        for(int i=0;i<s.size();i++){
            if(s[i]=='('||s[i]=='['){
                st.push(s[i]);
            }else if(s[i]==')'){
                if(st.empty()){
                    f=false;
                    break;
                }
                if(st.top()=='('){
                    st.pop();
                }else{
                    f=false;
                    break;
                }
            }else if(s[i]==']'){
                if(st.empty()){
                    f=false;
                    break;
                }
                if(st.top()=='['){
                    st.pop();
                }else{
                    f=false;
                    break;
                }
            }
        }
        if(!st.empty()){
            f=false;
        }
        if(f){
            cout<<"yes"<<endl;
        }else{
            cout<<"no"<<endl;
        }
    }
    return 0;
}


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

#define H 500000

void maxHeapify(int *,int);
void buildMaxHeap(int *);

int h;
int main(){
  int i;
  int A[H+1];
  
  scanf("%d",&h);

  for(i=1;i<h+1;i++){
    scanf("%d",&A[i]);
  }

  buildMaxHeap(A);  

  for(i=1;i<h+1;i++){
    printf(" %d",A[i]);
  }
  printf("\n");

  return 0;
}
void maxHeapify(int *A,int i){
  int l,r,largest,tmp;
  l = 2*i;
  r = 2*i+1;
  if(l<=h && A[l] > A[i]){
    largest = l;
  }
  else{
    largest = i;
  }

  if(r<= h && A[r] > A[largest]){
    largest = r;
  }

  if(largest != i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(A,largest);
  }
}

void buildMaxHeap(int *A){
  int i;
  for(i=h/2;i>=1;i--){
    maxHeapify(A,i);
  }
}



Measured memory_bytes: 3696
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

k = inp()

runrun = [["1","2","3","4","5","6","7","8","9"]]
runrun_int = []

for j in range(2,11):
    tmp = []
    for i in range(len(runrun[j - 2])):
        if runrun[j-2][i][j-2] == "0":
            tmp.append(runrun[j-2][i] + str(int(runrun[j-2][i][j-2])))
            tmp.append(runrun[j-2][i] + str(int(runrun[j-2][i][j-2]) + 1))
        elif runrun[j-2][i][j-2] in ["1","2","3","4","5","6","7","8"]:
            tmp.append(runrun[j-2][i] + str(int(runrun[j-2][i][j-2]) - 1))
            tmp.append(runrun[j-2][i] + str(int(runrun[j-2][i][j-2])))
            tmp.append(runrun[j-2][i] + str(int(runrun[j-2][i][j-2]) + 1))
        elif runrun[j-2][i][j-2] == "9":
            tmp.append(runrun[j-2][i] + str(int(runrun[j-2][i][j-2]) - 1))
            tmp.append(runrun[j-2][i] + str(int(runrun[j-2][i][j-2])))
    runrun.append(tmp)

ans = []
for i in range(len(runrun)):
    for j in range(len(runrun[i])):
        ans.append(int(runrun[i][j]))
ans.sort()

print(ans[k - 1])

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

ll dp[110][2][4]; // 桁、N未満フラグ、出現する0以外の個数

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

    string s;
    int K;
    cin >> s >> K;

    rep(i,110){
        rep(j,2){
            rep(k,4) dp[i][j][k] = 0;
        }
    }
    dp[0][0][0] = 1;
    int n = s.size();
    for(int i = 0; i < n; i++){
        int D = s[i] - '0';
        for(int j = 0; j < 2; j++){
            for(int k = 0; k < 4; k++){
                for(int d = 0; d <= (j ? 9 : D); d++){
                    if(d != 0){
                        if(k + 1 > K) continue;
                        dp[i+1][j || (d < D)][k+1] += dp[i][j][k];
                    } else {
                        dp[i+1][j || (d < D)][k] += dp[i][j][k];
                    }
                }
            }
        }
    }
    cout << dp[n][1][K] + dp[n][0][K] << endl;
}



Measured memory_bytes: 256
N, Y = map(int, input().split())

ans = [-1, -1, -1]
findit = False
sen = 0
for man in range(N + 1):
    for gosen in range(N + 1):
        sen = N - man - gosen
        if (man * 10000) + (gosen * 5000) + (sen * 1000) == Y and 0 <= sen:
            ans = [man, gosen, sen]

str_ans = map(str, ans)
print(" ".join(str_ans))

Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, A, B);
  rep(i, 9, 1500) {
    int a = i * .08;
    int b = i * .1;
    if (a == A && b == B) {
      print(i);
      return;
    }
    if (a > A || b > B) {
      print(-1);
      return;
    }
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a,b;

    scanf("%d %d", &a, &b);

    if(a < b){
        printf("a < b\n");
    }else if (a > b){
        printf("a > b\n");
    }else if(a == b){
        printf("a == b\n");
    }

    return 0;
}


Measured memory_bytes: 2124
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n; i++)
#define P pair<ll, ll>
typedef long long ll;
const ll mod = 1e9+7;

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

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  int k;
  cin >> k;
  int eve = 0;
  int odd = 0;
  REP(i, k+1){
    if(i % 2 == 0) eve++;
    else odd++;
  }
  int ans = eve * odd;
  cout << ans<< endl;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

string S;
int main() {
  cin >> S;
  int n = S.length();
  int one = 0, zero=0;
  rep(i,n) if (S[i] == '0') zero++; else one++;
  cout << 2 * min(one, zero) << endl;
  return 0;
}

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

#include <tuple>
#include <string>
#include <vector> 
#include <set>
//https://atcoder.jp/contests/abc073/tasks/abc073_c
int cnt_digits(ll n){

    int digits =0;
    while(n > 0){

        digits++;
        n /= 10;

    }
    return digits;
}

//最大公約数
ll gcd(ll a,ll b){
    if(b ==0) return a;
    else return gcd(b ,a % b);
}

//最小公倍数
ll lcm(ll a,ll b){
  ll g = gcd(a,b);
  return (a / g) * b;
}

int main() {
    
    int n;
    cin >> n;
    set<int> a;

    for(int i=0;i <n;i++){
        bool exist = false;
        int t;
        cin >>t;
        if(i == 0){
            a.insert(t);
            continue;
        }
        
        auto p = a.find(t);
        //発見
        if(p != a.end()){
            a.erase(p);
        }else{
            a.insert(t);
        }

    }

    int ans = a.size();

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

Measured memory_bytes: 4864
#include<stdio.h>

int main(void){
    
    int S, h, m, s;
    int t;
    
    scanf("%d", &S);
    
    h = S / 3600;
    t = h;
    m = (S % 3600) / 60;
    s = ((S % 3600) % 60);
    
    printf("%d:%d:%d\n", h, m, s);
    
    return 0;
    
}


Measured memory_bytes: 2044
a = list(map(int, input().split()))
if a[0] == 0 or a[1] ==1:
  print(0)
else:
  if a[0]%a[1] > a[1]/2:
    print(a[1] - a[0]%a[1])
  else:
    print(a[0]%a[1])

Measured memory_bytes: 3060
def f(x)
	k = 0
	k += x / 500
	x %= 500
	k += x / 100
	x %= 100
	k += x / 50
	x %= 50
	k + x / 10
end
	
ans = []
loop {
	price = gets.to_i
	break if price == 0
	a, b, c, d = gets.split.map &:to_i
	min = Float::INFINITY
	min_by = nil
	(0..a).each{|x|
	(0..b).each{|y|
	(0..c).each{|z|
	(0..d).each{|w|
		total = 10*x+50*y+100*z+500*w
		next if total < price
		net = f(total - price) - (x + y + z + w)
		if net < min
			min = net
			min_by = [x, y, z, w]
		end
	}
	}
	}
	}
	tmp = %w(10 50 100 500)
	ans << (0..3).map{|i| min_by[i] > 0 ? "#{tmp[i]} #{min_by[i]}\n" : nil}.compact.join
}

puts ans.join("\n")

Measured memory_bytes: 6188
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
using namespace std;
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<ll> a(n), diffA(n);
  for(int i=0;i<n;i++) {
    cin >> a[i];
    diffA[i] = a[i] - (i + 1);
  }

  sort(diffA.begin(), diffA.end());
  ll diffMedian = n%2==0 ? ((diffA[n/2] + diffA[n/2-1]) / 2) : diffA[n/2];

  ll ans = 0;
  for(int i=0;i<n;i++) {
    ans += abs(a[i] - (diffMedian + i+1));
  }

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


Measured memory_bytes: 3328
import math

A, B, H, M = map(int, input().split())
A_rad = H/12*360 + ((M/60)*(360/12))
B_rad = M/60*360
rad = abs(A_rad - B_rad)
if rad >= 180:
    rad = 360 - rad

cosAB = round(math.cos(math.radians(rad)), 13)
C = ((A**2 + B**2) - 2*A*B*cosAB)**0.5
print(C)

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

int N;
vector<int> A;
int all;
int ans;

void solve() {
  for (int i = 0; i <= N; ++i) {
    all += abs(A[i] - A[i + 1]);
  }
  for (int i = 1; i <= N; ++i) {
    ans = all - (abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1])) + abs(A[i - 1] - A[i + 1]);
    cout << ans << endl;
  }
}

int main() {
  cin >> N;
  A.resize(N + 2);
  A[0] = 0;
  A[N + 1] = 0;
  for (int i = 1; i <= N; ++i) {
    cin >> A[i];
  }
  solve();
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    ll y[x];
    ll sum=1;
    for (int i=0; i<x; i++)
    {
        cin>>y[i];
    }
    sort(y,y+x);
    if (y[0]==0){
        cout<<0<<endl;
        return 0;
    }
    for (int i=0; i<x; i++)
    {
        ll m=(ll)(1e18);
        if (m/sum<y[i]){
           cout<<-1<<endl;
            return 0;
        }
        else
        {
            sum*=y[i];
        }
    }
    cout<<(sum>1e18?-1:sum)<<endl;
    return 0;
}

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

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L

#define long long long int

using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> b(n - 1);
    for (int i = 0; i < n - 1; i++) cin >> b[i];
    long s = b[0] + b[n - 2];
    for (int i = 1; i < n - 1; i++) {
        s += min(b[i - 1], b[i]);
    }
    cout << s;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int res=0;
    int c=0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='R')
        {
            c++;
            res=max(res,c);
        }
        else
        {
            c=0;
        }
        
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
#define rep1(i,N) for(int i=1;i<=(int)N;i++)
#define pb push_back
#define chmax(x,y) x=max(x,y)
using namespace std;
int main(){
	string s;
	cin>>s;
	vector<int> vc;
	rep(d,10){
		int sum=0;
		rep(i,12){
			int x=d;
			if(s[i]!='?') x=s[i]-'0';
			if(i==11){
				int p=11-sum%11;
				if(p>=10) p=0;
				if(p==x) vc.pb(d);
			}
			int n=11-i;
			if(1<=n&&n<=6) sum+=(n+1)*x;
			if(7<=n&&n<=11) sum+=(n-5)*x;
		}
	}
	if(vc.size()>1){
		puts("MULTIPLE");
		return 0;
	}
	cout<<vc[0]<<endl;
}

Measured memory_bytes: 3196
/**
 *    author:  math2do
 *    created: 18.01.2020 12:32:36
**/

#include <bits/stdc++.h>

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "1" : "0");
}
string to_string(const char &ch) {
  return string(1, ch);
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  reverse(res.begin(), res.end());
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

//..import matrix, queue, stack
template <typename T> 
string to_string(vector <vector<T>> &mat) {
  string res = "";
  char temp[32];
  int n = mat.size();
  if (n == 0) return res;
  res += "\n";
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < (int) mat[i].size(); j++) {
      sprintf(temp, "%15s", to_string(mat[i][j]).c_str());
      res += string(temp);
    }
    res += "\n";
  }
  return res;
}


void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  #ifdef LOCAL
    freopen("D_knapsack.in", "rt", stdin);
  #endif
  int n, W;
  cin >> n >> W;
  vector <int> w(n), v(n);
  for (int i = 0; i < n; i++) {
    cin >> w[i] >> v[i];
  }
  vector <long long> dp(W + 1, 0);
   
  for (int i = 0; i < n; i++) {
    for (int j = W - w[i]; j >= 0; j--) {
      dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
    } 
  } 

  long long ans = 0;
  for (int i = 0; i <= W; i++) {  
    ans = max(ans, dp[i]);
  } 
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

void saiki(int n,vector<int> v){
    if(n == 0){
	cout << v[1];
	FOR(i,2,v.size()){
	    cout << " " << v[i];
	}
	cout << endl;
	return ;
    }
    RFOR(i,1,n+1){
	if(v[v.size()-1] < i) continue;
	v.PB(i);
	saiki(n-i,v);
	v.erase(v.begin() + v.size() - 1);
    }
}

int main(){
    while(true){
	int n;
	cin >> n;
	if(n==0) break;
	vector<int> v(1,10000000);
	saiki(n,v);
    }
    return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<int> a1(n);
  vint a2(n);
  int  x;
  rep(i,n){
    cin>>a1[i];
  }
  rep(i,n){
    cin>>a2[i];
  }
  int max=0;
  rep(i,n){
    int count=0;
    rep(j,i+1){
      count+=a1[j];
    }
    REP(j,i,n){
      count+=a2[j];
    }
    chmax(max,count);
  }
  cout<<max<<'\n';
  return(0);
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val nk = readLine()!!.split(' ')
    val n = nk[0].toInt()
    val k = nk[1].toLong()
    
    val a = readLine()!!.split(' ').map { it.toInt()-1 }
    val plan = IntArray(n+1){-1}
    val visited = IntArray(n){-1}
    var now = 0
    var loopEnd = n
    var loopHead = 0
    for (i in 0 .. n) {
        if (visited[now] == -1) {
            plan[i] = a[now]
            visited[now] = i
            now = a[now]
        } else {
            loopEnd = i
            loopHead = visited[now]
            break
        }
    }

    val tail = k - loopHead.toLong()
    if (tail >= 0) {
        var m = (tail % (loopEnd - loopHead).toLong()).toInt()
        if (m == 0) m = loopEnd - loopHead
        println(plan[loopHead + m -1] + 1)
    } else {
        println(plan[k.toInt() -1] + 1)
    }

}


Measured memory_bytes: 64604
/*
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

int main()
{
    int r, d;
    int x[20];
    std::cin >> r >> d >> x[0];

    for(int i= 1; i<=10;i++){
        x[i] = x[i-1] * r -d;
        std::cout << x[i] << std::endl;
    }

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;

#define X first
#define Y second


const int N=2e5+10;

int dist;
ll p10[30],cov[30];
map <ll,ll> ma[2];


int main(){
    p10[0]=1;
    for(int i=1;i<20;i++) p10[i]=p10[i-1]*10;
    cin>>dist;
    ll ans=0;
    for(int n=2;n<=19;n++){
        for(int i=0;i<=1;i++) ma[i].clear();
        cov[n/2]=0;
        for(int i=n/2-1;i>=0;i--) cov[i]=cov[i+1]+8*(p10[n-i-1]-p10[i]);
        ma[1][0]=1;
        int cur=0;
        for(int p1=0;n-p1-1>=p1;p1++){
//            cout<<p1<<'\n';
            ma[cur].clear();
            int last=cur^1;
            for(auto i:ma[last]){
//                if (n==3) cout<<p1<<" "<<i.X<<" "<<i.Y<<'\n';
                for(int cd=-9;cd<=9;cd++){
                    if (p1==n-p1-1&&cd!=0) continue;
                    ll nway=i.Y*(10-abs(cd)-(p1==0));
                    ll nsum=i.X+cd*(p10[n-p1-1]-p10[p1]);
                    if (nsum+cov[p1]<dist||nsum-cov[p1]>dist) continue;
                    ma[cur][nsum]+=nway;
                }
            }
            cur^=1;
        }
//        cout<<n<<" "<<ans<<'\n';
        ans+=ma[cur^1][dist];
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   string s;
   cin >> s;
   int n = s.size();
   string t = "ACGT";

   int cnt, ans;
   cnt = ans = 0;
   rep(i, 0, n) {
      bool fg = false;
      for (int j = 0; j < 4; j++)
         if (s[i] == t[j]) fg = true;
      if (fg) {
         cnt++;
         chmax(ans, cnt);
      } else {
         cnt = 0;
      }
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
def resolve():
	n, k = map(int, input().split())
	a = list(map(int, input().split()))
	rec = [True]*(n+2)
	now = 0
	stp = [1]

	while rec[now]:
		rec[now] = False
		now = a[now] - 1
		stp.append(now+1)
	before_loop = stp.index(now+1)
	loop = stp[before_loop:-1]
	if k <= (before_loop):
		print(stp[k])
	else:
		r = (k - before_loop) % len(loop)
		print(loop[r])
resolve()

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x) ((int) x.size())
#define all(x) (x).begin(), (x).end()
#define re return
#define mp make_pair
#define makeunique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define endl '\n'

typedef pair<int, int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<string> vs;

template <class T> T abs (T x) { re x > 0 ? x : -x; }
template <class T> T sqr (T x) { re x * x; }

const double pi = acos(-1.);
const int mod = 1e9 + 7;
const int N = 3e5 + 17;

int n, m;

vs s[10];
void prepare (int x, int p, vi a = {}) {
	if (!x) {
		string cur = "";
		for (auto i: a) cur += char('0' + i);
		s[p].pb(cur);
		re;
	}
	for (int i = 1; i <= x; i++) {
		vi na = a;
		na.pb(i);
		prepare(x - i, p, na);
	}
}

int to[N][10];
int gt[N][10];
int link[N], pr[N];
int pc[N], ok[N];
int cnt = 1;

ll dp[50][N];

void add(const string& s) {
	int cur = 0;
	for (auto x : s) {
		int p = (int) (x - '0');
		if (to[cur][p] == -1) {
			to[cur][p] = cnt++;
			gt[cur][p] = cnt - 1;
			pr[cnt - 1] = cur;
			pc[cnt - 1] = p;
		}
		cur = to[cur][p];
	}
	ok[cur] = 1;
}

int go(int v, int c) {
	if (gt[v][c] != -1) re gt[v][c];
	if (!v) re 0;
	re gt[v][c] = go(link[v], c);
}

void make() {
	queue<int> q;
	q.push(0);
	while (!q.empty()) {
		int best = q.front();
		q.pop();
		if (best && pr[best]) 
			link[best] = go(link[pr[best]], pc[best]); 
		ok[best] |= ok[link[best]];
		for (int i = 0; i < 10; i++)
			if (to[best][i] != -1) 
				q.push(to[best][i]);
	}
}

ll power(ll x, ll y) {
	ll ans = 1;
	while (y) {
		if (y & 1) ans = ans * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	re ans;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int a, b, c;
	cin >> n >> a >> b >> c;
	for (int i = 1; i < 8; i++) {
		prepare(i, i);
	}
	memset(gt, -1, sizeof(gt));
	memset(to, -1, sizeof(to));
	memset(dp, -1, sizeof(dp));
	for (auto i: s[a])
		for (auto j: s[b])
			for (auto k: s[c])
				add(i + j + k);		
	make();
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < cnt; j++)
			if (dp[i][j] >= 0) {
			 	for (int k = 0; k < 10; k++) {
			 	 	auto t = go(j, k);
			 	 	if (!ok[t]) {
			 	 		if (dp[i + 1][t] < 0) dp[i + 1][t] = 0;
			 	 		dp[i + 1][t] = (dp[i + 1][t] + dp[i][j]) % mod;
			 	 	}
			 	}
			}
	}
	ll ans = 0;
	for (int i = 0; i < cnt; i++)
		if (dp[n][i] >= 0) ans += dp[n][i];
	cout << (power(10, n) + mod - ans % mod) % mod;
}


Measured memory_bytes: 144852
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

char a[111];
bool bio[111][111];

int c;
int n, m;
  
void dfs(int x, int y) {
  if (bio[x][y]) return;
  bio[x][y] = true;
  c++;
  dfs(n-x-1, y);
  dfs(x, m-y-1);
}

int main(void) {
  vector<int> cnt(26, 0);
  scanf("%d %d", &n, &m);
  REP(i, n) {
    scanf("%s", a);
    REP(j, m) cnt[a[j]-'a']++;
  }

  vector<int> v;
  REP(i, n) REP(j, m)
    if (!bio[i][j]) {
      c = 0;
      dfs(i, j);
      v.push_back(c);
    }

  sort(v.begin(), v.end(), greater<int>());
  for (int x: v) {
    sort(cnt.begin(), cnt.end());
    if (cnt.back() < x) {
      puts("No");
      return 0;
    }
    cnt.back() -= x;
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 256
N, M, x, y = map(int, input().split())

X_list = list(map(int, input().split()))
Y_list = list(map(int, input().split()))

for z in range(x + 1, y + 1):
    if max(X_list) < z <= min(Y_list):
        print('No War')
        exit()
print('War')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

constexpr ll MOD = 1000000007;

int main()
{
    ll N, K;
    cin >> N >> K;

    vector<ll> A, B;

    rep (i, N)
    {
        ll x;
        cin >> x;

        if (x >= 0) { A.emplace_back(x); }
        else        { B.emplace_back(abs(x)); }
    }

    sort(A.begin(), A.end(), greater<ll>());
    sort(B.begin(), B.end(), greater<ll>());

    const ll AN = A.size();
    const ll BN = B.size();

    ll ai = 0, bi = 0;

    // 絶対値的に大きくなる方を順番に取る
    while (ai + bi < K)
    {
        if (AN <= ai) { ++bi; continue; }
        if (BN <= bi) { ++ai; continue; }

        if (A[ai] >= B[bi]) { ++ai; } else { ++bi; }
    }

    // 負数になる場合は帳尻を合わせる
    if (bi&1)
    {
        // 負数を捨てて正数を取る場合
        const bool canA = bi != 0 && ai != AN;    // 可能かどうか
        const auto a1 = ai != AN ? A[ai]     : 0; // 取る
        const auto b1 = bi != 0  ? B[bi - 1] : 0; // 捨てる

        // さらに負数を取る場合
        const bool canB = ai != 0 && bi != BN;    // 可能かどうか
        const auto a2 = ai != 0  ? A[ai - 1] : 0; // 捨てる
        const auto b2 = bi != BN ? B[bi]     : 0; // 取る

        if (canA && canB)
        {
            if (a1 * a2 >= b1 * b2)
            {
                ++ai;
                --bi;
            }
            else
            {
                --ai;
                ++bi;
            }
        }
        else if (canA)
        {
            ++ai;
            --bi;
        }
        else if (canB)
        {
            --ai;
            ++bi;
        }
    }

    // 帳尻を合わせても負数になる場合は最小の値を選ぶ
    if (bi&1)
    {
        ai = 0;
        bi = 0;

        reverse(A.begin(), A.end());
        reverse(B.begin(), B.end());

        while (ai + bi < K)
        {
            if (AN <= ai) { ++bi; continue; }
            if (BN <= bi) { ++ai; continue; }

            if (A[ai] < B[bi]) { ++ai; } else { ++bi; }
        }
    }

    ll ans = 1LL;
    rep (i, ai) { ans *= A[i]; ans %= MOD; }
    rep (i, bi) { ans *= B[i]; ans %= MOD; }

    if (bi&1)
    {
        ans *= -1;
        while (ans < 0) { ans += MOD; }
    }

    cout << (ans % MOD) << endl;

    return 0;
}


Measured memory_bytes: 5564
using System;

public class a
{
	public static void Main()
    {
        for(int i=1; i<=9; ++i)
        {
            for(int j=1; j<=9; ++j)
            {
                Console.WriteLine("{0}x{1}={2}", i, j, i*j);
            }
        }
    }
}

Measured memory_bytes: 8792
#include <stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s)
{
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}
template <class T>
inline string toString(T x)
{
	ostringstream sout;
	sout << x;
	return sout.str();
}

//math
//-------------------------------------------
template <class T>
inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

//repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
					  << " " << __FILE__ << endl;

int main(void)
{
  int N;
  VI a;
  int sum=0;
  cin >> N;
  REP(i,N){
	int v;cin >>v;
	a.PB(v);
	sum+=v;
  }
  SORT(a);
  if(sum % 10 != 0){
	  cout << sum << endl;
	  return 0;
  }
  REP(i,N){
	  if(a[i]%10 != 0){
		  sum -= a[i];
		  cout << sum << endl;
		  return 0;
	  }
  }
  cout << 0 << endl;
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,p;
  char op = '+';
  while (1){
    scanf("%d %c %d",&a,&op,&b);
    if (op == '+'){
      p = a+b;
    }else if (op == '-'){
      p = a-b;
    }else if (op == '*'){
      p = a*b;
    }else if (op == '/'){
      p = a/b;
    }else if (op == '?'){
      break;
    }
    printf("%d\n",p);
  }
  return 0;
}



Measured memory_bytes: 2740
#include <stdio.h>

int main(void){
  int h, w;
  scanf("%d%d", &h, &w);
  char s[101][101];
  
  for(int i = 0; i < h; i++){
    scanf("%s", s[i]);
  }
  
  for(int i = 0; i < h; i++){
    printf("%s\n%s\n", s[i], s[i]);
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Test | diff Test.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Test.cpp && ./a.out

/*
 
 4/26/2020
 
 14:19-
 
 */

const int MAX_N=500+1;
int A[MAX_N][MAX_N],D[31][31];
int N,C;

void solve() {
  VV<int> X(3);
  REP(i,N)REP(j,N) {
    X[(i+j)%3].push_back(--A[i][j]);
  }
  VV<int> cost(3,VI(C));
  REP(c,C)REP(i,3) {
    int sum=0;
    FORR(x,X[i]) sum+=D[x][c];
    cost[i][c]=sum;
  }
  
  int res=1e9;
  REP(c1,C)REP(c2,C)if(c1!=c2)REP(c3,C)if(c2!=c3&&c3!=c1) {
    int sum=cost[0][c1]+cost[1][c2]+cost[2][c3];
    SMIN(res,sum);
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>C;
  REP(i,C)REP(j,C) cin>>D[i][j];
  REP(i,N)REP(j,N) cin>>A[i][j];
  solve();
  
  return 0;
}


Measured memory_bytes: 2544
a, b, c = map(int, input().split())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    divisors.sort()
    return divisors

array_ab = [i for i in range(a, b + 1)]
array_c = make_divisors(c)
count = 0

for i in array_ab:
    if i in array_c:
        count += 1

print(count)


Measured memory_bytes: 5992