akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int block[120][120];

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

int bfs(int step, int x, int y) {
	int ans = 1;
	int flag[120][120] = {};
	flag[x][y] = 1;
	vector<int> st{ step,x,y };
	queue<vector<int> > stk;
	stk.push(st);
	while(stk.size()) {
		vector<int> pos = stk.front();
		stk.pop();
		if(pos[0] > 0) {
			for(int i = 0;i < 6;i++) {
				if(flag[pos[1] + dx[i]][pos[2] + dy[i]] == 0 && block[pos[1] + dx[i]][pos[2] + dy[i]] == 0) {
					flag[pos[1] + dx[i]][pos[2] + dy[i]] = 1;
					ans++;
					stk.push(vector<int>{pos[0] - 1, pos[1] + dx[i], pos[2] + dy[i]});
				}
			}
		}
	}

	return ans;
}

int main() {
	int n, t;
	for(cin >> t >> n;t != 0 || n != 0;cin >> t >> n) {
		for(int i = 0;i < 120*120;i++) {
			block[i % 120][i / 120] = 0;
		}
		for(int i = 0;i < n;i++) {
			int x, y;
			cin >> x >> y;
			block[x + 60][y + 60] = 1;
		}
		int xx, yy;
		cin >> xx >> yy;
		cout << bfs(t,xx+60,yy+60) << endl;
	}
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string check[4] = {"remaerd", "maerd", "esare", "resare"};
  string s;
  cin >> s;
  int n = s.size(), i=0;
  reverse(s.begin(), s.end());

  for (i = 0; i < n;) {
    bool flag = true;
    for (int j = 0; j < 4; j++) {
      if (check[j] == s.substr(i, check[j].size())) {
        i += check[j].size();
        flag = false;
      }
    }
    if (flag == true) break;
  }
  if (i == n) cout << "YES" << '\n';
  else cout << "NO" << '\n';
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	ld n, m, d;
	cin >> n >> m >> d;
	if (d > 0) {
		printf("%.20LF\n", (2 * (m - 1)* (n - d)) / n / n);
	}
	else {
		printf("%.20LF\n", (ld)(m - 1) / n);
	}
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int N; cin >> N;
	int sum = 0, max_l = 0;
	rep(i, N) {
		int L; cin >> L;
		sum += L;
		max_l = max(max_l, L);
	}
	sum -= max_l;
	if (max_l < sum) cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

public class Main {
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		InputReader in = new InputReader(System.in);
		int n = in.readInt();  
		int k = in.readInt();
		char[] s = in.readString().toCharArray();
		s[k-1] = (char) (s[k-1] + 32);
		System.out.println(s);
	}
}
class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(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 readInt() {
		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 String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long 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 String next() {
		return readString();
	}

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


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  long long N, M;
  cin >> N >> M;
  long long ans;
  if (N >= M)
  {
    ans = M / 2;
  }
  else
  {
    M = max((long long)0, M - (2 * N));
    ans = N + (M / 4);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split());s=input();l=[0]*m;a,t,p=0,0,1
if 10%m:
  for i in s[::-1]:l[t%m]+=1;t+=int(i)*p;a+=l[t%m];p=p*10%m
else:a=sum(i+1 for i in range(n) if int(s[i])%m<1)
print(a)

Measured memory_bytes: 3628
import sys
import numpy as np
import math
import collections
import copy
from collections import deque 
from functools import reduce
from itertools import product
from itertools import combinations

# input = sys.stdin.readline

def get_prime_list(number):
    is_prime = np.ones(number, dtype=bool)
    is_prime[:2] = False
    num_sqrt = np.sqrt(number) + 1
    for i in range(2, int(num_sqrt) + 1):
        if (is_prime[i]):
            is_prime[i*2::i] = False
    prime_list = np.arange(number)[is_prime]
    return prime_list

Q = int(input())
LRn = [list(map(int, input().split())) for _ in range(Q)]
prime_list = get_prime_list(10**5)
prime_cnt = [0 for _ in range(10**5 + 10)]
for i in range(3, 10**5):
    if i in prime_list:
        if ((i+1)/2) in prime_list:
#             print(i)
            prime_cnt[i] = prime_cnt[i-1] + 1
            continue
    prime_cnt[i] = prime_cnt[i-1]
for LR in LRn:
    print(prime_cnt[LR[1]]-prime_cnt[LR[0]-1])













Measured memory_bytes: 46340
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> list = new ArrayList<Integer>();
        while(true) {
            String line;
            try {
                line = sc.nextLine();
            }catch(Exception e){
                break;
            }
            int n = Integer.parseInt(line);
            if(n == 0) {
                System.out.println(list.get(list.size()-1));
                list.remove(list.size()-1);
            }else {
                list.add(n);
            }
        }    
    }
}



Measured memory_bytes: 26008
#include <cstdio>

const long long mod=998244353ll;

const int MSIZE=4000000;


void ad(long long &a,long long b){a+=b;a%=mod;}
void mn(long long &a,long long b){a+=mod-b;a%=mod;}
void ml(long long &a,long long b){a*=b;a%=mod;}
long long sq(long long a){return a*a%mod;}
long long pw(long long a,long long n)
{
  return n==0?1ll:sq(pw(a,n/2))*(n%2==1?a:1ll)%mod;
}
long long iv(long long a){return pw(a,mod-2);}
long long inv[MSIZE],F[MSIZE],iF[MSIZE];

void prev(int N)
{
  inv[0]=0;
  inv[1]=1;
  for(int i=2;i<N;i++){
    inv[i]=(mod-mod/i)*inv[mod%i]%mod;
  }
  F[0]=iF[0]=1;
  for(int i=1;i<N;i++){
    F[i]=F[i-1]*i%mod;
    iF[i]=iF[i-1]*inv[i]%mod;
  }
}

long long Ch(int i,int j)
{
  return i<0||j<0||i<j?0:F[i]*iF[j]%mod*iF[i-j]%mod;
}

int main()
{
  int n,m;
  scanf("%d%d",&n,&m);
  prev(n+3*m);
  long long ans=Ch(3*m+n-1,n-1);
  mn(ans,n*Ch(m-1+n-1,n-1)%mod);
  for(int i=m+1;i<=3*m&&i<=n;i++){
    if((3*m-i)%2==0){
      mn(ans,Ch(n,i)*Ch((3*m-i)/2+n-1,n-1)%mod);
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 63616
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

const int MOD = 1000000007;

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int>> calcNext(const string &S)
{
  int n = (int)S.size();
  vector<vector<int>> res(n + 1, vector<int>(26, n));
  for (int i = n - 1; i >= 0; --i)
  {
    for (int j = 0; j < 26; ++j)
      res[i][j] = res[i + 1][j];
    res[i][S[i] - 'a'] = i;
  }
  return res;
}

void add(long long &a, long long b)
{
  a += b;
  if (a >= MOD)
    a -= MOD;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin >> S;
  int n = (int)S.size();
  string T = S;
  reverse(T.begin(), T.end());

  auto ns = calcNext(S);
  auto nt = calcNext(T);
  vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, 0));
  dp[0][0] = 1;
  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j < n; ++j)
    {
      for (int k = 0; k < 26; ++k)
      {
        int ni = ns[i][k];
        int nj = nt[j][k];
        if (ni + nj + 2 > n)
          continue;
        add(dp[ni + 1][nj + 1], dp[i][j]);
      }
    }
  }
  long long res = 0;
  for (int i = 0; i <= n; ++i)
  {
    for (int j = 0; i + j <= n; ++j)
    {
      int num = 1;
      for (int k = 0; k < 26; ++k)
        if (ns[i][k] + 1 + j <= n)
          ++num;
      res = (res + dp[i][j] * num % MOD) % MOD;
    }
  }
  cout << res - 1 << endl;
  return 0;
}

// https://qiita.com/drken/items/a207e5ae3ea2cf17f4bd



Measured memory_bytes: 34840
list1=[]
for i in range(10):
    n=int(input())
    list1.append(n)
list1.sort()

del list1[0:7]
    
list2=[]
for i in range(10):
    m=int(input())
    list2.append(m)
list2.sort()

del list2[0:7]

a=sum(list1)
b=sum(list2)

print(a,b)


Measured memory_bytes: 5600
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	char ch; cin>>ch;
	cout<<(tolower(ch)==ch ? 'a' : 'A')<<"\n";
	return 0;
}

Measured memory_bytes: 3648
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def dijkstra(s,graph):
    d = [inf]*n
    d[s] = 0
    h = [(0,s)]
    while h:
        c,v = heappop(h)
        if d[v] < c:
            continue
        for t,cost in graph[v]:
            if d[v] + cost < d[t]:
                d[t] = d[v] + cost
                heappush(h,(d[t],t))
    return d

n,x,y = LI()
ans = [0]*n
edge = [[] for _ in range(n)]
for i in range(n-1):
    edge[i].append([i+1,1])
    edge[i+1].append([i,1])

edge[x-1].append([y-1,1])
edge[y-1].append([x-1,1])
for i in range(n):
    d = dijkstra(i, edge)
    for j in range(i+1,n):
        ans[d[j]] += 1
for k in range(1,n):
    print(ans[k])

Measured memory_bytes: 121308
M, D = gets.split.map(&:to_i)

counter = 0
(1..M).each do |m|
  (20..D).each do |d|
    juu = d / 10
    iti = d - juu * 10
    if iti >= 2 && juu >= 2 && iti * juu == m
      counter += 1
    end
  end
end

puts counter

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

int N,M;
vector<string> A,B;

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

  cin>>N>>M;
  rep(i,N){
    string input;
    cin>>input;
    A.push_back(input);
  }
  rep(i,N){
    string input;
    cin>>input;
    B.push_back(input);
  }

  ll res=0;
  rep(i,N)rep(j,M){
    if(A[i][j]!=B[i][j])res++;
  }
  cout<<res<<endl;

  return 0;
}



Measured memory_bytes: 11328
#include <stdio.h>
int main(){

  int N ,v,i,j;
  int A[1000];

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  for(j=0;j<N;j++){
      printf("%d", A[j]);
      if (j != N-1) printf(" "); 
    }
    printf("\n");

  for(i = 1;i<N;i++){
    v = A[i];
    j = i - 1;


      while( j >=0 && A[j] > v){
	A[j+1] = A[j];
	j--;
      }
      A[j+1] = v;
    for(j=0;j<N;j++){
     
       printf("%d",A[j]);
       if(j != N-1) printf(" ");
    }
    printf("\n");
   
  }

  
  return 0;
}


Measured memory_bytes: 2084
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1 << 29;
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a.at(i);
    }

    // ソートする
    sort(a.begin(), a.end());

    // A_maxの値
    int a_max = a.at(n - 1);

    // 1からA_maxまでの条件を満たすかの配列
    // i番目より小さいiの約数がAに存在しないことを表す
    vector<bool> qualified(a_max, true);

    // 各Aの要素について倍数を全てfalseにする
    // 計算量解析によるとO(A_max log A_max)時間
    rep(i, n) {
        // Aのi番目の要素の値
        int a_i = a.at(i);

        // 条件を満たさないものの倍数は既に条件を満たさないことになっている
        if (qualified.at(a_i - 1) == false) continue;

        // 2個前と同じならば既に処理は完了している
        if (i >= 2) {
            if (a_i == a.at(i - 2)) {
                continue;
            }
        }

        //1個前と同じやつだったら自分自身も条件を満たさない
        if (i >= 1) {
            if (a_i == a.at(i - 1)) {
                qualified.at(a_i - 1) = false;
            }
        }

        //1以上の数でA_maxまでで調べる(a_iはカウントしない)
        for (int x = 2 * a_i; x < a_max + 1; x += a_i) {
            // 倍数xは条件を満たさない
            qualified.at(x - 1) = false;
        }
    }

    int ans = 0;

    // 二部探索でAの要素が条件を満たすかを確認する
    for (int a_i : a) {
        // a_iがtrueであれば答えに1をプラスする
        if (qualified.at(a_i - 1)) ans++;
    }

    cout << ans << endl;
}


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

    using namespace std;
    #define ll long long
    #define rep(i,a,n) for(int i=a;i<n;i++)
    #define pb push_back
    #define in insert
    
    #define SORT(x) sort(x.begin(),x.end())
    #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
    #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
    #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
    #define All(x) (x).begin(),(x).end()
    #define rAll(x) (x).rbegin(),(x).rend()
    #define db  double
    #define sc scanf
    #define pf printf
    const ll MAX=10e18;
    //ll d[MAX],h[MAX];
    const double pi=3.14159265358979323846;
    ll gcd(ll x,ll y){
    	if(x==0)return y;
    	else return gcd(y%x,x);
    }
    ll lcm(ll x,ll y){
    	return (x*y)/gcd(x,y);
    }
   
      bool isPrime(ll n) 
{  
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (ll i = 5; i * i <= n; i = i + 6){ 
        if (n % i == 0 || n % (i + 2) == 0){ 
            return false; 
        }
    }
    return true; 
} 
bool pdrome(string s){
    ll n = s.length();
    for(int i=0;i<n/2;i++){
        if(s[i]!=s[n-i-1]){
            return false;
        }
    }
    return true;
}
ll mindig(ll x){
    ll ans = 9;
    ll t = x;
    while(x){
        ans = min(ans,x%10);
        x/=10;
    }
    x = t;
    return ans;
}
ll maxdig(ll x){
    ll ans = 0;
    ll t = x;
    while(x){
        ans = max(ans,x%10);
        x/=10;
    }
    x = t;
    return ans;
}
ll t,ans=0;
vector<ll>v;

  
  
  
    int main() {
    	ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
       long double a,b;ll c;
       cin>>a>>b;
       c=a*b;
       cout<<c;
    return 0;
}
    	

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

int main(){
    ll X,K,D;
    cin>>X>>K>>D;
    X=abs(X);
    ll Z=X/D;
    if(K<Z)cout<<X-K*D;
    else{
        if ((Z-K)%2==0) cout<<abs(X-Z*D);
        else cout<<abs(X-(Z+1)*D);
    }
}


Measured memory_bytes: 3588
from collections import deque

S = deque(input())
lenq = int(input())
Q = [input() for _ in range(lenq)]

# len(S) <= 100000
# lenq <= 2 * 10 ** 5

# q == '1' のとき、実際に反転すると O(N)かかるので反転しないで、
# どちらが先頭かだけの情報を持っておく
head = 1 # or -1
for q in Q:
    if q == '1':
        head *= -1
    else:
        _, f, c = q.split()
        if f == '1':
            if head == 1:
                S.appendleft(c)
            else:
                S.append(c)
        else:  # f == '2'
            if head == 1:
                S.append(c)
            else:
                S.appendleft(c)
S = ''.join(list(S))
if head == -1:
    S = S[::-1]
print(S)


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

string s;
long long it;
vector<string> perm;

long long numCalc(vector<long long> num, string ope) {
	
	
	for(long long o=0;o<3;o++) {
		for(long long i=0;i<ope.size();i++) {
			if(find(perm[o].begin(), perm[o].end(),ope[i]) != perm[o].end()) {
				if(ope[i]=='+')
				{
					num[i] += num[i+1];
				}else if(ope[i]=='-')
				{
					num[i] -= num[i+1];
				}else if(ope[i]=='*')
				{
					num[i] *= num[i+1];
				}
				num.erase(num.begin()+(i+1));
				ope.erase(ope.begin()+i);
				i--;
			}
		}
	}
	return num[0];
}
long long calc(void)
{
	long long ans = 0;
	string ope;
	vector<long long> num; 
	while(it<s.size())
	{
		if(s[it]=='(')
		{
			it++;
			num.push_back(calc());
		}
		else if(s[it]==')')
		{
			it++;
			return numCalc(num,ope);
		}
		else
		{
			if(s[it]<'0' or s[it]>'9')
				ope.push_back(s[it]);
			else
			{
				string tmp = "";
				tmp += s[it++];
				while(it<s.size())
				{
					if(s[it]<'0' or s[it]>'9')
					{
						it--;
						break;
					}
					tmp+=s[it++];
				}
				num.push_back(stoll(tmp));
			}
			it++;
		}
	}
	return numCalc(num, ope);
}

int main() {
	cin >> s;
	long long ans = LLONG_MIN;
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			for(int k=0;k<3;k++)
			{
				perm=vector<string>(3);
				perm[i].push_back('+');
				perm[j].push_back('-');
				perm[k].push_back('*');
				it=0;
				ans = max(ans, calc());
			}
	cout << ans << endl;


}


Measured memory_bytes: 3248
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
vector<tuple<int,int,int>>v;
lli dp[100000][3];
#define m_t make_tuple
#define pb push_back

lli knapsack(int weight[],int value[],int N,int W)
{
    lli dp[N+1][W+1];
    int i,j;
    
    for(i=0;i<=N;i++)
    dp[i][0]=0;
    for(i=0;i<=W;i++)
    dp[0][i]=0;
    
    for(i=1;i<=N;i++)
    {
        for(j=1;j<=W;j++)
        {
            if(weight[i-1]<=j)
                dp[i][j]=max(value[i-1]+dp[i-1][j-weight[i-1]],dp[i-1][j]);
            else
              dp[i][j]=dp[i-1][j];
        }
    }
    
    return dp[N][W];
}

int main()
{
	int N,W,i;
	cin>>N>>W;
	
	int weight[N],value[N];
	
	for(i=0;i<N;i++)
	cin>>weight[i]>>value[i];
	
	cout<<knapsack(weight,value,N,W);
	
	
	
	return 0;
}

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

int main () {
  int  N, M, X, Y;
  cin >> N >> M >> X >> Y; 
  
  vector <int> x(N);
  vector <int> y(M);
  for (int i = 0; i < N; i++) cin >> x.at(i);
  for (int i = 0; i < M; i++) cin >> y.at(i);
  sort (x.begin(),x.end());
  sort (y.begin(),y.end());
  int y_min = y.at(0);
  
  bool ans = true;
  if (X >= y_min) ans = false;
  else if (x.at(N-1) >= y_min) ans = false;
  else if (y_min > Y) ans = false;
  if (!ans) cout << "War" << endl;
  else cout << "No War" << endl;
}

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

# define F first
# define S second
# define mp make_pair
// everything go according to my plan
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right

using namespace std;

typedef pair <int, int> pii;
typedef long long ll;
typedef long double ld;

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput (string in = "s") {
  if (fopen (in.c_str(), "r"))
    freopen (in.c_str(), "r", stdin);
  else {
    cerr << "Input file not found" << endl;
  }
}    
int cnt[Sz];

int used[Sz];

int n, m;

int main()
{
  Read_rap();
  localInput();
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cnt[i]++;

  used[1] = 1;
  for (int i = 1; i <= m; i++) {
    int x, y; 
    cin >> x >> y;
    cnt[x]--;
    cnt[y]++;
    if (used[x])
      used[y] = 1;
    if (!cnt[x]) {
      used[x] = 0;
    }
  }
  cout << accumulate (used + 1, used + n + 1, (int)0);         

     


  return 0;
}










// Coded by Z..


Measured memory_bytes: 2688
#include <iostream>
using namespace std;
int main(void){
    int n;
    int sum = 0;
    cin >>n;
    int *b = new int[n-1];
    for (int i= 0;i< n-1; ++i){
        cin >> b[i];
    }
    
    sum += b[0];
    for (int i = 1;i < n-1;i++){
        if (b[i] > b[i-1]){
            sum += b[i-1];   
        }else{
            sum += b[i];
        }
    }
    sum += b[n-2];
    cout << sum<<endl;
    
}


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

int main() {
    vector<int> n(3);
    for(int i = 0; i < 3; i++)
    {
        cin >> n.at(i);
    }
    
    bool ans = true;

    for(int i = 0; i < 2; i++)
    {
        if(n.at(i) != n.at(i+1))ans = false;
    }
    

    if(ans)cout << "Yes\n";
    else cout << "No\n";

}

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

using namespace std;

int main()
{
    int row,col,n,p,q,i,a=0,b=0;
    cin>>row>>col>>n;
    for(i=1;i<=row;i++){
        a+=row;
        p=i;
        if(a>=n)
        break;
    }
     for(i=1;i<=col;i++){
        b+=col;
        q=i;
        if(b>=n)
        break;
    }
    cout<<min(p,q)<<endl;
}

Measured memory_bytes: 256
H, W, h, w = gets.split.map(&:to_i)
if H%h == 0 && W%w == 0
    puts 'No'
    exit
end

plus = 10**9 / h / w
minus = -plus*(h*w - 1) - 1

ans = Array.new(H){Array.new(W)}
H.times do |i|
    W.times do |j|
        ans[i][j] = ((i+1)%h == 0 && (j+1)%w == 0 ? minus : plus)
    end
end
puts 'Yes'
ans.each do |row|
    puts row.join(' ')
end

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

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

  bool mae = false,usiro = false;
  if ( (char)s[0] == '0' && (char)s[1] != '0'){
    mae = true;
  }else if ( ( (char)s[0] == '1' ) && ( (char)s[1] == '1' || (char)s[1] == '2') ){
    mae = true;
  }

  if ( (char)s[2] == '0' && (char)s[3] != '0'){
    usiro = true;
  }else if ( ( (char)s[2] == '1' ) && ( (char)s[3] == '1' || (char)s[3] == '2') ){
    usiro = true;
  }
  if (mae == true && usiro == true ) cout << "AMBIGUOUS" << endl;
  else if (mae == true ) cout << "MMYY" << endl;
  else if (usiro == true ) cout << "YYMM" << endl;
  else cout << "NA" << endl;

  return 0;
}


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

int main() {

  int K;
  string S;
  
  cin >> K;
  cin >> S;
  
  if(S.size() <= K){
  cout << S << endl;
  }
  
  else{
   for(int i=0; i < K; i++){
   cout << S.at(i);
   } 
    cout << "..." << endl;
  }
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9 + 10)
#define PI (acos(-1))
#define MOD (1000000007)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int N,M;
    cin >> N;
    cin >> M;
    vector<vector<int>> G;
    vector<vector<int>> R;
    int h[N] = {};//入次数をここで管理する
    G.assign(N, vector<int>());
    R.assign(N, vector<int>());
    REP(i, N+M-1) {
        int x, y;
        cin >> x;cin >> y;
        G[x-1].push_back(y-1);
        R[y-1].push_back(x-1);
        h[y-1]++;
    }
    stack<int> st;
    REP(v, N) {
        if (h[v] == 0) st.push(v);
    }
    int topo[N];//Nのトポロジカル順位をここにぶち込む
    int rank = 0;
    while (!st.empty()){
        int v = st.top();st.pop();
        topo[v] = rank++;
        for (int u:G[v]){
            h[u]--;
            if(h[u] == 0) st.push(u);
        }
    }
    int prev;
    REP(v, N) {
        prev = -1;rank = -1;
        if (!R[v].empty()){
            for(int u: R[v]){
                if (chmax(rank, topo[u])) prev = u;
            }
        }
        cout << prev + 1 << endl;
    }
}

Measured memory_bytes: 12544
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int k,s,ans=0;
  cin >> k >> s;
  for(int i=0; i<=k; i++) {
    for(int j=0; j<=k; j++) {
      if(s-i-j<=k&&s-i-j>=0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}


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

#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
#define pb push_back
#define sz(s) (int)s.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define for1(i,n) for(int i=1;i<=(int)n;i++)
#define ford(i, b, a) for (int i = (int)(b); i >= a; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
const int N = (int)1e5+77;
const ll inf = (ll) 1e15+77;
const int mod = (int) 1e9 + 7;
const ld pi = acos(-1);

ll dp[3005][3005];
int main() {
    fast;
    int n;
    cin >> n;
    vector<int> a(n);
    forn(i, n) cin >> a[i];
    ford(L, n - 1, 0) {
        fore(R, L, n - 1) {
            if (L == R) dp[L][R] = a[L];
            else dp[L][R] = max(a[L] - dp[L + 1][R], a[R] - dp[L][R - 1]);
        }
    }
    cout << dp[0][n - 1] << endl;
    return 0;
}

Measured memory_bytes: 70016
#include<iostream>

using namespace std;

int summary(int n)
{int sum = 0;
 
 while( n > 0)
 {sum += n %10;
  n /= 10;
 }
 return sum;
}
//桁和計算

int main()
{int N,A,B;
 int cnt = 0;
  cin >> N >> A >> B;

 for(int i = 1; i <= N ; i++ )
 {int c = summary(i);
  
  if(c >= A && c <= B){cnt += i;}
 }
 cout << cnt << endl;
 return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

N, M = list(map(int, input().split()))
ps_list = [[] for _ in range(N)]

for _ in range(M):
    p, s = list(input().split())
    p = int(p) - 1
    ps_list[p].append(s)

wa_c = 0
ac_c = 0
total_wa_c = 0

for i, ss in enumerate(ps_list):
    wa_c = 0
    for s in ss:
        if s == "WA":
            wa_c += 1
        else:
            ac_c += 1
            total_wa_c += wa_c
            break

ans = "{} {}".format(ac_c, total_wa_c)
print(ans)


Measured memory_bytes: 20400
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,q,a[100001];
	cin>>n>>k>>q;
	memset(a,0,sizeof(a));
	int ai;
	for(int i=0;i<q;i++)
	{
		scanf("%d",&ai);
		a[ai]++;
	}
	for(int j=1;j<=n;j++)
		if(a[j]<q-k+1) printf("No\n");
		else printf("Yes\n");
	return 0;
}

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

int main()
{
	int b;
	vector<int> a;
	for (int i = 0; i < 3; i++)
	{
		cin >> b;
		a.push_back(b);
	}
	sort(a.rbegin(), a.rend());
	cout << 10 * a[0] + a[1] + a[2];
	return 0;
}

Measured memory_bytes: 256
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    l, r = list(map(int, readline().split()))
    t = 10 ** 20
    for i in range(l, r):
        for j in range(i + 1, r + 1):
            t = min(t, (i * j) % 2019)
            if t == 0:
                print(t)
                exit()
    print(t)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38768
#include<cstdio>
#include<algorithm>
using namespace std;

#define int long long

int a[111111];

signed main(){
  int n;
  int f,s;
  
  f = s = 0;
   
  scanf(" %lld",&n);
  for(int i=0;i<n;i++){
    scanf(" %lld",&a[i]);
  }
  
  sort(a, a+n);
  
  for(int i=n-1;0<i;i--){
    if(f && s)break;

    if(f == 0 && a[i-1] == a[i]){
      f = a[i];
      i--;
    } else if(a[i-1] == a[i]){
      s = a[i];
      i--;
    }
  }
  
  printf("%lld\n",f*s);
   
  return 0;
}  

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

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

    float ans = 0.0;
    for (int i = 0; i < N; i++) {
        float x;
        cin >> x;
        ans += 1 / x;
    }

    cout << (1 / ans) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
vector<ll>adj[100005];
ll vis[100005];
ll level[100005];
ll ans=1;
ll n,m;
ll n1;
void bfs(ll s)
{
   queue<ll>q;
   q.push(s);
   vis[s]=true;
   level[s]=0;
   ans=(ans*n1)%mod;
   ll count=0;
   while(!q.empty())
   {
       count++;
       ll p= q.front();
       q.pop();
       ll f1;
       if(count==1)
       f1=n1-1;
       else
       f1 = n1-2;
       for(int i=0;i<adj[p].size();i++)
       {
           if(vis[adj[p][i]]==false)
           {
               level[adj[p][i]]=level[p]+1;
               ans=(ans*(f1)%mod)%mod;
               f1--;
               vis[adj[p][i]]=true;
               q.push(adj[p][i]);
           }
       }
   }
}

signed main()
{   
      senky_bansal
      IIIT_ALLAHABAD
      
      cin>>n>>m;
      n1=m;
      for(int i=0;i<n-1;i++)
      {
          ll a,b;
          cin>>a>>b;
          adj[a].pb(b);
          adj[b].pb(a);
      }
      bfs(1);
      cout<<ans%mod<<endl;
    
    
}









Measured memory_bytes: 8948
#include <iostream>
#include <unistd.h>
#include <cmath>
#include <vector>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

const ll INF    = 1e16;
ll dp[110][101010];

int main(){
    ll n, W;
    cin >> n;
    cin >> W;
    vector<ll>w(n);
    vector<ll>v(n);
    rep(i, n)   cin >> w[i] >> v[i];
    //DPtable
    ll maxV = n*1000;
    for(int i = 0; i <= n; i++) for(int j = 0; j <= maxV; j++){
        dp[i][j] = INF;
    }
    dp[0][0] = 0;
    rep(i, n){
        for(int j = 0; j <= maxV; j++){
            if(j >= v[i]){   //i番目を入れる
                dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]]+w[i]);
            }else{
                dp[i+1][j] = dp[i][j];
            }
          	/*
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            dp[i+1][j+v[i]] = min(dp[i+1][j+v[i]], dp[i][j]+w[i]);
            */
        }
        //debug
      /*
        printf("   |");
        for(int j = 0; j <= 18; j++)    printf("%3d", j);
        printf("\n---+");
        for(int j = 0; j <= 18; j++)    printf("---");
        printf("\n");
        rep(i, 8){
            printf("%3d|", i);
            for(int j = 0; j <= 18; j++){
                if(dp[i][j] == INF){
                    printf("INF");
                }else{
                    printf("%3lld", dp[i][j]);
                }
            }
            printf("\n");
        }
        sleep(1);
        printf("\n");
        */
    }
    ll ans = 0;
    for(ll i = 0; i <= maxV; i++){
        if(dp[n][i] <= W)   ans = max(ans, i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 80128
N=int(input())
P=list(map(int,input().split()))
count=0
flag=0
for i in range(N):
    if flag:
        flag=0
        continue
    if P[i]==i+1:
        count+=1
        if i!=N-1:
            if P[i+1]==i+2:
                flag=1
print(count)


Measured memory_bytes: 53036
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;
using MIte = multimap<vector<long>, int>::iterator;

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

	int N, M;
	cin >> N >> M;

	vector<int> vL(N,0);
	vector<int> vR(N, 0);

	int Lmax = 0;
	int Rmin = N + 1;
	rep(i, M) {
		int L, R;
		cin >> L >> R;
		Lmax = max(L, Lmax);
		Rmin = min(R, Rmin);
	}

	if (Rmin >= Lmax) {
		cout << (Rmin - Lmax + 1) << endl;
	}
	else {
		cout << "0" << endl;
	}


	return 0;
}

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

using namespace std;

const int N = 1234567;

int z[N];
int a[N];
int pos[N];
int at[N];

int main() {
  int n, m, q;
  scanf("%d %d", &n, &m);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", z + i);
    z[i]--;
  }
  for (int i = 0; i < m; i++) {
    a[i] = -1;
    pos[i] = -1;
    at[i] = 0;
  }
  int known = 0;
  at[0] = n;
  at[m] = 0;
  for (int it = q - 1; it >= 0; it--) {
    int i = z[it];
    if (pos[i] == -1) {
      a[known] = i;
      pos[i] = known;
      at[known]--;
      known++;
      at[known]++;
      continue;
    }
    if (at[pos[i]] > 0) {
      at[pos[i]]--;
      at[pos[i] + 1]++;
    }
  }
  int first = -1;
  for (int i = 0; i <= m; i++) {
    if (at[i] > 0) {
      first = i;
      break;
    }
  }
  vector <int> all;
  for (int i = first; i < known; i++) {
    all.push_back(a[i]);
  }
  for (int i = 0; i < m; i++) {
    if (pos[i] == -1) {
      all.push_back(i);
    }
  }
  sort(all.begin(), all.end());
  for (int i = first; i < known; i++) {
    if (all[i - first] != a[i]) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef  long long ll;
int gcd(int f , int s){if(s==0)return f;else return gcd(s,f%s);}
int const N = 1000006;
ll const M = 1020;
long double const ep = .000000000000000001;
stack<int> q;
vector<pair < int , int > > ans;
int curr = 2, n ; 
void go(int node , int lol){
	while(q.size()!=0){
		int num = q.top();
		ans.pb(mp(node , curr));
		lol -= num;
		q.pop();
		go(curr++ , num - 1);
	}
	for(int i = 0 ; i < lol ; i++){
		ans.pb(mp(node,curr++));
	}
}
int main() {
	
	string s;cin >> s;
	n = s.length();
	if(s[0] == '0'){printf("-1\n");return 0;}
	if(s[s.length()-1] == '1'){printf("-1\n");return 0;}
	int to = ceil(s.length() / 2.0);
	for(int i = 0 ; i < to ; i++){
		if(s[i] != s[s.length() - 2 - i]){
			printf("-1\n");
			return 0;
		}
		if(s[i] == '1')q.push(i+1);
	}
	go(1 , n - 1);
	for(int i = 0  ; i < ans.size() ;i++)printf("%d %d\n", ans[i].first , ans[i].second);
	return 0;
}

Measured memory_bytes: 5428
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> b[i];

    vector<vector<ll>> can(n, vector<ll>(51));
    REP(i, n) can[i][a[i]] = 1;

    ll ret = 0;
    for(ll i=50; i>=1; --i) {
        vector<vector<ll>> d(51, vector<ll>(51, INF));
        REP(j, 51) d[j][j] = 0;
        FOR(j, 1, i) REP(k, 51) chmin(d[k][k%j], 1LL<<j); 
        REP(k, 51) REP(a, 51) REP(b, 51) chmin(d[a][b], d[a][k]+d[k][b]);

        bool ok = true;
        REP(j, n) {
            bool flag = false;
            REP(k, 51) if(can[j][k] && d[k][b[j]] != INF) flag = true;
            if(!flag) ok = false;
        }
        if(!ok) {
            ret += 1LL<<i;
            REP(j, n) REP(k, 51) if(can[j][k]) can[j][k%i] = 1;
        }
    }

    bool flag = true;
    REP(i, n) if(!can[i][b[i]]) flag = false;
    if(flag) cout << ret << endl;
    else cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007
#define M 998244353

using namespace std;

int main(){
    lli n,Min=0,sum=0;
    string s;
    lli i,j=0;
    cin>>s;
    n=s.size()+1;
    vector<lli> vec(n,0);
    rep(i,0,n-1){
        if(s[i]=='<'){
            vec[i+1]=vec[i]+1;
        }
    }
    rrep(i,n-1,-1){
        if(s[i]=='>'){
            vec[i]=max(vec[i],vec[i+1]+1);
        }
    }
    rep(i,0,n){
//        cout<<vec[i]<<" ";
        sum+=vec[i];
    }
//    cout<<endl;
    cout<<sum<<endl;
}


Measured memory_bytes: 4740
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        bool debugFlg = false;
        if (debugFlg)
        {
            var exStdIn = new System.IO.StreamReader("stdin.txt");
            System.Console.SetIn(exStdIn);
        }
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }

    static Scanner cin;

    void calc()
    {
        int N = cin.nextInt();
        int ans = 0;
        for (int i = 1; i <= N; i++)
        {
            string chk = i.ToString();
            if (chk.Length % 2 == 1) ans++;
        }

        Console.WriteLine($"{ans}");
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 13268
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char[] c = str.toCharArray();
        
        boolean ok = false;
        if (c[0] == c[1] && c[2] == c[3] && c[0] != c[2]) {
            ok = true;
        } else if (c[0] == c[2] && c[1] == c[3] && c[0] != c[1]) {
            ok = true;
        } else if (c[0] == c[3] && c[1] == c[2] && c[0] != c[1]) {
            ok = true;
        }
        
        if (ok) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int y = scan.nextInt();
        int r;
        while(x != 0){
            r = y%x;
            y = x;
            x = r;
        }
        System.out.println(y);
    }
}


Measured memory_bytes: 26196
import itertools
N = int(input())
L = input().split()
L = [int(x) for x in L]
counter = 0
if N < 3:
  print(0)
  exit()
listed = {}
set_li = []
for i in L:
  if i in listed:
    listed[i] += 1
  else:
    listed[i] = 1
for i in L:
  if i in set_li:
    continue
  else:
    set_li.append(i)
p_lis = []
for p in itertools.combinations(set_li, 3):
  p_lis.append(p)
for i in p_lis:
  a, b, c = i[0], i[1], i[2]
  if a + b > c and a + c > b and b + c > a:
    counter += 1 * listed[a] * listed[b] * listed[c]
print(counter)

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

// string max(string p,string q){
// 	if(p.length() > q.length()){
// 		return p;
// 	}
// 	return q;
// }

string solve(string p,string q){
	int m = p.length();
	int n = q.length();

	int dp[m+1][n+1] = {0};

	for(int i=0;i<m+1;i++){
		for(int j=0;j<n+1;j++){
			if(i==0||j==0){
				dp[i][j] = 0;
			}
			else if(p[i-1] == q[j-1]){
				dp[i][j] = dp[i-1][j-1] + 1;
			}
			else{
				dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
			}
		}
	}

	string ans = "";
	int i = m;
	int j = n;
	while(i>=1 && j>=1){
      if(dp[i][j]!=max(dp[i-1][j],dp[i][j-1])) {ans=ans+p[i-1];i--;j--;}
      else if(dp[i][j]==dp[i-1][j]) i--;
      else j--;
  }
  reverse(ans.begin(),ans.end());
	return ans;

	// return dp[m][n];
}

int main(){
	string p,q;
	cin>>p>>q;
	cout<<solve(p,q)<<endl;
}

Measured memory_bytes: 35456
#include <iostream>
#include<cstdio>
using namespace std;

int main() {
	int a[4],b[4];
	while(~scanf("%d%d%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&b[0],&b[1],&b[2],&b[3]))
	{
		bool v[4];
		int ch=0,cb=0;
		for(int i=0;i<4;i++)v[i]=true;
		for(int i=0;i<4;i++)
		{
			if(a[i]==b[i])
			{
				v[i]=false;
				ch++;
			}
		}
		for(int i=0;i<4;i++)
		{
			for(int j=0;v[i]&&j<4;j++)
			{
				if(a[i]==b[j])
				{
					cb++;
				}
			}
		}
		cout<<ch<<" "<<cb<<endl;
	}
	return 0;
}

Measured memory_bytes: 3096
import java.io.*;
import java.util.*;
public class Main
{
  public static void main(String args[])throws IOException
   {
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tk;
    
    int n=Integer.parseInt(br.readLine());
    int task[][]=new int[n][3];
   
    for(int i=0;i<n;i++)
    {
       tk=new StringTokenizer(br.readLine());
      for(int j=0;j<3;j++)
      { 
        task[i][j]=Integer.parseInt(tk.nextToken());
       }
      
    }
    int dp[]=new int[3];
    
     for(int i=0;i<n;i++)
    {
       int new_dp[]=new int[3];
      for(int j=0;j<3;j++)
      {
        for(int k=0;k<3;k++)
        {
           if(j!=k)
             new_dp[j]=Math.max(dp[k]+task[i][j],new_dp[j]);
          
        }
                              
        
      }
       dp=new_dp;  
       
      
      
    }
    System.out.println(Math.max(dp[0] , Math.max(dp[1],dp[2])));
    
    
    
    
    
  }
  
}
 
 

Measured memory_bytes: 46224
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9) + 7;
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int res = 0;
		
		if (a <= b) {
			res = a;
		} else {
			res = a - 1;
		}
		
		System.out.println(res);
	}

    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 21204