akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <functional>
#include <stack>
#include <map>
#include <utility>
#define REP(i,n) for(int i=0;i<n;++i)
using namespace std;

int main() {
  int n, d, dd, c = 0, f = 0;
  cin >> n;
  REP(i, n){
    cin >> d >> dd;
    if (d == dd) {
      ++c;
    } else {
      c = 0;
    }
    if (c == 3) {
      cout << "Yes" << endl;
      f = 1;
      break;
    }
  }
  if (f == 0) {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#define mop 1000000007
using namespace std;


int main() {
    

    int n;
    cin >> n;
    vector <int> a;
    long long sum = 0;
    for (int i=0;i<n;i++){
        int p;
        cin >> p;
        sum += p;
        a.push_back(p);
    }
    long double ave = static_cast<long double>(sum) / n;
    long double minv = 101;
    int num;
    for (int i=0;i<n;i++){
        if (minv > abs(a[i] - ave)){
            num = i;
            minv = abs(a[i] - ave);
        }
    }
    cout << num << endl;

}

Measured memory_bytes: 256
k,n = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
ans = 0
max = 0
n.times do |i|
 if i == n-1
    buf = (k - a[i]) + (a[0] - 0)
 else
    buf = a[i+1]  - a[i] 
 end
  ans += buf 
  max = buf if max < buf
end
puts ans - max

Measured memory_bytes: 16644
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#include<string>
#include<cassert>
using namespace std;

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

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

//#define NO_DEBUG

int N;
string S;
ll R_dp[4001];
ll B_dp[4001];
ll G_dp[4001];
ll ans_count = 0;


void checkingB(bool can_check,int check_k){	
	if(can_check){
		if(S[check_k] == 'B'){
			ans_count -= 1;
		}
	}
}
void checkingG(bool can_check,int check_k){	
	if(can_check){
		if(S[check_k] == 'G'){
			ans_count -= 1;
		}
	}
}
void checkingR(bool can_check,int check_k){	
	if(can_check){
		if(S[check_k] == 'R'){
			ans_count -= 1;
		}
	}
}


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

	R_dp[0] = 0;
	G_dp[0] = 0;
	B_dp[0] = 0;

	for(int i = 1; i <= N; i++){
		if(S[i-1] == 'R'){
			R_dp[i] = R_dp[i-1] + 1;
			G_dp[i] = G_dp[i-1];
			B_dp[i] = B_dp[i-1];
		}
		else if(S[i-1] == 'G'){
			G_dp[i] = G_dp[i-1] + 1;
			R_dp[i] = R_dp[i-1];
			B_dp[i] = B_dp[i-1];
		}
		else{
			B_dp[i] = B_dp[i-1] + 1;
			G_dp[i] = G_dp[i-1];
			R_dp[i] = R_dp[i-1];
		}
	}

	for ( int i = N-1; i >= 2; i-- ){
		for ( int j = i - 1;  j >= 1; j-- ){

			int diff = i - j;
			int check_k = j - diff;
			bool can_check = check_k >= 0;
			assert(i - j > 0);

			if(S[i] == 'R'){
				if(S[j] == 'G'){
					ans_count += B_dp[j];
					checkingB(can_check,check_k);
				}
				if(S[j] =='B'){
					ans_count += G_dp[j];
					checkingG(can_check,check_k);
				}
			}else if (S[i] == 'G'){
				if(S[j] == 'R'){
					ans_count += B_dp[j];
					checkingB(can_check,check_k);
				}
				if(S[j] =='B'){
					ans_count += R_dp[j];
					checkingR(can_check,check_k);
				}
			}else{
				if(S[j] == 'R'){
					ans_count += G_dp[j];
					checkingG(can_check,check_k);
				}
				if(S[j] =='G'){
					ans_count += R_dp[j];
					checkingR(can_check,check_k);
				}
			}
		}
	}
	/*
	 * i,j,k
	 * 素朴ならi,j,kを動かしながら全探索していけばよい
	 * 
	 * あるindex移行のR,G,Bの数を数える
	 * 2箇所決めれば残りは数えた数でできる
	 * ２か所決めれば、距離が一緒になるindexは最大でひとつ
	 * これだけはぶけば良い
	 * n^2ならorder敵にいける
	 */
	cout<<ans_count<<endl;
	return 0;
}



Measured memory_bytes: 3676
import java.io.*;
  
class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
int count=1;
while(!(line=br.readLine()).equals("0")){
int weight=0;
int W=Integer.parseInt(line);
int n=Integer.parseInt(br.readLine());
int[] v=new int[n];
int[] w=new int[n];
for(int i=0;i<n;i++){
String[] str=br.readLine().split(",");
v[i]=Integer.parseInt(str[0]);
w[i]=Integer.parseInt(str[1]);
}
solve(W,n,v,w,count);
count++;
}
}
private static void solve(final int W,final int n,final int[] v,final int[] w,int count){
int[][] dp=new int[n+1][W+1];
int maxValue=0;
int minWeight=0;
for(int i=0;i<=W;i++){
dp[n][i]=0;
}
for(int i=n-1;i>=0;i--){
for(int j=0;j<=W;j++){
if(j<w[i]){
dp[i][j]=dp[i+1][j];
}
else{
dp[i][j]=Math.max(dp[i+1][j],dp[i+1][j-w[i]]+v[i]);
}
}
}
for(int i=W;i>0;i--){
if(maxValue<=dp[0][i]){
maxValue=dp[0][i];
minWeight=i;
}
}
System.out.println("Case "+count+":");
System.out.println(maxValue);
System.out.println(minWeight);
}
}

Measured memory_bytes: 28420
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        int mod = 10007;
        int n = sc.nextInt();
        String str = sc.next();
        int[] tanto = new int[n];
        for(int i=0; i<n; i++){
            if(str.charAt(i)=='J') tanto[i] = 0;
            else if(str.charAt(i)=='O') tanto[i] = 1;
            else tanto[i] = 2;
        }

        int[][] dp = new int[2][1<<3];
        int idx = 1;
        dp[0][0] = 1;
        for(int i=0; i<n; i++){
            for(int bit=0; bit<(1<<3); bit++){
                if((bit&(1<<tanto[i]))==0) continue;
                for(int bit2=0; bit2<(1<<3); bit2++){
                    if(i==0 && ((bit&1)!=1)) continue;
                    if(i!=0 && (bit&bit2)==0) continue;
                    dp[idx][bit] += dp[1-idx][bit2];
                    dp[idx][bit] %= mod;
                }
            }
            //System.out.println(Arrays.toString(dp[idx]));
            idx = 1-idx;
            Arrays.fill(dp[idx], 0);
        }

        idx = 1-idx;
        int sum = 0;
        for(int i=0; i<(1<<3); i++) sum = (sum + dp[idx][i]) % mod;
        System.out.println(sum);
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 18024
// BEGINNING WITH THE NAME OF ALMIGHTY GOD ALLAH
// AUTHOR:: MOHAMMAD FAISAL
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.flush();
	string s;
    cin >> s;
    int mind = 0;
    for(int i=0;s[i];i++)
    {
      if(s[i]=='-')
        --mind;
      else
        ++mind;
    }
  	cout<<mind;

	return 0;
	// BYE BYE 
}


Measured memory_bytes: 256
diff = []
for h in range(3):
    c1,c2,c3 = [int(x) for x in input().split()]
    diff.append([c1-c2, c2-c3])

judge = True
for h in range(2):
    judge &= (diff[h][0] == diff[h+1][0] and diff[h][1] == diff[h+1][1])
print("Yes" if judge else "No")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define T top()
#define E end()
#define PS push
#define Q queue
#define PP pop()
#define L0 (LL)0
#define V vector
#define ST stack
#define FI first
#define MAX 4e18
#define MIN -MAX
#define DQ deque
#define RE rend()
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define SE second
#define DL double
#define G getline
#define IN insert
#define endl "\n"
#define EM empty()
#define EE emplace
#define RB rbegin()
#define MD 1000000007
#define PSB push_back
#define PI acos(-1.00)
#define PPB pop_back()
#define PSF push_front
#define ub upper_bound
#define lb lower_bound
#define PPF pop_front()
#define EB emplace_back
#define LL long long int
#define PQ priority_queue
#define N cout<<"NO"<<endl
#define Y cout<<"YES"<<endl
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define UOSMOY v.C;w.C;ww.C;uu.C;uo.C;vo.C;vu.C;ab.C;bc.C;cc.C;uuu.C;a.C;b.C;c.C;u.C
V<LL>v;
V<LL>w,ab,bc;
set<LL>uo;
map<LL,LL>ww,cc,u;
V<pair<LL,LL> >uu;
map<LL,V<LL> >uuu;
map<pair<LL,LL>,LL> vo;
map<pair<LL,LL>,LL> vu;
LL ar[100];
LL dxx[]= {-1,0,1,0};
LL dyy[]= {0,1,0,-1};
LL dx[]= {2,1,-1,-2,-2,-1,1,2};
LL dy[]= {1,2,2,1,-1,-2,-2,-1};
int main()
{
//  BRR;
//  file;
    FAST;
    char ch;
    string a,b,c;
    DL x,y,d,e,f,g,h;
    LL n,m,i,j,k,p,q,o,l,s,tt=1,t,z,aa,r=0;
//    cin>>tt;
    while(tt--)
    {
        UOSMOY;
       cin>>n;
       for(i=0;i<n;i++)
       {
           cin>>o;
           v.PSB(o);
       }
       k=0;
       for(i=0;i<n-2;i++)
       {
           for(j=i+1;j<n-1;j++)
           {
               for(l=j+1;l<n;l++)
               {
                   if(v[i]+v[j]>v[l] && v[i]+v[l]>v[j] && v[l]+v[j]>v[i] && v[i]!=v[l] && v[i]!=v[j] && v[j]!=v[l])
                   {
                       k++;
                   }
               }
           }
       }
       cout<<k<<endl;
    }
    return 0;
    //IN
    //AL
}


Measured memory_bytes: 3656
#include <stdio.h>

int main() {
	int input;
	for(int i=1; i<=10000; i++){
		scanf("%d", &input);
		if (input == 0) {
			break;
		}
		else {
			printf("Case %d: %d\n", i, input);
		}

	}
	return 0;
}

Measured memory_bytes: 1820
#include <stdio.h>
#include <stdlib.h>
int main(){
    int a[4];
    for (int i = 0; i < 4; ++i) {
         scanf("%d", &a[i]);
    }
  if(abs(a[0]-a[2])<=a[3]) printf("Yes");
  else if(abs(a[0]-a[1])<=a[3] && abs(a[1]-a[2])<=a[3]) printf("Yes");
  else printf("No");
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <list>
 
using namespace std; 
 
int main() {
    map<char, vector<int>> AA;
    string s, t;
 
    cin >> s >> t;
 
    int tmps_prev = 0;
    for(int i = 0; i < s.size(); i++){
        char s_c = s[i];
        AA[s_c].push_back(i);        
    }
    for(int i = 0; i < s.size(); i++){
        char s_c = s[i];
        AA[s_c].push_back(s.size() + i);        
    }    
        
    long long NOM = 0;
	long long f2 = 0;
    for(const auto & t_c : t){
        
        if(AA[t_c].size()==0) {
            cout << -1 << endl;
            return 0;
        }
        
         f2 = *lower_bound(AA[t_c].begin(), AA[t_c].end(), f2) + 1;
        
        if(f2 >= s.size()){
            f2 = f2 - s.size();
			NOM += s.size();
        }
    
 
                
    }
	
	NOM += f2;
    

    
    cout << NOM << endl;
    
    
    
    
    return 0;
}

Measured memory_bytes: 1724
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N,K;cin>>N>>K;
  vector<long>H(N);for(int i=0;i<N;i++)cin>>H[i];
  sort(H.begin(),H.end());
  long m=LONG_MAX;
  for(int s=0;s+K-1<N;s++)m=min(m,H[s+K-1]-H[s]);
  cout<<m;
}



Measured memory_bytes: 1024
import heapq
t = 1
def max(a,b):
	if a > b:
		return a
	return b
def min(a,b):
	if a < b:
		return a
	return b

while t > 0:
	t -= 1
	a,b = map(int,input().split())
	i = 1
	c = a
	if b == 1:
		print(0)
		exit(0)
	while a < b:
		if(i == 0):
			a = a+(c)
		else:
			a = a+(c-1)
		i += 1
	print(i)


Measured memory_bytes: 62136
while(True):
    n, m = map(int, input().split())
    st = []
    sh = []
    if(n==0):
        break

    for i in range(n):
        st.append(int(input()))

    for i in range(m):
        sh.append(int(input()))

    # st.sort()
    # sh.sort()

    ans = [100000, 100000]

    if (sum(st)-sum(sh))%2 == 1:
        print(-1)
        continue

    diff = (sum(st)-sum(sh))//2
    for i in range(len(st)):
        for j in range(len(sh)):
            if st[i]-sh[j] == diff and st[i]+sh[j] < sum(ans):
                ans = [st[i], sh[j]]

    if(ans == [100000, 100000]):
        print(-1)
    else:
        print(str(ans[0])+" "+str(ans[1]))



Measured memory_bytes: 5608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int t[] = new int[N+1];
		int x[] = new int[N+1];
		int y[] = new int[N+1];
		for (int i = 1; i <= N; i++) {
			t[i] = scanner.nextInt();
			x[i] = scanner.nextInt();
			y[i] = scanner.nextInt();
		}
		scanner.close();
		
		for (int i = 1; i <= N; i++) {
			if (Math.abs(x[i] - x[i-1]) + Math.abs(y[i] - y[i-1]) > t[i] - t[i-1]) {
				System.out.println("No");
				return;
			} else if (Math.abs(Math.abs(x[i] - x[i-1]) + Math.abs(y[i] - y[i-1]) - t[i] + t[i-1]) % 2 != 0) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}

}

Measured memory_bytes: 90968
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    int ans = 0;

    for(int i=1;i<N-2;++i){
        map<char,int> mp;
        int tmpans = 0;
        rep(j,i) mp[S[j]] = 1;
        for(int j=i;j<N;++j) if(mp[S[j]] == 1) mp[S[j]] = 2;
        for(auto e:mp) if(e.second == 2) ++tmpans; 
        ans = max(ans,tmpans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
const int maxn = 200005;

int main()
{
	ll n;
	cin>>n;
	ll ans=n*(n+1)*(n+2)/6;
	for(int i=0,u,v;i<n-1;i++){
		cin>>u>>v;
		if(u>v)swap(u,v);
		ans-=(ll)u*(n-v+1);
	}
	cout<<ans<<endl;
	return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  string s;
  cin >> s;

  ll ans;
  REP(i, 26){
    string t = s;
    ll k = s.size();
    while(k>0){
      bool all = true;
      bool next = true;

      REP(j, k){
        if(t[j]-'a'==i)
          continue;
        else if(t[j+1]-'a'==i){
          t[j] = t[j+1];
          all = false;
        }
        else
          all = next = false;
      }

      if(all)
        break;
      k--;
      if(next)
        break;
    }


    ans = min(ll(s.size())-k, ans);
  }

  cout << ans << endl;
}


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

int main(){
  int n; cin >> n;
  int m = 1001001001, M = 0;
  for(int i = 0; i < n; i++){
    int a; cin >> a;
    m = min(a, m);
    M = max(a, M);
  }
  cout << M - m << endl;
}
    

Measured memory_bytes: 256
n=int(input())
s=input()

l=0
r=s[1:].count("E")
ans=r
MIN=r

for i in range(1,n):
    if s[i-1]=="W":
        ans+=1
    if s[i]=="E":
        ans-=1
    MIN=min(ans,MIN)
print(MIN)


Measured memory_bytes: 3700
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy

def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    n, m, x, y = intin()
    xlist = intina()
    ylist = intina()

    for z in range(x, y):
        z = z + 1

        peace = True

        for x in xlist:
            if x >= z:
                peace = False

        for y in ylist:
            if y < z:
                peace = False

        if peace:
            print('No War')
            return

    print('War')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3540
#include <algorithm>
#include <iostream>
#include <vector>
using ll = long long;
#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using namespace std;

int main() {
    int n;
    cin >> n;
    int ans = n % 10;
    if (ans == 2 | ans == 4 | ans == 5 | ans == 7 | ans == 9) {
        cout << "hon" << endl;
    } else if (ans == 0 | ans == 1 | ans == 6 | ans == 8) {
        cout << "pon" << endl;
    } else if (ans == 3) {
        cout << "bon" << endl;
    }
    // cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

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

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

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

    ll l = lcm(N,M);
    ll k = gcd(N,M);

    while(l <= N*M){
        bool flag = true;
        for (size_t i = 0; i < min(N,M); i++)
        {
            if(i*(N/k) >= N || i*(M/k) >= M) break;
            if(S[i*(N/k)] != T[i*(M/k)]) {
                flag = false;
                break;
            }
        }

        if(flag){
            pr(l);
            return 0;
        }
        l += lcm(N,M);
    }

    pr(-1);
}

Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string s;
  cin >> s;
  ll ans = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == 'R') {
      ans = 1;
      while (i + 1 < 3 && s[i + 1] == 'R') {
        ans++;
        i++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#pragma GCC optimize(3)
#include <bits/stdc++.h>

using namespace std;

long long a, b;

long long igcd(long long a, long long b)
{
	if(a < b)
	{
		long long t;
		t = a;
		a = b;
		b = t;
	}
	if(a % b == 0) return b;
	return igcd(b, a % b);
}

int main()
{
	cin>>a>>b;
	cout<<a * b / igcd(a, b);
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{
    public static void sort(int[] A) {
        int i, j, tmp;
        for (i = 1; i < A.length; i++) {
            tmp = A[i];
            j = i - 1;
            while (j >= 0 && A[j] > tmp) {
                A[j + 1] = A[j];
                j--;
            }
        A[j + 1] = tmp;
        printArray(A);
        }
    }
    
    public static void printArray(int[] A) {
        int i = 0;
        for (int value : A) {
            System.out.print(value);
            if (i != A.length - 1) {
                System.out.print(" ");
            } else {
                System.out.println();
            }
            i++;
        }
    }
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        String str = br.readLine();
        String[] s = str.split(" ");
        int[] array = new int[N];
        for (int i = 0; i < N; i++) {
            array[i] = Integer.parseInt(s[i]);
        }
        
        printArray(array);
        sort(array);
        
    }
}


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

class Dice{
public:
    int f[6];
    Dice(){}
    void roll_x(){ roll(1, 2, 4, 3);}
    void roll_y(){ roll(0, 2, 5, 3);}
    void roll_z(){ roll(0, 1, 5, 4);}
    void roll(int i, int j, int k, int l){
        int t= f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
    }
    
};
    
int right( Dice d1, int f1, int f2 ){
    for(int i=0; i<6; i++){
        for(int j=0; j<4; j++){
            
            if(d1.f[0] == f1 && d1.f[1] == f2) return d1.f[2];
            
            d1.roll_x();
        }
        
        if(i % 2 == 0) d1.roll_y();
        else d1.roll_z();
    }
    
    return -1;
}




int main(){
    Dice d;
    int f1, f2;
    
    for(int i=0; i<6; i++) cin >> d.f[i];
    int q;
    cin >> q;
    
    for(int j=0; j<q; j++){
        cin >> f1 >> f2;
        cout << right(d, f1, f2) << endl;
    }
    
    return 0;
}
    


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

int main() {
  int s;
  cin >> s;
  if(1<=s/100 && s/100<=12 && 1<=s%100 && s%100<=12) puts("AMBIGUOUS");
  else if(1<=s/100 && s/100<=12) puts("MMYY");
  else if(1<=s%100 && s%100<=12) puts("YYMM");
  else puts("NA");
  return 0;
}

Measured memory_bytes: 256
import sys
fin = sys.stdin.readline

def range_sum(cuml_list, l, r):
    if l == 0:
        return cuml_list[r]
    else:
        return cuml_list[r] - cuml_list[l - 1]


N, K = [int(elem) for elem in fin().split()]
a_list = [int(elem) for elem in fin().split()]
cuml_list = []
current_sum = 0
for a in a_list:
    current_sum += a
    cuml_list.append(current_sum)

all_beautifulness = []
for l in range(N):
    for r in range(l, N):
        cuml_sum = range_sum(cuml_list, l, r)
        all_beautifulness.append(cuml_sum)

assert len(all_beautifulness) == N*(N+1) // 2

current_num = 0
for t in range(40, 0, -1):
    count = 0
    comp = current_num + 2**(t - 1)
    for b in all_beautifulness:
        if comp & b == comp:
            count += 1
    if count >= K:
        current_num += 2**(t - 1)
print(current_num)

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

int main(){
    int n;
    cin >> n;
    int sum = 0;
    int high = 0;
    int p;
    for (int i = 0; i < n; i++){
        cin >> p;
        sum += p;
        high = max(high,p);
    }
    cout << sum - high/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=2e5;
int N;
typedef pair<ll,ll> P;
P bal[MAX_N*2];
int main(){
	cin>>N;
	ll ans=1e18;
	ll ma,mi;
	{
		set<ll> sr,sb;
		REP(i,N){
			ll x,y;
			cin>>x>>y;
			if (x>y){
				swap(x,y);
			}
			sr.insert(x);
			sb.insert(y);
			bal[i*2]=P(x,y);
			bal[i*2+1]=P(y,0);
		}
		ll rmi,rma,bmi,bma;
		auto ite=sr.begin();
		rmi=*ite;
		ite=sr.end();
		ite--;
		rma=*ite;
		ite=sb.begin();
		bmi=*ite;
		ite=sb.end();
		ite--;
		bma=*ite;
		ans=min(ans,(rma-rmi)*(bma-bmi));
		mi=rmi;
		ma=bma;
	}
	sort(bal,bal+N*2);
	{
		priority_queue<ll> pque;
		REP(i,N*2){
			if (bal[i].second!=0){
				pque.push(bal[i].first);
			}
		}
		REP(i,N*2){
			ans=min(ans,(ma-mi)*(pque.top()-bal[i].first));
			if (bal[i].second!=0){
				pque.push(bal[i].second);
			}else{
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 25216
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#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 SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

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

    ll a, b;
    cin >> a >> b;
    if (a < b)swap(a, b);
    if ((a + b) % 2)cout << "IMPOSSIBLE\n";
    else cout << (a + b) / 2 << "\n";
}

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  set<int> S;
  S.insert(a);
  if ((S.find(b) != S.end()) ^ (S.find(c) != S.end())){
    cout << "Yes" << endl;
  }
  else if ((S.find(b) != S.end()) && S.find(c) != S.end()){
    cout << "No" << endl;
  }
  else{
    cout << (b == c ? "Yes" : "No") << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 2e5+5;
int main() {
	ll a,b;
	cin>>a>>b;
	if(b==1||a==1) cout<<1<<endl;
	else if(a%2==0){
		cout<<a*b/2<<endl;
	}
	else {
		cout<<(a/2)*b+(b+1)/2<<endl;
	}
    return 0;
}



Measured memory_bytes: 256
Sx, Sy, Tx, Ty = map(int,input().split())

X = int(Tx - Sx)
Y = int(Ty - Sy)
#S-T-S-T-Sy

z = 'R'*X+'U'*Y+'L'*X+'D'*Y+'D'+'R'*(X+1)+'U'*(Y+1)+'L'+'U'+'L'*(X+1)+'D'*(Y+1)+'R'


print(z)

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

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(ll it=0;it<n;it++) cout<<a[it]<<" ";cout<<endl;
#define pcont(a)                     for(auto it:a) cout<<it<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'

/*constants*/
#define MAXN                         100005
#define PI                           3.14159265358979323846

/*debug*/
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>void __f(const char* name, Arg1&& arg1){ std::cout << name << " : " << arg1 << '\n';}
    template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ','); std::cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define trace(...)
#endif

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    ll i,j,n,m,k,cnt=0,ans=0,t=1;
    cin>>n>>m;
    priority_queue<ll> pq;
    rep(i,0,n){
        cin>>j;
        pq.push(j);
    }    
    while(!pq.empty() && m>0){
        auto u=pq.top();
        pq.pop();
        u/=2;
        if(u>0) pq.push(u);
        m--;
    }
    while(!pq.empty()){
        ans+=pq.top();
        pq.pop();
    }
    ret(ans)
    return 0;
}

Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {
    public static double[][] probs;

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        probs = new double[n+1][n+1];
        for(int i = 0; i <= n; i++){
            for(int j = 0; j <= n; j++){
                probs[i][j] = 0;
            }
        }
        probs[0][0] = 1;
        double[] coins = new double[n+1];
        for(int i = 1; i <= n; i++){
            coins[i] = scanner.nextDouble();
        }
        coins(coins, n);
        double res = 0;
        for(int i = n/2 +1; i <= n; i++){
            res += probs[i][n];
        }
        System.out.println(res);
    }

    public static void coins(double[] coins, int n){
        for(int c = 1; c <= n; c++){
            for(int h = 0; h <= c; h++){
                if(h==c){
                    probs[h][c] = probs[h-1][c-1] * coins[c];
                }else if(h==0){
                    probs[h][c] = probs[h][c-1] * (1-coins[c]);
                }else{
                    probs[h][c] = probs[h][c-1] * (1-coins[c]) + probs[h-1][c-1] * coins[c];
                }
            }
        }
    }
}


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

ll solve() {
    string S;
    cin >> S;
    if ( S.back() == 's' ) {
        S.append("es");
    } else {
        S.append("s");
    }
    cout << S << "\n";
    return 0;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3592
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    	int num = sc.nextInt();
    	int score = sc.nextInt();
    	if(num < 10) {
          System.out.println(score + 100 * ( 10 - num));
        } else {
          System.out.println(score);
        }
  }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
using ll = int64_t;
template<typename T>
using vec = vector<T>;
using P = pair<ll, ll>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//ll pas[51][52];

struct edge{
    int64_t to, cap, rev;
};

class Flow{
    int64_t size_;
    vector<vector<edge>> G;
    vector<bool> used;
	public:
    Flow(int64_t size){
        size_ = size;
        G.resize(size);
        used.resize(size,false);
    }
    void add_edge(int64_t from, int64_t to, int64_t cap){
        G[from].push_back((edge) {to, cap, G[to].size()});
        G[to].push_back((edge) {from, 0ll, G[from].size() - 1});
    }
    int64_t dfs(int64_t v, int64_t t, int64_t f){
        if(v == t) return f;
        used[v] = true;
        for(int i = 0;i < G[v].size();i++){
            edge &e = G[v][i];
            if(!used[e.to] && e.cap > 0){
                int64_t d = dfs(e.to, t, min(f, e.cap));
                if(d > 0ll){
                    e.cap -=d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    int64_t max_flow(int64_t s, int64_t t){
        int64_t flow = 0;
        while(1){
            for(int i = 0;i < size_;i++)used[i] = false;
            int64_t f = dfs(s, t, 1e16);
            if(f == 0)return flow;
            flow += f;
        }
    }
};

signed main(){
	IOS;
	ll n;
	cin >> n;
	vec<P> a(n), b(n);
	REP(i,n){
		ll x, y;
		cin >> x >> y;
		a[i] = P(x, y);
	}
	REP(i,n){
		ll x, y;
		cin >> x >> y;
		b[i] = P(x, y);
	}
	Flow fl(2 * n + 2);
	REP(i, n)fl.add_edge(2 * n,i,1);
	REP(i, n)fl.add_edge(n + i,2 * n + 1,1);
	REP(i, n){
		REP(j, n){
			ll x1 = a[i].first, y1 = a[i].second;
			ll x2 = b[j].first, y2 = b[j].second;
			if(x1 < x2 && y1 < y2)fl.add_edge(i,j + n,1);
		}
	}
	ll ans = fl.max_flow(2 * n, 2 * n + 1);
	dump(ans);
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>  // sort, 二分探索, etc
#include <iomanip>  // setprecision (浮動小数点の出力の誤差)
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cmath>
#include <list>

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=a,i##_len=(b);i<i##_len;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define cauto const auto&
#define UNIQUE(v) (v).erase( unique(all(v), (v).end() );
#define SZ(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define INF 1000000000000
#define MOD 1000000007
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

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

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

const char newl = '\n';

ll qp(ll a,ull b){ll ans=1;do{if(b&1u)ans*=a;a*=a;}while(b>>=1u);return ans;}
ll qp(ll a,ull b,ll mod){ll ans=1;do{if(b&1u)ans=ans*a%mod;a=a*a%mod;}while(b>>=1u);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll comb(int n, int r) {
    vector<vector<ll> > v(n+1, vector<ll>(r+1, 0));
    for(int i=0;i<n+1;i++) {v[i][0]=1; if(i < r+1)v[i][i]=1; }
    for(int i=1;i<n+1;i++) {for(int j=1;j<min(i,r+1);j++) {v[i][j]=v[i-1][j-1]+v[i-1][j];}}
    return v[n][r];
}

// INT_MAX   = 2.1e+09 (2147483647)
// LONG_MAX  = 9.2e+18 (9223372036854775807)
// LLONG_MAX = 9.2e+18 (9223372036854775807)


int main() {
    ll n; cin >> n;
    vector<ll> vec;
    rep(i, n) {
        ll x; cin >> x;
        vec.push_back(x);
    }

    ll cnt = 0;
    rep(i, n) {
        rep(j, i+1, n) {
            rep(k, j+1, n) {
                if (vec[i] == vec[j] || vec[j] == vec[k] || vec[k] == vec[i]) {
                    continue;
                }
                if (abs(vec[i] - vec[j]) < vec[k] && vec[k] < vec[i] + vec[j]) {
                    cnt += 1;
                }
            }
        }
    }

    cout << cnt << newl;


    return 0;
}


Measured memory_bytes: 3196
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] tmp = sc.nextLine().split(" ");
		int k = Integer.parseInt(tmp[1]);
		char[] s = sc.nextLine().toCharArray();
		sc.close();

		s[k-1] = (char)(s[k-1] - 'A' + 'a');
		for(char c: s) {
			System.out.print(c);
		}
		System.out.println();
	}
}


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

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

int main() {
	ios::sync_with_stdio(false);
	
	int c[6] = {500, 100, 50, 10, 5, 1};
	while(1) {
		int a;
		cin >> a;
		if(!a)break;
		a = 1000-a;
		int s = 0;
		rep(i, 6) {
			int t = a/c[i];
			a -= t*c[i];
			s += t;
		}
		cout << s << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1192
#include <iostream>

using namespace std;

const int INFTY = 1 << 14;
const int MAX = 50001;
const int M = 21;

int T[M][MAX];
int C[M];

int main() {
	int n,m;
	cin >> n >> m;
	for (int i=1; i<=m; i++) {
		cin >> C[i];
	}

	//初始化
	for (int i=0; i<=m; i++) {
		for (int j=0; j<=n; j++) {
			if (j == 0) {
				T[i][j] = 0;
			} else {
				T[i][j] = INFTY;
			}
		}
	}

	for (int i=1; i<=m; i++) {
		for (int j=1; j <= n; j++) {
			if (j-C[i] < 0) {
				T[i][j] = T[i-1][j];
			} else {
				T[i][j] = min(T[i-1][j],T[i][j-C[i]] + 1);
			}
		}
	}
	/*for (int i=1; i<=m; i++) {
		for (int j=1; j <= n; j++) {
			cout << T[i][j] << " ";
		}
		cout << endl;
	}*/

	cout << T[m][n] << endl;
	return 0;
}


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int n;
    string s;
    cin>> n>> s;

    for( int i=0; i<s.size(); i++)
    {
        s[i]=( s[i] + n <= 'Z' ? s[i]+ n : s[i]+ n-26);
    }

    cout << s << '\n';

    return 0;
}




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

int partition(int* array, int p, int r)
{
    int i = p, v = array[r-1];
    for(int j=p;j<r-1;++j)
    {
        if(array[j] <= v)
        {
            swap(array[i++], array[j]);
        }
    }
    swap(array[i], array[r-1]);
    return i;
}

int main()
{
    int array[100000];
    int n, ans;
    cin >> n;
    for(int i=0;i<n;++i) cin >> array[i];
    ans = partition(array, 0, n);
    for(int i=0;i<n;++i)
    {
        if(i) cout << " ";
        if(i == ans) cout << "[";
        cout << array[i];
        if(i == ans) cout << "]";
    }
    cout << endl;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()

const int MAX = 1e5+10;
const int MOD = 1e9+7;

int N, M, A[MAX];
ll dp[MAX];

int solve() {
    set<int> step;
    REP (m, M) step.insert(A[m]);
    dp[0] = 1;
    if (step.find(1) == step.end()) dp[1] = 1;
    FOR (i, 2, N+1) if (step.find(i) == step.end()) {
        dp[i] = dp[i-1] + dp[i-2];
        dp[i] %= MOD;
    }
    return dp[N];
}

int main() {
    cin >> N >> M;
    REP (m, M) cin >> A[m];
    cout << solve() << endl;
}

Measured memory_bytes: 5376
import java.util.*;

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

        int tmp = (a + b) / 2;
        if(Math.abs(a - tmp) == Math.abs(b - tmp)) {
            System.out.println(tmp);
        } else if(Math.abs(a - tmp + 1) == Math.abs(b - tmp + 1)) {
            System.out.println(tmp - 1);
        } else if(Math.abs(a - tmp - 1) == Math.abs(b - tmp - 1)) {
            System.out.println(tmp + 1);
        } else {
            System.out.println("IMPOSSIBLE");
        }
    } 
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
const ll mod = 1e9 + 7;
ll ksm(ll a, ll p)
{
	ll res = 1;
	while (p)
	{
		if (p & 1) res = res * a % mod;
		a = a * a % mod;
		p >>= 1;
	}
	return res;
}
ll n, a, b;
ll cal(ll x, ll y)
{
	ll res = 1;
	for (int i = 1; i <= y; i++)
	res = res * (x - i + 1) % mod * ksm(i, mod - 2) % mod;
	return res;
}
int main()
{
	scanf("%lld%lld%lld", &n, &a, &b);
	ll tot = ksm(2, n);
	ll sum = (1 + cal(n, a) + cal(n, b)) % mod;
	tot = (tot - sum + mod) % mod;
	printf("%lld\n", tot);
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define ll long long

using namespace std;

char st[110],s[110];
int now,n,ans;

int check(int x){
	for (int i=2;i<=x;++i)
		if (s[i]!=s[1]) return 0;
	return 1;
}

int main(){
	scanf("%s",st+1);
	n=strlen(st+1);ans=n;
	for (int i=0;i<26;++i){
		for (int j=1;j<=n;++j) s[j]=st[j];
		now=0;
		for (int j=n;j;--j){
			if (check(j)) break;
			for (int k=1;k<=j;++k){
				if (s[k]-'a'==i) continue;
				if (s[k+1]-'a'==i) s[k]=s[k+1];
			}
			now++;
		}
		ans=min(ans,now);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long

using namespace std;

int N, K;

int dist[2000][2000];
vector<int> nextV[2000];
bool del[2000];

void setDistP(int root, int now, int prev, int dis) {
    dist[root][now] = dis;

    for (int i = 0; i < nextV[now].size(); i++) {
	int v = nextV[now][i];
	if (prev == v) continue;
	setDistP(root, v, now, dis + 1);
    }
}

void setDist() {
    for (int i = 0; i < N; i++) {
	setDistP(i, i, -1, 0);
    }
}

int over[2000];

signed main() {
    cin >> N >> K;

    for (int i = 0; i < N-1; i++) {
	int A, B;
	cin >> A >> B;
	A--; B--;
	nextV[A].push_back(B);
	nextV[B].push_back(A);
    }

    setDist();

    for (int i = 0; i < N; i++) {
	for (int j = 0; j < N; j++) {
	    if (dist[i][j] > K) {
		over[i]++;
	    }
	}
    }

    int ret = 0;
    while (true) {
	int maxArg = -1;
	int maxNum = 0;
	for (int i = 0; i < N; i++) {
	    if (del[i]) continue;
	    if (nextV[i].size() >= 2) continue;

	    if (over[i] > maxNum) {
		maxNum = over[i];
		maxArg = i;
	    }
	}

	if (maxArg == -1) break;

	ret++;
	for (int i = 0; i < N; i++) {
	    if (dist[i][maxArg] > K) {
		over[i]--;
	    }
	    if (dist[i][maxArg] == 1) {
		nextV[i].pop_back();
	    }
	}
	del[maxArg] = true;
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 31744
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	char a[N + 1];
	f(i, N + 1)a[i] = 0;
	int n, k;
	int x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%s", a);
	n = strlen(a);
	s = 0;
	f(i, n){
		if (a[i] == 'B')s++;
		else ans += s;
	}

	printf("%lld\n", ans);


	return 0;
}

Measured memory_bytes: 384
from math import log10

N = int(input())
A = list(map(int, input().split()))
s = 1
threshold = 10**18
if 0 in A:
    print(0)
else:
    for a in A:
        s *= a
        if s > threshold:
            print(-1)
            break
    else:
        print(s)




Measured memory_bytes: 22336
import java.util.*;

public class Main {
    public static void main(String[] args) {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        
        String strf = s.substring(0,2);
        String strb = s.substring(2); 
        
        int sf = Integer.parseInt(strf);
        int sb = Integer.parseInt(strb);
        
        String ans = "NA";
        
        if(1 <= sf && sf <= 12 && 1 <= sb && sb <= 12){
            ans = "AMBIGUOUS";
        }else if(1 <= sf && sf <= 12){
            ans = "MMYY";
        }else if(1 <= sb && sb <= 12){
            ans = "YYMM";    
        }
        System.out.println(ans);  
       
    }
}


Measured memory_bytes: 21716
def find(x):
    if parent[x]<0:
        return x
    else:
        parent[x]=find(parent[x])
        return parent[x]

def same(x,y):
    return find(x)==find(y)

def union(x,y):
    root_x=find(x)
    root_y=find(y)
    if root_x==root_y:
        return
    if parent[root_x]>parent[root_y]:
        root_x,root_y=root_y,root_x
    parent[root_x]+=parent[root_y]
    parent[root_y]=root_x

def members(n,x):
    root=find(x)
    return [i for i in range(n) if find(i)==root]

def get_size(x):
    return -parent[find(x)]

def get_root():
    return [i for i, root in enumerate(parent) if root<0]

N,M=map(int,input().split())
parent=[-1 for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    a=a-1
    b=b-1
    union(a,b)

ans=0
for i in range(N):
    ans=max(ans,get_size(i))
print(ans)

Measured memory_bytes: 14832
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var H = vals[0];
        var W = vals[1];
        var S = new string[H];
        for (int i = 0; i < H; i++)
        {
            S[i] = Console.ReadLine();
        }
        var xSum = new int[H, W];
        var ySum = new int[H, W];
        for (int y = 0; y < H; y++)
        {
            var count = 0;
            for (int x = 0; x <= W; x++)
            {
                if (x < W && S[y][x] == '.')
                {
                    count++;
                }
                else
                {
                    for (int xx = x - 1; xx >= 0; xx--)
                    {
                        if (S[y][xx] == '.')
                        {
                            xSum[y, xx] = count;
                        }
                        else
                        {
                            break;
                        }
                    }
                    count = 0;
                }
            }
        }

        for (int x = 0; x < W; x++)
        {
            var count = 0;
            for (int y = 0; y <= H; y++)
            {
                if (y < H && S[y][x] == '.')
                {
                    count++;
                }
                else
                {
                    for (int yy = y - 1; yy >= 0; yy--)
                    {
                        if (S[yy][x] == '.')
                        {
                            ySum[yy, x] = count;
                        }
                        else
                        {
                            break;
                        }
                    }
                    count = 0;
                }
            }
        }

        var max = 0;
        for (int y = 0; y < H; y++)
        {
            for (int x = 0; x < W; x++)
            {
                max = Math.Max(max, xSum[y, x] + ySum[y, x] - 1);
            }
        }

        Console.WriteLine(max);
    }
}

Measured memory_bytes: 61128