akhauriyash/Code-Regression huggingface dataset:
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

using Cons = System.Console;

class PriorityQueue<T>
{
    private readonly List<T> m_list;
    private readonly Func<T, T, int> m_compare;
    private int m_count;
    public PriorityQueue(int capacity, Func<T, T, int> compare)
    {
        m_list = new List<T>(capacity);
        m_compare = compare;
        m_count = 0;
    }
    private int Add(T value)
    {
        if (m_count == m_list.Count)
        {
            m_list.Add(value);
        }
        else
        {
            m_list[m_count] = value;
        }
        return m_count++;
    }
    private void Swap(int a, int b)
    {
        T tmp = m_list[a];
        m_list[a] = m_list[b];
        m_list[b] = tmp;
    }
    public void Enqueue(T value)
    {
        int c = Add(value);
        while (c > 0)
        {
            int p = (c - 1) / 2;
            if (m_compare(m_list[c], m_list[p]) < 0) { Swap(p, c); } else { break; }
            c = p;
        }
    }
    public T Dequeue()
    {
        T value = m_list[0];
        m_list[0] = m_list[--m_count];
        int p = 0;
        while (true)
        {
            int c1 = p * 2 + 1;
            int c2 = p * 2 + 2;
            if (c1 >= m_count) { break; }
            int c = (c2 >= m_count || m_compare(m_list[c1], m_list[c2]) < 0) ? c1 : c2;
            if (m_compare(m_list[c], m_list[p]) < 0) { Swap(p, c); } else { break; }
            p = c;
        }
        return value;
    }
}

class Program
{
    static int Main(string[] args)
    {
        var sw = new StreamWriter(Cons.OpenStandardOutput()){AutoFlush = false};
        Cons.SetOut(sw);

        int ret = Solve();
        Cons.Out.Flush();
        
        return ret;
    }

    static int Solve()
    {
        List<int> list = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToList();

        if((list[1] * 2 - 1) > list[0]){
            Cons.WriteLine("NO");
        }
        else{
            Cons.WriteLine("YES");
        }

        return 0;
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a;
    rep(i, n)
    {
        int temp;
        cin >> temp;
        a.push_back(temp);
    }
    cout << abs(
                *max_element(a.begin(), a.end()) -
                *min_element(a.begin(), a.end()))
         << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

public class Program{

  public static void Main(){

    int money = int.Parse(Console.ReadLine());
    int checker = money  / 100;
    int max = 5 * checker;
    if(money % 100 <= max) {
      Console.WriteLine(1);
    } else {
      Console.WriteLine(0);
    }
  }
}


Measured memory_bytes: 13140
import sys


def solve(inp):
    A = list(map(int, inp.readline().strip().split(' ')))

    if A[0] % 3 == 0 or A[1] % 3 == 0 or sum(A) % 3 == 0:
        return "Possible"
    else:
        return "Impossible"


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
//20/07/2019
#include<bits/stdc++.h>

using namespace std;

#define debug printf("Debug\n");
#define ll long long
#define ull unsigned long long
#define pi acos(-1.0)
#define mod 1000000007

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_freopen  freopen("in.txt", "r", stdin);
#define out_freopen freopen("out.txt", "w", stdout);

vector<ll>vec;
ll a[200005];

int main(){
    ll n;

    scanf("%lld",&n);

    for(ll i=1;i<=n;i++){
        ll x;
        scanf("%lld",&x);
        a[i]=x;
        vec.push_back(x);
    }

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

    ll maxi,secndmaxi;
    maxi=vec[0];
    secndmaxi=vec[1];

    for(ll i=1;i<=n;i++){
        if(a[i]==maxi)
            printf("%lld\n",secndmaxi);
        else
            printf("%lld\n",maxi);
    }

    return 0;
}


Measured memory_bytes: 4848
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;

int main() {
	int W, H, N;
	cin >> W >> H >> N;

	int x, y, a;
	int w = 0, h = 0;
	for (int i = 0; i < N; i++) {
		cin >> x >> y >> a;
		if (a == 1) {
			if (x > w) w = x;
		}
		else if (a == 2) {
			if (x < W) W = x;
		}
		else if (a == 3) {
			if (y > h) h = y;
		}
		else {
			if (y < H) H = y;
		}
	}

	if (H <= h || W <= w) {
		cout << 0 << endl;
		return 0;
	}
	cout << abs(W - w) * abs(H - h) << endl;
}


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

int main() {
    int A, B, C;
    std::cin >> A >> B >> C;

    if (A == B) {
        std::printf("%d\n", C);
    } else if (B == C) {
        std::printf("%d\n", A);
    } else {
        std::printf("%d\n", B);
    }

    return 0;
}


Measured memory_bytes: 256
program main
     implicit none
     integer N, K
     integer Nk
     integer keta
     integer i
     
     read *,N, K
     
     keta=0
     Nk=N
     do i=1,1000000000
      Nk=Nk/K
      keta =keta+1
      if (Nk<K) then
       if ( i /= 1 ) keta=keta+1
       print '(i0)', keta
       exit
      end if
     end do
     
    endprogram main

Measured memory_bytes: 384
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<iostream>
#include<string>
#include<set>
#include<queue>
#include<random>

using namespace std;

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> st;*/

#pragma GCC optimize("Ofast")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")

#define pb push_back
#define ld long double
#define int long long

mt19937 rnd(51);

pair<int, int> func(string s) {
	bool x = 1;
	while (x && s.size() > 1) {
		x = 0;
		for (int i = 0; i < (int)s.size() - 1; i++) {
			if (s[i] == '(' && s[i + 1] == ')') {
				string s1 = "";
				for (int j = 0; j < i; j++) {
					s1 += s[j];
				}
				for (int j = i + 2; j < (int)s.size(); j++) {
					s1 += s[j];
				}
				s = s1;
				x = 1;
				break;
			}
		}
	}
	if (s.size() == 0) {
		return { 0, 0 };
	}
	int cnt = 0, cnt1 = 0;
	for (int i = 0; i < (int)s.size(); i++) {
		if (s[i] == ')') {
			cnt++;
		}
		else {
			cnt1++;
		}
	}
	return { cnt, cnt1 };
}

bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
	return a.first > b.first || (a.first == b.first && a.second < b.second);
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	vector<string> v(n);
	vector<pair<int, int>> a, b;
	int now = 0, del = 0;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		pair<int, int> p = func(v[i]);
		if (p.first == 0) {
			now += p.second;
		}
		else if (p.second == 0) {
			del += p.first;
		}
		else {
			if (p.second >= p.first) {
				a.pb(p);
			}
			else {
				b.pb(p);
			}
		}
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < (int)a.size(); i++) {
		if (now >= a[i].first) {
			now += a[i].second - a[i].first;
		}
		else {
			cout << "No";
			return 0;
		}
	}
	sort(b.begin(), b.end(), cmp);
	for (int i = 0; i < (int)b.size(); i++) {
		if (now >= b[i].first) {
			now += b[i].second - b[i].first;
		}
		else {
			cout << "No";
			return 0;
		}
	}
	if (now - del == 0) cout << "Yes";
	else cout << "No";
	return 0;
}


Measured memory_bytes: 34556
#include "bits/stdc++.h"
#define ll long long int
#define mp(a, b) make_pair(a, b)
using namespace std;
typedef pair<ll, ll> pairs;
typedef pair<ll, pairs> tpl;
ll dp[100001][3], a[100001], b[100001], c[1000001], n, k;
ll getans(ll i, ll f)
{
	if (i >= n)
		return 0;
	if (dp[i][f] != -1)
		return dp[i][f];
	if (f == 0)
		return dp[i][f] = max(getans(i + 1, 1) + b[i], getans(i + 1, 2) + c[i]);
	else if (f == 1)
		return dp[i][f] = max(getans(i + 1, 0) + a[i], getans(i + 1, 2) + c[i]);
	else
		return dp[i][f] = max(getans(i + 1, 1) + b[i], getans(i + 1, 0) + a[i]);
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (ll i = 0; i < n; i++)
		cin >> a[i] >> b[i] >> c[i];
	memset(dp, -1, sizeof(dp));
	cout << max(getans(0, 0), max(getans(0, 1), getans(0, 2)));
}

Measured memory_bytes: 12912
#include <iostream>

using namespace std;


//辺の長さが、a,b,cも時、三角形ができるかどうかを判定。できる場合はYESを返し、できない場合はNOを返す。
void judge_triangle(int a,int b,int c){
  int max = 0;
  bool flag = false;


  if( a*a+b*b==c*c || b*b+c*c==a*a || c*c+a*a == b*b){
    flag = true;
  }

  if(flag == true){
    cout <<"YES\n";
  }else {
    cout <<"NO\n";
  }

}

int main(){
  int data_length;
  int sides_length[] ={ -1,-1,-1};
  int i,j;

  cin >> data_length;

  for(i = 0;i < data_length;i++){
    for(j = 0;j<3;j++){
      cin >> sides_length[j];
      if(j==2){
        judge_triangle(sides_length[0],sides_length[1],sides_length[2]);
      }
    }
  }

  return 0;
}



Measured memory_bytes: 2940
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
int main(void){
    
    while(1){
        int n;
        scanf("%d",&n);
        if(n==0)break;
        double px[n],py[n],pz[n],vx[n],vy[n],vz[n],r[n],vr[n];
        for(int i=0;i<n;i++)scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&px[i],&py[i],&pz[i],&vx[i],&vy[i],&vz[i],&r[i],&vr[i]);
        vector<pair<double,pair<int,int> > > po;
        for(int i=0;i<n;i++)po.push_back(make_pair(r[i]/vr[i],make_pair(i,i)));
        for(int i=0;i<n;i++)for(int j=i+1;j<n;j++){
            double unkorx=px[j]-px[i];
            double unkory=py[j]-py[i];
            double unkorz=pz[j]-pz[i];
            double unkovx=vx[j]-vx[i];
            double unkovy=vy[j]-vy[i];
            double unkovz=vz[j]-vz[i];
            double aru=r[i]+r[j];
            double aruv=vr[i]+vr[j];
            double a=unkovx*unkovx+unkovy*unkovy+unkovz*unkovz-aruv*aruv;
            double b=unkorx*unkovx+unkory*unkovy+unkorz*unkovz+aru*aruv;
            double c=unkorx*unkorx+unkory*unkory+unkorz*unkorz-aru*aru;
            if(b*b>a*c){
                double ans1=(-b-sqrt(b*b-a*c))/a;
                double ans2=(-b+sqrt(b*b-a*c))/a;
                if(ans1>ans2){double yyy=ans1;ans1=ans2;ans2=yyy;}
                if(ans1>0)po.push_back(make_pair(ans1,make_pair(i,j)));
                else if(ans2>0)po.push_back(make_pair(ans2,make_pair(i,j)));
            }
        }
        sort(po.begin(),po.end());
        double kotae[n];
        for(int i=0;i<n;i++)kotae[i]=-1;
        for(int i=0;i<po.size();i++){
            if(kotae[po[i].second.first]<0&&kotae[po[i].second.second]<0){kotae[po[i].second.first]=po[i].first;kotae[po[i].second.second]=po[i].first;}
        }
        for(int i=0;i<n;i++)printf("%.10f\n",kotae[i]);
    }
    
    return 0;
}


Measured memory_bytes: 3660
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;

int ar[1000];

int main() {
	while (1) {
		int n;
		cin >> n;
		if (n == 0)break;
		for (int i = 0; i < n; i++)cin >> ar[i];

		sort(ar, ar + n);

		int ans = 99999999;

		for (int i = 0; i < n - 1; i++) {
			ans = min(ans, abs(ar[i] - ar[i + 1]));
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3148
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        abc157_c solver = new abc157_c();
        solver.solve(1, in, out);
        out.close();
    }

    static class abc157_c {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();
            int s[] = new int[M];
            int c[] = new int[M];
            int minn = 1;

            for (int i = 0; i < M; i++) {
                int inps = in.nextInt();
                int inpc = in.nextInt();
                //minn = Math.min(minn, inps);
                s[i] = inps;
                c[i] = inpc;
            }
            if (N == 1) {
                minn = 0;
            } else {
                for (int i = 0; i < N - 1; i++) {
                    minn *= 10;
                }
            }
            //minn *= 10;
            int res = -1;
            //for (int i = minn; i <= 999; i++) {
            for (int i = 0; i <= 999; i++) {
                //     int i = 700;
                if (String.valueOf(i).length() != N) {
                    continue;
                } else {
                    if (M == 0) {
                        out.println(i);
                        return;
                    }
                }
                boolean isthis = false;
                for (int j = 0; j < M; j++) {
                    if (String.valueOf(i).length() >= s[j]) {
                        char ci = String.valueOf(i).charAt(s[j] - 1);
                        char si = String.valueOf(c[j]).charAt(0);
                        if (ci == si) {
                            isthis = true;
                        } else {
                            isthis = false;
                            break;
                        }
                    } else {
                        isthis = false;
                        break;
                    }
                }
                if (isthis) {
                    out.println(i);
                    return;
                }
            }
            out.println("-1");

        }

    }
}



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

int sum(int n) {
  int a = 0;
  while (n > 0){
    a += n % 10;
    n /= 10;
  }
  return a;
}
int main() { 
  int n,a,b; cin >> n >> a >> b;
  int count = 0;
  for (int i = 1; i <= n; i++) {
    int count2 = sum(i);
    if (a <= count2 && count2 <= b) count += i;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define maxn 10010
char str[maxn];
int n,m,i,s=0,s1=0,s2=0,s3=0;
int main()
{
	scanf("%d",&n);
	for (;n;n--)
	{
		scanf("%s",str);
		m=strlen(str);
		for (i=0;i<m-1;i++)
			if ((str[i]=='A') && (str[i+1]=='B')) s++;
		if ((str[m-1]=='A') && (str[0]=='B')) s3++;
			else if (str[m-1]=='A') s1++;
				else if (str[0]=='B') s2++;
	}
	if (s3 && !s1) s1++,s3--;
	if (s3 && !s2) s2++,s3--;
	printf("%d\n",s+min(s1,s2)+s3);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
f = [0] * (10**4 + 1)
for x in range(1, 10**2):
    for y in range(1, x+1):
        for z  in range(1, y+1):
            tmp = x**2 + y**2 + z**2 + x*y + y*z + z*x
            s = set()
            s.add(x)
            s.add(y)
            s.add(z)
            if tmp <= 10**4:
                if len(s) == 3:
                    f[tmp] += 6
                elif len(s) == 2:
                    f[tmp] += 3
                else:
                    f[tmp] += 1
for i in range(1, N+1):
    print(f[i])

Measured memory_bytes: 9284
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=20;
long long inf;
long long a[N];
long long dp(int l,int r,long long xl,long long xr)
{
	//printf("%d,%d,%lld,%lld\n",l,r,xl,xr);
	if(l+1==r)
		return 0;
	long long ans=inf;
	//printf("%d,%d,%lld,%lld <%lld>\n",l,r,xl,xr,ans);
	int i;
	for(i=l+1;i<r;i++)
		ans=min(ans,dp(l,i,xl,xl+xr)+dp(i,r,xl+xr,xr)+(xl+xr)*a[i]);
	//printf("%d,%d,%lld,%lld  %lld\n",l,r,xl,xr,ans);
	return ans;
}
int main()
{
	inf=1<<30;
	inf<<=30;
	int n,i;
	long long ans;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		cin>>a[i];
	ans=dp(1,n,1,1);
	ans+=a[1]+a[n];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;

ll n,a[30],ans;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    for(ll i=0; i<n; i++) cin >> a[i];
    for(ll i=1; i<n-1; i++) if( a[i]>min(a[i-1],a[i+1]) && a[i]<max(a[i-1],a[i+1]) ) ans++;
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
X,Y = [],[]
for i in range(N):
    x,y = MI()
    X.append((x,i+1))
    Y.append((y,i+1))

X.sort()
Y.sort()


# Kruskal


class Kruskal():
    def __init__(self,n):
        self.e = []
        self.par = [i for i in range(n+1)]  # 親のノード番号
        self.rank = [0]*(n+1)
    def add(self,u,v,d):  # クラスカル法で考えるのは無向グラフ
        self.e.append([u,v,d])
    def find(self,x):  # xの根のノード番号
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def same_check(self,x,y):  # x,yが同じグループか否か
        return self.find(x) == self.find(y)
    def unite(self,x,y):  # x,yの属するグループの併合
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        elif self.rank[x] > self.rank[y]:
            self.par[y] = x
        else:
            self.par[y] = x
            self.rank[x] += 1
    def Kruskal(self):
        edges = sorted(self.e,key=lambda x: x[2])  # 距離でソート
        a = 0
        for e in edges:
            if not self.same_check(e[0],e[1]):
                self.unite(e[0],e[1])
                a += e[2]
        return a


K = Kruskal(N)
for j in range(N-1):
    x0,i0 = X[j]
    x1,i1 = X[j+1]
    K.add(i0,i1,x1-x0)
for j in range(N-1):
    y0,i0 = Y[j]
    y1,i1 = Y[j+1]
    K.add(i0,i1,y1-y0)

print(K.Kruskal())


Measured memory_bytes: 121084
N = int(input())
a_list = [int(input()) for _ in range(N)]

a_list.sort(reverse=True)

half = N // 2

ans1 = 0
ans2 = 0
for i in range(half):
    if i == half - 1:
        ans1 += a_list[i]
        ans1 -= a_list[-(i + 1)]
    else:
        ans1 += 2 * a_list[i]
        ans1 -= 2 * a_list[-(i + 1)]
ans2 = ans1
if N % 2 != 0:
    ans1 += a_list[half - 1]
    ans1 -= a_list[- (half + 1)]
    ans2 += a_list[half]
    ans2 -= a_list[- half]

print(max(ans1, ans2))


Measured memory_bytes: 7512
#include<iostream>
using namespace std;
int visit[101],d[101],f[101],t;
int n,M[101][101];

static const int WHITE=0;
static const int GRAY=1;

void dfs(int u){
  visit[u]=GRAY;
  d[u]=++t;
  for(int v=0;v<n;v++){
    if(M[u][v]==0) continue;
    if(visit[v]==WHITE){
      dfs(v);
    }
  }
  f[u]=++t; 
}

int main(){
  int u,v,k;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      cin>>v;
      v--;
      M[u][v]=1;
    }
  }

  for(int i=0;i<n;i++){
    if(visit[i]==WHITE){
      dfs(i);
    }
  }
  for(int i=0;i<n;i++){
    cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
  }
  return 0;
} 





Measured memory_bytes: 3144
using System;
using System.Collections.Generic;
using System.Linq;


namespace ConsoleApp15
{
    class Class284
    {
        static void Main()
        {
            var NX = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int N = NX[0];
            int X = NX[1];
            var x = Console.ReadLine().Split().Select(y=>Math.Abs(int.Parse(y)-X)).ToArray();
            int ans = x[0];
            for (int i = 0; i < N; i++)
            {
                ans = GCD(x[i], ans);
            }

            Console.WriteLine(ans);
        }
        static int GCD(int a,int b)
        {
            return a == 0 ? b : GCD(b % a, a);
        }
    }
}


Measured memory_bytes: 19680
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;cin>>s;
    sort(s.begin(),s.end());

    if(s[0] == s[1] && s[2] == s[3]
       && s[0]!=s[3]){
        cout<<"Yes"<<endl;
    }else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<set>
#include<queue>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;

#define pb push_back
#define PI acos(-1.0)
#define MAX 10000007 //1e7+7
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define __FastIO  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
ll arr[100005],brr[100005];
int main(){
  ll N,M,A,B,C,D,i,testCase;
  string str;
  while(cin>>str){
    bool flag=true;
    for(i=0;i<str.length();i++){
      if(i%2==0){
        if((str[i]!='R')&&(str[i]!='U')&&(str[i]!='D')){
          flag=false;
        }
      }
        else{
          if((str[i]!='L')&&(str[i]!='U')&&(str[i]!='D')){
            flag=false;
          }
        }
    }
    //cout<<0%2<<endl;
    if(!flag){
      cout<<"No"<<endl;
    }
    else{
      cout<<"Yes"<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vl =vector<ll>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define all(a) a.begin(),a.end()
struct UnionFind{
    vl par,rank;
    UnionFind(int x){par.resize(x); iota(all(par),0); rank.resize(x,0);}
    int find(int x){
        if(par[x] == x) return x;
        else return par[x]=find(par[x]);
    }
    void unite(int x, int y){ // xにyをつなぐ
        if(same(x,y))return;
        x=find(x); 
        par[y]=x;
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,q;
    while(cin>>n>>q, n){
        vl p(n,0);
        rep(i,n-1){cin>>p[i+1];p[i+1]--;}
        vector<char> type(q);
        vl query(q);

        vl marked(n,0);
        marked[0]=1;
        rep(i,q){
            char c; ll num;
            cin>>c>>num;
            type[i]=c;
            query[i]=num-1;
            if(c=='M'){
                marked[query[i]]++;
            }
        }
        
        UnionFind uf(n);
        rep(i,n)if(marked[i]==0){
            uf.unite(p[i], i);
        }

        ll ans=0;
        for(ll i=q-1; i>=0;i--){
            if(type[i]=='M'){
                marked[query[i]]--;
                if(marked[query[i]]==0){
                    uf.unite(p[query[i]], query[i]);
                }
            }else{
                ans += uf.find(query[i])+1;
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 7000
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
C.sort()

ans = 0
for b in B:
    i = bisect.bisect_left(A, b)
    j = bisect.bisect_right(C, b)
    ans += i * (N - j)

print(ans)

Measured memory_bytes: 23360
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

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

int main(){
    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll> a(n),sum_a(n+1,0);
    vector<ll> b(m),sum_b(m+1,0);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];
    sum_a[0] = 0;
    sum_b[0] = 0;
    
    int pos = 0;
    int ans = 0;
    rep(i,n){
        sum_a[i+1] = sum_a[i] + a[i];
    }
    rep(i,m){
        sum_b[i+1] = b[i] + sum_b[i];
        if(k < sum_b[i+1] && pos == 0){
            pos = i;
        }
    }
    if(pos == 0) pos = m;
    if(a[0] > k) pos = 0;
    ans = pos;
    
    reps(i,1,n+1){
        ll tmp = k - sum_a[i];
        if(tmp < 0) break;
        while(tmp < sum_b[pos]){
            if(pos>0) pos--;
            else break;
        }

        ans = max(ans,pos+i);
    }

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


Measured memory_bytes: 9596
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
const int MAXN=200000;
int panjang,dp[MAXN+5],kondisi=0;
map<int,int> posisi;
string input;
int ubah(char a){
	return a-'a';
}
int main()
{
	posisi.clear();
	cin>>input;
	panjang=input.length();
	dp[0]=0;
	posisi[kondisi]=1;
	for(int i=1;i<=panjang;i++)
	{
		assert(ubah(input[i-1])<26);
		kondisi^=(1<<ubah(input[i-1]));
		assert(kondisi<(1<<26));
		dp[i]=dp[i-1]+1;		//sebagai INF
		if(posisi.find(kondisi)!=posisi.end())
			dp[i]=min(dp[i],posisi[kondisi]);
		
		for(int j=0;j<26;j++)
		{
			kondisi^=(1<<j);
			/*if(j==ubah(input[i-1]))
			{
				assert(posisi.find(kondisi)!=posisi.end());
				assert(dp[posisi[kondisi]]<=dp[i-1]);
			}*/
			assert(kondisi<(1<<26));
			if(posisi.find(kondisi)!=posisi.end())
				dp[i]=min(dp[i],posisi[kondisi]);
			kondisi^=(1<<j);
		}
		if(posisi.find(kondisi)!=posisi.end())
			posisi[kondisi]=min(dp[i]+1,posisi[kondisi]);
		else
			posisi[kondisi]=dp[i]+1;
		assert(dp[i]<=i);
	}
	cout<<dp[panjang]<<endl;
}

Measured memory_bytes: 10756
using System;
using System.Linq;
class p
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int N = int.Parse(input[0]);
    int M = int.Parse(input[1]);
    int X = int.Parse(input[2]);
    int Y = int.Parse(input[3]);
    
    input = Console.ReadLine().Split(' ');
    int[] xArr = new int[N];
    for (int i = 0; i < N; i++) {
      xArr[i] = int.Parse(input[i]);
    }
    
    input = Console.ReadLine().Split(' ');
    int[] yArr = new int[M];
    for (int i = 0; i < M; i++) {
      yArr[i] = int.Parse(input[i]);
    }
    
    bool result = false;
    for (int z = X + 1; z <= Y; z++) {
      int x = xArr.Max();
      int y = yArr.Min();
      if (x < z && z <= y) {
        result = true;
        break;
      }
    }
    Console.WriteLine(result ? "No War" : "War");
  }
}


Measured memory_bytes: 13268
n,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(m)]
lis.sort(key=lambda x: x[1])
ans = 0
cou = 0
for num,nu in lis:
  if cou <= num:
    ans += 1
    cou = nu
print(ans)

Measured memory_bytes: 29084
import java.io.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int height[] = new int[10];
		int out[] = {0,0,0}; 
		for(int i = 0; i < 10; i++){
			try{
				height[i] = Integer.parseInt(in.readLine());
//				System.out.println(height[i]);
			}catch(IOException e){}
		}
		for(int i = 0; i < height.length; i++){
			if(out[0] < height[i] ){
				out[2] = out[1];
				out[1] = out[0];
				out[0] = height[i];
			}else if(out[1] < height[i]){
				out[2] = out[1];
				out[1] = height[i];
			}else if(out[2] < height[i]){
				out[2] = height[i];
			}
		}
		//out?????°????????????
		for(int i = 0; i < out.length; i++){
			System.out.println(out[i]);
		}
	}

}

Measured memory_bytes: 24332
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,l = inm()
a = inl()
for i in range(n-1):
    if a[i]+a[i+1]>=l:
        print('Possible')
        for j in range(i):
            print(j+1)
        for j in range(n-2,i-1,-1):
            print(j+1)
        exit()
print('Impossible')


Measured memory_bytes: 63856
import java.util.Scanner;

public class Main {
    static final long mod = 1000000007;
    static long dp[][] = new long[100010][2];

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        dp[0][0] = 1;
        for (int i = 1; i <= n; ++i) {
            dp[i][0] += dp[i - 1][0] + dp[i - 1][1];
            dp[i][0] %= mod;
            dp[i][1] += dp[i - 1][0] + dp[i - 1][1];
            dp[i][1] %= mod;
            if (i - m >= 0) {
                dp[i][1] = (dp[i][1] - dp[i - m][0] + mod) % mod;
            }
        }

        System.out.println((pow2(n) - (dp[n][0] + dp[n][1]) + mod * mod) % mod);
    }

    static long pow2(int k) {
        //v = 2^n mod 1e9+7
        long v = 1L;
        for (int i = 0; i < k; i++) {
            v *= 2L;
            v %= mod;
        }
        return v;
    }
}



Measured memory_bytes: 29884
#include <stdio.h>

int main(void) {
    int R,G,B,N,i,j,ans = 0;
    scanf("%d %d %d %d",&R,&G,&B,&N);
    for (i = 0;i * R <= N;i++) {
        for (j = 0;i * R + j * G <= N;j++) {
            if ((N - i * R - j * G) % B == 0) ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include<iostream> 
#include <list> 
#define N 100001
using namespace std; 
int n, loop;
int color=0;

int flag[N];

bool *visited = new bool[N];

class Graph{ 
    int V; 
    list<int> *adj; 
  
public: 
    void DFSUtil(int v); 
    Graph(int V);  
    void addEdge(int v, int w); 
    void connectedComponents(); 
}; 
  
void Graph::connectedComponents() { 
    for(int v = 0; v < V; v++){
        visited[v] = false; 
	}
  
    for (int v=0; v<V; v++) { 
        if (visited[v] == false) {
        	color++;
            DFSUtil(v); 
        } 
    } 
}
  
void Graph::DFSUtil(int v) 
{ 
    visited[v] = true;
    flag[v]=color;
    list<int>::iterator i; 
    for(i = adj[v].begin(); i != adj[v].end(); ++i){
        if(!visited[*i]){
            DFSUtil(*i); 
		}
	}
} 
  
Graph::Graph(int V) { 
    this->V = V; 
    adj = new list<int>[V]; 
} 
  
void Graph::addEdge(int v, int w) { 
    adj[v].push_back(w); 
    adj[w].push_back(v); 
} 

int main() {
  	int i, x,y,uji,j;
  	cin>>n>>loop;
	Graph g(n);
	 
	
	
  	for(i=0; i<loop; i++){
		cin>>x>>y;
		g.addEdge(x,y);
	}
	
	for(j= 0; j < n; j++){
	   visited[j] = false; 
	   flag[j]=0;
	}
	g.connectedComponents();
	
	cin>>uji;
	int prev=-1;
	for(i=0; i<uji; i++){
		cin>>x>>y;
		
		if(flag[y]==flag[x]){
			cout<<"yes"<<endl;
		}else{
			cout<<"no"<<endl;
		}
		prev=x;
	}
    return 0; 
} 


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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  deque<pair<int,int>> que;
  que.emplace_back(1 % n, 1);
  vector<bool> rec(n);
  while (!que.empty()) {
    int a, b;
    tie(a, b) = que.front();
    que.pop_front();
    if (rec[a]) {
      continue;
    }
    rec[a] = true;
    if (a == 0) {
      printf("%d\n", b);
      return 0;
    }
    que.emplace_front(a * 10 % n, b);
    que.emplace_back((a + 1) % n, b + 1);
  }
  assert(0);
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        int mod = 1000000007;
        for(int i=1;i<=k;i++){
            if(n-k+1<i){
                System.out.println(0);
            }else{
                long blue = nCkMod(k-1, i-1, mod);
                long red = nCkMod(n-k+1, i, mod);
                System.out.println((blue*red)%mod);
            }
        }
        sc.close();
    }

    public static long getPowMod(long a, long x,long mod){
        long res = 1;
        while(x > 0){
            if((x&1)==1){
                res = (res*a)%mod;
            }
            x>>=1;
            a = (a*a)%mod;
        }
        return res;
    }
    public static long getFactorialMod(long n,long mod){
        if(n==0){
            return 1;
        }else{
            return (n*getFactorialMod(n-1, mod))%mod;
        }
    }

    public static long nCkMod(long n,long k,long mod){
        if(n < k){
            return 0;
        }else{
            long nMod = getFactorialMod(n, mod);
            long kinvMod = getPowMod(getFactorialMod(k, mod), mod-2, mod);
            long n_kinvMod = getPowMod(getFactorialMod(n-k, mod), mod-2, mod);
            long x = (nMod*kinvMod)%mod;
            return (x*n_kinvMod)%mod;
        }
    }

}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define REP(i,  n) for (int i  =  0; i < (int)(n); ++i)
#define REPR(i,  n) for (int i  =  n - 1; i >= 0; --i)
using namespace std;

int main() {
  string S, T; cin >> S >> T;
  int L = S.size();
  int cnt = 0;
  REP(i, L) {
    if (S[i] != T[i]) ++cnt;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3820
s = input()
n = len(s)
p = 2019
ans = 0

num_rem = [0] * p
t = 1
mod = 0
num_rem[mod] = 1
for i in range(n):
    mod = (mod + int(s[-i-1])*t)%p
    num_rem[mod] += 1
    t = (10*t)%p
for m in num_rem:
    ans += (m*(m-1))//2
print(ans)

Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(b==100)
		cout<<b+1;
	else
		cout<<b;
		for(int i=1;i<=a;i++)
			cout<<"00";
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ui unsigned int
#define rui register ui
#define inl inline
#define rep(i,l,r) for(rui i=l,_=r;i<_;i++)
#define mxn 12
ui n,m,x,p[12];
bool f[1<<12],b[12][12];
char a[12][12];
inl ui rnd() {
	x^=x<<13;
	x^=x>>17;
	x^=x<<5;
	return x;
}
inl void rsh() {
	rep(i,1,n)
		swap(p[i],p[rnd()%i]);
}
int main() {
	srand(time(0));
	x=rand();
	scanf("%d%d",&n,&m);
	rep(i,0,n) p[i]=i;
	rep(i,0,n) scanf("%s",a[i]);
	ui y=CLOCKS_PER_SEC*15;
	while(clock()<<3<=y) {
		rsh();
		memset(b,1,sizeof(b));
		rep(i,0,m) rep(j,i,m) rep(k,0,n)
			if(a[p[k]][i]!=a[p[n-k-1]][j])
				b[i][j]=0;
		memset(f,0,sizeof(f));
		f[0]=1;
		rep(k,0,1<<m)	if(f[k])
			rep(i,0,m)	rep(j,i+1,m)
				if(!(1<<i&k)&&!(1<<j&k)&&b[i][j])
					f[k|(1<<i)|(1<<j)]=1;
		bool chk=0;
		if(!(m&1))
			chk=f[(1<<m)-1];
		else	rep(i,0,m)
			chk|=f[(1<<m)-1-(1<<i)];
		if(chk) {
			puts("YES");
			return 0;
		}
	}
	puts("NO");
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N, M;
  cin >> N >> M;
  vector<string> A(N), B(M);
  REP(i, N) cin >> A[i];
  REP(i, M) cin >> B[i];
  bool ok = false;
  REP(i, N - M + 1) {
    REP(j, N - M + 1) {
      bool t = true;
      REP(k, M) REP(l, M) {
        if (A[i + k][j + l] != B[k][l]) t = false;
      }
      if (t) {
        ok = true;
      }
    }
  }
  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3600
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = 105;
int n;
char tmp[maxn];
string s, t, ans;

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  scanf("%s", tmp);
  s = tmp;
  scanf("%s", tmp);
  t = tmp;
  return true;
}

void solve() {
  for (int len = n;; len++) {
    ans.resize(len);
    for (int i = 0; i < n; i++) {
      ans[i] = s[i];
    }
    for (int i = 0; i < n; i++) {
      ans[len - n + i] = t[i];
    }
    bool ok = true;
    for (int i = 0; i < n; i++) {
      if (ans[i] != s[i]) {
        ok = false;
      }
    }
    if (ok) {
      printf("%d\n", len);
      return;
    }
  }
}

int main() {
  precalc();
#ifdef LOCAL
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    class BIT:
        def __init__(self,n):
            self.num=n
            self.dat=[0]*(self.num+1)
            self.depth=n.bit_length()
        
        def add(self,i,x):
            i+=1
            while i<=self.num:
                self.dat[i]+=x
                i+=i&-i
        
        def sum(self,i):
            i+=1
            s=0
            while i>0:
                s+=self.dat[i]
                i-=i&-i
            return s
        
        def lower_bound(self,x):
            sum_=0
            pos=0
            for i in range(self.depth,-1,-1):
                k=pos+(1<<i)
                if k<=self.num and sum_+self.dat[k]<x:
                    sum_+=self.dat[k]
                    pos+=1<<i
            return pos, sum_
    
    N,Q=map(int,input().split())
    S,T,X=[0]*N,[0]*N,[0]*N
    for i in range(N):
        S[i],T[i],X[i]=map(int,input().split())
    unique_X=sorted(list(set(X)))
    d={unique_X[i]:i for i,x in enumerate(unique_X)}
    l=[0]*(N*2+Q)
    for i in range(N):
        l[i*2]=((S[i]-X[i])<<40)+(1<<20)+d[X[i]]
        l[i*2+1]=((T[i]-X[i])<<40)+d[X[i]]
    for i in range(N*2,N*2+Q):
        l[i]=(int(input())<<40)+(2<<20)
    l.sort()
    mask=(1<<20)-1
    b=BIT(len(unique_X))
    for tqx in l:
        x=tqx&mask
        q=(tqx>>20)&mask
        t=(tqx>>40)&mask
        if q==0:
            b.add(x,-1)
        elif q==1:
            b.add(x,1)
        else:
            res,_=b.lower_bound(1)
            print(unique_X[res] if res<len(unique_X) else -1)
        


if __name__ == '__main__':
    main()


Measured memory_bytes: 167384
n=int(input())
a=[int(i) for i in input().split()]
r='Yes'
for i in range(n-1):
  if a[-2-i]-a[-1-i]>1:
    r='No'
    break
  elif a[-2-i]-a[-1-i]==1:
    a[-2-i]=a[-2-i]-1
print(r)    

Measured memory_bytes: 14224
fn main() {
    let mut v = read_vec::<u32>();
    v.sort();
    let diff = (v[2] - v[0]) + (v[2] - v[1]);
    if diff % 2 == 0 {
        println!("{}", diff / 2);
    } else {
        println!("{}", diff / 2 + 2);
    }
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

typedef double Weight;
struct Edge {
  int src, dst;
  Weight weight;
  int c;                        // c ÍOtÅÍ§À¬xAqueue ÅÍ¬x
  Edge(int src, int dst, Weight weight, int c) :
    src(src), dst(dst), weight(weight), c(c){ }
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src :
    e.dst != f.dst ? e.dst < f.dst : e.c < f.c;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef pair<int,int> pii;

double dist[30][30][32];           // dist[i][j][k] = Xs[h k ÌóÔÅ j ©ç i ÉÂ­ÅZ£

double dijkstra(const Graph &g, int s, int t) {
  int n = g.size();
  REP(i,n) REP(j,n) REP(k,32) dist[i][j][k] = INF;
  priority_queue<Edge> Q;
  Q.push(Edge(s,s,0,0));
  int cnt = 0;
  while(!Q.empty()) {
    Edge e = Q.top(); Q.pop();
    if (e.dst == t && e.c == 1) break;
    REP(k,3) {
      int v = e.c - 1 + k;
      if (v<=0) continue;
      if (dist[e.dst][e.src][v] < e.weight) continue;
      FOR(f, g[e.dst]) {
        if (v > f->c) continue;
        if (f->dst == e.src) continue;
        double hoge = e.weight + f->weight / v;
        if (dist[f->dst][f->src][v] > hoge) {
          dist[f->dst][f->src][v] = hoge;
          Q.push(Edge(f->src, f->dst, hoge, v));
        }
      }
    }
    if (cnt++ > 200000) break;
  }

  double res = INF;
  REP(i,n)
    res = min(res, dist[t][i][1]);
  return res;
}

int main() {
  int n,m;
  while(cin >> n>>m,n||m) {
    int s,t;
    cin >> s >> t;
    s--;t--;
    Graph g(n);
    REP(i,m) {
      int x,y,d,c;
      cin >> x>>y>>d>>c;
      x--;y--;
      g[x].push_back(Edge(x,y,d,c));
      g[y].push_back(Edge(y,x,d,c));
    }
    double res = dijkstra(g,s,t);
    if (res == INF)
      cout << "unreachable" << endl;
    else
      printf("%.5f\n",res);
  }
}

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

using namespace std;

vector<int> prime_cnt(25);
/*
0:2
1:3
2:5
3:7
4:11
5:13
6:17
7:19
8:23
9:29
10:31
11:37
12:41
13:43
14:47
15:53
16:59
17:61
18:67
19:71
20:73
21:79
22:83
23:89
24:97
*/

int data_num[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
vector<int> prime_num(data_num, end(data_num));

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

    for(int i=1;i<=n;i++){
        int j=0, k=i;
        while(k!=1){
            if(k%prime_num.at(j)==0){
                prime_cnt.at(j)++;
                k /= prime_num.at(j);
            }
            else j++;
        }
    }

    /*
    for(int i=0;i<25;i++){
        cout << prime_num.at(i) << " : " << prime_cnt.at(i) << endl;
    }
    */

    int cnt = 0;
    for(int i=0;i<25;i++){
        if(prime_cnt.at(i) >= 74)cnt++;
        if(prime_cnt.at(i) >= 24){
            for(int j=0;j<25;j++){
                if((i!=j)&&(prime_cnt.at(j) >= 2))cnt++;
            }
        }
        if(prime_cnt.at(i) >= 14){
            for(int j=0;j<25;j++){
                if((i!=j)&&(prime_cnt.at(j) >= 4))cnt++;
            }
        }
        if(prime_cnt.at(i) >= 4){
            for(int j=i+1;j<25;j++){
                if(prime_cnt.at(j) >= 4){
                    for(int k=0;k<25;k++){
                        if((i!=k)&&(j!=k)&&(prime_cnt.at(k) >= 2))cnt++;
                    }
                }
            }
        }
    }

    cout << cnt << endl;

    return 0;
}

/*
a^2 * b^4 * c^4

a^2 * b^24

a^4 * b^14

a^74
*/

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define SUM(x) accumulate(ALL(x), 0)
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000

int main()
{
  int h, w; cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  REP(i, h) {
    string s_; cin >> s_;
    REP(j, w) {
      s.at(i).at(j) = s_[j];
    }
  }

  int bk = 0;
  int wh = 0;
  REP(i, h) {
    REP(j, w) {
      if (s.at(i).at(j) == '.') wh++;
      else bk++;
    }
  }

  if (wh == h * w) {
    cout << "Yes" << endl;
    return 0;
  }

  int cnt = 0;
  vector<int> di = { 0, -1, 0, 1 };
  vector<int> dj = { -1, 0, 1, 0 };
  REP(i, h) {
    REP(j, w) {
      if (s.at(i).at(j) == '.') continue;
      REP(d, 4) {
        int ni = i + di.at(d);
        int nj = j + dj.at(d);
        if (ni < 0 || h <= ni) continue;
        if (nj < 0 || w <= nj) continue;
        if (s.at(ni).at(nj) == '#') {
          cnt++;
          break;
        }
      }
    }
  }

  if (cnt == bk) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int yakusu(int a, int b) {
	int tmp, r;

	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

int main() {
	int N, i, A[100000], ans;

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

	ans = A[0];
	for (i = 1; i < N; i++) {
		ans = yakusu(ans, A[i]);
	}

	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 512
S = input()
ca = S.count("a")
cb = S.count("b")
cc = S.count("c")
n = min(ca,cb,cc)
ca2 = ca - n
cb2 = cb - n
cc2 = cc - n
flg = [ca2,cb2,cc2]
flg.sort()
if flg in [[0,0,0],[0,0,1],[0,1,1]]:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3188
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line = reader.readLine();
		int n = Integer.parseInt(line);
		int x[][] = new int[n][4];
		int y[][][] = new int[4][3][10];
		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 3; j++){
				for(int k = 0; k < 10; k++){
					y[i][j][k] = 0;
				}
			}
		}
		for(int l = 0; l < n; l++){
			String line1 = reader.readLine();
			String[] sarray = line1.split(" ", -1);
			for(int m = 0; m < 4; m++){
				x[l][m] = Integer.parseInt(sarray[m]);
			}
			y[x[l][0] - 1][x[l][1] - 1][x[l][2] - 1] += x[l][3];
		}
		for(int p = 0; p < 4; p++){
			for(int q = 0; q < 3; q++){
				for(int r = 0; r < 10; r++){
					System.out.print(" " + y[p][q][r]);
				}
				System.out.println();
			}
			if(p < 3){
				System.out.println("####################");
			}
		}
	}
}

Measured memory_bytes: 24700