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

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    char[][] c = new char[2][3];

    for (int i = 0; i < 2; i++) {
      String s = sc.next();
      for (int j = 0; j < 3; j++) {
        c[i][j] = s.charAt(j);
      }
    }

    if ((c[0][0] == c[1][2]) && (c[0][1] == c[1][1]) && (c[0][2] == c[1][0])) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }

  }
}

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

using ll=long long;
const ll MOD=1000000007;

int main() {
  ll n;
  cin >> n;
  ll k=sqrt(n),s=0;
  //cout << k << endl;
  for(int i=k;i>0;i--){
    if(n%i==0){
      s=i;
      break;
    }
  }
  //cout << s << endl;
  ll t=n/s;
  ll ans;
  for(int i=0;i<11;i++){
    if(pow(10,i)<=t&&t<pow(10,i+1)){
      ans=i+1;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
"use strict";
function main(input) {
    let line = input.split(/\r?\n/g);
    let arr = line[0].split(" ");
    const a = parseInt(arr[0]), b = parseInt(arr[1]);
    let an = "";
    let bn = "";
    for (let i = 0; i < b; i++)
        an += a;
    for (let i = 0; i < a; i++)
        bn += b
    console.log(an < bn ? an : bn)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

int main() {
  int N, A, x, y;
  x=y=0;//2で割れる回数
  cin >> N;
  for(int i=0; i<N; i++){
    cin >> A;
    for(int j=0; j-1<x; j++){
     if(A%2 == 0){
       A/=2;
       x++;
     }
     else{
       if(i==0 || y>=x){
         y=x;
       }
       x=0;
     }
    }
  }
  cout << y << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(int i = (a); i<(b); ++i)
#define rep(i, n) for (int i=0; i<(n); ++i)
#define out(x) cout << x << endl

int main() {
    ll N;
    cin >> N;
    unordered_map<string, int> mp;
    vector<string> max_words;
    int max_count = 0;
    rep(i, N) {
        string s;
        cin >> s;
        mp[s]++;
        if (max_count < mp[s]) {
            max_count++;
            max_words.clear();
            max_words.push_back(s);
            continue;
        } else if (max_count == mp[s]) {
            max_words.push_back(s);
        }
    }
    sort(max_words.begin(), max_words.end());
    rep(i, max_words.size()) {
        out(max_words.at(i));
    }
}


Measured memory_bytes: 25656
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

#define MAX_N 16

struct P {
    int t, stage;

    bool operator >(const P& p) const {
        return t > p.t;
    }
};

int main()
{
    int n;
    int t[MAX_N][MAX_N+1];
    int mintime[1<<16];
    while (cin >> n, n) {
        fill_n((int *)mintime, 1<<16, INF);
        rep(i, n) {
            rep(j, n+1) {
                int input;
                cin >> input;
                t[i][j] = input;
            }
        }
        int goal = (1 << n) - 1;
        priority_queue<P, vector<P>, greater<P> > q;
        q.push((P){0, 0});
        while (!q.empty()) {
            P p = q.top(); q.pop();
            // goal
            if (p.stage == goal) {
                cout << p.t << endl;
                break;
            }
            // push
            rep(i, n) {
                if (!(p.stage&(1<<i))) {
                    int nstage = p.stage|(1<<i);
                    if(mintime[nstage] > p.t+ t[i][0]) {
                        q.push((P){p.t+t[i][0], nstage});
                        mintime[nstage] = p.t+t[i][0];
                    }
                    REP(j, 1, n+1) {
                        if(p.stage&(1<<(j-1)) && mintime[nstage] > p.t+t[i][j]) {
                            q.push((P){p.t+t[i][j], nstage});
                            mintime[nstage] = p.t+t[i][j];
                        }
                    }
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4496
def dijkstra(g,st):
    from heapq import heappush, heappop, heapify
    inf=10**18
    dist=[inf for i in range(len(g))]
    visited=[False for i in range(len(g))]
    dist[st]=0
    que=[]
    heappush(que,(0,st))
    while que:
        c,v=heappop(que)
        if visited[v]:
            continue
        visited[v]=True
        for x in g[v]:
            tmp=x[0]+c
            if tmp<dist[x[1]] and not visited[x[1]]:
                dist[x[1]]=tmp
                heappush(que,(tmp,x[1]))
    return dist

h,w=map(int,input().split())
field=[[]for i in range(h)]
num=0
st=-1
for i in range(h):
    s=input()
    for j in range(w):
        field[i].append((s[j],num))
        if s[j]=='.' and st==-1:
            st=num
        num+=1
dx=[1,0,-1,0]
dy=[0,1,0,-1]

g=[[]for i in range(h*w)]
for i in range(h):
    for j in range(w):
        if field[i][j][0]!='.':
            continue
        for x,y in zip(dx,dy):
            if 0<=i+x<h and 0<=j+y<w and field[i+x][j+y][0]!='#':
                g[field[i][j][1]].append((1,field[i+x][j+y][1]))

mxx=0
for i in range(h):
    for j in range(w):
        if field[i][j][0]=='#':
            continue
        for ans in dijkstra(g,field[i][j][1]):
            if ans!=10**18:
                mxx=max(mxx,ans)
print(mxx)

Measured memory_bytes: 3316
package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func NextFloat() float64 {
  n, _ := strconv.ParseFloat(NextLine(), 64)
  return n
}
func NextFloatVec() []float64 {
  L := strings.Split(NextLine(), " ")
  N := make([]float64, len(L))
  for i := range N {
    N[i], _ = strconv.ParseFloat(L[i], 64)
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}


func Solve() {
  NMQ := NextIntVec()
  N, M, Q := NMQ[0], NMQ[1], NMQ[2]
  G := make([][]int, N)
  for i := range G {
    G[i] = make([]int, M)
    S := NextLine()
    for j, s := range S {
      if s == '1' { G[i][j] = 1 }
    }
  }
  V := make([][]int, N + 1)
  for i := range V {
    V[i] = make([]int, M + 1)
  }
  for i := 0; i < N; i++ {
    for j := 0; j < M; j++ {
      V[i + 1][j + 1] += V[i + 1][j] + G[i][j]
    }
  }
  for j := 0; j < M; j++ {
    for i := 0; i < N; i++ {
      V[i + 1][j + 1] += V[i][j + 1]
    }
  }
  EV := make([][]int, N + 1)
  EH := make([][]int, N + 1)
  for i := range EV {
    EV[i] = make([]int, M + 1)
    EH[i] = make([]int, M + 1)
  }
  for i := 0; i < N; i++ {
    for j := 0; j < M; j++ {
      if 0 < i && G[i][j] == 1 && G[i - 1][j] == 1 { EV[i + 1][j + 1]++ }
      if 0 < j && G[i][j] == 1 && G[i][j - 1] == 1 { EH[i + 1][j + 1]++ }
    }
  }
  for i := 0; i < N; i++ {
    for j := 0; j < M; j++ {
      EV[i + 1][j + 1] += EV[i + 1][j]
      EH[i + 1][j + 1] += EH[i + 1][j]
    }
  }
  for j := 0; j < M; j++ {
    for i := 0; i < N; i++ {
      EV[i + 1][j + 1] += EV[i][j + 1]
      EH[i + 1][j + 1] += EH[i][j + 1]
    }
  }
  for i := 0; i < Q; i++ {
    XY := NextIntVec()
    x1, y1, x2, y2 := XY[0], XY[1], XY[2], XY[3]
    v := V[x1 - 1][y1 - 1] + V[x2][y2] - V[x1 - 1][y2] - V[x2][y1 - 1]
    e1 := EV[x1][y1 - 1] + EV[x2][y2] - EV[x1][y2] - EV[x2][y1 - 1]
    e2 := EH[x1 - 1][y1] + EH[x2][y2] - EH[x1 - 1][y2] - EH[x2][y1]
    Write(v - e1 - e2)
  }
  return
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 168064
#include <iostream>

using namespace std;

int main()
{
   string s;
   cin>>s;
   string ar[7]={ "SUN", "MON" , "TUE" ,"WED" , "THU", "FRI" , "SAT"};
   for(int i=0;i<7;i++)
   {
       if(s==ar[i])
       {
           cout<<7-i<<endl;
       }
   }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int cmp(const void *a,const void *b){
  return *(int*)a-*(int*)b;}
int main(){
  int x;
  scanf("%d",&x);
  int a,b;
  a=x/100;
  b=x%100;
  if(x>1999)
    printf("1\n");
  else{
    if(0<=b&&b<5*a+1)
      printf("1\n");
    else
      printf("0\n");
  }
  return 0;}


Measured memory_bytes: 128
#include <stdio.h>
 int main(){
   int a;
   scanf("%d",&a);
   if(a>=400&&a<600){
     printf("8\n");
   }else if(a>=600&&a<800){
     printf("7\n");
   }else if(a>=800&&a<1000){
     printf("6\n");
   }else if(a>=1000&&a<1200){
     printf("5\n");
   }else if(a>=1200&&a<1400){
     printf("4\n");
   }else if(a>=1400&&a<1600){
     printf("3\n");
   }else if(a>=1600&&a<1800){
     printf("2\n");
   }else if(a>=1800&&a<2000){
     printf("1\n");
   }
return 0;
            }

Measured memory_bytes: 1644
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(int argc,char** argv) {
	int n,t = 1;
	cin >> n;
	while(n >= t * 2) t = t * 2;
	cout << t;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

bool are_same(string &s) {
	for (int i = 1; i < (int) s.size(); ++i) {
		if (s[i] != s[i - 1]) {
			return false;
		}
	}

	return true;
}

int get_operations_number(string s, char c) {
	int op = 0;
	while (!are_same(s)) {
		string t = "";
		for (int i = 0; i < (int) s.size() - 1; ++i) {
			if (s[i + 1] == c) {
				t.push_back(c);
			} else {
				t.push_back(s[i]);
			}
		}

		++op;

		s = t;
	}

	return op;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	string s;
	cin >> s;

	set<char> characters;
	for (int i = 0; i < (int) s.size(); ++i) {
		characters.insert(s[i]);
	}

	int min_operations = INT_MAX;
	for (auto it = characters.begin(); it != characters.end(); ++it) {
		min_operations = min(min_operations, get_operations_number(s, *it));
	}

	cout << min_operations << "\n";

	return 0;

}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrepa(i,a,n) for(int i=(n)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main(){
   
    ll n,x;
    cin >> n >> x;
    ll ans=n;

    ll a=n-x,b=x;
    if(a<b)swap(a,b);

    ll tmp;
    while(a%b != 0){
        tmp = a/b;
        ans += 2*b*tmp;
        a -= b*tmp;
        swap(a,b);
    }
    ans += b*((a/b)*2-1);

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

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

class DisjointSet {
public:
  vector<int> p, rank, size;
  DisjointSet(int n) {
    p.assign(n, 0);
    rank.assign(n, 0);
    size.assign(n, 0);
    for (int i = 0; i < n; i++) {
      make_set(i);
    }
  }

  void make_set(int x) {
    p[x] = x;
    rank[x] = 0;
    size[x] = 1;
  }

  int find_set(int x) {
    if (x != p[x]) {
      p[x] = find_set(p[x]);
    }
    return p[x];
  }

  bool same(int x, int y) {
    return find_set(x) == find_set(y);;
  }

  int union_size(int x) {
    if (x != p[x]) {
      size[x] = union_size(find_set(x));
    }
    return size[x];
  }

  void link(int x, int y) {
    if(rank[x]  > rank[y]) {
        p[y] = x;
        size[x] = size[x] + size[y];
    }else if(rank[x] < rank[y]){
        p[x] = y;
        size[y] = size[x] + size[y];
    }else if(x != y) {
      p[y] = x;
      rank[x]++;
      size[x] = size[x] + size[y];
    }
  }

  void unite(int x, int y) {
      link(find_set(x), find_set(y));
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  char c[H][W];
  int n = H * W;
  int d[n];
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < W; j++) {
      c[i][j] = s[j];
      int idx = i * W + j;
      if (c[i][j] == '#') d[idx] = 0;
      else d[idx] = 1;
    }
  }
  DisjointSet ds(n);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (i + 1 < H && c[i][j] != c[i + 1][j]) {
        ds.unite(W * i + j, W * (i + 1) + j);
      }
      if (j + 1 < W && c[i][j] != c[i][j + 1]) {
        ds.unite(W * i + j, W * i + j + 1);
      }
    }
  }
  ll ans = 0;
  ll b[n]{};
  ll w[n]{};
  for (int i = 0; i < n; i++) {
    if (d[i] == 0) b[ds.find_set(i)]++;
    else  w[ds.find_set(i)]++;
  }
  for (int i = 0; i < n; i++) {
    ans += b[i] * w[i];
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 5376
module Factwithmod
  implicit none
  integer(16),allocatable,dimension(:)::Kaijo
  contains
subroutine initiationFactorial(maxnum,mo)
  implicit none
  integer(16)::maxnum
  integer(16)::mo
  integer(16)::i

  allocate(Kaijo(0:maxnum))
  Kaijo(0)=1
  do i=1,maxnum
    Kaijo(i)=mod(Kaijo(i-1)*i,mo)
  end do
end subroutine

function combination(n,k,l)
implicit none
integer(16),intent(in)::n,k,l
integer combination

combination=mod(Kaijo(N)*inv(Kaijo(K),l)*inv(Kaijo(N-K),l),l)

end function

function inv(K,L)
integer(16),intent(in)::k,l
integer(16) l2,y
integer(16) inv
inv=1
l2=l-2
y=k
do
  if(mod(l2,2)==1)inv=mod(inv*y,l)
  y=mod(y*y,l)
  l2=l2/2
  if(l2==0)exit
end do
end function

function permutation(n,k,mo)
implicit none
  integer(16)::n,k
  integer(16)::mo,permutation
  permutation=mod(Kaijo(N)*inv(Kaijo(N-K),mo),mo)
end function
end module

program abc145d
    use Factwithmod
    integer(16)::X,Y
    integer(16)::mo=10**9+7
    read*,X,Y
    if(mod(X+Y,3)/=0)then
        print"(I0)",0
        stop
    endif
    if(2*Y-X<0)then
        print"(I0)",0
        stop
    endif
    if(2*x-Y<0)then
        print"(I0)",0
        stop
    endif
    call initiationFactorial(X+Y,mo)
    print"(I0)",combination((X+Y)/3,(2*Y-X)/3,mo)
contains
end

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

using namespace std;
const int N = 1e3 + 3;
char s[N];
int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
#endif
	int n;
	double sum = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		int a;
		scanf("%d", &a);
		sum += 1.0 / a;
	}
	printf("%.9lf\n", 1.0 / sum);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll a[200005];

int main(void){
	scanf("%d",&n);
	ll xsum=0;
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
		xsum^=a[i];
	}
	for(int i=0;i<n;i++){
		printf("%lld%c",xsum^a[i],i+1==n?'\n':' ');
	}
	return 0;
}


Measured memory_bytes: 5384
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
int h, w, k, v[5] = {-1, 0, 1, 0, -1};
string s[800];
bool z[800][800];
queue<pii> q, q2;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w >> k;
  FOR(i, 0, h) cin >> s[i];
  int ans = iinf;
  FOR(i, 0, h)FOR(j, 0, w){
    if(s[i][j] == 'S'){
      q.push(mp(i, j));
      z[i][j] = true;
      FOR(l, 0, k+1){
        while(!q.empty()){
          pii t = q.front();
          q.pop();
          mins(ans, t.fi);
          mins(ans, t.se);
          mins(ans, h-1-t.fi);
          mins(ans, w-1-t.se);
          FOR(m, 0, 4){
            int x = t.fi+v[m], y = t.se+v[m+1];
            if(0<=x && x<h && 0<=y && y<w && s[x][y] == '.' && !z[x][y]){
              z[x][y] = true;
              q2.push(mp(x, y));
            }
          }
        }
        swap(q, q2);
      }
      if(ans == 0){
        cout << 1 << endl;
      }else{
        cout << (ans-1)/k+2 << endl;
      }
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>

int main()
{
  
  char s[50];
  scanf("%s",s);
  
  if((s[2]==s[3]) && (s[4]==s[5]))
  {
  printf("Yes");
  }
  else
  {
    printf("No");
  }
  
  
 
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
//i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;

int main(int argc, char **argv) {
    string s, t;
    cin >> s >> t;
    vector<vector<i64>> mp(s.size()+1, vector<i64>(26, -1));
    //cout << s.size() <<" " << t.size() << endl;

    vector<set<i64>> v(26);

    for (i64 i=0; i<s.size(); ++i) {
        char c = s[i]-'a';
        v[c].insert(i+1);
    }

    for (i64 i=0; i<=s.size(); ++i) {
        for (char c2=0; c2<26; ++c2) {
            if (v[c2].empty()) {
                mp[i][c2] = -1;
            }
            auto it = v[c2].upper_bound(i);
            if (it == v[c2].end()) {
                mp[i][c2] = mp[0][c2];
            } else {
                mp[i][c2] = *it;
            }
        }
    }
    /*
    for (auto m: mp) {
        for (auto m2 :m) {
            cout << m2 << " ";
        }
        cout <<endl;
    }
    */
    i64 ans = 0;
    i64 curr = 0;
    for (char c : t) {
        //cout << curr << " " << ans <<endl;
        i64 next = mp[curr][c-'a'];
        if (next == -1) {
            cout << -1 << endl;
            return 0;
        }
        if (next <= curr) ++ans;
        curr = next;
    }

    cout << (ans*s.size()+curr) << endl;
    return 0;
}


Measured memory_bytes: 32280
#include<iostream>

using namespace std;

int main()
{ char a,b,c,d; cin >> a >> b >> c >> d;
  int A,B,C,D; A = a - '0'; B = b - '0'; C = c - '0'; D = d - '0';
 
 if( A + B + C + D == 7){cout << A << '+' << B << '+' << C << '+' << D << '=' << 7;}
 else if(A + B + C - D == 7){cout << A << '+' << B << '+' << C << '-' << D << '=' << 7;}
 else if(A + B - C + D == 7){cout << A << '+' << B << '-' << C << '+' << D << '=' << 7;}
 else if(A - B + C + D == 7){cout << A << '-' << B << '+' << C << '+' << D << '=' << 7;}
 else if(A + B - C - D == 7){cout << A << '+' << B << '-' << C << '-' << D << '=' << 7;}
 else if(A - B + C - D == 7){cout << A << '-' << B << '+' << C << '-' << D << '=' << 7;}
 else if(A - B - C + D == 7){cout << A << '-' << B << '-' << C << '+' << D << '=' << 7;}
 else if(A - B - C - D == 7){cout << A << '-' << B << '-' << C << '-' << D << '=' << 7;}
 
 return 0;
}


Measured memory_bytes: 256
import java.util.*;
    public class Main {
    	public static void main(String[] args){
    		Scanner sc = new Scanner(System.in);
    		// 整数の入力
    		int a = sc.nextInt();
    		int b = sc.nextInt();
    		int x = sc.nextInt();
    		// 出力
    		if(a <= x && x <= (a + b)){
    		    System.out.println("YES");
    		}else{
    		    System.out.println("NO");
    		}
    	}
    }


Measured memory_bytes: 23764
a, b, c ,d = map(int, input().split())

flag = 0

if((a-b)**2<=d**2):
    flag += 1

if((b-c)**2<=d**2):
    flag += 1

if((c-a)**2<=d**2):
    flag += 2

if(flag>=2):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
from collections import Counter
from itertools import product

N, W = map(int,input().split())
w2vl = {}
lw = []

for i in range(N):
    w, v = map(int, input().split())
    lw.append(w)
    if w2vl.get(w, None) is None:
        w2vl[w] = []
    w2vl[w].append(v)
    w2vl[w] = sorted(w2vl[w],reverse=True)

ct = Counter(lw)

args = []
ws = []
for w in range(lw[0], lw[0]+4):
    if ct[w] == 0: continue
    args.append(range(ct[w]+1))
    ws.append(w)

a = 0
for i in product(*args):
    w = sum(map(lambda x: x[0] * x[1] ,zip(i,ws)))
    if 1 > w or w > W: continue
    v = sum([sum(w2vl[k][:j]) for j,k in zip(i,ws)])
    if a < v:
        a = v

print(a)

Measured memory_bytes: 3700
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <list>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

const double PI  = 3.141592653589793238463;
const int INF = 1000000007;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

int match(int i, const string& s){
    const vector<string> ts = {"dreameraser", "dreamerase", "dreamer", "dream", "eraser", "erase"};
    for(auto t: ts){
        int n = t.size();
        if(s.substr(i, n) == t){
            return i + n;
        }
    }
    return i;
}


bool solve_(const string& s){
    int i = 0;
    while(true){
        if(i == s.size()){
            return true;
        }
        int j = match(i, s);
        if(i == j){
            break;
        }else{
            i = j;
        }
    }
    return false;
}

string solve(string& s){
    if(solve_(s)){
        return "YES";
    }else{
        return "NO";
    }
}

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    cout << solve(s) << endl;

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

signed main() {
	int a, b, c; cin >> a >> b >> c;
	puts(b - a == c - b ? "YES" : "NO");
}

Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector.Unboxed as VU

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [a, b, m] <- getIntList
    as <- VU.fromList <$> getIntList
    bs <- VU.fromList <$> getIntList
    ds <- replicateM m $ do
        [x, y, c] <- getIntList
        return $ (as VU.! (x - 1)) + (bs VU.! (y - 1)) - c
    print $ min ((VU.minimum as) + (VU.minimum bs)) (minimum ds)

Measured memory_bytes: 60156
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

ll modpow(ll a, ll n){
    if(n == 1)return a;
    if(n % 2 == 1) return (a * modpow(a, n-1)) % MOD;
    ll t = modpow(a, n/2);
    return (t * t) % MOD;
}

ll ncr(ll n, ll r){
    ll x = 1, y = 1;
    rep(i, r){
        x *= n-i;
        y *= i+1;
        x %= MOD;
        y %= MOD;
    }
    y = modpow(y, MOD-2);
    return x*y % MOD;
}

int main()
{
    ll n, a, b; cin >> n >> a >> b;
    ll ans = modpow(2, n)-1;
    ans += MOD-ncr(n, a);
    ans += MOD-ncr(n, b);
    ans %= MOD;
    cout << ans << endl;
    system("pause");
}



Measured memory_bytes: 504
#include <iostream>

using namespace std;

int num_comp = 0;
const int MAX = 500000;
//int L[MAX/2 + 2];
//int R[MAX/2 + 2];
const int SENTINEL = 2000000000;


// Merge
void Merge(int A[], int left, int mid, int right)
{
	int n1 = mid - left;
	int n2 = right - mid;
  int L[n1+1];
  int R[n2+1];
  
	for (int i = 0; i < n1; i++)
		L[i] = A[left + i];
	for (int i = 0; i < n2; i++)
		R[i] = A[mid + i];
	L[n1] = SENTINEL;
	R[n2] = SENTINEL;

	int i = 0;
	int j = 0;
	for (int k = left; k < right; k++) {
		num_comp++;
		if (L[i] <= R[j]) {
			A[k] = L[i];
			i++;
		}
		else {
			A[k] = R[j];
			j++;
		}
	}
}

// Merge sort
void Mergesort(int A[], int left, int right)
{
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		Mergesort(A, left, mid);
		Mergesort(A, mid, right);
		Merge(A, left, mid, right);
	}

}

// MAIN FUNCTION
int main(int argc, char** argv)
{
	// Input
	int A[MAX];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> A[i];

	// Merge sort
	Mergesort(A, 0, n);

	// Print all elements
	for (int i = 0; i < n; i++) {
		if (i)
			cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << num_comp << endl;

	return 0;
}



Measured memory_bytes: 6888
#include "bits/stdc++.h"
using namespace std;

long long a,b,c,k,ans;

int main()
{
	cin>>a>>b>>c>>k;

	ans+=min(a,k);
	k-=min(a,k);
	ans+=0*min(b,k);
	k-=min(b,k);
	ans+=-1*min(c,k);
	cout<<ans;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int  k;
ll ans;
int main()
{

cin>>k;
for(int a=1;a<=k;a++)
   for(int b=1;b<=k;b++)
        for(int c=1;c<=k;c++)
{
ans+=__gcd(__gcd(a,b),c);	
}
cout<<ans;
return 0;

}

Measured memory_bytes: 3612
#include <iostream>
#include<string>
using namespace std;
int main(void){
    //受け取り
    string num;
    cin>>num;
    //数字を数える
    long long N=num.size();
    int S[N];
    //int型の数列にねじこむ
    for (long long i = 0; i < N; ++i)
    {
        S[i]=(int)(num[i]-'0');
    }
    //どっちかが先頭を0にするパターンでどっちかが1にするパターン
    long long count1=0;
    long long count2=0;
    for (long long i = 0; i < N; i++)
    {
        if (i%2==0)
        {
            if (S[i]==0)
            {
                count1++;
            }else
            {
                count2++;
            }
            
            
        }else
        {
            if (S[i]==1)
            {
                count1++;
            }else
            {
                count2++;
            }   
        }
    }
    //小さい方をcoutで吐き出す
    if (count1>count2)
    {
        count1=count2;
    }
    cout<<count1<<endl;
    return 0;
}


Measured memory_bytes: 896
#include <string>
#include <vector>
#include <iostream>

using namespace std;

string Affine(string S)
{
	vector<int> F(26);

	for (int i = 0; i < 26; i++) // alpha
	{
		for (int j = 0; j < 26; j++) // beta
		{
			for (int k = 0; k < 26; k++) // gamma
			{
				F[k] = (i * k + j) % 26;
			}
			
			string T = S;

			for (int k = 0; k < S.size(); k++)
			{
				if (islower(S[k]))
				{
					T[k] = F[S[k] - 97] + 97;
				}
				else
				{
					T[k] = S[k];
				}
			}

			if (T.find("this") != string::npos || T.find("that") != string::npos)
			{
				return T;
			}
		}
	}

	return "";
}

int main()
{
	int n; string S;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		S = "";

		while (S == "")
		{
			getline(cin, S);
		}

		cout << Affine(S) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3128
using System;
using System.Collections.Generic;
using System.Linq;
class TEST
{
    public static void Main()
    {
        string[] value1 = Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

        int num = int.Parse(value1[0]);
        int hissatu = int.Parse(value1[1]);
        long attackcount = 0;

        List<long> hps = new List<long>();
        hps.AddRange(StringToLongArray(Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)));
        hps.Sort();
  //      hps.Reverse();

        while (hps.Count > 0)
        {
            if (hissatu > 0)
            {
                hps.RemoveAt(hps.Count-1);
                hissatu--;
                continue;
            }

            attackcount += hps[hps.Count-1];
            hps.RemoveAt(hps.Count-1);
        }

        Console.WriteLine(attackcount);
       //   Console.ReadLine();
    }

    static long[] StringToLongArray(string[] arr)
    {
        long[] temp = new long[arr.Length];

        for (int i = 0; i < temp.Length; i++)
        {
            temp[i] = long.Parse(arr[i]);
        }

        return temp;
    }

}

Measured memory_bytes: 50876
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<>();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
		    int type = sc.nextInt();
		    if (type == 0) {
		        list.add(sc.nextInt());
		    } else if (type == 1) {
		        sb.append(list.get(sc.nextInt())).append("\n");
		    } else {
		        list.remove(list.size() - 1);
		    }
		}
		System.out.print(sb);
	}
}



Measured memory_bytes: 132292
// https://atcoder.jp/contests/abc170/tasks/abc171_e
#include<bits/stdc++.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a (n);
	vector<int> forward_sum (n+1);
	vector<int> reverse_sum (n+1);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		forward_sum[i+1] = forward_sum[i]^a[i];
	}
	for (int i = n-1; i >= 0; i--) {
		reverse_sum[i] = reverse_sum[i+1]^a[i];
	}
	for (int i = 0; i < n; i++) {
		int ans = forward_sum[i]^reverse_sum[i+1];
		cout << ans << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 5580
#include<bits/stdc++.h>
using namespace std;
long long mod = 1e9+7;
int mark[2009] = {};
int limit = 0;
long long dp[2050] = {};
long long getSum(long long n)
{
    if(dp[n] != -1 && n >= 0)
    {
        return dp[n];
    }
    if(n == 0)
    {
        return 1;
    }
    if(n < 0)
    {
        return 0;
    }
    long long res = 0;
    for(int i = 1; i <= limit; i++)
    {
        if(n-mark[i] >= 0)
        {
            res =(res+getSum(n-mark[i]))%mod;
        }
    }
    return dp[n] = res%mod;
}
void solve()
{
    long long n; cin >> n;
    for(int i = 3; i <= n; i++)
    {
        limit++;
        mark[limit] = i;
    }
    long long sum = getSum(n)%mod;
    cout << sum << endl;
}
int main()
{
    memset(dp, -1, sizeof(dp));
    solve();
    return 0;
}


Measured memory_bytes: 3668
import sys

#+++++
		
def main():
	n = int(input())
	al = list(map(int, input().split()))
	ans=0
	for i, v in enumerate(al):
		for j, v2 in enumerate(al[i+1:]):
			#print(i,j,v,v2)
			ans+=v*v2
	print(ans)
	return 
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3064
import java.util.*;

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

  Scanner sc = new Scanner(System.in);
     int a = sc.nextInt();
      int b = sc.nextInt();

      if(a < b){
        System.out.println("a < b");
      }
      else if(a > b){
        System.out.println("a > b");
    }  else if(a == b){
        System.out.println("a == b");
      }
  }
}



Measured memory_bytes: 26232
#include<bits/stdc++.h>
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
namespace io
{
	int F()
	{
		 int F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
	long long G()
	{
		 long long F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
}
int R(int l,int r)
{
	return (rand()<<15|rand())%(r-l+1)+l;
}
int a[333],b[333];
int f[666][666];
int vis[666];
int g[666];
int sum[666];
const int M=1000000007;
int main()
{
	int n=io::F(),k=io::F();
	for(register int i=1;i<=k;++i)a[i]=io::F(),b[i]=io::F(),vis[a[i]]=vis[b[i]]=1;
	g[0]=1;
	for(register int i=2;i<=n+n;i+=2)
		g[i]=1ll*g[i-2]*(i-1)%M;
	int cnt=0;
	for(register int i=1;i<=n+n;++i)
		cnt+=!vis[i];
	for(register int i=1;i<=n+n;++i)
		sum[i]=sum[i-1]+!vis[i];
	int ans=0;
	for(register int l=2;l<=n+n;l+=2)
		for(register int i=1;i+l<=n+n+1;++i)
		{
			int fl=0;
			for(register int j=1;j<=k;++j)
				if((i<=a[j]&&a[j]<i+l)^(i<=b[j]&&b[j]<i+l))
					{fl=1;break;}
			if(fl)continue;
			int c2=0;
			for(register int j=i;j<i+l;++j)c2+=!vis[j];
			f[i][i+l-1]=g[c2];
			for(register int j=i+1;j<i+l-1;j+=2)
				f[i][i+l-1]=(f[i][i+l-1]+1ll*(M-f[i][j])*g[sum[i+l-1]-sum[j]])%M;
			ans=(ans+1ll*f[i][i+l-1]*g[cnt-c2])%M;
		}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1792
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.List

main = do
  [n,c] <- fmap (map read . words) getLine
  !text <- getContents
  let xs = map ((\(x:v:_)-> x`seq`v`seq`(x,v)) . map read . words) (lines text)
  print (solve c xs)


-- MaxState, CurrentState, CurrentX
type State = (Int, (Int, Int))

solve :: Int -> [(Int,Int)] -> Int
solve c xs =
  solveTurn roundR roundL
  where
    !roundR = scanl f (0,(0,0)) xs
    !roundL = scanr (flip f) (0,(0,0)) [(c-x,v)|(x,v)<-xs]

--    f (m,(s,y)) (x,v) = let s' = s-(x-y)+v in s' `seq` (max m s', (s', x))
    f (m,(s,y)) (x,v) = let s' = s-(x-y)+v in (max m s', (s', x))

solveTurn :: [State] -> [State] -> Int
solveTurn ss1 ss2 =
--  go ss1 ss2 0
  foldl' f 0 (zip ss1 ss2)
  where
--    go :: [State] -> [State] -> Int -> Int
--    go [(m1,(s1,x1))]     [(m2,(s2,x2))]     a = max a (max m1 m2)
--    go ((m1,(s1,x1)):tt1) ((m2,(s2,x2)):tt2) a = let a' = max a $! (s1+m2-x1) in a' `seq` go tt1 tt2 a'
--    go ((m1,(s1,x1)):tt1) ((m2,(s2,x2)):tt2) a = let a' = max a $! max (s1+m2-x1) $! (s2+m1-x2) in a' `seq` go tt1 tt2 a'

    f a (((m1,(s1,x1))),((m2,(s2,x2)))) = max a $! max (s1+m2-x1) $! (s2+m1-x2)

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

using namespace std;

struct mobile {
    int p;
    int q;
    int r;
    int b;
};

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

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

int bestmob(vector<mobile> mobs, int index) {
    mobile mobtemp = mobs[index];
    int g=gcd(mobtemp.p,mobtemp.q);
    int rlen=mobtemp.p/g;
    int blen=mobtemp.q/g;
    int rw,bw;

    rw=(mobtemp.r==-1?blen:bestmob(mobs,mobtemp.r));
    bw=(mobtemp.b==-1?rlen:bestmob(mobs,mobtemp.b));

    int l=lcm(rw*rlen,bw*blen);

    return l/rlen+l/blen;
}

int main() {
    int n;
    cin >> n;
    while(n!=0) {
        vector<mobile> mobs;
        vector<int> deg(n,0);

        for(int i=0; i<n; ++i) {
            mobile mobtemp;
            cin >> mobtemp.p >> mobtemp.q >> mobtemp.r >> mobtemp.b;
            --mobtemp.r;
            --mobtemp.b;
            mobs.push_back(mobtemp);
            if(mobtemp.r!=-1) ++deg[mobtemp.r];
            if(mobtemp.b!=-1) ++deg[mobtemp.b];
        }

        int start;

        for(int i=0; i<n; ++i) {
            if(deg[i]==0) {
                start=i;
                break;
            }
        }


        cout << bestmob(mobs,start) << endl;
        mobs.clear();
        cin >> n;
    }
    return 0;
}

Measured memory_bytes: 3240
from collections import Counter

x = int(input())
a = list(map(int,input().split()))
c = Counter(a)
t = c.most_common()
d = 0
l = len(set(a))
for i in range(l):
    if t[i][1]>1:
        d+=t[i][1]-1
ans = l-d%2
print(ans)


Measured memory_bytes: 27860
#include <stdio.h>

int main(void)
{
	int n, y;
	
	scanf("%d%d", &n, &y);
	
	for (int i = 0; i <= n; i++)
		for (int j = 0; j <= n-i; j++)
			if (y == 10000*i+5000*j+1000*(n-i-j)) {
				printf("%d %d %d\n", i, j, n-i-j);
				return 0;
			}
	
	puts("-1 -1 -1");
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x, y, b, p;
        cin >> x >> y >> b >> p;
        cout << min(x*b+y*p, (max(b, 5)*x+max(p, 2)*y)/5*4) << "\n";
    }
    return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll N, K;
    cin >> N >> K;
    ll rem = N%K;
    cout << min(rem, K-rem) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

double distanceAB(double xa, double ya, double xb, double yb);
//void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/


class DisjointSet
{
public:
	vector<int> rank, p;
	
	DisjointSet() {}
	DisjointSet(int size)
	{
		rank.resize(size, 0);
		p.resize(size, 0);
		for (int i=0; i<size; i++) makeSet(i);
	}
	
	void makeSet(int x)
	{
		p[x] = x;
		rank[x] = 0;
	}
	
	bool same(int x, int y)
	{
		return findSet(x) == findSet(y);
	}
	
	void unite(int x, int y)
	{
		link(findSet(x), findSet(y));
	}
	
	void link(int x, int y)
	{
		if (rank[x] > rank[y])
		{
			p[y] = x;
		} else {
			p[x] = y;
			if (rank[x] == rank[y])
			{
				rank[y]++;
			}
		}
	}
	
	int findSet(int x)
	{
		if (x != p[x])
		{
			p[x] = findSet(p[x]);
		}
		
		return p[x];
	}
};


int main()
{
	int n, a, b, q;
	int t;
	
	cin >> n >> q;
	DisjointSet ds = DisjointSet(n);
	
	REP(q)
	{
		cin >> t >> a >> b;
		if (t == 0) ds.unite(a, b);
		else if (t == 1)
		{
			if (ds.same(a, b)) cout << 1 << endl;
			else cout << 0 << endl;
		}
	}
	
	return 0;
}


/*
void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}
*/


double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

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

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int x=0,mx=0;
    for(int i=0;i<n;i++){
        if(s[i]=='I'){
            x++;
            mx=max(mx,x);
        }else{
            x--;
            mx=max(mx,x);
        }
    }
    cout<<mx<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    ll N;
    cin >> N;
    for(ll n = 1; n <= 3500; n++) {
        for(ll h = 1; h <= 3500; h++) {
            ll p = N*h*n;
            ll q = 4*n*h-N*n-N*h;
            if(p*q > 0 && p%q == 0) {
                cout << n << " "<< h << " " << p/q << endl;
                return 0;
            }
        }
    }
}



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

int main()
{
    int N;
    cin >> N;
    long long dp[N + 10];
    long long height[N];

    for (int i = 0; i < N; i++)
    {
        cin >> height[i];
    }

    fill_n(dp, N + 10, 1e+18 + 10);

    dp[0] = 0;
    for (int i = 0; i < N; i++)
    {
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(height[i] - height[i + 1]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(height[i] - height[i + 2]));
    }

    cout << dp[N - 1] << endl;
    return 0;
}

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



int main(){
  int a,b;
  cin >> a>> b;
  cout << a*b << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

// debug
template <class T> ostream& operator<<(ostream &s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
  int n; cin >> n;
  vector<map<string, int>> dp(n);
  auto ok = [](string last4) {
    string s = "$$" + last4 + "$";
    REP (i, s.size() - 1) {
      swap(s[i], s[i + 1]);
      if (s.find("AGC") != -1) return false;
      swap(s[i], s[i + 1]);
    }
    return true;
  };
  function<int(int, string)> dfs = [&](int cur, string last3) {
    if (cur == n) return 1LL;
    if (dp[cur].count(last3)) return dp[cur][last3];
    int ret = 0;
    for (char c: string("TAGC")) {
      if (!ok(last3 + c)) continue;
      ret += dfs(cur + 1, last3.substr(1) + c);
      ret %= MOD;
    }
    return dp[cur][last3] = ret;
  };
  cout << dfs(0, "TTT") << endl;
}


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

class Main {
    static Scanner scanner = new Scanner();
    static long mod = 1000000007;

    public static void main(String[]$) {
        char[] s = scanner.next().toCharArray();
        char[] s2 = Arrays.copyOf(s, s.length);
        long k = scanner.nextInt();
        long count = 0;
        char first = s[0];
        boolean all = true;
        for (int i = 1; i < s.length; i++) {
            all &= first == s[i];
        }
        if (all) {
            System.out.println(s.length * k / 2);
        } else {
            int start = 0;
            if (s[0] == s[s.length - 1]) {
                start++;
                while (s[start] == s[start - 1]) {
                    start++;
                }
            }
            for (int i = 0; i < s.length; i++) {
                if (s[(i + start) % s.length] == s[(i + start + 1) % s.length]) {
                    s[(i + start + 1) % s.length] = '\0';
                    count++;
                }
            }
            count *= k - 1;
            for (int i = 1; i < s.length; i++) {
                if (s2[i - 1] == s2[i]) {
                    s2[i] = '\0';
                    count++;
                }
            }
            System.out.println(count);
        }
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

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

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


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

int main()
{
    int k, x;
    cin >> k >> x;

    int sum = 500 * k;
    string ans;
    if (sum >= x)
    {
        ans = "Yes";
    }
    else
    {
        ans = "No";
    }

    cout << ans;
}


Measured memory_bytes: 256