akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
using namespace std;

const int N = 2e5 + 10;

char str[N];
int n, k, ans, op[N], sz[N], s[N], s0[N], m;

int fin(int x) {
    int l = 1, r = x, mid, ans = -1;
    while(l <= r) {
        mid = (l + r) >> 1;
        if(s0[x] - s0[mid - 1] <= k) r = (ans = mid) - 1;
        else l = mid + 1;
    }
    return ans;
}

int main() {
    scanf("%d%d%s", &n, &k, str + 1);
    op[0] = -1;
    for(int i = 1; i <= n; i ++) {
        if(op[m] != str[i] - '0') {
            op[++ m] = str[i] - '0';
            sz[m] = 1;
        } else sz[m] ++;
    }
    for(int i = 1; i <= m; i ++) s[i] = s[i - 1] + sz[i];
    for(int i = 1; i <= m; i ++) s0[i] = s0[i - 1] + (op[i] == 0);
    for(int i = 1; i <= m; i ++) {
        int l = fin(i);
        // printf("%d <\n", l);
        ans = max(ans, s[i] - s[l - 1]);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1792
package main

import (
  "fmt"
)

func maxInt(a ...int) int {m := a[0]; for _, x := range a {if x > m {m = x}}; return m}
func minInt(a ...int) int {m := a[0]; for _, x := range a {if x < m {m = x}}; return m}

func main() {
  var n, k int 
  fmt.Scan(&n, &k)
  tot := 0
  for i := 0; i < n; i++ {
    var x int 
    fmt.Scan(&x)
    tot += minInt(x, k-x) * 2
  }
  fmt.Println(tot)
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ld> pairID;
#define FOR(i,n) for(int i=0; i<int(n); i++)
#define FOR1(i,m,n) for(int i=int(m); i<int(n); i++)

ll N, L;
deque<pairID> A;

int main(int argc, char *argv[])
{
    ll t, v;
    ld total_heat;

    scanf("%lld%lld", &N, &L);
    scanf("%lld%lld", &t, &v);
    
    A.push_front(make_pair(v, t));
    total_heat = (ld)v * t;
    printf("%.7f\n", (double)total_heat / L);
    
    FOR1(i,1,N) {
        pairID back;
        ll vol;

        scanf("%lld%lld", &t, &v);
        total_heat += (ld)v * t;
        
        vol = v;
        while (vol > 0) {
            back = A.back();
            A.pop_back();
            vol -= back.first;
            total_heat -= back.first * back.second;
        }
        if (vol != 0) {
            A.push_back(make_pair(-vol, back.second));
            total_heat += -vol * back.second;
        }

        ld heat = v * t;
        vol = v;
        while(A.size() > 0 && heat / vol <= A.front().second) {
            heat += A.front().first * A.front().second;
            vol += A.front().first;
            A.pop_front();
        }
        A.push_front(make_pair(vol, heat / vol));

        printf("%.7f\n", (double)total_heat / L);
    }
    return 0;
}


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


int main() {
  char N;
  cin >> N;
  if(N=='A'){
    cout <<"T";
  }else if (N=='T'){
    cout << "A";
  }else if(N=='C'){
    cout << "G";
  }else{
    cout << "C";
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>


int fstDgt(int n) {
    int nDgt = (int)log10(n);
    return (int)(n/pow(10, nDgt));
}

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


    int cache[9][9];
    // initialize:
    for (int i = 0; i < 9; ++i) {
        for (int j = 0; j < 9; ++j) {
            cache[i][j] = 0;
        }
    }

    int h, t;
    for (int i = 1; i <= n; ++i) {
        h = fstDgt(i);
        t = i % 10;
        if (t == 0) continue;
        cache[h-1][t-1] ++;
    }

    int res = 0;
    for (int i = 0; i < 9; ++i) {
        for (int j = 0; j < 9; ++j) {
            res += cache[i][j] * cache[j][i];
        }
    }
    printf("%d\n", res);
}

Measured memory_bytes: 384
def divide_string(s):
    result = []
    prev, t = '', ''
    for i in range(len(s)):
        t += s[i]
        if prev != t:
            result.append(t)
            prev, t = t, ''
    if t != '':
        if len(result) == 1 or len(result[-2]) == 1:
            result[-1] = result[-1] + t
        else:
            result[-2] = result[-2] + t
    return result


S = input()

print(len(divide_string(S)))


Measured memory_bytes: 8296
N = int(input())
A = list(map(int, input().split()))

ans = [sum(A) - 2 * sum([A[i] for i in range(1, N, 2)])] + [0] * (N - 1)

for i in range(N):
    ans[(i + 1) * 2 % N] = ans[i * 2 % N] + \
        2 * (A[(i * 2 + 1) % N] - A[i * 2 % N])

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


Measured memory_bytes: 19120
import sys
readline = sys.stdin.readline

# 0-indexでやる

D = int(readline())

C = list(map(int,readline().split())) # 満足度の下がりやすさ

last_submit = [-26] * 26

for i in range(D):
  S = list(map(int,readline().split()))
  for j in range(len(S)):
    S[j] = (S[j],j)
  S = sorted(S, key = lambda x:x[0], reverse = True)
  for j in range(len(S)):
    index = S[j][1]
    if i - last_submit[index] < 26:
      continue
    print(index + 1)
    last_submit[index] = i
    break
  else:
    print(S[0][1] + 1)


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

const int nmax = 8;
bool graph[nmax][nmax];

int dfs(int v,int N,bool visited[nmax]){
    bool clear = true;
    for(int i=0;i<N;i++){
        if(!visited[i]){
            clear = false;
        }
    }
    if(clear){
        return 1;
    }
    int ret = 0;
    for(int i=0;i<N;i++){
        if(!graph[v][i])continue;
        if(visited[i])continue;
        visited[i]=true;
        ret += dfs(i,N,visited);
        visited[i]=false;
    }
    return ret;
}

int main(){
    int N,M;
    cin>>N>>M;
    for(int i=0;i<M;i++){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        graph[a][b]=true;
        graph[b][a]=true;
    }
    bool visited[nmax];
    for(int i=0;i<N;i++){
        visited[i]=false;
    }
    visited[0]=true;
    cout<<dfs(0,N,visited)<<endl;
}

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

int main(){
    int64_t N ;
    cin >> N;
    int64_t res = 0;
    for ( int64_t i = 1; i <= N; ++i){
        if ( i % 3 != 0 and i % 5 != 0 )
            res += i;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;
public class Main {

		static void solve() {
			Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();
			int sum = 0;
			int array[] = new int[n];
			for(int i = 0;i<n;i++) {
				array[i] = sc.nextInt();
			}
			for(int i = 0;i<n-1;i++) {
				for(int l =i+1;l<n;l++) {
					sum+= array[l]*array[i];
				}
			}
			System.out.println(sum);
			sc.close();
		}
	
	public static void main(String[] args) {
		solve();

	}

}


Measured memory_bytes: 21716
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args)throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        int i = 1;
        while(true){
            int x = Integer.parseInt(br.readLine());
             if(x == 0){
                 break;
             }
             System.out.println("Case" + " " + i + ":" + " " + x);
             i++;
        }
    }
}

Measured memory_bytes: 31676
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

bool isPrime(int x) {
	if (x < 2)return 0;
	else if (x == 2)return 1;
	if (x % 2 == 0)return 0;
	for (int i = 3; i*i<= x; i+=2)
		if (x%i == 0)return 0;
	return 1;
}

int main() {
	int b = 0;
	for (int a; cin >> a;)
		b += isPrime(a);
	cout << b << endl;
	return 0;
}

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

int main() {
	int n,len,mid,j,c=0;
	char str[100];
	scanf("%d",&n);
	scanf("%s",str);
	len=strlen(str);
	if(n>0) {
		if(n==len) {
			if(n%2==0) {
				mid=n/2;
				for(int i=0,j=mid;i<mid,j<len;i++,j++) {
					if(str[i]==str[j]) {
						continue;
					}
					else {
						c=1;
						break;
					}
				}
			}
		}
	}
	if(n%2!=0) {
		c=1;
	}
	if(c==0) {
		printf("Yes");
	}
	else {
		printf("No");
	}
}

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

const int MAXN = 100+9;
int n;
int F[MAXN][MAXN];
int P[MAXN][MAXN];
int sle[12];
int ans=INT_MIN;

bool check(){
	int re=0;
	for(int i=1;i<=10;i++)
		re+=sle[i];
	return re>0;
}

int calc(){
	int re=0;
	for(int i=1;i<=n;i++){
		int cnt=0;
		for(int j=1;j<=10;j++){
			if(F[i][j]==1 && sle[j]==1)
				cnt++;
		}
		re+=P[i][cnt];
	}
	return re;
}

void DFS(int x){
	if(x==11){
		if(check())
			ans=max(ans,calc());
		return;
	}
	sle[x]=1;
	DFS(x+1);
	sle[x]=0;
	DFS(x+1);
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=10;j++)
			scanf("%d",&F[i][j]);
	for(int i=1;i<=n;i++)
		for(int j=0;j<=10;j++)
			scanf("%d",&P[i][j]);
	DFS(1);
	printf("%d\n",ans);
	return 0;
}

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

int main(){
  long long N;
  string S;
  cin >> N >> S;
  long long count=0; long long R_count=0; long long G_count=0; long long B_count=0;
  for(int i=0;i<N;i++){
    if(S.at(i)=='R'){
      R_count++;
    }
    else if(S.at(i)=='G'){
      G_count++;
    }
    else{
      B_count++;
    }
  }

  if(N%2==0){
    for(int i=1;i<N/2;i++){
      for(int j=0;j<N-2*i;j++){
        if(S.at(j)!=S.at(i+j) && S.at(i+j)!=S.at(2*i+j) && S.at(j)!=S.at(2*i+j)){
          count++;
        }
      }
    }
  }
  else{
    for(int i=1;i<(N+1)/2;i++){
      for(int j=0;j<N-2*i;j++){
        if(S.at(j)!=S.at(i+j) && S.at(i+j)!=S.at(2*i+j) && S.at(j)!=S.at(2*i+j)){
          count++;
        }
      }
    }
  }
  cout << R_count*G_count*B_count-count << endl;
}


Measured memory_bytes: 3612
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());
    if(s < t)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> list = new ArrayList<String>();
		
		while (true){
			String str = br.readLine();
			if ("0 0".equals(str)) break;
			list.add(str);
		}
		int swap = 0 ;
		for (int i = 0 ;i < list.size() ; i++){
			String[] stra = list.get(i).split(" ");
			int a = Integer.parseInt(stra[0]);
			int b = Integer.parseInt(stra[1]);
			if(b < a){
				swap = a ;
				a = b ;
				b = swap;
			}
			System.out.println(a + " " + b);
		}
	}

}

Measured memory_bytes: 25296
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e:t) fill_v(e, v);
}

typedef pair<int, int> P;

class CSwitches {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N, M;
        cin >> N >> M;
        map<int, int> m;
        REP(i, M) {
            int k;
            cin >> k;
            REP(j, k) {
                int s;
                cin >> s;
                s--;
                m[i] |= (1 << s);
            }
        }
        vector<int> p(M);
        REP(i, M) {
            cin >> p[i];
        }

        int res = 0;
        REP(s, 1 << N) {
            map<int, int> cnt;

            REP(i, M) {
                cnt[i] = 0;
                REP(j, N) {
                    if ((s & (1 << j)) == 0) continue;
                    if ((m[i] & (1 << j)) > 0) {
                        cnt[i]++;
                    }
                }
            }

            bool ok = true;
            REP(i, M) {
                if (cnt[i] % 2 != p[i]) {
                    ok = false;
                    break;
                }
            }
            if (ok) res++;
        }
        cout << res << endl;

    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CSwitches solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 888
def main():
    n = int(input())
    s = input()

    if n % 2 == 0:
        if s[:n // 2] == s[n // 2:]:
            ans = "Yes"
        else:
            ans = "No"
    else:
        ans = "No"

    print(ans)


if __name__ == "__main__":
    main()


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

const int MAX_N = 1e5+1;
vector<int> graph[MAX_N], ans;
bool visited[MAX_N];

void dfs(int x) {
    visited[x] = true;
    ans.push_back(x);
    for (int i : graph[x]) {
        if (!visited[i]) {
            dfs(i);
            break;
        }
    }
}

int main() {
    int N, M, a, b;
    cin >> N >> M;
    rep(i, M) {
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    dfs(1);
    reverse(ans.begin(), ans.end());
    ans.pop_back();
    dfs(1);

    cout << ans.size() << endl;
    rep(i, ans.size()) {
        //if (i) cout << " ";
        cout << ans[i] << " ";
    }
    cout << endl;
}

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

using namespace std;

// Header files, namespaces,
// macros as defined above
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>


#define f first
#define s second
#define db long double
#define pb push_back
#define sz(c) (c).size()
#define all(c) (c).begin(),(c).end()

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

const ll mod = 1e9+7;
const int MAX = 4e2+5;
const db eps = 1e-13;

ll memo[MAX][MAX] , v[MAX];


ll dp ( int lo , int hi ) {

    if( hi==lo )
        return 0;

    ll &res = memo[lo][hi];

    if( res != -1 )
        return res;

    res = 1e18;

    for( int i = lo ; i < hi ; i++ ) {

        res = min( ( dp( lo , i ) + dp( i+1 , hi ) ) + (v[i] - v[lo-1]) + (v[hi] - v[i]) , res );

    }

    return res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
    cout<<setprecision(11)<<fixed;
    memset( memo , -1 , sizeof memo );
    int n;cin>>n;
    for( int i = 1; i <= n ; i++ ) {
        cin>>v[i];
        v[i] += v[i-1];

    }

    cout<<dp( 1, n )<<"\n";

}


Measured memory_bytes: 1536
const println = (value) => console.log(value)
const readInt = (input) => parseInt(input, 10)
const readIntList = (input) => input.split(' ').map(n => parseInt(n, 10))
const naturalOrder = (a, b) => {
    if (b == a) return 0
    return (a < b) ? -1 : 1
}

function main(input) {
    const tmp = input.split('\n')
    const n = readInt(tmp[0])
    const aArray = readIntList(tmp[1]).sort(naturalOrder).reverse()

    const alice = aArray.filter((a, index) => index % 2 == 0).reduce((acc, a) => acc + a)
    const bob = aArray.filter((a, index) => index % 2 == 1)
    const ans = (bob.length == 0) ? alice : alice - bob.reduce((acc, a) => acc + a)
    println(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 29468
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
int main()
{
	int N, K;
	scanf("%d%d", &N, &K);
	if (K == 1) {
		printf("0");
	}
	else {
		printf("%d", N - K);
	}
	return 0;
}

Measured memory_bytes: 128
from ctypes import *
import subprocess as sp
from operator import itemgetter
import sys
import os.path

set_code = r"""
#include <set>

std::set<int> s;

void add(int x) {
    s.insert(x);
}

bool find(int x) {
    return s.find(x) != s.end();
}

void remove(int x) {
    s.erase(x);
}

bool empty() {
	return s.empty();
}

int getMin() {
	return *s.begin();
}
"""

class CppSet:
	counter = 0

	def __init__(self):
		lib_name = './hoge{}.so'.format(CppSet.counter)

		if not os.path.exists(lib_name):
			code_file_name = "tmp.cpp"
			with open(code_file_name, "w") as f:
				f.write(set_code)

			CppSet.counter += 1
			sp.Popen(['g++', '-fPIC', '-shared', '-std=c++11', code_file_name, '-o', lib_name]).communicate()

		lib = CDLL(lib_name)
		self.add = getattr(lib, "_Z3addi")
		self.find = CFUNCTYPE(c_bool, c_int)(
						("_Z4findi", lib),
						((1, "x"), )
					)
		self.remove = getattr(lib, "_Z6removei")
		self.empty = CFUNCTYPE(c_bool)(
						("_Z5emptyv", lib),
						()
					)

		self.getMin = CFUNCTYPE(c_int)(
						("_Z6getMinv", lib),
						()
					)

def main():
	N, Q = map(int, sys.stdin.readline().split())
	tmp = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
	stx = [(s - x, 1, x) for s, t, x in tmp] + [(t - x, -1, x) for s, t, x in tmp]
	stx.sort()
	
	D = [int(sys.stdin.readline()) for _ in range(Q)] 
	ans = [-1]*Q

	idx = 0
	stx_len = len(stx)
	se = CppSet()
	for i, d in enumerate(D):
		while idx < stx_len:
			t, com, x = stx[idx]
			if t > d:
				break
			if com == 1:
				se.add(x)
			else:
				se.remove(x)
			idx += 1
		ans[i] = (-1 if se.empty() else se.getMin())

	print(*ans, sep='\n')

if __name__ == "__main__":
	main()


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

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C, long long D){
    long long ta = C/B;
    ta += (C%B==0)? 0 :1;
    long long ao = A/D;
    ao += (A%D==0)? 0 :1;

    if (ta<=ao) printf("Yes\n");
    else printf("No\n");
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    solve(A, B, C, D);
    return 0;
}


Measured memory_bytes: 3760
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		int x = 1000;
		while(true) {
			if(x>=N)break;
			x= x+ 1000;
		}
		System.out.println(x - N);

	}
}


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

using namespace std;

int main() {
	int N, C[50], V[50], ans = 0;
	cin >> N;
	for (int i = 0; i < N; ++i)
		cin >> V[i];
	for (int i = 0; i < N; ++i)
		cin >> C[i];
	for (int i = 0; i < (1 << N); ++i){
		int value_sum = 0;
		int cost_sum = 0;
		for (int j = 0; j < N; ++j)
			if (i & (1 << j)){
				value_sum += V[j];
				cost_sum += C[j];
			}
		ans = max(ans, value_sum - cost_sum);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int cnt[N];
int a[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	vector<LL> v[2];
	v[0].push_back(-INF * 1000000);
	v[0].push_back(-INF * 100000);
	v[1].push_back(-INF * 1000000);
	v[1].push_back(-INF * 100000);
	int n, m;
	cin >> n >> m;
	int q;
	cin >> q;
	for (int i = 1; i <= n; i++)
	{
		LL x;
		cin >> x;
		v[0].push_back(x);
	}
	for (int i = 1; i <= m; i++)
	{
		LL x;
		cin >> x;
		v[1].push_back(x);
	}
	v[0].push_back(INF * 100000);
	v[0].push_back(INF * 1000000);
	v[1].push_back(INF * 100000);
	v[1].push_back(INF * 1000000);
	while (q--)
	{
		LL x;
		cin >> x;
		LL ans = INF * INF;
		for (int o = 0; o < 2; o++)
		{
			auto iter1 = lower_bound(v[o].begin(), v[o].end(), x);
			vector<LL> v1 = { *(iter1 - 1),*iter1 };
			int oo = o ^ 1;
			for (auto& y : v1)
			{
				auto iter2 = lower_bound(v[oo].begin(), v[oo].end(), y);
				vector<LL> v2 = { *(iter2 - 1),*iter2 };
				for (auto& z : v2)
				{
					ans = min(ans, abs(x - y) + abs(y - z));
				}
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
  int A,B,K;
  cin>>A>>B>>K;
  if(A+K-1>=B-K+1){
    for(int i=A;i<=B;i++){
    cout<<i<<endl;
    }
  }
  else{
    for(int i=A;i<=A+K-1;i++){
      cout<<i<<endl;
    }
    for(int i=B-K+1;i<=B;i++){
      cout<<i<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
    using namespace std;
    int x, y, z, qaq, ans;
    int main()
    {
    	cin >> x >> y >> z;
    	qaq = z;
    	while(qaq + y + z <= x){
    		qaq += y + z;
    		ans ++;
    	}
    	cout << ans << endl;
    	return 0;
    }

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

int main()
{
    
    char ss[200000];
    long int len,i,countA=0,countB=0;
    
    scanf("%s",ss);
    len = strlen(ss);
    
    for(i=0;i<len;i++){
        if(ss[i]=='A')break;
        countA++;
    }
    for(i=len-1;i>=0;i--){
        if(ss[i]=='Z')break;
        countB++;
    }

    printf("%ld\n",len-countA-countB);

    return 0;
}

Measured memory_bytes: 384
#!/usr/bin/perl

my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @d = map { $_ - 0 } split(/\s+/,<STDIN>);

my $r = 0;
for(my $i=0;$i<$n-1;$i++){
  for(my $j=$i+1;$j<$n;$j++){
    $r += $d[$i] * $d[$j];
  }
}
print "$r\n";


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
            var min = -1L;
            for (var i = 1; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    var tmp = i + n / i - 2;
                    if (min == -1 || tmp < min) min = tmp;
                }
            }

            Console.WriteLine(min);
        }
    }
}

Measured memory_bytes: 27552
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;
 
class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
  public static void Main()
  {
    var tmp = ReadIntArray();
    int n = tmp[0], ma = tmp[1], mb = tmp[2];
    int[] a = new int[n];
    int[] b = new int[n];
    int[] c = new int[n];
    
    for (int i = 0; i < n; i++)
    {
      tmp = ReadIntArray();
      a[i] = tmp[0]; b[i] = tmp[1]; c[i] = tmp[2];
    }
    
    int nMax = 40, aMax = 10, bMax = 10, cMax = 100;
    int [,,] d = new int[n+1, nMax*aMax+1, nMax*bMax+1];
    
    int inf = 1000000;
    
    for (int i = 0; i <= n; i++){
      for (int j = 0; j <= nMax*aMax; j++){
    	for (int k = 0; k <= nMax*bMax; k++){
          d[i,j,k] = inf;
        }
      }
    }

    d[0,0,0] = 0;
    for (int i = 0; i < n; i++){
      for (int j = 0; j <= nMax*aMax; j++){
    	for (int k = 0; k <= nMax*bMax; k++){
          if(d[i,j,k] == inf) continue;
          d[i+1,j,k] = Math.Min(d[i+1,j,k], d[i,j,k]);
          d[i+1,j+a[i],k+b[i]] = Math.Min(d[i+1,j+a[i],k+b[i]], d[i,j,k]+c[i]);
        }
      }
    }

    int ans = inf;
    for (int i = 1; i <= nMax*aMax; i++){
      for (int j = 1; j <= nMax*bMax; j++){
        if(i*mb == j*ma) ans = Math.Min(ans, d[n,i,j]);
      }
    }
    
    WriteLine(ans < inf ? ans : -1);
  }
}


Measured memory_bytes: 36832
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  int a,b;
  int c;
  cin >> n >> m;
  int N = pow(2,n);
  int dp[N];
  REP(i,N){
    dp[i] = INTINF;
  }
  dp[0] = 0;
  REP(i,m){
    cin >> a >> b;
    int key = 0;
    REP(j,b){
      cin >> c;
      key += pow(2,c-1);
    }
    REP(j,N){
      dp[j] =  min(dp[j&~key]+a,dp[j]);
    }
    //cout << key << endl;
  }
  if (dp[N-1]==INTINF)dp[N-1] = -1;
  cout << dp[N-1] << endl;
}


Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e6+5;
const int mo=998244353;
int n,m,ans,p[N+5],q[N+5];
long long ksm(long long x,int y)
{
	long long t=1;
	for (;y;y>>=1)
	{
		if (y&1) t=t*x%mo;
		x=x*x%mo;
	}
	return t;
}
long long c(int x,int y){return (long long)p[x]*q[y]%mo*q[x-y]%mo;}
int main()
{
	scanf("%d%d",&n,&m);
	p[0]=q[0]=1;
	for (int i=1;i<=n+m;i++) p[i]=(long long)p[i-1]*i%mo;
	q[n+m]=ksm(p[n+m],mo-2);
	for (int i=n+m-1;i;i--) q[i]=(long long)q[i+1]*(i+1)%mo;
	if (n<m) swap(n,m);
	for (int i=1;i<=m;i++) ans=(ans+c(i+i,i)*c(n+m-i-i,n-i))%mo;
	ans=(ans*ksm(2*c(n+m,n)%mo,mo-2)+n)%mo;
	printf("%d",ans);
	return 0;
}



Measured memory_bytes: 7936
n, m  = map(int, input().split())

li = [list(map(int, input().split()))[1:] for _ in range(n)]
ans = 0
for i in range(1, m+1):
    tf = True
    for j in li:
        if i not in j:
            tf = False
            break
    if tf:
        ans += 1

print(ans)

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

import javax.lang.model.util.ElementScanner6;

class Main {
    public static boolean isPrime(int a) {
        for (int i = 2; i <= Math.sqrt(a); i++) {
            if (a % i == 0)
                return false;
        }
        return true;
    }

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        try {
            int n = Integer.parseInt(br.readLine());
            int nums[] = new int[n];
            int max, min;
            for (int i = 0; i < n; i++)
                nums[i] = Integer.parseInt(br.readLine());

            /*
             * for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { if (nums[i] -
             * nums[j] > max) max = nums[i] - nums[j]; } }
             */
            min = nums[0];
            max = -1000000000;
            for (int i = 1; i < n; i++) {
                if (nums[i] - min > max)
                    max = nums[i] - min;
                if (nums[i] < min)
                    min = nums[i];
            }
            System.out.println(max);

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}


Measured memory_bytes: 43348
package main

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

var (
	in = bufio.NewReader(os.Stdin)
)

func readln() string {
	buf := make([]byte, 0)
	for {
		line, prefix, err := in.ReadLine()
		if err != nil {
			panic(err)
		}
		buf = append(buf, line...)
		if prefix == false {
			break
		}
	}
	return string(buf)
}

func strSlice() []string {
	line := strings.Split(readln(), " ")
	return line
}

func intSlice() []int {
	line := strSlice()
	slice := make([]int, 0)
	for _, tmp := range line {
		val, err := strconv.Atoi(tmp)
		if err != nil {
			panic(err)
		}
		slice = append(slice, val)
	}
	return slice
}

func read() (T int, t []int) {
	line := intSlice()
	T = line[1]
	t = intSlice()
	return T, t
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	T, t := read()

	x := uint64(T)
	for i := 0; i < len(t)-1; i++ {
		x += uint64(minInt(T, t[i+1]-t[i]))
	}
	fmt.Println(x)

}


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

int main() {
	int n;
	cin>>n;
	long long arr[n];
	long long cntneg=0;
	long long sum=0;
	long long mini=INT_MAX;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		if(arr[i]<0) cntneg++;
		sum+=abs(arr[i]);
		mini=min(mini,abs(arr[i]));
	}
	if(cntneg%2==0)cout<<sum;
	else cout<<sum - ((2*1LL)* mini);
	return 0;
}

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

int main() {
    int N;  cin >> N;
    vector<int> a(N + 1);
    for (int i = 1; i <= N; ++i) cin >> a[i];
    bool ok = true;
    for (int i = N; i > 0; --i) {
        if (a[i] >= a[i - 1]) continue;
        else if (a[i] < a[i - 1] - 1) ok = false;
        else --a[i - 1];
    }
    cout << (ok ? "Yes" : "No") << endl;
}


Measured memory_bytes: 640
import copy


class Dice:
    def __init__(self, a, b, c, d, e, f):
        self.top = a
        self.front = b
        self.right = c
        self.left = d
        self.behind = e
        self.bottom = f

    def S(self):
        self.top, self.front, self.behind, self.bottom = self.behind, self.top, self.bottom, self.front

    def N(self):
        self.behind, self.top, self.bottom, self.front = self.top, self.front, self.behind, self.bottom

    def E(self):
        self.top, self.bottom, self.left, self.right = self.left, self.right, self.bottom, self.top

    def W(self):
        self.left, self.right, self.bottom, self.top = self.top, self.bottom, self.left, self.right

    def spin(self):
        self.left, self.behind, self.right, self.front = self.front, self.left, self.behind, self.right

    def __eq__(self, _dice2):
        dice2 = copy.deepcopy(_dice2)
        for i in range(4):
            if self._eqaul(dice2):
                return True
            dice2.spin()
        dice2 = copy.deepcopy(_dice2)
        dice2.N()
        dice2.N()
        for i in range(4):
            if self._eqaul(dice2):
                return True
            dice2.spin()
        dice2 = copy.deepcopy(_dice2)
        dice2.N()
        for i in range(4):
            if self._eqaul(dice2):
                return True
            dice2.spin()
        dice2 = copy.deepcopy(_dice2)
        dice2.E()
        for i in range(4):
            if self._eqaul(dice2):
                return True
            dice2.spin()
        dice2 = copy.deepcopy(_dice2)
        dice2.W()
        for i in range(4):
            if self._eqaul(dice2):
                return True
            dice2.spin()
        dice2 = copy.deepcopy(_dice2)
        dice2.S()
        for i in range(4):
            if self._eqaul(dice2):
                return True
            dice2.spin()
        return False

    def _eqaul(self, dice2):
        return self.front == dice2.front and self.behind == dice2.behind and self.left == dice2.left and self.right == dice2.right and self.top == dice2.top and self.bottom == dice2.bottom

    def __repr__(self):
        return ",".join([str(object=i) for i in (self.top, self.front, self.right, self.left, self.behind, self.bottom)])


while True:
    n=int(input())
    if n==0:
        break
    dices=[]
    for i in range(n):
        c=input().split(" ")
        dice=Dice(*c)
        if (dice in dices)==False:
            dices.append(dice)
    print(n-len(dices))



Measured memory_bytes: 6356
#include<bits/stdc++.h>
using namespace std;
#define ll long long;
const int maxn = 1e5+10;
int main(){
	int n;
	int maxn=0;
	int sum=0;
	cin>>n;
	for(int i=0;i<n;i++){
		int t;
		cin>>t;
		sum+=t;
		maxn=max(maxn,t);
	}
	cout<<sum-maxn+(int)(maxn/2)<<endl;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    string a, b;
    cin >> a >> b;
    string ab = a + b;
    int n = stoi(ab);
    int sq = sqrt(n);
    cout << (sq * sq == n ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m,s,t,f;
ll dist[105][105];
ll dist2[105][105];
ll dist3[105][105];
int u[1005],v[1005],a[1005],b[1005],d[1005];

int main(void){
	scanf("%d%d%d%d%d",&n,&m,&s,&t,&f);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			dist[i][j]=1LL<<50;
			dist2[i][j]=1LL<<50;
			dist3[i][j]=1LL<<50;
		}
		dist[i][i]=0;
		dist2[i][i]=0;
		dist3[i][i]=0;
	}
	int d2=-1;
	for(int i=0;i<m;i++){
		scanf("%d%d%d%d%d",&u[i],&v[i],&a[i],&b[i],&d[i]);
		d[i]=min(d[i],f);
		if(a[i]<b[i]){
			d2=d[i];
		}
		ll val=a[i]*f;
		if(f>=d[i]){
			val=a[i]*d[i]+(f-d[i])*b[i];
		}
		dist[u[i]][v[i]]=min(dist[u[i]][v[i]],val);
	}
	if(d2!=-1){
		for(int i=0;i<m;i++){
			ll val=a[i]*d2;
			if(d2>=d[i]){
				val=a[i]*d[i]+(d2-d[i])*b[i];
			}
			dist2[u[i]][v[i]]=min(dist2[u[i]][v[i]],val);
		}
		d2=f-d2;
		for(int i=0;i<m;i++){
			ll val=a[i]*d2;
			if(a[i]<b[i])continue;
			if(d2>=d[i]){
				val=a[i]*d[i]+(d2-d[i])*b[i];
			}
			dist3[u[i]][v[i]]=min(dist3[u[i]][v[i]],val);
		}
	}
	for(int k=0;k<n;k++){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
				dist2[i][j]=min(dist2[i][j],dist2[i][k]+dist2[k][j]);
				dist3[i][j]=min(dist3[i][j],dist3[i][k]+dist3[k][j]);
			}
		}
	}
	ll ans=dist[s][t];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			ans=min(ans,dist2[i][j]+dist[s][i]+dist[j][t]+dist3[i][j]);
		}
	}
	if(ans==(1LL<<50)){
		printf("Impossible\n");
	}else{
		printf("%lld\n",ans);
	}
	return 0;
}


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

using namespace std;

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

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

    vector<int> nums(N);
    rep(i, N) cin >> nums[i];

    int sum = 0;
    rep(i, N) sum += nums[i] - 1;

    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
using db = double;
#define INF 2000000000
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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
  数値型から文字列に変換　to_string(number);これは簡単
  文字列から数値型に変換　stoi(number)
  文字列からllに変換　stoll(number)
  __gcd(a,b)は最大公約数を取ってくれる、aとb
  の大きい方をNとしたとき、計算量は log(N);
 */
const int mod = 1e9 + 7;
// pie = M_PI
//ここから書き始める
int main(){
	cout << setprecision(10);
	int n, a, b, c, d; 
	cin >> n >> a>> b >> c >> d;
	string s ; cin >> s;

		int bjudge = 1;
		int ajudge = 1;
		for(int i = b - 1; i < d ; i ++){
			if(s[i]=='#'&&s[i+1]=='#'){
				bjudge = 0;
			}
		}
		for(int i = a - 1; i < c ; i ++){
			if(s[i]=='#'&&s[i+1]=='#'){
				ajudge = 0;
			}
		}
		if(c<d&&ajudge&&bjudge){
			//cout<<"c<d"<<endl;
			cout << "Yes"<<endl;
			return 0 ;
		}
		else{//d<cのときは、連続して3つの空き地がd（dは含まない)より前にあればYesになれる
			if(c<=b&&ajudge&&bjudge){
				cout<<"Yes"<<endl;
				return 0;
			}
			int null = 0;
			//Bの1個手前から見て3連続で岩じゃなければいい。
			int x = b - 1; //Bの要素番号」
			for(int i = x - 1 ; i <= d - 2 ; i ++){
				if(s[i] == '.'){
					if(s[i+1]=='.'&&s[i+1+1]=='.'){
						null = 1;
					}
				}
			}
			if(ajudge&&bjudge&&null){
				//cout<<"null"<<endl;
				cout << "Yes"<<endl;
				return 0;
			}
		}
		cout << "No"<<endl;
}



Measured memory_bytes: 640
# include <string.h>
# include <iostream>

using namespace std;

int main() {
	int nminus[100000] = {0};
	int N = 0;
	int oscore = 0;
	int round = 0;
	cin >> N >> oscore >> round;
	int temp = -1;
	
	for ( int i = 0 ; i < round ; i++ ) {
		cin >> temp;
		nminus[temp-1]++;
	} // for
	
	for ( int i = 0; i < N ; i++ ) {
		if ( oscore - round + nminus[i] <= 0 ) {
			cout << "No\n";
		} // if
		
		else {
			cout << "Yes\n";
		}
	} // for
}// main

Measured memory_bytes: 1024
#include <iostream>
#include <climits>
#include <vector>
#include <cmath>

using namespace std;
int main() {
	int N, K;
	cin >> N >> K;
	vector<int> h(N);

	for(int i = 0; i < N; i++) {
		int cur;
		cin >> cur;
		h[i] = cur;
	}

	vector<int> cost(N, INT_MAX);
	cost[0] = 0;

	for (int i = 1; i < N; i++) {
		for (int j = 0; j < min(i, K); j++) {
			cost[i] = min(cost[i], cost[i - j - 1] + abs(h[i - j - 1] - h[i]));
		}


	}
	cout << cost[N - 1] << endl;
	return 0;
}


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

public class Main {
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);

	public void run() {
		while (true) {
			int h = in.nextInt(), w = in.nextInt();
			if ((h|w) == 0) break;
			
			int resH = 1000, resW = 1000;
			loop : for (int i = h+1; i <= 150; i++) {
				for (int j = i + 1; j <= 150; j++) {
					if (h*h + w*w == i*i + j*j) {
						resH = i;
						resW = j;
						break loop;
					}
				}
			}
			
			if (resH == 1000 && resW == 1000) {
				for (int i = 1; i <= 150; i++) {
					for (int j = i + 1; j <= 150; j++) {
						if (h*h + w*w < i*i + j*j && i*i + j*j < resH * resH + resW * resW) {
							resH = i;
							resW = j;
						}
					}
				}
			}
			
			System.out.println(resH + " " + resW);
		}
	}

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

	public void debug(Object... obj) {
		System.out.println(Arrays.deepToString(obj));
	}

	class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner(InputStream stream) {
			this.stream = stream;
			//stream = new FileInputStream(new File("dec.in"));

		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

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

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

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}

Measured memory_bytes: 20180
#coding:utf-8

import sys
import copy

def main():
    line = sys.stdin.readline()
    #case
    while line.split() != ["0","0"]:
        analy(line)
        line = sys.stdin.readline()
    return

def analy(line):
    #?°??
    field = [int(n) for n in line.split()]
    # ?£?¢??
    num = int(sys.stdin.readline())
    data = []
    for i in range(num):
        a = sys.stdin.readline()
        b = [int(n) for n in a.split()]
        #?£?¢??
        data.append(b)
    print (compute(field, data))

def compute(field, ng):
    list = []
    for i in range(field[1]):
        for j in range(field[0]):
            #?£¢?????°??°????????
                if i == 0 :
                    #°?????
                    if [j+1,i+1] in ng:
                        list.append(0)
                    elif j == 0:
                        #???¬????
                        list.append(1)
                    else:
                        list.append(list[j-1])
                else:
                    if [j+1,i+1] in ng:
                        list[j] = 0
                    elif j != 0:
                    #no left >> the same.
                        list[j] = list[j-1] + list[j]
    return list[len(list)-1]

if __name__ == "__main__":
    main()

Measured memory_bytes: 4296
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
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;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;

 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
  
 

ll sum(ll n) {
ll m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}




 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  st s;
    ci(s);
  ll k;
    ci(k);
  ll ans=0;
  ll n=s.sz;
  ll count=1;
  ll head=0;
  ll end=0;
  FOR(i,1,n){
    
    if(s[i-1]==s[i]){
      count++;
    }
    
    else if(i==count){
      head=count;
      count=1;
    }
    
    else{
      ans+=count/2*k;
      count=1;
    }
    
    if(i==n-1){
      end=count;
    }  
  }

  if(count==n){
    ans=k*n/2;
  }
  else if(s[0]==s[n-1]){
    ans+=(head+end)/2*(k-1);
    ans+=head/2+end/2;
  }
  else{
    ans+=head/2*k;
    ans+=end/2*k;
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{  vector<int>vc,vc2;
int a,i,cnt=0,j,n,t;
cin>>a;
for(i=0;i<a;i++)
    {  cin>>n;
    vc.push_back(n);
    vc2.push_back(n);
    }
    sort(vc.begin(),vc.end());
    for(i=0;i<a;i++)
    { if(vc[i]!=vc2[i]) cnt++;

    }
     if(cnt>2) cout<<"NO\n";
    else
        cout<<"YES\n";




return 0;
}


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

using namespace std;

int main() {
    long double n, m, d;
    cin >> n >> m >> d;

    cout.setf(ios::fixed);
    cout.precision(10);
    cout << (m - 1) * (1 + (d != 0)) * (n-d) / pow(n, 2) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    cin >> n;
    double ans;
    double x;
    string u;
    for (int i=0;i<n;i++) {
        cin >> x >> u;
        if (u=="BTC") x*=380000.0;
        ans+=x;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <iomanip>

using namespace std;




int main(void)
{
    
    int n,m;
    while(cin>>n>>m){
        int graph[105]={0};
        while(1){
            graph[n]++;
            graph[m]++;
            cin>>n>>m;
            if(n==0&&m==0)break;
        }
        bool flag=true;
        if(graph[1]%2==0||graph[2]%2==0){
            flag=false;
            cout<<"NG"<<endl;
        }
        if(flag){
            for(int i=3; i<105; i++){
                if(graph[i]%2==1){
                    flag=false;
                    cout<<"NG"<<endl;
                    break;
                }
            }
        }
        if(flag){
            cout<<"OK"<<endl;
        }
        
        
    }
    
    
}

Measured memory_bytes: 1156
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		long sum = 0, ans = 0, ans2 = 0;
		// + - + - + ...
		for(int i = 0 ; i < n ; i++) {
			sum += a[i];
			if(i % 2 == 0 && sum <= 0) {
				ans += 1 - sum;
				sum = 1;
			} else if(i % 2 == 1 && sum >= 0) {
				ans += sum + 1;
				sum = -1;
			}
		}
		sum = 0;
		// - + - + - ...
		for(int i = 0 ; i < n ; i++) {
			sum += a[i];
			if(i % 2 == 0 && sum >= 0) {
				ans2 += sum + 1;
				sum = -1;
			} else if(i % 2 == 1 && sum <= 0) {
				ans2 += 1 - sum;
				sum = 1;
			}
		}
		System.out.println(Math.min(ans, ans2));
	}
}


Measured memory_bytes: 50860
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int a,b,c;
        a = input.nextInt();
        b = input.nextInt();
        c = input.nextInt();
        if(a!=b && a!=c && b!=c)
            System.out.println(3);
        else if(a==b && a!=c && b!=c)
            System.out.println(2);
        else if(a!=b && a==c && b!=c)
            System.out.println(2);
        else if(a!=b && a!=c && b==c)
            System.out.println(2);
        else if(a==b && a==c && b==c)
            System.out.println(1);
        
        
    }
    
}


Measured memory_bytes: 26864