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

using namespace std;


void solve() {
    int h, w, n;
    cin >> h >> w >> n;
    int x, y;
    cin >> x >> y;
    string S(n+1, '.'), T(n+1, '.');
    cin >> &S[1];
    cin >> &T[1];
    int l = 1, r = w;
    bool flag = true;
    for (int i = n; i >= 1; i--) {
        if (T[i] == 'L' && r < w) {
            r++;
        }
        if (T[i] == 'R' && l > 1) {
            l--;
        }
        if (S[i] == 'R') {
            r--;
        }
        if (S[i] == 'L') {
            l++;
        }
        if (l > r) {
            flag = false; break;
        }
    }
    if (!flag || y > r || y < l) {
        cout << "NO"; return;
    }
    l = 1, r = h;
    flag = true;
    for (int i = n; i >= 1; i--) {
        if (T[i] == 'U' && r < h) {
            r++;
        }
        if (T[i] == 'D' && l > 1) {
            l--;
        }
        if (S[i] == 'D') {
            r--;
        }
        if (S[i] == 'U') {
            l++;
        }
        if (l > r) {
            flag = false; break;
        }
    }
    if (!flag || x > r || x < l) {
        cout << "NO"; return;
    }
    cout << "YES";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 640
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		long n = long.Parse(Console.ReadLine());//int.Parseは文字列を整数に変換。
		long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    long[] adds = new long[n+1];
    adds[0] = 0;
    long memo = 1;
    long answer = 0;

    for(long i = 1; i < n+1; i++)
    {
      adds[i] = adds[i-1] + nums[i-1];
    }

    Array.Sort(adds);

    for(long i = 1; i < n+1; i++)
    {
      if(adds[i] == adds[i-1]) memo++;
      else
      {
        answer += memo*(memo-1)/2;
        memo = 1;
      }
      if(i == n) answer += memo*(memo-1)/2;
    }
      
		Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
	}
}

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

int main(){
	int n, i;
	cin >> n;
	vector<int> t(n+1);
	vector<int> x(n+1);
	vector<int> y(n+1);
	t[0] = x[0] = y[0] = 0;
	for(int i=1; i<n+1; ++i) cin >> t[i] >> x[i] >> y[i];
	for(int i=1; i<n+1; ++i){
		int necessaryTime = abs(x[i]-x[i-1]) + abs(y[i]-y[i-1]);
		int diffTime = t[i] - t[i-1];
		bool isOdd = necessaryTime%2;
		if( diffTime < necessaryTime ){
			cout << "No" << endl;
			return 0;
		}
		if( diffTime%2 != necessaryTime%2 ){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>

int main(void){
    unsigned i,j,N,count=0,usa[100001];
    for(i=0;i<100002;i++){
        usa[i]=0;
    }
    scanf("%u%*c",&N);
    for(i=1;i<=N;i++){
        scanf("%u%*c",&usa[i]);
        if(usa[i]<i && usa[usa[i]]==i) count++;
    }
    printf("%u\n",count);
    return 0;
}


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

int main() {
	string S;
	cin >> S;
	int N = S.length();
	int MIN = 100;
	for (int i = 0; i < N; i++) {
		char key = S[i];
		int now = 0, maxdif = 0;
		for (int j = 0; j < N; j++) {
			if (S[j] == key) {
				maxdif = max(now, maxdif);
				now = 0;
			}
			else now++;
		}
		maxdif = max(now, maxdif);
		MIN = min(MIN, maxdif);
	}
	cout << MIN << endl;

}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int gasto,moedas,satisfeito;
    int total;
    cin >> gasto >> moedas >> satisfeito;

    total = moedas / gasto;
    if(total >= satisfeito)
    {
        cout << satisfeito << endl;
    }
    else
    {
        cout << total << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }

int digitsMod(const char s[], int n, int m) {
    int x = 0; long long pow10 = 1;
    for (int i = n - 1; i >= 0; i--) {
        if ((x += pow10 * (s[i] - '0') % m) >= m) x -= m;
        pow10 = pow10 * 10 % m;
    }
    return x;
}

int main() {
    int N, a;
    while (~scanf("%d", &N)) {
        a = 1;
        --a;
        string k;
        cin >> k;
        int K = (int)k.size() >= 7 ? INF : atoi(k.c_str());
        vector<int> b(N);
        for (int i = 0; i < N; ++i)
            scanf("%d", &b[i]), --b[i];
        vi v(N, -1);
        rep(t, K) {
            if (v[a] != -1) {
                int head = v[a];
                int len = t - v[a];
                int m = digitsMod(k.c_str(), k.size(), len);
                m = ((m - head) % len + len) % len;
                rep(i, m)
                    a = b[a];
                break;
            }
            v[a] = t;
            a = b[a];
        }
        printf("%d\n", a + 1);
    }
    return 0;
}


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

if m == 0:
  print('0 0')
else:
  # 逆順にすると、各問題に関して、最後にACになったもの以降のWAの数がWAのカウント対象。
  outputs = reversed([input().split(' ') for i in range(m)])

  problem_ac = set()  # ACになった問題番号のセット
  problem_wa = {}  # 問題番号:WAの数
  for o in outputs:
    num = o[0]
    result = o[1]
    if result == 'AC':
      if num in problem_ac:  # ACの後に再度ACになっている場合を考慮
        problem_wa[num] = 0
      problem_ac.add(num)
    else:  # WC
      if num in problem_ac:
        problem_wa[num] = problem_wa[num] + 1 if num in problem_wa.keys() else 1
  # print('{} {}'.format(str(problem_ac), str(problem_wa)))
  ac_count = len(problem_ac)
  wa_count = sum(problem_wa.values()) if len(problem_wa) > 0 else 0
  print('{} {}'.format(ac_count, wa_count))

Measured memory_bytes: 38280
#include <iostream>

using namespace std;

int main() {

	int n = 0;
	int m = 0;
	int l = 0;
	int a[100][100] = { 0 };
	int b[100][100] = { 0 };
	long long int c[100][100] = { 0 };

	cin >> n >> m >> l;

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

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

			cin >> a[i][u];

		}

	}

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

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

			cin >> b[i][u];

		}

	}

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

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

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

				c[i][u] += a[i][y] * b[y][u];

			}

		}

	}

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

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

			cout << c[i][u];

			if (u != l - 1) {

				cout << " ";

			}

		}

		cout << endl;

	}
	


	return 0;

}



Measured memory_bytes: 3276
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define digit(x) floor(log10(x))+1
#define mod 1000000007
typedef long long ll;
typedef long double ld;
typedef vector<vector<ll>> matrix;
typedef vector<ll> arr;
typedef vector<string> vs;
typedef vector<pair<ll,ll>> pv;
#define in1(x) scanf("%lld",&x)
#define in2(x,y) scanf("%lld %lld",&x,&y)
#define in3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define all(x) x.begin(),x.end()
#define debug(x) cerr << #x << " is " << x << endl;
int main(){
    fast;
    ll n;
    cin>>n;
    map<ll,ll>x;
    arr a;
    for(int i=0;i<n;i++){
        ll d;
        cin>>d;
        x[d]++;
        a.pb(d);
    }
    ll ans=0;
    int j=0;
    map<ll,ll>z;
    for(auto i : x){
        ll k=i.second;
        ans+=(k*(k-1))/2;
    }
    for(int i=0;i<n;i++){
        cout<<ans-x[a[i]]+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 11120
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<stdio.h>
#include<algorithm>
using namespace std;

const int maxn=2000000;
const long long M=924844033;
const long long g=5;
typedef long long LL;

LL A[maxn];
LL B[maxn];

int Rev[maxn];
int N,Lg;

struct edge
{
	int obj;
	edge *Next;
} e[maxn<<1];
edge *head[maxn];
int cur=-1;

int num[maxn];
int Size[maxn];
int fa[maxn];

LL fac[maxn];
LL nfac[maxn]; 
int n;

void Add(int x,int y)
{
	cur++;
	e[cur].obj=y;
	e[cur].Next=head[x];
	head[x]=e+cur;
}

void Dfs(int node)
{
	Size[node]=1;
	for (edge *p=head[node]; p; p=p->Next)
	{
		int son=p->obj;
		if (son==fa[node]) continue;
		fa[son]=node;
		Dfs(son);
		Size[node]+=Size[son];
		num[ Size[son] ]++;
	}
	num[ n-Size[node] ]++;
}

LL Pow(LL x,LL y)
{
	if (!y) return 1;
	LL temp=Pow(x,y>>1);
	temp=temp*temp%M;
	if (y&1) temp=temp*x%M;
	return temp;
}

void DFT(LL *a,int f)
{
	for (int i=0; i<N; i++)
		if (i<Rev[i]) swap(a[i],a[ Rev[i] ]);
	
	for (int len=2; len<=N; len<<=1)
	{
		int mid=(len>>1);
		LL e=Pow(g,(M-1)/len);
		if (f==-1) e=Pow(e,M-2);
		
		for (LL *p=a; p!=a+N; p+=len)
		{
			LL wn=1;
			for (int i=0; i<mid; i++)
			{
				LL temp=wn*p[mid+i]%M;
				p[mid+i]=(p[i]-temp+M)%M;
				p[i]=(p[i]+temp)%M;
				wn=wn*e%M;
			}
		}
	}
}

void NTT()
{
	N=1,Lg=0;
	while (N<2*n+2) N<<=1,Lg++;
	for (int i=0; i<N; i++)
		for (int j=0; j<Lg; j++)
			if (i&(1<<j)) Rev[i]|=(1<<(Lg-j-1));
	
	DFT(A,1);
	DFT(B,1);
	for (int i=0; i<N; i++) A[i]=A[i]*B[i]%M;
	DFT(A,-1);
	
	LL inv=Pow(N,M-2);
	for (int i=0; i<N; i++) A[i]=A[i]*inv%M;
}

int main()
{
	
	scanf("%d",&n);
	for (int i=1; i<=n; i++) head[i]=NULL;
	for (int i=1; i<n; i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		Add(u,v);
		Add(v,u);
	}
	
	Dfs(1);
	
	fac[0]=1;
	for (LL i=1; i<=n; i++) fac[i]=fac[i-1]*i%M;
	for (int i=0; i<=n; i++) nfac[i]=Pow(fac[i],M-2);
	
	for (int i=0; i<=n; i++) A[i]=(long long)num[i]*fac[i]%M;
	for (int i=0; i<=n; i++) B[i]=nfac[i];
	for (int i=0; n-i>i; i++) swap(B[i],B[n-i]);
	
	NTT();
	
	for (int k=1; k<=n; k++)
	{
		LL ans=(long long)n*fac[n]%M;
		ans=ans*nfac[k]%M;
		ans=ans*nfac[n-k]%M;
		LL Dec=A[n+k];
		Dec=Dec*nfac[k]%M;
		ans=(ans-Dec+M)%M;
		printf("%lld\n",ans);
	}
	
	return 0;
}






















Measured memory_bytes: 52608
import java.util.Scanner;

class Main{
	public static void main(String[] args) 	{
		Scanner sc = new Scanner(System.in);
		while(0 < 1){
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a == 0 && b == 0) break;
		else for(int i = 0;i < a;i++) {
			for(int j = 0;j < b;j++) {
				System.out.printf("#");
			}
			System.out.printf("\n");
		}
		System.out.printf("\n");
		}
		sc.close();
	}	
}


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

using namespace std;

int main(){
	long long int L;
	cin >> L;
	vector<pair<pair<long long int, long long int>, long long int>>path;
	long long int maxv = 0;
	long long int memov = 0;
	long long int goal = 0;
	long long int pathmemo = 0;
	long long int count = 0;
	long long int L_ = L;
	long long int Lval = L;
	while( L_ ){
		L_ /= 2;
		count++;
	}
	count--;
	for( size_t i = 0; i < count; i++ ){
		path.push_back(make_pair(make_pair(i, i + 1), 0));
		path.push_back(make_pair(make_pair(i, i + 1), ( 1LL << i )));
	}
	goal = count;
	L -= ( 1LL << ( goal + 1 ) - 1 );
	maxv = 1LL << goal;
	while( L ){
		L_ = L;
		long long int c = 0;
		while( L_ ){
			c++;
			L_ /= 2;
		}
		c--;
		path.push_back(make_pair(make_pair(c, goal), maxv));
		L -= 1LL << c;
		maxv += 1LL << c;
	}


	cout << count + 1 << " " << path.size() << endl;
	for( auto p : path ){
		cout << p.first.first + 1 << " " << p.first.second + 1 << " " << p.second << endl;
	}

}


Measured memory_bytes: 256
#include<stdio.h>

#define MAX 100005
#define NIL -1
   
struct Node{
  int p, l, r;
};

struct Node N[MAX];
int n;

void Preorder(int u){
  if(u != NIL){
    printf(" %d", u); 
    Preorder(N[u].l);
    Preorder(N[u].r);
  }
}

void Inorder(int u){
  if(u != NIL){
    Inorder(N[u].l);
    printf(" %d", u);
    Inorder(N[u].r);
  }
}

void Postorder(int u){
  if(u != NIL){
    Postorder(N[u].l);
    Postorder(N[u].r);
    printf(" %d", u);
  }
}

int main(){
  int i, j, d, v, c, l;
  int first;
  scanf("%d", &n);
  
  for(i = 0; i < n; i++){
    N[i].p = N[i].l = N[i].r = NIL;
  }
  
  for (i = 0; i < n; i++){
    scanf("%d %d %d", &v, &d, &c);
    if(i == 0) first = v;
    N[d].p = v;
    N[c].p = v;
    N[v].l = d;
    N[v].r = c;
  }
  
  for(i = 0; i < n; i++){
    if(N[i].p == NIL){
      first = i;
      break;
    }
  }
  
  printf("Preorder\n");
  Preorder(first);
  
  printf("\n");
  printf("Inorder\n");
  Inorder(first);
  
  printf("\n");
  printf("Postorder\n");
  Postorder(first);
  
  printf("\n");
  return 0;
}

Measured memory_bytes: 620
#include "bits/stdc++.h"

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
//bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

int n;
int F[110][15];
int P[110][15];

ll maxv = -INF;

int main(void){
	cin>>n;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < 10; j++) cin>>F[i][j];

	for (int i = 0; i < n; i++)
		for (int j = 0; j <= 10; j++) cin>>P[i][j];

	for (int i = 1; i < (1 << 10); i++) {
		bitset<10> joshino(i);
		ll value = 0;

		for (int j = 0; j < n; j++) {
			int cnt = 0;
			for (int k = 0; k < 10; k++) {
				if (joshino[k] && F[j][k] == 1) cnt++;
			}
			value += P[j][cnt];
		}
		maxv = max(maxv, value);
	}

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
  int n,i,res[4];
  string s;
  cin >> n;
  fill(res,res+4,0);
  for(i=0;i<n;i++){
    cin >> s;
    if(s=="AC")
      res[0]++;
    else if(s=="WA")
      res[1]++;
    else if(s=="TLE")
      res[2]++;
    else
      res[3]++;
  }
  cout << "AC x " << res[0] << endl;
  cout << "WA x " << res[1] << endl;
  cout << "TLE x " << res[2] << endl;
  cout << "RE x " << res[3] << endl;
  return 0;
}

Measured memory_bytes: 3628
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		String[] S = new String[N];
		for (int i = 0; i < N; i++)
			S[i] = sc.next();

		for (int i = 0; i < N; i++) {
			if (S[i].equals("Y")) {
				System.out.println("Four");
				return;
			}
		}
		System.out.println("Three");

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	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() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		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 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();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


Measured memory_bytes: 21332
a, b, c = map(int, input().split())
abc = [a, b, c]
abc.sort()
sho, chu, dai = abc[0], abc[1], abc[2]

huyasu = dai-chu + dai-sho
if huyasu % 2 == 1:
    huyasu += 3
print(huyasu//2)

Measured memory_bytes: 38256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5;
int n;
int a[N+10],b[N+10],maxa,maxb;
struct node
{
	int cnt,x;
}aa[N+10],bb[N+10];
bool cmp(node x,node y){return x.cnt>y.cnt;}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		if(i&1) scanf("%d",&a[(i+1)>>1]);
		else scanf("%d",&b[i>>1]);
	}
	n>>=1;
	for(int i=1;i<=n;i++) maxa=max(maxa,a[i]),maxb=max(maxb,b[i]);
	for(int i=1;i<=maxa;i++) aa[i].x=i;
	for(int i=1;i<=maxb;i++) bb[i].x=i;
	for(int i=1;i<=n;i++) aa[a[i]].cnt++,bb[b[i]].cnt++;
	sort(aa+1,aa+maxa+1,cmp);
	sort(bb+1,bb+maxb+1,cmp);
	if(aa[1].x!=bb[1].x){printf("%d\n",(n<<1)-aa[1].cnt-bb[1].cnt);return 0;}
	printf("%d\n",min((n<<1)-aa[1].cnt-bb[2].cnt,(n<<1)-aa[2].cnt-bb[1].cnt));
	return 0;
}

Measured memory_bytes: 2176
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e3+5, M = 4e1+5;
int n, m, a[N], b[N], c[M]; char s[M];
int main()
{
    n = read(); for(int i = 1; i <= n; ++i) a[i] = read(), b[i] = read();
    c[1] = 1, m = ~abs(a[1]+b[1])&1;
    for(int i = 2; i <= n; ++i) if(m != (~abs(a[i]+b[i])&1)) return puts("-1"), 0;
    c[++m] = 1; for(int i = 1; i <= 30; ++i) c[++m] = 1<<i;
    printf("%d\n", m);
    for(int i = 1; i <= m; ++i) printf("%d ", c[i]); puts("");
    for(int i = 1; i <= n; ++i)
    {
        int nx = 0, ny = 0;
        for(int j = m; j; --j)  
        {
            int dx = a[i]-nx, dy = b[i]-ny;
            if(abs(dx) > abs(dy)) dx>0?(nx += c[j], s[j] = 'R'):(nx -= c[j], s[j] = 'L');
            else dy>0?(ny += c[j], s[j] = 'U'):(ny -= c[j], s[j] = 'D');
        }
        puts(s+1);
    }
    return 0;
}   

Measured memory_bytes: 256
o = input()
e = input()
if len(o)==len(e):
  for i in range(len(o)):
    print(o[i],end="")
    print(e[i],end="")
else:
  for i in range(len(o)-1):
    print(o[i],end="")
    print(e[i],end="")
  print(o[-1])

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;

long long N;
vector<vector<long long> > V;

long long DFS(long long P, long long Q) {
	long long COUNT = 0;
	for (long long NP : V[P]) {
		if (NP != Q) {
			COUNT ^= DFS(NP, P);
		}
	}
	return COUNT + 1;
}

int main() {
	cin >> N;
	V.resize(N);
	for (int i = 0; i < N - 1; i++) {
		long long X, Y;
		cin >> X >> Y;
		X--, Y--;
		V[X].push_back(Y);
		V[Y].push_back(X);
	}
	long long XOR = 0;
	for (long long P : V[0]) {
		XOR ^= DFS(P, 0);
	}
	cout << (XOR == 0 ? "Bob" : "Alice") << endl;
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
/* Coding space */
int main(){
  ll n; cin >> n;
  vector<ll> in(n);
  rep(i,n) cin >> in[i];
  
  ll ans = 0;
  
  rep(iii,10000){
  rep(i,n){
    if(in[i] >= n){
      ans += in[i]/n;
      rep(j,n)if(i!=j)in[j] += in[i]/n;
      in[i] %= n;
    }
  }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
num = input().split()
list = input().split()
list2 = [int(x) for x in list]
max = -1000000
min = 1000000
sum = 0
for x in list2:
    if x > max:
        max = x
    if x < min:
        min = x
    sum = sum + x
print(min,max,sum)


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

//#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    queue<int> q[n];
    int cnt[m];
    for (int i = 0; i < m; i++) cnt[i] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            int x;
            cin >> x;
            q[i].push(x-1);
            if (j == 0) cnt[x-1]++;
        }
    }
    int res = 1e9;
    set<int> bad;
    for (int iter = 0; iter < m-1; iter++) {
        int maxi = 0;
        int id = 0;
        for (int i = 0; i < m; i++) {
            if (cnt[i] > maxi) {
                maxi = cnt[i];
                id = i;
            }
        }
        bad.emplace(id);
        res = min(res, maxi);
        for (int i = 0; i < n; i++) {
            while (bad.count(q[i].front()) != 0) {
                cnt[q[i].front()]--;
                q[i].pop();
                cnt[q[i].front()]++;
            }
        }
    }int maxi = 0;
    int id = 0;
    for (int i = 0; i < m; i++) {
        if (cnt[i] > maxi) {
            maxi = cnt[i];
            id = i;
        }
    }
    bad.emplace(id);
    res = min(res, maxi);

    cout << res << '\n';
}
/*

 */

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

    public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);
	    int n = scanner.nextInt();
	    int[] array = new int[n];
	    for(int i=0; i<n; i++) {
	        array[i] = scanner.nextInt();
        }

		int tmp;
	    for(int j=0; j<array.length; j++) {
			if(array[0] < array[j]) {
				tmp = array[0];
				array[0] = array[j];
				array[j] = tmp;
			}
        }
	    int maxVal = array[0];
	    for (int k=0; k<array.length; k++) {
	    	if(array[0] > array[k]) {
	    		array[0] = array[k];
			}
		}
	    int minVal = array[0];
	    System.out.println(maxVal-minVal);
    }
}

Measured memory_bytes: 21844
// ABC143D.cpp

//#include "pch.h"
#include <iostream>
#include <vector>
#include <algorithm> // sortを使う
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int>L(N);
	for (int i = 0; i < N; i++)
	{
		cin >> L.at(i);
	}
	sort(L.begin(), L.end(), greater<int>()); // 降順にソート
	int ans = 0;
	for (int j = 0; j < (N-2); j++)
	{
		for (int k = j+1; k < (N-1); k++)
		{
			int c = L.at(j) - L.at(k);
			for (int m = k+1; m < N; m++)
			{
				if (L.at(m)>c)
				{
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
x,k,d=map(int,input().split())
x=abs(x)
ans=0
if x>k*d:
    print(x-k*d)
else:
    a=x//d
    p=x-d*a
    q=abs(x-d*a-d)
    print(q if (k-a)%2 else p)

Measured memory_bytes: 61784
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
template <class T>
inline void chmin(T &a, T b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, T b) { a = max(a, b); }
template <class T>
inline bool kbit(T &x, int k) { return ((x >> k) & 1LL); }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
void debug() { cerr << "ok" << endl; }
template <class T>
void printv(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void readv(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    V<int> c(n + 1);
    for (int i = 0; i < k; i++) {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++) {
            int a;
            cin >> a;
            c[a]++;
        }
    }
    int res = 0;
    for (int i = 1; i <= n; i++) {
        res += (c[i] == 0);
    }
    cout << res << '\n';
}

Measured memory_bytes: 3664
import math

a, b, x = map(int, input().split())
k = 2 * b - (2 * x) / (a * a)
if k <= b:
    print(math.degrees(math.atan(k / a)))
else:
    l = (2 * x) / (a * b)
    print(math.degrees(math.atan(b / l)))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll h, n;
    cin >> h >> n;
    vector<ll> value(n), weight(n);
    vector<ll> dp(2 * h + 1, 1145141919810364);
    for (ll i = 0; i < n; i++)
    {
        cin >> value[i] >> weight[i];
    }
    dp[0] = 0;
    for (ll i = 1; i <= h * 2; i++)
    {   
        for (ll j = 0; j < n; j++)
        {   
            if(i - value[j] < 0)
                dp[i] = min(dp[i], dp[0] + weight[j]);
            if (i - value[j] >= 0)
                dp[i] = min(dp[i], dp[i - value[j]] + weight[j]);
        }
    }
    ll ans = 1145141919810;
    for (ll i = h; i < 2 * h; i++)
    {
        ans = min(ans, dp[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
void rle(string &s, vector<pair<char,int>> &t){
    int j=0;
    t={make_pair(s[0],1)};
    for(int i=1; i<s.size(); ++i){
        if(s[i]==s[i-1]){
            ++t[j].second;
        }else{
            t.push_back(make_pair(s[i],1));
            ++j;
        }
    }
}
int main(){
	int n, k; cin >> n >> k;
    string s; cin >> s;
    vector<pair<char,int>> t;
    rle(s, t);

    int cnt=0;
    for(auto i : t) cnt += i.second-1;

    int lr=0, rl=0;
    for(int i=0; i<n-1; ++i){
        if(s.substr(i,2)=="LR") ++lr;
        if(s.substr(i,2)=="RL") ++rl;
    }
    
    int ans=(cnt+2*min({k,lr,rl}));
    if(k-min(lr,rl)>0 && abs(lr-rl)>0) ++ans;
    cout << ans << endl;
}

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

using namespace std;

int main()

{
    string s;
    cin>>s;
    if(((s[0]=='0' && s[1]>'0') || (s[0]=='1' && s[1]<='2')) && ((s[2]=='0' && s[3]>'0') || (s[2]=='1' && s[3]<='2'))) {
        cout<<"AMBIGUOUS"<<endl;
    }
    else if(!((s[0]=='0' && s[1]>'0') || (s[0]=='1' && s[1]<='2')) && !((s[2]=='0' && s[3]>'0') || (s[2]=='1' && s[3]<='2'))) {
        cout<<"NA"<<endl;
    }
    else if((s[0]=='0' && s[1]>'0') || (s[0]=='1' && s[1]<='2')) {
        cout<<"MMYY"<<endl;
    }
    else if((s[2]=='0' && s[3]>'0') || (s[2]=='1' && s[3]<='2')){
        cout<<"YYMM"<<endl;
    }


    return 0;
}


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

int main(){
	int n,h;
	string s;
	cin>>n>>s>>h;
	
	vector<bool> used(n,false);
	rep(i,s.size()){
		if(h<=0)break;
		if(s[i]=='0'){
			s[i]='1';
			used[i]=true;
			h--;
		}
	}
	
	for(int i=s.size()-1;i>=0;i--){
		if(h<=0)break;
		if(s[i]=='1'&&used[i]==false){
			s[i]='0';
			h--;
		}
	}
	cout<<s<<endl;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
//typedef __int128_t Int;
#define DBG 1
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define loop(n) rep(loop,(0),(n))
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(12);

  int N, A; cin >> N >> A;
  vector<int> x(N); rep(i, 0, N){ cin >> x[i]; }
  int C=2550;
  vector<vector<int>>dp(C,vector<int>(N+1));
  dp[0][0]=1;
  rep(i,0,N){
    rrep(j,x[i],C){
      rrep(k,1,N+1){

        dp[j][k]+=dp[j-x[i]][k-1];

      }
    }
  }
  int ans=0;
  rep(i,1,N+1){
    ans+=dp[A*i][i];
  }
  cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i,n) cin >> l.at(i);
  sort(ALLR(l));
  int sum = 0;
  rep(i,n-1) sum+=l.at(i+1);
  if(l.at(0)<sum){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll             long long
#define pl             pair <ll,ll>
#define ps             pair <string,string>
#define vi         vector <int>
#define vl             vector <ll>
#define vpi            vector <pi>
#define vpl            vector <pl>
#define f(i,a,b)       for(ll i=(a);i<(b);i++)
#define fd(i,a,b)      for(ll i=(a);i>(b);i--)
#define Max(a,b)       ((a)>(b)?(a):(b))
#define Min(a,b)       ((a)<(b)?(a):(b))
#define x              first
#define y              second
#define si(a)          scanf("%d",&a)
#define sii(a,b)       scanf("%d %d",&a,&b)
#define siii(a,b,c)    scanf("%d %d %d",&a,&b,&c)
#define sl(a)          scanf("%lld",&a)
#define sll(a,b)       scanf("%lld %lld",&a,&b)
#define slll(a,b,c)    scanf("%lld %lld %lld",&a,&b,&c)
#define ss(s)          scanf("%s",s)
#define pf             printf
#define pfi(n)         printf("%d\n",n)
#define pfl(n)         printf("%lld\n",n)
#define pfls(n)        printf("%lld ",n)
#define pfci(n,ans)    printf("Case %lld: %d\n",n,ans)
#define pfcl(n,ans)    printf("Case %lld: %lld\n",n,ans)
#define pfcd(n,ans)    printf("Case %lld: %lf\n",n,ans)
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define mem(a,v)       memset(a,v,sizeof(a))
#define MOD 1000000007
#define LG  16
#define mid ((l+r)/2+1)
#define PI (acos(-1.0))
#define ppl pair<pl,ll>
#define PT pair<double,double>
#define IN(n) (2*n-1)
#define OUT(n) (2*n)


#define MAX 100008
using namespace std;

vl G[MAX];
ll par[MAX], d[MAX], sum[MAX];

void dfs(ll n,ll p){
    par[n]=p;
    if(n==p) d[n]=0;
    else d[n]=d[p]+1;
    sum[n]=1;
    f(i,0,G[n].size()){
        ll v=G[n][i];
        if(p!=v){
            dfs(v,n);
            sum[n]+=sum[v];
        }
    }
}

int main(){
    ll N;
    sl(N);
    f(i,1,N){
        ll a,b;
        sll(a,b);
        G[a].pb(b);
        G[b].pb(a);
    }
    dfs(1,1);
    ll u=(d[N]-1)/2;
    ll now=N;
    f(i,0,u){
        now=par[now];
    }
    if(sum[now]>=(N-sum[now])) pf("Snuke\n");
    else pf("Fennec\n");
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
map<string,int>mp;
string s[N];
int main(){
	int n,ma=0;scanf("%d",&n);
	for(int i=0;i<n;i++){
		cin>>s[i];mp[s[i]]++;
		ma=max(ma,mp[s[i]]);
	}
	sort(s,s+n);
	for(int i=0;i<n;i++){
		if(mp[s[i]]==ma)mp[s[i]]=0,cout<<s[i]<<"\n";
	}
	return 0;
}

Measured memory_bytes: 26752
#include<iostream>
#include<vector>
#include<queue>
#include<string.h>
using namespace std;

int W,H;
bool in(int x,int y){
	if(x<0 || y<0 || x>=W || y>=H) return false;
	return true;
}

struct Info{
	int x,y,cost;
	Info(int para_x,int para_y,int para_c){
		x=para_x;y=para_y;cost=para_c;
	}
};

void solve()
{
	
	int cost[30][30];
	bool r[30][30];
	bool u[30][30];
	memset(r,false,sizeof(r));
	memset(u,false,sizeof(u));

	for(int x=0;x<W-1;x++){//ツ催渉可づ個暗ェツ行
		int k; 
		cin>>k;
		if(k==0) r[0][x]=true;
	}

	for(int y=1;y<H;y++){
		for(int x=0;x<W;x++){
			int k;
			cin>>k;
			if(k==0) u[y][x]=true;
		}
		for(int x=0;x<W-1;x++){
			int k;
			cin>>k;
			if(k==0) r[y][x]=true;
		}
	}

	memset(cost,-1,sizeof(cost));
	queue<Info> Q;
	Q.push(Info(0,0,0));

	while(!Q.empty()){
		Info t=Q.front();
		Q.pop();
		if(!in(t.x,t.y)) continue;
		if(cost[t.y][t.x]>=0) continue;
		if(t.y==H-1 && t.x==W-1){cout<<t.cost+1<<endl;return;}
		cost[t.y][t.x]=t.cost;
		if(u[t.y][t.x]) Q.push(Info(t.x,t.y-1,t.cost+1));
		if(r[t.y][t.x]) Q.push(Info(t.x+1,t.y,t.cost+1));
		if(t.x!=0 && r[t.y][t.x-1]) Q.push(Info(t.x-1,t.y,t.cost+1));
		if(t.y!=H-1 && u[t.y+1][t.x]) Q.push(Info(t.x,t.y+1,t.cost+1));
	}
	cout<<0<<endl;
}


int main()
{
	while(cin>>W>>H){
		if(W==0) return 0;
		solve();
	}
}

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

int main() {
  int A,B;
  cin>>A>>B;
  if(A!=1&&B!=1){
    cout<<"1"<< endl;
  }
  if(A!=2&&B!=2){
    cout<<"2"<< endl;
  }
  if(A!=3&&B!=3){
    cout<<"3"<< endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

int main(void)
{
	int n, a, min = 1000000, max = -1000000;
	long long sum = 0;
	std::cin >> n;
	for (int i = 0; i < n; i++){
		std::cin >> a;
		if (a < min) {
			min = a;
		}
		if (max < a) {
			max = a;
		}
		sum += a;
	}
	std::cout << min << " " << max << " " << sum << std::endl;
	return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int dp[20010][256];

int main() {
    while(1){
        int n,m;
        cin>>n>>m;
        if(n==0 && m==0) break;
        int c[m],x[n];
        rep(i,m) cin>>c[i];
        rep(i,n) cin>>x[i];

        rep(i,20010) rep(j,256) dp[i][j]=INF;
        dp[0][128]=0;

        rep(i,n){
            rep(j,256){
                if(dp[i][j]==INF) continue;
                rep(k,m){
                    int y=j+c[k];
                    if(y<0) y=0;
                    if(y>255) y=255;
                    int sum2=(x[i]-y)*(x[i]-y);
                    dp[i+1][y]=min(dp[i+1][y],dp[i][j]+sum2);
                }
            }
        }
        int ans=INF;
        rep(j,256){
            //cout<<dp[n][j]<<endl;
            ans=min(ans,dp[n][j]);
        }

        cout<<ans<<endl;
    }

    return 0;

}




Measured memory_bytes: 23060
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
int dp[1010][10010];
int main(){
  int h,n;
  cin>>h>>n;
  vector<int> a(n),b(n);
  for(int i=0;i<n;i++)cin>>a[i]>>b[i];
  int INF=1e9;
  fill_n(*dp,1010*10010,INF);
  dp[0][0]=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<=h;j++){
      if(dp[i][j]==INF)continue;
      int ni=i+1;
      int nj=min(h,j+a[i]);
      dp[ni][j]=min(dp[ni][j],dp[i][j]);
      dp[i][nj]=min(dp[i][nj],dp[i][j]+b[i]);
    }
  }
  cout<<dp[n][h]<<endl;
}


Measured memory_bytes: 39808
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        int[] a = new int[n+1];
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            p[i] = x;
            a[x] = i;
        }
        long ans = 0L;
        TreeSet<Integer> set = new TreeSet<>();
        set.add(a[n]);
        for (int i = n-1; i > 0 ; i--) {
            Integer l1, l2, r1, r2;
            l1 = set.lower(a[i]);
            r1 = set.higher(a[i]);
            if(l1 == null) l1 = -1;
            if(r1 == null) r1 = n;
            if(l1 == -1){
                l2 = -1;
            }else{
                l2 = set.lower(l1);
                if(l2 == null) l2 = -1;
            }
            if(r1 == n){
                r2 = n;
            }else{
                r2 = set.higher(r1);
                if(r2 == null) r2 = n;
            }
            ans += (long) i * ((l1 - l2)*(r1 - a[i]) + (a[i] - l1)*(r2 - r1));
            set.add(a[i]);
        }
        System.out.println(ans);
        sc.close();

    }

}


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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    double a, b, x; cin >> a >> b >> x;
    double s = x/a;
    double ans = 0;
    // 台形
    if(s > a*b/2) {
        double tmp = 2*s/a - b;
        double nb = b-tmp;
        ans = atan(a/nb);
    } else {    // 三角形
        double na = 2*s/b;
        ans = atan(na/b);
    }
    cout << fixed << setprecision(6);
    cout << 90.0 - ans*180/M_PI << '\n';
    return 0;
}

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

const int MAXN = 1000005;
int dp[MAXN][2], n, A[MAXN];
char s[MAXN];

int main(){
    scanf("%s", s+1);
    n=strlen(s+1);
    for(int i=1;i<=n;++i)A[i]=s[i]-'0';
    memset(dp, 0x3f, sizeof dp);
    dp[0][0]=0;
    dp[0][1]=1;
    for(int i=1;i<=n;++i){
        dp[i][0]=min(dp[i-1][0]+A[i], dp[i-1][1]+10-A[i]);
        dp[i][1]=min(dp[i-1][0]+A[i]+1, dp[i-1][1]+9-A[i]);
    }

    cout<<dp[n][0];

    return 0;
}


Measured memory_bytes: 12928
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solve();
	}
	int n;
	String[] s;
	void solve(){
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		s=new String[n];
		StringBuffer[] sb=new StringBuffer[n];
		for(int i=0;i<n;i++){
			s[i]=sc.next();
			sb[i]=new StringBuffer(s[i]);
		}
		StringBuilder ans=new StringBuilder();
		//a=97 z=122
		boolean check=true;
		int[] num=new int[n];
		LOOP:for(int i=0;i<sb[0].length();i++){
			char ch=sb[0].charAt(i);
			
			for(int j=1;j<n;j++){
				check=false;
				
				for(int k=0;k<sb[j].length();k++){
					if(sb[j].charAt(k)==ch){
						num[j]=k;
						check=true;
						break;
					}
				}
				if(!check)continue LOOP;
			}
			ans.append(ch);
			for(int j=1;j<n;j++){
				sb[j].deleteCharAt(num[j]);
			}
		}
		for(int j=0;j<ans.length()-1;j++){
		for(int i=0;i<ans.length()-1-j;i++){
			if(ans.charAt(i)>ans.charAt(i+1)){
				String temp=ans.substring(i, i+1);
				ans.replace(i, i+1, ans.substring(i+1,i+2));
				ans.replace(i+1, i+2,temp);
			}
		}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define int long long
using namespace std; 

std::vector<int> v[26];

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

    string s , t;
    cin >> s >> t;
    
    int n = s.size();
    int m = t.size();

    int h[26] = {};
    int c = 0;
    for(auto x : s){
        h[x - 'a']++;
        v[x - 'a'].push_back(c++ + 1);
    }

    for(auto x : t){
        if(h[x - 'a'] == 0){
            cout << -1 << "\n";
            return 0;
        }
    }
    int pos = 0;
    int ans = 0;

   /*for(int i = 0 ; i < 26 ; i++){
        if(v[i].size() == 0) continue;
        cout << (char)(i + 'a') << "--> ";
        for(auto x : v[i]) cout << x << " ";
        cout << endl;
    }*/

    for(auto x : t){
        int curr = x - 'a';
        int u = (upper_bound(v[curr].begin() , v[curr].end() , pos) - v[curr].begin());
     // cout << x << " " << u << " " << v[curr][u] << endl;
        if(u == v[curr].size()){
            ans += n - pos + v[curr][0];
            pos = v[curr][0];
        }else ans += v[curr][u] - pos  , pos = v[curr][u];
    }

    cout << ans << endl;

    return 0;
}


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

long long N, M;
vector<long long> tree[100005];
long long ans[100005];

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

	for(long long i = 0; i < M; i++) {
		long long A, B;
		cin >> A >> B;
		A--;B--;
		tree[B].push_back(A);
		tree[A].push_back(B);
	}

	for(long long i = 0; i < N; i++){
		ans[i] = -1;
	}

	// (cost, (point, parent))
	priority_queue<pair<long long, pair<long long, long long> >, vector<pair<long long, pair<long long, long long> > >, greater<pair<long long, pair<long long, long long> > > > queue;

	queue.push(make_pair(0, make_pair(0, -1)));

	while(!queue.empty()) {
		long long cost = queue.top().first;
		long long point = queue.top().second.first;
		long long parent = queue.top().second.second;
		queue.pop();

		//cout << "cost = " << cost << " point = " << point << " parent = " << parent << endl;

		if(ans[point] != -1) {
			continue;
		}
		if(parent != -1){
			ans[point] = parent;
		}

		for(long long i = 0; i < tree[point].size(); i++){
			long long next_point = tree[point][i];
			//cout << " next " << next_point << endl;
			if(ans[next_point] == -1) {
				queue.push(make_pair(cost + 1, make_pair(next_point, point)));
			}
		}
	}


	for(long long i = 1; i < N; i++) {
		if(ans[i] == -1) {
			cout << "No" << endl;
			return 0;
		}
	}


	cout << "Yes" << endl;
	for(long long i = 1; i < N; i++) {
		cout << ans[i] + 1 << endl;
	}
}


Measured memory_bytes: 18980
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit
#include <cstdio>	// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define DEBUG 0

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
string FILE_NAME = "testcase.dart";
string NAME;
string itos (int n )
{
	stringstream ss;
	ss << n;

	return ss.str();
}

/*
	解法３ O(n^2log(n))
	
	3本の矢を投げて、残りの矢を２分探索する
*/
int n, m, k;
int p[1005];
int s[1005*1005];

bool query (int c, int sum )
{
	return (sum + s[c] <= m );
}

int solve (int sum )
{
	int L = 0;
	int R = k;
	while( R-L > 1 ){
		int C = (L+R)/2;
		(query(C, sum ) ? L : R ) = C;
	} // end while

	return sum + s[L]; 
}
int main()
{
//	cut here before submit 
#if DEBUG
	NAME = FILE_NAME;
	int CNT = 1;
	NAME += itos (CNT );
	while (freopen (NAME.c_str() , "r", stdin ) != NULL ) {
#endif
	while (scanf ("%d %d", &n, &m ), n, m ){
		memset (p, 0, sizeof (p ) );
		memset (s, 0, sizeof (s ) );
		for (int i = 1; i <= n; i++ )	scanf ("%d", &p[i] );
		sort (p, p+n+1 );
		k = 0;
		for (int a = 0; a <= n; a++ ){
			for (int b = 0; b <= n; b++ ){
				if (p[a] + p[b] > m ) continue;
				s[k++] = p[a] + p[b];
			} // end for
		} // end for

		sort (s, s+k );

		int res = 0;
		rep (i, k ){
			int curr = solve (s[i] );	
			res = max (res, curr );
		} // end rep

		printf ("%d\n", res );
	} // end while
#if DEBUG
	CNT++;	// cut here before submit
	NAME = FILE_NAME;
	NAME += itos (CNT );
	} // end loop; cut here before submit
#endif			
	return 0;
}

Measured memory_bytes: 5184
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
using ll=long long;
using pint=pair<int,int>;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define el '\n'
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
#define $in(v,n) ;rep(II,0,n)cin>>v[II]
inline void IN(void){return;}
template<typename F,typename... R>inline void IN(F& f, R&... r){cin>>f;IN(r...);}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

int main(){
    int n, r;
    IN(n, r);
    if(n >= 10) cout << r << el;
    else {
        r += 100*(10-n);
        cout << r << el;
    }
    return 0;
}


Measured memory_bytes: 3196
/* 
	بسم الله الرحمن الرحیم

	(; طلا یک جهانی
*/

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define F first
#define S second
typedef pair<int, int> pii;

int32_t main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n, a[2][3];
	cin >> n;
	for (int i = 0; i < 2; i++)
		for (int j = 0; j < 3; j++)
			cin >> a[i][j];
	for (int l = 0; l < 2; l++) {
		int mx = n;
		for (int i = 0; i <= n && (!i || a[1][0] > a[0][0]); i += a[0][0])
			for (int j = 0; i + j <= n && (!j || a[1][1] > a[0][1]); j += a[0][1]) {
				int t = i / a[0][0] * a[1][0] + j / a[0][1] * a[1][1];
				if (a[0][2] < a[1][2])
					t += (n - i - j) / a[0][2] * a[1][2] + (n - i - j) % a[0][2];
				else
					t += n - i - j;
				mx = max(t, mx);
			}
		n = mx;
		for (int i = 0; i < 3; i++)
			swap(a[0][i], a[1][i]);
		if (a[1][2] <= a[0][2]) {
			swap(a[0][0], a[0][2]);
			swap(a[1][0], a[1][2]);
		}
	}
	cout << n;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int prev = sc.nextInt();
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        for (int i = 1; i < n; i++) {
            int x = sc.nextInt();
            queue.add(x - prev - 1);
            prev = x;
        }
        int sum = n;
        for (int i = 0; i < n - k; i++) {
            sum += queue.poll();
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 70912
#include<cstdio>
#include<cstring>
#include<algorithm>
#include <numeric>
using namespace std;

int main()
{	
	long long int N;
	scanf("%lld", &N);
	long long int chuo;
	long long int A[N], B[N];
	for(long long int i=0;i<N;i++){
		scanf("%lld", &A[i]);
	}
	for(long long int i=0;i<N;i++){
		B[i]=1000000000+i-A[i];
	}
	sort(B,B+N);
	
	chuo=B[N/2];
	long long int answer=0;
	for(long long int i=0;i<N;i++){
		answer+=abs(1000000000+i-A[i]-chuo);
	}
	printf("%lld", answer);
}


Measured memory_bytes: 3328
using System;
using System.Linq;

namespace MinPro2019D
{
    public class Program
    {
        static void Main()
        {
            var L = int.Parse(Console.ReadLine());
            var dp = new long[5];

            for (var i = 0; i < L; i++)
            {
                var A = long.Parse(Console.ReadLine());
                var x = A == 0 ? 2 : A & 1;

                for (var t = 1; t < 5; t++)
                {
                    dp[t] = Math.Min(dp[t - 1], dp[t]);
                }

                dp[0] += A;
                dp[1] += x;
                dp[2] += (x & 1) ^ 1;
                dp[3] += x;
                dp[4] += A;
            }

            Console.WriteLine(dp.Min());
        }
    }
}

Measured memory_bytes: 17484