akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<cstring>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int           long long
#define umapii        unordered_map<int,int>
#define ps(x,y)       fixed<<setprecision(y)<<x // sets precision upto required digits
#define arr(a,n)      int n;cin>>n;int a[n];for(int i=0;i<n;i++){cin>>a[i];}
#define outarr(a,n)   for(int i=0;i<n;i++){cout<<a[i]<<" ";}
#define mod           1000000007
#define ff            first
#define big           1e15
#define ss            second
#define add           push_back
#define remove        pop_back
#define mapii         map<int,int>
#define large         *max_element
#define small         *min_element
#define float         double
#define pqi           priority_queue<int>
#define mpqi          priority_queue<int,vector<int>,greater<int>>
#define in(n)         int n;cin>>n;
#define w(t)          int t;cin>>t;while(t--)
#define vi            vector<int>
#define vivi          vector<vector<int>>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>pbds;




char a[7][7];
char b[7][7];
int n, m, k;

void copymatrix() {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            b[i][j] = a[i][j];
        }
    }
}
void color(int i, int j) {
    for (int x = 0; x < n; x++) {
        if (i & (1 << x)) {
            for (int y = 0; y < m; y++) {
                b[x][y] = 'R';
            }
        }
    }
    for (int x = 0; x < m; x++) {
        if (j & (1 << x)) {
            for (int y = 0; y < n; y++) {
                b[y][x] = 'R';
            }
        }
    }
}
bool ok() {
    int count = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (b[i][j] == '#') {
                count++;
            }
        }
    }
    return count == k;
}
int32_t main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output3.txt", "w", stdout);
#endif

    cin >> n >> m >> k;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < (1 << m); j++) {
            copymatrix();
            color(i, j);
            if (ok()) {
                ans++;
            }
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 3648
//#include "pch.h"
#include <iostream>
#include<string>
#include<algorithm>
#include<iomanip>
#include<stdlib.h>

using namespace std;


int main() {

	int N,L;
	cin >> N>>L;

	int ap[210];
	int aps[210];

	for (int i = 0; i < N; i++) {
		ap[i] = L + i;
		aps[i]= abs(ap[i]);

	}
	
	sort(aps, aps + N);

	int ans=0;
	
	for (int i = 0; i < N; i++) {
		ans += ap[i];
	}
	
	if (ap[0]==aps[0]||ap[0]==aps[0 ]*(-1)){
		ans -= ap[0];
	}
	else if (ap[N-1] == aps[0] || ap[N-1] == aps[0] * (-1)) {
		ans -= ap[N-1];
	}
	
	

	cout << ans << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int a[100005];
int main()
{
	int N,i,j,m;
	cin>>N;
	for(i=1;i<=N;i++)
	{
		cin>>m;
		a[m]=i;
	}
	for(j=1;j<=N;j++)
	{
		cout<<a[j]<<" ";
	}
	return 0;
}

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

struct StCond                  // 材料質量・限界量
{
  int m_nWaterA;
  int m_nWaterB;
  int m_nSugerC;
  int m_nSugerD;
  double m_nConcE;
  int m_nLimitF;
};

struct StAmt                   // 使用量
{
  StAmt() : m_nAmtA(0), m_nAmtB(0), m_nAmtC(0), m_nAmtD(0) { }

  int m_nAmtA, m_nAmtB, m_nAmtC, m_nAmtD;
};

struct StRslt                  // 出力結果
{
  StRslt() : m_nAllMass(0), m_nSugerMass(0) { }

  int m_nAllMass, m_nSugerMass;
};

void fnInput(StCond& roCond)
{
  cin >> roCond.m_nWaterA >> roCond.m_nWaterB >> roCond.m_nSugerC >> roCond.m_nSugerD;
  cin >> roCond.m_nConcE  >> roCond.m_nLimitF;
}

void fnAmtClear(string sProc, const StCond& cnroCond, StAmt& roAmt)
{ 
  if      (sProc == "A")
    { roAmt.m_nAmtA = 0; roAmt.m_nAmtB = 0; roAmt.m_nAmtC = 0; roAmt.m_nAmtD = 0; }
  else if (sProc == "B")
    { roAmt.m_nAmtB = 0; roAmt.m_nAmtC = 0; roAmt.m_nAmtD = 0; }
  else if (sProc == "C")
    { roAmt.m_nAmtC = 0; roAmt.m_nAmtD = 0; }
  else if (sProc == "D")
    { roAmt.m_nAmtD = 0; }
}

int fnAmtSumup(string sProc, const StCond& cnroCond, const StAmt& cnroAmt)
{ 
  if (sProc == "ALL")
    return  (cnroCond.m_nWaterA * cnroAmt.m_nAmtA + cnroCond.m_nWaterB * cnroAmt.m_nAmtB) * 100
          + (cnroCond.m_nSugerC * cnroAmt.m_nAmtC + cnroCond.m_nSugerD * cnroAmt.m_nAmtD);
  else                       // sProc == "SUG"         
    return  (cnroCond.m_nSugerC * cnroAmt.m_nAmtC + cnroCond.m_nSugerD * cnroAmt.m_nAmtD);
}

double fnConcCalc(const StCond& cnroCond, const StAmt& cnroAmt)
{
  static double nLimtConc = 0.0;

  if (!nLimtConc)
    nLimtConc = cnroCond.m_nConcE / (100.0 + cnroCond.m_nConcE);

  double nNowConc =  (double)fnAmtSumup("SUG", cnroCond, cnroAmt)
                   / (double)fnAmtSumup("ALL", cnroCond, cnroAmt);

  if (nLimtConc < nNowConc)  return 0.0;
  else                       return nNowConc;
}

void fnConcCheck(const StCond& cnroCond, StRslt& roRslt)
{
  StAmt oAmt;
  double nMaxConc = -1.0;

  fnAmtClear("A", cnroCond, oAmt);
  while (true)
  {
    fnAmtClear("B", cnroCond, oAmt);
    if (fnAmtSumup("ALL", cnroCond, oAmt) > cnroCond.m_nLimitF)  break;

    if (!oAmt.m_nAmtA)  oAmt.m_nAmtB = 1;
    while (true)
    {
      fnAmtClear("C", cnroCond, oAmt);
      if (fnAmtSumup("ALL", cnroCond, oAmt) > cnroCond.m_nLimitF)  break;

      while (true)
      {
        fnAmtClear("D", cnroCond, oAmt);
        if (fnAmtSumup("ALL", cnroCond, oAmt) > cnroCond.m_nLimitF)  break;

        while (true)
        {
          if (fnAmtSumup("ALL", cnroCond, oAmt) > cnroCond.m_nLimitF)  break;

          double nNowConc = fnConcCalc(cnroCond, oAmt);
          if (nMaxConc < nNowConc)
          {
            nMaxConc = nNowConc;
            roRslt.m_nAllMass = fnAmtSumup("ALL", cnroCond, oAmt);
            roRslt.m_nSugerMass = fnAmtSumup("SUG", cnroCond, oAmt);
          }
          oAmt.m_nAmtD++;
        }
        oAmt.m_nAmtC++;
      }
      oAmt.m_nAmtB++;
    }
    oAmt.m_nAmtA++;
  }
}

int main()
{
  StCond oCond;
  StRslt oRslt;

  fnInput(oCond);
  fnConcCheck(oCond, oRslt);
  cout << oRslt.m_nAllMass << " " << oRslt.m_nSugerMass << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

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

        boolean isOdd = false;
        for (int i = 1; i < 4; i++) {
            if ((a * b * i) % 2 != 0) {
                isOdd = true;
                break;
            }
        }

        if (isOdd) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}


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

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  for (int i = 0; i < h; i++) {
    cin >> a[i];
  }

  vector<vector<bool>> used(h, vector<bool>(w, false));
  queue<pair<pair<int, int>, int>> q;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '#') {
        q.push({{i, j}, 0});
        used[i][j] = true;
      }
    }
  }

  int ans = 0;
  while (!q.empty()) {
    auto p = q.front(); q.pop();
    ans = max(ans, p.second);
    for (int i = 0; i < 4; i++) {
      int tx = p.first.first + dx[i];
      int ty = p.first.second + dy[i];
      if (0 <= tx && tx < h && 0 <= ty && ty < w && !used[tx][ty]) {
        q.push({{tx, ty}, p.second + 1});
        used[tx][ty] = true;
      }
    }
  }

  cout << ans << endl;

}


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

int main (int argc,char **argv)
{
	int a = 0,b = 0,c = 0,d = 0;
	int left = 0,right = 0;

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

	left = a + b;
	right = c + d;

	if (left > right)
	{
		printf("Left\n");
	}

	else if(left == right)
	{
		printf("Balanced\n");
	}

	else
	{
		printf("Right\n");
	}

	return 0;

}

Measured memory_bytes: 128
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        if (A <= 9 && B <= 9) {
            System.out.println(A*B);
        } else {
            System.out.println(-1);
        }
    }
}

Measured memory_bytes: 21844
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;

import static java.lang.StrictMath.sqrt;

/**
 * Wrong Answer
 */
class Main {
	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);

		Stack<Integer> stack = new Stack<Integer>();
		while(in.hasNext()) {
			int d = in.nextInt();
			if(d == 0) {
				int ans = stack.pop();
				System.out.println(ans);
			} else {
				stack.push(d);
			}
		}
	}
}

Measured memory_bytes: 26028
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
 
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 200005;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));

ll modularExponentiation(ll x,ll n)
{
    int result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%MOD;
        x=(x*x)%MOD;
        n=n/2;
    }
    return result;
}
ll ncr( ll n, ll c){
    ll t=1;
    c = min(c,n-c);
    for(ll i=1; i<=c ;i++)
        t= (t*(n-i+1))%MOD,t = (t*modularExponentiation(i,MOD-2))%MOD;
    return t;
}
void solve()
{
   ll n,a,b;
   cin >> n >> a >> b;
   ll ans = modularExponentiation(2,n);
   ans--;
   ans = (ans - ncr(n,a) + MOD)%MOD;
   ans = (ans - ncr(n,b) + MOD)%MOD;
   cout<<ans;
}

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


Measured memory_bytes: 256
sa=Array.new(4,0)
3.times{
	s,e=gets.split(" ").map(&:to_i)
	sa[s-1]+=1
	sa[e-1]+=1
}
cnt1=0
cnt2=0
sa.each{|f|
	if f==1
		cnt1+=1
	elsif f==2
		cnt2+=1
	end
}
if cnt1==2 && cnt2==2
	puts "YES"
else
	puts "NO"
end

Measured memory_bytes: 1788
while True:
    n=int(input())
    if n==0:
        break
    
    l=[0]*10
    for i in range(n):
        x=int(input())
        l[x]+=1
        
    for i in range(10):
        if l[i]==0:
            print("-")
        else:
            print("*"*l[i])


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

long long n;
string ans;

signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	while (n) {
		ans += char('a' + (n - 1) % 26);
		n = (n - 1) / 26;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << '\n';
}


Measured memory_bytes: 3644
def f(u, x)
  count = 0
  u.each { |i|
    count +=1 if x == i.sum
  }
  return count
end

while (n, x, = gets.split.map(&:to_i)) != [0, 0]
  a = [*1..n]
  u = a.combination(3).to_a
  puts f(u, x)
end


Measured memory_bytes: 60408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cstdlib>
using namespace std;

int maxfunc(long A, long B) {
    int resultA = 0;
    int resultB = 0;
    while(A != 0) {
        A = A / 10;
        ++resultA;
    }
    while(B != 0) {
        B = B / 10;
        ++resultB;
    }
    return std::max(resultA, resultB);
} 

int main()
{
    // 整数の入力
    long N, A, B;
  	int resulttmp;
    int result = 1000000;
    cin >> N;

    for (int i=1; i<= (int)sqrt(N); i++) {
        resulttmp = 0;
        if (N % i == 0) {
            A = i;
            B = N / A;
            resulttmp = maxfunc(A, B);
            if (result > resulttmp) {
                result = resulttmp;
            }
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
n=100000
p=[0]*2+[1]*(n-1)
for i in range(2,n+1):
  if p[i]:
    for j in range(i*2,n+1,i):
      p[j]=0
for i in range(1,n+1)[::-1]:
  if p[i]:
    if p[(i+1)//2]:
      continue
    p[i]=0
p[2]=0
c=[0]*(n+1)
for i in range(1,n+1):
  c[i]=c[i-1]+p[i]
q=int(input())
for i in range(q):
  l,r=map(int,input().split())
  print(c[r]-c[l-1])

Measured memory_bytes: 7140
main :: IO ()
main = do
    line <- getLine
    putStrLn $ eval (parseInts line)

parseInts :: String -> [Int]
parseInts line = map (\x -> read x :: Int) $ words line

eval :: [Int] -> String
eval [x, y, z]
    | x < y && y < z = "Yes"
    | otherwise      = "No"

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long  n,sub=0;
  long long sum=0;
  long long hig=0;
  cin>>n;
  int a[n+4]={};
  for(int i=0;i<n;i++){
  cin>>a[i];
  }
  hig=a[0];
  for(int i=1;i<n;i++){
    if(hig<a[i]){
      hig=a[i];
    }else{
       sub=hig-a[i];
       sum+=sub;
    }
    }
  cout<<sum<<endl;
  return(0);
}

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

int main(){
    int n,q;
    cin >> n;
    
    vector<int> s(n);
    rep(i,n) cin >> s[i];
    
    cin >> q;
    
    vector<int> t(q);
    rep(i,q) cin >> t[i];
    
    int cnt = 0;
    
    for(int i = 0; i < q; i++){
        for(int j = 0; j < n; j++){
            if(s[j]==t[i]){
                cnt++;
                break;
            }
        }
    }
    cout << cnt << endl;
    
}





Measured memory_bytes: 3140
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,k,s;
	cin >>n>>k>>s;
	Vi ans(n, 1e9);
	if(s==1e9){
		rep(i, n) { ans[i] = 1; }
	}
	rep(i, k) { ans[i] = s; }

	rep(i, n) { cout << ans[i];
	if(i!=n-1){
		cout << " ";
	} }
	cout << endl;
}

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

char ok[10];

int good(int n) {
	return n == 0 ? 1 : good(n / 10) && ok[n % 10];
}

int main() {
	int n, k;

	scanf("%d%d", &n, &k);
	memset(ok, 1, sizeof ok);
	while (k-- > 0) {
		int d;

		scanf("%d", &d);
		ok[d] = 0;
	}
	while (!good(n))
		n++;
	printf("%d\n", n);
	return 0;
}

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

long long n, q, a, b, c, s = 0, m[100010];
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a, m[a]++, s += a;
    cin >> q;
    for(int i = 0; i < q; i++) {
        cin >> b >> c;
        s += (c - b) * m[b];
        m[c] += m[b];
        m[b] = 0;
        cout << s << endl;
    }
}

Measured memory_bytes: 4360
#include <iostream>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>
#include <stack>

using namespace std;

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repl(i, n) for(LL i = 0; i < (LL)(n); i++)

int n, m, x;
bool found = false;

bool comp(vector<int> a, vector<int> b) {
  return a[0] < b[0];
}

int main(void){
  cin >> n >> m >> x;
  vector<vector<int> > vec(n, vector<int>(m+1, 0));

  rep(i, n) {
    cin >> vec[i][0];
    rep(j, m) {
      cin >> vec[i][j+1];
    }
  }

  sort(vec.begin(), vec.end(), comp);

  int min_total = INT_MAX;

  rep(i, pow(2, n)) {
    int total = 0;
    string b = bitset<12>(i).to_string();
    vector<int> skill(m, 0);

    rep(j, n) {
      vector<int> book = vec[j];
      if (b[11 - j] == '1') {
        rep(k, m) {
          skill[k] += book[k+1];
        }
        total += book[0];
      };
    }

    found = true;
    rep(j, m) {
      if (skill[j] < x) {
        found = false;
      }
    }

    if (found && (total < min_total)) {
      min_total = total;
    }
  }

  if (min_total == INT_MAX) {
    cout << "-1" << endl;
  } else {
    cout << min_total << endl;
  }

  return 0;
}

Measured memory_bytes: 4120
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------


int n;
void _main() {
	cin >> n;
	int p[20];
	rep(i, 0, n) {
		cin >> p[i];
	}
	int count = 0;
	int Jmax;
	int Jmin;
	rep(j, 1, n - 1) {
		Jmax = NULL;
		Jmin = inf;
		rep(k,j-1,j+2){
			Jmax = max(Jmax, p[k]);
			Jmin = min(Jmin, p[k]);
		}
		//cout << "p[j]=" << p[j] << endl;
		//cout << "Jmax" << Jmax << endl;
		//cout << "Jmin" << Jmin << endl;
		if (Jmax != p[j] && Jmin != p[j]) count++;
	}
	cout << count << endl;
}

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

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int n = sc.nextInt();
    if(n == 0){
      System.out.println(x);
      return;
    }
    int distance = 0;
    int answer = 0;
    List<Integer> list = new ArrayList();
    for(int i = 0; i < n; i++){
      list.add(sc.nextInt());
    }
    while(true){
      if(list.contains(x + distance)){
        if(distance < 0){
          distance = - distance;
        } else {
          distance = (distance + 1) * -1;
        }
      } else {
        answer = x + distance;
        break;
      }
    }
    System.out.println(answer);
  }
}

Measured memory_bytes: 35688
s = gets.chomp
n = s.length
v = s[0..((n - 1) / 2) - 1]
w = s[(((n + 3) / 2) - 1)..n]

if (s == s.reverse) && (v == v.reverse) && (w == w.reverse)
  puts "Yes"
else
  puts "No"
end


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

flag = 1
for i in range(1, N):
  if A[i] < A[i - 1]:
    flag = 0
    break
if flag:
  print(0)
  exit()

abs_max = -1
index = 0
for i, a in enumerate(A):
  if abs(a) > abs_max:
    abs_max = abs(a)
    index = i
    
answer = []
if A[index] > 0:
  for i in range(1, N):
    for _ in range(2):
      if A[i - 1] > A[i]:
        A[i] += abs_max
        answer.append((index + 1, i + 1))
        if A[i] > abs_max:
          abs_max = A[i]
          index = i
else:
  abs_max = -abs_max
  for i in range(N - 2, -1, -1):
    for _ in range(2):
      if A[i] > A[i + 1]:
        A[i] += abs_max
        answer.append((index + 1, i + 1))
        if A[i] < abs_max:
          abs_max = A[i]
          index = i

print(len(answer))
for a in answer:
  print(*a)

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

int main(void){
    int i=0,n,j,x,minv,maxv;
	
	scanf("%d",&n);
	
	int R[n];
	
	while((scanf("%d",&x)!=EOF)){
		R[i]=x;
		i++;
	}
	
	minv=R[0];
	maxv=R[1]-R[0];
	
	for(j=1;j<n;j++){
		
		if(maxv<R[j]-minv){
			maxv=R[j]-minv;
		}
		if(minv>R[j]){
			minv=R[j];
		}
	}
	
	printf("%d\n",maxv);
	
    return 0;
}



Measured memory_bytes: 2564
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
using namespace std;
#define MAX 5
set<int> leg;
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("in6.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    int T = 1;
    // cin >> T;
    
    FOR1(tt, T){
        // cout << "Case #" << tt << ": ";
        int a, b, c, d; cin >> a >> b >> c >> d;
        int p1 = a*c, p2 = a*d, p3 = b*c, p4 = b*d;
        cout << max({p1, p2, p3, p4});
        cout << '\n';
    }
    return 0;
}


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

vector<vector<int>> g(15, vector<int>(15, -1));

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    int m;
    cin >> m;
    rep(j, m) {
      int x, y;
      cin >> x >> y;
      g[i][x - 1] = y;
    }
  }

  int ans = 0;
  rep(i, 1 << n) {
    vector<int> d(n);
    rep(j, n) if (i&1<<j) d[j] = 1;
    bool ok = true;
    rep(j, n) {
      if (!d[j]) continue;
      rep(k, n) {
        if (g[j][k] == -1) continue;
        if (g[j][k] != d[k]) ok = false;
      }
    }
    if (ok) ans = max(ans, __builtin_popcount(i));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int bit = 0;
        for (int i=0; i<N; i++) {
            bit |= sc.nextInt();
        }
        System.out.println(Integer.numberOfTrailingZeros(bit));
    }
}

Measured memory_bytes: 23124
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
     string s[200005];
     long long n,i,t=1;
     cin>>n;
     for(i=1;i<=n;i++)
     {
         cin>>s[i];
     }
     sort(s+1,s+1+n);
     for(i=1;i<n;i++)
     {
         if(s[i]!=s[i+1])
         {
             t++;
         }
     }
     cout<<t<<endl;
     return 0;
}

Measured memory_bytes: 9896
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

const double EPS = 1e-8;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		vi data(n);
		rep(i, n)
			scanf("%d", &data[i]);
		
		int cnt = 0;
		rep(i, n-1){
			rep(j, n-i-1){
				if(data[j] > data[j+1]){
					swap(data[j], data[j+1]);
					++cnt;
				}
			}
		}
		
		printf("%d\n", cnt);
	}
	
	return 0;
}

Measured memory_bytes: 0
n = int(input())
lst = []
for i in range(1, n + 1):
    if i % 3 == 0:
        lst.append(i)
    if '3' in str(i):
        lst.append(i)

lst = set(lst)
lst = [str(i) for i in lst]
print(' ' + ' '.join(lst))



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

#define INF 1e9
#define LLINF 1e18
#define pi 3.14159265358979323
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int gcd(int a, int b) {
    if(a % b == 0) {
        return b;
    }
    else {
        return(gcd(b, a % b));
    }
}


int main() {
    int n;
    ll ans = 0;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    rep(i, n) {
        cin >> a.at(i);
    }
    rep(i, n) {
        cin >> b.at(i);
    }
    rep(i, n) {
        cin >> c.at(i);
    }
    sort(a.begin(), a.end());
    sort(c.begin(), c.end());
    rep(i, n) {
        auto itr = lower_bound(a.begin(), a.end(), b.at(i));
        auto itc = upper_bound(c.begin(), c.end(), b.at(i));
        ans += (itr - a.begin()) * (c.end() - itc);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4576
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(void)
{
    int n;
    int count=0,pa=0;
    int cost[100001];
    int a[100001];
    cin >> n ;
    cost[0] = 0;
    a[0] = 0;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        cost[i] = cost[i-1] + abs(a[i] - a[i-1]);
        //cout << a[i] << cost[i] << endl;
    }
    cost[n+1] = cost[n] + abs(a[n]);
    a[n+1] = 0;
    for(int i=1;i<=n;i++){
        if(a[i-1] < a[i] && a[i] < a[i+1] || a[i-1] > a[i] && a[i] > a[i+1])
            cout << cost[n+1] << endl; 
        else
            cout << cost[n+1] - 2 * (min(cost[i] - cost[i-1] , cost[i+1] - cost[i])) << endl;
    }
    return 0;
}

Measured memory_bytes: 2048
import           Control.Monad
import           Data.IORef
import           Data.List.Split
import           Data.Maybe
import           Data.List

main :: IO ()
main = do
  [k, s] <- map read . words <$> getLine

  print $ length
    [ 0 | x <- [0 .. k], y <- [0 .. k], k >= s - (x + y) && 0 <= s - (x + y) ]

Measured memory_bytes: 1148
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main() {
    int a,b,c,d,e;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    cin >> e;

    char lastChar = 'e';
    int minMod = 10;
    int m = a % 10;
    if (m > 0 && m < minMod) {
        minMod = m;
        lastChar = 'a';
    } 
    m = b % 10;
    if (m > 0 && m < minMod) {
        minMod = m;
        lastChar = 'b';
    } 
    m = c % 10;
    if (m > 0 && m < minMod) {
        minMod = m;
        lastChar = 'c';
    } 
    m = d % 10;
    if (m > 0 && m < minMod) {
        minMod = m;
        lastChar = 'd';
    }

    int time = 0;

    if (lastChar != 'a') {
        time += a;
        if (time % 10 > 0) {
            time = time + (10 - time % 10);
        }
    }
    if (lastChar != 'b') {
        time += b;
        if (time % 10 > 0) {
            time = time + (10 - time % 10);
        }
    }
    if (lastChar != 'c') {
        time += c;
        if (time % 10 > 0) {
            time = time + (10 - time % 10);
        }
    }
    if (lastChar != 'd') {
        time += d;
        if (time % 10 > 0) {
            time = time + (10 - time % 10);
        }
    }
    if (lastChar != 'e') {
        time += e;
        if (time % 10 > 0) {
            time = time + (10 - time % 10);
        }
    }

    switch (lastChar)
    {
        case 'a':
            time += a;
            break;
        case 'b':
            time += b;
            break;
        case 'c':
            time += c;
            break;
        case 'd':
            time += d;
            break;
        case 'e':
            time += e;
            break;
    }

    cout << time << endl;

    return 0;
}

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

int main() {
  long long top,under,x;cin >> under >> top >> x;
  under += (x-(under%x))%x;
  top -= top%x;
  //cout << under << top << endl;
  long long temp=top-under;
  long long ans;
  if(temp<-1) {
    ans =0;
  }
  else {
    ans = temp/x+1;
  }
  cout << ans << endl;
}

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


using namespace std;
const int maxn=1e5+5;
int gcd(int a , int b)
{
        return a%b==0? b:gcd(b,a%b);
}
inline LL quickread()
{
	LL X=0; bool flag=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
	while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
	if(flag) return X;
	return ~(X-1);
}
int main()
{
    int n,x,t;
    cin>>n>>x>>t;
    int ans;
    if(n%x==0)
        ans=(n/x)*t;
    else
        ans=((n/x)+1)*t;
    cout<<ans<<endl;

}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	int n,m;
	cin>>n>>m;
	int now=m,ans=m;
	vi a(n),b(n);
	rep(i,0,n) cin>>a[i]>>b[i];
	rep(i,0,n){
		now+=a[i]-b[i];
		ans=max(ans,now);
		if(now<0){
			o(0); return 0;
		}
	}
	o(ans);
}

Measured memory_bytes: 1272
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

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

    int first = S / 100;
    int second = S % 100;

    //cout << first << endl;
    //cout << second << endl;

    string ans;

    if (first == 0 && second == 0)
    {
        ans = "NA";
    }
    else if (first > 12 && second > 12)
    {
        ans = "NA";
    }
    else if (first >= 1 && first <= 12 && second >= 1 && second <= 12)
    {
        ans = "AMBIGUOUS";
    }
    else if (first >= 1 && first <= 12)
    {
        ans = "MMYY";
    }
    else if (second >= 1 && second <= 12)
    {
        ans = "YYMM";
    }
    else
    {
        ans = "NA";
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int n, x;
	cin >> n >> x;
	vector<int> l(n);
	REP(i, n) {
		cin >> l[i];
	}
	int cnt = 0;
	vector<int> dp(110);
	dp[0] = 0;
	REP(i, n) {
		dp[i+1] = l[i] + dp[i];
		if (dp[i+1] <= x) {
			cnt++;
		}
	}
	cout << cnt+1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main()
{
	int A,B,C,X,va=500,vb=100,vc=50,cnt=0;
	scanf("%d %d %d %d",&A,&B,&C,&X);
	for(int i=0;i<=A;i++)
		for(int j=0;j<=B;j++)
		{
			int res=X-i*va-j*vb;
			if(res<0)
				break;
			if(res%vc==0)
			{
				int num=res/vc;
				if(num<=C)
					cnt++;
			}
		}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 128
s = input()
dec = ["AKIHABARA","AKIHABAR","AKIHABRA","AKIHABR","AKIHBARA","AKIHBAR","AKIHBR","KIHABARA","KIHABAR","KIHABRA","KIHABR","KIHBARA","KIHBAR","KIHBRA","KIHBR"]
if s in dec:
	print("YES")
else:
	print("NO")

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

using namespace std;
int main() {
    int n;
    cin>>n;
    map<pair<long long, long long>, long long> cnt;
    for(int rep = 0; rep < n; ++rep) {
        double x;
        cin>>x;
        long long i = llround(x * 1e9);
        int two = 0, five = 0;
        while(i % 2 == 0) {
            two++;
            i /= 2;
        }
        while(i % 5 == 0) {
            five++;
            i /= 5;
        }
        ++cnt[{two,five}];
    }
    long long ans = 0;
    for(auto p1 : cnt) {
        for(auto p2 : cnt) {
            if(p1.first.first+p2.first.first >= 18 && p1.first.second+p2.first.second >= 18) {
                if(p1 < p2) {
                    ans +=  p1.second * p2.second;
                }
                else if(p1 == p2) {
                    ans +=  p1.second * (p1.second - 1) / 2;
                }
            }
        }
    }
    cout<<ans;
}

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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int x,N; cin >> x >> N;
    int p[N]; for(int i=0;i<N;i++) cin >> p[i];
    int ans=INF;
    int fans;
    for(int i=x-1000;i<=x+1000;i++){
        bool flag=true;
        for(int j=0;j<N;j++){
            if(p[j]==i) flag=false;
        }
        if(!flag) continue;
        if(ans>abs(x-i)){
            ans=abs(x-i);
            fans=i;
        }
    }
    cout << fans << endl;
}


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

data = {}
for i in range(1, N+1):
    a = i - A[i-1]
    if a in data:
        data[a] += 1
    else:
        data[a] = 1

ans = 0
for i in range(1, N+1):
    a = A[i-1]+i
    if a in data:
       ans += data[a]

print(ans)

Measured memory_bytes: 40540
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    ll h,w,n;
    cin >> h >> w >> n;
    ll a[n];
    for (ll i=0;i<n;i++)cin >> a[i];
    ll x[h*w],c=0;
    for (ll i=0;i<n;i++){
        for (ll j=0;j<a[i];j++){
            x[c]=i+1;
            c++;
        }
    }
    ll ans[h][w],o=0;
    for (ll i=0;i<w;i++){
        if (i%2){
            for (ll j=0;j<h;j++){
                ans[j][i]=x[o];
                o++;
            }
        }else{
            for (ll j=h-1;j>=0;j--){
                ans[j][i]=x[o];
                o++;
            }
        }
    }
    for (ll i=0;i<h;i++){
        for (ll j=0;j<w;j++){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3816
#include<bits/stdc++.h>
using namespace std;
// 12 10
// --------------------------------------------------------------------------------
#define fast_IO	ios_base::sync_with_stio(false),cin.tie(NULL),cout.tie(NULL);
#define ll long long 
#define mset(arr,val) memset(arr,val,sizeof(arr))
#define deb(name,value) cout <<"->>  "<<name<< "= " <<value<<" "
#define frepi(a,b,k) for(int i=a;i<=b;i+=k)
#define frepj(a,b,k) for(int j=a;j<=b;j+=k)
// --------------------------------------------------------------------------------


void solve()
{
    int n;cin>>n;
    vector<string>s(3);
    s[0]="hon";
    s[1]="pon";
    s[2]="bon";
    int r = n%10;
    if(r==2 || r==4 || r==5 || r==7 || r==9)
    {
    	cout<<s[0]<<"\n";
    	return;
    }
    if(r==3)
    {
    	cout<<s[2];
    	return;
    }
    cout<<s[1];
}

int main()
{
	// #ifndef ONLINE_JUDGE
 //    	freopen("/home/suryakant/input.txt","r",stdin);
 //        freopen("/home/suryakant/output.txt","w",stdout);
 //    #endif
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
    }
    
}


Measured memory_bytes: 3648
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a;
	cin>>a;
	cout<<a+a*a+a*a*a<<endl;


	return 0;
}


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main(){
  int i,j,k;
  string s;
  cin >> i;
  if(i<1200){
    cout << "ABC" << endl;
  }else if(i>=1200 && i<2800){
    cout << "ARC" << endl;
  }else{
    cout << "AGC" << endl;
  }
  return 0;
}


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

int main() {

  int N;
  cin >> N;

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

  long max = 0;

  for (int i = 0; i < N; i++) {
    max += a[i] - 1;
  }

  cout << max << endl;

}

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

int main() 
{
    int K,X;
    cin >> K >> X;

    vector<int> ans;
    int step = K-1;
    ans.push_back(X);

    for(int i=1;i<=step;i++) {
        ans.push_back(X+i);
        ans.push_back(X-i);
    }
    sort(ans.begin(),ans.end());
    for(int i=0;i<ans.size();i++) {
        cout << ans[i] << " ";
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
# define MOD 1000000000+7
# define INF 1000000000
typedef long long ll;
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }


int main() {
	int n = 0, ans = 0;
	int v[20] = {}, c[20] = {};
	int sa[20] = {};
	cin >> n;
	rep(i, n) {
		cin >> v[i];
	}
	rep(i, n) {
		cin >> c[i];
		sa[i] = v[i] - c[i];
	}
	sort(sa, sa + n, greater<int>());
	rep(i, n) {
		if (sa[i] > 0) {
			ans += sa[i];
		}
	}
	cout << ans << endl;

}




Measured memory_bytes: 256
import scala.io.StdIn._
object Main extends App{
  val sc = new java.util.Scanner(System.in)
  var a = sc.nextInt
  val b = sc.nextInt
  val c = sc.nextInt
  if(a+b>=c){
    println("Yes")
  }
  else{
    println("No")
  }
}

Measured memory_bytes: 25536
s = input()
for i, si in enumerate(s):
    if i % 2 == 0 and si not in ('R', 'U', 'D'):
        print('No')
        break
    elif i % 2 == 1 and si not in ('L', 'U', 'D'):
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 2940
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

using ll = long long;

int main() {
    ll k, n;
    cin >> k >> n;

    vector<ll> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    vector<ll> m(n);
    ll ma = 0;
    for (int i = 0; i < n-1; i++) {
        m[i] = abs(a[i+1] - a[i]);
        ma = max(ma, m[i]);
    }
    m[n-1] = (k - a[n-1]) + a[0];
    ma = max(ma, m[n-1]);
    
    ll ans = 0;
    
    for (int i = 0; i < n; i++) {
        ans += m[i];
    }
    cout << ans - ma << endl;
}

Measured memory_bytes: 3456
import java.util.*
 
fun main(args: Array<String>) {
  var count = readLine()!!.toInt()
  var nums = readLine()!!.split(" ").map{it -> it.toInt() }
  var descCount = 0
  var enable = true
  count = count - 1
  
  for ((index,num) in nums.withIndex()) {
    if (count-index != 0) {
      if (descCount >= 1) { // １つ前の処理で-1している
        if(nums[count-index].minus(1).minus(nums[count-index-1]) == -1) {
          descCount++
        } else if(nums[count-index].minus(1).minus(nums[count-index-1]) < -1) {
          enable = false
        } else {
          descCount = 0
        }
      } else { // していない=処理の余地がある
        if(nums[count-index].minus(nums[count-index-1]) == -1) {
          descCount++
        } else if(nums[count-index].minus(nums[count-index-1]) < -1) {
          enable = false
        } else { // する必要なし
        }
      }
    }
  }
  if (enable){
    println("Yes")
  } else {
    println("No")
  }
}

Measured memory_bytes: 57740
import javax.xml.crypto.Data;
import java.util.*;
import java.io.*;

public class Main {
    public static int SENTINEL = 100000007;
    public static int MAX = 10007;
    public static int NIL = -1;

    public static int[] Depth = new int[MAX];
    public static int[] Height = new int[MAX];
    public static Node[] Tree = new Node[MAX];
    public static int n;

    public static void main(String[] args) throws IOException {

        //??\???
        /*
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        */

        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        for(int i = 0; i < n; i++) {
            Tree[i] = new Node(NIL, NIL, NIL);
        }
        int v, l, r;
        for (int i = 0; i < n; i++) {
            v = sc.nextInt();
            l = sc.nextInt();
            r = sc.nextInt();
            Tree[v].left = l;
            Tree[v].right = r;
            if(l != NIL) Tree[l].parent = v;
            if(r != NIL) Tree[r].parent = v;
        }

        int root = 0;
        for(int i = 0; i < n; i++) {
            if(Tree[i].parent == NIL) root = i;
        }

        // ??????
        System.out.println("Preorder");
        preorder(root);
        System.out.println();
        System.out.println("Inorder");
        inorder(root);
        System.out.println();
        System.out.println("Postorder");
        postorder(root);
        System.out.println();
    }

    public static void preorder(int u) {
        if(u == NIL) return;
        System.out.printf(" %d", u);
        preorder(Tree[u].left);
        preorder(Tree[u].right);
    }
    public static void inorder(int u) {
        if(u == NIL) return;
        inorder(Tree[u].left);
        System.out.printf(" %d", u);
        inorder(Tree[u].right);
    }
    public static void postorder(int u) {
        if(u == NIL) return;
        postorder(Tree[u].left);
        postorder(Tree[u].right);
        System.out.printf(" %d", u);
    }

}

class Node {
    int parent;
    int left;
    int right;
    Node(int p, int l, int r) {
        parent = p;
        left = l;
        right = r;
    }
}

Measured memory_bytes: 26800
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A, B, C, D, E, K):
    a = A, B, C, D, E
    for p, q in combinations(a, r=2):
        if abs(p-q) > K:
            return ':('


    return 'Yay!'


def main():
    A = read_int()
    B = read_int()
    C = read_int()
    D = read_int()
    E = read_int()
    K = read_int()

    print(slv(A, B, C, D, E, K))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5484
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_139
{
    class E
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[][] others = new int[n][];
            for (int i = 0; i < n; i++) others[i] = ReadInts();
            int[] nows = new int[n];
            Queue<int> queue = new Queue<int>();
            for (int i = 0; i < n; i++)
            {
                queue.Enqueue((i + 1) * 10000 + others[i][0]);
            }
            var hashs = new HashSet<int>();
            int day = 0;
            while (queue.Count > 0)
            {
                day++;
                Queue<int> next = new Queue<int>();
                while (queue.Count > 0)
                {
                    int val = queue.Dequeue();
                    int me = val / 10000;
                    int other = val % 10000;
                    if (hashs.Contains(other * 10000 + me))
                    {
                        nows[me - 1]++;
                        nows[other - 1]++;
                        if (nows[me - 1] < n - 1)
                        {
                            next.Enqueue(
                                me * 10000 + others[me - 1][nows[me - 1]]);
                        }
                        if (nows[other - 1] < n - 1)
                        {
                            next.Enqueue(
                                other * 10000 + others[other - 1][nows[other - 1]]);
                        }
                        hashs.Remove(other * 10000 + me);
                    }
                    else
                    {
                        hashs.Add(val);
                    }
                }
                queue = next;
            }

            for(int i = 0; i < n; i++)
            {
                if (nows[i] < n-1)
                {
                    WriteLine(-1);
                    return;
                }
            }
            WriteLine(day);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 39052