akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, a, b);
    if(a > b) swap(a, b);
    Rep(b) cout << a;
    cout << endl;
}


Measured memory_bytes: 256
<?php
while(true){
  $deck = strtolower(trim(fgets(STDIN)));
  if($deck === "-") break;
  $time = intval(trim(fgets(STDIN)));
  for($i = 0;$i < $time;++$i){
    $h = intval(trim(fgets(STDIN)));
    $t = substr($deck, $h);
    $t .= substr($deck, 0, $h);
    $deck = $t;
  }
  print($deck . "\n");
}



Measured memory_bytes: 9216
s = input()
for i in range(1,len(s)+1):
    if i % 2 == 0:
        if s[i-1] not in ['L','U', 'D']:
            print('No')
            exit()
    else:
        if s[i-1] not in ['R','U','D']:
            print('No')
            exit()
print('Yes')

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		System.out.println((a + b + c) - Math.max(Math.max(a, b), c));

		sc.close();

	}

}

Measured memory_bytes: 35700
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
#define SEGMAX 131072
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
long long Comb(int n, int r)
{
	//n, rが負またはn<rの時は失敗
	if(n<0||r<0||n<r) return 0;

	//nCr=nCn-r
	r=(n<n-r)?n:(n-r);

	//r=0,1の時は計算する必要がない
	if(r==0) return 1;
	if(r==1) return n;

	vector<int> numerator(r), denominator(r);

	for(int k=0; k<r; k++){
		numerator[k]=n-r+k+1;
		denominator[k]=k+1;
	}

	for(int p=2; p<=r; p++){
		int pivot=denominator[p-1];
		if(pivot>1){
			int offset=(n-r)%p;
			for(int k=p-1; k < r; k+=p){
				numerator[k-offset]/=pivot;
				denominator[k]/=pivot;
			}
		}
	}

	long long result=1;
	for(int k=0; k<r; k++){
		if(numerator[k]>1) result*=numerator[k];
	}
	return result;
}
int main(void)
{
	int n, a, b;

	cin>>n>>a>>b;

	vll v(n);

	rep(i, n) cin>>v[i];

	sort(all(v)); reverse(all(v));

	int num=0;
	ll sum=0;
	long double ave=0;
	rep(i, b){
		sum+=v[i];
		if(i+1>=a){
			long double temp=(long double)sum/(long double)(i+1);
			if(ave<=temp){
				ave=temp; num=i;
			}
		}
	}
	
	int count0=0, count=0, count2=0, count3=0;
	rep(i, n){
		if(v[i]!=v[0]){
			break;
		}else{
			if(i<num+1) count0++;
			count++;
		}
	}
	if(v[0]!=v[num]){
		rep(i, n){
			if(v[i]<v[num]){
				break;
			}else if(v[i]==v[num]){
				if(i<num+1) count3++;
				count2++;
			}
		}
	}

	//cout<<num<<" "<<count0<<" "<<count<<endl;
	//cout<<num<<" "<<count2<<" "<<count3<<endl;

	cout<<setprecision(numeric_limits<long double>::max_digits10)<<ave<<endl;
	if(v[0]==v[num]){
		//cout<<(unsigned long long)(Comb(count, count0))*(((unsigned long long)1<<min(count, b))-1)<<endl;
		unsigned long long ans=0;
		repr(i, a, b+1){
			ans+=(unsigned long long)Comb(count, i);
		}
		cout<<ans<<endl;
	}else if(count2!=count3){
		cout<<Comb(count2, count3)<<endl;
	}else{
		cout<<1<<endl;
	}
}


Measured memory_bytes: 384
(defun count-div (v)
  (if (zerop v)
      0
      (multiple-value-bind (q r)
        (truncate v 2)
        (if (= 0 r)
            (1+ (count-div q))
            0))))

(let* ((n (read))
       (a (make-array n)))
  (dotimes (i n)
    (setf (aref a i) (read)))
  (format t "~A~%"
          (loop for ai across a
                minimize (count-div ai))))

Measured memory_bytes: 16864
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
long long modpow(long long m, long long n, long long modvalue) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2, modvalue);
        return t * t % modvalue;
    } else {
        return modpow(m, n - 1, modvalue) * m % modvalue;
    }
}

long long moddiv(long long a, long long b, ll modvalue) { return (a * modpow(b, mod - 2, modvalue)) % modvalue; }

const ll INF = 1LL << 60;

string change_binary(long long a) {
    string ret;
    for (int i = 31; i >= 0; i--) {
        ret += (a >> i & 1) + '0';
    }
    return ret;
}

ll nCkmod(ll n, ll k, ll modvalue) {
    ll numera = 1;
    for (int i = n; i > n - k; i--) {
        numera *= i;
        numera %= modvalue;
    }
    ll denomi = 1;
    REP(i, k) {
        denomi *= (i + 1);
        denomi %= modvalue;
    }
    return moddiv(numera, denomi, modvalue);
}

map<ll, ll> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}
int main() {
    ll n;
    cin >> n;
    vector<ll> as(n);
    REP(i, n) {
        cin >> as[i];
        as[i] -= i + 1;
    }
    sort(as.begin(), as.end());
    ll sum = 0;
    REP(i, n) { sum += abs(as[i] - as[n / 2]); }
    cout << sum << endl;
}

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

int n,m,ans;
int a[10],b[10];
string color[10];

vector<int> adj[10];

bool ch(){
  bool flag = true;
  for(int i=0;i<n;i++){
    if(color[i] == "White")
    flag = false;
  }
  if(flag){
    return true;
  }else{
    return false;
  }
}

void ini(){
  rep(i,n)color[i]="White";
}

void dfs(int now){

  if(ch()){
    ans++;
    return;
  }
  for(int i : adj[now]){
    if(color[i]=="White"){
      color[i]="Black";
      dfs(i);
      color[i]="White";
    }
  }

}
int main(){
  cin>>n>>m;
  rep(i,n)color[i]="White";

  int x,y;
  rep(i,m){
    cin>>x>>y;
    x--;y--;
    adj[x].push_back(y);
    adj[y].push_back(x);

  }
  int now=0;
  color[now]="Black";
  dfs(now);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;    
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    int r = scanf("%d", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    int r = scanf("%lld", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, double i)
{
    printf("%.20f", i);
    return my;
}

constexpr char BR = '\n';


///////////////////////////////////////////////////
#include <atcoder/math>
using namespace atcoder;

int main()
{
    int T;
    io >> T;
    for (int t = 0; t < T; t++)
    {
        ll N, M, A, B;
        io >> N >> M >> A >> B;
        io << floor_sum(N, M, A, B) << BR;
    }
    return 0;
}

Measured memory_bytes: 3768
//#pragma GCC optimize ('O3')
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 2e6 + 5;
const int M = 1e5 + 5;
const int OO = 2e9;
const int mod = 1e9 + 7;

int s1,s2;
string s;

void init() {



}

int main() {

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

    cin >> s;

    for (int i = 0; i < s.size(); ++i) {

        if(i&1) {

            if(s[i]=='1') ++s1;
            else ++s2;

        } else {

            if(s[i]=='0') ++s1;
            else ++s2;

        }

    }

    cout << min(s1, s2) << '\n';

    return 0;
}

Measured memory_bytes: 3748
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        a: u64, b: u64, c: u64, d: u64
    }
    let ceil = |x, y| x / y + (if x % y == 0 { 0 } else { 1 });
    let ans = if ceil(c, b) <= ceil(a, d) {
        "Yes"
    } else {
        "No"
    };
    println!("{}", ans);
}


Measured memory_bytes: 2164
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#ifdef BTK
#define DEBUG if(1)
#else
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
    
int main(){
    int N;
    cin>>N;
    map<int,int> cnt;
    vector<int> a(N);
    cin>>a;
    REP(i,N){
        cnt[a[i]]++;
    }
    int ret=0;
    auto f=[&](int X){
        return cnt[X-1]+cnt[X]+cnt[X+1];
    };
    REP(i,N){
        chmax(ret,f(a[i]-1));
        chmax(ret,f(a[i]));
        chmax(ret,f(a[i]+1));
    }
    cout<<ret<<endl;
    return 0;
}


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

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

    static class CFlipFlipAndFlip {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextInt(), m = in.nextInt();
            if (n > m) {
                long t = n;
                n = m;
                m = t;
            }

            assert n <= m;

            long answer;
            if (n >= 2) {
                answer = (n - 2) * (m - 2);
            } else if (m >= 2) {
                answer = m - 2;
            } else {
                answer = 1;
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



Measured memory_bytes: 23252
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long lint;

lint N;
const lint MAX_N = 100005;
lint a[MAX_N],b[MAX_N];

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

	cin >> N;
	for(lint i=0;i<N;i++){
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b,b+N);

	for(lint i=0;i<N;i++){
		a[i] = lower_bound(b,b+N,a[i])-b;
	}

	lint ans = 0;
	for(lint i=0;i<N;i++){
		ans += (a[i]^i)&1;
	}

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

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int a[200000];
signed main(){
	int n;scanf("%d",&n);
	rep(i,n)scanf("%d",&a[i]);
	map<int,int>mp;
	for(int i=0;i<n;i+=2){
		mp[a[i]]++;
	}
	map<int,int>mp2;
	for(int i=1;i<n;i+=2){
		mp2[a[i]]++;
	}
	vector<P>u,v;
	for(auto p:mp){
		u.push_back(p);
	}
	for(auto p:mp2){
		v.push_back(p);
	}
	sort(u.begin(),u.end(),[](P a,P b){return a.second>b.second;});
	sort(v.begin(),v.end(),[](P a,P b){return a.second>b.second;});
	int Max=0;
	rep(i,min(2,(int)u.size())){
		rep(j,min(2,(int)v.size())){
			if(u[i].first==v[j].first)Max=max(Max,max(u[i].second,v[j].second));
			else Max=max(Max,u[i].second+v[j].second);
		}
	}
	cout<<n-Max<<endl;
}

Measured memory_bytes: 6520
N,E=map(int,input().split())
G=[]
for i in range(E):
    a,b,c=map(int,input().split())
    G.append([-c,a-1,b-1])
def bellman_ford(G,s):
    INF=10**18
    d=[INF]*N
    d[s]=0
    j=0
    while(True):
        update=False
        for i in range(E):
            cost,fro,to=G[i]
            if d[fro]!=INF and d[to]>d[fro]+cost:
                d[to]=d[fro]+cost
                update=True
                if j==N-1 and to==N-1:
                    return True,0#負の閉路あり
        if j==N-1:
            return False,d
        j+=1
        if not(update):
            break
    return False,d#負の閉路なし、ｓからの最短距離ｄ
bool,d=bellman_ford(G,0)
if bool:
    print("inf")
else:
    print(-d[N-1])


Measured memory_bytes: 3404
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cstdint>

using namespace std;

struct Task
{
    int duration;
    int end;
};

Task task[200'000];
int lstart[200'000];

int main()
{
    int n;

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> task[i].duration >> task[i].end;
    }

    sort(task, task + n, [](const Task &l, const Task &r) {
        return l.end < r.end;
    });

    for (int i = n - 1; i >= 0; i--)
    {
        if (i == n - 1)
        {
            lstart[i] = task[i].end - task[i].duration;
            continue;
        }
        lstart[i] = min(task[i].end, lstart[i + 1]) - task[i].duration;
    }

    cout << (lstart[0] >= 0 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 2560
import math

N =int(input())
Xn = list(map(int ,input().split()))

Xn_2 = [x*x for x in Xn]

S_Xn = sum(Xn)
S_Xn_2 = sum(Xn_2)

P = S_Xn/N
P_min = math.floor(P)
P_max = math.ceil(P)

print(min(S_Xn_2-2*S_Xn*P_max+N*P_max*P_max,S_Xn_2-2*S_Xn*P_min+N*P_min*P_min))

Measured memory_bytes: 3064
N,M = gets.split.map(&:to_i)
XS = gets.split.map(&:to_i)

xs = XS.sort
ds = []
0.upto(XS.length-2) do |i|
  ds << xs[i+1] - xs[i]
end

ds.sort!

p (ds[0..-N].inject(&:+) || 0)

Measured memory_bytes: 10736
# include <bits/stdc++.h>
using namespace std;
long long n,r,k,ans,ans1,a[100005];
int main()
{
     cin>>n;
     for (long long  i=1; i<=n; i++)
     {
          cin>>a[i];
     }
     ans=1e9;
     for (long long  i=1; i<=1000; i++)
     {
          ans1=0;
          for(long long  j=1; j<=n; j++)
          {
               ans1+=((a[j]-i)*(a[j]-i));
          }
          ans=min(ans,ans1);
     }
     cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define M 11

int main(void){
  int i,j;
  int map[M][M];
  int curx=2,cury=0;
  int vector=6;
  char b,d,f,h,
       a,c,e,g,o;
  char way[100];
  char hoge;

  for(i=0;i<M;i++)
    for(j=0;j<M;j++)
      map[i][j]=8;

  for(i=1;i<=7;i+=2){
    scanf("%c%c%c%c%c",
        &b,&d,&f,&h,&hoge);
    map[i][2]=b-'0';
    map[i][4]=d-'0';
    map[i][6]=f-'0';
    map[i][8]=h-'0';
    scanf("%c%c%c%c%c%c",
        &a,&c,&e,&g,&o,&hoge);
    map[i+1][1]=a-'0';
    map[i+1][3]=c-'0';
    map[i+1][5]=e-'0';
    map[i+1][7]=g-'0';
    map[i+1][9]=o-'0';
  }
  scanf("%c%c%c%c%c",
      &b,&d,&f,&h,&hoge);
  map[9][2]=b-'0';
  map[9][4]=d-'0';
  map[9][6]=f-'0';
  map[9][8]=h-'0';

  map[cury][curx]=2;

  //L:curx--;
  //R:curx++;
  //U:cury--;
  //D:cury++;
  way[0]='R';
  for(i=1;(!(cury==2 && curx==2)) || vector!=4;i++)
    if(vector==6){
      way[i]='R'; curx+=2;
      map[cury][curx]=2;
            if(map[cury+1][curx]!=1){ vector=2; i--;
      }else if(map[cury][curx+1]!=1){ vector=6;
      }else if(map[cury-1][curx]!=1){ vector=8; i++; way[i]='U';
      }else if(map[cury][curx-1]!=1){ vector=4; i++;way[i]='U'; i++;way[i]='L';
      }
    }else if(vector==2){
      way[i]='D'; cury+=2;
      map[cury][curx]=2;
            if(map[cury][curx-1]!=1){ vector=4; i--;
      }else if(map[cury+1][curx]!=1){ vector=2;
      }else if(map[cury][curx+1]!=1){ vector=6; i++; way[i]='R';
      }else if(map[cury-1][curx]!=1){ vector=8; i++;way[i]='R'; i++;way[i]='U';
      }
    }else if(vector==4){
      way[i]='L'; curx-=2;
      map[cury][curx]=2;
            if(map[cury-1][curx]!=1){ vector=8; i--;
      }else if(map[cury][curx-1]!=1){ vector=4;
      }else if(map[cury+1][curx]!=1){ vector=2; i++; way[i]='D';
      }else if(map[cury][curx+1]!=1){ vector=6; i++;way[i]='D'; i++;way[i]='R';
      }
    }else if(vector==8){
      way[i]='U'; cury-=2;
      map[cury][curx]=2;
            if(map[cury][curx+1]!=1){ vector=6; i--;
      }else if(map[cury-1][curx]!=1){ vector=8;
      }else if(map[cury][curx-1]!=1){ vector=4; i++; way[i]='L';
      }else if(map[cury+1][curx]!=1){ vector=2; i++;way[i]='L'; i++;way[i]='D';
      }
    }
  way[i]=0;
  printf("%s\n",way);

  return 0;
}

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

template <int64_t N>
class modint {
    int64_t x;
public:
    modint(int64_t x = 0) : x((x % N + N) % N) {}
    modint operator-() const { return modint(-x); }
    modint& operator+=(const modint& a) { if ((x += a.x) >= N) x -= N; return *this; }
    modint& operator-=(const modint& a) { if ((x += N - a.x) >= N) x -= N; return *this; }
    modint& operator*=(const  modint& a) { (x *= a.x) %= N; return *this; }
    modint operator+(const modint& a) const { return modint(*this) += a; }
    modint operator-(const modint& a) const { return modint(*this) -= a; }
    modint operator*(const modint& a) const { return modint(*this) *= a; }
    modint pow(int64_t t) const {
        if (not t) return 1;
        modint a = pow(t >> 1); a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime mod
    modint inv() const { return pow(N - 2); }
    modint& operator/=(const modint& a) { return (*this) *= a.inv(); }
    modint operator/(const modint& a) const { return modint(*this) /= a; }
    friend ostream& operator<<(ostream& os, const modint& m){ os << m.x; return os; }
};

const int64_t mod = 1e9 + 7;
using mint = modint<mod>;

int main(){
    int n, k; cin >> n >> k; mint ans = 1;
    vector<int64_t> c;
    vector<pair<int64_t, bool>> d(n);
    for (auto i = 0; i < n; i++) {
        int64_t a; cin >> a;
        if(a < 0) c.push_back(a);
        d.push_back({abs(a), (a < 0)});
    }

    sort(c.begin(), c.end(), greater<>());
    if(k % 2 and (int)c.size() == n) { // 選ぶ個数が奇数かつ負の値しかない
        for (auto i = 0; i < k; i++) ans *= c[i];
        cout << ans << endl;
        return 0;
    }

    sort(d.begin(), d.end(), greater<>());
    bool minus = false; pair<int64_t, int64_t> prev(-1, -1), next(-1, -1);
    for (auto i = 0; i < k; i++) {
        ans *= ((d[i].second) ? -1 : 1) * d[i].first;
        if(d[i].second) minus = not minus, prev.second = -d[i].first;
        else prev.first = d[i].first;
    }
    if(k == n) {
        cout << ans << endl; return 0;
    }

    if(minus) {
        auto cnt = bitset<2>(3);
        for (auto i = k; i < n; i++) {
            if(d[i].second and cnt[0])
                next.second = -d[i].first, cnt[0] = false;
            else if(not d[i].second and cnt[1])
                next.first = d[i].first, cnt[1] = false;
        }
        if(prev.first == -1 or next.second == -1)
            ans /= prev.second, ans *= next.first;
        else if (prev.second == -1 or next.first == -1)
            ans /= prev.first, ans *= next.second;
        else {
            if(prev.first * next.first >= prev.second * next.second)
                ans /= prev.second, ans *= next.first;
            else
                ans /= prev.first, ans *= next.second;
        }
    }

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

Measured memory_bytes: 13064
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int H;
int W;
int A;
int B;
char res1[1002];
char res2[1002];
int main(){
  int i;
  rd(H);
  rd(W);
  rd(A);
  rd(B);
  for(i=(0);i<(W);i++){
    res1[i] = res2[i] = '0';
  }
  for(i=(0);i<(A);i++){
    res1[i] += 1;
  }
  for(i=(A);i<(W);i++){
    res2[i] += 1;
  }
  for(i=(0);i<(B);i++){
    wt_L(res1);
    wt_L('\n');
  }
  for(i=(B);i<(H);i++){
    wt_L(res2);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190921-1

// --- original code ---
// int H, W, A, B;
// char res1[1002], res2[1002];
// {
//   rd(H,W,A,B);
//   rep(i,W) res1[i] = res2[i] = '0';
//   rep(i,A) res1[i] += 1;
//   rep(i,A,W) res2[i] += 1;
//   rep(i,B) wt(res1);
//   rep(i,B,H) wt(res2);
// }


Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		
		while(input.hasNext()){
			String S = input.next();
			int[] countAlphbet = new int[26];
			
			for(int i = 0; i < S.length(); ++i){
				++countAlphbet[S.charAt(i) - 'a'];
			}
			
			boolean allExist = true;
			for(int i = 0; i < countAlphbet.length; ++i){
				if(countAlphbet[i] == 0){
					allExist = false;
					System.out.println((char)('a' + i));
					break;
				}
			}
			
			if(allExist){
				System.out.println("None");
			}
		}

	}

}


Measured memory_bytes: 25180
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int a[4];

int main () {
  string input; cin >> input;
  REP(i,4) a[i] = input[i]-'0';

  REP(b,1<<3) {
    int sum = a[0];
    string ans;
    ans += (char)('0' + a[0]);
    REP(i,3) {
      if (b&(1<<i)) {
        sum += a[i+1];
        ans += '+';
        ans += (char)('0'+a[i+1]);
      }
      else {
        sum -= a[i+1];
        ans += '-';
        ans += (char)('0'+a[i+1]);
      }
    }
    if (sum == 7) {
      ans += "=7";
      cout << ans << endl;
      return 0;
    }
  }
  return 0;
}

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

int N, M, p;
int ans = 99999999;
int d[10001];

int distanceA(int v)
{
	if (v >= p) return v - p;
	else return N - (p - v);
}
int distanceB(int v)
{
	if (v <= p) return p - v;
	else return N - (v - p);
}

int main()
{
	cin >> N >> M >> p;
	for (int i = 0; i < M; i++)
	{
		cin >> d[i];
	}
	d[M] = p;

	sort(d, d + M + 1);

	for (int i = 0; i <= M; i++)
	{
		int a = distanceA(d[i]);
		int b = distanceB(d[(i + 1) % (M + 1)]);
		if (a > b) swap(a, b);
		ans = min(ans, a * 2 + b);
	}
	cout << ans * 100 << endl;

	return 0;
}

Measured memory_bytes: 1216
/*==============================================*\
Codeforces ID:    mdshihab
                                                  |
Name:     Md. Shihabul Minhaz                     |
Study:      CSE, JKKNIU                           |
Address:  Trishal, Mymensingh, Bangladesh         |
                                                  |
 mail:   mdshihabul20171@gmail.com                |
 FB  :   fb.com/mdshihabul.minhaz.7               |
 github: Shihabulminhaz                           |
stopstalk :  mdshihab                             |
                                                  |
@uthor   Md. Shihabul Minhaz (shihab)             |
\*===============================================*/


#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void FI()
{
#ifndef ONLINE_JUDGE
    freopen("C:\\Users\\SHIHAB\\Desktop\\input.in","r",stdin);
#endif // ONLINE_JUDGE
}

int main()
{
    fast
    FI(); /// skip this line for compile
    int n,m,d,cnt=0;
    string s;
    cin >> n >> m >> d;
    for(int i=n;i<=m;i++){
        if(i%d==0) cnt++;
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 3644
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif
using namespace std;

int main() {
    int m, d;
    cin >> m >> d;
    int m2, d2;
    cin >> m2 >> d2;
    cout << (d + 1 != d2 ? 1 : 0) << endl;
    return 0;
}


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

using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;

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

	int A, B;
	cin >> A >> B;
	cout << A*B << endl;

	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main () {
  double A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  double ans = -1, w = 0, s = 0;
  vector<double> water(31), salt(1501);
  water.at(0) = 1, salt.at(0) = 1;
  for(int i = 0; i + A <= 30; i++){
    if(water.at(i) == 1){
      water.at(i + A) = 1;
    }
  }
  for(int i = 0; i + B <= 30; i++){
    if(water.at(i) == 1){
      water.at(i + B) = 1;
    }
  }
  for(int i = 0; i + C <= 1500; i++){
    if(salt.at(i) == 1){
      salt.at(i + C) = 1;
    }
  }
  for(int i = 0; i + D <= 1500; i++){
    if(salt.at(i) == 1){
      salt.at(i + D) = 1;
    }
  }
  for(double i = 1; i < water.size(); i++){
    if(water.at(i) == 0)continue;
    for(double j = 0; j < salt.size(); j++){
      if(salt.at(j) == 0)continue;
      if(i * 100 + j > F || i * E < j)break;
      if(j * 100 / (i * 100 + j) > ans){
        ans = j * 100 / (i * 100 + j);
        w = i * 100 + j;
        s = j;
      }
    }
  }
  cout << w << ' ' << s << endl;
  return 0;
}

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

int main(){
    int n, x;
    cin >> n >> x;
    int now = 0;
    int cnt = 0;
    for(int i = 0; i < n; i++) {
        int l;
        cin >> l;
        if(now <= x) cnt++;
        now += l;
    }
    if(now <= x) cnt++;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
 
int main(){
    string str;
    string str1="CF";
    while (cin >> str){
        int a=0, b = 0;
        while (a < str.length()&&b<str1.length()){
            if (str[a++] == str1[b])
                b++;
 
        }
        if (b == str1.length())
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
 
}

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

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

  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  for (int i = 0; i + 2 < n; ++i) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
      ans++;
    }
  }
  cout << ans << "\n";

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

ll A[MAXN];
ll F[MAXN];

bool ok(ll n,ll k,ll x)
{

    ll res = 0;
    ll cur;

    for(int i=0;i<n;i++){
        cur = x/F[i];
        res+=max(A[i]-cur,0LL);
    }

    return (k>=res);
}

int main()
{
    ll n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

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

    cin>>n>>k;

    for(int i=0;i<n;i++)
        cin>>A[i];

    for(int i=0;i<n;i++)
        cin>>F[i];

    sort(A,A+n,greater<int>());
    sort(F,F+n);

    ll L = 0;
    ll R = 1000000000000LL;
    ll mid,ans = -1;

    while(L<=R){
        mid = (L+R)>>1;
        if(ok(n,k,mid))ans = mid,R = mid-1;
        else L = mid+1;
    }

    cout<<ans<<"\n";

    return 0;
}


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

int main(void){
    int R;
    cin >> R ;
    cout << 2 * M_PI * R << endl;
    return 0;
}

Measured memory_bytes: 3708
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll a,b ;
	cin >> a >> b ;
	a-- ;
	ll ans = 0 ;
	ll num = 1 ;
	for(int i=0;i<50;i++){
		num *= 2 ;
		ll sub = a/num*num/2 ;
		if(a%num>=num/2) sub += a%num-num/2+1 ;
		ll sub2 = b/num*num/2 ;
		if(b%num>=num/2) sub2 += b%num-num/2+1 ;
		sub2 -= sub ;
		if(sub2&1) ans += num/2 ;
	}
	cout << ans << endl ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll H,W,h,w;
    cin >>H>>W>>h>>w;
    
    cout << (H-h)*(W-w) << endl;


    return 0;
    

}

Measured memory_bytes: 3616
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using LL = long long int;
using ULL = unsigned long long;

LL dp[100001][13];
const ULL MOD = 1000000007LL;

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

    dp[0][0] = 1;
    rep(i, str.length()) {
        int c = 0;
        if (str[i] == '?') c = -1;
        else c = str[i] - '0';

        rep(j, 10) {
            if (c != -1 and c != j) continue;

            rep(ki, 13) {
                dp[i + 1][(ki * 10 + j) % 13] += dp[i][ki];
            }
        }
        rep(j, 13) {
            dp[i + 1][j] %= MOD;
        }
    }
    LL res = dp[str.length()][5];
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 10688
S = input()

ans = 0

for i in range(len(S)):
    n = 0
    for j in range(i, len(S)):
        if S[j] == 'A' or S[j] == 'C' or S[j] == 'T' or S[j] == 'G':
            n += 1
        else:
            break
    ans = max(ans, n)

print(ans)


Measured memory_bytes: 2940
# AtCoder Beginner Contest 128 C - Switches

import sys

N, M = map(int, sys.stdin.readline().strip().split())

S = [[0] * N for _ in range(M)]
for i in range(M):
    _, *s = map(int, sys.stdin.readline().strip().split())
    for j in s:
        S[i][j-1] = 1
p = list(map(int, sys.stdin.readline().strip().split()))

ans = 0
for i in range(2 ** N):
    bit = [(i >> j) & 1 for j in range(N)]
    for i, s in enumerate(S):
        o_e = sum([x * y for x, y in zip(s, bit)]) % 2
        if o_e != p[i]:
            break
    else:
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
using namespace std;

vector<vector<int> > rot = {
	{0,1,2,3,4,5}, {0,2,4,1,3,5}, {0,4,3,2,1,5}, {0,3,1,4,2,5},
	{1,5,2,3,0,4}, {1,2,0,5,3,4}, {1,0,3,2,5,4}, {1,3,5,0,2,4},
	{2,5,4,1,0,3}, {2,4,0,5,1,3}, {2,0,1,4,5,3}, {2,1,5,0,4,3},
	{3,4,5,0,1,2}, {3,5,1,4,0,2}, {3,1,0,5,4,2}, {3,0,4,1,5,2},
	{4,0,2,3,5,1}, {4,2,5,0,3,1}, {4,5,3,2,0,1}, {4,3,0,5,2,1},
	{5,4,2,3,1,0}, {5,2,1,4,3,0}, {5,1,3,2,4,0}, {5,3,4,1,2,0}
};

vector<vector<vector<int> > > cond = {
	{},
	{{3,0,2}},
	{{1,1,4}},
	{{1,0,4},{2,2,3}},
	{{0,3,5}},
	{{0,2,5},{3,4,2}},
	{{0,1,5},{4,5,1}},
	{{0,0,5},{2,6,3},{4,4,1}}
};

struct State { int id, r; };
State pz[8];

string dice[8];
bool used[8];

char toggleCase(char c) {
	if (islower(c)) return toupper(c);
	return tolower(c);
}

string solve(int x) {
	if (x == 8) return "YES";
	for (int i=1; i<8; ++i) {
		if (used[i]) continue;
		for (int j=0; j<24; ++j) {
			pz[x].id = i;
			pz[x].r = j;
			bool ok = true;
			for (int k=0; k<(int)cond[x].size(); ++k) {
				int bloc1 = x;
				int face1 = rot[pz[bloc1].r][cond[x][k][0]];
				int bloc2 = cond[x][k][1];
				int face2 = rot[pz[bloc2].r][cond[x][k][2]];
				if (toggleCase(dice[pz[bloc1].id][face1]) != dice[pz[bloc2].id][face2]) {
					ok = false; break;
				}
			}
			if (ok) {
				used[i] = true;
				if (solve(x+1) == "YES") return "YES";
				used[i] = false;
			}
		}
	}
	return "NO";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	while (cin >> dice[0], dice[0] != "0") {
		for (int i=1; i<8; ++i) {
			cin >> dice[i];
		}
		memset(used, false, sizeof used);
		used[0] = true;
		pz[0].id = 0;
		string res = "NO";
		for (int i=0; i<24; ++i) {
			pz[0].r = i;
			if (solve(1) == "YES") {
				res = "YES"; break;
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<algorithm>
#include<iomanip>
#include<typeinfo>
#include<complex>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(ll i = a;i < b; i++)

int main() {

	int n;
	cin >> n;

	int suma = 0, sumb = 0;

	vector<int> w(n);
	rep(i, 0, n) {
		cin >> w[i];
		if (i != 0) sumb += w[i];
		else suma += w[i];
	}

	int diff = sumb - suma, mini = abs(diff);

	rep(i, 1, n - 1) {
		suma += w[i];
		sumb -= w[i];
		diff = sumb - suma;
		diff = abs(diff);
		mini = min(diff, mini);
	}

	cout << mini << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int i;
  char a[26]={0},ch;
  while((ch = getchar()) != EOF){
    if(('a' <= ch) && (ch <= 'z')){
      a[ch-'a']++;
    }
    else if(('A' <= ch) && (ch <= 'Z')){
      a[ch-'A']++;
    }
  }
  for(i='a'; i<='z'; i++){
    printf("%c : %d\n",i,a[i-'a']);
  }
  return 0;
}

Measured memory_bytes: 524
import heapq
from math import ceil


def main():
    N, M = map(int, input().split())

    # As heapq.heappop returns the mininum value of the sequence,
    # we need to multiply -1 in order to attain the maximum
    # value of the sequence.
    A = list(map(lambda x: (-1) * int(x), input().split()))
    heapq.heapify(A)
    for i in range(M):
        heapq.heappush(A, ceil(heapq.heappop(A) / 2))

    print(-sum(A))


if __name__ == '__main__':
    main()

Measured memory_bytes: 96792
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long

string S;
string T;

signed main(void){
	cin >> S;
	cin >> T;
	string ans("No");

	rep(i,S.length()) {
		string tmp;
		tmp = S[S.length()-1];
		S.pop_back();
		tmp += S;
		S = tmp;

		if (S == T) {
			ans = "Yes";
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int[] a = new int[n];
		boolean[] vis = new boolean[n];
		for(int i = 0;i < n;i++){
			a[i] = saori.saori_hayami() - 1;
		}
		int ans = 0;
		for(int i = 0;i < n;i++){
			int num = a[i];
			if(i == a[num] && !vis[num]){
				ans++;
				vis[i] = true;
				vis[num] = true;
			}
		}
		System.out.println(ans);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 23824
#include <stdio.h>
#define MIN(a, b) ((a) < (b)) ? (a) : (b)
int main(int argc, const char *argv[])
{
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  int ans = MIN(b / a, c);
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
'''
問題：
    高橋君と青木君がモンスターを闘わせます。

    高橋君のモンスターは体力が A で攻撃力が B です。
    青木君のモンスターは体力が C で攻撃力が D です。

    高橋君→青木君→高橋君→青木君→... の順に攻撃を行います。
    攻撃とは、相手のモンスターの体力の値を自分のモンスターの攻撃力のぶんだけ減らすことをいいます。
    このことをどちらかのモンスターの体力が 0 以下になるまで続けたとき、
    先に自分のモンスターの体力が 0 以下になった方の負け、そうでない方の勝ちです。

    高橋君が勝つなら Yes、負けるなら No を出力してください。
'''

'''
制約：
    1 ≦ A, B, C, D ≦ 100
    入力は全て整数である
'''
class Monster:
    def __init__(self, hp, power):
        self.hp = hp
        self.power = power

    def fight(self, power)  -> int:
        self.hp -= power
        return self.hp

    def is_loser(self)   -> bool:
        return self.hp <= 0

# 標準入力から A, B, C, D を取得する
a, b, c, d = map(int, input().split())

takahashi_monster = Monster(a, b)   # 高橋モンスター
aoki_monster = Monster(c, d)    # 青木モンスター
result = "ret"

while True:
    aoki_monster.fight(b)   # 高橋の攻撃
    if aoki_monster.is_loser():
        result = "Yes"
        break

    takahashi_monster.fight(d)  # 青木の攻撃
    if takahashi_monster.is_loser():
        result = "No"
        break

print(result)


Measured memory_bytes: 9208