akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class Task {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int k = in.nextInt(), a = in.nextInt(), b = in.nextInt();
            for (int i = a; i <= b; ++i) {
                if (i % k == 0) {
                    out.println("OK");
                    return;
                }
            }
            out.print("NG");
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 32468
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

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

  int n; cin >> n;
  map<ll,ll,greater<ll>> a;

  rep(i, n) {
    ll x; cin >> x;
    ++a[x];
  }

  ll ans = 0;
  vll x, y;

  for (auto e : a) {
    if (e.se >= 4) x.eb(e.fi);
    if (e.se >= 2) y.eb(e.fi);
  }

  for (auto e : x) chmax(ans, e * e);
  sort(all(y),greater<ll>());

  if (si(y) >= 2) chmax(ans, y[0] * y[1]);

  cout << ans << endl;

  return (0);
}


Measured memory_bytes: 9776
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,x,y,s1=0,s2=0,s3=0,s4=0,t,z=0,d;
    cin>>a>>b>>c>>x>>y;
    s1 = a*x + b*y;
    //cout<<s1<<endl;
    //d[0] = s1;
    if(x < y)
    {
        s2 = (x+x)*c;
        s2 += (y-x)*b;
        d = min(s1,s2);
        z = (y+y)*c;
        t = min(d,z);
        //d[1] = s2;
    }
    else if(x > y)
    {
        s3 = (y+y)*c;
        s3 += (x-y)*a;
        //cout<<s3<<endl;
        //d[2] = s3;
        d = min(s1,s3);
        z = (x+x)*c;
        t = min(d,z);
    }
    if(x == y)
    {
        s4 = (x+x)*c;
        t = min(s1,s4);
    }


    cout<<t<<endl;


}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
const int N  = 3e5 + 5;

int n, m, fen[N];
ii seg[N];

void add(int p, int val) {
  for (; p <= m; p += p & -p) fen[p] += val;
}

int sum(int p) {
  int res = 0;
  for (; p; p -= p & -p) res += fen[p];
  return res;
}

#define L first
#define R second
int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> seg[i].L >> seg[i].R;
  sort(seg + 1, seg + 1 + n, [](const ii &x, const ii &y){ return x.R - x.L < y.R - y.L; });

  int x = n, j = 1;
  for (int d = 1; d <= m; ++d) {
    while (j <= n && seg[j].R - seg[j].L + 1 < d) {
      add(seg[j].L, +1);
      add(seg[j].R + 1, -1);
      --x; ++j;
    }
    int ans = x;
    for (int i = d; i <= m; i += d)
      ans += sum(i);
    cout << ans << "\n";
  }
  return 0;
}

Measured memory_bytes: 3712
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    char[] c;
    int[] KUPC;
    int ans;

    void run(){
	while(sc.hasNext()){
	    c = sc.next().toCharArray();
	    KUPC = new int[4];
	    ans = Integer.MAX_VALUE;
	    solve();
	}
    }

    void solve(){
	for(int i=0; i<c.length; i++){
	    if(c[i]=='K') KUPC[0]++;
	    else if(c[i]=='U') KUPC[1]++;  
	    else if(c[i]=='P') KUPC[2]++; 
	    else if(c[i]=='C') KUPC[3]++;
	}
	for(int i=0; i<KUPC.length; i++)
	    if(KUPC[i]<=ans) ans = KUPC[i];

	System.out.println(ans);
    }
}

Measured memory_bytes: 17324
import math

N = int(input())

def enumerate_divisors(N):
  all_divisors = set()
  for divisor in range(1, int(math.sqrt(N)) + 1):
    if N%divisor == 0:
      if divisor == 1:
        all_divisors.add(N/divisor)
      else:
        all_divisors = all_divisors | {divisor, N/divisor}

  all_divisors = list(all_divisors)
  return all_divisors

def calculate_reminder(N, d):
  while True:
    reminder = N%d
    if reminder == 0:
      N /= d
    else:
      return reminder

if N == 2:
  counter = 1
else:
  counter = len(enumerate_divisors(N-1))
  for div in enumerate_divisors(N):
    if calculate_reminder(N, div) == 1:
      counter += 1

print(counter)

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

#define clr(a,i) memset((a), (i) ,sizeof(a))

vi x(50,0);

template <typename T>
inline std::string to_bin_str(T n, std::size_t digit_num) {
   std::string str;
   while (n > 0) {
       str.push_back('0' + (n & 1));
       n >>= 1;
   }
   str.resize(digit_num, '0');
   std::reverse(str.begin(), str.end());
   return str;
}

int main(){
  unsigned long long n;
  std::cin >> n;
  std::vector<unsigned long long> t(n), a(n);
  rep(i,n){
    std::cin >> t[i]>> a[i];
  }
  loop(i,1,n){
    if(t[i-1]/t[i]>a[i-1]/a[i]&&t[i-1]%t[i]!=0){
      unsigned long long tmp =t[i-1]/t[i]+1;
      t[i]*=tmp;
      a[i]*=tmp;
    }else if(t[i-1]/t[i]>a[i-1]/a[i]){
          unsigned long long tmp =t[i-1]/t[i];
          t[i]*=tmp;
          a[i]*=tmp;
    }else if(t[i-1]/t[i]<a[i-1]/a[i]&&a[i-1]%a[i]!=0){
          unsigned long long tmp =a[i-1]/a[i]+1;
          t[i]*=tmp;
          a[i]*=tmp;
    }else if(t[i-1]/t[i]<a[i-1]/a[i]){
      unsigned long long tmp =a[i-1]/a[i];
      t[i]*=tmp;
      a[i]*=tmp;
    }else if(t[i-1]%t[i]!=0||a[i-1]%a[i]!=0){
      unsigned long long tmp =a[i-1]/a[i]+1;
      t[i]*=tmp;
      a[i]*=tmp;
    }else{
      unsigned long long tmp =a[i-1]/a[i];
      t[i]*=tmp;
      a[i]*=tmp;
    }

  }
  cout << t[n-1]+a[n-1] << endl;




}


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

int main(){
  ll n,h,w;
  cin >> n >> h >> w;
  vector<ll> A(n+10);
  vector<ll> B(n+10);
  ll ans = 0;
  rep(i,n){
    cin >> A[i] >> B[i];
    if(A[i] >= h && B[i] >= w) ++ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N = input()
a = list(map(int, input().split()))
a = sorted(a, reverse = True)
Alist = []
Blist = []
for i in range(len(a)):
    if i % 2 == 0:
        Alist.append(a[i])
    else:
        Blist.append(a[i])
print(sum(Alist) - sum(Blist))

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <math.h>
#include <list>

#define max 300000 
using namespace std;



//余りを調べる
int chkmod(int n) {
	if( n % 7 == 1 || n % 7 == 6 ) return 1;
	return 0;
}

//月曜素因数かどうか調べる
int isPrime(int n) {
	if(n <= 1) return 0;
	if( chkmod(n) == 0 ) return 0;

	int flg = 1;
	for(int i = 2; i <= (int)sqrt((double)n) + 1; i++) {
		if( ( chkmod(i) == 1 ) && ( chkmod(n/i) == 1 ) && ( n % i == 0 ) ) {
			flg = 0;
			break;
		}
	}
	return flg;
}

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);
	
	vector<int> primelist;
	for(int i = 0; i <= max; i++) 
		if( isPrime( i ) == 1) {
			primelist.push_back(i);
	//		cout << i << endl;
		}

	while(1) {
		int n;
		cin >> n;
		if( n == 1 ) break;

		cout << n << ":";
		
		
		//月曜素因数の個数を調べる
		for(int i = 0; i < primelist.size(); i++) {
			if( ( n / primelist.at(i) > 0 ) && ( n % primelist.at(i) == 0) && ( chkmod(n / primelist.at(i) ) == 1 ) )
				cout << " " << primelist.at(i);
		}
		cout << endl;

	}

	//while(1){}
	return 0;
}

Measured memory_bytes: 1348
#include <stdio.h>

class Dice2{
public:
	Dice2(){
		number = new int[6];
		relative = new int[55];
		relative[31] = relative[43] = relative[24] = relative[12] = 0;
		relative[3] = relative[20] = relative[52] = relative[35] = 1;
		relative[1] = relative[40] = relative[54] = relative[15] = 2;
		relative[4] = relative[10] = relative[51] = relative[45] = 3;
		relative[2] = relative[30] = relative[53] = relative[25] = 4;
		relative[21] = relative[42] = relative[34] = relative[13] = 5;
 	};
	~Dice2(){
		delete[] number;
		delete[] relative;
	};

	void setNumber(int index,int num){
		number[index] = num;
	};

	int returnRight(int top,int front){
		int top_index,front_index;
		for(int i = 0; i < 6; i++){
			if(number[i] == top)
				top_index = i;
			if(number[i] == front)
				front_index = i;
		}
		return number[relative[10*top_index+front_index]];
	}
private:
	int* number;
	int* relative;
};

int main(){
	Dice2 dice2;
	int x,q,top,front;
	for(int i = 0; i < 6; i++){
		scanf("%d",&x);
		dice2.setNumber(i,x);
	}
	scanf("%d",&q);
	for(int i = 0; i < q; i++){
		scanf("%d %d",&top,&front);
		printf("%d\n",dice2.returnRight(top,front));
	}
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    char n;
    cin>>a>>n>>b;
    switch(n)
    {
    case '+':
        cout<<a+b<<endl;
        break;
    case '-':
        cout<<a-b<<endl;
        break;
    default:
        break;
    }
    return 0;
}


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

int main(){
  ll N,M,X;cin>>N>>M>>X;
  vll C(N);
  vector<vll> A(N,vll(M));
  rep(i,N){
    ll c;cin>>C[i];
    rep(j,M) cin>>A[i][j];
  }
  ll ans=1e9;
  for(int bit=0;bit<(1<<N);++bit){
    ll tmp=0;
    vll rikai(M,0);
    for(int i=0;i<N;++i){
      if(bit & 1<<i){
        tmp += C[i];
        rep(j,M){
          rikai[j] += A[i][j];
        }
      }
    }
    bool flag = true;
    rep(k,M){
      if(rikai[k]<X) flag=false;
    }
    if(flag) ans = min(tmp,ans);
  }
  if(ans<1e9) cout<<ans<<endl;
  else cout<<"-1"<<endl;
}

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

typedef long long ll;

const int MAXN = 1e5 + 5;

int N;
int a[MAXN], b[MAXN];

void input(int *arr) {
	for (int i = 0; i < N; i++)
		scanf("%d", arr + i);
}

void load() {
	scanf("%d", &N);
	input(a);
	input(b);
}

int solve() {
	vector <int> diff;
	ll sum = 0;
	int sol = 0;
	for (int i = 0; i < N; i++)
		if (a[i] < b[i]) {
			sum += b[i] - a[i];
			sol++;
		}
		else if (a[i] > b[i])
			diff.push_back(a[i] - b[i]);
	
	sort(diff.begin(), diff.end(), greater <int> ());
	
	for (auto it : diff) {
		if (sum <= 0)
			break;
		sum -= it;
		sol++;
	}

	return sum > 0 ? -1 : sol;
}

int main() {
	load();
	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <queue>
#include <list>
#include <bit>
#include <bitset>

using namespace std;
using ll=long long;
using ull=unsigned long long;
using ui=unsigned int;

ull twopowmodp[200005];
ull twopowmodm[200005];
ull ans[200005];

void calc(ull *a, ull m, ull N)
{
  if(m <= 0)return;
  ull b = 1;
  for(ull i = 0;i < N;i++)
  {
    a[N-1-i] = b % m;
    b = (b*2) % m;
  }
}

ull firstmod(ull *a, string e, ull m)
{
  if(m <= 0)return 0LL;
  ull ret = 0;
  ull el = e.length();
  for(ull i = 0;i < el;i++)
  {
    if(e[i] == '1')ret = (ret + a[i]) % m;
  }
  return ret;
}

ull f(ull in)
{
  ull ret = 0;
  while(in != 0)
  {
    in = in % bitset<32>((ui)in).count();
    ret++;
  }
  return ret;
}

int main()
{
  ll N;
  string X;
  cin >> N >> X;
  ull initcnt = 0;
  for(ull i = 0;i < N;i++)
  {
    if(X[i] == '1')initcnt++;
  }
  calc(twopowmodp, initcnt+1, N);
  calc(twopowmodm, initcnt-1, N);

  if(initcnt == 0)
  {
    for(ull i = 0;i < N;i++)cout << 1 << endl;
    return 0;
  }
  
  ull initmodp;
  ull initmodm;

  initmodp = firstmod(twopowmodp, X, initcnt+1);
  initmodm = firstmod(twopowmodm, X, initcnt-1);

  for(ull i = 0;i < N;i++)
  {
    if(initcnt == 1 && X[i] == '1')
    {
      ans[i] = 0;
    }
    else
    {
      ull cur;
      if(X[i] == '0')
      {
        cur = (initmodp + twopowmodp[i]) % (initcnt+1);
      }
      else
      {
        cur = (initmodm + initcnt - 1 - twopowmodm[i]) % (initcnt-1);
      }
      ans[i] = 1 + f(cur);
    }
  }

  for(ull i = 0;i < N;i++)
  {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 7928
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
struct item{
	ll wt;
	ll val;
};
ll dp[105][100005];
ll knapsack(ll wt,ll n,vector<item> &things){
	if(wt == 0 || n == 0){
		return 0;
	}
	if(dp[n][wt]!=-1){
		return dp[n][wt];
	}
	ll ans1 = knapsack(wt,n-1,things);
	ll ans2 = INT_MIN;
	if(things[n-1].wt<=wt){
		ans2 = things[n-1].val+knapsack(wt-things[n-1].wt,n-1,things);
	}
	return dp[n][wt] = max(ans1,ans2);
}
int main(int argc,char const* argv[]){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	ll n,w;
	cin>>n>>w;
	vector<item> things(n);
	for(int i=0;i<n;i++){
		cin>>things[i].wt>>things[i].val;
	}
	memset(dp,-1,sizeof(dp));
	cout<<knapsack(w,n,things)<<endl;
	return 0;
}

Measured memory_bytes: 82304
h, w = map(int, input().split())
mp = [list(input()) for i in range(h)]
dp = [[0]*105 for _ in range(105)]
if mp[0][0]=='#':
    dp[0][0]+=1
for i in range(w-1):
    plus=0
    if mp[0][i+1]!=mp[0][i] and mp[0][i+1] == '#':
        plus=1
    dp[0][i+1] = dp[0][i]+plus
for i in range(h-1):
    plus=0
    if mp[i+1][0]!=mp[i][0] and mp[i+1][0] == '#':
        plus=1
    dp[i+1][0] = dp[i][0]+plus

for i in range(1,h):
    for j in range(1,w):
        plus=0
        plus2=0
        if mp[i][j]!=mp[i-1][j] and mp[i][j]=='#':
            plus=1
        if mp[i][j]!=mp[i][j-1] and mp[i][j]=='#':
            plus2=1
        dp[i][j] = min(dp[i-1][j]+plus, dp[i][j-1]+plus2)

print(dp[h-1][w-1])
    




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

#define min(a,b) (a<b?a:b)

int main(void){
  int n,a[3]={};
  scanf("%d",&n);
  char s[11];

  int len,i,j,ans=0;
  for(i=0;i<n;i++){
    scanf("%s",s);
    len=strlen(s);
    if(s[0]=='B')                    // a[0]: ---A
      a[s[len-1]=='A'?1:2]++;        // a[1]: B--A
    else if(s[len-1]=='A')a[0]++;    // a[2]: B---
    for(j=1;j<len;j++)
      if(s[j-1]=='A' && s[j]=='B')ans++;
  }
  
  int m;
  if(a[1]){
    ans+= a[1]-1;
    a[1]=1;
  }

  
  m=min(a[0],a[1]);
  ans+=m;
  a[0]-=m;
  m=min(a[1],a[2]);
  ans+=m;
  a[2]-=m;
  m=min(a[0],a[2]);
  ans+=m;

  printf("%d",ans);

  return 0;
}
  


Measured memory_bytes: 128
fn main() {
    let (k, s) = input();
    println!("{}", solve(k, s));
}

fn input() -> (usize, String) {
    let mut buf1 = String::new();
    let mut buf2 = String::new();
    std::io::stdin().read_line(&mut buf1).unwrap();
    std::io::stdin().read_line(&mut buf2).unwrap();
    buf1.pop();
    buf2.pop();
    let k: usize = buf1.parse().unwrap();
    (k, buf2)
}

fn solve(k: usize, s: String) -> String {
    if k >= s.len() {
        return s;
    }
    format!("{}{}", &s[..k].to_string(), String::from("..."))
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


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

    d = d * 2 + 1;

    cout << (n + d - 1) / d << endl;

    return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define N 2010

int n,sum,cnt;
bitset<2010000> f;
int a[N];

int main()
{
	f.set(0);
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]),sum+=a[i];
	//sort(a+1,a+n+1);
	//cnt=unique(a+1,a+n+1)-a-1;
	//for (int i=1;i<=cnt;i++) sum+=a[i];
	for (int i=1;i<=n;i++) f|=(f<<a[i]);
	for (int i=sum/2;i>=0;i--)
		if (f[i]) {printf("%d\n",sum-i); return 0;}
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 99999999;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };



int main() {
	int N;
	int T;
	int t[1008];
	int c[1008];
	int ans = c_INF;
	scanf("%d%d", &N, &T);
	for (int i = 0; i < N; i++) {
		scanf("%d%d", &c[i], &t[i]);
		if (t[i] <= T && c[i] < ans)ans = c[i];
	}


	if(ans!=c_INF)printf("%d", ans);
	else printf("TLE");

}



/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
・文字列の＜＜スペル＞＞は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <string>
#define rep(i,n) for (int i=0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    bool t = true;
    for(int i=0; i<s.size(); i++) {
        if (i % 2 == 0) {
            if (s.substr(i, 1) == "R" || s.substr(i, 1) == "U" || s.substr(i, 1) == "D") {
                continue;
            } else {
                t = false;
                break;
            }
        } else {
            if (s.substr(i, 1) == "L" || s.substr(i, 1) == "U" || s.substr(i, 1) == "D") {
                continue;
            } else {
                t = false;
                break;
            }
        }
    }
    if(t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=1<<18;


int main(){
    ld n,k;
    cin>>n>>k;
    ld ans=0;
    if(n>=k){
        ans+=(n-k+1);
    }
    for(int i=1;i<min(n+1,k);i++){
        ld num=0;
        ld buf=i;
        while(buf<k){
            num++;
            buf*=2;
        }
        ans+=1/pow(2,num);
    }
    ans/=n;
    cout<<setprecision(15)<<ans<<endl;

}

Measured memory_bytes: 3836
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<string>
#include<string.h>
#include<map>
#include<math.h>
using namespace std;

#define ll long long

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

template<class S, class T> inline void chmax(S &a, T b){ if (a < b)a = b; }
template<class S, class T> inline void chmin(S &a, T b){ if (a > b)a = b; }

int main(){
	int i, j;
	int N;
	int ans(0);
	cin>>N;
	for (int i = 0; i < N; i++){
		ans += i + 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 1005;
const int MAXM = 5005;
const int INF = 0x3f3f3f3f;

int n, a[MAXN], par[MAXN], f[MAXN][MAXM];

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read();
	for (int i = 2; i <= n; i ++)
		par[i] = Read();
	for (int i = 1; i <= n; i ++)
		a[i] = Read();
	for (int i = n; i; i --)
	{
		int val = INF;
		for (int j = 0; j <= a[i]; j ++)
			val = min(val, f[i][j]);
		if (val == INF)
			return puts("IMPOSSIBLE"), 0;
		for (int j = a[par[i]]; ~j; j --)
		{
			int cur = INF;
			if (j >= val)
				cur = min(cur, f[par[i]][j - val] + a[i]);
			if (j >= a[i])
				cur = min(cur, f[par[i]][j - a[i]] + val);
			f[par[i]][j] = cur;
		}
	}
	return puts("POSSIBLE"), 0;
}


Measured memory_bytes: 17792
#include <iostream>

using ui = uint64_t;
char used[100000];
constexpr ui MOD = 1000000000+7;
int main()
{
	std::cin.sync_with_stdio(false);
	std::cout.sync_with_stdio(false);
	int N;
	std::cin >> N;
	ui res = 1;
	for(int i = 0;i < N; ++i){
		int A;
		std::cin >> A;
		++used[A];
		if(A == 0){
			if(2 <= used[A]){
				res = 0;
			}
			continue;
		}
		
		if(used[A] == 1){
			res *= 2;
			if(MOD <= res){res -= MOD;}
		}
		else if(3 <= used[A]){
			res = 0;
		}
	}
	std::cout << res << std::endl;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
typedef map<int,int> mp;

const int MOD = 1e9 + 7;


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

    int k, x;
    cin >> k >> x;

    if(k * 500 >= x){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }



    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i)
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
#define dis distance
#define so sort
#define rev reverse
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;

int main (){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<bool> B(8);//1灰 2茶 3緑 4水 5青 6黄 7橙 8赤
    int freep = 0;
    REP(i,n){
        int a;
        cin >> a;
        if(a >= 3200)freep++;
        else B[a/400] = true;
    }
    int color = 0;
    REP(i,8){
        if(B[i])color++;
    }
    cout << max(1,color) << " "  << color + freep << endl;
    return 0;
}

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

int n, m, t, ans;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n >> m >> t;
	int tmp = -1;
	for(int i=0; i<n; ++i){
		int a;
		cin >> a;
		if(i == 0){
			ans += a - m;
		}else{
			ans += max(0, a - tmp - 2*m);
		}
		tmp = a;
		if(i == n-1){
			ans += max(0, t - tmp - m);
		}
	}
	cout << ans << "\n";
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N;
	cin>>N;
	vector<int> p(N);
	rep(i,N){
		cin>>p[i];
	}
	vector<int> t(N);
	rep(i,N){
		t[i] = i+1;
	}
	string ans = "NO";
	rep(i,N)rep(j,N){
		vector<int> q(N);
		rep(k,N){
			if(k == i){
				q[k] = p[j];
			}
			else if(k == j){
				q[k] = p[i];
			}
			else{
				q[k] = p[k];
			}
		}
		if(q == t){
			ans = "YES";
			i = j = N;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

vector<VI>G;

int dfs(int p) {
	VI tmp;

	REP(i, G[p].size()) {
		tmp.push_back(dfs(G[p][i]));
	}
	rSORT(tmp);
	int ans = 0;
	REP(i, tmp.size()) {
		ans = max(ans, tmp[i] + i + 1);
	}
	return ans;
}


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

	int N;
	cin >> N;
	G.resize(N);
	REP(i, N - 1) {
		int a;cin >> a;
		a--;
		G[a].push_back(i + 1);
	}

	cout << dfs(0) << endl;

	return 0;
}



Measured memory_bytes: 15104
#include<bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define ll long long
#define endl '\n'
#define vi vector<int>
#define rep(i, n) for (i = 0; i < n; i++)
#define rep1(i, n) for (i = 1; i <=n; i++)
#define rep2(i, n) for (i = 0; i < n-1; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend() //Sort in reverse,Vector.
#define present(v,x) (v.find(x)!=v.end()) //set/map etc.


int main()
{  ios_base::sync_with_stdio(false);cin.tie(NULL);
   #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   #endif
   
   int i,n,x,sum1,sum2,sum3,sum4;

   sum1=sum2=sum3=sum4=0;

   cin>>n;

   char str1[] = "AC", str2[] = "WA", str3[] = "TLE",str4[] = "RE";

   for(i=0;i<n;i++)
   {
      char str[5];
      cin>>str;

       if(strcmp(str,str1)==0)
         sum1+=1;

      if(strcmp(str,str2)==0)
         sum2+=1;

      if(strcmp(str,str3)==0)
         sum3+=1;

      if(strcmp(str,str4)==0)
         sum4+=1;

   }

   cout<<"AC x "<<sum1<<endl;
   cout<<"WA x "<<sum2<<endl;
   cout<<"TLE x "<<sum3<<endl;
   cout<<"RE x "<<sum4<<endl;

}    


Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
        Integer input = scan.nextInt();
 
        if(input == 1) {
        	System.out.println(1);
        } else {
        	int passKindCount = input * input * input;
        	System.out.println(passKindCount);
        }
        scan.close();
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n,m; cin >> n >> m;
    vpl v(n);
    rep(i,n) cin >> v[i].first >> v[i].second;
    sort(all(v));
    //rep(i,n) cout << v[i].first << v[i].second << endl;
    priority_queue<ll> pq;
    ll index = 0;
    ll ans = 0;
    for(ll i=1; i<=m; i++){
        while(v[index].first == i) {
            pq.push(v[index].second);
            index++;
        }
        if(!pq.empty()) {
            ans += pq.top(); pq.pop();
        }
        //cout << ans << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2936
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, *a = map(int, read().split())
ans = 1
mod = 10 ** 9 + 7
memo = [0, 0, 0]
for check in a:
    if check in memo:
        ans *= memo.count(check)
        ans %= mod
        memo[memo.index(check)] += 1
    else:
        print(0)
        exit()
print(ans)


Measured memory_bytes: 12408
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define INF 10e10
using namespace std;
int main(){
  int n; 
  cin >> n;
  while(n!=0){
    string s;
    long long time,tmp,d,e,sv,val,cnt,seed,income,i_rate;
    vector<pair<long long ,string> > p;
    for(int i=0;i<n;i++){
      cin >> s;
      time=0;
      cin >> sv;
      for(int j=0;j<3;j++){
        cin >> tmp;
        time+=tmp;
      }
      cin >> d>>e;
      cin >> seed>>val>>cnt;
      time+=cnt*(d+e);
      income = val*seed*cnt - sv;
      income *= 1000000000;
      p.push_back(make_pair(-income/time,s));
    }
    sort(p.begin(),p.end());
    for(int i=0;i<p.size();i++){
      cout << p[i].second <<endl;
    }
    cout << "#\n";
    cin >> n;
  }
}



Measured memory_bytes: 3180
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((V).begin(), (V).end())
#define RSORT(v) sort((V).rbegin(), (V).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (V.erase(remove((V).begin(), (V).end(), (a)), (V).end()))
#define REVERSE(v) (reverse((V).begin(), (V).end()))
#define LOWER_BOUND(v,a) (lower_bound((V).begin(), (V).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((V).begin(), (V).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;

signed main()
{
	int N;
	int F[100][10];
	int P[100][10];
	
	cin >> N;
	REP(i, N) REP(j, 10) cin >> F[i][j];
	REP(i, N) REP(j, 10 + 1) cin >> P[i][j];

	int max = INT_MIN;
	for (int i = 1; i < 1024; i++)
	{
		int sum = 0;
		for (int j = 0; j < N; j++)
		{
			int cnt = 0;
			for (int k = 0; k < 10; k++)
			{
				bool b = ((i & (1 << k)) > 0);
				if (F[j][k] == 1 && b)
				{
					cnt++;
				}
			}
			sum += P[j][cnt];
		}
		max = MAX(max, sum);
	}
	cout << max << endl;
}



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

bool is[1000000];

int main()
{
    int n; cin >> n;
    int ans = -1;
    memset( is, true, sizeof is );
    vector<int>pr;
    for( int i = 2; i < 1000000; i++ ){
        if( is[i] ){
            if( i >= n && ans == -1 ){
                ans = i;
            }
            for( int j = i*2; j < 1000000; j+=i ){
                is[j] = false;
            }
        }
    }
    cout << ans << endl;
}


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

using namespace std;

bool kaibun(string s) {
	for (int i = 0;i < s.size() / 2;i++) {
		if (s[i] != s[s.size() - 1 - i]) return false;
	}

	return true;
}

int main() {
  
  	int a, b, ans=0;
  
  	cin>> a >> b;
  
  	for(int i=a;i<=b;i++){
      	if(kaibun(to_string(i))) ans++;
    }
  
  	cout<< ans << endl;
  
	return 0;
}


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

int a[8];
map<int, int> mp;
int st[8][3] = {
    {1, 4, -1},
    {0, 2, 5},
    {1, 3, 6},
    {2, 7, -1},
    {0, 5, -1},
    {1, 4, 6},
    {2, 5, 7},
    {3, 6, -1}
};

bool game_over(int* state) {
    for(int i = 0; i < 8; ++i) {
        if(state[i] != i) return false;
    }
    return true;
}

void to_state(int s, int* state) {
    for(int i = 7; i >= 0; --i) {
        state[i] = s % 10;
        s /= 10;
    }
}

int get_state(int* state) {
    int res = 0;
    for(int i = 0; i < 8; ++i) {
        res = res * 10 + state[i];
    }
    return res;
}
void init() {
    queue<int> q;
    q.push(1234567);
    mp[1234567] = 0;
    int is_found = false;
    int state[8];
    while(!q.empty()) {
        int now = q.front();
        q.pop();
        to_state(now, state);
        int zero_pos = find(state, state + 8, 0) - state;
        for(int i = 0; i < 3; ++i) {
            if(st[zero_pos][i] != -1) {
                swap(state[st[zero_pos][i]], state[zero_pos]);
                int ns = get_state(state);
                if(mp.count(ns) == 0) {
                    mp[ns] = mp[now] + 1;
                    q.push(ns);
                }
                swap(state[st[zero_pos][i]], state[zero_pos]);
            }
        }
    }
}
int main() {
    init();
    while(true) {
        for(int i = 0; i < 8; ++i) {
            if(scanf("%d", a + i) == EOF) goto END;
        }
        int start = get_state(a);
        printf("%d\n", mp[start]);
    }
END:
    return 0;
}



Measured memory_bytes: 4144
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <cstring>
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
int main(){
	int a[3];
	scanf("%d %d %d", &a[0], &a[1], &a[2]);
	sort(a, a+3);
	if((a[0]==a[1]&&a[1]!=a[2])||(a[2]==a[1]&&a[1]!=a[0]))
		printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
int n,k;
int p[100004];
char a[100004];
int main(){
	cin>>n>>k;
	for (int i=0;i<n;i++){
		cin>>a[i];
		if (i==0 || a[i]!=a[i-1]) p[i]=1;
		else i--,n--,p[i]++;
	}
	int num0=0;
	for (int i=0;i<n;i++) if (a[i]=='0') num0++;
	for (int i=1;i<n;i++) p[i]+=p[i-1];
	int now=0,ans=0,l=0;
	int fru=0;
	for (int i=0;i<n;i++){
		if (a[i]=='0') fru++;
		if (k>=fru)ans=max(p[i]-(l==0?0:p[l-1]),ans);
		else{
			if (a[l]=='0') l++;
			else l+=2;
			ans=max(p[i]-(l==0?0:p[l-1]),ans);
			fru--;
		}
	}
	cout<<ans;	
}

Measured memory_bytes: 768
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::fastout;
use proconio::input;
use proconio::marker::Usize1;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::VecDeque;

// 自力で解こうとしたがうまくいかなかったので答えを見た
// O(NQ+N^2)解法

#[fastout]
fn main() {
    input! {
        N: usize,
        M: usize,
        Q: usize,
        LRs: [(Usize1, Usize1); M],
        PQs: [(Usize1, Usize1); Q],
    }

    // O(10^5)のループの内側でクエリに回答する
    // つまり、クエリへの回答はO(1)でできる必要がある (← 注: これ嘘です。10^7までは食えるので今回はO(NQ)までいけます)
    // ある「領域」に属する個数を高速で求める → 累積和
    // ここで、領域は幅を持っている → 2次元累積和
    // この問題ではオーバーキルな解法らしい
    // なので、いったんN <=500、つまり N^2 < 10^6を利用した解法を使う

    // x[l][r]を区間[l,r]を走る電車の本数とするとき、
    // acc[l][r+1] := sum $ [ x[l][i] for i in 0..r ]
    let mut acc: Vec<Vec<i64>> = vec![vec![0i64; N + 1]; N];

    // まず目印を付けて、後でaccに直す
    let mut mark: Vec<Vec<i64>> = vec![vec![0i64; N]; N];
    for &(l, r) in LRs.iter() {
        mark[l][r] += 1;
    }

    // accに直す
    // 横一列の累積和でO(N)、それをN行重ねるからO(N^2)
    for l in 0..N {
        for r in 0..N {
            acc[l][r + 1] = acc[l][r] + mark[l][r];
        }
    }

    for &(p, q) in PQs.iter() {
        // ループの中はほぼO(1)じゃないと間に合わない (← 注: これ嘘です。10^7までは食えるので今回はO(NQ)までいけます)
        // 区間、O(1)と来れば累積和でしょう

        let mut ans = 0;
        for l in p..=q {
            ans += acc[l][q + 1] - acc[l][l];
        }
        println!("{}", ans);
    }
}


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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//型名省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define tll(n) array<long long,(int)(n)>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define vt(n) vector<array<long long,(int)(n)>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define Fi first
#define Se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define lin(s) getline(cin,(s))
#define Ssort(v) sort((v).begin(),(v).end(),[](auto &left,auto &right){return left.second<right.second;})

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
//YES.NO
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//累乗
template<typename t>
constexpr t mypow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
        }
    return x;
}
#define pow mypow

//chmin,chmax
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;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

ll solve(ll x,ll y){
    ll dis=abs(abs(y)-abs(x));
    if(x>=0&&y>0){
        if(y>x){
            return dis;
        }else{
            return dis+2;
        }
    }else if(x<0&&y<=0){
        if(y>x){
            return dis;
        }else{
            return dis+2;
        }
    }else{
        return dis+1;
    }
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll x,y;
    cin>>x>>y;
    cout<<solve(x,y)<<endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int main(void){
    int n;
    vector <int> ans;
    int sub;
    
    cin >> n;
    
    if(n == 0)      cout << 0 << endl;
    else{
        while(1){
            if(n % 2 == 0){
                ans.push_back(0);
                n = n / (-2);
            }
            else{
                ans.push_back(1);
                n = (n - 1) / (-2);
            }
            
            if(n == 1){
                ans.push_back(1);
                break;
            }
        }
        
        for(int i = ans.size() - 1; i >= 0; i--){
            cout << ans[i];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
n,m = map(int,input().split())
b = [int(input()) for _ in range(m)]
a = set(b)

dp = [0] * (n+1)
dp[0] = 1
dp[1] = 1

for i in range(2,n+1):
  if i-1 in a :
    dp[i-1] = 0
  if i-2 in a :
    dp[i-2] = 0
  dp[i] = dp[i-1] + dp[i-2]

print(dp[n] % 1000000007)

Measured memory_bytes: 460020
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

#define MAX_N 200010

using namespace std;

struct uftree {
    int par[MAX_N], rank[MAX_N], size[MAX_N];
    uftree(int N) {
        for (int i = 0; i < N; i++) {
            par[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }
    int root(int x) {
        if (par[x] == x)
            return x;
        else {
            int r = root(par[x]);
            size[x] = size[par[x]];
            return par[x] = r;
        }
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (rank[x] > rank[y])
            par[y] = x;
        else {
            par[x] = y;
            if (rank[x] == rank[y]) rank[y]++;
        }
        size[x] += size[y];
        size[y] = size[x];
    }
    int getsize(int x) {
        root(x);
        return size[x];
    }
    bool same(int x, int y) { return root(x) == root(y); }
};

int main() {
    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;
    a--; b--; c--; d--;
    uftree uft(n);
    int scnt=0, rcnt=0, i=0, prev = -1;
    vector<int> trees;
    for (auto si:s) {
        if (si == '.') {
            scnt++;
            if (scnt == 3) trees.push_back(i);
            if (rcnt <= 1 && prev >= 0) uft.unite(prev, i);
            rcnt = 0;
            prev = i;
        } else {
            scnt=0;
            rcnt++;
        }
        // cerr << scnt << ' ' << rcnt << ' ' << prev << '\n';
        i++;
    }
    // for (auto t:trees) cerr << t << ' ' << uft.same(t, a) << '\n';
    if (uft.same(a, c) && uft.same(b, d)) {
        if (c < d) {
            cout << "Yes" << '\n';
            return 0;
        }
        for (auto t:trees) {
            if (uft.same(a, t) && b <= t-1 && t-1 <= d) {
                cout << "Yes" << '\n';
                return 0;
            }
        }
    }
    cout << "No" << '\n';
    return 0;
}


Measured memory_bytes: 2948
n, x, y = map(int, input().split())

ans = {}
for i in range(n-1):
  ans[i+1] = 0
  
for i in range(n):
  for j in range(i+1,n):
    if i <= x-1:
      if j <= x-1:
      	t=j-i
      	ans[t] += 1
      elif j <= y-1:
      	t = min(j-i, (x-1)-i + 1 + (y-1) -j)
      	ans[t] += 1
      else: #j > y-1
      	t = (x-1)-i + 1 + j -(y-1)
      	ans[t] += 1
    elif i < y-1:
      if j < y-1:
      	t = min(j-i, i-(x-1) + 1 + (y-1) -j)
      	ans[t] += 1
      else: #j >= y-1:
      	t = min(j-i, i-(x-1) + 1 + j - (y-1))
      	ans[t] += 1
    elif i >= y-1:
      t=j-i
      ans[t] += 1
    else:
      print("error")

for i in range(1,n):
  print(ans[i])


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

using namespace std;
using vi = vector<int>;

#define rep(i,n) for(int i=0;i<(n);++i)
const int INF = 1e9;

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

  int a[M];
  vi c(M, 0);

  rep(i, M) {
    int b; cin >> a[i] >> b;
    rep(j, b) {
      int _c; cin >> _c;
      --_c;
      c[i] |= 1 << _c;
    }
  }

  vi min_v(1 << N, INF);

  min_v[0] = 0;
  rep(bit, 1 << N) {
    rep(i, M) {
      min_v[bit|c[i]] = min(min_v[bit|c[i]], min_v[bit] + a[i]);
    }
  }
  if (min_v[(1 << N) - 1] == INF)
    cout << "-1\n";
  else
    cout << min_v[(1 << N)-1] << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;


public class Main
{

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

		
		StringBuilder sb = new StringBuilder();
		
		sb.append(a);
		
		sb.reverse();
		
		
		if(a.equals(sb.toString()))
		{
			String b= a.substring(0,(a.length()/2));
			String c = a.substring((a.length()/2) + 1,a.length());
			if(b.equals(c))
			{
				System.out.println("Yes");
			}
			else 
			{
				System.out.println("No");
			}
			
		}
		else
		{
			System.out.println("No");
		}
		sc.close();
	}

}


Measured memory_bytes: 23636