akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
string a[110];
int n;
int l[110];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++) l[i]=a[i].length();
	for(int i=2;i<=n;i++) if(a[i][0]!=a[i-1][l[i-1]-1]) {puts("No");return 0;}
	for(int i=1;i<=n;i++)
	  for(int j=i+1;j<=n;j++)
	    if(a[i]==a[j]){
	    	puts("No");
	    	return 0;
		}
	puts("Yes");
	return 0;
 } 

Measured memory_bytes: 256
#include <cstdio>

int N;
int P[200010];
int memo[200010];
int res;

void solve()
{
	int i;
	for(i=0; i<N; i++)
		memo[i] = -1;
	for(i=0; i<N; i++){
		if(P[i] == 0){
			memo[0] = 1;
			continue;
		}
		if(memo[P[i]-1] != -1)
			memo[P[i]] = memo[P[i]-1] + 1;
		else
			memo[P[i]] = 1;
	}
	int mx = 0;
	for(i=0; i<N; i++){
		if(memo[i] > mx)
			mx = memo[i];
	}
	res = N - mx;
	printf("%d\n", res);
}

int main()
{
	int i;
	scanf("%d", &N);
	for(i=0; i<N; i++){
		scanf("%d", &P[i]);
		P[i] --;
	}
	solve();
	return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>

int main (int argc, char *argv[]) {
    int i = 1;
    int first = 0;
    int isFound = 0;
    char c;
    c = getchar();
    while (i <= 100 && c != EOF) {
        if (c == 'C') first = 1;
        if (first == 1 && c == 'F') isFound = 1;
        c = getchar();
        i++;
    }
    if (isFound == 1) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
#define INF 100000000
#define MAX_V 100001
#define MOD 1000000007
typedef vector<vector<int> > Graph;

int main(){
    int a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f;
    vector<vector<int>> dp(3001,vector<int>(3001,0));
    dp[0][0]=1;
    int s_max=(int)((double)f/100*e);
    for(int i=0;i<f+1;i++){
        for(int j=0;j<s_max+1;j++){
            if(i-100*a>=0) dp[i][j]=max(dp[i-100*a][j],dp[i][j]);
            if(i-100*b>=0) dp[i][j]=max(dp[i-100*b][j],dp[i][j]);
            if(i-c>=0&&j-c>=0) dp[i][j]=max(dp[i-c][j-c],dp[i][j]);
            if(i-d>=0&&j-d>=0) dp[i][j]=max(dp[i-d][j-d],dp[i][j]);
        }
    }
    ld ans=0;
    ld MAX=(ld)e/(100.0+(ld)e);
    int m_sum,m_s;
    for(int i=0;i<f+1;i++){
        for(int j=0;j<f/100*e+1;j++){
            if(dp[i][j]==1){
                ld s=(ld)j/(ld)i;
                if(s>=ans){
                    if(s>MAX) continue;
                    ans=s;
                    m_sum=i;
                    m_s=j;
                }
            }
        }
    }
    cout<<m_sum<<' '<<m_s<<endl;
}
 



Measured memory_bytes: 35584
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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;}

const ll INF=1e18;

int main(){
    ll n,x;
    cin >> n >> x;
    vector<ll> m(n);
    rep(i,n){
        cin >> m[i];
        x-=m[i];
    }
    sort(m.begin(),m.end());
    ll ans=n;
    ans+=x/m[0];
    cout << ans << endl;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];

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

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	if (n > k * 2) {

	}
	return fac[n] / (fac[k] * fac[n - k]);
}

ll dp[201010][2];
ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
char c[10][10];
bool flag[10][10];
bool flag2[10][10];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	vector<ll>p(n), q(n);
	rep(i, n) {
		cin >> p[i];
	}
	rep(i, n) {
		cin >> q[i];
	}
	ll res = 0;
	do {
		res++;
	} while (next_permutation(p.begin(), p.end()));
	do {
		res--;
	} while (next_permutation(q.begin(), q.end()));
	ll ans = abs(res);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3612
#B - Guidebook (別解)
N = int(input())

iSP = []
for i in range(N):
    s,p = input().split()
    iSP.append([i+1,s,int(p)])


ans = sorted(iSP, key = lambda x:x[2], reverse = True)

ans = sorted(ans, key = lambda x:x[1])

for j,k,l in ans:
    print(j)

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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  a = (a + d - 1) / d;
  c = (c + b - 1) / b;
  
  if(a < c) cout << "No" << endl;
  else cout << "Yes" << endl;
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

void solve ( int test_case )
{
    int a , b , c ;
    cin >> a >> b >> c ;

    cout << min ( c , b/a ) ;
}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 256
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100000;

int N;
int A[MAX_N+2];
int da1[MAX_N+1];
int da2[MAX_N];

int main() {
  cin >> N;
  for (int i = 1; i <= N; ++i) cin >> A[i];
  A[0] = A[N+1] = 0;

  ll c = 0;
  for (int i = 0; i < N; ++i) {
    da1[i] = abs(A[i+1]-A[i]);
    da2[i] = abs(A[i+2]-A[i]);
    c += da1[i];
  }
  da1[N] = abs(A[N+1]-A[N]);
  c += da1[N];

  for (int i = 1; i <= N; ++i) {
    ll ans = c;
    ans -= da1[i-1] + da1[i];
    ans += da2[i-1];
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 2432
from copy import deepcopy


def solve(maze, i, j, h, w, count):
    distance = 0
    if maze[i][j] == ".":
        distance = 0
        next_search = [(i, j)]
        while not next_search == []:
            now = next_search.pop(0)
            if maze[now[0]][now[1]] == ".":
                maze[now[0]][now[1]] = "#"
                for direction in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
                    search = [direction[0] + now[0], direction[1] + now[1]]
                    if search[0] < 0 or h <= search[0] or search[1] < 0 or w <= search[1] or \
                            maze[search[0]][search[1]] == "#":
                        continue
                    else:
                        count[search[0]][search[1]] = count[now[0]][now[1]] + 1
                        next_search.append(tuple(search))
                        distance = max(distance, count[search[0]][search[1]])
    return distance


def main():
    height, width = map(int, input().split(" "))
    maze = []
    answer = 0
    for _ in range(height):
        maze.append(list(input()))
    count = [[0 for _ in range(width)] for _ in range(height)]
    for i in range(height):
        for j in range(width):
            answer = max(answer, solve(deepcopy(maze), i, j, height, width, deepcopy(count)))
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 3444
using System;
using System.Reflection;
using System.Linq.Expressions;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder {
    public class Program {
        static int[] getKeys(char delimiter) {
            var Keys = Console.ReadLine().Split(' ');
            int N = Keys.Length;
            int[] Ns = new int[N];
            for (int i = 0; i < N; i++) {
                Ns[i] = int.Parse(Keys[i]);
            }
            return Ns;
        }
        static void Show<T>(T[,] map) {
            int H = map.GetLength(0);
            int W = map.GetLength(1);
            Console.WriteLine("-------------------------");
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    Console.Write(map[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine("-------------------------");
        }
        static void Show<T>(T[,] map, string delimiter) {
            int H = map.GetLength(0);
            int W = map.GetLength(1);
            Console.WriteLine("-------------------------");
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    Console.Write(map[i, j] + delimiter);
                }
                Console.WriteLine();
            }
            Console.WriteLine("-------------------------");
        }
        static void Show<T>(IEnumerable<T> ts) {
            foreach (var item in ts) {
                Console.Write(item + " ");
            }
            Console.WriteLine();
        }
        static void Show<T>(IEnumerable<T> ts, string delimiter) {
            foreach (var item in ts) {
                Console.Write(item + delimiter);
            }
            Console.WriteLine();
        }
        static void Main() {
            int N = int.Parse(Console.ReadLine());
            int Sum = 0;
            int[] Keys;
            for (int i = 0; i < N; i++) {
                Keys = getKeys(' ');
                Sum += Keys[1] - Keys[0] + 1;
            }
            Console.WriteLine(Sum);
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll n,i,j,l,ans = 0;
  cin>>n;
  vector<ll> a(n),b(n);
  for(i=0;i<n;i++) cin>>a[i];
  b = a;
  sort(b.begin(),b.end());
  b.erase(unique(b.begin(),b.end()), b.end());
  l = b.size();
  if(b[0]!=1) {cout<<-1; return 0;}
  j = 0;
  for(i=0;i<n;i++)
  {
    if(a[i]!=b[j]) ans++;
    else 
    {
        if(b[j]!=j+1) ans++;
        j++;
    }
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<queue>
#include<unordered_map>
#include<map>
#include<stack>
#include<bits/stdc++.h>
#include<string.h>
#include <ext/pb_ds/assoc_container.hpp>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
//#define f first
//#define s second
#define respr(fir,sec) for(int i=0;i<=fir;i++){for(int j=0;j<=sec;j++){cout << res[i][j] << " ";}cout << "\n";}
#define pb push_back
//#define INF (1LL<<31)
using namespace std;
using namespace __gnu_pbds;
const int mod = 1e9+7;
const ll MAX = 1000000000000000000;
const ll INF = 1000000000000000000;
typedef pair<int,ll> pii;
typedef pair<ll,int> pi;
typedef tuple<long long,int> tp;
typedef tuple<int,int,long long> tu;
typedef multimap<pii , int> mpp;
typedef priority_queue< tp , vector<tp>, greater<tp>>  minheap;
typedef priority_queue<pii , vector<pii>> maxheap;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>  new_data_set;
const int nax=105;
//const int nax1 = 105;


int main()
{
	FASTIO;
	int n,w;
	cin >> n >> w;
	vector<int> weight(n);
	vector<int> value(n);
	for(int i=0;i<n;i++){
		cin >> weight[i] >> value[i];
	}
	
	vector<ll> dp(w+1);
	
	int w1,v1;
	for(int item=1;item<=n;item++){
		w1 = weight[item-1];
		v1 = value[item-1];
		
		for(int i=w-w1;i>=0;--i){
			dp[i+w1] = max(v1+dp[i], dp[i+w1]);
		}
	}

	
	cout << dp[w] << "\n";
	return 0;
}


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

int h[111111], x[111111];
int main() {
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++)
        cin >> h[i + 1];
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        if(h[a] > h[b])
            swap(a, b);
        x[a]++;
        if(h[a] == h[b])
            x[b]++;
    }
    int r = 0;
    for(int i = 0; i < n; i++)
        if(!x[i + 1])
            r++;
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 4420
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    import bisect
    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 b in B:
        i=bisect.bisect_left(A,b)
        j=bisect.bisect_right(C,b)
        ans+=i*(n-j)
    print(ans)
resolve()

Measured memory_bytes: 96056
#include<bits/stdc++.h>
#define re register
#define int long long
using namespace std;
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int n,a[200002],ans,b[200002];
signed main(){
	n=read();
	for(re int i=1;i<=n;++i)++a[b[i]=read()];
	for(re int i=1;i<=n;++i){
		ans+=(a[i]*(a[i]-1))/2;
	}
	for(re int i=1;i<=n;++i)printf("%lld\n",ans-a[b[i]]+1);
}


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

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

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

    vector<string> s;
    for(int i=0;i<h;++i){
        string str;
        cin >> str;
        s.push_back(str);
    }

    bool ok = true;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            if(s[i][j] != '#')continue;
            bool flag = false;
            for(int k=0;k<4;++k){
                int nx = j+dx[k], ny = i+dy[k];
                if(nx < 0 || nx >= w || ny < 0 || ny >= h)continue;
                if(s[ny][nx] == '#'){
                    flag = true;
                    break;
                }
            }
            if(!flag){
                ok = false;
                i = h;
                j = w;
            }
        }
    }

    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;


// ===========Disjoint Set Union================
struct dsu {
  public:
    dsu() : _n(0) {}
    dsu(int n) : _n(n), parent_or_size(n, -1) {}

    int merge(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y) return x;
        if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(int a) {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0) return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }

    int size(int a) {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    std::vector<std::vector<int>> groups() {
        std::vector<int> leader_buf(_n), group_size(_n);
        for (int i = 0; i < _n; i++) {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        std::vector<std::vector<int>> result(_n);
        for (int i = 0; i < _n; i++) {
            result[i].reserve(group_size[i]);
        }
        for (int i = 0; i < _n; i++) {
            result[leader_buf[i]].push_back(i);
        }
        result.erase(
            std::remove_if(result.begin(), result.end(),
                           [&](const std::vector<int>& v) { return v.empty(); }),
            result.end());
        return result;
    }

  private:
    int _n;
    // root node: -1 * component size
    // otherwise: parent
    std::vector<int> parent_or_size;
};
// =======================================

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, M;
  cin >> N >> M;
  dsu d(N);
  for (ll i = 0; i < M; ++i) {
    ll a, b;
    cin >> a >> b;
    a -= 1, b -= 1;
    d.merge(a, b);
  }
  vector<vector<int>> g = d.groups();
  cout << g.size() - 1 << "\n";
}


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

int cmp(const int *a,const int *b){
  if(*a>*b){
    return 1;
  }
  else if(*a<*b)
  return -1;
  else return 0;
}

int main(void){
  int n;
  int half;
  int i=0;
  scanf("%d",&n);
  char s[n];
  scanf("%s",s);
  if(n%2==1){
    printf("No");
    return 0;
  }
  else{
    half=n/2;
  }
  for(i=0;i<half;i++){
    if(s[i]!=s[half+i]){
      printf("No");
      return 0;
    }
  }
  printf("Yes");

return 0;
}


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

using namespace std;

int N, M;
int MapData[2020];

int main() {
	int a, nPos;
	bool flag;

	memset(MapData, 0, sizeof(MapData));
	cin >> N;
	for (int i = 1; i <= N; ++i) {
		cin >> MapData[i];
	}

	cin >> M;
	for (int i = 0; i < M; ++i) {
		cin >> a;
		if (MapData[a] > 2018) {
			continue;
		}
		flag = false;
		nPos = MapData[a] + 1;
		for (int j = 1; j <= N; ++j) {
			if (MapData[j] == nPos) {
				flag = true;
				break;
			}
		}
		if (flag) {
			continue;
		}
		MapData[a] = nPos;
	}
	for (int i = 1; i <= N; ++i) {
		cout << MapData[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 3120
#require 'benchmark'
M=998244353
#n,xs,ds,ys,n2,zs,fr,cs=[]
#Benchmark.bm(6,"total:","avg:"){|bm|
#bm.report("input"){
n=gets.to_i
xs,ds=[],[]
tmp=$<.read.split.map(&:to_i)
(0...n).sort_by{|i| tmp[i*2] }.each{|i| xs.push(tmp[i*2]); ds.push(tmp[i*2+1]) }
#}
#p n,xs,ds
#bm.report("setup"){
ys=(0...n).map{|i|
  sup=xs[i]+ds[i]
  n+( (i+1-n..-1).bsearch{|j| xs[n+j]>=sup } || 0 )
}
#}
#p ys
#bm.report("build"){
n2=1<<1+n.bit_length
zs=[]
fr=->b,e{
  w=1<<(b^e).bit_length-1
  rm=b&e&~(w-1)|w
  ret=-1
  rt,wt=rm,w
  while b<rt
    if b<=rt-wt
      t=zs[n2-(n2-rt)/wt-1]
      ret=t if t>ret
      rt-=wt
    end
    wt>>=1
  end
  rt,wt=rm,w
  while rt<e
    if rt+wt<=e
      t=zs[n2-(n2-rt)/wt]
      ret=t if t>ret
      rt+=wt
    end
    wt>>=1
  end
  ret
}
(n-1).downto(0){|i|
  zs[i]=zprev=ys[i]==i+1 ? i+1 : fr[i+1,ys[i]]
  break if i==0
  iprev,n2t=i,n2
  while i&1==0
    i>>=1
    n2t>>=1
    inext=n2-n2t+i
    t=zs[iprev+1] or break
    zprev=t if t>zprev
    zs[inext]=zprev
    iprev=inext
  end
}
#}
#p zs
#bm.report("finish"){
cs=[0]*(n+1)
cs[0]=1
(0...n).each{|i|
  cs[i+1]=(cs[i+1]+cs[i])%M
  cs[zs[i]]=(cs[zs[i]]+cs[i])%M
}
#p cs
#}
#}
puts cs[n]

Measured memory_bytes: 49956
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;
constexpr int mod = 1e9 + 7;

int main(){ 
  int n;
  cin >> n;
  int res = 0;
  rep(i,n) {
    int a;
    cin >> a;
    if (i % 2 == 0 && a % 2 == 1) res++;
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 3592
#include<stdio.h>
#include<stdlib.h>

int sort(const void * a, const void * b);

int main(void)
{
	int i;
	int n[10];
	
	for(i = 0;i < 10;i++){
		scanf("%d", &n[i]);
	}
	
	qsort(n, 10, sizeof(n[0]),sort);
	
	printf("%d\n%d\n%d\n", n[0], n[1], n[2]);
	
	return (0);
}

int sort(const void * a, const void * b)
{
	if(*(int *)a < *(int *)b){
		return 1;
	}
	else if(*(int *)a > *(int *)b){
		return -1;
	}
	else {
		return 0;
	}
}

Measured memory_bytes: 604
from sys import stdin
from collections import defaultdict
from math import gcd


def main():
    MOD = 1000000007

    N, *AB = map(int, stdin.buffer.read().split())

    d = defaultdict(int)
    n_zeros = 0

    for a, b in zip(AB[::2], AB[1::2]):
        if a == 0 and b == 0:
            n_zeros += 1
            continue

        g = gcd(a, b)
        a, b = a // g, b // g

        if a * b > 0 or b == 0:
            c = (abs(a), abs(b))
        else:
            c = (-abs(a), -abs(b))

        d[c] += 1

    ans = 1
    n_not_paired = 0
    for ab, n in d.items():
        ab_pair = (-ab[1], -ab[0])
        if ab_pair in d:
            if ab[0] > 0:
                m = d[ab_pair]
                ans = ans * (pow(2, n, MOD) + pow(2, m, MOD) - 1) % MOD
        else:
            n_not_paired += n

    ans = (ans * pow(2, n_not_paired, MOD) + n_zeros - 1) % MOD
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 74104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int m=scan.nextInt();
		char a[][]=new char[n][n];
		char b[][]=new char[m][m];
		for(int i=0;i<n;i++){
			String str=scan.next();
			a[i]=str.toCharArray();
		}
		for(int i=0;i<m;i++){
			String str=scan.next();
			b[i]=str.toCharArray();
		}
		scan.close();
		int check=0;
		for(int i=0;i<n-m;i++) {
			for(int j=0;j<n-m;j++) {
				check=0;
				for(int k=0;k<m;k++) {
					for(int l=0;l<m;l++) {
						if(a[i+k][j+l]!=b[k][l]) {
							check=-1;
							break;
						}
					}
					if(check==-1)break;
				}
				if(check==0)break;
			}
			if(check==0)break;
		}
		System.out.println((check==0)? "Yes":"No");

	}
}

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

#define int long long

#define INF 4611686016279904256LL
#define MAX_V 100000

struct edge { int to, cost; };
typedef pair<int, int> P;

int V;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d + V, INF);
    d[s] = 0;
    que.push(P(0, s));
    
    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

signed main() {
    cin >> V;
    for (int i = 0; i < V - 1; i++) {
        int a, b; ll c;
        cin >> a >> b >> c;
        edge e1; e1.to = b - 1; e1.cost = c;
        edge e2; e2.to = a - 1; e2.cost = c;
        G[a - 1].push_back(e1);
        G[b - 1].push_back(e2);
    }
    int q, k;
    cin >> q >> k;
    dijkstra(k - 1);
    for (int i = 0; i < q; i++) {
        int x, y;
        cin >> x >> y;
        cout << d[x - 1] + d[y - 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 11120
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
//const ll MOD = 1e9 + 7;
const ll MOD = 998244353;



int main() {
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		ll n, m, a, b;
		cin >> n >> m >> a >> b;

		cout << floor_sum(n, m, a, b) << endl;
	}

} 

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

int find(int n){
  int sum=0;
  while(n>0){
    sum += n%10;
    n/=10;
  }
  return sum;
}


int main(){
  int n,a,b;
  cin>>n>>a>>b;
  int total=0;
  for(int i=1;i<=n;++i){
    int sum=find(i);
    if(sum>=a&&sum<=b){
      total += i;    }
  }
  cout<<total<<endl;
}


Measured memory_bytes: 256
input = raw_input
s = input().strip()
t = input().strip()

NS = len(s)
NT = len(t)

dp = [[0] * (NT+2) for i in range(NS+2)]
dp2 = [[""] * (NT+2) for i in range(NS+2)]

for i in range(1,NS+1):
    for j in range(1,NT+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = max(dp[i-1][j-1]+1, dp[i-1][j], dp[i][j-1])
            if dp[i-1][j-1]+1 > dp[i-1][j] and dp[i-1][j-1]+1 > dp[i][j-1]:
                dp2[i][j] = dp2[i-1][j-1] + s[i-1]
            elif dp[i-1][j] > dp[i][j-1]:
                dp2[i][j] = dp2[i-1][j]
            else:
                dp2[i][j] = dp2[i][j-1]
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])
            if dp[i-1][j] > dp[i][j-1]:
                dp2[i][j] = dp2[i-1][j]
            else:
                dp2[i][j] = dp2[i][j-1]
print(dp2[NS][NT])


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

int main(){
	int n,m;
	while( cin >> n >> m , n|m){
		int a[2001]={},b[2001]={};
		for(int i=0 ; i<n ; ++i ){
			cin >> a[i];
		}
		for(int i=0 ; i<m ; ++i ){
			cin >> b[i];
		}
		int ans = 0, pos = 0;
		while( pos < n-1 ){
			pos += b[ans];
			pos += a[pos];
			ans++;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    ll x,y;
    cin >> x >> y;
    cout << (abs(x-y)<=1?"Brown":"Alice") << endl;
    return 0;
}

Measured memory_bytes: 3608
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Random;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		PrintWriter pw=new PrintWriter(System.out);
		int A=sc.nextInt();
		int B=sc.nextInt();
		int C=sc.nextInt();
		pw.println((A+B>=C)?"Yes":"No");
		pw.close();
	}

	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public int nextInt() {
    	return Integer.parseInt(next());
    }
    
    public long nextLong() {
    	return Long.parseLong(next());
    }
}

Measured memory_bytes: 21204
#18:29
n = int(input())
mod = 10 ** 9 + 7
now = [[[0 for _ in range(4)] for _ in range(4)] for _ in range(4)]
now[3][3][3] = 1
#print(part)
boo = [[0,0,1,2],[1,0,1,2],[2,0,1,2],[3,0,1,2],
       [0,0,1,2],[0,1,1,2],[0,2,1,2],[0,3,1,2],
       [0,1,0,2],[0,1,1,2],[0,1,2,2],[0,1,3,2],
       [0,1,0,2],[1,1,0,2],[2,1,0,2],[3,1,0,2],
       [0,0,2,1],[1,0,2,1],[2,0,2,1],[3,0,2,1]]
#print(now)
for i in range(n):
  last = now
  now = [[[0 for _ in range(4)] for _ in range(4)] for _ in range(4)]
  #print(i,'l',last)
  #print(i,'n',now)
  for i in range(4):
    for j in range(4):
      for k in range(4):
        for l in range(4):
          if [i,j,k,l] not in boo:
            now[j][k][l] += last[i][j][k]
            now[j][k][l] %= mod
ans = 0
for i in range(4):
  for j in range(4):
    for k in range(4):
      ans += now[i][j][k]
      ans %= mod
#print(last)
#print(now)
print(ans)

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

//===============typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef set<int> si;
typedef map<string, int> msi;
//=================
const  ll mod=1e9+7;


//=============define
#define inf 10000000
#define cln(a) memset(a,0,sizeof a);
#define clni(a) memset(a,inf,sizeof a);
#define all(x) x.begin(), x.end()
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define sp(c,x) ((c).find(x) != (c).end())  // for set,map
#define vp(c,x) (find(all(c),x) != (c).end())  // for vector
#define uu first
#define vv second
#define fr(i,a,b) for(int i=int(a);i<int(b);++i)
#define nfr(i,a,b) for(int i= int(a);i>=int(b);--i)
#define tc cin>>t ; while(t--)
#define pc()  cout<<"Case "<<cs++<<": "
#define mx (int)1e5+10
#define sc2(x,y) scanf("%d %d",&x,&y)
#define sc3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sc(x) scanf("%d",&x)
#define pfs(x) printf("%d ",x)
#define pf(x) printf("%d\n",x)
#define el puts("");
#define getcx() getchar()
#define Fi freopen("inp.txt","r",stdin)
#define rt return 0
#define dbg(x) cerr<<x<<endl
//============functions
ll bigmod(ll a,ll b)
{
    ll ans=1;
    while(b)
    {
    if(b&1)
    ans=(ans*a)%mod;
    a=(a*a)%mod;
    b>>=1;
    }
    return ans;
}

int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0}; 
//int vis[505][505];
//int vis[505]
//string s[505];
bitset<2005*2005>bit;
void dfs(int u,int v)
{

}
int main()
{
	int n,x;
	sc(n);
	ll sum=0;
	bit[0]=1;
	while(n--)
	{
		sc(x);
		sum+=x;
		bit|=bit<<x;
	}
	for(int i=(sum+1)/2;i<=sum;i++)
	{
		if(bit[i])
		{
			return cout<<i,0;
		}
	}

}           

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

int R;
int main()
{
    cin >> R;
    if( R < 1200 ) {
        cout << "ABC" << endl;
    }
    else if( R < 2800 ) {
        cout << "ARC" << endl;

    } else {
    cout << "AGC" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1){
		cerr << name << " : " << arg1 << std::endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args){
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
	}
#else
#define debug(...)
#endif
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define rall(c) c.rbegin(), c.rend()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
#define init(a, x) memset(a,x,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
// ordered_set X
//K-th smallest
//*X.find_by_order(k-1)
//NO OF ELEMENTS < A
//X.order_of_key(A)
const int L=1e3+7;
ll dp[L][L];
string s[L];
ll h, w, m = 1e9 + 7;
ll solve(int i, int j)
{
	if(i==h-1 && j==w-1)return 1;
	if(i>=h || j>=w)return 0;
	if(s[i][j] == '#')return 0;
	if(dp[i][j] != -1)return dp[i][j];
	ll &ret = dp[i][j];
	ret = 0;
	ret += solve(i+1,j);
	ret %= m;
	ret += solve(i,j+1);
	ret %= m;
	return ret;
}
void fff()
{
	init(dp, -1);
	cin >> h >> w;
	FOR(i,0,h)cin >> s[i];	
	cout<<solve(0,0);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//int t;cin >> t;while(t--)
	fff();
	return 0;
}

Measured memory_bytes: 12612
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
	int n,m;
	cin >> n >> m;
	int b[1001],c[1001];
	int score[1001]={0};
	for(int i=0;i<n;i++){
		cin >> b[i];
	}
	for(int i=0;i<m;i++){
		cin >> c[i];
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			if(c[i]>=b[j]){
				score[j]++;
				break;
			}
		}
	}
	int ans = 0;
	int pos = 0;
	for(int i=0;i<n;i++){
		if(ans < score[i]){
			ans = score[i];
			pos = i+1;
		}
	}
	cout << pos << endl;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,a,b;

int main(){
	cin >> n >> a >> b;
	
	cout << n-(n-a)/b*b-a << endl;
	return 0;
}


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

#define int long long
int start[100005], end[100005];
int times[100005];
int n,m;

signed main(void){
	ios::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.inp","r",stdin);
	cin>>n>>m;
	int from,to;
	cin>>to;
	for (int i=0; i<m-1; i++){
		from=to;
		cin>>to;
		start[i]=min(from-1,to-1);
		end[i]=max(from-1,to-1);
	}
	sort(start,start+m-1);
	sort(end,end+m-1);
	int pts=0,pte=0;
	int cur=0;
	int real_cost=0;
	for (int i=0; i<n-1; i++){
		int cost1,cost2,cost3;
		while (i==start[pts]&&pts<m-1){
			cur++;
			pts++;
		}
		while (i==end[pte]&&pte<m-1){
			cur--;
			pte++;
		}
		cin>>cost1>>cost2>>cost3;
		real_cost+=min(cur*cost1,cost3+cur*cost2);
	}
	cout<<real_cost<<endl;
	return 0;
}

Measured memory_bytes: 4700
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define DEBUG true
#define $(x) {if (DEBUG) {cout << #x << " = " << (x) << endl;}}

 VI listDivisors(LL n) {
    VI divs;
    FOR(i, 1, (LL)(sqrt(n) + 1)) {   // {1, n} を除く場合は2番目の引数を 2 にする
        if (n % i == 0) {
            divs.PB(i);
            divs.PB(n / i);
        }
    }
    SORT(divs);
    return divs;
}

inline LL nDigit(LL N) {
    LL ret = 0;
    while (N > 0) {
        ret++;
        N /= 10;
    }
    return ret;
}


int main() {
    LL N;
    cin >> N;
    VI divs = listDivisors(N);
    cout << nDigit(divs[SZ(divs) / 2]) << endl;

    return 0;
}


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

int F(int x) {
	int res = 0;
	while (x > 0) {
		res += x % 10;
		x /= 10;
	}
	return res;
}

int main() {
	int n;
	
	ignore = scanf("%d", &n);
	
	int ans = 11111111;
	
	for (int a = 1; a < n; a++) {
		int b = n - a;
		int cur = F(a) + F(b);
		ans = min(ans, cur);
	}
	
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            long[] a = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            Array.Sort(a);
            Array.Reverse(a);
            long alice = 0;
            for (int j = 0; j < N; j = j + 2)
            {
                //偶数アリス
                alice += a[j];
            }
            Console.WriteLine(alice - (a.Sum() - alice));
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();


Measured memory_bytes: 28228
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define REP(i,j,n) for(int i = j;i < (n);i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl


int main(){
  ll N, M, K;
  cin >> N >> M >> K;
  string ans = "No";
  rep(i,N+1){
    rep(j,M+1){
      ll cnt = i*M + j*N - 2*i*j;
      if(cnt == K){
        ans = "Yes";
        break;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
/*
 ============================================================================
 Name        : AtCoder.c
 Author      :
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>

int main(void){
	int n,k,x,y,omega;
	fflush(0);
	scanf("%d\n%d\n%d\n%d",&n,&k,&x,&y);
	if(n-k>0){
		omega=(n-k)*y+k*x;
	}else{
		omega=n*x;
	}
	printf("%d\n",omega);
	return 0;
}


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

class Main {
    static Scanner scanner = new Scanner();

    static int dx, dy;
    static boolean swap;
    public static void main(String[]$) {
        int k = scanner.nextInt();
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        dx = x < 0 ? -1 : 1;
        dy = y < 0 ? -1 : 1;
        x = Math.abs(x);
        y = Math.abs(y);
        if (x < y) {
            int t = x;
            x = y;
            y = t;
            swap = true;
        }
        int n = (int)Math.ceil((double)(x + y) / k);
        if (k % 2 == 0 && (x + y) % 2 == 1) {
            System.out.println(-1);
            return;
        } else if (x + y < k) {
            if ((x + y) % 2 == 1) {
                System.out.println(3);
                print(x, x - k);
                print(x + (k + x - y) / 2, x - k + (k - x + y) / 2);
                print(x, y);
                return;
            } else {
                n = 2;
            }
        } else if ((k - (x + y) % k) % k % 2 == 1) {
            n++;
        }
        System.out.println(n);
        int m = (k * n - x - y) / 2;
        for (int i = 1; i <= n; i++) {
            if (m > k * i) {
                print(0, -k * i);
            } else if (x + m > k * i) {
                print(k * i - m, -m);
            } else {
                print(x, k * i - 2 * m - x);
            }
        }
    }

    static void print(int x, int y) {
        System.out.println(swap ? dx * y + " " + dy * x : dx * x + " " + dy * y);
    }

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

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

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

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

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

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

#define MAX 10
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define REP(i, a, b) for(int i = a; i >= b; i--)

int m, n, k;
char a[MAX][MAX];

int main() {
    //freopen("main.inp", "r", stdin);
    cin >> m >> n >> k;
    FOR(i, 1, m) cin >> a[i] + 1;
    int ans = 0;
    FOR(x, 0, (1 << m) - 1)
        FOR(y, 0, (1 << n) - 1) {
           int res = 0;
           FOR(i, 1, m)
               FOR(j, 1, n)
                  if(!((x >> (i - 1)) & 1))
                      if(!((y >> (j - 1)) & 1))
                         res += (a[i][j] == '#');
           if(res == k) ans++;
        }
    cout << ans;
}


Measured memory_bytes: 3512
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans, cnt;


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

	int N;
	cin >> N;

	vector<ll> a(3*N);
	rep(i, 3*N) {
		cin >> a[i];
	}

	sort(a.begin(), a.end(), greater<ll>());

	int index = 1;
	while (true) {
		if (cnt == N) {
			break;
		}
		ans += a[index];
		index += 2;
		cnt++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define INF 0x3f3f3f3f
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
const ll mod=1000000007;
const double PI = acos(-1.0);
const double epsilon = PI / 180.0;//角度转弧度 
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N = 1e3+10;
string s = "abcdefghijklmnopqrstuvwxyz";
int main() {
	ll a;
	cin>>a;
	string ans = "";
	while(a) {
		a--;
		ans += s[a % 26];
		a /= 26;
	}
	reverse(ans.begin(), ans.end());
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3632
fun main(args: Array<String>) {
    fun divisor(n: Long): List<Long> {
        val list = mutableListOf<Long>()
        var i = 1L
        while (i * i <= n) {
            if (n % i == 0L) {
                list.add(i)
                if (i != n / i) {
                    list.add(n / i)
                }
            }
            i++
        }
        return list.sortedDescending()
    }

    val (n, k) = readLine()!!.split(' ').map(String::toLong)
    val aList = readLine()!!.split(' ').map(String::toLong)
    val divList = divisor(aList.sum())

    for (div in divList) {
        val modList = aList.map { it % div }.filter { it != 0L }.sorted()
        val modDivList = modList.map { div - it }
        if(modList.isEmpty()){
            println(div)
            return
        }else if(modList.size == 1){
            continue
        }
        
        val modRuiseki = mutableListOf(modList[0])
        (1 until modList.size).forEach { modRuiseki.add(modList[it] + modRuiseki[it - 1]) }
        val modDivRuiseki = mutableListOf(modDivList.last())
        (modDivList.size -2 downTo 0).forEach { modDivRuiseki.add(0,modDivList[it] + modDivRuiseki[0]) }

        for(i in 0 until modRuiseki.size-1){
            if(modRuiseki[i]<=k &&  modRuiseki[i]==modDivRuiseki[i+1]){
                println(div)
                return
            }
        }
    }
    println(1)
}


Measured memory_bytes: 74648
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
    int n, q;
    cin >> n >> q;
    vector< queue<int> > v(n);
    for(int i = 0; i < q; i++){
	  int cmd;
	  cin >> cmd;
	  if (cmd == 0){
		  int t, x;
		  cin >> t >> x;
		  v[t].push(x);  
		}
      if (cmd == 1){
		  int t;
		  cin >> t;
		  if (!v[t].empty()) cout << v[t].front() << endl;
		}
      if (cmd == 2){
		  int t;
		  cin >> t;
		  if (!v[t].empty()) v[t].pop();
		 }	
   }	
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



Measured memory_bytes: 5052