akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int gcd(int,int);
int main(){
    int N;
    cin >> N;
    int A[N];
    for(int i = 0;i < N;i++){
        cin >> A[i];
    }
    int R[N + 2];
    int L[N + 2];
    R[0] = L[0] = 0;
    R[N + 1] = L[N + 1] = 0;

    for(int i = 0;i < N;i++){
        L[i + 1] = gcd(L[i],A[i]);
    }
    for(int i = N;i >= 1;i--){
        R[i] = gcd(R[i + 1],A[i - 1]);
    }
    int ans = 0;
    for(int i = 1;i <= N;i++){
        ans = max(ans,gcd(L[i - 1],R[i + 1]));
    }
    cout << ans << endl;


    return 0;
}

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

Measured memory_bytes: 1408
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! flush {
    () => {
        std::io::stdout().flush().unwrap();
    };
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut xs: Vec<i64> = sc.vec(n);
    xs.reverse();
    let mut ok = true;
    for i in 1..n {
        // trace!(&xs);
        if xs[i] <= xs[i - 1] {
        } else if xs[i] - 1 <= xs[i - 1] {
            xs[i] = xs[i] - 1;
        } else {
            ok = false;
            break;
        }
    }
    put!(if ok { "Yes" } else { "No" });
}

use std::collections::VecDeque;
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Scanner {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}


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

int main() {
    string s;
    cin>>s;
    int n=s.size()+1;
    int a[n],b[n];
    a[0]=b[n-1]=0;
    for(int i=0;i<n-1;i++){
        if(s[i]=='<'){
            a[i+1]=a[i]+1;
        }
        else{
            a[i+1]=0;
        }
    }
    for(int i=n-2;i>=0;i--){
        if(s[i]=='<'){
            b[i]=0;
        }
        else{
            b[i]=b[i+1]+1;
        }
    }
    long long res=0;
    for(int i=0;i<n;i++){
        res+=max(a[i],b[i]);
    }
    cout<<res<<"\n";
    return 0;
}

Measured memory_bytes: 4740
x,y = map(int,input().split())
table = []
for i in range(y,y+x):
    table.append(i)

if table[-1] <= 0:
    ans = sum(table) - table[-1]
elif table[0] < 0 and 0 <= table[-1]:
    ans = sum(table)
elif 0 <= table[0]:
    ans = sum(table) - table[0]
print(ans)





Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
    string s[101];
    int n,i,j,f=0;
    cin >> n;
    cin >> s[1];
    for (i=2;i<=n;i++){
        cin >> s[i];
        if (s[i-1][s[i-1].size()-1]!=s[i][0])
            f=1;
    }
    for (i=1;i<=n;i++){
        for (j=1;j<=n;j++){
            if (i==j)
                continue;
            if (s[i]==s[j])
                f=1;
        }
    }
    if (f==0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
char s[1005];
int t[5];
int main()
{
 scanf("%s",s);
 int len=strlen(s);
 for(int i=0;i<len;i++)
  if(s[i]=='N')t[1]=1;
  else if(s[i]=='S')t[2]=1;
  else if(s[i]=='W')t[3]=1;
  else t[4]=1;
 if((t[1]^t[2])||(t[3]^t[4]))puts("No");
 else puts("Yes");
 return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;
const int INF = 1 << 30;
const long long MOD = 1000000000 + 7;

// 最小公約数
long long gcd(long long a, long long b) {
	if (a % b == 0)return(b);
	else return(gcd(b, a % b));
}

// 最小公倍数
long long lcm(long long a, long long b) {
	return a * b / gcd(a, b);
}

int main() {
	long long A, B, C, D; cin >> A >> B >> C >> D;
	long long range = B - A + 1;
	long long ans = range;
	long long div = C;
	long long num = B / div - (A - 1) / div;
	ans -= num;
	div = D;
	num = B / div - (A - 1) / div;
	ans -= num;
	div = lcm(C, D);
	num = B / div - (A - 1) / div;
	ans += num;

	cout << ans;

}

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

struct pair {
  int index;
  int value;
};

int main(int argc, char**argv) {
  int n;
  std::cin >> n;
  std::vector<int> a(n);

  for(int i = 0; i < n; i++) {
    std::cin >> a[i];
  }

  pair max = {0, a[0]};
  pair min = {0, a[0]};

  for(int i = 0; i < n; i++) {
    if(a[i] < min.value) {
      min.index = i;
      min.value = a[i];
    } else if (max.value < a[i]) {
      max.index = i;
      max.value = a[i];
    }
  }

  /*
   * a[i] += min.value (or max.value)
   * a[i] = sum(a, 0..i) + i * max.value(or (n-i) * min.value)
   */
  std::cout << 2 * n - 2 << std::endl;

  if(min.value * -1 > max.value) {
    for(int i = 0; i < n; i++) {
      if(min.index != i) {
        std::cout << min.index + 1<< " " << i + 1<< std::endl;
      }
    }
    for(int i = n - 1; i > 0; i--) {
      std::cout << i+ 1 << " " << i << std::endl;
    }
  } else {
    for(int i = 0; i < n; i++) {
      if(max.index != i) {
        std::cout << max.index + 1<< " " << i + 1<< std::endl;
      }
    }
    for(int i = 1; i < n; i++) {
      std::cout << i<< " " << i + 1<< std::endl;
    }
  }
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <tuple>
#include <cstdio>

using namespace std;
int main() {
    int A,B;
    cin >> A >> B;

    int ans = 0;
    if ((B-A)%2 == 0) {
        ans = abs((B-A)/2);
        ans += (A < B) ? A : B;
        cout << ans << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX

#include <bits/stdc++.h>
#define db(x) cout << (x) << '\n';
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<double,ll> pdi;
typedef pair<ld,ld> pdd;
typedef pair<double,ll> pdi;
typedef pair<double,pii> pdp;
typedef pair<string,ll> psi;
typedef pair<ll,string> pls;
typedef pair<string,string> pss;
typedef pair<ll,pii> pip;
typedef pair<pii,pii> ppp;
typedef complex<ld> point;
#define mod (ll)(998244353)
#define eps (1e-9)
#define oo (ll)(0x3f3f3f3f)
#define pi acos(-1)
#define MAXN (ll)(3e3+5)

ll dp[MAXN][MAXN];

ll qp(ll b,ll e)
{
    if(!e)
        return 1;
    ll x=qp(b,e/2);
    x=(x*x)%mod;
    if(e&1)
        x=(x*b)%mod;
    return x;
}

ll prec[MAXN][MAXN];
ll preci[MAXN];

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

    for(int i=1;i<MAXN;i++)
    {
        prec[i][0]=1;
        ll f1=i;
        for(int e=1;e<MAXN;e++)
            prec[i][e]=(prec[i][e-1]*f1)%mod;
    }

    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    dp[a][b]=qp(a,d-b);
    for(ll i=a+1;i<=c;i++)
    {
        for(ll j=b+1;j<=d;j++)
            dp[i-1][j]=(dp[i-1][j]+dp[i-1][j-1])%mod;;
        ll f1=qp(i-1,mod-2);
        preci[0]=1;
        for(int j=1;j<MAXN;j++)
            preci[j]=(preci[j-1]*f1)%mod;
        for(ll j=b+1;j<=d;j++)
        {
            ll f1=(dp[i-1][j-1]+j*((dp[i-1][j]-dp[i-1][j-1]+mod)%mod))%mod;
            ll f2=(prec[i][d-j]*preci[d-j])%mod;
            dp[i][j]=(f1*f2)%mod;
        }
        dp[i][b]=(b*dp[i-1][b])%mod;
        ll f2=(prec[i][d-b]*preci[d-b])%mod;
        dp[i][b]=(dp[i][b]*f2)%mod;
    }
    for(ll j=b+1;j<=d;j++)
        dp[c][j]=(dp[c][j]+dp[c][j-1])%mod;
//    for(int i=a;i<=c;i++,cout << '\n')
//        for(int j=b;j<=d;j++)
//            cout << dp[i][j] << ' ';
    db(dp[c][d])

    return 0;
}
/**
2 1 3 4
31 41 59 265
**/


Measured memory_bytes: 144528
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
template<typename T> inline void chkmin(T &a, const T &b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T &a, const T &b) { a = a > b ? a : b; }

const int MAXN = 2005, MAXM = 4000005, MOD = 1e9 + 7;
int f[MAXN][MAXN], g[MAXM], inv[MAXM], n, K;

int main() {
	scanf("%d%d", &n, &K);
	if (K == 1) return puts("1") * 0;
	inv[1] = 1;
	for (int i = 2; i <= n * K; i++)
		inv[i] = MOD - (LL)MOD / i * inv[MOD % i] % MOD;
	g[K - 2] = 1;
	for (int i = K - 1; i <= n * K; i++)
		g[i] = (LL)g[i - 1] * i % MOD * inv[i - K + 2] % MOD;
	f[n][n] = 1;
	for (int i = n - 1; i >= 0; i--)
	for (int j = n; j >= i; j--)
		f[i][j] = (f[i + 1][j] + (LL)f[i][j + 1] * g[i + (K - 1) * (j + 1) - 1] % MOD * (j + 1)) % MOD;
	printf("%d\n", f[0][0]);
	return 0;
}

Measured memory_bytes: 46336
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define HEAP(T) priority_queue<T>
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__>,greater<__VA_ARGS__> > 
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define error(...) fprintf(stderr,__VA_ARGS__)
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
using namespace std;

const int N=200005,M=100005,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
template<class T,class S> inline void ch(T &x,const S y){x=(x+y)%mod;}
const int BufferSize=1<<16;
char buffer[BufferSize],*Bufferhead,*Buffertail;
bool Terminal;
inline char Getchar(){
	if(Bufferhead==Buffertail){
		int l=fread(buffer,1,BufferSize,stdin);
		if(!l){Terminal=1;return 0;}
		Buffertail=(Bufferhead=buffer)+l;
	}
	return *Bufferhead++;
}
template<class T>inline bool read(T &x){
	x=0;char c=Getchar(),rev=0;
	while(c<'0'||c>'9'){c=Getchar();rev|=c=='-';if(Terminal)return 0;}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
	x=rev?-x:x;
	return 1;
}
inline bool reads(char *x){
	char c=Getchar();
	while(c<33||c>126){c=Getchar();if(Terminal)return 0;}
	while(c>=33&&c<=126) (*x++)=c,c=Getchar();
	*x=0;return 1;
}
template<class T>inline void print(T x,const char c){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[10];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
inline int exp(int x,int y,const int mod=::mod){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,tot,lg[N],p[N],x[N],pos[N],f[2][N][20],ans[N];
bool vis[N];
heap(pair<int,pii> ) q;
int get(int l,int r){
	int p=l&1,x=lg[r-l+1];
	return min(f[p][l][x],f[p][r-(1<<x)+1][x]);
}
void push(int r,int l){
	if(l>r) return;
	int k=get(l,r);
	q.push(mp(k,mp(l,r)));
}

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	scanf("%d",&n);
	for(int i=2;i<=n+4;i++) lg[i]=lg[i>>1]+1;
	for(int i=1;i<=n;i++){
		scanf("%d",&x[i]);
		pos[x[i]]=i;
		f[i&1][i][0]=x[i];f[i-1&1][i][0]=inf;
	}
	for(int p=0;p<2;p++)
	for(int j=1;j<20;j++)
		for(int i=1;i<=n;i++)
			if(i+(1<<j)<=n+1) f[p][i][j]=min(f[p][i][j-1],f[p][i+(1<<j-1)][j-1]);
	push(n,1);
	while(!q.empty()){
		int k=pos[q.top().FF],l=q.top().SS.FF,r=q.top().SS.SS;q.pop();
		if(l<k) push(k-1,l);
		int g=pos[get(k+1,r)];
		if(k+1<=g-1) push(g-1,k+1);
		if(g+1<=r) push(r,g+1);
		ans[++tot]=x[k];ans[++tot]=x[g];
		vis[x[k]]=1,vis[x[g]]=1;
	}
	for(int i= 1;i<=n;i++)
		printf("%d%c",ans[i],i<n?' ':'\n');
	return 0;
}

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

typedef pair<int, int> P;

int N, M, H, K;
int S[1010];
vector<P> V[1010];
int A[100010], B[100010];
int R[10010];
int HS[1010][1010];

int f(int x, int h, int s) {
  auto it = lower_bound(V[x].begin(), V[x].end(), P(h+1, 0));
  if (it == V[x].end()) return S[x];
  P p = *it;
  int d = p.second, nh = p.first;
  HS[x][nh] = s;
  return f(d, nh, s);
}

int main() {
  while (cin >> N >> M >> H >> K) {
    if (N == 0 && M == 0 && H == 0 && K == 0) break;
    for (int i=1; i<=N; i++) {
      cin >> S[i];
      V[i].clear();
    }
    for (int i=0; i<M; i++) {
      cin >> A[i] >> B[i];
      V[A[i]].push_back(P(B[i], A[i]+1));
      V[A[i]+1].push_back(P(B[i], A[i]));
    }
    for (int i=1; i<=N; i++) sort(V[i].begin(), V[i].end());
    for (int i=1; i<=N; i++) R[i] = f(i, 0, i);
    int iv = 0;
    for (int i=1; i<=K; i++) iv += R[i];
    int m = iv;

    for (int i=0; i<M; i++) {
      int a = A[i], b = B[i];
      int xa = HS[a][b], xb = HS[a+1][b];
      if (xa > xb) swap(xa, xb);
      if (xa <= K && xb > K) m = min(m, iv - R[xa] + R[xb]);
    }
    cout << m << "\n";
  }
  return 0;
}

Measured memory_bytes: 9820
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sn = new Scanner(System.in);
		while(sn.hasNext()) {
			int n = sn.nextInt();
			int count = 0;
			for (int a = (n > 1000) ? 1000 : n; a >= 0; a--) {
				for (int b = (n - a > 1000) ? 1000 : n - a; b >= 0
						&& n - a - b <= 2000; b--) {
					int N = n - a - b;
					count += (N > 1000) ? 2000 - N + 1 : N + 1;
				}
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 19028
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;

int main()
{
	int A, B, C, D;

	cin >> A >> B >> C >> D;

	if (A + B == C + D)
		cout << "Balanced" << endl;
	else if (A + B > C + D)
		cout << "Left" << endl;
	else
		cout << "Right" << endl;

	return 0;
}

Measured memory_bytes: 256
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...) 
#define hash _hash
#define rank _rank
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)
 
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 100010
 
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}
 
//FILE* outFile;
 
inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}
 
int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}


int dp[N],f[N];
int main(){
    int T,i,j,k,n,m=0;
    scanf("%d%d",&n,&m);
    dp[0]=1;
    rep(i,0,n)f[i]=1;
    while(m--){
    	scanf("%d%d",&i,&j);i--,j--;
    	dp[j]|=dp[i];
    	f[j]++;f[i]--;
    	if(f[i]==0)dp[i]=0;
    }
    int ans=0;
    rep(i,0,n)if(dp[i])ans++;
    printf("%d\n",ans);
    //cerr<<1.*clock()/CLOCKS_PER_SEC<<"s\n";
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

const int SZ = 51;

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

int H, W;
bool visit[SZ][SZ][SZ][SZ];
string LIN[SZ], REN[SZ];

inline bool inside(int x, int y){
  return 0 <= x && x < H && 0 <= y && y < W;
}

bool bfs(int lsx, int lsy, int rsx, int rsy){
  memset(visit, false, sizeof(visit));
  visit[lsx][lsy][rsx][rsy] = true;
  queue<int> que_lx, que_ly, que_rx, que_ry;
  que_lx.push(lsx);
  que_ly.push(lsy);
  que_rx.push(rsx);
  que_ry.push(rsy);
  while(!que_lx.empty()){

    int lx = que_lx.front(); que_lx.pop();
    int ly = que_ly.front(); que_ly.pop();
    int rx = que_rx.front(); que_rx.pop();
    int ry = que_ry.front(); que_ry.pop();
    
    if(LIN[lx][ly] == '%' && REN[rx][ry] == '%') return true;
    REP(i, 4){
      int nlx = lx + dx[i];
      int nly = ly + dy[i];
      int nrx = rx + dx[i];
      int nry = ry + dy[(i+2)%4];
      
      if(!inside(nlx, nly) || LIN[nlx][nly] == '#') nlx = lx, nly = ly;
      if(!inside(nrx, nry) || REN[nrx][nry] == '#') nrx = rx, nry = ry;
      if(!visit[nlx][nly][nrx][nry] && !((LIN[lx][ly] == '%') ^ (REN[rx][ry]=='%'))){
        visit[nlx][nly][nrx][nry] = true;
        que_lx.push(nlx);
        que_ly.push(nly);
        que_rx.push(nrx);
        que_ry.push(nry);        
      }
    }
  }
  
  return false;
}


int main(){
  while(cin >> W >> H && H + W > 0){
    REP(i, H) cin >> LIN[i] >> REN[i];
    int rsx, rsy, lsx, lsy;
    
    REP(i, H)REP(j, W){
      if(LIN[i][j] == 'L') lsx = i, lsy = j;
      if(REN[i][j] == 'R') rsx = i, rsy = j;
    }
    cout << (bfs(lsx, lsy, rsx, rsy) ? "Yes" : "No") << endl;
      
  }
  return 0;
}

Measured memory_bytes: 8780
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
}init;




int main(){
  LLI N;
  while(cin >> N){
    LLI ans = LLONG_MAX;

    for(LLI i = 1; i*i <= N; ++i){
      if(N % i == 0){
        chmin(ans, i-1 + N/i-1);


        
      }
    }
    



    cout << ans << endl;
  }



  return 0;
}


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

int main()
{
    int H,W=0;
    int i,j=0;
    int count = 0;
    cin >>H>>W;
    char c[55][55];
    bool hantei ;
    
    for(i=1;i<=H;i++){
        for(j=1;j<=W;j++){
            cin >>c[i][j];
        }}
    
    for(i=1;i<=H;i++){
        for(j=1;j<=W;j++){
            if(c[i][j]=='#'){
                if(c[i][j+1]!='#'&&c[i][j-1]!='#'&&c[i+1][j]!='#'&&c[i-1][j]!='#')
    {
        count +=1;
    }
            }
    }
    }
    if(count  == 0){
        cout <<"Yes"<<endl;
    }
    else{
        cout <<"No" << endl;
    }
    
    
    
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>

using namespace std;
#define REP(i,m,n) for(long long i=m;i<n;++i)
#define INF 10000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define all(v) v.begin(),v.end()

vector<int>v{ 1,-1 };
vector<char>ch{ '+','-' };

int main() {
	string s;
	cin >> s;
	int a = (int)s[0] - (int)'0';
	int b = (int)s[1] - (int)'0';
	int c = (int)s[2] - (int)'0';
	int d = (int)s[3] - (int)'0';
	REP(i, 0, 2) {
		REP(j, 0, 2) {
			REP(k, 0, 2) {
				if (a + b*v[i] + c*v[j] + d*v[k] == 7) {
					cout << a << ch[i] << b << ch[j] << c << ch[k] << d << "=7" << endl;
					return 0;
				}
			}
		}
	}
	return 0;
}

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


int main(){

	int n=0;
	cin>>n;
	int *S=new int[n];
	for(int i=0; i<n;i++)
		cin>>S[i];

	int q=0;
	cin>>q;
	int *T=new int[q];
	for(int i=0; i<q; i++)
		cin>>T[i];

	int match=0;
	for(int i=0; i<q; i++)
		for(int j=0; j<n; j++)
			if(T[i]==S[j]){
				match++;
				break;
			}

	cout<<match<<endl;
	return 0;
}

Measured memory_bytes: 3596
#include <iostream> // cout, endl, cin
#include <vector> // vector
#include <string> // string, to_string, stoi

using namespace std;
int main(){
    int N;
    cin >> N;
    
    long long previous = 0;
    long long box_sum = 0;
    for(int i=0;i < N;i++){
        long long height;
        cin >> height;
        if(i==0){
            previous = height;
            continue;
        }
        if(height < previous){
            long long diff = previous - height;
            box_sum += diff;
            previous = height + diff;
        }else{
            previous = height;
        }
    }
    cout << box_sum << endl;
}

Measured memory_bytes: 3588
using System;

class Guki
{
    static void Main()
    {
        var input = Console.ReadLine();
        var nums = input.Split();

        Console.WriteLine(Solve(int.Parse(nums[0]), int.Parse(nums[1])));
    }

    static int Solve(int n, int m)
    {
        return Combination(n, 2) + Combination(m, 2);
    }

    static int Combination(int n, int m)
    {
        var si = 1;
        for (int i = 0; i < m; i++)
        {
            si *= (n - i);
        }

        var bo = 1;
        for (int i = 1; i <=m; i++)
        {
            bo *= i;
        }

        return si / bo;
    }
}

Measured memory_bytes: 11092
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] array = new int[n+1];
		int[] list = new int[n];
		for(int i = 0; i < n; i++){
		    int a = sc.nextInt();
		    list[i] = a;
		    array[a]++;
		}
		
		// 計算
		long result = 0;
		for(int i = 0; i < n+1; i++){
		    int a = array[i];
		    result += (long)a*(a-1)/2;
		}
		
		for(int i = 0; i < n; i++){
		    long t = array[list[i]];
		    System.out.println(result - (t-1));
		}
		
		// 出力
		//System.out.println(result);
		
	}
}


Measured memory_bytes: 102512
import itertools

N,M,R = map(int, input().split())
rlist = [int(r) for r in input().split()]
INF = 10**9
E = [[INF]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    E[a-1][b-1] = c
    E[b-1][a-1] = c
    
for k in range(N):
    for i in range(N):
        for j in range(N):
            E[i][j] = min(E[i][j], E[i][k]+E[k][j])
            
ans = 10**9

for i in range(R):
    rlist[i] -= 1
    
for p in itertools.permutations(rlist):
    d = 0
    for i in range(1, R):
        d += E[p[i-1]][p[i]]
    ans = min(ans, d)
    
print(ans)

Measured memory_bytes: 46808
#include <iostream>
using namespace std;
static const int MAX = 100;

int main(){
    int a[MAX], n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = n; i > 0; i--) {
        cout << a[i-1];
        if (i-1) cout << ' ';
        else cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3076
#include<cstdio>
#include<algorithm>
using namespace std;
#define INF ( 1 << 25 )
int N,mas[16][17],dp[1<<16];
int solve(){
  for(int i = 0 ; i < 1 << N ; i++ ) dp[i] = INF;
  dp[(1 << N) - 1] = 0;
  for(int bit = (1 << N) - 1 ; bit >= 0 ; bit-- ){
    for(int i = 0 ; i < N ; i++ ){
      if(!(bit & (1 << i))) continue;
      int min_cost = mas[i][0];
      for(int j = 0 ; j < N ; j++ ){
        if(!(bit & (1 << j))) min_cost = min( min_cost, mas[i][j+1]);
      }
      dp[bit&~(1<<i)] = min(dp[bit&~(1<<i)],min_cost + dp[bit]);
    }
  }
  return dp[0];
}
int main(){
  while(scanf("%d",&N), N ){
    for(int i = 0 ; i < N ; i++ ){
      for(int j = 0 ; j <= N ; j++ ){
        scanf("%d",&mas[i][j]);
      }
    }
    printf("%d\n",solve());
  }
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    int M;
    cin >> M;
    ll ans = 0, sum = 0;
    for (int i = 0; i < M; ++i) {
        int d;
        ll c;
        cin >> d >> c;
        sum += d * c;
        ans += c;
    }
    ans += (sum - 1) / 9;

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <numeric>
#include <fstream>
#include <queue>
#include <cstdio>
using namespace std;
#define fol(i,n) for (int i=0;i<n;i++)
#define db(a) cout << a<< endl;
typedef pair <int,int>P;
typedef long long ll;
using namespace std;

int main(){
    int a,b,c;
    cin >> a>>b>>c;
    cout << min({a+b,b+c,c+a})<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int h = scan.nextInt();
        
        System.out.println((a + b) * h / 2);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(x) (int)x.size()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
// You should only debug a pair of simple data types. For example,
// the debug won't work if one of pair's elements is collection type
// (std::vector, std::map, std::set...).
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


// bool check_prime(int n)  return whether a number is prime or not O(sqrt(N));
// int BE(int x,int n,int m)  return x^n%m; O(logN);
// void sieve()  from number 1-1000001 saare prime store kar lega  in bool is_prime[1000001] array
// vector<int> z_array(string s)  return vector which is Z-array of string s;
// vector<int> lps(string s)      return vector which is lps array of string s;
// int power(int x,int n) return x^n; O(logN);
// using_ordered_set (template for using ordered set , replace first 2 lines of this page with this code..);
const int gf = 1e6 + 9;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max({a * c, a * d, b * c, b * d}) << en;



	return 0;
}




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

int main() {
  int N;
  cin >> N;
  string S, T;
  cin >> S >> T;

  for (int i = 0; i < N; i++) {
    cout << S.at(i) << T.at(i);
  }
  cout << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cstdlib>
#include <stack>
#include <random>

using namespace std;

typedef long long ll;





int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k % 2)
        cout << b - a << "\n";
    else
        cout << a - b << "\n";
    return 0;
}








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

pair<vector<char>, vector<ll>> get_rle() {
	vector<char> c;
	vector<ll> l;
	char ch;
	while (cin >> ch, ch != '$') {
		int x;
		cin >> x;
		c.push_back(ch);
		l.push_back(x);
	}
	return make_pair(c, l);
}

pair<vector<char>, vector<ll>> compress_rle(const vector<char>& c, const vector<ll>& l) {
	int n = c.size();
	vector<char> rc(1, c[0]);
	vector<ll> rl(1, l[0]);
	for (int i = 1; i < n; i++) {
		if (c[i] == rc.back()) {
			rl.back() += l[i];
		}
		else if (l[i] > 0) {
			rc.push_back(c[i]);
			rl.push_back(l[i]);
		}
	}
	return make_pair(rc, rl);
}

void out_rle(const vector<char>& c, const vector<ll>& l) {
	int n = c.size();
	for (int i = 0; i < n; i++) {
		cout << c[i] << ' ' << l[i] << ' ';
	}
	cout << '$' << endl;
}

int main()
{
	vector<char> ac, bc, cc, rc;
	vector<ll> al, bl, cl, rl;
	tie(ac, al) = get_rle();
	tie(bc, bl) = get_rle();
	tie(cc, cl) = get_rle();
	int l1 = ac.size(), l2 = bc.size(), l3 = cc.size();
	bool end = false;
	for (int i = 0; i < l1; i++) {
		if (l2 == 1) {
			if (!end && ac[i] == bc[0] && al[i] >= bl[0]) {
				end = true;
				al[i] -= bl[0];
				for (int j = 0; j < l3; j++) {
					rc.push_back(cc[j]);
					rl.push_back(cl[j]);
				}
			}
			if (al[i]) {
				rc.push_back(ac[i]);
				rl.push_back(al[i]);
			}
		}
		else if (i + l2 <= l1 && ac[i] == bc[0] && al[i] >= bl[0]) {
			bool ng = false;
			for (int j = 1; j + 1 < l2; j++) {
				if (ac[i + j] != bc[j] || al[i + j] != bl[j]) {
					ng = true;
					break;
				}
			}
			if (ac[i + l2 - 1] != bc[l2 - 1] || al[i + l2 - 1] < bl[l2 - 1]) ng = true;
			if (end || ng) {
				rc.push_back(ac[i]);
				rl.push_back(al[i]);
				continue;
			}
			end = true;
			if (al[i] - bl[0] > 0) {
				rc.push_back(ac[i]);
				rl.push_back(al[i] - bl[0]);
			}
			for (int j = 0; j < l3; j++) {
				rc.push_back(cc[j]);
				rl.push_back(cl[j]);
			}
			al[i + l2 - 1] -= bl.back();
			i += l2 - 2;
		}
		else if (al[i] > 0) {
			rc.push_back(ac[i]);
			rl.push_back(al[i]);
		}
	}
	tie(rc, rl) = compress_rle(rc, rl);
	out_rle(rc, rl);
	return 0;
}



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

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long double A, B, H, M;
    cin >> A >> B >> H >> M;
    long double thetaA, thetaB;
    thetaB = M / 60.0 * 2.0 * 3.14159265358979323846; //長針
    thetaA = (H / 12.0 + M / 60.0 / 12.0) * 2.0 * 3.14159265358979323846;
    long double sqrt_C = 0;

    //cout << thetaB << " " << thetaA << " " << thetaB - thetaA << endl;

    if (thetaB > thetaA)
    {
        cout << fixed << setprecision(18) << sqrt(A * A + B * B - 2 * A * B * cos(thetaB - thetaA)) << endl;
    }
    else if (thetaA > thetaB)
    {
        cout << fixed << setprecision(18) << sqrt(A * A + B * B - 2 * A * B * cos(thetaA - thetaB)) << endl;
    }
    else
    {
        cout << abs(A - B) << endl;
    }

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for(int i = 0; i < N; i++) cin >> A[i] >> B[i];
  vector<int> ord(N);
  iota(ord.begin(), ord.end(), 0);
  sort(ord.begin(), ord.end(), [&](int x, int y) {
    return B[x] < B[y];
  });
  bool ans = true;
  int time = 0;
  for(int i : ord) {
    time += A[i];
    if(time > B[i]) {
      ans = false;
      break;
    }
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int x; cin >> x;
    if (30 <= x)print("Yes");
    else print("No");

    return 0;
}

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

int main(void) {
    int N, K;
    string S;

    cin >> N >> S >> K;
    for (int i = 0; i < S.length(); i++) {
        S[i] = S[i] != S[K - 1] ? '*' : S[i];
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
//金桥 傅思程
#include <bits/stdc++.h>
using namespace std;

int main()
{
	int a,ans=0;
	char c;
	cin>>a;
	for(int i=0;i<a;i++){
		cin>>c;
		if(c=='R')ans++;
		else ans--;
	}
	if(ans>0)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[][] a = new int[n][20];
    for(int i = 0; i < n; i++) {
      int aa = sc.nextInt();
      for(int j = 0; j < 20; j++) {
        if(aa % 2 == 1) a[i][j] = 1;
        aa /= 2;
      }
    }
    long ans = 0;
    int p = 0;
    int[] b = new int[20];
    for(int i = 0; i < n; i++) {
      ans += (p - i);
      for(int j = p; j < n; j++) {
        int t = 0;
        for(int k = 0; k < 20; k++) {
          b[k] += a[j][k];
          if(b[k] > 1) t++;
        }
        if(t == 0) {
          ans++;
          if(j == (n - 1)) {
            p = n;
            break;
          }
        } else {
          p = j;
          for(int k = 0; k < 20; k++) {
            b[k] -= (a[i][k] + a[j][k]);
          }
          break;
        }
      }
    }
    System.out.println(ans);
  }
}

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

const int maxn = 100100;
vector<int> g[maxn];
int w[maxn];
int cnt[maxn];

struct DSU {
  vector<int> col, rk;

  DSU(int n): col(n), rk(n) {
    iota(col.begin(), col.end(), 0);
  }

  int get(int u) {
    if (u == col[u]) {
      return u;
    }
    return col[u] = get(col[u]);
  }

  bool join(int u, int v) {
    u = get(u), v = get(v);
    if (u == v) {
      return false;
    }
    if (rk[u] > rk[v]) {
      swap(u, v);
    }
    if (rk[u] == rk[v]) {
      ++rk[v];
    }
    col[u] = v;
    return true;
  }
};

signed main() {
#ifdef LOCAL
  assert(freopen("d.in", "r", stdin));
#endif
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> w[i];
  }
  DSU dsu(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    dsu.join(u, v);
  }
  for (int i = 0; i < n; ++i) {
    ++cnt[dsu.get(i)];
  }
  vector<pair<pair<int, int>, int>> o;
  for (int i = 0; i < n; ++i) {
    int c = dsu.get(i);
    o.emplace_back(pair<int, int>{cnt[c], c}, -w[i]);
  }
  sort(o.begin(), o.end());
  reverse(o.begin(), o.end());
  multiset<int> ws;
  ll res = 0;
  for (int i = 0; i < n; ++i) {
    if (i > 0 && o[i].first.second != o[i - 1].first.second) {
      if (ws.empty()) {
        cout << "Impossible\n";
        return 0;
      }
      res += *ws.begin();
      ws.erase(ws.begin());
      res += -o[i].second;
    } else {
      ws.insert(-o[i].second);
    }
  }
  cout << res << '\n';
}


Measured memory_bytes: 9844
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0516

"""
import sys
from sys import stdin
from collections import deque
input = stdin.readline


def main(args):
    while True:
        n, k = map(int, input().split())
        if n == 0 and k == 0:
            break

        d = deque([int(input()) for _ in range(k)])
        sum_value = sum(d)
        maximum_sum = sum_value

        for _ in range(n-k):
            v = int(input())
            o = d.popleft()
            sum_value = sum_value - o + v
            if sum_value > maximum_sum:
                maximum_sum = sum_value
            d.append(v)

        print(maximum_sum)


if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 10276
# coding: utf-8
# Your code here!

sl = list(input())

dp = [[0 for i in range(13)] for i in range(len(sl)+1)]
dp[0][0] = 1
for idx, s in enumerate(sl):
    if s == "?":
        n = -1
    else:
        n = int(s)
    for j in range(13):
        for i in range(10):
            if n == -1 or n == i: 
                dp[idx+1][(10*j+i) % 13] += dp[idx][j]
                dp[idx+1][(10*j+i) % 13] %= 10**9 + 7

print(dp[-1][5] % (10**9 + 7))
            

Measured memory_bytes: 70152
#include <bits/stdc++.h>
using namespace std;
#define LONGLONGMAX 9223372036854775807
#define LONGLONGMIN -9223372036854775807
#define INTMAX 32767
#define INTMIN -32767
#define ROUNDUP(divisor,dividend) (divisor + (dividend - 1)) / dividend
 int a,b;
int main(){
  cin >> a >> b;
  cout << (a>b?a+(a-1): a!=b ? b+(b-1):a+b) << endl; 
}


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

int main()
{
    int N, A, B;
    cin >> N;
    
    if(N==1){
        cout << "Hello World" << endl;
    }
    if(N==2){
        cin >> A >> B;
        cout << A + B << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
#define INF 1 << 28
typedef pair<int,int> Pi;
#define F first
#define S second
#define pb push_back

inline void chmax(int &a, int b) { a = max(a,b); }
inline void chmin(int &a, int b) { a = min(a,b); }

int main()
{
  string s, t;
  while(cin >> s >> t) {
    vector<vector<int> > dp(2,vector<int>(4005,0));
    int ss = s.size(), ts = t.size();
    int maxv = 0;
    Rep(i,ts) {
      Rep(j,ss) {
	if(s[j] == t[i]) {
	  dp[1][j + 1] = dp[0][j] + 1;
	  chmax(maxv,dp[1][j + 1]);
	}else {
	  dp[1][j + 1] = 0;
	}
      }
      dp[0] = dp[1];
    }
    cout << maxv << endl;
  }
  return 0;
}

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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	ll A, B;
	
	cin >> A >> B;
	
	for(int i = 1; i <= 100000; i++){
		if(A * i % B == 0){
			cout << A * i << endl;
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int main(void) {

	// 1_8-A Toggling Cases
	
	char str[1200];
	int i=0;
	int n;
	gets(str);

	for(i=0; str[i]!='\0'; i++){
		if('A'<=str[i] && str[i]<='Z'){
			str[i] += ('a' - 'A');
		}else if('a'<=str[i] && str[i]<='z'){
			str[i] += ('A' - 'a');
		}
		putchar(str[i]);
	}
	putchar('\n');

        return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <utility>
#include <math.h>
#include <climits>
#include <string>
#include <iomanip>
#include <stack>
#include <queue>
#define f(i,n) for(int i=0;i<n;i++)
#define f1(i,a,b) for(int i=a;i<b;i++)
#define ld long double
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define mii map<int,int>
#define msi map<string,pair<int,int>>
#define pii pair<int,int>
#define F first
#define S second
#define PI 3.1415926535
typedef long long ll;
using namespace std;
ll dp[10000][10000];
ll solve(int i,int j,ll arr[])
{
    if(dp[i][j]!=-1)
    return dp[i][j];
    if(i==j)
    return arr[i];
    if(j==i+1)
    return max(arr[i],arr[j]);
    dp[i][j]=max((arr[i]+min(solve(i+2,j,arr),solve(i+1,j-1,arr))),(arr[j]+min(solve(i,j-2,arr),solve(i+1,j-1,arr))));
    return dp[i][j];
}
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    f(i,10000)
    {
        f(j,10000)
        dp[i][j]=-1;
    }
    ll n;
    cin>>n;
    ll arr[n];
    ll sum=0;
    f(i,n)
    {
        cin>>arr[i];
        sum+=arr[i];
    }
    ll r=solve(0,n-1,arr);
    ll a=sum-r;
    ll b=r-a;
    cout<<b<<endl;
}


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

int main()
{
	string W, L, T;
	int n = 0;
	unsigned long j = 0;

	cin >> W;

	for (unsigned int i = 0; i < W.size(); i++) {
		if (W[i] >= 'A' && W[i] <= 'Z')
			W[i] = tolower(W[i]);
	}		

	getline(cin, L);

	while (L != "END_OF_TEXT") {
		for (unsigned int i = 0; i < L.size(); i++) {
			if (L[i] >= 'A' && L[i] <= 'Z')
				L[i] = tolower(L[i]);
		}

		T += L + " ";

		getline(cin, L);
	}

	j = T.find(W);

	while (j < T.size()) {
		if ((j == 1) | (T[j - 1] == ' ')) {
			if ((j == T.size() - W.size()) | (T[j + W.size()] == ' '))
				n++;
		}

		j = T.find(W, j + 1);
	}

	cout << n << endl;

    return 0;
}

Measured memory_bytes: 3176
#include <stdio.h>
int main(void){
  int N;
  int H[21];
  int i;
  int max=0;
  int s=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&H[i]);
    if(max<H[i]){
      max=H[i];
      s=s+1;
    }
    else if(max==H[i]){
      s=s+1;
    }
  }
  printf("%d\n",s);
  return 0;
}

Measured memory_bytes: 1728
import java.util.*;

public class Main
{

    static int sieve[] = new int[1000001];

    public static void main(String args[])
    {
        Scanner kb = new Scanner(System.in);
        int n = kb.nextInt();
        makeSieve();
        int res = 0;
        for(int i = 1 ; i < n ; i++)
        {
            HashMap<Integer,Integer> map = new HashMap<>();
            int t = i;
            while(t > 1)
            {
                map.put(sieve[t],map.getOrDefault(sieve[t],0)+1);
                //System.out.println(t + " " + sieve[t]);
                t = t/sieve[t];
            }
            int tot = 1;
            for(int k : map.keySet())
                t = t * (map.get(k) + 1);
            res += t;
        }

        System.out.println(res);

    }
    public static void makeSieve()
    {
        for(int p = 2 ; p*p <= 1000000 ; p++)
        {
            if(sieve[p] == 0)
            {
                sieve[p] = p;
                for(int i = p*p ; i <= 1000000 ; i += p)
                    sieve[i] = p;
            }
        }

        for(int i = 2 ; i <= 1000000 ; i++)
        {
            if(sieve[i] == 0)
                sieve[i] = i;
        }
    }
}

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

int main() {
  string T; cin >> T;
  int N = T.size();
  for(int i=0; i<N; i++) {
    if(T.at(i)=='?') T.at(i)='D';
    cout << T.at(i);
  }
  return 0;
}

Measured memory_bytes: 3764
#include <stdio.h>
int main()
{
  int x,a,b,c,d;
scanf("%d%d%d",&x,&a,&b);
c=x-a;
d=x-b;
if(c<0) c=-c;
if(d<0) d=-d;
if (c>d)  printf("B\n");
else printf("A\n");
return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main(){
    int A,B;
    char op;
    scanf("%d %c %d",&A,&op,&B);
    if(op == '+'){
        printf("%d",A + B);
    }
    else{
        printf("%d",A - B);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 128