akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

  int total = 0;

  if(s[0] == t[0]) {
    total++;
  }
  if(s[1] == t[1]) {
    total++;
  }
  if(s[2] == t[2]) {
    total++;
  }

  cout << total << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

int abs1(int x){
    if(x > 0) return x;
    else return -x;
}

int main(){
    int x, n;
    cin >> x >> n;
    int p[n];
    rep(i, n) cin >> p[i];
    sort(p, p + n);
    int idx = 0;
    int mn = 10000;
    int ans;
    for (int i = 0; i <= 101; i++){
        if(idx < n && p[idx] == i){
            idx++;
            continue;
        }
        if(abs(x - i) < mn){
            ans = i;
            mn = abs(x - i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
var
 a,b,i,ss:longint;
 s:string;
begin
 readln(a,b);
 readln(s);
 for i:=1 to a+b+1 do
  if (i<>a+1) and not (s[i] in ['0'..'9']) then ss:=1;
 if (ss=1) or (s[a+1]<>'-') then writeln('No')
                            else writeln('Yes');
end.

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

S = sum(A)

suma = 0
for i in range(1,N,2):
    suma += A[i]

X1 = S - 2 * suma
ans = [X1]

prev = X1
for i in range(0, N-1):
    nx = 2 * A[i] - prev
    ans.append(nx)
    prev = nx

print(*ans)

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

int K;
int A[100010];
long long inf = 1e15;

bool okmax(long long n){
	for(int i=0;i<K;i++){
		n = (n/A[i])*A[i];
	}
	if(n<=2) return true;
	else return false;
}

bool okmin(long long n){
	for(int i=0;i<K;i++){
		n = (n/A[i])*A[i];
	}
	if(n>=2) return true;
	else return false;
}

int main(){
	cin >> K;
	bool judge = false;
	long long amin,amax;
	for(int i=0;i<K;i++){
		cin >> A[i];
	}
	long long l = 0, r = inf;
	long long m = 0;
	while(l+1<r){
		m = (l+r)/2;
		if(okmax(m)){
			l = m;
			judge = true;
		}
		else r = m;
	}
	amax = l;
	r = inf;
	l = 0;
	/*if(!judge){
		cout << -1 << endl;
		return 0;
	}*/
	while(l+1<r){
		m = (l+r)/2;
		if(okmin(m)) r = m;
		else l = m;
	}
	amin = r;
	if(amin<=amax) cout << amin << " " << amax << endl;
	else cout << -1 << endl;
}

Measured memory_bytes: 640
//============================================================================
// Name        : Hello.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
#include<vector>
#include<tuple>
using namespace std;
int main() {

	int w,h,n;
	cin>>w>>h>>n;

	//vector<vector<int>> field(h, vector<int>(w, 1));
	vector <vector<int>> field(h, vector<int>(w,1));
//	vector<int> g(w,1);
//	vector<vector<int>> field(h,g);
	vector<tuple<int, int, int>> s;

	for(int i=0;i<n;i++){
		int x,y,a;
		cin>>x>>y>>a;

		s.emplace_back(x, y, a);

		for(int yi=0;yi<h;yi++){
			for(int xi=0;xi<w;xi++){
				if(a==1 && xi<x)
					field[yi][xi]=0;

				if(a==2 && xi>=x)
					field[yi][xi]=0;

				if(a==3 && yi<y)
					field[yi][xi]=0;
				if(a==4 && yi>=y)
					field[yi][xi]=0;
			}
		}

	}

	int cnt=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(field[i][j]==1)cnt+=1;
		}
	}


	cout<<cnt<<endl;

//	for(vector<int> v:field){
//		for(int a:v)
//			cout<<a<<" ";
//		cout<<endl;
//	}

//	for(tuple<int, int, int> t:s){
//		int x, y, a;
//		tie(x, y, a)=t;
//		cout<<x<<y<<a<<endl;
//	}

//	vector<int> u;
//
//	for(auto p:u){}  //決まってる場合はautoでもいい
//
//	for(int i=0;i<n;i++){
//		int x=get<0>(s[i]);
//		int y=get<1>(s[i]);
//		int a=get<2>(s[i]);
//		cout<<x<<y<<a<<endl;
//	}


	return 0;
}



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

int main(void)
{
  int a, b, c, d, ab, bc, ca;

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

  ab = abs(a - b);
  bc = abs(b - c);
  ca = abs(c - a);

  if((ab <= d && bc <= d) || ca <= d){
    printf("Yes");
  }
  else{
    printf("No");
  }

  return 0;

}


Measured memory_bytes: 128
var
  a1,a2,a3,b1,b2,b3:char;
begin
  readln(a1,a2,a3);
  readln(b1,b2,b3);
  if a1=b3 then if a2=b2 then if a3=b1 then 
                                         begin
                                           writeln('YES');
                                           exit;
                                         end;
  writeln('NO');
end.

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  string s, t; cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
  cout << (s < t ? "Yes\n" : "No\n");

  return 0;
}



Measured memory_bytes: 3632
#include <stdio.h>

#define MAX 10000
#define NIL -1

struct Node {int p, l, r;};
struct Node T[MAX];
int n;

void preParse(int u) {
  if(u == NIL) return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}
void inParse(int u) {
  if(u == NIL) return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}


void postParse(int u) {
  if(u == NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(void) {
  int i, v, l, r, root;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    T[i].p = NIL;
  }
  
  for(i=0; i<n; i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }
  
  for(i=0;i<n;i++) if(T[i].p == NIL) root = i;
  
  printf("Preorder\n");
  preParse(root);
  printf("\n");

  printf("Inorder\n");
  inParse(root);
  printf("\n");

  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
#include <regex>
using namespace std;

const int N_MAX = 500;
const int C_MAX = 30;
const int INF = 1 << 30;

int main() {
	int N, C;
	int D[C_MAX][C_MAX];
	int grid[N_MAX][N_MAX];
	int costs[C_MAX][3] = { {0} };

	cin >> N >> C;
	for (int i = 0; i < C; i++) {
		for (int j = 0; j < C; j++) {
			cin >> D[i][j];
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> grid[i][j];
		}
	}

	for (int c = 0; c < C; c++) {

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				costs[c][(i + j) % 3] += D[grid[i][j] - 1][c];
			}
		}
	}

	int ans = INF;
	for (int i = 0; i < C; i++) {
		for (int j = 0; j < C; j++) {
			for (int k = 0; k < C; k++) {
				if (i == j || j == k || i == k)continue;
				ans = min(ans, costs[i][0] + costs[j][1] + costs[k][2]);
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1280
B,W = map(int,input().split())
A,V= map(int,input().split())
T = int(input())

def main():
    if V >= W:
        print("NO")
        return
    
    
    elif abs(B-A)/abs(V-W) <= T:
        print("YES")
    else:
        print("NO")
        



main()

Measured memory_bytes: 9172
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
const long long INF = 1LL << 60;


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;
}

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

//約数求める //約数
void divisor(ll n,vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	
}
//階乗
long long factorial(long long n, long long mod) {
	long long ret = 1;
	for (long long i = 1; i <= n; i++) {
		ret = (ret * i) % mod;
	}
	return ret;
}
//モジュラ逆数
long long inv_mod(long long n, long long mod) {
	long long a = n % mod, b = mod - 2, ret = 1;
	while (b > 0) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}

long long nPr(long long n, long long r, long long mod) {
	long long ret = 1;
	for (long long i = n; i >= n - r + 1; i--) {
		ret = ret * (i % mod) % mod;
	}
	return ret;
}

long long nCr(long long n, long long r, long long mod) {
	return nPr(n, r, mod) * inv_mod(factorial(r, mod), mod) % mod;
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {//降順second
	if (a.second != b.second) {
		return a.second > b.second;
	}
	else {
		return a.first > b.first;
	}
}

bool compare_by_a(pair<ll, ll> a, pair<ll, ll> b) {//降順first
	if (a.first != b.first) {
		return a.first > b.first;
	}
	else {
		return a.second > b.second;
	}
}

ll gcd(ll m, ll n){
	if (n == 0)return m;
	return gcd(n, m%n);
}//gcd


int main() {
	ll a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	ll min = INF;
	chmin(min, a*x + b * y);
	
	if (x == y) {
		chmin(min, c*x * 2);
	}
	if (x > y) {
		chmin(min, c*x * 2);
		chmin(min, c*y * 2 + (x - y)*a);
	}
	if (y > x) {
		chmin(min, c*y * 2);
		chmin(min, c*x * 2 + (y - x)*b);
	}
	cout << min;

	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

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

		final int N = scanner.nextInt();
		final int M = scanner.nextInt();
		final int K = scanner.nextInt();

		List<Integer>[] friendLists = new ArrayList[N];
		for (int i = 0; i < N; i++) {
			friendLists[i] = new ArrayList<Integer>();
		}

		int A, B;
		for (int i = 0; i < M; i++) {
			A = scanner.nextInt() - 1;
			B = scanner.nextInt() - 1;
			friendLists[A].add(B);
			friendLists[B].add(A);
		}

		boolean[] visited = new boolean[N];

		int[] root = new int[N];
		int[] size = new int[N];

		for (int i = 0; i < N; i++) {
			if (!visited[i]) {
				DFS(friendLists, i, i, visited, root, size);
			}
		}

		int[] except = new int[N];

		for (int i = 0; i < K; i++) {
			A = scanner.nextInt() - 1;
			B = scanner.nextInt() - 1;
			if (root[A] == root[B]) {
				except[A]++;
				except[B]++;
			}
		}
		for (int i = 0; i < N; i++) {
			System.out.print(size[root[i]] - friendLists[i].size() - except[i] - 1);
			System.out.print(i == N - 1 ? "\n" : " ");
		}

	}

	static int groupSize;

	static void DFS(List<Integer>[] graph, int rep, int vertex, boolean[] visited, int[] root, int[] size) {
		visited[vertex] = true;
		root[vertex] = rep;
		size[rep]++;
		graph[vertex].forEach(neighbor -> {
			if (!visited[neighbor]) {
				DFS(graph, rep, neighbor, visited, root, size);
			}
		});
	}

}


Measured memory_bytes: 144556
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;
int a[N], b[N], f[N], sz[N];
int found(int x) {
    return x==f[x] ? x:(f[x]=found(f[x]));
}
int main() {
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++) f[i] = i, sz[i] = 1;
    for(int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
    }
    ll ans = (ll)n*(n-1)/2;
    vector<ll> res;
    for(int i = m-1; i >= 0; i--) {
        res.push_back(ans);
        int fa = found(a[i]), fb = found(b[i]);
        if(fa != fb) {
            f[fa] = fb;
            ans += 1LL*sz[fa]*(sz[fa]-1)/2;
            ans += 1LL*sz[fb]*(sz[fb]-1)/2;
            sz[fb] += sz[fa];
            ans -= 1LL*sz[fb]*(sz[fb]-1)/2;
            sz[fa] = 0;
        }
    }
    reverse(res.begin(), res.end());
    for(ll x:res) {
        cout << x << '\n';
    }
    return 0;
}

Measured memory_bytes: 5108
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define EACH( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

const double EPS = 1e-9;

struct Point
{
	double x, y;

	Point()
	{
		x = y = 0;

		return;
	}

	Point( double x, double y ) : x( x ), y( y )
	{
		return;
	}

	Point operator - ( const Point &a ) const
	{
		return Point( x - a.x, y - a.y );
	}
};

double dot( const Point &a, const Point &b )
{
	return a.x * b.x + a.y * b.y;
}

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

	Point a, b, c, d;

	while ( cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y >> d.x >> d.y )
	{
		Point ab = b - a;
		Point cd = d - c;

		cout << ( abs( dot( ab, cd ) ) < EPS ? "YES" : "NO" ) << endl;
	}

	return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
vector<int> v[100005];
long long cnt[2];
#define ll int
void dfs(int node,int pnode,int color)
{
    cnt[color]++;
    for (int i=0;i<v[node].size();i++)
    {
        if (v[node][i]!=pnode)
        dfs(v[node][i],node,!color);
    }
}

#define rep(i, c) for(int i = 0; i < (int)c; i++)
 const int inf = 1000000000; 

int main() {
    int N;
     cin >> N;
     vector<int> X(N);
     rep(i, N) cin >> X[i];
     int ans = inf;
     for(int i = 1; i <= 100; i++) {
     int cost = 0;
     rep(j, N) cost += (X[j] - i) * (X[j] - i);
     ans = min(ans, cost);
     }
     cout << ans << endl;
 return 0;
 }


Measured memory_bytes: 2560
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))

edges = []

from collections import deque
def diam_bfs(i):
  que = deque([i])
  dist = {i: 0}
  prev = {i: -1}
  while que:
    u = que.popleft()
    d = dist[u]
    for w in edges[u]:
      if w in dist:
        continue
      dist[w] = d + 1
      prev[w] = u
      que.append(w)
  w = u
  D = []
  while w != -1:
    D.append(w)
    w = prev[w]
  return u, D


def main():
  global edges
  n = int(input())
  edges = [[] for _ in range(n)]
  for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
  _, path = diam_bfs(diam_bfs(0)[0])
  if len(path) % 3 == 2:
    print('Second')
  else:
    print('First')


if __name__ == '__main__':
  main()


Measured memory_bytes: 144488
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000


int main(){

	int N;
	cin>>N;
	
	vector<int> p(N);
	for(int i=0;i<N;i++){
		cin>>p[i];
		p[i]--;
	}
	int ans = 0;
	for(int i=0;i<N;i++){
		if(p[i]==i){
			ans++;
			if(i==0){
				swap(p[i],p[i+1]);
			}
			else if(i==N-1){
				swap(p[i],p[i-1]);
			}
			else{
				swap(p[i],p[i+1]);
			}
		}
	}
	
	cout<<ans<<endl;
		
	
    return 0;
}



Measured memory_bytes: 640
def main():
    alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    n = len(alpha)
    s2i = {}
    i2s = {}
    for i, s in enumerate(alpha):
        s2i[s] = i
        i2s[i] = s

    N = int(input())
    S = input()
    w = ''.join([i2s[(s2i[s] + N) % n] for s in S])
    print(w)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include<stdio.h>
int main(){
    int n;
    int count = 0;
    scanf("%d",&n);
    for(int i = 1;i<= n;i++){
        if(i % 2 != 0){
            count++;
        }
    }
    double ans = (double)count / (double)n;
    printf("%lf",ans);
    return 0; 
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination MOD prime
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < MOD);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n, int k) {
    return fact[n]*ifact[n-k];
  }
} comb(10000007);
// comb(5, 2) → 10, comb.p(5, 2) → 20
// comb.fact[4] → 24, 2のN乗 → mint(2).pow(N)

mint dp[3005];

int main() {
  // ApplePen、dpでそれまでの個数を保持、LとRを含まなくて良いことに注意
  int N, S;
  cin >> N >> S;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  mint ans = 0;
  for (int i = 0; i < N; i++) {
    dp[0] += 1; // iがLの場合
    for (int j = S-A[i]; j >= 0; j--) {
      dp[j+A[i]] += dp[j];
    }
    ans += dp[S];
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 159316
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main(void) {
    string s;
    cin >> s;
    stack<int> k;
    vector<P> a;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == '\\') k.push(i);
        if(s[i] == '/' && !k.empty()) {
            int t = k.top();
            k.pop();
            int sum = 0;
            for(int j = a.size() - 1; j >= 0; j--) {
                if(a[j].first < t) break;
                sum += a[j].second;
                a.pop_back();
            }
            a.push_back(P(t, i - t + sum));
        }
    }
    int ans = 0;
    for(int i = 0; i < a.size(); i++) ans += a[i].second;
    cout << ans << endl << a.size();
    for(int i = 0 ; i < a.size(); i++) cout << ' ' << a[i].second;
    cout << endl;
    return 0;
}


Measured memory_bytes: 3300
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  ll a,b,c=0,g=0;cin>>a;
  vector<ll>d(1000002,0);
    ll l=0; 
  vector<ll>e(a);
  rep(i,a){
    cin>>e[i];
    b=e[i];
        if(d[e[i]]>0){
          d[b]=2;
          continue;
        }
    d[e[i]]=1;
    for(ll o=2;o<1000002;o++){
    if(b*o>=1000002)break;
      d[b*o]++;
    }
  }
  rep(i,a){
    if(d[e[i]]==1)c++;
  }
  cout<<c;
}


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

const int mod = 1000000007;

struct mint
{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint &operator+=(const mint m)
    {
        if((x += m.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator-=(const mint m)
    {
        if((x += mod - m.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator*=(const mint m)
    {
        (x *= m.x) %= mod;
        return *this;
    }
    mint operator+(const mint m) const
    {
        return mint(*this) += m;
    }
    mint operator-(const mint m) const
    {
        return mint(*this) -= m;
    }
    mint operator*(const mint m) const
    {
        return mint(*this) *= m;
    }
    mint pow(ll n) const
    {
        if(!n) return 1;
        mint m = pow(n>>1);
        m *= m;
        if(n & 1) m *= *this;
        return m;
    }
    mint inv() const { return pow(mod-2);}
    mint &operator/=(const mint m) { return *this *= m.inv();}
    mint operator/(const mint m) const { return mint(*this) /= m;}
};
istream &operator>>(istream &is, const mint &m) { return is >> m.x;}
ostream &operator<<(ostream &os, const mint &m) { return os << m.x;}

struct combination
{
    vector<mint> fact, ifact;
    combination(int n) : fact(n+1), ifact(n+1)
    {
        assert(n < mod);
        fact.at(0) = 1;
        for(int i=1; i<=n; i++)
        {
            fact.at(i) = fact.at(i-1) * i;
        }
        ifact.at(n) = fact.at(n).inv();
        for(int i=n; i>=1; i--)
        {
            ifact.at(i-1) = ifact.at(i) * i;
        }
    }
    mint operator()(int n, int k)
    {
        if(k < 0 || k > n) return 0;
        return fact.at(n) * ifact.at(k) * ifact.at(n-k);
    }
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> as(N);
    for(int i=0; i<N; i++) cin >> as.at(i);

    sort(as.begin(), as.end());
    if(N%2)
    {
        bool ok = true;
        int prea = 0;
        if(as[0] != 0) ok = false;
        for(int i=1; i<N-1; i+=2)
        {
            if(prea + 2 != as[i]) ok = false;
            if(as[i] != as[i+1]) ok = false;
            prea = as[i];
        }
        mint ans = 2;
        if(ok) cout << ans.pow(N/2) << '\n';
        else cout << "0\n";
    }
    else
    {
        bool ok = true;
        int prea = -1;
        for(int i=0; i<N-1; i+=2)
        {
            if(prea + 2 != as[i]) ok = false;
            if(as[i] != as[i+1]) ok = false;
            prea = as[i];
        }
        mint ans = 2;
        if(ok) cout << ans.pow(N/2) << '\n';
        else cout << "0\n";
    }
    

    return 0;
}


Measured memory_bytes: 640
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
T = [INT() for i in range(N)]

def many_lcm(l):
    tmp = l[0]
    for i in range(1, len(l)):
        tmp = tmp * l[i]//gcd(tmp, l[i])
    return tmp

m = many_lcm(T)
print(m)

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(int argc, const char * argv[]) {
    // source code
    int64_t a, b;
    cin >> a >> b;
    map<int64_t, int> af = prime_factor(a);
    map<int64_t, int> bf = prime_factor(b);
    int ret = 1;
    for (auto m : af) for (auto n : bf) {
        if (m.first == n.first) ret++;
    }
    cout << ret;
    
    return 0;
}


Measured memory_bytes: 256
import bisect
 
a, b, q = map(int, input().split())
INF = 10 ** 12
S = [-INF] + [int(input()) for i in range(a)] + [INF]
T = [-INF] + [int(input()) for i in range(b)] + [INF]

for i in range(q):
    x = int(input())
    sid = bisect.bisect_left(S, x)
    tid = bisect.bisect_left(T, x)
    ans = INF
    for s in (S[sid - 1], S[sid]):
        for t in (T[tid - 1], T[tid]):
            ans = min(ans, abs(x - s) +abs(s - t))
            ans = min(ans, abs(x - t) + abs(t - s))
    print(ans)

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

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

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

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

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

ll binpow(ll x, ll e) {
  ll ret = 1, p = x;
  while(e > 0) {
    if(e&1) {(ret *= p) %= MOD; e--;}
    else {(p *= p) %= MOD; e /= 2;} 
  }
  return ret;
}

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

    ll n, k;
    cin >> n >> k;

    vector<ll> div;
    for(ll i=1; i*i<=n; ++i) {
        if(n%i == 0) {
            div.push_back(i);
            if(n/i != i) div.push_back(n/i);
        }
    }
    sort(ALL(div));

    ll m = div.size(), ret = 0, inv2 = binpow(2, MOD-2);
    vector<ll> dp(m);
    REP(i, m) {
        // 周期div[i]以下の回文が何通りか
        dp[i] = binpow(k, ceil(div[i], 2LL));
        // div[i]の約数の分を引く
        for(ll j=0; j<i; ++j) {
            if(div[i]%div[j]) continue;
            (dp[i] += MOD - dp[j]) %= MOD;
        }
        if(div[i]%2) (ret += div[i] * dp[i] % MOD) %= MOD;
        else (ret += div[i] * dp[i] % MOD * inv2 % MOD) %= MOD;
    }
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define pb push_back
#define mp make_pair
#define fi(i,start,end) for(int i=start; i < end ; ++i)
#define Fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
//#define mod 1000000007



using namespace std;





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

	int n=s.length()-1;

	if(s[n]=='s')
        cout<<s+"es";
    else
      cout<<s+"s";


	return 0;
}



Measured memory_bytes: 3636
let range start stop =
  let rec loop n acc =
    if n >= start then
      loop (n-1) (n :: acc)
    else
      acc
  in
  loop stop []

let make_full () =
  let suits, nums = range 0 3, range 1 13 in
  List.concat (List.map (fun s -> List.map (fun n -> (s, n)) nums) suits)

let find_all_lose hand full =
  List.filter (fun c -> not (List.mem c hand)) full

let to_str (s, n) = (String.sub "SHCD" s 1) ^ " " ^ (string_of_int n)

let to_tup s =
  Str.split (Str.regexp " ") s |>
  (function | [s; n] -> (String.index "SHCD" s.[0], int_of_string n)
            | _ -> failwith "invalid input")

let rec input_loop () =
  let rec loop n acc = match n with
    | 0 -> acc
    | n -> loop (n-1) ((read_line ()) :: acc)
  in
  let num = int_of_string (read_line ()) in
  loop num []

let () =
  let hand = List.map to_tup (input_loop ()) in
  List.iter print_endline (make_full () |>
                           find_all_lose hand |>
                           List.sort compare |>
                           List.map to_str)

Measured memory_bytes: 2328
import math

data = input().split()
a = float(data[0])
b = float(data[1])
C = math.radians(int(data[2]))

S = a * b * math.sin(C) * 0.5
print(S)
c = math.sqrt((a**2 + b**2 - 2*a*b*math.cos(C)))
print(a + b + c)
print(S/a * 2 )


Measured memory_bytes: 5708
S = str(input())
T = str(input())
s = len(S)
t = len(T)
ans = []
for i in range(s-t+1):
    count = 0
    U = S[i:i+t]
    for j in range(t):
        if U[j] != T[j]:
            count += 1
    ans.append(count)

print (min(ans))

Measured memory_bytes: 8948
import sys

# Set max recursion limit
sys.setrecursionlimit(1000000)


def li_input():
    return [int(_) for _ in input().split()]


def is_exist(A, x):
    l = 0
    r = len(A) - 1

    while l <= r:
        m = (l + r) // 2
        if A[m] == x:
            return True
        
        if A[m] < x:
            l = m + 1
        else:
            r = m - 1

    return False
            


def main():
    n = int(input())
    S = li_input()
    q = int(input())
    T = li_input()

    ans = 0

    for t in T:
        if is_exist(S, t):
            ans += 1

    print(ans)


main()



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

using namespace std;


int main(){
    long N;
    string A,B,C;

    cin>>N>>A>>B>>C;

    long ans=0;
    for(int i=0;i<N;++i){
        if(A[i]==B[i]&&C[i]==A[i]&&B[i]==C[i]){

        }else if(A[i]==B[i]&&C[i]!=A[i]&&B[i]!=C[i]||A[i]!=B[i]&&C[i]!=A[i]&&B[i]==C[i]||A[i]!=B[i]&&C[i]==A[i]&&B[i]!=C[i]){
            ans++;
        }else{
            ans+=2;
        }
    }


    cout<<ans<<endl;



}

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

int main(){
    ll a,b,x; cin >> a >> b >> x;
    cout << (b>0?b/x+1:1) - (a>0?(a-1)/x+1:0) << endl;
}

Measured memory_bytes: 256
import collections,sys
def s():
 d=collections.deque()
 input()
 for e in sys.stdin:
  if'i'==e[0]:d.appendleft(e[7:-1])
  else:
   if' '==e[6]:
    m=e[7:-1]
    if m in d:d.remove(m)
   elif len(e)%2:d.pop()
   else:d.popleft()
 print(*d)
s()


Measured memory_bytes: 69732
k=list(input())
l=k[::]
n=int(input())
for i in range(len(k)):
    if i==0:
        continue
    a,b=k[i-1],k[i]
    if a==b:
        k[i]="0"
l[0]="0"
for i in range(len(l)):
    if i==0:
        continue
    a,b=l[i-1],l[i]
    if a==b:
        l[i]="0"
if k[-1]!=k[0]:
    print(k.count("0")*n)
else:
    if k[0]!=l[-1]:
        print(k.count("0")*(n-n//2)+l.count("0")*(n//2))
    else:
        print(k.count("0")+l.count("0")*(n-1))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#define DIVCEIL(A,B) ((A+(B-1))/B)
#define LL long long
#define INF (LL)(1LL<<60)
using namespace std;


void solve(long long N, long long W, std::vector<long long> w, std::vector<long long> v){
    vector<vector<LL>> vs(4);
    vector<vector<LL>> accs(4);
    auto w1 = w[0];
    for(LL i=0; i<N; i++)vs[w[i]-w1].emplace_back(v[i]);
    for(LL i=0; i<4; i++)sort(vs[i].begin(), vs[i].end(), greater<LL>());
    for(LL i=0; i<4; i++){
        LL acc=0;
        accs[i].emplace_back(0);
        for(auto val: vs[i]){
            acc += val;
            accs[i].emplace_back(acc);
        }
    }
    LL ans=0;
    for(LL i=0; i<accs[0].size(); i++){
        for(LL j=0; j<accs[1].size(); j++){
            for(LL k=0; k<accs[2].size(); k++){
                for(LL l=0; l<accs[3].size(); l++){
                    if(w1*(i+j+k+l)+j+2*k+3*l > W)break;
                    ans = max(ans, accs[0][i]+accs[1][j]+accs[2][k]+accs[3][l]);
                }
            }
        }
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long W;
    scanf("%lld",&W);
    std::vector<long long> w(N);
    std::vector<long long> v(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&w[i]);
        scanf("%lld",&v[i]);
    }
    solve(N, W, std::move(w), std::move(v));
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void)
{
    int n,t1,c,t2,cnt=0, mn=1e9;
    cin >> n >> t1;
    for(int i=1;i<=n;i++)
    {
        cin >> c >> t2;
        if(t1<t2) cnt++;
        else
            if(mn>c)
                mn=c;
    }
    if(cnt==n)
        cout << "TLE";
    else
        cout << mn;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i, x, y) for(int i = x, _b = y; i <= _b; i ++)
#define ff(i, x, y) for(int i = x, _b = y; i <  _b; i ++)
#define fd(i, x, y) for(int i = x, _b = y; i >= _b; i --)
#define ll long long
#define pp printf
#define hh pp("\n")
using namespace std;

const int N = 3e5 + 5;

int w, h, n;

struct P {
	int x, y;
} a[N];

int ans;

int d[N], d0;

map<int, int> rd;

void ls() {
	d0 = 0; d[++ d0] = 0; d[++ d0] = w;
	fo(i, 1, n) d[++ d0] = a[i].x;
	sort(d + 1, d + d0 + 1);
	d0 = unique(d + 1, d + d0 + 1) - (d + 1);
	rd.clear(); fo(i, 1, d0) rd[d[i]] = i;
}

P b[N], c[N]; int b0, c0;

int op;

int cmp1(P a, P b) {
	if(a.x == b.x) {
		if(a.y == b.y) return 0;
		return (a.y < b.y) ^ op;
	}
	return a.x < b.x;
}

void gg(P *a, int &a0) {
	sort(a + 1, a + a0 + 1, cmp1);
	int A = a0; a0 = 0;
	fo(i, 1, A) if(i == 1 || a[i].x != a[a0].x)
		a[++ a0] = a[i];
}

int t[N * 4], lz[N * 4], pl, pr, px;
#define i0 i + i
#define i1 i + i + 1
void down(int i) { 
	if(lz[i]) {
		t[i0] += lz[i], lz[i0] += lz[i];
		t[i1] += lz[i], lz[i1] += lz[i];
		lz[i] = 0;
	}
}
void add(int i, int x, int y) {
	if(y < pl || x > pr) return;
	if(x >= pl && y <= pr) { t[i] += px, lz[i] += px; return;}
	int m = x + y >> 1; down(i);
	add(i0, x, m); add(i1, m + 1, y);
	t[i] = t[i0] > t[i1] ? t[i0] : t[i1];
}
void pla(int x, int y, int z) {
	pl = x, pr = y, px = z;
	add(1, 1, d0);
}

int z1[N], z2[N];

void ad1(int f) {
	P u = b[z1[z1[0] - 1]], v = b[z1[z1[0]]];
	pla(rd[u.x], rd[v.x] - 1, f * (h - v.y));
}

void ad2(int f) {
	P u = c[z2[z2[0] - 1]], v = c[z2[z2[0]]];
	pla(rd[u.x], rd[v.x] - 1, f * v.y);
}

void work() {
	ls();
	b0 = c0 = 0;
	fo(i, 1, n)	if(a[i].x) {
		if(a[i].y >= h / 2) b[++ b0] = a[i];
		if(a[i].y <= h / 2) c[++ c0] = a[i];
	}
	op = 0; gg(b, b0);
	op = 1; gg(c, c0);
	
	fo(i, 1, d0 * 4) lz[i] = 0, t[i] = 0;
	
	b[0] = c[0] = (P) {0, h / 2};
	z1[0] = z2[0] = 1;
	z1[1] = z2[1] = 0;
	
	int l1 = 1, l2 = 1;
	fo(i, 1, d0) {
		while(l1 <= b0 && b[l1].x < d[i]) {
			while(b[l1].y < b[z1[z1[0]]].y)
				ad1(1), z1[0] --;
			z1[++ z1[0]] = l1; ad1(-1);
			l1 ++;
		}
		while(l2 <= c0 && c[l2].x < d[i]) {
			while(c[l2].y > c[z2[z2[0]]].y)
				ad2(1), z2[0] --;
			z2[++ z2[0]] = l2; ad2(-1);
			l2 ++;
		}
		ans = max(ans, t[1] + d[i]);
		
		pl = pr = i; px = h - d[i];
		add(1, 1, d0);
	}
	
}

int main() {
	scanf("%d %d %d", &w, &h, &n);
	fo(i, 1, n) scanf("%d %d", &a[i].x, &a[i].y), a[i].x *= 2, a[i].y *= 2;
	w *= 2, h *= 2;
	ans = max(w, h);
	work();
	swap(w, h); fo(i, 1, n) swap(a[i].x, a[i].y);
	work();
	pp("%d\n", ans);
}

Measured memory_bytes: 32896
import itertools
S=input()
lis = list(itertools.product([0,1], repeat=len(S)-1))
ans=0
for li in lis:
    st=0
    x=0
    for i in range(len(S)-1):
        if li[i]==1:
            x += int(S[st:i+1])
            st = i+1
            
    x += int(S[st:])
    
    ans += x         
print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ld, ld> pdd;

void solve();

const int N = 2e5 + 10;

int main() {
    fast_cin();

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

void solve() {
    int a, b;
    cin >> a >> b;
    // int a[N];
    // for (int i=1; i <= n; i++) { 
    //     cin >> a[i];
    // }

    int ans[] = {1, 2, 3};
    for (auto val_in: ans) {
        if (a != val_in and b != val_in) {
            cout << val_in << '\n';
            return;
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 16
int c[maxn][maxn];
int main(){
	int n,a,x,y,ans=0,w;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a);
		for(int j=0;j<a;j++){
			scanf("%d%d",&x,&y),x--;
			if(y)c[i][x]=1;else c[i][x]=-1;
		}
	}
	for(int i=0;i<(1<<n);i++){
		bool fl=1;w=0;
		for(int j=0;j<n;j++){
			if(i&(1<<j)){
				w++;
				for(int k=0;k<n;k++){
					if(c[j][k]==1&&(i&(1<<k))==0){fl=0;break;}
					if(c[j][k]==-1&&(i&(1<<k))){fl=0;break;}
				}
				if(!fl)break;
			}
		}
		if(fl)
		ans=max(ans,w);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define ll long long

ll gcd(ll a ,ll b){
    return b==0?a:gcd(b,a%b);
}

int main(void){
    int n;
    ll evens[251];
    ll odds[251*250/2];
    while(cin >> n && n){
        //ll evens[n];
        //ll odds[n*(n-1)/2];
        ll g,tmp;
        ll oindex=0, eindex=0;
        for(int i=0;i<n*(n+1)/2;i++){
            cin >> tmp;
            tmp%2?odds[oindex++] = tmp:evens[eindex++] = tmp;
        }
        sort(evens, evens+n);
        sort(odds, odds + n * (n-1)/2);
        tmp = gcd(evens[0], odds[0]);
        g = (ll)sqrt(evens[0] / tmp * (evens[1] / (odds[0] / tmp)));
        cout << g << endl;
        for(int i=0;i<n-1;i++){
            cout << (ll)round((double)evens[i]/g) << " ";
        }
        cout << (ll)round((double)evens[n-1]/g) << endl;
    }
}

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

double dp[3001][3001];
int main() {
  int n;
  cin >> n;
  vector<double> p(n);
  rep(i, n) cin >> p[i];
  dp[0][0] = 1.0;
  rep(i, n) rep(j, i + 1) {
    dp[i + 1][j + 1] += dp[i][j] * p[i];
    dp[i + 1][j] += dp[i][j] * (1.0 - p[i]);
  }
  double ans = 0.0;
  for (int j = n / 2 + 1; j <= n; j++) ans += dp[n][j];
  printf("%.10lf\n", ans);
  return 0;
}

Measured memory_bytes: 68992
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
	int N,L;
	cin >>N>>L;
	string S[100];
	for(int i=0;i<N;i++){
		cin>>S[i];
	}
	sort(S,S+N);
	for(int i=0;i<N;i++){
		cout<<S[i];
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main(void){

    int N , K;  cin >> N >> K;
    vector<int> h(N);  for(int i = 0 ; i < N ; i++)  cin >> h[i];
    sort(h.begin() , h.end());
    long dp[100000];   dp[0] = 0;
    for(int i = 1 ; i < N ; i++)
        dp[i] = dp[i - 1] + h[i] - h[i - 1];  //0本目を基準としたi本目までの絶対値
  
    long ans = 1000000000;
    for(int i = 0 ; i < N - K + 1 ; i++)
        if(dp[i + K - 1] - dp[i] < ans)   ans = dp[i + K - 1] - dp[i];
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int A[100001],n;
int partition(int p, int r){
    int x,i,j;
    x = A[r];
    i = p-1;
    for(j=p;j<r;j++){
        if(A[j] <= x){
            i++;
            swap(A[i],A[j]);
        }
    }
    swap(A[i+1],A[r]);
    return i+1;
}
int main(){
    int i,q;
    int N;
    cin >> N;
    for(int j = 0; j < N;j++){
        cin >> A[j]; 
        
    }
    q = partition(0,N-1);
    
    for(int i = 0;i < N;i++){
        if(i)cout << " ";
        if(i == q)cout << "[";
        cout << A[i];
        if(i == q)cout << "]";
    }
    cout << endl;
    return 0;
    
}


Measured memory_bytes: 3364
import collections

V, E = map(int, input().split())
Adj_list = [[] for _ in range(V)]
Indeg = [0] * V #??\?¬???°
isVisited = [False] * V
ans = []

for i in range(E):
    u, v = map(int, input().split())
    Adj_list[u].append(v)
    Indeg[v] += 1

def BFS(u):
    dq = collections.deque()
    dq.append(u)
    isVisited[u] = True
    
    while dq:
        v = dq.popleft()
        ans.append(v)
        
        for s in Adj_list[v]:
            Indeg[s] -= 1
            if Indeg[s] == 0 and isVisited[s] != True:
                isVisited[s] = True
                dq.append(s)
    return ans

for i in range(V):
    if Indeg[i] == 0 and isVisited[i] != True:
        BFS(i)

for i in ans:
    print(i)

Measured memory_bytes: 11292
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int mypow(int x,int n){
    if(n==0)
        return 1;
    if(n%2==1)
        return mypow(x,n-1)*x;
    int tmp=mypow(x,n/2);
    return tmp*tmp;
}
signed main() {
    int N,P;
    cin >> N >> P;
    vector<int>A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        if(A[i]%2) {
            cout << mypow(2,N-1) << endl;
            return 0;
        }
    }
    if(!P) {
        cout << mypow(2,N) << endl;
    }
    else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 3640
package main

import "fmt"

func abs(i float64) float64 {
	if i < 0 {
		return -i
	}
	return i
}

func main() {
	var (
		n    int
		t, a float64
	)
	fmt.Scan(&n, &t, &a)

	var (
		h, rd float64
		ri    int
	)
	for i := 0; i < n; i++ {
		fmt.Scan(&h)
		ht := t - h*0.006
		d := abs(a - ht)

		if i == 0 {
			rd = d
			continue
		}

		if d < rd {
			ri = i
			rd = d
		}
	}

	fmt.Println(ri + 1)
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
		int a = n % 1000;
		
		if(a==0) {
			System.out.println(0);
			
		}
		
		else {
			System.out.println(1000-a);
		}
	}

	
}


Measured memory_bytes: 27040
import Data.List( sort)
main = do
    n <- (readLn::IO Int)
    ls <- return . map (read::String->Int) . words =<< getLine
    let sortedls = sort ls
	mins [] = []
	mins (l1:l2:ls) = (min l1 l2):mins ls
    print . sum $ mins sortedls

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  int h,w,k;
  cin >> h >> w >> k;
  char c[h][w];
  REP(i,h) {
    REP(j,w) {
      cin >> c[i][j];
    }
  }
  int ans=0;
  REP(i,pow(2,h)) {
    vi row_check;
    REP(x,h) {
      if((i>>x)&1) row_check.push_back(x);
    }
    REP(j,pow(2,w)) {
      vi column_check;
      REP(y,w) {
        if((j>>y)&1) column_check.push_back(y);
      }
      int cnt=0;
      REP(a,h) {
        REP(b,w) {
          if(find(ALL(row_check),a)==row_check.end()) continue;
          if(find(ALL(column_check),b)==column_check.end()) continue;
          if(c[a][b]=='#') cnt++;
        }
      }
      if(cnt==k) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4108
import java.util.Scanner;

public class Main {

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		int n = input();
		int[][][] arrays = new int[4][3][10];

		for (int i = 0; i < n; i++) {

			int b = input();
			int f = input();
			int r = input();
			int v = input();

			v =+ v;

			arrays[b - 1][f - 1][r - 1] += v;

		}

		for (int j = 0; j < 4; j++) {

			for (int k = 0; k < 3; k++) {

				for (int l = 0; l < 10; l++) {


					System.out.print(" ");
					System.out.print(arrays[j][k][l]);

				}

				System.out.println("");

			}

			if (j + 1 != 4) {

				for (int m = 0; m < 20; m++) {

					System.out.print("#");

				}

				System.out.println("");

			}
		}

		close();

	}

	public static int input() {

		return scanner.nextInt();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

		}
	}
}

Measured memory_bytes: 29704
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
    int a, b, C;
    double S, L, h, d;
    cin >>a >>b >>C;
    d = (acos(-1.0)*C)/180.0;
    S = a*b*sin(d)/2.0;
    L = a + b + sqrt(a * a + b * b - 2 * a * b * cos(d));
    h = b * sin(d);

    printf("%lf\n%lf\n%lf\n", S, L, h);

    return 0;
}


Measured memory_bytes: 3564
x,k,d=map(int,input().split())

x=abs(x)

if x==0:
    if k%2==0:
        print(0)
        exit()
    
    else:
        print(d)
        exit()

if x>=k*d:
    print(x-k*d)
    exit()



xxx=x//d

yyy=x%d

zzz=k-xxx

if zzz%2==0:
  print(yyy)

else:
    print(abs(yyy-d))

Measured memory_bytes: 61708