akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n - 1);
  int ans = 0;
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n) cin >> b[i];
  rep(i, 0, n - 1) cin >> c[i];
  int index = -3;
  rep(i, 0, n) {
    ans += b[a[i] - 1];
    if (index == a[i] - 1) ans += c[index - 1];
    index = a[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

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

func main() {
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()
	c := nextInt()
	d := nextInt()
	numC := 0
	numD := 0
	numCAndD := 0

	minC := a / c
	maxC := b / c
	minCRem := a % c

	minD := a / d
	maxD := b / d
	minDRem := a % d
	lcmCD := lcm(c, d)

	minCAndD := a / lcmCD
	maxCAndD := b / lcmCD
	minCAndDRem := a % lcmCD

	if minCRem != 0 {
		numC = maxC - minC
	} else {
		numC = maxC - minC + 1
	}
	if minDRem != 0 {
		numD = maxD - minD
	} else {
		numD = maxD - minD + 1
	}
	if minCAndDRem != 0 {
		numCAndD = maxCAndD - minCAndD
	} else {
		numCAndD = maxCAndD - minCAndD + 1
	}
	fmt.Println(b - a + 1 - (numC + numD - numCAndD))
}


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

using namespace std;

int main() {
    long long n;
    cin >> n;
    if (n == 0) cout << -1 <<endl;
    else {
        string ans = "";
        while( n > 0) {
            n--;
            ans += (char)('a' + n % 26 );
            n /= 26;
        }
        reverse(ans.begin(),ans.end());
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int A,B;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> A >> B;
}

int solve(){
    if(B%A==0) cout << A+B << endl;
    else cout << B-A << endl;
    return 0;
}   

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


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

int main () {
	int n,i;
	cin >> n;
	int all=0,max=0,tmp;
	for (i=0;i<n;++i) {
		cin >> tmp;
		if (max<tmp) max=tmp;
		all+=tmp;
	}
	cout << all-max/2 << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int a,b,c,d;
 cin>>a>>b>>c>>d;
 while(a>0 && c>0)
 {
  c-=b;
  if(c<=0)
  {
    cout<<"Yes"<<endl;
    break;
  }
  a-=d;
  if(a<=0)
  {
    cout<<"No"<<endl;
    break;
  }
  
 }
 
return 0;
}

Measured memory_bytes: 3636
N,M= map(int, input().split())
p = [0]*M
S = [0]*M
for i in range(M):
    _, S[i] = input().split()
    p[i] = int(_)

# ACの個数とACした問題を特定する。
q_a = [0]*N
ans = [0,0]
for i in range(M):
    if S[i] == "AC" and q_a[p[i]-1] == 0:
        q_a[p[i]-1] = 1
        ans[0]+= 1

p_count = 0
i=0
while i<M:
    if q_a[p[i]-1]:
        if S[i] == "WA":
            p_count += 1
        else:
            ans[1] += p_count
            p_count = 0
            q_a[p[i]-1] = 0
    i += 1

print(*ans)

Measured memory_bytes: 14068
#include <cstdio>
#include <algorithm>

using namespace std;

int N, K;
int A[100005];
int maxA;

int gcd(int m, int n) {
    int r = 0;
    while (r = m % n) m = n, n = r;
    return n;
}

int main() {
    scanf("%d%d", &N, &K);
    for (int i = 0; i != N; ++i) {
        scanf("%d", &A[i]);
        maxA = max(maxA, A[i]);
    }
    if (maxA < K) {
        puts("IMPOSSIBLE");
        return 0;
    }
    int g = A[0];
    for (int i = 1; i != N; ++i)
        g = gcd(g, A[i]);
    if (K % g != 0) {
        puts("IMPOSSIBLE");
        return 0;
    }
    puts("POSSIBLE");
    return 0;
}

Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

d = []

p = 0
m = 0

ans = 0
for i in range(n):
    d.append(a[i]-b[i])
    if d[-1]>0:
        p+= d[-1]
    if d[-1]<0:
        m-= d[-1]
        ans +=1

if p<m:
    print(-1)
    exit()

d.sort()
d.reverse()

i = 0
while m>0:
    m-=d[i]
    ans += 1
    i += 1
print(ans)

Measured memory_bytes: 84656
#include<bits/stdc++.h>
#define MOD 1000000007
#define mp make_pair
#define ll long long
#define pb push_back
#define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug cout<<"Debugging.."<<endl
using namespace std;
int main()
{
	faster;

	ll int tc=1;
	//cin>>tc;
	while(tc--)
	{
		ll int n;
		cin>>n;
		string s;
		cin>>s;
		
		int count=0;
		for(int i=0;i<n-2;i++)
		{
			if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
			{
				count++;
			}
		}
		
		cout<<count<<endl;

	}
}




Measured memory_bytes: 3652
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>

using namespace std;

int main()
{
    int ab, bc, ca;
    cin >> ab >> bc >> ca;

    cout << ab * bc / 2 << 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 a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int ans = 0;
        if (a == b) {
            ans = c;
        } else if (b == c) {
            ans = a;
        } else if (a == c) {
            ans = b;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22868
import java.util.ArrayDeque;
import java.util.Arrays;

public class Main {
  private static void solve() {
    int n = ni();
    long d = ni();
    long a = ni();

    long[][] p = new long[n][2];
    for (int i = 0; i < n; i++) {
      p[i][0] = ni();
      p[i][1] = ni();
    }

    Arrays.sort(p, (o1, o2) -> Long.signum(o1[0] - o2[0]));
    long dam = 0;
    long ret = 0;

    ArrayDeque<long[]> q = new ArrayDeque<>();

    for (int i = 0; i < n; i++) {
      while (q.size() > 0 && q.peekFirst()[0] < p[i][0]) {
        long[] v = q.pollFirst();
        dam -= v[1];
      }

      long need = p[i][1];
      if (need > dam * a) {
        long x = (need + a - 1) / a - dam;
        ret += x;
        dam += x;
        q.addLast(new long[] {p[i][0] + 2 * d, x});
      }
    }
    System.out.println(ret);

  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 70364
import itertools

def dist(F,G):
  x1=F[0]
  x2=G[0]
  y1=F[1]
  y2=G[1]
  return ((x1-x2)**2+(y1-y2)**2)**0.5

def paths(n):
  if n==1:
    return 1
  return n*paths(n-1)


N=int(input())
A=[[0,0] for _ in range(N)]
for i in range(N):
  A[i][0],A[i][1]=map(int,input().split())
B=[]
for i in range(len(A)):
  B.append(i)


patterns=itertools.permutations(B)
totlen=0
avelen=0
for lis in patterns:
  for i,l in enumerate(lis[:-1]):
    for j in lis[i+1:]:
      totlen+=dist(A[l],A[j])
      break



avelen=totlen/(paths(N))
print(avelen)



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

int main(){
    int n;
    cin>>n;
    int A[n];
    rep(i, n) cin>>A[i];

    int x_or=0;
    rep(i, n) x_or=x_or^A[i];
    rep(i, n){
        int num=x_or^A[i];
        cout<<num<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 4272
#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(){
  string s;
  cin >> s;
  rep(i, s.size()){
    cout << "x";
  }

  cout << endl;

  return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
__int128 ubound = 1000000000000000000;


void solve(long long N, std::vector<long long> A){
    __int128 ans = 1;
    sort(ALL(A));
    REP(i, N) {
        ans *= A[i];
        if(ans > ubound) {cout<<-1<<endl;return;}
    }
    cout<<(ll)ans<<endl;

}
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int k = 2;
  while (true) {
    int c = k * (k - 1) / 2;
    if (c == N) {
      break;
    } else if (N < c) {
      cout << "No" << endl;
      return 0;
    }
    k++;
  }
  cout << "Yes" << endl;
  cout << k << endl;

  int x = 1;
  vector<vector<int>> S(k);
  for (int i = 0; i < k-1; i++) {
    for (int j = i+1; j < k; j++) {
      S[i].push_back(x);
      S[j].push_back(x++);
    }
  }
  for (auto Si : S) {
    cout << Si.size();
    for (int s : Si) {
      cout << ' ' << s;
    }
    cout << endl;
  }
}

Measured memory_bytes: 2304
import bisect as bi

N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))

ans=0
for Bi in B:
    a=bi.bisect_left(A,Bi)
    c=N-bi.bisect_right(C,Bi)
    ans+=a*c

print(ans)

Measured memory_bytes: 107108
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
int main()
{
    Hello
    int n;
    cin >> n;
    set<string> st;
    for (int (i) = 0; (i) < n; ++(i)) {
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size();
    return 0;
}

Measured memory_bytes: 19220
#include <iostream>
#include <map>

typedef long long ll;

using namespace std;

int main(void)
{

    ll n, m;
    cin >> n >> m;
    ll MOD = 1e9 + 7;
    map<ll, ll> mp, fact;

    for (int i = 2; i <= m; i++)
    {
        while (m % i == 0)
        {
            mp[i] += 1;
            m /= i;
        }
    }

    for (auto m : mp)
    {
        // cout << m.first << "<-" << m.second << endl;

        for (int i = m.second; i >= 1; i--)
        {
            ll bunbo = i + n - 1;
            ll bunshi = i;
            for (int j = 2; j <= bunbo; j++)
            {
                while (bunbo % j == 0)
                {
                    fact[j] += 1;
                    bunbo /= j;
                }
            }
            for (int j = 2; j <= bunshi; j++)
            {
                while (bunshi % j == 0)
                {
                    fact[j] -= 1;
                    bunshi /= j;
                }
            }
        }
    }

    ll ans = 1;
    for (auto f : fact)
    {
        for (int i = 0; i < f.second; i++)
        {
            ans *= f.first;
            ans %= MOD;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef string str;
typedef std::pair<ll,ll> pl;
typedef std::map<string, ll> msl;
typedef std::map<ll, ll> mll;
typedef std::vector<ll> vl;
const long double EPS = 1e-9;
 
#define rep(i, n) for(ll (i) = 0; (i) < (n) ; (i)++ )
#define For(i, a, b) for(ll (i) = (a); (i) < (b) ; (i)++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define tol(c) char((c)+0x20)
#define tou(c) char((c)-0x20)
#define pb push_back
#define mp make_pair
#define pr(a) cout << (a)
#define prl(a) cout << (a) << endl
#define prl2(a,b) cout << (a) << " " << (b) << endl
#define prs(a) cout << (a) << " "
#define yn(condition) if ((condition)) prl("Yes"); else prl("No");
#define YN(condition) if ((condition)) prl("YES"); else prl("NO");
#define rpr(i,n,ans) rep((i),(n)) prs((ans[(i)]))
#define cpr(i,n,ans) rep((i),(n)) prl((ans[(i)]))
#define in1(a) cin >> (a)
#define in2(a,b) cin >> (a) >> (b)
#define in3(a,b,c) cin >> (a) >> (b) >> (c)
#define in4(a,b,c,d) cin >> (a) >> (b) >> (c) >> (d)
#define rin1(i,n,a) rep((i),(n)) cin >> (a[(i)])
#define rin2(i,n,a,b) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)])
#define rin3(i,n,a,b,c) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)]) >> (c[(i)])
#define e1 first
#define e2 second
#define ctol(c) ll((c)) - ll('0')
#define ltos(n) to_string((n))
#define items(kv, v) for(auto &(kv): (v))
#define ndig(N, n) ctol(ll(ltos((N))[ll(ltos((N)).length()) - (n)]))
#define beto(a,b,c) (a) < (b) && (b) < (c)
#define betc(a,b,c) (a) <= (b) && (b) <= (c)
#define rsort(a,n) sort(a,a+n,greater<>())
 
const ll mod = 1e9 + 7;
const ll INF = mod * mod;
const ll MAX_N = 100;
 
int main(void){
    ll a,b,h;
    str s,t,u;

    in3(a,b,h);
    prl(((a+b)*h)/2);


    return 0;
}

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

#define ff first
#define ss second
#define pb push_back
#define ll long long
#define mod 1000000007
#define ull unsigned long long
#define mst(ss,b) memset(ss,b,sizeof(ss));
#define pl(x) cout << #x << "= " << x << endl;
const int inf = 0x3f3f3f3f;
const int N = 1e5+5;



int  main(){
    int x, y;
    cin>>x>>y;
    cout<<(x+y)%24<<endl;
    return 0;
}

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

int main(){

  int n,m,l;
  cin>> n >>m>>l;
  int A[n][m],B[m][l];
  long long int C[n][l];
  int s;
  //n[2][3]
  //array<array<int, m>, n> A;
  //array<array<int, l>, m> B;
  //怒られる
  for(int i=0; i<n;i++){
    for(int j=0; j<m;j++){
      cin >>s;
      A[i][j]=s;
    }
  }
  for(int i=0; i<m;i++){
      for(int j=0; j<l;j++){
	cin >>s;
	B[i][j]=s;
      }
  }

  long long int t;
  for(int i=0; i<n;i++){
    for(int j=0; j<l;j++){
      t=0;
      for(int k=0; k<m;k++){
	t+=A[i][k]*B[k][j];
	//cout <<A[i][k]*B[k][j]<<" ";
      }
      C[i][j]=t;
    }
  }

  for(int i=0; i<n;i++){
    for(int j=0; j<l;j++){
      if(j!=(l-1)){
	cout <<C[i][j]<<" ";
      }
      else{
	cout <<C[i][j];
      }
    }
    cout <<endl;
  }
	
  return 0;
}



Measured memory_bytes: 3228
mod = 10**9 + 7
n = int(input())
a = sorted(list(map(int,input().split())))
 
if n % 2 == 0:
  for i in range(n//2):
    if not a[2*i] == a[2*i+1] == 2*i+1:
      print(0)
      exit()
else:
  if a[0] != 0:
    print(0)
    exit()
  for i in range(n//2):
    if not a[2*i+1] == a[2*i+2] == 2*i+2:
      print(0)
      exit()
print(pow(2, n//2) % mod)

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

const int MAXN = 11;
const int MAXD = 11;
const int MAXX = 100005;
int n, d, x;
int p[MAXD][MAXN];
int dp[MAXD][MAXX];

int main() {
  for(; cin >> n >> d >> x; ) {
    for(int i = 0; i < d; ++i) {
      for(int j = 0; j < n; ++j) {
        cin >> p[i][j];
      }
    }
    for(int i = 0; i < d-1; ++i) {
      for(int x = 0; x < MAXX; ++x) dp[i][x] = x;
      for(int j = 0; j < n; ++j) {
        for(int x = p[i][j]; x < MAXX; ++x) {
          dp[i][x] = max(dp[i][x],
                         dp[i][x-p[i][j]] + p[i+1][j]);
        }
      }
    }
    for(int i = 0; i < d-1; ++i) x = dp[i][x];
    cout << x << endl;
  }
  return 0;
}

Measured memory_bytes: 5252
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <climits>
#include <utility>
typedef long long ll;
using namespace std;

const ll MOD = 998244353LL;
const ll MAX = 2000010LL;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main(int argc, char *argv[]) {
  COMinit();

  ll n, m, k;

  cin >> n >> m >> k;

  ll ans = 0LL;

  for(ll i=0;i<=k;i++){
    ans += ((m*modpow(m-1LL,n-i-1LL)%MOD)*COM(n-1LL,i)) % MOD;
    ans %= MOD;
  }

  if(ans<0LL){
    ans += MOD;
  }

  cout << ans << endl;

  return 0;
}


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

int main()
{
    char s[15], ans[15];
    int ind = 0;
    scanf("%s", s);
    for(int i = 0; s[i] != '\0'; i++)
    {
        if(s[i] == '0')ans[ind++] = '0';
        else if(s[i] == '1')ans[ind++] = '1';
        else
        {
            if(ind > 0)ind--;
        }
    }
    ans[ind] = '\0';
    printf("%s", ans);
    return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back

const int maxm = 1000000000 + 7;


using namespace std;


int main()
{

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

	ll n;
	cin>>n;

	cout<<n*(n-1)/2<<endl;





}

Measured memory_bytes: 3560
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	int a,b,c;
	cin>>a>>b>>c;
	int k;
	cin>>k;
	int cnt=0;
	while(b<=a)
	{
		b*=2;
		cnt++;
	}
	while(c<=b){
		c*=2;
		cnt++;
	}
	if(cnt<=k)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}







Measured memory_bytes: 3636
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

public class Hello{
    public static void Main(){
        var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int A = line.Max();
        int B = line.Min();
        if((A+B)%2==0){
            Console.WriteLine((A+B)/2);
        }else{
            Console.WriteLine("IMPOSSIBLE");
        }
    }
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 500100;

int N;
ll L;
ll t[MAXN], v[MAXN];

vector <pair <ld, ld> > hull;

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N >> L;
    for (int i = 0; i < N; i++)
        cin >> t[i] >> v[i];
    cout << fixed << setprecision(9);

    hull.push_back (make_pair (0, 0));
    int chull = 0;
    for (int i = 0; i < N; i++)
    {
        ld vtot = v[i] + hull.back().first;
        ld ttot = t[i] * v[i] + hull.back().second;
        hull.push_back (make_pair (vtot, ttot));

        while (chull + 1 < hull.size() && hull[chull+1].first + L <= vtot)
            chull++;
        ld vlo = hull[chull].first - (vtot - L), vhi = hull[chull+1].first - (vtot - L);
        ld ttemp = (vhi * hull[chull].second - vlo * hull[chull+1].second) / (vhi - vlo);
        hull[chull] = make_pair (vtot - L, ttemp);
        cout << (ttot - ttemp) / L << "\n";

        hull.pop_back();
        while (hull.size() > chull + 1)
        {
            ld v1 = hull[hull.size()-2].first, t1 = hull[hull.size()-2].second;
            ld v2 = hull[hull.size()-1].first, t2 = hull[hull.size()-1].second;
            if (t1 * (vtot - v2) + ttot * (v2 - v1) < (vtot - v1) * t2)
                hull.pop_back();
            else
                break;
        }
        hull.push_back (make_pair (vtot, ttot));
    }
}

Measured memory_bytes: 33764
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

void DFS(int n, vector<vector<int>> &G, vector<bool> &V) {
	for (int nn: G[n]) {
		if (!V[nn]) {
			V[nn] = true;
			DFS(nn, G, V);
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<vector<int>> G(n, vector<int>());
	vector<bool> visited(n, false);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (!visited[i]) {
			visited[i] = true;
			ans++;
			DFS(i, G, visited);
		}
	}
	cout << ans - 1 << endl;
}



Measured memory_bytes: 9536
// by newbiechd
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>

// DELETE the debugging information!
#define debug(x) std::cerr << #x << " = " << (x) << std::endl

const int N_MAX = 2003;
std::vector<int> g[N_MAX];
int u[N_MAX], v[N_MAX];

int lim;
int dfs(int x, int fa, int dis) {
  if (dis > lim)
    return 0;
  int ret = 1;
  for (int y : g[x])
    if (y != fa)
      ret += dfs(y, x, dis + 1);
  return ret;
}

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
    u[i] = x, v[i] = y;
  }
  
  lim = k / 2;
  int ans = 0;
  if (k & 1) {
    for (int i = 1; i < n; ++i)
      ans = std::max(dfs(u[i], v[i], 0) + dfs(v[i], u[i], 0), ans);
  }
  else {
    for (int i = 1; i <= n; ++i)
      ans = std::max(dfs(i, 0, 0), ans);
  }
  printf("%d\n", n - ans);
  return 0;
}


Measured memory_bytes: 384
N,T = map(int,input().split())
A = list(map(int,input().split()))
B = [0 for _ in range(N)]
amax = A[-1]
for i in range(N-2,-1,-1):
    a = A[i]
    if a>amax:
        B[i] = 0
        amax = a
    else:
        B[i] = amax-a
bmax = 0
amax = 0
for i in range(N):
    b = B[i]
    if b>bmax:
        amax = A[i]+b
        bmax = b
Ind = []
for i in range(N):
    if B[i]==bmax:
        Ind.append(i)
cnt = 0
cur = N-1
for i in range(len(Ind)-1,-1,-1):
    j = Ind[i]
    amax = A[j]+B[j]
    for k in range(cur,j,-1):
        if A[k]==amax:
            cnt += 1
    cur = j
print(cnt)

Measured memory_bytes: 93040
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  vector<ll>s(n);
  rep(i,n){
    cin>>s[i];
  }

  s[0]=0;
  s[n-1]=0;
  ll res=s[n-1];
  repi(d,1,n){
    vector<ll>su;
    //cout<<d<<endl;
    if((n-1)%d==0){

      for(int i=0;i<n-1-i;i+=d)su.push_back(s[i]+s[n-1-i]);


      ll l=su.size();
      rep(i,l-1)su[i+1]+=su[i];
      rep(i,l)chmax(res,su[i]);
    }
    else {
      for(int i=0;i<n;i+=d)su.push_back(s[i]+s[n-1-i]);

      ll l=su.size();
      su[l-1]=0;
      rep(i,l-1)su[i+1]+=su[i];
      rep(i,l)chmax(res,su[i]);

    }
  }
  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 1932
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  ll mx=1e18;
  vector<ll> a(n);
  rep(i,n){
    cin >> a[i];
    if(a[i]==0){
      cout << 0 << endl;
      return 0;
    }
    mx/=a[i];
  }
  if(mx==0){
    cout << -1 << endl;
    return 0;
  }
  ll ans=1;
  rep(i,n){
    ans*=a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;

int main()
{
    ll N;
    cin >> N;
    vll A(N), B(N);
    vector<pair<ll, ll>> C(N);
    ll sum = 0;
    rep(i, N)
    {
        cin >> A[i] >> B[i];
        C[i] = {A[i] + B[i], i};
        sum += B[i];
    }
    sort(all(C), greater<pair<int, int>>());
    ll Ta = 0, Ao = 0;
    rep(i, N)
    {
        if (i % 2 == 0)
            Ta += A[C[i].second];
        else
        {
            Ao += B[C[i].second];
        }
    }
    cout << Ta - Ao;
    return 0;
}

Measured memory_bytes: 3456
#include <iostream>

using namespace std;

int main()
{
    int dice[6];
    for(int i=0; i<6; ++i){
        cin >> dice[i];
    }

    string s;
    cin >> s;
    int tmp;
    for(const auto& c: s){
        switch(c){
            case('S'):
                tmp = dice[5];
                dice[5] = dice[1];
                dice[1] = dice[0];
                dice[0] = dice[4];
                dice[4] = tmp;
                break;
            case('N'):
                tmp = dice[5];
                dice[5] = dice[4];
                dice[4] = dice[0];
                dice[0] = dice[1];
                dice[1] = tmp;
                break;
            case('E'):
                tmp = dice[5];
                dice[5] = dice[2];
                dice[2] = dice[0];
                dice[0] = dice[3];
                dice[3] = tmp;
                break;
            case('W'):
                tmp = dice[5];
                dice[5] = dice[3];
                dice[3] = dice[0];
                dice[0] = dice[2];
                dice[2] = tmp;
                break;
        }


    }

    cout << dice[0] << endl;

    return 0;
}


Measured memory_bytes: 3216
def main():
    n = int(input())
    xd = [map(int, input().split()) for _ in range(n)]
    mod = 998244353
    INF = 10 ** 10

    xx = [(x, x + d, i) for i, (x, d) in enumerate(xd, 1)]
    xx.sort()
    c = [[] for _ in range(n + 1)]
    stack = [(INF, 0)]
    for l, r, i in xx:
        while stack[-1][0] <= l:
            stack.pop()

        ip = stack[-1][1]
        c[ip].append(i)
        stack.append((r, i))

    dp = [1] * (n + 1)
    for _, _, u in xx[::-1]:
        for v in c[u]:
            dp[u] *= dp[v]
            dp[u] %= mod

        dp[u] += 1
        dp[u] %= mod

    for v in c[0]:
        dp[0] *= dp[v]
        dp[0] %= mod

    ans = dp[0]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 139696
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>

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

int N, Q;
long long int T, A[112345];
int D[112345];
int X[1123];

int main() {

	scanf("%d %lld %d", &N, &T, &Q);

	vector<int> point;
	int prevD = 0;
	rep(i, N) {
		scanf("%lld %d", &A[i], &D[i]);
		if (prevD == 1 && D[i] == 2) point.push_back(i - 1);
		prevD = D[i];
	}
	rep(i, Q) scanf("%d", &X[i]);

	int x = 0;
	int count = -1;
	prevD = 0;
	rep(i, N) {
		if (prevD != 1 && D[i] == 1) count++;
		prevD = D[i];
		if (i == X[x] - 1) {
			if (count == -1) printf("%lld\n", A[i] - T);
			else if (count >= point.size()) printf("%lld\n", A[i] + T);
			else if (D[i] == 1) printf("%lld\n", min((A[point[count]] + A[point[count] + 1]) / 2, A[i] + T));
			else printf("%lld\n", max((A[point[count]] + A[point[count] + 1]) / 2, A[i] - T));
			x++;
			if (x >= Q) break;
		}
	}

	return 0;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using i64 = long long;

std::vector<std::deque<int>> g;
std::vector<i64> c, r;

void dfs(int v, int p) {
    static int pos = 0;
    r[v] = c[pos++];
    for (int to : g[v]) {
        if (to == p) continue;
        dfs(to, v);
    }
}

int main() {
    int n;
    std::cin >> n;
    g.resize(n); c.resize(n); r.resize(n);
    for (int i = 1; i < n; i++) {
        int u, v;
        std::cin >> u >> v;
        --u; --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for (int i = 0; i < n; i++) std::cin >> c[i];
    std::sort(c.begin(), c.end(), std::greater<>());
    dfs(0, -1);
    std::cout << std::accumulate(c.begin() + 1, c.end(), 0ll) << std::endl;
    for (int i = 0; i < n; i++) std::cout << r[i] << " ";
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 7808
INF = 10**9

H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]

# (i, j)に進むときの色の反転回数の最小値
dp = [[INF for j in range(W)] for i in range(H)]

if s[0][0] == '#':
    dp[0][0] = 1
else:
    dp[0][0] = 0

for i in range(H):
    for j in range(W):
        if i == H - 1 and j == W - 1:
            break
        
        if i != H - 1:
            if s[i][j] == '.' and s[i + 1][j] == '#':
                dp[i + 1][j] = min(dp[i][j] + 1, dp[i + 1][j])
            else:
                dp[i + 1][j] = min(dp[i][j], dp[i + 1][j])
        
        if j != W - 1:
            if s[i][j] == '.' and s[i][j + 1] == '#':
                dp[i][j + 1] = min(dp[i][j] + 1, dp[i][j + 1])
            else:
                dp[i][j + 1] = min(dp[i][j], dp[i][j + 1])

print(dp[H-1][W-1])

Measured memory_bytes: 3188
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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 T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

string str;
string solve() {
  map<char,int> ma;
  for (auto c : str) {
	ma[c]++;
	if (ma[c] > 1) return "no";
  }
  return "yes";
  
}

int main() {
  while (cin >> str) {
	cout << solve() << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main (void)
{
  int i,great,combo,max;
  char dna[11];
  scanf("%s",dna);
  
  for(i=0;i<10;i++){
    great=0;
    if('A'==dna[i]) great++;
  	if('T'==dna[i]) great++;
  	if('G'==dna[i]) great++;
  	if('C'==dna[i]) great++;
    if(great==1) combo++;
    if(combo>max) max=combo;
    if(great==0) combo=0;
    
  }
  
  printf("%d",max);

  return 0; 
}

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

using namespace std;
int k,n,a[200010],minn;
int main(){
	cin>>k>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n;i++){
        int ans=0;
        int f=(i+n-1)%n;
        ans=(a[f]-a[i]+k)%k;
        if(i==0) minn=ans;
        else minn=min(minn,ans);
    }
    cout<<minn;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>


using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> P;

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define Rep(i, n) for(int i=n; i >= 0; i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える

const int INF = 50010;

int main() {
	int n, m; cin >> n >> m;
	vi c(m); rep(i, m) cin >> c[i];

	vvi dp(m + 1, vi(n + 1, INF));
	dp[0][0] = 0;

	rep(i, m) rep(j, n + 1) {
		if (c[i] <= j) dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - c[i]] + 1);
		else dp[i + 1][j] = dp[i][j];
	}

	cout << dp[m][n] << endl;
}



Measured memory_bytes: 7068
#include<stdio.h>
int main()
{
    unsigned long long int k, a, b;
    scanf("%lld %lld %lld", &k, &a, &b);
    if (a + 1 >= b)
        printf("%d\n", k + 1);
    else
    {
        k -= a - 1;
        unsigned long long int  ans = a;
        ans += (b - a)*(k / 2);
        if (k % 2 == 1)
            ans++;
        printf("%lld\n", ans);
    }
    return 0;
}

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

int main() 
{
	vector<int>s(0);
	for (int a = 0; a < 28; a++) {
		int b;
		cin >> b;
		s.push_back(b - 1);
	}
	sort(s.begin(), s.end());
	vector<int>d(0); int f = 0;
	for (int e = 0; e < 30; e++) {
		if (s[e] != e+f) {
			d.push_back(e+f);
			if (f)break;
			f++;
		}
	}
	sort(d.begin(), d.end());
	cout << d[0] + 1 <<endl << d[1] + 1 << endl;
}

Measured memory_bytes: 3152
import java.io.*;
import java.util.*;
public class Main {
	
	public static void main(String... args) {
		FastScanner sc = new FastScanner();
		char[] s = sc.next().toCharArray();
		for(int i = 0; i < s.length; i++) {
			if(s[i] == '?') s[i] = 'D';
		}
		PrintWriter pw = new PrintWriter(System.out);
		pw.println(s);
		pw.flush();
	}
	
	static class FastScanner {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public FastScanner() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
        public String nextLine() {
        	try {
        		return reader.readLine();
        	} catch(IOException e) {
        		throw new RuntimeException(e);
        	}
        }
    }
	

}

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

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

int main() {
    int a[3];
	cin >> a[0]>>a[1]>>a[2];
    sort(a,a+3);
    if((a[0]==a[1]&&a[1]==a[2])||(a[0]!=a[1]&&a[1]!=a[2])){
        cout<<"No";
    }else{
        cout<<"Yes";
    }
	return 0;
}

Measured memory_bytes: 764
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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 INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int h=0;
  rep(i,101){
  if(a<=i&&i<b&&c<=i&&i<d)
    h++;
  }
  out(h);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

void print(char str[1000], int a, int b) {
	char substr[1000];
	strncpy(substr, str + a, b - a + 1);
	substr[b - a + 1] = '\0';
	printf("%s\n", substr);
}

void reverse(char str[1000], int a, int b) {
	int i;
	char revstr[1000];
	strcpy(revstr, str);
	for (i = a;i <= b;i++) {
		revstr[i] = str[b + a - i];
	}
	strcpy(str, revstr);
}

void replace(char str[1000], int a, int b, char p[1000]) {
	int i;
	for (i = a;i <= b;i++) {
		str[i] = p[i - a];
	}
}

int main() {
	int i;
	int a, b, n;
	char str[1000], p[1000];
	char op[10];
	
	scanf("%s", str);
	scanf("%d", &n);

	for (i = 0;i < n;i++) {
		scanf("%s", op);

		if (strcmp(op, "print") == 0) {
			scanf("%d %d", &a, &b);
			print(str, a, b);
		}
		else if (strcmp(op, "reverse") == 0) {
			scanf("%d %d", &a, &b);
			reverse(str, a, b);
		}
		else if (strcmp(op, "replace") == 0) {
			scanf("%d %d %s", &a, &b, p);
			replace(str, a, b, p);
		}
	}

	return 0;
}

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

const int INF = 1e9;

int main() {
    int N;  cin >> N;
    vector<vector<int>> F(N, vector<int>(10));
    for (int i = 0; i < N; ++i) for (int j = 0; j < 10; ++j) cin >> F[i][j];
    vector<vector<int>>  P(N, vector<int>(11));
    for (int i = 0; i < N; ++i) for (int j = 0; j <= 10; ++j) cin >> P[i][j];

    int ans = -INF;
    for (int i = 1; i < (1 << 10); ++i) {
        int sum = 0;
        for (int j = 0; j < N; ++j) {
            int cnt = 0;
            for (int k = 0; k < 10; ++k) {
                if (((i >> k) & 1) && (F[j][k] == 1)) ++cnt;
            }
            sum += P[j][cnt];
        }
        ans = max(ans, sum);
    }

    cout << ans << endl;
}


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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int N;
	cin >> N;
	for(int i = 111; i <= 999; i += 111){
		if(N <= i){
			cout << i << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-


H, W = map(int, input().split())
a = []
for i in range(H):
    a.append(list(input()))

result = [[0 for i in range(W)] for j in range(H)]

for h in range(H):
    for w in range(W):
        if a[h][w] == '#':
            result[h][w] = '#'
        else:
            indice = [(h-1, w-1), (h, w-1), (h-1, w+1), (h-1, w),
                      (h+1, w+1), (h, w+1), (h+1, w-1), (h+1, w)]
            for tp in indice:
                if tp[0] >= 0 and tp[0] < H and tp[1] >= 0 and tp[1] < W \
                   and a[tp[0]][tp[1]] == '#':
                    result[h][w] += 1

for i in range(H):
    print(''.join(map(str, result[i])))

Measured memory_bytes: 3064