akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {
	static final int MOD = 1_000_000_007;

	public static void main(String[] args){
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		String s = sc.next();
		
		for(int i = 1; i < 4; i++) {
			if(s.charAt(i-1) == s.charAt(i)) {
				out.println("Bad");
				return;
			}
		}
		out.println("Good");
	}

	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static long lcm(long a, long b) {
		return a / gcd(a, b) * b;
	}

	public static long min(long... a) {
		long min = Long.MAX_VALUE;
		for(int i = 0; i < a.length; i++) {
			if(a[i] < min) min = a[i];
		}
		return min;
	}

	public static long max(long... a) {
		long max = Long.MIN_VALUE;
		for(int i = 0; i < a.length; i++) {
			if(a[i] > max) max = a[i];
		}
		return max;
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(K key, V value) {
        super(key, value);
    }

    public Pair<V, K> swap() {
    	return new Pair<V, K>(getValue(), getKey());
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

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

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

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

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

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

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

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

signed main(){
  int a, b, x, y;
  cin >> a >> b >> x >> y;
  printf("%.12f %d\n", double(a)*double(b)/2, x+x==a and y+y==b); 

  return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
using namespace std;
int a[100005],b[5];
int main ( ) {
	int n,i;
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]),a[i]%=4,b[a[i]]++;
	if (b[1]+b[3]>b[0]+1) {
		puts("No");return 0;
	}
	if (b[1]+b[3]==b[0]+1 && b[2]!=0) {
		puts("No");return 0;
	}
	if (b[2]==1 && b[0]==0) {
		puts("No");return 0;
	}
	puts("Yes");
	return 0;
}
/* 
3
1 10 100

Yes

4
1 2 3 4

No

3
1 4 1

Yes

2
1 1

No

6
2 7 1 8 2 8

Yes
*/

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define int long long int
#define FILEIO  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 
#define maxn 1000000
 

using namespace std;

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

signed main() {
//FILEIO;
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
char c;
cin>>c;
if(c >= 'A' and c <= 'Z')
{
	cout<<'A';
}
else
{
	cout<<'a';
}










    return 0;
}


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

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

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

int main () {
  int h, w, a, b;
  cin >> h >> w >> a >> b;

  rep(i,h) {
    rep(j,w) {
      if ((i<b)^(j<a)) {
        cout << 1;
      }
      else {
        cout << 0;
      }
    }
    cout << "\n";
  }
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF 1000000007
using namespace std;

int main(void){
    int ans=INF;
    string s;
    cin >> s;
    for(int i=0; i<s.length()-2; i++){
        int temp=stoi(s.substr(i,3));
        ans=min(ans,abs(753-temp));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    
    public static void main(String[]args){
         Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int d = scan.nextInt();
        int fl = 0 , min = d , sum =0; 
        for(int i =2 ; i<=n ; i++){
            
            fl = (d+i)-1;
            if(Math.abs(fl)<Math.abs(min)){
                sum+=min ;
                min = fl ;
            } else{
                sum+=fl ;
            }
        }
        
        System.out.println(sum);
    }
}

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

int main() {
  string S; cin >> S;
  string result = "Yes";
  for (int i = 1; i <= S.size(); ++i) {
    char c = S.at(i-1);
    if (i % 2 == 0) {
      if (c != 'L' && c != 'U' && c != 'D') {
        result = "No";
        break;
      }
    } else {
      if (c != 'R' && c != 'U' && c != 'D') {
        result = "No";
        break;
      }
    }
  }

  cout << result << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
const ll INF = 9223372036854775807-1;
const int inf = 2147483647-1;

int h,w;
char s[50][50];
bool flag = true;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
int main() {
    cin >> h >> w;
    REP(i,h){
        REP(j,w){
            cin >> s[i][j];
        }
    }
    REP(i,h){
        REP(j,w){
            if(s[i][j]=='#'){
                bool b_flag = false;
                REP(k,4){
                    if(s[i+dx[k]][j+dy[k]]=='#'){
                        b_flag = true;
                    }
                }
                if(!b_flag){
                    flag = false;
                }
            }
        }
    }
    if(flag)put("Yes")
    else put("No")
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

N, M = map(int, input().split())

if N-M == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 77584
#n,m=map(int,input().split())
#p_3,p_4=map(int,input().split())
#n=int(input())
#a=int(input())
#b=int(input())
s=input()
#T=input()
#recipe=[list(input().split())for _ in range(n)]
#m=int(input())
#have=[list(input().split())for _ in range(m)]
#s=[list(input())for _ in range(n)]
#b=list(map(int,input().split()))
#b=list(map(int,input().split()))
#c=list(map(int,input().split()))
#c=list(map(float,input().split()))
#n=int(input())
#s=[list(map(int,input().split()))for _ in range(n)]
#s=[list(input().split())for _ in range(n)]
#s=[input()for _ in range(n)]
if s=="Sunny":
    print("Cloudy")
elif s=="Cloudy":
    print("Rainy")
elif s=="Rainy":
    print("Sunny")

Measured memory_bytes: 2940
#include <stdio.h>
 
 
int main()
{
  int i,j,tmp,A[1000],n,count = 0;
 
  scanf("%d",&n);
 
  for(i =  0;i < n;i ++){

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

  printf("%d\n",count);
 
  return 0;
}

Measured memory_bytes: 604
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return (a % 1000000007);
}

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


int main(){
  string s,t ; cin >> s >> t; bool flag = true;
  
  rep(i,s.size()){
    if(s[i] != t[i]) flag = false;
  }
  
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3632
import java.util.*;
import java.lang.*;



public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        int shortEnough = 0, tooLong=N/2+1;

        while(shortEnough+1<tooLong){
            int trial = (shortEnough+tooLong)/2;
            boolean found = false;

            Map<String, Integer> dic = new HashMap<>();
            for(int l=0; l<=N-trial; l++){
                String current = S.substring(l,l+trial);
                if(dic.containsKey(current) && dic.get(current)<=l-trial){
                    found = true;
                    break;
                }else{
                    dic.putIfAbsent(current, l);
                }
            }

            if(found) shortEnough = trial;
            else tooLong = trial;
        }
        System.out.println(shortEnough);
    }
}


Measured memory_bytes: 113992
from sys import stdin
def input():
    return stdin.readline().strip()

n, weight = map(int, input().split())
w, v = [0]*n, [0]*n
for i in range(n):
    w[i], v[i] = map(int, input().split())

base = w[0]

for i in range(n):
    w[i] -= base

# dp[i][j] = i個選んで重さの余りがjの時の、価値の最大値
dp = [[0] * (3*n+1) for _ in range(n+1)]

for i in range(n):
    for j in range(i, -1, -1):
        for k in range(3*j+1):
            if dp[j+1][k+w[i]] < dp[j][k] + v[i]:
                dp[j+1][k+w[i]] = dp[j][k] + v[i]

ans = 0
for i in range(n+1):
    for j in range(3*n+1):
        if base * i + j <= weight and ans < dp[i][j]:
            ans = dp[i][j]

print(ans)

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

struct UF{
	vector<int> p;
	UF() {}
	UF(int n) : p(n, -1) {}
	int find(int a){ return p[a] < 0 ? a : p[a] = find(p[a]); }
	bool unite(int a, int b) {
		a = find(a); b = find(b);
		if(a == b) return false;
		if(-p[a] < -p[b]) swap(a, b);
		p[a] += p[b]; p[b] = a;
		return true;
	}
	bool root(int a){ return p[a] < 0; }
	bool same(int a, int b){ return find(a) == find(b); }
	int size(int a){ return -p[find(a)]; }
};

int main(){
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, k, l;
	cin >>n >>k >>l;
	
	UF ufa(n), ufb(n);
	rep(i, k){
		int p,q;
		cin >>p >>q;
		ufa.unite(p-1, q-1);
	}
	rep(i, l){
		int p,q;
		cin >>p >>q;
		ufb.unite(p-1, q-1);
	}
	map<pii, int> mem;
	map<int, set<int>> mpa, mpb;
	rep(i,n) mpa[ufa.find(i)].insert(i);
	rep(i,n) mpb[ufb.find(i)].insert(i);
	VI ans(n);
	rep(i, n){
		if(ufa.size(i) ==1 || ufb.size(i) ==1){ ans[i] = 1; continue;}
		int sm =0, pa=ufa.find(i), pb=ufb.find(i);
		if(mem.count(pii(pa, pb))){ans[i] = mem[pii(pa,pb)]; continue; }
		for(auto& z: mpa[pa]){
			if(mpb[pb].count(z)) sm++;
		}
		mem[pii(pa, pb)] = sm;
		ans[i] = sm;
	}
	rep(i, n) cout<<(i? " ":"") <<ans[i]; cout<<endl;
	return 0;
}

Measured memory_bytes: 55040
# 169A

#　1．入力をちゃんと受け取ること
# ex:「2 5」=>a=2,b=5と変数を作成する
# スペース区切りの入力を整数として受け取る例
a, b = map(int, input().split())
# print(a)
# print(b)

# 2．目的通りの計算をする
# ex:2つの整数AとBの掛け算をして、計算結果を出力する
print(a * b)

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

#define ONLINE_JUDGE
#define pb(a) push_back(a)
#define ALL(a) (a.begin(), a.end())
#define FOR(x,to) for(x=0;x<(to);x++)

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////

void solve() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int mx = 0;
	for (int i = 0; i < n-1; ++i) {
		set<char> lets;
		lets.clear();
		int cnt = 0;
		for (int j = 0; j <= i; ++j) {
			lets.insert(s[j]);
		}
		for (int j = i+1; j < n; ++j) {
			if (lets.count(s[j])) {
				++cnt;
				lets.erase(s[j]);
			}
		}

		mx = max(mx,cnt);
	}

	cout << mx << '\n';
}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

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

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int a[10];
bool dfs(int i,int b,int c){
	if(i<10){
		if(a[i] > b) {
			if(dfs(i+1,a[i],c)){
				return true;
			}
		}
		else if(a[i] > c) {
			if(dfs(i+1,b,a[i])) {
				return true;
			}
		}
		return false;
	}
	return true;
}
int main(){
	int i,n;
	while(cin >> n && n){
		for(i=0;i<n;i++){
			for(int j = 0;j<10;j++){
				cin >> a[j];
			}
			if(dfs(0,0,0)) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
/*
真ん中に区切るところを全探索すると
左右それぞれの数列はできるだけ近い値になるように分割するのが良い.
解説では尺取り方を用いるとあったが, 自分は左右の数列の総和の
半分の値となるような区切りを二部探索で見つけて, さらに
それらの+-1の区切り位置の場合も考えることで
二部探索で見つけた位置よりもより値の差が小さくなるような場合も見つけることができる.
*/
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

const int MAX_N = 2 * 1e5 + 2;
const ll INF = 1LL << 40;

ll A[MAX_N];

int main() {
    int N;
    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        A[i] += A[i - 1];
    }
    ll ans = INF;
    for (int i = 2; i <= N - 2; i++) {
        ll sub_ans = 0;
        int idx1 = lower_bound(A + 1, A + i + 1, A[i] / 2) - A;
        if (idx1 == i) idx1--;
        int idx2 = lower_bound(A + i + 1, A + N + 1, A[i] + ((A[N] - A[i]) / 2)) - A;
        if (idx2 == N) idx2--;
        for (int j = -1; j <= 1; j++) {
            for (int k = -1; k <= 1; k++) {
                if (idx1 + j == 0 || idx1 + j == N + 1 || idx2 + k == 0 || idx2 + k == N + 1) continue;
                ll P = A[idx1 + j], Q = A[i] - A[idx1 + j], R = A[idx2 + k] - A[i], S = A[N] - A[idx2 + k];
                ans = min(ans, abs(max(P, max(Q, max(R, S)))) - min(P, min(Q, min(R, S))));
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main () {
  int N;
  std::cin >> N;
  std::vector<int> data(3*N);
  for (int i=0; i<3*N; i++) {
    std::cin >> data.at(i);
  }
  std::sort(data.rbegin(), data.rend());
  long long int sum = 0;
  for (int i=1; i<2*N+1; i+=2) {
    sum += data.at(i);
  }
  std::cout << sum << std::endl;
}


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

int main(){
	int n,m,x;
	cin >> n >> m >> x;
	int a[m];
	rep(i,m)cin>>a[i];
	int countn=0,count0=0;
	rep(i,m){
		if(a[i]>x)countn++;
		else count0++;
	}
	cout << min(count0,countn) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
 
int main(){

    int A,B,K;

    cin >> A >> B >> K;

    for(int i=A;i<=B;i++){
        if(i<(A+K)){
            cout << i << " ";
        }else if(i>(B-K)){
            cout << i << " ";
        }
    }

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 200005
#define INF 1000000001
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,tot,T;
vector<int> v;
P a[MAXN];
int dp[MAXN][40];
void upd(int &a,int b) {a=min(a,b);}
bool cmp(P x,P y)
{
    return 1LL*y.F*x.S+y.F<1LL*x.F*y.S+x.F;
}
int main()
{
    scanf("%d%d",&n,&T);
    for(int i=1;i<=n;i++) 
    {
        int x,y;
        scanf("%d%d",&x,&y);
        if(x==0) v.push_back(y);
        else
        {
            ++tot;
            a[tot].F=x; a[tot].S=y;
        }
    }
    sort(v.begin(),v.end());
    sort(a+1,a+tot+1,cmp);
    for(int i=0;i<=tot;i++)
        for(int j=0;j<40;j++) 
            dp[i][j]=INF;
    dp[0][0]=0;
    for(int i=0;i<tot;i++)
    {
        for(int j=0;j<40;j++)
        {
            if(dp[i][j]==INF) continue;
            upd(dp[i+1][j],dp[i][j]);
            if(1LL*a[i+1].F*(dp[i][j]+1)+dp[i][j]+1+a[i+1].S<=T) upd(dp[i+1][j+1],1LL*a[i+1].F*(dp[i][j]+1)+dp[i][j]+1+a[i+1].S);
        }
    }
    int ans=0;
    for(int j=0;j<40;j++)
    {
        if(dp[tot][j]<=T)
        {
            int cur=j;
            int now=dp[tot][j];
            for(auto x:v)
            {
                now+=x+1;
                if(now>T) break;
                cur++;
            }
            ans=max(ans,cur);
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 33024
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int n, m;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	cout << (n - 1) * (m - 1) << "\n";
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.max

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (n, m) = readLongList()
    if (n == 1L && m == 1L) {
        out.println(1)
        return
    }
    val ans = if (n == 1L || m == 1L) m * n - 2 else (n - 2) * (m - 2)
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 36492
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll       long long
#define DS       pair<ll, ll>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) {
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}


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

using namespace std;

int main(){
  int N; cin >> N;
  vector<int> a(N);
  for(auto& t : a) cin >> t;
  int sum = 0;
  for(auto& t : a) sum += t;
  int res = 0, dif = 1000000000;
  for(int i=0;i<N;i++){
    int sub = abs(sum - N * a[i]);
    if(sub < dif){ res = i; dif = sub; }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
p=0
sun=1
answer=0
count=0
for i in range(1,n+1):
  if i < k:
    if i == 1:
      while(sun<k):
        sun *= 2
        count+=1
    else:
      while(sun>=k):
        sun /= 2
        count-=1
      sun *= 2
      count +=1
    answer+=1/n*1/pow(2,count)
    sun = sun/i*(i+1)
  else:
    answer+=1/n
print(answer)

Measured memory_bytes: 3064
/******************************************
* AUTHOR : GURUTEJA *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second

void debug(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 

}

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

     long long int n,count=0;

     cin>>n;

     long long int a[n];

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

        if(i>0 && a[i]<a[i-1]){
        	 count+=a[i-1]-a[i];
        	 a[i]+=a[i-1]-a[i];
        }
     }
     cout<<count<<endl;
    return 0;
  }

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

using namespace std;

int main()
{   
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    int count=0;
    for(int i=0;i<n-2;i++)
    {
        for(int j=i+1;j<n-1;j++)
        {
            if(a[i]!=a[j])
            {
                for(int k=j+1;k<n;k++)
                {
                    if(a[k]<(a[j]+a[i])&&a[j]!=a[k]) count++;
                }
            }
        }
    }
    cout<<count;
    return 0;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(void){

    string S,T; cin>>S>>T;
    int ans=0;
    for (int i = 0; i < 3; ++i) {
        if(S[i]==T[i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

const int X = 50;

using i64 = long long;

vector<i64> v, ans;

static void halt() {
	assert(ans.size() <= 200);

	cout << ans.size() << '\n';
	for (auto i: ans)
		cout << i << ' ';
	cout << endl;

	exit(0); }

int main() {
#ifdef HOME
	freopen("agc12c.in", "r", stdin);
	freopen("agc12c.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	i64 n, t(2 * X), cc(0);

	cin >> n;
	for (int i = 1; (1LL << i - 1) <= n; ++i) {
		ans.push_back(0);
		ans.push_back(i);
		n-= (1LL << i - 1); }

	for (int i = 0; i < ans.size() / 2; ++i) if (n & (1LL << i))
		ans[2 * i] = --t;

	ans.erase(remove(begin(ans), end(ans), 0), end(ans));
	for (int i = 1; i <= 2 * X; ++i)
		ans.push_back(i);
	halt();

	return 0; }


Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

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

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

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    size_t H, W; cin >> H >> W;

    queue<pair<int, int>> que;
    auto dist = make_v(INF, H, W);

    vector<string> mat(H);
    for (size_t i = 0; i < H; ++i) {
        cin >> mat[i];
        for (size_t j = 0; j < W; ++j) {
            if (mat[i][j] == '#') {
                que.emplace(i, j);
                dist[i][j] = 0;
            }
        }
    }

    int res = 0;
    while (!que.empty()) {
        int y = que.front().first;
        int x = que.front().second;
        que.pop();
        for (size_t i = 0; i < 4; ++i) {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if (inside(ny, nx, H, W) && chmin(dist[ny][nx], dist[y][x] + 1) && mat[ny][nx] != '#') {
                que.emplace(ny, nx);
                chmax(res, dist[ny][nx]);
            }
        }
    }

    cout << res << "\n";

    return 0;
}


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

int main()
{
  string s, t;

  cin >> s >> t;
  int c = 0;
  for (int i = 0; i < 3; ++i) {
    c += (s[i] == t[i]);
  }
  cout << c;

  return 0;
}



Measured memory_bytes: 256
def C_Traveling():
    N = int(input())
    a = 0
    b =0
    c =0
    for i in range(N):
        t, x, y = map(int, input().split())
        t1 = t-a
        x1 = abs(x-b)
        y1 = abs(y-c)
        z =t1 - x1 -y1
        if z%2  == 0 and z>=0:
            a =t
            b =x
            c =y
            continue
        else:
            print('No')
            break
    else: print('Yes')
        
C_Traveling()

Measured memory_bytes: 3064
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const ll MOD = TEN(9) + 7;
const int MAX_N = 100000;
int n;
int a[MAX_N];
int c[3];

int main() {
    fastio();

    int n;
    cin >> n;
    forn(i, n) cin >> a[i];

    ll ans = 1;
    forn(i, n) {
        vi ci;
        forn(j, 3) {
            if (c[j] == a[i]) ci.push_back(j);
        }

        if (ci.size() == 0) {
            ans *= 0;
            continue;
        }
        if (ci.size() == 2) {
            ans = ans * 2 % MOD;
        } else if (ci.size() == 3) {
            ans = ans * 3 % MOD;
        }
        c[ci.front()]++;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	
//ここから書き始める

int main()
{
	cout <<setprecision(10);
	string s;cin >> s;
	int n = s.size();
	vector<int> A(3);
	rep(i,n){
		if(s[i] == 'a'){
			A[0]++;
		}else if(s[i] =='b'){
			A[1]++;
		}else A[2]++;
	}
	SORT(A);
	int need =  (A[2] - 1);
	if(A[1] >= need && A[0] >= need){
		cout<<"YES"<<endl;
	}
	else cout << "NO"<<endl;




}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int X,Y;cin >> X >> Y;
  int ans = 0;
  if(X==1 && Y==1) ans += 400000;
  if(X==1) ans += 300000;
  if(X==2) ans += 200000;
  if(X==3) ans += 100000;
  if(Y==1) ans += 300000;
  if(Y==2) ans += 200000;
  if(Y==3) ans += 100000;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import fractions

N, M = map(int, input().split())
S = input()
T = input()
c = fractions.gcd(N, M)
d = N*M//c
ans = d
for i in range(c):
    if S[i*(N // c)] != T[i*(M // c)]:
        ans = -1
print(ans)

Measured memory_bytes: 5432
import java.util.*

fun main() {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val D = sc.next().toLong()
        val T = sc.next().toLong()
        val S = sc.next().toLong()
        pw.println(if (S * T >= D) "Yes" else "No")
    }
}


Measured memory_bytes: 36460
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

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

    int ans=0;
    for(int i=1;i<=N-1;i++){
        int cnt=0;
        for(int c='a';c<='z';c++){
            bool l=false,r=false;
            for(int j=0;j<i;j++) if(s[j]==c) l=true;
            for(int j=i;j<N;j++) if(s[j]==c) r=true;
            if(l and r) cnt++;
        }
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;
 
}


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

using namespace std;

bool solve(int, int, int, int*);

int main(){
	int n, q;
	vector<int> A, m;
	int i, j, k;
	int ain, min;
	bool exist;
	
	cin >> n;
	for(i=0;i<n;++i){
		cin >> ain;
		A.push_back(ain);
	}
	cin >> q;
	for(i=0;i<q;++i){
		cin >> min;
		m.push_back(min);
	}
	
	for(i=0;i<q;++i){
		exist = false;
		
		if(solve(0, m[i], n, &A[0]))exist = true;
		if(exist)cout << "yes\n";
		else cout << "no\n";
	}
	
	return 0;
}

bool solve(int i, int m, int n, int* tmp){
	int res;
	if(m == 0)return true;
	if(i>=n)return false;
	res = solve(i+1, m, n, tmp) || solve(i+1, m-tmp[i], n, tmp);
	return res;
}


Measured memory_bytes: 3124
def main():
    from collections import deque
    n = int(input())
    s = input()
    need_left, need_right = 0, 0
    for i in s:
        if i == "(":
            need_right += 1
        else:
            if need_right == 0:
                need_left += 1
            else:
                need_right -= 1
    for i in range(need_left):
        s = "(" + s
    for j in range(need_right):
        s = s + ")"
    print(s)
if __name__ == "__main__":
    main()

Measured memory_bytes: 38384
import java.io.*;
import java.math.*;
import java.util.*;

class Main {
	
	public static void main(String[] args) throws IOException {

		BufferedReader br =
			new BufferedReader(new InputStreamReader(System.in));
		
		ArrayList<String> ans = new ArrayList<String>();
		
		while (true) {
			
			String s = br.readLine();
			if (s == null) break;
			
			// 入力された値を２進数に変換し、反転させた文字列str
			String str = new StringBuffer(BigInteger.valueOf((Integer.parseInt(s))).toString(2)).reverse().toString();
			String a = "";
			for (int i = 0; i < str.length(); i++) {
				if (str.charAt(i) == '1') {
					a += String.valueOf((int)Math.pow(2, i));
					if (i != str.length() - 1)
						a += " ";
				}
			}
			ans.add(a);
		}
		for (String p : ans) {
			System.out.println(p);
		}
	}

}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  int N;
  cin >>N;
  int count=0;
  repl(i,1,10) {
if( (N%i==0) &&(N/i<10)) {
cout <<"Yes"<< endl;
  break;
}
    else {
      count=i;
    }
  }
  if(count==9) {
cout <<"No"<< endl;
  }
}
  

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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	double n,d;
	cin >> n>>d;
	int ans = 0;
	rep(i, n) {
		double x, y;
		cin >> x >> y;
		if ((x*x + y * y) <= d*d)ans++;
	}
	print(ans);
}

Measured memory_bytes: 3724
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int a, b;
string s;

bool check()
{
  for(int i = 0; i < a; i++) {
    if (!isdigit(s[i]))
      return false;
  }
  if (s[a] != '-') return false;
  for(int i = a + 1; i <= a + b; i++) {
    if (!isdigit(s[i]))
      return false;
  }
  return true;
}

int main()
{
  cin >> a >> b >> s;
  if (check())
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 998244353
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;
struct segtree {
public:
	const int SIZE = 1 << 18;
	VI seg, lazy;
	//seg:区間の合計値 lazy:区間に対して、加える値でまだ遅延しているもの

	segtree() :seg(SIZE * 2), lazy(SIZE * 2) {}
	void lazy_evaluate(int k, int l, int r) {
		if (lazy[k] != 0) {
			seg[k] += lazy[k];
			seg[k] %= mod;
			//区間[l,r)にすべて同じ値を追加することになっていて、
			//segには合計値が入っているので、加える値を足す
			if (r - l > 1) {
				lazy[k * 2 + 1] += lazy[k];
				lazy[k * 2 + 2] += lazy[k];
				lazy[k * 2 + 1] %= mod;
				lazy[k * 2 + 2] %= mod;
			}
			lazy[k] = 0;
		}
	}

	void update(int a, int b, int k, int l, int r, int x) {
		lazy_evaluate(k, l, r);
		if (r <= a || b <= l)return;
		if (a <= l && r <= b) {
			lazy[k] += x;
			lazy[k] %= mod;
			lazy_evaluate(k, l, r);
		}
		else {
			update(a, b, k * 2 + 1, l, (l + r) / 2, x);
			update(a, b, k * 2 + 2, (l + r) / 2, r, x);
			seg[k] = seg[k * 2 + 1] + seg[k * 2 + 2];
			seg[k] %= mod;
		}
	}
	int query(int a, int b, int k, int l, int r) {
		lazy_evaluate(k, l, r);
		if (r <= a || b <= l)return 0;
		if (a <= l && r <= b)return seg[k];
		int x = query(a, b, k * 2 + 1, l, (l + r) / 2);
		int y = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return (x + y) % mod;
	}

	void update(int a, int b, int x) { update(a, b, 0, 0, SIZE, x); }
	//update(a,b,x) := [a,b)を全てxを加える
	int query(int a, int b) { return query(a, b, 0, 0, SIZE); }
	//query(a,b) := [a,b)に対する合計値を求める

};

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

	int N; cin >> N;
	int K; cin >> K;
	VP A(K);
	REP(i, K)cin >> A[i].first >> A[i].second;
	SORT(A);
	segtree seg;
	seg.update(0, 1, 1);
	REP(i, N - 1) {
		int add = seg.query(i, i + 1);
		REP(j, K) {
			int L = A[j].first, R = A[j].second;
			seg.update(i + L, i + R + 1, add);
		}
	}





	cout << seg.query(N - 1, N) << endl;

	return 0;
}



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

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

using namespace std;

template<class G>
class Fenwick_tree{
	vector<G> a;
public:
	Fenwick_tree(int n):a(n){}
	void add(int i,G val){
		for(i++;i<=a.size();i+=i&-i) a[i-1]+=val;
	}
	G sum(int l,int r)const{
		if(l==0){
			G res{};
			for(;r>0;r-=r&-r) res+=a[r-1];
			return res;
		}
		return sum(0,r)-sum(0,l);
	}
	int lower_bound(G val)const{
		if(val<=G{}) return 0;
		int x=0,k;
		for(k=1;k<=a.size();k<<=1);
		for(k>>=1;k>0;k>>=1) if(x+k<=a.size() && a[x+k-1]<val) val-=a[x+k-1], x+=k;
		return x;
	}
	int upper_bound(G val)const{
		if(val<G{}) return 0;
		int x=0,k;
		for(k=1;k<=a.size();k<<=1);
		for(k>>=1;k>0;k>>=1) if(x+k<=a.size() && a[x+k-1]<=val) val-=a[x+k-1], x+=k;
		return x;
	}
};

int n,bad[100000];

vector<pair<int,int>> V;

Fenwick_tree<int> F(0);
int ans[100000];

bool dfs(int i){
	if(i==n) return true;
//printf("i  = %d\n",i);

	int next=-1;
	for(auto p:V){
		int deg=p.first,x=p.second;
		if(deg==n-1 && F.sum(x,x+1)==1){
			if(next!=-1) return false;
			next=x;
		}
	}
	if(next!=-1){
//printf("next = %d\n",next);
		int x=next;
		if(i==0 || bad[ans[i-1]]!=x){
			F.add(x,-1);
			ans[i]=x;
			for(auto& p:V) if(bad[x]!=p.second) p.first++;
			if(dfs(i+1)) return true;
			for(auto& p:V) if(bad[x]!=p.second) p.first--;
			F.add(x, 1);
		}
		return false;
	}

	for(int p=1;;p++){
		int x=F.lower_bound(p);
		if(x==n) break;
		if(i==0 || bad[ans[i-1]]!=x){
			F.add(x,-1);
			ans[i]=x;
			for(auto& p:V) if(bad[x]!=p.second) p.first++;
			if(dfs(i+1)) return true;
			for(auto& p:V) if(bad[x]!=p.second) p.first--;
			F.add(x, 1);
		}
	}
	return false;
}

int main(){
	scanf("%d",&n);
	rep(i,n) scanf("%d",&bad[i]), bad[i]--;

	if(n==2) return puts("-1"),0;

	F=Fenwick_tree<int>(n);
	rep(i,n) F.add(i,1);

	vector<int> deg(n);
	rep(i,n) deg[bad[i]]++;
	vector<pair<int,int>> p(n);

	rep(i,n) p[i]={-deg[i],i};
	sort(p.begin(),p.end());
	rep(i,min(300,n)) V.emplace_back(-p[i].first,p[i].second);
//for(auto q:V) printf("%d %d\n",q.first,q.second);

	bool ok=dfs(0);

	if(ok){
		rep(i,n) printf("%d%c",ans[i]+1,i<n-1?' ':'\n');
	}
	else{
		puts("-1");
	}

	return 0;
}


Measured memory_bytes: 11008
import math


def main():
    n = int(input())
    dp = [0] * (n + 1)
    dp[0] = 1
    for i in range(1, n + 1):
        for j in range(100, 106):
            if i - j >= 0:
                dp[i] = dp[i] | dp[i-j]
    print(dp[n])

if __name__ == "__main__":
    main()


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mn=1e5+10;
typedef pair<int,int>pii;
pii p[mn];
int dp[mn];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d%d",&p[i].first,&p[i].second),p[i].second+=p[i].first,p[i].first=2*p[i].first-p[i].second;
    sort(p+1,p+1+n,[](pii a,pii b){return a.second<b.second;});
    for(int i=1;i<=n;i++){
        int bes=lower_bound(p+1,p+1+n,make_pair(0,p[i].first+1),[](pii a,pii b){return a.second<b.second;})-p-1;
        dp[i]=max(dp[i-1],dp[bes]+1);
    }
    printf("%d",dp[n]);
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
string a;
int ans=1073741824; 
int main()
{
    cin>>a;
    for(int i=1;i<a.size();i++)
        if(a[i]!=a[i-1])
            ans=min(ans,max(i,int(a.size())-i));
    cout<<min(ans,int(a.size()))<<endl;
    return 0;
}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

vector<vector<int>> g;
vector<bool> checked;

void dfs(int v, int &num, int a, int b){
    checked[v] = true;
    num++;
    for(int nv : g[v]){
        if(checked[nv]) continue;
        if(v == a && nv == b) continue;
        if(v == b && nv == a) continue;
        dfs(nv, num, a, b);
    }
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n,m; cin >> n >> m;
    g.resize(n);
    checked.assign(n, false);

    vector<pair<int, int>> edge(m);
    for(int i = 0; i < m; i++){
        int a, b; cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
        edge[i] = make_pair(a, b);
    }

    int ans = 0;
    for(int i = 0; i < m; i++) {
        checked.assign(n, false);
        int cnt = 0;
        int a, b; tie(a,b) = edge[i];
        dfs(0, cnt, a, b);
        if(cnt != n) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import math
from itertools import permutations


def calc_distance(a, b):
    dx = a[0] - b[0]
    dy = a[1] - b[1]
    d = math.sqrt(dx * dx + dy * dy)
    return d

N = int(input())

city = [0] * N
for i in range(N):
    city[i] = list(map(int, input().split()))

mtx = [0 for i in range(N)] * N

mtx = [[calc_distance(a, b) for a in city] for b in city]


all_distance = 0
paths = permutations([i for i in range(N)])
cnt = 0
for pt in paths:
    distance = 0
    for idx in range(1, len(pt)):
       distance += mtx[pt[idx]][pt[idx-1]]

    all_distance += distance
    cnt += 1

all_distance /= cnt


print(all_distance)




Measured memory_bytes: 9236
from math import cos, sqrt, pi

[A,B,H,M] = [ int(x) for x in input().split() ]
aAngle = (H%12 + M/60.0) / 12.0 * 2*pi
bAngle = M%60 / 60.0 * 2*pi
angle = max(aAngle,bAngle) - min(aAngle, bAngle)
ans = A**2 + B**2 - 2*A*B*cos(angle)
ans = sqrt(ans)
print(ans)

Measured memory_bytes: 9516
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        Stack<Integer> st = new Stack<Integer>();
        while (stdin.hasNext()) {
            int i = stdin.nextInt();
            if (i == 0) {
                System.out.println(st.pop());
            } else {
                st.push(i);
            }




        }
    }
}

Measured memory_bytes: 17200
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
#define double long double
typedef pair<double, string> P;

bool solve(){
	int n;
	string name;
	int p, a, b, c, d, e, f, s, m;
	P data[50];
	
	cin >> n;
	if( n == 0 ) return false;
	for( int i = 0; i < n; i++ ){
		cin >> name >> p >> a >> b >> c >> d >> e >> f >> s >> m;
		int income = s * f * m - p;
		int timer = a + b + c + m * (d + e);
		double effect = (double)income / timer;
		data[i].first = -effect;	//Swap Order Technic.
		data[i].second = name;
	}
	sort(data, data + n);
	
	for( int i = 0; i < n; i++ ){
		cout << data[i].second << endl;
	}
}

int main(){
	while(1){
		if( !solve() )
			break;
		else
			cout << "#" << endl;
	}
	return 0;
}

Measured memory_bytes: 1220