akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
    int H, W, M;
    cin >> H >> W >> M;

    vector<int> h_num(H);
    vector<int> w_num(W);
    int max_h = 0;
    int max_w = 0;

    set<pair<int, int>> s;

    for(int i=0; i<M; ++i){
        int h, w;
        cin >> h >> w;
        h--; w--;
        h_num[h]++;
        max_h = max(max_h, h_num[h]);
        w_num[w]++;
        s.emplace(h, w);
        max_w = max(max_w, w_num[w]);
    }

    //candidate h, w, indexs
    vector<int> candidate_h_idx;
    for(int h=0; h<H; ++h){
        if(h_num[h] != max_h) continue;
        candidate_h_idx.push_back(h);
    }


    vector<int> candidate_w_idx;
    for(int w=0; w<W; ++w){
        if(w_num[w] != max_w) continue;
        candidate_w_idx.push_back(w);
    }

    //tmp ans
    int ans = max_h + max_w;

    //check if all the points are crossed or not
    bool all_crossed = true;

    for(int h : candidate_h_idx){
        for(int w : candidate_w_idx){
            if(s.count({h, w})) continue;
            all_crossed = false;
            break;
        }
    }

    if(all_crossed){
        cout << ans -1 << endl;
    }else{
        cout << ans << endl;
    }

}


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

int main(){
    cout << fixed << setprecision(10);
    int n;
    cin>>n;
    double m = (double)n;
    if(n!=1){
        if(n%2 ==0){
            
            m=0.5;
        }else{
            m = 1.0*(n/2+1) /n;   
            
        }
    }
    cout << m << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main
{
public static void main(String[] args)
 {
 Scanner sc = new Scanner(System.in);
  int  n  = sc.nextInt();
  int p[][][] = new int[4][3][10];
  int i, j, k, b, f,r, v;
  
  for(i=0; i<n; i++){
   b =sc.nextInt();
   f =sc.nextInt();
   r =sc.nextInt();
   v =sc.nextInt();
   p[b-1][f-1][r-1]+=v;
  }

  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
        System.out.print(" "+p[i][j][k]);
      }
      System.out.println();
    }
    if(i<3)System.out.println("####################");
  }
}
}



Measured memory_bytes: 29380
#include <bits/stdc++.h>
using namespace std;
int n,i,j;
double ans,d[3009][3009],a[3000];
double dp(int i,int x){
    if(x==-1) return 0;
    if(i==n) return x==0;
    if(d[i][x]!=-1) return d[i][x];
    d[i][x]=a[i]*dp(i+1,x-1)+(1-a[i])*dp(i+1,x);
    return d[i][x];
}
int main()
{
    cin>>n;
    for(i=0;i<n;i++) cin>>a[i];
    for(i=0;i<=3000;i++) for(j=0;j<=3000;j++) d[i][j]=-1;
    for(i=n;i>n/2;i--) ans+=dp(0,i);
    if(n%2==0) ans+=dp(0,n/2);
    cout<<fixed<<setprecision(10)<<ans;
    return 0;
}


Measured memory_bytes: 71040
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

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

    if (s[0] == '9' || s[1] == '9') {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    } 

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

vector<int> S;
void solve(std::string s){
  for(long long i = 0; i < s.size(); i++){
    if(s[i]=='A'){
      S.push_back(0);
    }
    else if(s[i]=='B'&&s[i+1]=='C'){
      S.push_back(1);
      i++;
    }
    else{
      S.push_back(2);
    }
  }
  ll ans=0,cnt=0;
  for(long long i = 0; i < S.size(); i++){
    if(S[i]==0){
      cnt++;
    }
    if(S[i]==1){
      ans+=cnt;
    }
    if(S[i]==2){
      cnt=0;
    }
  }
  cout<<ans<<endl;
}

int main(){
    std::string s;
    std::cin >> s;
    solve(s);
    return 0;
}


Measured memory_bytes: 1788
import math
n = int(input())
a = list(map(int,input().split()))

def generate_D(maxA):
  seq = [i for i in range(maxA+1)]
  p = 2
  while p*p <= maxA:
    if seq[p]==p:
      for q in range(p*2,maxA+1,p):
        if seq[q]==q:
          seq[q] = p
    p += 1
  return seq

cur = a[0]
for v in a[1:]:
  cur = math.gcd(cur,v)
if cur > 1:
  print('not coprime')
else:  
  d = generate_D(max(a))
  primes = set([])
  tf = 1
  for v in a:
    tmp = set([])
    while v > 1:
      tmp.add(d[v])
      v //= d[v]
    for k in tmp:
      if k in primes:
        tf = 0
      else:
        primes.add(k)
  if tf:
    print('pairwise coprime')
  else:
    print('setwise coprime')

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

enum
{
  P,
  W,
  G,
  Y,
};

int main()
{
  int N;
  char c;
  cin >> N;
  int in[4] = {0};
  for (int i = 0; i < N; i++)
  {
    cin >> c;
    if      (c == 'P') in[P] = 1;
    else if (c == 'W') in[W] = 1;
    else if (c == 'G') in[G] = 1;
    else if (c == 'Y') in[Y] = 1;
  }
  int colors = 0;
  for (int i = 0; i < 4; i++)
  {
    colors += in[i];
  }
  if      (colors == 1) cout <<  "One"   << endl;
  else if (colors == 2) cout <<  "Two"   << endl;
  else if (colors == 3) cout <<  "Three" << endl;
  else if (colors == 4) cout <<  "Four"  << endl;
}


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

int main(){
  int A , B , C , D;
  cin >> A ;
  cin >> B ;
  cin >> C ;
  cin >> D ;
  
  if(A + B == C + D){
      cout << "Balanced" << endl;
  }
  else if(A + B < C + D){
      cout << "Right" << endl;
  } 
  else if(A + B > C + D){
      cout << "Left" << endl;
  } 
}

Measured memory_bytes: 256
import java.io.*;

class Main
{
   public static void main(String args[]) throws IOException
   {
	
	BufferedReader br =
	 new BufferedReader(new InputStreamReader(System.in));

	String str = br.readLine();
	int x = Integer.parseInt(str);

	System.out.println(x*x*x);
   }
}

Measured memory_bytes: 24256
import itertools

n = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

tmp = list(itertools.permutations(P,n))

tmp = sorted(tmp)


a = 0
b = 0
for i in range(len(tmp)):
    if tmp[i] == P:
        a = i
    if tmp[i] == Q:
        b = i
        
        
print(abs(a-b))

Measured memory_bytes: 8308
#include<stdio.h>
int main(){
  int n,s,i,ans=0,min=111111;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&s);
    ans+=s;
    if(s%10!=0&&s<min)
      min=s;
  }
  if(ans%10==0){
    if(min<100000)
      ans-=min;
    else
      ans=0;
  }
  printf("%d\n",ans);
  return 0;
}

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

int main(){
    int n,k;
    scanf("%d %d",&n, &k);
    vector<int> a(n);
    for(int &x : a)
        scanf("%d",&x);
    
    vector<bool> dp(k+1,false);
    //here dp[k] => true if the player who starts first is the winner
    //if k == 0, dp[0] =false => player who will end up in this state will lose because he can't take any turn from this point
    // and the player who is in state dp[k + x] where k = 0 , can win the game
    // i.e if(dp[i-x] == false){
    //       /*this means the second player will lose his shit*/
    //       dp[i] = true;//player which is playing this turn wins
    //   }
    for(int stones = 0;stones <= k;stones++){
        for(int v : a){
            if(stones >= v && !dp[stones - v])
                dp[stones] =true;
        }
    }
    
    
    puts(dp[k]?"First":"Second");
    return 0;
}

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

int main() {
  char c = 'a';
  cin>> c;
  if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
    cout << "vowel" <<endl;
  }
  else{
    cout << "consonant" <<endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#define N 101
using namespace std;
int A[N][N];
int n;
int main(){
    int k,num;
    int e;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)
            A[i][j]=0;
    }
    for(int i=0;i<n;i++){
        cin>>k;
        k--;
        cin>>num;
        for(int j=0;j<num;j++){
            cin>>e;
            e--;
            A[k][e]=1;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(j) cout<<' ';
            cout<<A[i][j];
        }
        cout<<endl;
    }
}



Measured memory_bytes: 3096
a, b, c = input().split(' ')
a = int(a)
b = int(b)
c = int(c)
flag = 0
x = a%b
for i in range(1, 101):
    if (x*i)%b == c:
        flag=1
        break

if flag == 1:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int M,D;
    cin >> M >> D;
    int d10,d1;
    int cont = 0;
    for(int i = 1 ; i <= M;i++){
        
        for(int j = 1; j <= D;j++){
            
            d10=j/10;
            if(d10<2)continue;
            d1 = j - d10*10;
            //cout << d1<<" " << d10<<endl;
            if(d1<2)continue;
            
            if(i==d10*d1){
               // cout << i <<":"<<j<<endl;   
                cont++;
            }
            
        }
        
        
    }
    
    cout << cont << endl;
    
}


Measured memory_bytes: 256
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18
#list(map(int, stdin.readline().rstrip().split()))
n,m,x = map(int, stdin.readline().rstrip().split())
numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
#word = [stdin.readline().rstrip() for _ in range(n)]
#number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]

rikai = [0] * m
l = [i for i in range(1,n+1)]
ans = 10**9
for i in l:
    books = list(comb(l,i))

    for j in books:
        # jを選ぶ
        pay = 0
        rikaii = rikai[:]
        for u in j:
            cost = numbers[u-1][0]
            skill = numbers[u-1][1:]
            pay += cost
            rikaii = [x + y for (x, y) in zip(rikaii, skill)]
        ok = 0
        for y in range(m):
            if rikaii[y] >= x:
                ok += 1
        if ok == m:
            ans = min(ans,pay)

if ans == 10**9:
    print(-1)
else:
    print(ans)



Measured memory_bytes: 9392
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from bisect import bisect_left 
from bisect import bisect_right
def main():
    n = int(readline()) 
    a = [int(i) for i in readline().split()]
    b = [int(i) for i in readline().split()]
    c = [int(i) for i in readline().split()]
    a.sort()
    c.sort()
    ans = 0
    for v in b:
        i = bisect_left(a, v)
        j = bisect_right(c, v)
        ans += i*(n-j)
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 21088
A = list(map(int, input().split()))

E = [a for a in A if a % 2 == 0]
O = [a for a in A if a % 2 == 1]

ans = 0

if len(E) == 2:
    ans += 1
    E = [e + 1 for e in E]
    A = E + O

if len(O) == 2:
    ans += 1
    O = [o + 1 for o in O]
    A = E + O

biggest = max(A)
A = [biggest - a for a in A]
print(ans + sum(A) // 2)


Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <iostream>
#include <bitset>
#include <map>
#include <numeric>
#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
#define pp pair<int,int>
#define fix(n) fixed << setprecision(n)
#define gmax(a,b) __gcd(a,b)
#define gmin(a,b) a/__gcd(a,b)*b
using namespace std;
//obj;
class binary{
public:
    bool isOK(int index, int key,vi a) {
    if (a[index] >= key) return true;
    else return false;
}
int binary_search(int key,vi a) {
   
    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key,a)) ok = mid;
        else ng = mid;
    }
    return ok;
}
}obj;

ll hantei(int a){
    ll ans=1;
   for (int i = 2; i <= sqrt(a); i++) {
    ll cnt = 0;
    while (a % i == 0) {
      cnt++;
      a /= i;
    }
    ans *= (cnt + 1);
    if (a == 1) break;
   }
   if (a != 1) ans *= 2;
//ans=ans*a;
    return ans;
   
}

ll tousawa(ll a,ll n){
    ll s=n/a;
    ll d=s*a;
    ll ans=(s*(a+d))/2;
    return ans;
}
int main(){
    ll n;cin>>n;
    ll ans=0;
    rep(i,n){
        ans+=tousawa(i+1,n);
    }
    cout<<ans<<endl;
 }


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

int main() {

  int n;
  cin >> n;
  vector<int> p(n);
  for(int i = 0; i < n; i++) {
    cin >> p.at(i);
  }
  
  int ans = 0;
  vector<int> tmp(3);
  for(int i = 1; i < n-1; i++) {
    int t = i - 1;
    int j = i + 1;
    tmp.at(0) = p.at(t);
    tmp.at(1) = p.at(i);
    tmp.at(2) = p.at(j);
    sort(tmp.begin(), tmp.end());
    if(p.at(i) == tmp.at(1)) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FOREACH(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define SIZE(v) ((int)(v).size())
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ll long long
#define llint long long
#define pii pair<int, int>
#define UNVISITED -1


template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}
 
template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
 
class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

const ll mod = 1000000007;

int main() {
    int N; scanf("%d", &N);
    if(N == 1) printf("0\n");
    else {
        ll ans = 1;
        REP(i, N) ans = (ans*10)%mod;
        ll tmp = 2;
        ll cur = 1;
        REP(i, N) tmp = (tmp * 9)%mod;
        REP(i, N) cur = (cur * 8)%mod;

        printf("%lld\n", (ans - tmp + cur + mod)%mod);
    }
    
}

Measured memory_bytes: 3812
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
    int a, b;
    cin >> a >> b;
    if (a < b) {
        for (int i = 0; i < b; ++i) cout << a;
        }
    else {
        for (int i = 0; i < a; ++i) cout << b;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
bool dp[1000001];
bool isprime(int& x){
  for(int i = 2 ; i * i <= x ; i++ ) if( x % i == 0) return true;
  return x == 1;
}
int solve(int& i){
  if( i % 2 == 0 ) i--;
  while(true){
    if(dp[i] && !isprime(i)) return i;
    i -= 2;
  }
}
int main(){
  int n,x,data,ans;
  dp[0] = true;
  while(scanf("%d %d",&n,&x) , n){
    for(int i = 1 ; i <= x ; i++ ) dp[i] = false;
    for(int i = 0 ; i < n ; i++ ){
      scanf("%d",&data);
      for(int i = data ; i <= x ; i++ ) if(dp[i-data]) dp[i] = true;
    }
    if(1 < (ans = solve(x))) printf("%d\n",ans);
    else printf("NA\n");
  }
}

Measured memory_bytes: 2016
days = [31,29,31,30,31,30,31,31,30,31,30,31]
ans = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]

while True:
    idx = 3
    m,d = map(int, input().split())
    if m==0: break
    print(ans[(idx+sum(days[:m-1])+d-1)%7])

Measured memory_bytes: 7596
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

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

    int b = 0;
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            if (i * j == n) {
                b = 1;
                break;
            }
        }
    }

    cout << (b ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import deque
N,M,P,*L = map(int, open(0).read().split())
INF = 10**9
Els = []
dic = [[] for i in range(N+1)]
rdic = [[] for i in range(N+1)]
for a,b,c in zip(*[iter(L)]*3):
  dic[a].append((b,c-P))
  rdic[b].append((a,c-P))
  Els.append((a,b,-c+P))
ok1 = [False]*(N+1)
ok1[1] = True
q = deque([1])
while q:
  v = q.popleft()
  for p,c in dic[v]:
    if not ok1[p]:
      ok1[p] = True
      q.append(p)

ok2 = [False]*(N+1)
ok2[N] = True
q = deque([N])
while q:
  v = q.popleft()
  for p,c in rdic[v]:
    if not ok2[p]:
      ok2[p] = True
      q.append(p)

ok = [a&b for a,b in zip(ok1,ok2)]

dist = [INF]*(N+1)
dist[1] = 0
cnt = 0
while True:
  end = True
  for a,b,c in Els:
    if ok[a] and ok[b] and dist[a]!=INF and dist[b]>dist[a]+c:
      end = False
      dist[b] = dist[a]+c
  if end:
    print(max(0,-dist[N]))
    break
  cnt += 1
  if cnt>N:
    print(-1)
    break

Measured memory_bytes: 48928
#include<stdio.h>
int MIN(int a,int b){return  a<b?a:b;}
int r,ord[100010],low[100010];
void cdfs(int s,int *ta,int *to,int *nt,int *p){//printf("s%d %d\n",s,r);
  int i;
  ord[s]=low[s]=r++;
  for(i=ta[s];i+1;i=nt[i]){
    if(p[to[i]]==-1){
      p[to[i]]=s;
      cdfs(to[i],ta,to,nt,p);
      low[s]=MIN(low[s],low[to[i]]);
    }
    else if(to[i]-p[s])low[s]=MIN(low[s],ord[to[i]]);
  }
}
int brig(int v,int e,int *a,int *b){
  int ta[100010],to[100010],nt[100010],p[100010],ans=0,co=0,i,j,f[100010]={0};
  for(i=0;i<v;i++)ta[i]=p[i]=-1;
  for(p[0]=i=0;i<e;i++){
    nt[i  ]=ta[to[i+e]=a[i]];
    nt[i+e]=ta[to[i  ]=b[i]];
    ta[b[ta[a[i]]=i]]=i+e;
  }
  for(i=r=0;i<v;i++){
    if(r<v)cdfs(i,ta,to,nt,p);
  }
  for(i=1;i<v;i++){//橋を配列に格納していく
    if(ord[p[i]]<low[i])co++;
  }
  return co;
}
int main(){
  int n,m,i,a[100100],b[10010];
  scanf("%d %d",&n,&m);
  for(i=0;i<m;i++){
    scanf("%d %d",&a[i],&b[i]);
    a[i]--;
    b[i]--;
  }
  printf("%d\n",brig(n,m,a,b));
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int gcd(int a, int b)
{
	int c;
	while (a != 0) {
		c = a; a = b%a;  b = c;
	}
	return b;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	string S, T;
	cin >> S >> T;
	int res = (N / gcd(N, M)) * M;
	map<int, char> mp;
	for (int i = 0; i < N; i++) {
		mp[(res / N)*i] = S[i];
	}
	for (int i = 0; i < M; i++) {
		if (mp.count((res / M)*i) != 0 && mp[(res / M)*i] != T[i]) {
			res = -1;
			//cerr << (res / M)*i << endl;
		}
	}
	
	cout << res << endl;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int N = 200000;



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

    string s, ss;
    cin >> s >> ss;
    int c = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i] != ss[i]){
            c++;
        }
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 3804
#include<iostream>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin >> n;
    for(int i=1; i<(n+1); i++){
        if(i%3==0 || i%10==3 || (i/10)%10==3 || (i/100)%10==3 || (i/1000)%10==3 || (i/10000)%10==3){
            cout <<  " " << i;
        }
    }
    cout << endl;
    return 0;
}

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

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

int main() {
  int n, m, X, Y;
  cin >> n >> m >> X >> Y;
  vector<int> x(n), y(m);
  rep(i, n) cin >> x[i];
  rep(i, m) cin >> y[i];
  x.push_back(X);
  y.push_back(Y);
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  string ans;
  if (x.back() >= y.front())
    ans = "War";
  else
    ans = "No War";

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


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

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

  long long cnt[2] = {};
  for (int i = 0; i < 2; i++) {
    long long sum = 0;
    for (int j = 0; j < n; j++) {
      sum += a[j];
      if (sum == 0) {
        if ((i + j) % 2 == 0) sum++;
        else sum--;
        cnt[i]++;
      } else if (sum > 0 && (i + j) % 2 == 1) {
        long long x = sum + 1;
        sum -= x;
        cnt[i] += x;
      } else if (sum < 0 && (i + j) % 2 == 0) {
        long long y = abs(sum) + 1;
        sum += y;
        cnt[i] += y;
      }
    }
  }

  cout << min(cnt[0], cnt[1]) << endl;
}

Measured memory_bytes: 640
import sys


class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0] * n

    def add(self, k, x):
        while k < self.n:
            self.bit[k] += x
            k |= k + 1

    def sum(self, k):
        s = 0
        while k >= 0:
            s += self.bit[k]
            k = (k & (k + 1)) - 1
        return s


input = sys.stdin.readline
MOD = 998244353
N = int(input())
X, Y = [], []
xs, ys = {}, {}
pow2 = [1]
for i in range(N):
    pow2.append((pow2[-1] * 2) % MOD)
for i in range(N):
    x, y = map(int, input().split())
    xs[x] = 0
    ys[y] = 0
    X.append(x)
    Y.append(y)

s = 0
for i in sorted(X):
    xs[i] = s
    s += 1

s = 0
for i in sorted(Y):
    ys[i] = s
    s += 1

for i in range(N):
    X[i] = xs[X[i]]
    Y[i] = ys[Y[i]]

P = [i for i in range(N)]
P = sorted(P, key=lambda k: X[k])


bit1 = BIT(N)
bit2 = BIT(N)

for i in range(N):
    bit2.add(i, 1)

ans = 0
for i in P:
    y = Y[i]
    bit2.add(y, -1)

    A = bit1.sum(y)
    B = bit2.sum(y)
    C = bit1.sum(N - 1) - bit1.sum(y - 1)
    D = bit2.sum(N - 1) - bit2.sum(y - 1)

    ans += pow2[N - 1]
    ans %= MOD
    ans += (pow2[A] - 1) * (pow2[D] - 1) * pow2[B] * pow2[C]
    ans %= MOD
    ans += pow2[A] * pow2[D] * (pow2[B] - 1) * (pow2[C] - 1)
    ans %= MOD
    ans += MOD - ((pow2[A] - 1) * (pow2[D] - 1) * (pow2[B] - 1) * (pow2[C] - 1)) % MOD
    ans %= MOD

    bit1.add(y, 1)

print(ans)



Measured memory_bytes: 119792
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define MOD 998244353LL

int main(){
  int n,m,x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  for(int i = 0; n > i; i++){
    cin >> c[i];
    for(int j = 0; m > j; j++)
	    cin >> a[i][j];
  }
  
  int Min = INT_MAX;
  
  for(int b = 0; 1 << n > b; b++){
    int sum[13] = {}, cs = 0; 
  for(int i = 0; n > i; i++){
    if(!((b >> i) & 1)) continue;
    cs += c[i];
    for(int j = 0; m > j; j++){
      sum[j] += a[i][j];
    }
  }
    bool f = true;
    for(int j = 0; m > j; j++)
  		if(sum[j] < x) f = false;
    if(f) Min = min(Min,cs);
    
  }
  if(Min == INT_MAX) Min = -1;
  cout << Min << endl;
  return 0;
}

Measured memory_bytes: 3196
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	vector<LL> a(32);
	a[1] = 1; a[2] = 2; a[3] = 4;
	FOR(i, 4, 32) {
		a[i] = a[i - 1] + a[i - 2] + a[i - 3];
	}
	while (true) {
		LL n; cin >> n;
		if (n == 0)break;
		LL day = (a[n] + 9) / 10;
		cout << (day + 364) / 365 << endl;
	}
}


Measured memory_bytes: 3044
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(){
    long long int l;
    scanf("%lld",&l);
    l = 3 * l * pow(10,4);
    long long x = l;
    long long y = l;
    long long h = l;
    long long v = 0;
    printf("%.12f",(((x / pow(10,4)) * (y / pow(10,4)) * (h / pow(10,4))) / (pow(3,6))));
    return 0;
}


Measured memory_bytes: 128
using System.Text;
using System.Collections.Generic;
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var q = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        Array.Sort(a);
        getAns(n, q, a);
    }
    static void getAns(int n, int q, int[] a)
    {
        var sb = new StringBuilder();
        var cr = "\n";
        for (int i = 0; i < q; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var L = int.Parse(line[0]);
            var r = int.Parse(line[1]);
            var ansL = LowerBound(a, L);
            var ansr = UpperBound(a, r);
            sb.Append((ansr - ansL).ToString() + cr);
        }
        Console.Write(sb);
    }
    static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
    {
        int low = start;
        int high = end;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (comparer.Compare(arr[mid], value) < 0)
                low = mid + 1;
            else
                high = mid;
        }
        return low;
    }
    static int LowerBound<T>(T[] arr, T value) where T : IComparable
    {
        return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
    }
    static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
    {
        int low = start;
        int high = end;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (comparer.Compare(arr[mid], value) <= 0)
                low = mid + 1;
            else
                high = mid;
        }
        return low;
    }
    static int UpperBound<T>(T[] arr, T value)
    {
        return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default);
    }
}



Measured memory_bytes: 33384
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;

int digit_sum(long n){
    string num;
    num = to_string(n);
    int len, r;
    r = 0;
    len = num.length();
    for(int i=0; i<len; ++i){
        r += num[i] - '0';
    }
    return r;
}
int main(){
    string n;
    int l;
    long m;
    bool b;
    b = true;
    m = 0;
    cin >> n;
    l = n.length();
    for(int i=l-1; i>=0; --i){
        if(i == 0){
            if(!b){
                m += (long)(n[0] - '0' - 1) * (long)(pow(10, l - (i + 1)));
            }
            else {
                m += (long)(n[0] - '0') * (long)(pow(10, l - (i + 1)));
            }
        }
        else {
            if (n[i] != '9'){b = false;}
            m += 9 * (long)(pow(10, l - (i + 1)));
        }
    }
    cout << digit_sum(m) << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int max ;
		if (A < B) {
			max = A;
		}else {
			max = B;
		}
		int min;
		if ((A + B) < N) {
			min = 0;
		}else {
			min = (A + B) - N;
		}
		System.out.println(max +" "+ min);
	}
}


Measured memory_bytes: 21844
#include<stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 1000

int top;
int S[MAX];

int initialize(){
       return top=0;
       }

int isempty(){
       return top==0;
       }

int isfull(){
       return top>=MAX-1;
       }

void push(int n){
       if (isfull()){printf("overflow\n");exit(1);}

       top++;
       S[top]=n;
       }

int pop(){
       if (isempty()){printf("unerflow\n");exit(1);}

       top--;
       return S[top+1];
       }

int main(){
       int i,j,x,y;
       char op[MAX];
       top=0;
       while(scanf("%s",&op) != EOF){
                   if(op[0]=='+'){
                               x=pop();
                               y=pop();
                               push(y+x);
                               }
                   else if(op[0]=='-'){
                               x=pop();
                               y=pop();
                               push(y-x);
                               }
                   else if(op[0]=='*'){
                               x=pop();
                               y=pop();
                               push(y*x);
                               }
                   else {push(atoi(op));}
                   }
          printf("%d\n",pop());
          return 0;
          }




Measured memory_bytes: 2124
N,K=map(int,input().split())
ans=0
kari=[i for i in range(N+1)]
for i in range(K,N+2):
    saidai=(N+N-i+1)*i//2
    saisyou=(i-1)*i//2
    ans+=saidai-saisyou+1

ans%=10**9+7
print(ans)

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

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

    ll ans1 = 0, ans2 = 0, cumsum = 0;
    // 偶数：正、 奇数：負 パターン
    for(int i = 0; i < n; i++) {
        ll cur = cumsum + a[i];
        if (i % 2 == 0) {
            if (cur <= 0) {
                ans1 += 1 - cur;
                cumsum = 1;
            } else {
                cumsum = cur;
            }
        } else {
            if (cur >= 0) {
                ans1 += 1 + cur;
                cumsum = -1;
            } else {
                cumsum = cur;
            }
        }
    }

    cumsum = 0;
    // 偶数：負、 奇数：正 パターン
    for (int i = 0; i < n; i++) {
        ll cur = cumsum + a[i];
        if (i % 2 == 1) {
            if (cur <= 0) {
                ans2 += 1 - cur;
                cumsum = 1;
            } else {
                cumsum = cur;
            }
        } else {
            if (cur >= 0) {
                ans2 += 1 + cur;
                cumsum = -1;
            } else {
                cumsum = cur;
            }
        }
    }

    cout << min(ans1, ans2) << endl;
    return 0;
}


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

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

        int num = Integer.parseInt(a + b);

        int s = (int)Math.sqrt(num);

        if(s * s == num){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  ll n; cin>>n;
  ll m = 3*n;
  vector<ll> a(m);
  rep(i, m) cin>>a[i];

  vector<ll> sl(m, -inf);
  vector<ll> sr(m, inf);
  {
    priority_queue<int, vector<int>, greater<int>> q;
    ll sum = 0;
    for (int i=0; i<m; i++) {
      q.push(a[i]);
      sum += a[i];
      if ((int)(q.size()) > n) {
        ll t = q.top(); q.pop();
        sum -= t;
      }
      if ((int)(q.size()) == n) {
        sl[i] = sum;
      }
    }
  }
  {
    priority_queue<int, vector<int>, less<int>> q;
    ll sum = 0;
    for (int i=m-1; i>=0; i--) {
      q.push(a[i]);
      sum += a[i];
      if ((int)(q.size()) > n) {
        ll t = q.top(); q.pop();
        sum -= t;
      }
      if ((int)(q.size()) == n) {
        sr[i] = sum;
      }
    }
  }
  ll ans = -inf;
  for (int i=n-1; i<2*n; i++) {
    ans = max(ans, sl[i]-sr[i+1]);
  }
  cout << ans << endl;

  return 0;
}


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

int n;
int res;

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int a; scanf("%d", &a);
		res += a - 1;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 256
using System;

class E
{
	static void Main()
	{
		var n = long.Parse(Console.ReadLine());
		if (n % 2 == 1) { Console.WriteLine(0); return; }

		long r = 0, t = 2;
		while (t < n) r += n / (t *= 5);
		Console.WriteLine(r);
	}
}


Measured memory_bytes: 13140
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

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

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


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

s = 0

for i in range(M):
    uf = UnionFind(N)
    for j in range(M):
        if j != i:
            uf.union(ab[j][0] - 1, ab[j][1] - 1)
    s += (len(uf.roots()) != 1)

print(s)


Measured memory_bytes: 3064
def main(input_str):
    nums = list(map(int, input_str.split()))

    count = 0
    for num_1 in range(nums[0]+1):
        for num_2 in range(nums[0]+1):
            if 0 <= nums[1]-(num_1+num_2) <= nums[0]:
                count += 1

    return count


if __name__ == "__main__":
    input_str = input()
    print(main(input_str))


Measured memory_bytes: 2940
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2 vector<vec>
#define vecll2 vector<vecll>
#define vec3 vector<vec2d>
#define vecll3 vector<vecll2d>
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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;}
template<class T> inline void print(vector<T> v){for(T e:v)cout<<e<<" ";cout<<endl;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
void print(vector<vec> v){for(auto e:v){for(auto ee:e)cout<<ee<<" ";cout<<endl;}}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}

const int N=1e5+10;
ll a[N<<4];
int sum[11];
main(){
    ios
    int h,w,n;scanf("%d%d%d",&h,&w,&n);
    h-=2,w-=2;
    int x;int y;
    int cnt=0;
    ll m=(ll)h*w;
    rep(iii,n){
        scanf("%d%d",&x,&y);
        rep(i,3)if( x-i>=1 && x-i<=h){
            rep(j,3)if(y-j>=1 && y-j<=w){
            a[cnt++]=((ll)(x-i)<<32)+(y-j);
            }
        }
    }
    sort(a,a+cnt);
    ll t=1;
    rep(i,cnt){
        if(a[i]==a[i+1])t++;
        else sum[t]++,t=1,m--;
    }
    cout<<m<<" ";
    rep2(i,1,9)cout<<sum[i]<<" ";
}



Measured memory_bytes: 8448
#include<stdio.h>

int main(){
	int A, B, C;
	char line[16];

	fgets(line, 16, stdin);
	sscanf(line, "%d %d %d", &A, &B, &C);

	if((C >= A) && (C <= B))
		puts("Yes");
	else
		puts("No");

	return 0;
}



Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
	int num[3];
	int i,j,change;
	int sum = 0;

	for (i = 0; i < 3; i++)
	{
		scanf("%d", &num[i]);
	}

	for (i = 0; i < 2; i++)
	{
		for (j = 1; j < 3; j++)
		{
			if (num[i] >num[j])
			{
				change = num[j];
				num[j] = num[i];
				num[i] = change;
			}
		}
	}

	for (i = 0; i < 2; i++)
	{
		sum = sum + num[i];
	}
	printf("%d\n", sum);
	return 0;
}

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(),a.end());
    int cnt = 1;
    for(int i = 0; i < n - 1; i++){
        if(a[i] < a[i+1]) cnt++;
    }
    cout << cnt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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() {
  ll n;
  cin >> n;
  ll a[n],b[n];
  FOR(i,0,n-1) {
    cin >> a[i];
    b[n-1-i] = a[i];
  }

  ll ans = 0;
  ll ans2 = 0;

  FOR(i,0,n-1){
    if(i==n-1) {
      ans += a[i]/2;
      continue;
    }

    ans += a[i]/2;
    if(a[i]%2==1 && a[i+1]>0){
      ++ans;
      --a[i+1];
    }
  }

  FOR(i,0,n-1){
    if(i==n-1) {
      ans2 += b[i]/2;
      continue;
    }

    ans2 += b[i]/2;
    if(b[i]%2==1 && b[i+1]>0){
      ++ans2;
      --b[i+1];
    }
  }

  // cout << ans << " " << ans2 << endl;

  cout << max(ans,ans2) << endl;



  
}



Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int a, b;
    int ans;
    
    scanf("%d%d", &a, &b);
    
    if (b>=a) {
        ans=a;
    } else {
        ans=a-1;
    }
    
    printf("%d", ans);
    
    return 0;
}



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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define SORT(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> P;

int main(){
  string s ;
  cin >>s;
  if((s.at(0)!=s.at(1))&&(s.at(1)!=s.at(2))&&(s.at(0)!=s.at(2))){
	cout<<"Yes"<<endl;
  }
  else{
	cout<<"No"<<endl;
  }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	LLi a, ans=0;
	string b;

	cin>> a >> b;

	LLi tmp=(LLi)(b[0]-'0');
	ans+=(LLi)(a*tmp)*100;

	if(b.size()>2){
		tmp=(LLi)(b[2]-'0');
		ans+=(LLi)(a*tmp)*10;
	}

	if(b.size()>3){
		tmp=(LLi)(b[3]-'0');
		ans+=(LLi)(a*tmp);
	}

	cout<< ans/100 <<endl;
 
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>
#include <math.h>

using namespace std;
#define li long long int
#define FOR(i, a, b) for (int i = a ; i < b ; ++i)
#define REP(i, n) for (int i = 0 ; i < n ; ++i)

li gcd(li a,li b) {
    return a % b == 0 ? b : gcd(b, a % b);
}

int main(void) {
    li N;
    cin >> N;
    li p[N];

    li max = 0;
    li index = 0;
    FOR(i, 0, N) {
        cin >> p[i];
        if (p[i] > max) {
            max = p[i];
            index = i;
        }
    }

    p[index] = max / 2;
    li sum = 0;
    FOR(i, 0, N) {
        sum += p[i];
    } 

    cout << sum;

    return 0;
}

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

int main(){
    string s;
    cin>>s;
    int n=s.size()-1;
    vector<int>a(4);
    for(int i=0;i<4;++i)
        a.at(i)=s.at(i)-'0';
    vector<char> op(3);
    for(int i=0,sum;i<(1<<n);++i){
        sum=a.at(0);
        for(int j=0;j<3;++j){
            if(i&(1<<j)){
                sum+=a.at(j+1);
                op.at(j)='+';
            } else {
                sum-=a.at(j+1);
                op.at(j)='-';
            }
        }
        if(sum==7){
            for(int i=0;i<3;++i){
                cout<<a.at(i)<<op.at(i);
            }
            cout<<a.at(3)<<"=7\n"s;
            return 0;
        }
    }
}

Measured memory_bytes: 256
A,B = map(int,input().split())
count = 0
for i in range(A,B + 1):
    if str(i)[0] == str(i)[1] == str(i)[-1] == str(i)[-2] :
        count += 1
    elif str(i)[0] == str(i)[-1] and str(i)[1] == str(i)[-2]:
        count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(n); ++i)
#define REPR(i,n,m) for (int i=(n); i>=(m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLD = vector<PLD>;

const int INF = numeric_limits<int>::max();

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

    LL n, a, b; cin >> n >> a >> b;

    if (a>b) { 
        cout << 0 << endl; 
    } else if (n==1&&a!=b) {
        cout << 0 << endl;
    } else if (n==1&&a==b) {
        cout << 1 << endl;
    } else {
        cout << (b-a)*(n-2) + 1 << endl;
    }

    return 0;
}


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

public class Main {
    static class pair{
        double f,s;
        pair(double f,double s){
            this.f=f;
            this.s=s;
        }
    }
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        int B[]=new int[n-1];
        for (int i = 0; i < n-1; ++i)
            B[i]=in.nextInt();

        long  ans = (B[0] + B[n-2]);

        for (int i = 1; i < n-1; ++i)
        {
            ans += Math.min(B[i],B[i-1]);
        }
        System.out.println(ans);
        in.close();
    }
}


Measured memory_bytes: 21844
n, t = map(int, input().split())
a = list(map(int, input().split()))
maxa = a.pop()
max_rizaya, count = 0, 0
while a:
    ca = a.pop()
    rizaya = maxa - ca
    if rizaya > max_rizaya:
        max_rizaya = rizaya
        count = 1
    elif rizaya == max_rizaya:
        count += 1
    maxa = max(maxa, ca)
print(count)


Measured memory_bytes: 15020
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
#include<map>
#include<vector>
#define int long long
using namespace std;
int test[51];
signed main() {
    double n, a; int b = 0, c = 0;;
    while (cin >> n >> a) {
        if (n < 35.5) { b = 7; }
        else if (n < 37.5) { b = 6; }
        else if (n < 40) { b = 5; }
        else if (n < 43) { b = 4; }
        else if (n < 50) { b = 3; }
        else if (n < 55) { b = 2; }
        else if (n < 70) { b = 1; }
        else { cout << "NA" << endl; continue; }
        if (a < 71) { c = 7; }
        else if (a < 77) { c = 6; }
        else if (a < 83) { c = 5; }
        else if (a < 89) { c = 4; }
        else if (a < 105) { c = 3; }
        else if (a < 116) { c = 2; }
        else if (a < 148) { c = 1; }
        else { cout << "NA" << endl; continue; }
        if (min(b, c) == 7) { cout << "AAA" << endl; }
        if (min(b, c) == 6) { cout << "AA" << endl; }
        if (min(b, c) == 5) { cout << "A" << endl; }
        if (min(b, c) == 4) { cout << "B" << endl; }
        if (min(b, c) == 3) { cout << "C" << endl; }
        if (min(b, c) == 2) { cout << "D" << endl; }
        if (min(b, c) == 1) { cout << "E" << endl; }
    }
}


Measured memory_bytes: 3156
s = input()
t = input()

len_s = len(s)
len_t = len(t)

min_cnt = len_t

for i in range(len_s - len_t + 1):
  tmp_cnt = len_t
  tmp = s[i:i+len_t]
  for ii in range(len_t):
    if tmp[ii] == t[ii]:
      tmp_cnt -= 1

  if min_cnt > tmp_cnt:
    min_cnt = tmp_cnt

print(min_cnt)

Measured memory_bytes: 9064