akhauriyash/Code-Regression huggingface dataset:
// E - Simple String Queries

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

// RSQを処理するためのセグメントツリー
class SegmentTreeRSQ {
private:
	vector<ll> nodes;
	ll N; // 葉の数
	ll I = 0; // 単位元

	// 親ノードのインデックスを返す
	ll parent(ll k) {
		return (k - 1) / 2;
	}

	// 左の子のインデックスを返す
	ll left_child(ll k) {
		return (k * 2) + 1;
	}

	// 右の子のインデックスを返す
	ll right_child(ll k) {
		return (k * 2) + 2;
	}

public:
	// 要素数nを処理するセグメントツリーを作成
	// 葉の数はn以上の最小の2冪数、単位元で初期化
	SegmentTreeRSQ(ll n) {
		N = 2;
		while (N < n) N *= 2; // 葉の数を計算
		nodes = vector<ll>(N + (N - 1), I); // 葉以外のノードはN-1個
	}

	// 葉[i]（iは0始まり）にxを加える
	void add(ll i, ll x) {
		ll k = i + N - 1; // 葉[i]のノード番号
		nodes[k] += x;
		while (k > 0) {
			// ノード k の親ノードの番号に変える
			k = parent(k);

			// 左右の子の和を計算しなおす
			nodes[k] = nodes[left_child(k)] + nodes[right_child(k)];
		}
	}

	// [a, b) の区間に対するクエリについて
	// ノード k （区間 [l, r) 担当）が答える
	ll query(ll a, ll b, ll k, ll l, ll r) {
		if (r <= a || b <= l) return I; // 区間が被らない場合は I を返す
		if (a <= l && r <= b) {
			// ノード k の担当範囲がクエリ区間 [a, b)に完全に含まれる
			return nodes[k];
		} else {
			ll c1 = query(a, b, left_child(k), l, (l + r) / 2); // 左の子に値を聞く
			ll c2 = query(a, b, right_child(k), (l + r) / 2, r); // 右の子に値を聞く
			return c1 + c2; // 左右の子の値の和を返す
		}
	}

	// [a, b) の区間に対するクエリについて
	// ノード 0 （全区間担当）が答える
	ll query(ll a, ll b) {
		return query(a, b, 0, 0, N);
	}

	//  for debug
	void print_nodes() {
		int e = 0;
		int d = 1;
		for (ll i=0; i<nodes.size(); i++) {
			cout << nodes[i] << " ";
			if (i == e) {
				cout << endl;
				e += pow(2, d);
				d++;
			}
		}
		cout << endl;
	}
};

int main() {
	int N, Q;
	string S;
	cin >> N >> S >> Q;

	map<char, SegmentTreeRSQ*> st_list;

	for (char ch='a'; ch<='z'; ch++) {
		st_list[ch] = new SegmentTreeRSQ(N);
	}

	for (int i=0; i<S.size(); i++) {
		st_list[S[i]]->add(i, 1);
	}

	char c;
	int t, i, l, r;
	vector<int> ans;
	for (int k=0; k<Q; k++) {
		cin >> t;
		if (t == 1) {
			cin >> i >> c;
			i--;
			for (char ch='a'; ch<='z'; ch++) {
				int t = st_list[ch]->query(i, i+1);
				if (t > 0) st_list[ch]->add(i, -t);
				//cout << "***" << ch << "***" << endl; // **** debug ****
				//st_list[ch]->print_nodes(); // **** debug ****
			}
			st_list[c]->add(i, 1);
		}

		if (t == 2) {
			cin >> l >> r;
			l--;
			int cnt = 0;
			for (char ch='a'; ch<='z'; ch++) {
				if (st_list[ch]->query(l, r) > 0) cnt++;
			}
			ans.push_back(cnt);
		}
	}

	for (int a : ans) {
		cout << a << endl;
	}

	return 0;
}

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


int enzan(int a, int b, int i) {
	if (i == 1) {
		return a - b;
	}
	else {
		return a + b;
	}
}

int main() {
	int a, b, c, d;
	int s;
	scanf("%d", &s);
	a = s/1000;
  s%=1000;
	b = s/100;
  s%=100;
	c= s/10;
  s%=10;
	d= s;

	for (int i = 0; i <= 1; i++) {
		for (int j = 0; j <= 1; j++) {
			for (int k = 0; k <= 1; k++) {
				if (enzan(enzan(enzan(a, b, i), c, j), d, k)==7) {
					printf("%d",a);
					if (i == 1) { printf("-"); }
					else { printf("+"); }
					printf("%d",b);
					if (j == 1) { printf("-"); }
					else { printf("+"); }
					printf("%d",c);
					if (k == 1) { printf("-"); }
					else { printf("+"); }
					printf("%d=7",d);
                  return 0;
				}
			}
		}
	}
}

Measured memory_bytes: 128
import bisect,copy,heapq,itertools,string
from collections import *
from math import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
x = LIST()
y = sorted(x)

b0 = y[n//2-1]
b1 = y[n//2]
for a in x:
  if a<=b0:
    print(b1)
  else:
    print(b0)

Measured memory_bytes: 33560
#include <iostream>
using namespace std;
int main(){
	int A;
	int B;
	int C;
	cin >> A;
	cin >> B;
	cin >> C;
	if (A*C <= B){
		cout << C << "\n";
	}else if (A*C >= B){
		cout << B/A << "\n";
	}
	return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.Math;

public class Main {
    public static void main(String[] args) {
        FS reader = new FS();
        // write reader
        int N = reader.nextInt();;
        int[] H = new int[N];
        for (int i=0; i<N; i++) {
            H[i] = reader.nextInt();
        }
        int max = 0;
        int ans = 0;
        for (int i=0; i<N; i++) {
            if (max <= H[i]) ans++;
            max = Math.max(max, H[i]);
        }
        System.out.println(ans);
    }
    
    public static void solver() {
        // write logic
    }
    
    // Read Class
    static class FS {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
    
        private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
        private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
        private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public int nextInt() {
            return (int)nextLong();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if(b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
    }
}



Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
} 


int main(){
    ll n,k;cin >> n >>k;
    ll ok=0,ng=INF;
    vl v(n);rep(i,n)cin >> v[i];
    while(ng-ok>1){
        ll mid=(ok+ng)/2;
        ll j=0;
        //cout << mid <<endl;
        rep(i,n){
            j+=(v[i]+mid-1)/mid-1;
            //cout << j <<endl;
        }
        //cout << endl;
        if(k>=j)ng=mid;
        else ok=mid;
    }
    cout << ng <<endl;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

typedef long long ll;

using namespace std;
int main()
{
    int N;
    cin >> N;
    ll a[N];
    REP(i, N)
    {
        cin >> a[i];
    }
    
    map<ll, bool> isExit;
    int ans = 0;
    REP(i, N)
    {
        auto itr = isExit.find(a[i]);
        if (itr != isExit.end())
        {
            if (itr->second)
            {
                ans--;
                itr->second = false;
            }
            else
            {
                ans++;
                itr->second = true;
            }
        }
        else
        {
            isExit[a[i]] = true;
            ans++;
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 7296
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_map>
# include <unordered_set>
# include <thread>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ui32 = unsigned int;
constexpr ll INFLL = 1e18;

#define CHECK_IMPL1(cond)              \
if (!(cond)) {                         \
    DEBUG("expected cond: " << #cond); \
    assert(cond);                      \
}

#define CHECK_IMPL2(cond, message)                                            \
if (!(cond)) {                                                                \
    DEBUG("expected cond: " << #cond << " failed with message: " << message); \
    assert(cond);                                                             \
}
#define CHECK_IMPL(_1, _2, NAME, ...) NAME
#define CHECK(...) CHECK_IMPL(__VA_ARGS__, CHECK_IMPL2, CHECK_IMPL1, CHECK_IMPL0)(__VA_ARGS__)

#ifdef __APPLE__
#define DEBUG(message) std::cerr << message << std::endl;
#else
#define DEBUG(message)
#endif

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> d;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    d[a[i]] = 1;
  }
  int cnt = 0;
  for (auto& x : d) {
    x.second = cnt;
    ++cnt;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 != d[a[i]] % 2) {
      ++ans;
    }
  }
  cout << ans / 2 << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifdef __APPLE__
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 5376
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		double res = 0;
		
		for(int i = 1; i <= n; i++) {
			int temp = i;
			int cnt = 0;
			
			while(temp < k) {
				temp+=temp;
				cnt++;
			}
			res += 1d/n * Math.pow(1d/2d, cnt);
		}
		
		out.println(res);
	}

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

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 21332
#include<stdio.h>
int main(void)
{
	int n,h[101],m[100],f[99],x,i,j,flg;
	while(1){
		flg=0;
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n+1;i++){
			scanf("%d",&h[i]);
		}
		for(i=0;i<n+1;i++){
			for(j=0;j<n;j++){
				if(i<=j){
					m[j]=h[j+1];
				}
				else{
					m[j]=h[j];
				}
			}
			for(j=0;j<n-1;j++){
				f[j]=m[j+1]-m[j];
			}
			for(j=0;j<n-2;j++){
				if(f[j]!=f[j+1]){
					flg=0;
					break;
				}
				if(f[j]==f[j+1]){
					flg=1;
				}
			}
			if(flg==1){
				x=h[i];
				i=1000;
			}
		}
		printf("%d\n",x);
	}
	return 0;
}

Measured memory_bytes: 1028
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(s: str):
    l, r = -1, -1
    for i, c in enumerate(s):
        if c == 'A' and l < 0:
            l = i
        if c == 'Z':
            r = i
    ret = r - l + 1
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3520
//====== begin of bisma c++ template===========
#include<bits/stdc++.h>
#include <assert.h>
using namespace std;
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define ll long long 
#define sum(a,b) a=a+b
#define mem(a, b) memset(a, (b), sizeof(a))
#define MEM(a, b) memset(a, (b), sizeof(a))


//=======binarysearch===========
int bsr(vector<int>&a,int que){
 auto it=lower_bound(a.begin(),a.end(),que);
 if(*it==que){
    return it-a.begin();
 }
 return -1;
}
//========binarysearch=========



//=======SUBSET WITH BRUTEFORCE=============
void subsets(int S[], int n) {
     int nSub = 1<<n; 
     for(int i=0; i<nSub; i++){
     	  cout<<"{ ";//optional
          for(int k=0; k<n; k++){
               //if the k-th bit is set
               if( (1<<k) & i){
                    cout<<S[k]<<" ";
               } 
          }
          cout<<"}\n"; //optional
     }
}
//======SUBSET WITH BRUTE FORCE================


//======permuatate all ==================
void permutate(){
int n,x;
cin>>n;

vector<int> permutation;
for (int i = 0; i < n; i++) {
	cin>>x;
permutation.push_back(x);
}
do {
 rep(i,0,n-1) cout<<permutation[i];
 cout<<endl;
} while (next_permutation(permutation.begin(),permutation.end()));

}
//====permuatate all======================



//======= the end of bisma c++ template ============



int main() {

int a,b,x;
cin>>a>>b>>x;

if(a>x){
	cout<<"NO";
	return 0;
}

if(x<=a+b){

	cout<<"YES";

}else{
	cout<<"NO";
}



return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <typeinfo>
#include <math.h>
#include <iomanip>
#include <limits>

using namespace std;
using ll = long long;
const ll res = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
	int n;
	cin >> n;
	int cnt = 1;
	vector<string> s(n);

	rep(i, n) cin >> s[i];
	sort(s.begin(), s.end());

	for (int i = 0; i < n - 1; i++) {
		if (s[i] != s[i + 1])cnt++;
	}
	
	cout << cnt << endl;
}

Measured memory_bytes: 9452
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9+1;

int main(){
    int n,m,l;
    cin>>n>>m>>l;
    int d[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            d[i][j]=INF;
        }
        d[i][i]=0;
    }
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        if(c>l)continue;
        d[a-1][b-1]=d[b-1][a-1]=c;
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    int ans[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            ans[i][j]=-1;
        }
        ans[i][i]=0;
        queue<pair<int,int>> q;
        q.push({i,0});
        while(q.size()){
            int v=q.front().first;
            int num=q.front().second;
            q.pop();
            for(int j=0;j<n;j++){
                if(ans[i][j]==-1&&d[v][j]<=l){
                    ans[i][j]=num+1;
                    q.push({j,num+1});
                }
            }
        }
    }
    int q;
    cin>>q;
    for(int i=0;i<q;i++){
        int s,t;
        cin>>s>>t;
        if(ans[s-1][t-1]==-1)cout<<-1<<endl;
        else cout<<ans[s-1][t-1]-1<<endl;
    }
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main()
{
    int n;
    scanf("%d", &n);
    vector<long double> p(n + 1);
    vector<vector<long double>> dp(n + 1, vector<long double>(n + 1, 0));
    for (int i = 1; i <= n; i++) scanf("%Lf", &p[i]);
    // dp[0][1] = 1;
    // dp[1][0] = 1 - p[1];
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) dp[i][0] = (1 - p[i]) * dp[i - 1][0];
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n; j++){
            dp[i][j] = p[i] * dp[i - 1][j - 1] + (1 - p[i]) * dp[i - 1][j];
        }
    }
    long double ans = 0;
    for (int i = n - (n / 2); i <= n; i++){
        ans += dp[n][i];
    }
    // for (int i = 1; i <= n; i++){
    //     for (int j = 0; j <= n; j++){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    printf("%.10Lf", ans);
    return 0;
}

Measured memory_bytes: 144140
n = int(input())

INF = 10**9 + 7

s = [0] * (n+1)

for i in range(1, n+1):
    ni = i
    p = 2
    while ni > 1:
        while ni % p == 0:
            ni //= p
            s[p] += 1
        p += 1

ans = 1
for i in s:
    ans *= i+1

print(ans % INF)

Measured memory_bytes: 3064
s = input()
n = len(s)
a = "10" * (n // 2) + "1" * (n % 2)
b = "01" * (n // 2) + "0" * (n % 2)

print(min(bin(int(s,2) ^ int(a, 2)).count("1") , bin(int(s, 2) ^ int(b, 2)).count("1")))

Measured memory_bytes: 3444
#!/usr/bin/env python3

def solve(n,a):
    ans = 0
    tallest = 0
    for i in range(n):
        if a[i] >= tallest:
            tallest = a[i]
        else:
            ans += abs(a[i] - tallest)
    return ans


def main():
    N = int(input())
    a = list(map(int,input().split()))
    print(solve(N,a),end="")
    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 32268
{-
ITP1_6-A

Time Limit : 1 sec, Memory Limit : 65536 KB
??°???????????¢

?????????????????°???????????????????????????????????°?????????????????????????????????
Input

??\????????\????????¢?????§?????????????????????

n
a1 a2 . . . an

n ?????°????????????????????????ai ??? i ???????????°?????¨????????????
Output

???????????°?????????????????????????????????????????°??????????´??????????????????????????????\?????????????????????????????°????????????????????\??????????????¨?????¨????????????????????????
Constraints

n ??? 100 ??¨????????????5
1 2 3 4 5


Sample Input 1

5
1 2 3 4 5

Sample Output 1

5 4 3 2 1

Sample Input 2

8
3 3 4 4 5 8 7 9

Sample Output 2

9 7 8 5 4 4 3 3

-}
import Data.List.Split
import Data.List

main = do
  s <- getLine
  t <- getLine
  putStrLn $ aux t

aux :: String -> String
aux s = intercalate " "  $ reverse f
  where f=splitOn " " s

Measured memory_bytes: 3636
import bisect

S = input()
T = input()

#dict型 各アルファベットのインデックスを登録
alp = {} #{str:list[int,int,~~],:,:}
for i,s in enumerate(S):
    alp.setdefault(s,[]).append(i)
# print(alp)


bef_idx = -1
ans = 0
for t in T:
    # print(t)
    if t not in alp:
        ans = -(bef_idx+2)
        break

    idx_list = alp[t]
    #bef_idxより右にtが無ければ次の連結
    #bef_idxは一番最後に足す
    if idx_list[-1] <= bef_idx:
        ans += len(S)
        bef_idx = -1
    idx = bisect.bisect_left(idx_list,bef_idx+1)
    bef_idx = idx_list[idx]
    # print(bef_idx,idx)
    # print(ans)
ans += (bef_idx+1)
print(ans)

Measured memory_bytes: 7668
while (True):
    n, x = map(int, input().split())
    if (n == 0 and x == 0):
        break
    c = 0
    li = [i for i in range(1, n + 1)]
    for i in range(len(li)):
        for j in range(i, len(li)):
            for k in range(j, len(li)):
                if (li[i] + li[j] + li[k] == x and len(set([li[i] , li[j] , li[k]])) == 3):
                    c += 1

    print(c)


Measured memory_bytes: 5608
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> p_ii;



int main() {
	
	int i, j, k, n; cin >> n;
	vector<vector<ll>> a(n, vector<ll>(n));
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < i; j++) {
			for (k = 0; k < n; k++) {
				if (i == k || j == k)continue;
				if (a[i][k] + a[k][j] < a[i][j]) {
					cout << -1 << endl;
					return 0;
				}
			}
		}
	}

	ll ans = 0;
	for (i = 0; i < n; i++) {
		for (j = 0; j < i; j++) {
			for (k = 0; k < n; k++) {
				if (i == k || j == k)continue;
				if (a[i][k] + a[k][j] == a[i][j]) {
					ans -= a[i][j];
					break;
				}
			}
			ans += a[i][j];
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
import kotlin.*
import kotlin.math.max

fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val n = sc.nextInt()
        val x = sc.nextInt()
        val a = sc.intArray()

        var ans = 0L
        for (i in 1 until n) {
            if (a[i - 1] + a[i] > x) {
                val diff= a[i-1] + a[i] - x
                ans += diff.toLong()
                a[i] = max(0, a[i] - diff)
            }
        }

        println(ans)
    }
}

class MyScanner {
    private var ptr = 0
    private var l = listOf<String>()

    fun next(): String {
        if (ptr >= l.size) {
            var s: String
            do {
                s = readLine()!!
            } while (s.isEmpty())
            l = s.split(' ')
            ptr = 0
        }
        return l[ptr++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun list(): List<String> {
        ptr = l.size
        val s = readLine()!!
        return if (s.isEmpty()) listOf() else s.split(' ')
    }

    fun intList() = list().map { s -> s.toInt() }
    fun longList() = list().map { s -> s.toLong() }
    fun doubleList() = list().map { s -> s.toDouble() }

    fun array() = list().toTypedArray()
    fun intArray() = intList().toIntArray()
    fun longArray() = longList().toLongArray()
    fun doubleArray() = doubleList().toDoubleArray()
}


Measured memory_bytes: 52532
#include <iostream>
#include <vector>
#include <string>
#include <cassert>

using namespace std;
typedef long long ll;

void write_mode( ll x, ll y){
    bool is_even = (abs(x) + abs(y)) % 2 == 0;
    if(is_even){
        cout << 'L';
        x += 1;
    }
    for(int i = 30; i >= 0; --i){
        ll d = 1LL << i;
        if(x > 0 && abs(x) > abs(y)){
            cout << 'R';
            x -= d;
        }else if(x < 0 && abs(x) > abs(y)){
            cout << 'L';
            x += d;
        }else if(y > 0 && abs(x) < abs(y)){
            cout << 'U';
            y -= d;
        }else{
            cout << 'D';
            y += d;
        }
    }
    assert(x == 0 && y == 0);
    cout << endl;
}

int main(){
    ll n;
    cin >> n;
    vector<pair<ll, ll>> p(n);
    for(int i = 0; i < n; ++i){
        cin >> p.at(i).first;
        cin >> p.at(i).second;
    }

    for(auto xy : p){
        if((abs(p.at(0).first) + abs(p.at(0).second)) % 2 !=
           (abs(xy.first) + abs(xy.second)) % 2){
            cout << -1 << endl;
            return 0;
        }
    }

    bool is_even = ((abs(p.at(0).first) + abs(p.at(0).second)) % 2 == 0);
    cout << 31 + is_even << endl;
    if(is_even){
        cout << 1 << ' ';
    }
    for(int i = 30; i >= 0; --i){
        cout << (1LL << i);
        if(i != 0){
            cout << ' ';
        }else{
            cout << endl;
        }
    }

    for(auto xy : p){
        write_mode(xy.first, xy.second);
    }

    return 0;
}


Measured memory_bytes: 256
let readCharArray _ = stdin.ReadLine().ToCharArray()

let readPicture n =
    [| 1 .. n |]
    |> Array.map (fun _ -> () |> readCharArray |> Array.indexed)
    |> Array.indexed
    |> Array.collect (fun (r, arr) -> arr |> Array.map (fun (c, ch) -> ((r, c), ch)))
    |> Map.ofArray

let readIntArray _ =
    stdin.ReadLine().Split(" ") |> Array.map int

let rec solve n m (row, col) template query =
    let isMatch =
        query
        |> Map.forall (fun (a, b) v -> template |> Map.find (a + row, b + col) |> (=) v)

    if isMatch then "Yes"
    elif n > m + col then solve n m (row, col + 1) template query
    elif n > m + row then solve n m (row + 1, 0) template query
    else "No"



()
|> readIntArray
|> fun [| n; m |] ->
    let t = n |> readPicture
    let q = m |> readPicture
    solve n m (0, 0) t q
|> printfn "%s"


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

int main (){
  int n,m;
  int a[10000];
  int sum = 0;
  int ans = -1;
  cin >> n >> m;

  for(int i = 0; i < m; i++){
      cin >> a[i];
      sum += a[i];
  }
  
  if(n-sum >= 0){
    ans = n - sum;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

string s[555];

string r1[555];
string r2[555];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	for (int i=0;i<n;i++){
		cin>>s[i];
	}
	for (int i=0;i<n;i++){
		for (int ii=0;ii<m;ii++){
			r1[i]+='.';
			r2[i]+='.';
		}
		for (int ii=0;ii<m;ii++){
			if (s[i][ii]=='#'){
				r1[i][ii]='#';
				r2[i][ii]='#';
			}
			else{
				if (i==0) r1[i][ii]='#';
				else if(i==n-1) r2[i][ii]='#';
				else {
					if (ii%2==0) r1[i][ii]='#';
					else r2[i][ii]='#';
				}
			}
		}
	}
	for (int i=0;i<n;i++){
		cout<<r1[i]<<'\n';
	}
	cout<<'\n';
	for (int i=0;i<n;i++){
		cout<<r2[i]<<'\n';
	}
}

Measured memory_bytes: 1536
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def find_mountain_rain_amount(N, A):
    for i in range(N):
        A[i] = A[i] * 2

    offset = 0
    for i in range(N):
        offset = A[i] - offset

    x = offset // 2

    cur = x
    ans = []
    for i in range(N):
        ans.append(cur)
        cur = A[i] - cur

    return ans


def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = find_mountain_rain_amount(N, A)
    for num in ans:
        print(num, end=" ")


main()



Measured memory_bytes: 14092
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, a, N) for(int i = a; i < N; i++)

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

    typedef pair<int, int> P;
    vector<P> A(N);
    rep(i, 0, N) scanf("%d %d", &A[i].first, &A[i].second);

    sort(A.begin(), A.end());
    int cnt = 0;
    ll ans = 0;
    rep(i, 0, N) {
        rep(j, 1, A[i].second + 1) {
            cnt++;
            ans += A[i].first;
            if (cnt == M) {
                cout << ans << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 1024
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <tuple>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}

template <class T>
T clampMax(const T& a, const T& b) { return min(a, b); }

template <class T>
T clampMin(const T& a, const T& b) { return max(a, b); }

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

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

#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int main()
{
    int N;
    string S;
    cin >> N >> S;
    vector<LL> cnts(26);
    cnts.assign(26, 0);
    for (char c : S)
    {
        ++cnts[c - 'a'];
    }
    LL ans = 1;
    for (LL cnt : cnts)
    {
        if (cnt > 0)
        {
            ans = (ans * (cnt + 1)) % MOD;
        }
    }
    cout << ans - 1 << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <stack>
#include <bitset>
#include <set>
#include <chrono>
#include <string>
#include <assert.h>

using namespace std;

#define endl '\n'

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

    int n; cin >> n;

    vector<vector<int>> mat(n, vector<int>(n));

    int t = 0;

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < i; ++j) {
            mat[i][j] = mat[j][i] = t++;
        }

    vector<vector<int>> adj(t);
    vector<int> deg(t);

    for (int i = 0; i < n; ++i) {
        int l; cin >> l; l--;

        for (int j = 0; j < n - 2; ++j) {
            int u; cin >> u;
            u--;
            adj[mat[i][l]].push_back(mat[i][u]);
            deg[mat[i][u]]++;
            l = u;
        }
    }

    vector<int> dp(t);

    vector<int> q;

    for (int i = 0; i < t; ++i) {
        if (deg[i] == 0) {
            q.push_back(i);
            dp[i] = 1;
        }
    }
    int ans = 0;

    for (int i = 0; i < q.size(); ++i) {
        int u = q[i];
        ans = max(ans, dp[u]);

        for (auto v : adj[u]) {
            if (--deg[v] == 0) {
                dp[v] = max(dp[v], dp[u] + 1);
                q.push_back(v);
            }
        }
    }

    if (q.size() == t) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 37624
/*
 *
 *    I am o0o0oo00.
 *
 */
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll          long long
#define p7          1000000007
#define p9          998244353
#define pb          push_back
#define ff          first
#define ss          second
#define vll         vector<ll>
#define pll         pair<ll,ll>
#define vpll        vector<pll>
#define mll         map<ll,ll>
#define test        ll T;cin>>T;while(T--)
#define ad(a,n)     vll a;a.resize(n);for(ll i=0;i<n;i++)cin>>a[i];
#define as(a,n)     for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<endl;
#define all(x)      x.begin(),x.end()

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll powm(ll x, ll y, ll m = p7) {
    x = x % m; ll res = 1; while (y)
    {if (y & 1)res = res * x; res %= m; y = y >> 1; x = x * x; x %= m;} return res;
}
ll modi(ll a, ll m = p7) {return powm(a, m - 2, m);}
void yesno(bool f) {f ? cout << "YES" << endl : cout << "NO" << endl;}


void ss99()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

ll a[22][22];
ll dp[22][(1 << 21) + 10];


int32_t main()
{
    ss99();
//    test
    {
        ll n; cin >> n;
        for (ll i = 0; i < n; i++)
            for (ll j = 0; j < n; j++)
                cin >> a[i][j];
        for (ll i = 0; i < n; i++)
        {
            ll x = (1 << i);
            for (ll j = 0; j < n; j++)
            {
                ll y = (1 << j);
                if (a[i][j])
                {
                    dp[i][y] = 1;
                    if (i > 0)
                    {
                        for (ll k = 0; k < (1 << 21); k++)
                        {
                            dp[i][y | k] += dp[i - 1][k];
                            if (i == n - 1)
                                dp[i][y | k] %= p7;
                        }
                    }
                }
            }
        }
        cout << dp[n - 1][(1 << n) - 1] << endl;
    }
    return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> jewel(N);
  for(int i = 0; i < N; i++) {
    cin >> jewel.at(i);
  }
  int ans = 0;
  for(int x = 0; x <= min(N, K); x++) {
    for(int y = 0; y <= min(N, K) - x; y++) {
      int count = 0;
      priority_queue<int, vector<int>, greater<int>> select;
      for(int i = 0; i < x; i++) {
        count += jewel.at(i);
        select.push(jewel.at(i));
      }
      for(int i = 0; i < y; i++) {
        count += jewel.at(N - 1 - i);
        select.push(jewel.at(N - 1 - i));
      }
      for(int i = 0; i < min(K - x - y, x + y); i++) {
        int a = select.top();
        if(a < 0) {
          count -= a;
          select.pop();
        }
        else {
          break;
        }
      }
      if(count > ans) {
        ans = count;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>

int count=0;
int merge(int *A,int left,int mid,int right)
{
	int L[500000],R[500000];
	int n1,n2,i,j,k;
	n1=mid-left;
	n2=right-mid;
	for(i=0;i<n1;i++)
	{
		L[i]=A[left+i];
	}
	for(i=0;i<n2;i++)
	{
		R[i]=A[mid+i];
	}
	L[n1]=999999999;
	R[n2]=999999999;
	i=0;
	j=0;
	for(k=left;k<right;k++)
	{
		if(L[i]<=R[j])
		{
			A[k]=L[i];
			i=i+1;
			count++;
		}
		else
		{
			A[k]=R[j];
			j=j+1;
			count++;
		
		}
	}
}

int mergesort(int *A,int left,int right)
{
	int mid;
	if(left+1<right)
	{
		mid=(left+right)/2;
		mergesort(A,left,mid);
		mergesort(A,mid,right);
		merge(A,left,mid,right);
	}
	else
	{
		return 0;
	}
}

int main()
{
	int n,i;
	int S[500000];
	
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&S[i]);
	}
	mergesort(S,0,n);
	
	for(i=0;i<n-1;i++)
	{
		printf("%d ",S[i]);
	}
	printf("%d\n",S[i]);
	printf("%d\n",count);
	return 0;
}


Measured memory_bytes: 5620
n=int(input())
ac=0
wa=0
tle=0
re=0
for i in range(n):
    s=input()
    if s=="AC":
        ac+=1
    elif s=="WA":
        wa+=1
    elif s=="TLE":
        tle+=1
    else:
        re+=1

print("AC x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tle))
print("RE x "+str(re))

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

using namespace std;
const int N = 100 + 5;

char mat[N][N];

int main(){
    int a, b, cnta = 1, cntb = 1;

    cin >> a >> b;
    for(int i = 0; i < 100; i++)
        for(int j = 0; j < 100; j++)
            if(j < 50) mat[i][j] = '.';
            else mat[i][j] = '#';
            
    for(int i = 0; i < 100 ; i += 2)
        for(int j = 0; j < 48; j += 2){
            if(cntb == b) break;
            mat[i][j] = '#'; cntb++;
    }
    for(int i = 0; i < 100; i += 2)
        for(int j = 51; j < 98; j += 2){
                if(cnta == a) break;
                mat[i][j] = '.'; cnta++;
           
    }
    printf("100 100\n");
    for(int i = 0; i < 100; i++){
        for(int j = 0; j < 100; j++){
            printf("%c", mat[i][j]);
        }
        printf("\n");
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DBG(x) cerr << #x << " = " << x << endl

using namespace std;
typedef long long LL;

const int N = 64;
char buf[N][N];
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
int n, m;
bool in(int x, int y) {
    return x >= 0 && x < n && y >= 0 && y < m;
}
int main(int argc, char **argv) {
    cin >> n >> m;
    for(int i = 0; i < n; ++i) cin >> buf[i];
    for(int i = 0; i < n; ++i) for(int j = 0; j < m; ++j) {
        if(buf[i][j] == '.') {
            int cnt = 0;
            for(int dir = 0; dir < 8; ++dir) {
                int x = i + dx[dir];
                int y = j + dy[dir];
                if(in(x, y) && buf[x][y] == '#') ++cnt;
            }
            buf[i][j] = cnt + '0';
        }
    }
    for(int i = 0; i < n; ++i) cout << buf[i] << endl;
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

long long int power(long long int x, long long int n, long long int M) {
	long long int ret = 1;
	long long int by = x;
	while (n) {
		if (n & 1) {
			ret *= by;
			ret %= M;
		}
		by *= by;
		by %= M;
		n >>= 1;
	}
	return ret;
}

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

	cin >> N;
	vector<long long int>v(N);
	for (auto &i : v)cin >> i;
	long long int ans = 0;
	long long int add = 0;
	vector<long long int>by(N + 1, 1);
	for (int i = 1; i <= N; i++) {
		by[i] = by[i - 1] * i;
		by[i] %= MOD;
	}
	add = by[N - 1];
	for (int i = 1; i < N; i++) {
	//	cout << add << endl;
		ans += (v[i] - v[i - 1])*add;
		ans %= MOD;
		add += by[N - 1] * power(by[i + 1], MOD - 2, MOD) % MOD*by[i]%MOD;
		add %= MOD;
	}
	cout << ans << endl;
//	vector<int>p(N-1);
//	for (int i = 0; i < N - 1; i++) {
//		p[i] = i;
//	}
//	vector<int>sum(N-1);
//	do {
//		auto q = p;
//		q.push_back(N - 1);
//		for (int i = 0; i < N - 1; i++) {
//			sum[i]++;
//			for (int j = i + 1; j < N; j++) {
//				if (q[i] > q[j]) {
//					sum[j]++;
//				}
//				else {
//					break;
//				}
//			}
//		}
//	} while (next_permutation(p.begin(), p.end()));
//	for (auto i : sum)cout << i << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

#define PI  3.14159

using namespace std;

struct E {
	int x;
	int y;
	double theta;
};

bool in_range(double from, double to)
{
	if (from > 0 && to < 0) to += 2 * PI;
	return (to - from) < PI;
}

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

	int n;
	cin >> n;

	vector<E> es;
	FOR_LT(i, 0, n) {
		int x, y; cin >> x >> y;
		if (x != 0 || y != 0) es.push_back({ x, y, atan2(y, x) });
	}

	std::sort(es.begin(), es.end(), [](const auto& lhs, const auto& rhs) {
		return lhs.theta < rhs.theta;
	});

	double ans = 0;
	FOR_LT(i, 0, es.size()) {
		int x = 0;
		int y = 0;

		int j = i;
		while (true) {
			if (hypot(x, y) >= hypot(x + es[j].x, y + es[j].y)) break;

			x += es[j].x;
			y += es[j].y;

			j++;
			if (es.size() <= j) j -= es.size();
			if (j == i) break;
		}

		ans = max(ans, hypot(x, y));
	}

	cout << std::setprecision(30) << ans << endl;

	return 0;
}

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

using namespace std;

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

	int cnt = 0;
	for (int i = 0; i < s.size(); ++i)
	{
		if (s[i] != t[i])
			cnt++;
	}
	cout << cnt;

	return 0;
}


Measured memory_bytes: 3916
import java.util.*

fun main(args:Array<String>) {
    val cubes = readLine()!!
    val stk = Stack<Char>()
    stk.push(cubes[0])
    for(i in (1 until cubes.length)) {
        if(stk.isNotEmpty() && stk.peek() != cubes[i]) {
            stk.pop()
        } else {
            stk.add(cubes[i])
        }
    }
    print(cubes.length - stk.size)
}


Measured memory_bytes: 34340
def is_palindrome(S):
    pal = True
    for i in range(len(S)//2):
            if S[i] != S[len(S)-1-i]:
                pal = False
    return pal
def main():
    S = input()
    l = S[:len(S)//2]
    r = S[len(S)//2+1:]
    if is_palindrome(S) and is_palindrome(l) and is_palindrome(r):
        print("Yes")
    else:
        print("No")
main()

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

int main() {

  while( true ) {

    int cnt[100] = {0};
    int n = 0;
    int in0, in1;

    bool flag = true;

    while( cin >> in0 >> in1 ) {

      flag = false;
      if ( in0 == 0 && in1 == 0 ) {
	int k = 0;
	if ( ( cnt[0] % 2 ) == 0 ) k++;
	if ( ( cnt[1] % 2 ) == 0 ) k++;
	for ( int i = 2; i < n; i++ ) {
	  if ( ( cnt[i] % 2 ) != 0 ) k++;
	}
	if ( k >= 1 ) {
	  cout << "NG" << endl;
	}else {
	  cout << "OK" << endl;
	}
	break;
      }
      cnt[in0-1]++;
      cnt[in1-1]++;
      n = max( n, max( in0, in1 ) );

    }
    if ( flag ) break;

  }

  return 0;

}

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

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

int main(){
  int d[10000];
  int g[10][10];
  int w,h;

  while(cin >> w >> h, w){
    int sy,sx, gy,gx, cy,cx;
    rep(i,h+2)rep(j,w+2)g[i][j] = 1;

    for(int i=1;i<=h;i++)for(int j=1;j<=w;j++){
      cin >> g[i][j];
      if(g[i][j] == 2){ cy=i; cx=j; g[i][j] = 0; }
      if(g[i][j] == 3){ gy=i; gx=j; g[i][j] = 0; }
      if(g[i][j] == 4){ sy=i; sx=j; g[i][j] = 0; }
    }

    int pos = sy*1000 + sx*100 + cy*10 + cx;
    memset(d,-1,sizeof(d));
    d[pos] = 0;
    deque<int> q;
    q.push_back(pos);

    int ans = -1;
    while(q.size()){
      pos = q.front(); q.pop_front();
      cx = pos%10;
      cy = (pos/10)%10;
      sx = (pos/100)%10;
      sy = (pos/1000)%10;

      if(cy == gy && cx == gx){
	ans = d[pos]; break;
      }

      rep(i,4){
	int ny = sy+dir[i], nx = sx+dir[i+1];
	if(g[ny][nx] == 1)continue;
	if(ny==cy && nx==cx){
	  int ncy = cy+dir[i], ncx = cx+dir[i+1];
	  if(g[ncy][ncx] == 1)continue;

	  int npos = ny*1000 + nx*100 + ncy*10 + ncx;
	  if(d[npos]<0){
	    d[npos] = d[pos] + 1;
	    q.push_back(npos);
	  }
	}else{
	  int npos = ny*1000 + nx*100 + cy*10 + cx;
	  if(d[npos]<0){
	    d[npos] = d[pos];
	    q.push_front(npos);
	  }
	}
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1244
#pragma comment(linker,"/stack:16777216")
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define forr(a,n) for(int a=n;a>=1;a--)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define repr(a,n) for(int a=n-1;a>=0;a--)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0x3f,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

string s,t,a;
int dp[3010][3010];
pii pre[3010][3010];
int main(int argc,char** argv){
	cin>>s>>t;
	int n=sz(s),m=sz(t);
	rep(i,n){
		rep(j,m){
			if(s[i]==t[j]){
				int x=dp[i][j+1],y=dp[i+1][j],z=dp[i][j]+1;
				dp[i+1][j+1]=max(x,max(y,z));
				int c=max(x,max(y,z));
				if(x==c){
					pre[i+1][j+1]=mp(i,j+1);
				}
				else if(y==c){
					pre[i+1][j+1]=mp(i+1,j);
				}
				else{
					pre[i+1][j+1]=mp(i,j);
				}
			}
			else{
				int x=dp[i][j+1],y=dp[i+1][j];
				dp[i+1][j+1]=max(x,y);
				int c=max(x,y);
				if(x==c){
					pre[i+1][j+1]=mp(i,j+1);
				}
				else{
					pre[i+1][j+1]=mp(i+1,j);
				}
			}
		}
	}
	/*
	rep(i,n+1){
		rep(j,m+1){
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}
	rep(i,n+1){
		rep(j,m+1){
			cout<<pre[i][j].fi<<" "<<pre[i][j].sc<<" ";
		}
		cout<<endl;
	}
	cout<<dp[n][m]<<endl;
	*/
	pii cur=mp(n,m);
	while(1){
		cur=pre[cur.fi][cur.sc];
		if(s[cur.fi]==t[cur.sc]){
			a+=s[cur.fi];
		}
		if(cur.fi==0||cur.sc==0){
			break;
		}
	}
	reverse(all(a));
	cout<<a;
	return 0;
}

Measured memory_bytes: 106368