akhauriyash/Code-Regression huggingface dataset:
n = int(input())
strs = [input() for _ in range(n)]

cnt = 0
enda = 0
startb = 0
ba = 0
for s in strs:
    cnt += s.count("AB")
    enda += 1 if (s[-1] == "A") else 0
    startb += 1 if (s[0] == "B") else 0
    ba += 1 if (s[0] == "B" and s[-1] == "A") else 0

cnt -= 1 if (ba != 0 and enda == ba and startb == ba) else 0

print(cnt + min(enda, startb))


Measured memory_bytes: 3700
n, m = map(int,input().split())
num = [0 for i in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    num[a-1] += 1
    num[b-1] += 1

for i in num:
    if i%2 == 1:
        print("NO")
        exit()

print("YES")


Measured memory_bytes: 3888
package main

import (
	"fmt"
	"os"
	"sort"
)

func run() int {
	var n int
	fmt.Scanf("%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	sort.Ints(a)

	for i := 0; i < len(a)-1; i++ {
		if a[i] == a[i+1] {
			fmt.Println("NO")
			return 0
		}
	}

	fmt.Println("YES")

	return 0
}

func main() {
	os.Exit(run())
}


Measured memory_bytes: 5632
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<list>
#include<stack>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;

int main(){
	int N,M;
	while(cin>>N>>M,N||M){
		bool is_die[1000]={};
		for(int i=0,cntM=1,cntH=N;;i=++i%N){
			if(is_die[i]==true) continue;
			if(cntH==1){
				printf("%d\n",i+1);
				break;
			}
			if(cntM==M){
				is_die[i] = true;
				cntH--;
				cntM = 0;
			}
			cntM++;
		}
	}
	return 0;
}

Measured memory_bytes: 1144
using System;

class Program{
    static void CountingSort(int[] A, int[] B, int k){
        var C=new int[k+1];
        for(var j=0; j<A.Length; j++){
            C[A[j]]++;
        }
        var remain=B.Length-1;
        for(; k>=0; k--){
            while(C[k]>0){
                B[remain]=k;
                remain--;
                C[k]--;
            }
        }
    }

    public static void Main(){
        var n=int.Parse(Console.ReadLine());
        var s=Console.ReadLine().Split(' ');
        var A=new int[n];
        var k=-1;
        for(var i=0; i<n; i++){
            A[i]=int.Parse(s[i]);
            if(A[i]>k){
                k=A[i];
            }
        }

        var B=new int[n];
        CountingSort(A, B, k);

        /*
        for(var i=0; i<B.Length; i++){
            Console.Write(B[i]);
            if(i>=B.Length-1){
                Console.WriteLine();
            } else{
                Console.Write(" ");
            }
        }
        */
        var ss=new System.Text.StringBuilder();
        for(var i=0; i<B.Length; i++){
            ss.Append(B[i]);
            if(i<B.Length-1){
                ss.Append(" ");
            }
        }
        Console.WriteLine(ss);
    }
}

Measured memory_bytes: 225396
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;

public class Main {
    private static Scanner sc;

    public Main() {
    }

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

    }

    private void solve() {
        int N = sc.nextInt();
        int K = sc.nextInt();
        int sum = 0;
        Set<Integer> set = new HashSet<Integer>();
        HashMap<Integer, Integer> m = new HashMap<Integer, Integer>();
        for (int i = 0; i < N; i++) {
            int now = sc.nextInt();
            if (m.containsKey(now)) {
                m.put(now, m.get(now) + 1);
            } else {
                m.put(now, 1);
            }
            set.add(now);
        }

        for (Integer i : m.values()) {
            sum += i;
        }

        List<Entry<Integer, Integer>> list_entries = new ArrayList<Entry<Integer, Integer>>(m.entrySet());

        // 3.比較関数Comparatorを使用してMap.Entryの値を比較する(昇順)
        Collections.sort(list_entries, new Comparator<Entry<Integer, Integer>>() {
            public int compare(Entry<Integer, Integer> obj1, Entry<Integer, Integer> obj2) {
                // 4. 昇順
                return obj1.getValue().compareTo(obj2.getValue());
            }
        });

        sum = set.size();
        if (sum <= K) {
            System.out.println(0);
        } else {
            int i = 0;
            int cnt = 0;
            while (true) {
                sum--;
                cnt += list_entries.get(i).getValue();
                i++;
                if (sum <= K) {
                    break;
                }
            }
            System.out.println(cnt);
        }
    }
}


Measured memory_bytes: 108312
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
typedef long long int ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

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

    bool shizurai(false);
    for(int i=0;i<s.size();i++){
        if(s[i] == s[i+1]) shizurai = true;
    }
    
    if(shizurai) cout << "Bad" << endl;
    else cout << "Good" << endl;

    return 0;
}

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

using namespace std;
using ll= long long;

ll dp[2][3005][3005];
int n;
ll a[3005];

ll dfs(int t, int x, int y){
    if(dp[t][x][y] != -1) return dp[t][x][y];
    if(x==y){
        return dp[t][x][y] = (1-2*t) * a[x];
    }
    if(t==0){
        return dp[t][x][y] = max(dfs(1-t, x+1, y) + a[x], dfs(1-t, x, y-1) + a[y]);
    }
    return dp[t][x][y] = min(dfs(1-t, x+1, y)-a[x], dfs(1-t,x,y-1) -a[y]);
}

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

    cin>>n;
    memset(dp, -1, sizeof(dp));
    for(int i=0;i<n;i++){
        cin>>a[i];
    }

    ll res = dfs(0, 0, n-1);
    cout<<res;

    return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  set<string> x;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    x.insert(s);
  }
  
  cout << x.size() << '\n';
}

Measured memory_bytes: 19140
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    print(n**3)
    return

#B
def B():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    ans = sum(b)
    for i in range(n-1):
        x = a[i]
        y = a[i+1]
        if y == x+1:
            ans += c[x-1]
    print(ans)
    return

#C
def C():
    n = I()
    b = LI()
    b.append(float("inf"))
    a = [min(b[i],b[i-1]) for i in range(n)]
    print(sum(a))
    return

#D
def D():
    n,k = LI()
    a = S()
    ans = 0
    for i in range(n-1):
        if a[i] == a[i+1]:
            ans += 1
    print(min(n-1,ans+2*k))
    return

#E
def E():
    def add(i):
        while i < len(bit):
            bit[i] += 1
            i += i&-i

    def sum(i):
        res = 0
        while i > 0:
            res += bit[i]
            i -= i&-i
        return res

    n = I()
    p = LI()
    p = [(p[i],i+2) for i in range(n)]
    p.sort(key = lambda x:-x[0])
    bit = [0]*(n+3)
    add(p[0][1])
    ans = 0
    for pi,i in p[1:]:
        s = sum(i)
        l = 0
        r = i
        while r-l > 1:
            m = (l+r)>>1
            if sum(m) == s:
                r = m
            else:
                l = m
        x1 = r

        l = i
        r = n+2
        while r-l > 1:
            m = (l+r)>>1
            if sum(m) == s:
                l = m
            else:
                r = m
        x2 = r

        s_ = s-1
        l = 0
        r = x1
        while r-l > 1:
            m = (l+r)>>1
            if sum(m) == s_:
                r = m
            else:
                l = m
        x3 = r

        s_ = s+1
        l = x2
        r = n+2
        while r-l > 1:
            m = (l+r)>>1
            if sum(m) == s_:
                l = m
            else:
                r = m
        x4 = r
        ans += pi*((x1-x3)*(x2-i)+(x4-x2)*(i-x1))
        add(i)
    print(ans)
    return

#F
def F():
    n = I()
    s = LI()
    s.sort()
    s = s[::-1]
    m = 1<<n
    f = [-1]*m
    f[0] = 0
    for i in range(n):
        k = 0
        l = 0
        for j in range(1<<i):
            while f[k] != i:
                k += 1
            while f[l] >= i or s[k] <= s[l]:
                l += 1
                if l == m:
                    print("No")
                    return
            f[l] = i+1
            k += 1
        for j in range(m):
            if f[j] >= 0:
                f[j] = i+1
    print("Yes")
    return

#Solve
if __name__ == "__main__":
    E()


Measured memory_bytes: 64288
#include<iostream>
#include<cstring>

using namespace std ;


bool sg[ 260 ][ 260 ] ;


int maxy ;
int n ;


int map[ 260 ] ;

void yuki(int now)
{
	int i,x;

	for(i=1;i<=maxy;i++)
	{
		x=now+i;
		x=x+map[x];

				if(x<=0) x=0;

				if(x>=n+1) x=n+1;
		if(sg[now][x])continue;
		sg[now][x]=true;

		if(x==0) continue ;
		if(x>=n+1) continue ;  // owari
		yuki(x);

	}

	return ;
}

void kaeri( int end )
{
	int i;
	for(i=0;i<=n;i++)
	{
		if(sg[i][end])
		{
			sg[i][end] = false;
			kaeri( i );
		}
	}
	return ;

}

int main()
{
	int i,j;
	
	while( 1 )
	{
		int flag = 0 ;

		cin >> maxy ;

		if( maxy == 0 )
		{
			return 0 ;
		}


		cin >> n ;


		for(i=1;i<=n;i++)
		{
			cin >> map[i];
		}

		yuki(0);
		/*for(i=0;i<=n;i++)
		{
			for(j=0;j<=n+1;j++)
			{
				cout << sg[ i ][ j ] << " " ;
			}	
			cout << endl ;
		}*/
                
		kaeri(n+1);
/*
cout << endl ;


		for(i=0;i<=n;i++)
		{
			for(j=0;j<=n+1;j++)
			{
				cout << sg[ i ][ j ] << " " ;
			}	
			cout << endl ;
		}*/





		for(i=0;i<=n;i++)
		{
			for(j=0;j<=n+1;j++)
			{
				if(sg[i][j])
				{
					cout << "NG\n" ;

					break ;
				}
			}

			if(sg[i][j])
			{
				++flag ;

				break ;
			}
		}

		if( flag == 0 )
		{
			cout << "OK\n";
		}

		memset( map ,0 ,sizeof map ) ;
		memset( sg ,false ,sizeof sg ) ;
	}
}

Measured memory_bytes: 3148
s = list(input())
t = list(input())

dp = [[0] * (len(t) + 1) for i in range(len(s) + 1)]
num = []

for i in range(len(s)):
  for j in range(len(t)):
    if(s[i] == t[j]):
      dp[i + 1][j + 1] = dp[i][j] + 1
    else:
      dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1], dp[i + 1][j + 1])

ans = ''
i = len(s)
j = len(t)

while(j > 0 and i > 0):
  if(dp[i - 1][j] == dp[i][j]):
    i -= 1
  elif(dp[i][j - 1] == dp[i][j]):
    j -= 1
  else:
    ans += s[i - 1]
    i -= 1
    j -= 1

print(ans[::-1])


Measured memory_bytes: 112860
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

void solve()
{
  ll n;
	cin>>n;
	vector<ll>a(n);
	rep(i,n)cin>>a[i];
	ll x=0;
	rep(i,n)x^=a[i];
	rep(i,n){
		if(i)cout<<" ";
		cout<<(x^a[i]);
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 4716
import java.util.Scanner;

class Main {
    public static void main (String[] arg) {
        int N, K;

        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        K = scanner.nextInt();
        scanner.close();

        int b = K - 1;

        System.out.println(N - b);
    } 
}

Measured memory_bytes: 21844
import java.util.*;

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

		int a = sc.nextInt();
		int b = sc.nextInt();

		if (a>9 || a<1 || b>9 || b<1)
			System.out.print (-1);
		else
			System.out.print (a*b);

	}
}

Measured memory_bytes: 24916
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}
int main() {
  uint64_t N;
  cin >> N;

  uint32_t flag = 0;
  for (uint32_t i = 1; i <= 9; ++i) {
    for (uint32_t j = 1; j <= 9; ++j) {
      if (i * j == N) flag = 1;
    }
  }
  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    int[] p = new int[n + 2];

    int outOfOrder = 0;

    for (int i = 0; i < n; ++i) {
      p[i] = sc.nextInt();
      if (outOfOrder == 0 && p[i] != i + 1)
        outOfOrder = 1;
      else if (outOfOrder == 1 && p[i] != i + 1) {
        if (p[p[i] - 1] == i + 1)
          outOfOrder = 2;
        else
          outOfOrder = -1;
      } else if (p[i] != i + 1)
        outOfOrder = -1;
    }

    if (outOfOrder == -1)
      System.out.println("NO");
    else
      System.out.println("YES");

  }
}

Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		final int N = s.nextInt();

		int[] cards = new int[N];
		long grandTotal = 0;
		for(int i = 0; i < N; i++) {
			cards[i] = Integer.parseInt(s.next());
			grandTotal += cards[i];
		}
		s.close();

		long subTotal = 0;
		long min = (int)Math.pow(10.0, 9.0) * 2;
		for(int i = 0; i < N-1; i++) {
			subTotal += cards[i];
			long sa = grandTotal - subTotal*2;
			if(sa<0) sa = -sa;

			if(sa < min) {
				min = sa;
			}
		}
		System.out.println(min);

	}

}


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

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

using ll = long long;
using P = pair<int,int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

int main() {
    ll N;
    cin>>N;
    ll ans = 0;
    for(ll i = 1; i*i+i<=N; i++){
        if(N%i!=0) continue;
        if(N/i-1>i) ans += N/i-1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

struct UnionFind {
  vector<int> par;  // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N) {  //最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++) par[i] = i;
  }

  int root(int x) {  // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {  // xとyの木を併合
    int rx = root(x);         // xの根をrx
    int ry = root(y);         // yの根をry
    if (rx == ry) return;  // xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] =
        ry;  // xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(int x, int y) {  // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  map<int, vector<int>> mp;
  UnionFind friends(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    friends.unite(a, b);
  }
  int ans = 0;
  map<int, int> x;
  for (int i = 0; i < n; i++) {
    x[friends.root(i)]++;
  }
  for (auto i = x.begin(); i != x.end(); i++) {
    ans = max((*i).second, ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 13472
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  string a, b, c;
  in3(a, b, c);
  if(a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0])
    out("YES");
  else
    out("NO");
  memi;
}

Measured memory_bytes: 256
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a,int b){return a*b/gcd(a,b);}

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

signed f(int num){
    if(num%2==0)return num/2;
    else return num*3+1;
}

void run(){
    int x;
    cin >> x;
    if(x==3||x==5||x==7)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int x[N],w[N];


int main()
{
	int n,l,t;
	scanf("%d %d %d",&n,&l,&t);
	for(int i=1;i<=n;i++)scanf("%d %d",&x[i],&w[i]);
	int pos=0;
	for(int i=1;i<=n;i++)
	{
		if(w[i]==1)x[i]+=t;
		else x[i]-=t;
		pos+=x[i]/l;
		if(x[i]%l<0)pos--;
		x[i]=(x[i]%l+l)%l;
	}
	sort(x+1,x+n+1);
	pos=(pos%n+n)%n;
	for(int i=pos+1;i<=n;i++)printf("%d\n",x[i]);
	for(int i=1;i<=pos;i++)printf("%d\n",x[i]);
	return 0;
}

Measured memory_bytes: 1920
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    line = S()
    unique = line[0]
    for c in line:
        if c != unique[-1]:
            unique += c
    print(len(unique)-1)

main()



Measured memory_bytes: 5592
#include<iostream>
#include<vector>
#define rep(i, s, n) for (int i=(s); i<(n); i++)
using namespace std;

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

  int cnt=0;
  rep(i, 0, n) {
    int minj=i;
    rep(j, i, n) {
      if (a[minj]>a[j]) minj=j;
    }
    swap(a[i], a[minj]);
    if (i!=minj) cnt++;
  }
  rep(i, 0, n-1) cout<<a[i]<<" ";
  cout<<a[n-1]<<endl;
  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 3088
import math
import fractions

def main():
    a, b, c, d = map(int, input().split())

    quotient = []
    temp_lcm = c * d // fractions.gcd(c, d)
    for i, x in enumerate([c, d, temp_lcm]):
        temp = (b // x) - ((a-1) // x)
        quotient.append(temp)
    temp1 = b - a + 1
    ans = temp1 - (quotient[0] + quotient[1]) + quotient[2]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5048
def main():
    n = int(input())

    if n == 1 or n == 2:
        ans = 0
    else:
        if n % 2 == 0:
            ans = n // 2 - 1
        else:
            ans = n // 2

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61872
(w,h),*z=$<.map{|s|s.split.map &:to_i};s=t=0;z.map{|x,y,a|a<2?x>s&&s=x:a<3?x<w&&w=x:a<4?y>t&&t=y:y<h&&h=y};p [0,w-s].max*[0,h-t].max

Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

const Int MAX_DIGIT = 50;
//Int dp[100][2];

template<class T>
vector<T> make_vec(size_t s, T val) { return vector<T>(s, val); }
template<class... Size>
auto make_vec(size_t s, Size... tail) {
	return vector<decltype(make_vec(tail...))>(s, make_vec(tail...));
}

auto dp = make_vec(100, 2, -1LL);

int main() {

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

	Int N, K;
	cin >> N >> K;

	vector<Int> A(N);
	for (Int i = 0; i < N; i++) {
		cin >> A[i];
	}
	
	dp[MAX_DIGIT][0] = 0; 

	for (Int digit = MAX_DIGIT - 1; digit >= 0; digit--) {
		Int mask = 1LL << digit; // 下からdigit桁目を立てたマスク

		// Aでもともと下からdigit桁目にビットが立っているものの個数
		Int num = 0;
		for (Int i = 0; i < N; i++) {
			if (A[i] & mask) {
				num++;
			}
		}

		// マスク値の下からdigit桁目を0, 1にしたときのスコア
		Int score0 = mask * num;
		Int score1 = mask * (N - num);

		//未満→未満
		if (dp[digit + 1][1] != -1) {
			dp[digit][1] = max(dp[digit][1], max(dp[digit + 1][1] + score0, dp[digit + 1][1] + score1));
		}

		// ちょうど→未満
		//Kのdigit桁目が1の場合のみ起こる遷移
		if (dp[digit + 1][0] != 1) {
			if (K & mask) { // Kの下からdigit桁目が立っていたら引っ込める
				dp[digit][1] = max(dp[digit][1], dp[digit + 1][0] + score0);
			}
		}

		// ちょうど→ちょうど
		if (dp[digit + 1][0] != -1) {
			if (K & mask) { // Kの下からdigit桁目が1
				dp[digit][0] = max(dp[digit][0], dp[digit + 1][0] + score1);
			}
			else { // Kの下からdigit桁目が0
				dp[digit][0] = max(dp[digit][0], dp[digit + 1][0] + score0);
			}
		}
	}

	cout << max(dp[0][1], dp[0][0]) << endl;

}


Measured memory_bytes: 1024
s = raw_input().split()
d = {}
w = None
mf = 0
m = None
ml = 0

for ww in s:
    if( len(ww) > ml ):
        m = ww
        ml = len(ww)
    try:
        d[ww] += 1
        if( d[ww] > mf ):
            mf = d[ww]
            w = ww
    except KeyError:
        d[ww] = 1

print w, m

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

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

  if( a < b ) cout<<"a < b"<<endl;
  if( a > b ) cout<<"a > b"<<endl;
  if( a == b ) cout<<"a == b"<<endl;
  
  return 0;
}



   
  



Measured memory_bytes: 3096
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

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

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

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

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

	vector<int> p = a;

	sort(all(p));

	int a0, b0;
	int x = 0;
	do
	{
		if (p == a)
		{
			a0 = x;
		}
		if (p == b)
		{
			b0 = x;
		}

		x++;
	} while (next_permutation(all(p)));

	println(abs(a0 - b0));
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	Scanner sc = new Scanner(System.in);

	int INF = 1 << 28;
	double EPS = 1e-9;

	int p0,q0,maxA,maxN;
	int ans;
	
	void run() {
		for(;;){
			p0=sc.nextInt();
			q0=sc.nextInt();
			maxA=sc.nextInt();
			maxN=sc.nextInt();
			if((p0|q0|maxA|maxN)==0){
				break;
			}
			solve();
		}
	}

	void solve() {
		int gcd=gcd(p0,q0);
		p0/=gcd;
		q0/=gcd;
		ans=0;
		dfs(0,1,1,1,0);
		// debug(ans);
		println(""+ans);
	}
	
	void dfs(int p,int q,int qNow,int a,int n){
		if(n>maxN){
			return;
		}
		if(a>maxA){
			return;
		}
		if(p*q0-q*p0>0){
			return;
		}
		{
			int p2=maxN-n;
			int q2=qNow;
			int pp=p*q2+q*p2;
			int qq=q*q2;
			if(pp*q0-qq*p0<0){
				return;
			}
		}
		// debug(p,q,qNow,a,n);
		if(p==p0&&q==q0){
			ans++;
			return;
		}
		for(int i=qNow;i*a<=maxA;i++){
			int p2=p*i+q;
			int q2=q*i;
			int gcd=gcd(p2,q2);
			p2/=gcd;
			q2/=gcd;
			dfs(p2,q2,i,i*a,n+1);
		}
	}
	
	int gcd(int m,int n){
		for(;m!=0;){
			int t=n%m;
			n=m;
			m=t;
		}
		return n;
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s) {
		System.out.print(s);
	}

	void println(String s) {
		System.out.println(s);
	}

	public static void main(String[] args) {
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define N 200006
#define mid ((l+r)>>1)
#define ls i<<1
#define rs i<<1|1
#define inf 1e18
#define in l==r
#define in2 x<=l&&r<=y
using namespace std;
map<int,int>g;
int n,k,x,tot,d[N],b[N],ll[N],rr[N],q[N],f[N<<2];long long s[N<<2],a[N];
void down(int i,int l,int r)
{
	if(f[i]){
		f[i]=0;s[i]=inf;
		if(l!=r)f[ls]=f[rs]=1;
	}
}
void build(int i,int l,int r)
{
	if(in){s[i]=-q[l];return;}
	build(ls,l,mid);build(rs,mid+1,r);s[i]=min(s[ls],s[rs]);
}
void del(int i,int l,int r,int x,int y)
{
	down(i,l,r);if(in2){f[i]=1;return;}
	if(x<=mid)del(ls,l,mid,x,y);if(y>mid)del(rs,mid+1,r,x,y);
	down(ls,l,mid);down(rs,mid+1,r);s[i]=min(s[ls],s[rs]);
}
long long query(int i,int l,int r,int x,int y)
{
	down(i,l,r);if(in2)return s[i];
	long long tmp=inf;if(x<=mid)tmp=query(ls,l,mid,x,y);
	if(y>mid)tmp=min(tmp,query(rs,mid+1,r,x,y));return tmp;
}
void change(int i,int l,int r,int x,long long y)
{
	down(i,l,r);if(in){s[i]=min(s[i],y-q[l]);return;}
	if(x<=mid)change(ls,l,mid,x,y);else change(rs,mid+1,r,x,y);
	down(ls,l,mid);down(rs,mid+1,r);s[i]=min(s[ls],s[rs]);
}
long long find(int i,int l,int r)
{
	down(i,l,r);if(in)return s[i]+q[l];
	return min(find(ls,l,mid),find(rs,mid+1,r));
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&x,&b[i]);
		if(b[i]==1&&x*2>k)return puts("-1"),0;
		a[i]=a[i-1]+1LL*x;if(b[i]==2)continue;
		ll[i]=-2LL*a[i-1]%k;ll[i]+=ll[i]<0?k:0;
		rr[i]=-2LL*a[i]%k;rr[i]+=rr[i]<0?k:0;
		d[i]=ll[i];d[n+i]=rr[i];
	}
	sort(d+1,d+2*n+1);
	for(int i=1;i<=2*n;i++)
		if(d[i]!=d[i-1]||i==1)g[d[i]]=++tot,q[tot]=d[i];
	build(1,1,tot);
	for(int i=1;i<=n;i++){
		if(b[i]==2)continue;
		int L=g[ll[i]],R=g[rr[i]];
		if(L>R){
			change(1,1,tot,L,(R+1<L?query(1,1,tot,R+1,L-1):inf)+ll[i]);
			if(R+1<L)del(1,1,tot,R+1,L-1);
		}else{
			change(1,1,tot,L,(1<L?query(1,1,tot,1,L-1):inf)+ll[i]);
			change(1,1,tot,L,(R<tot?query(1,1,tot,R+1,tot):inf)+k+ll[i]);
			if(1<L)del(1,1,tot,1,L-1);
			if(R<tot)del(1,1,tot,R+1,tot);
		}
	}
	printf("%lld",2LL*a[n]+find(1,1,tot));
}

Measured memory_bytes: 18944
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        sc.close();

        boolean can = false;
        for (int i = 0; i < 25; ++i) {
            for (int j = 0; j < 25; ++j) {
                if (N == 4 * i + 7 * j) {
                    can = true;
                }
            }
        }

        if (can == true) {
            System.out.print("Yes");
        } else {
            System.out.print("No");
        }
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define lli long long int
using namespace std;
#define S second
#define F first
#define pb push_back 
#define M1 1000000007
#define M2 998244353
#define plli pair<lli,lli>
#define setit set<lli>::iterator seti
#define mapit map<lli,lli> ::iterator mapi
#define MP make_pair
#define MT make_tuple
// map      iterator->first  iterator.first
// map      mp[key]=value
// set      *s.begin()
// vector   v[j]=value
// pair     p.first p.second
// vector of pairs v[j].first v[j].second
// tuple    get<index>(tuple_name)
// vector of tuples get<index>(v[j])  sort(v.begin(),v.end())
//priority queue .top() .pop() .push()
// __gcd(x,y)
#define fr(j,a,b) for(j=a;j<b;j++)

int power(int x, unsigned int y, int p)  
{    int res = 1;    
     x = x % p;
     if (x == 0) return 0;
     while (y > 0)  
     {  if (y & 1)  
        res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
     }  
    return res;  
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lli t,i,j,n,a,b;
     lli x;
    cin>>a>>b>>n;
    if(n<b){
        if((a*n)%b!=0){
            x=n;
        }
        else{
            x=n-1;
        }
    }
    else if(b==n){
        x=n-1;
    }
    else{
        if(n%b!=0){
            if((b*(ceil((1.0*n)/b)))-n<=(b/2)){
                x=n;
            }
            else{
                x=((n/b)*b)-1;
            }
        }
        else{
            x=n-1;
        }
    }
    j=((a*x)/b)-(a*(x/b));
    cout<<j;
}


Measured memory_bytes: 3668
#include<stdio.h>

int main(){
    int i;
    char st,al[53]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    
    
    do{
        scanf("%c", &st);
        for(i=0;i<53;i++){
            if(al[i] ==st){
                st = al[(i+26)%52];
                break;
            }}
            printf("%c",st);
        }
        while(st != '\n');
    return 0;
}



Measured memory_bytes: 2060
from sys import stdin
n = int(stdin.readline())
c = stdin.readline()[:-1]

red = c.count("R")
ans = red
numwhite = 0
for i in range(n):
    numwhite += 1 if c[i] == "W" else 0
    numred = i - numwhite + 1
    resred = red - numred
    if resred == numwhite:
        ans = min(ans,resred)
print(ans)


Measured memory_bytes: 67572
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fst first
#define snd second
const ll mod = 1000000007;
const ll INF = (1LL << 59);

int main(){
	string str; cin >> str;
	bool flg1, flg2;
	flg1 = str.length() % 2 == 0;
	flg2 = str[0] != str[str.length() - 1];
	if (flg1^flg2) {
		cout << "First" << endl;
	}
	else {
		cout << "Second" << endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int k=max({a,b,c});
  cout << 9*k+a+b+c << endl;
}

Measured memory_bytes: 256
N = int(input())
def dfs(s):
  if int(s)>N:
    return 0
  if all(s.count(i)>0 for i in "357"):
    c = 1
  else:
    c = 0
  for i in "357":
    c += dfs(s+i)
  return(c)
print(dfs("0"))

Measured memory_bytes: 9068
import java.util.Scanner;

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

		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();

		int fee = 0;

		if(B>A*N) fee = A*N;
		else fee = B;

		System.out.println(fee);
	}
}


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

int main() {
  string s, t;
  cin >> s >> t;
  t.erase(t.size() - 1);
  if(s == t) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n){
        ll tmp;
        cin >> tmp;
        a[i] = tmp-i-1;
    }
    sort(a.begin(), a.end());
    ll ans = 0;
    ll chuo;
    if (n%2){
        chuo = a[n/2];
    }else{
        chuo = (a[n/2] + a[(n-1)/2])/2;
    }
    rep(i, n){
        ans += abs(a[i] - chuo);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int mod = 1000000007;


int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif

   char c;
   cin>>c;
   cout<<(char)(c+1)<<endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
if N == 1:
    print(1)
else:
    if A[0] == A[1]:
        pre = 0
    elif A[0] > A[1]:
        pre = -1
    else:
        pre = 1
    prevalue = A[1]
    ans = 0
    for a in A[2:]:
        if a > prevalue:
            if pre == -1:
                ans += 1
                pre = 0
            else:
                pre = 1
        elif a < prevalue:
            if pre == 1:
                ans += 1
                pre = 0
            else:
                pre = -1
        prevalue = a
    print(ans+1)


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

class Main
{

	static Scanner sc;

	public static void main( String[] args ) throws IOException
	{
		sc = new Scanner( new BufferedReader( new InputStreamReader( System.in ) ) );
	    Queue<Integer> q = new PriorityQueue<>();
	    for(int i = 0; i < 3; i++)
	        q.offer(sc.nextInt());
	    int a = q.poll(), b = q.poll(), c = q.poll();
	    System.out.printf("%d %d %d\n", a, b, c);
	}
}


Measured memory_bytes: 26204
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 100000
#define X 1000000007
#define I2 500000004
#define C(x,y) (1LL*Fac[x]*IFac[y]%X*IFac[(x)-(y)]%X)
using namespace std;
int n,a[N+5],Fac[N+5],IFac[N+5],s[N+5];
I int QP(RI x,RI y) {RI t=1;W(y) y&1&&(t=1LL*t*x%X),x=1LL*x*x%X,y>>=1;return t;}
I int f(CI x) {return 1LL*Fac[n-x-1]*Fac[x]%X*C(n,x+1)%X;}
int main()
{
	RI i;for(scanf("%d",&n),i=1;i<=n;++i) scanf("%d",a+i);
	for(Fac[0]=i=1;i<=n;++i) Fac[i]=1LL*Fac[i-1]*i%X;
	for(IFac[n]=QP(Fac[n],X-2),i=n-1;~i;--i) IFac[i]=1LL*IFac[i+1]*(i+1)%X;
	for(s[0]=i=1;i<=n;++i) s[i]=(s[i-1]+IFac[i])%X;
	RI t=0,ans=0;for(i=2;i<=n;++i) t=(t+f(i-1))%X;
	for(i=1;i<=n;++i) t=(t+f(i-1))%X,ans=(1LL*t*a[i]+ans)%X,t=(t-f(n-i)+X)%X;
	return printf("%d\n",ans),0;
}

Measured memory_bytes: 5336
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin >> n;
    
    if(n < 1200)
    {
        cout << "ABC" << endl;
    }
    else if(n < 2800)
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "AGC" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    char c;
    cin >> c;
    cout << (char)(c+1) << endl;    

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
typedef pair<int,int>P;
P box[100001];
int main(void)
{
	int n,a,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&a);
		box[i].first=a;
		box[i].second=i;
	}
	sort(box+1,box+n+1);
	for(i=1;i<=n;i++){
		if(i!=1){
			printf(" ");
		}
		printf("%d",box[i].second);
	}
	printf("\n");
	return 0;
}
	

Measured memory_bytes: 1536
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int N;
	cin >> N;

	string S;
	cin >> S;

	int left_cost = 0;
	int right_cost = 0;
	for (int i = 1; i < N; i++)
	{
		if (S[i] == 'E') right_cost++;
	}

	int result = right_cost;
	for (int i = 1; i < N; i++)
	{
		if (S[i] == 'E') right_cost--;
		if (S[i - 1] == 'W') left_cost++;

		result = min(result, left_cost + right_cost);
	}

	cout << result;

	return 0;
}


Measured memory_bytes: 720
N,W = map(int, input().split())
Value = [0]*N
Weight = [0]*N
for i in range(N):
    v,w = map(int, input().split())
    Value[i] = v
    Weight[i] = w

dp = [0]*(W+1)
for i in range(N):
    for j in range(W+1):
        if j < Weight[i]:
            continue
        dp[j] = max(dp[j], dp[j-Weight[i]]+Value[i])

print(dp[W])


Measured memory_bytes: 5724
#include<stdio.h>

int quot_m2(int x){
	if(x>0)return -1*(x/2);
	return (-1*x+1)/2;
}

int ab(int x){
	if(x<0)return -x;
	return x;
}

int main(){
	int N,i=0;
	int ans[256];
	scanf("%d",&N);
	
	if(N==0){
		printf("0\n");
		return 0;
	}
	
	while(N!=0){
		ans[i]=ab(N)%2;
		N=quot_m2(N);
		i++;
	}
	for(i=i-1;i>=0;i--)printf("%d",ans[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A >> B;
  int num = 0;
  
  for (int i=A;i<B+1;i++){
      int C = i;
      int count = 0;
      int sum = 0;
      
      vector <int> x;
      while(C>0){
          
          int mod = C % 10;
          x.push_back(mod);
          C /= 10;
          count++;
      }
      for (int j=0;j<count;j++){
          
          sum += x.at(j) * pow(10,count-1-j);
          if(sum == i) {
              num++;
          }
      }
  }
  cout << num << endl;
  }


Measured memory_bytes: 4116
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
ll table[2019], t2[2019];
int main() {
	int N, M, f;
	cin >> N >> M;
	vector<string> A(N), B(M);
	rep(i, 0, N)cin >> A[i];
	rep(i, 0, M)cin >> B[i];
	rep(sy, 0, N - M + 1) {
		rep(sx, 0, N - M + 1) {
			f = 1;
			rep(y, 0, M) {
				rep(x, 0, M) {
					if (A[sy + y][sx + x] != B[y][x]) {
						f = 0;
						break;
					}
				}
				if (f == 0)break;
			}
			if (f) {
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
	return 0;
}

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

int main(){
    int l,r;
    cin >> l >> r;
    int d = min(2019,(r-l));
    int ans = 2019;

    for (int i = 0; i < d; i++){
        for (int j = i+1; j <= d; j++){
            int x = (l+i)%2019;
            int y = (l+j)%2019;
            ans = min(ans, (x*y)%2019);
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 3552
integer,allocatable,dimension(:)::K,A
integer ans
allocate(K(5),A(5))
do i=1,5
 read*,K(i)
 A(i)=mod(K(i),10)
 if(mod(K(i),10)/=0)K(i)=K(i)+10-A(i)
 if(A(i)==0)A(i)=10
end do
ans=sum(K)-10+minval(a)
print"(i0)",ans
end

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

int main()
{
   long N;
   long A[100000];
   std::cin >> N;
   for(int i=0; i<N; i++){
       std::cin >> A[i];
   }
   long A0=0;
   for(int i=0; i<N; i++){
       A0+=std::pow(-1,i)*A[i];
   }
   std::cout << A0 << " ";
   for(int i=0; i<N-2;i++){
       A0=2*A[i]-A0;
       std::cout << A0 << " "; 
   }
   std::cout << 2*A[N-2]-A0 <<std::endl;
    return 0;
}

Measured memory_bytes: 2048
#include <stdio.h>

int a, b;
int count;
int gaet;

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

Measured memory_bytes: 128
import math

N = int(input())
N = math.factorial(N) 

i = 2 
num = 1
ans = 1

while N != 1: 
    if N % i == 0:
        N = N // i
        num += 1
    else:
        ans *= num
        num = 1
        i += 1
ans *= num
ans %= (10 ** 9) + 7

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include <vector>
#include <map>
using namespace std;
long long Read() {
	long long x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9') {
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
	return x*f;
}
int main() {
	int n,a,b,s=0;
	a=Read(),b=Read();
	n=b;
	while(b) {
		s++;
		b/=10;
	}
	for(int i=1; i<=s; i++) {
		a*=10;
		
	}
	n+=a;
	for(int i=1; i<=100000; i++) {
		if(i*i==n) {
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

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

const int INF = 1001001001;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int,int>> key;
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    int s = 0;
    rep(j,b) {
      int c;
      cin >> c;
      --c;
      s += 1<<c;
    }
    key.emplace_back(s,a);
  }

  vector<int> dp(1<<n, INF);
  dp[0] = 0;
  rep(s,1<<n) {
    rep(i,m) {
      int t = s | key[i].first;
      int cost = dp[s] + key[i].second;
      dp[t] = min(dp[t], cost);
    }
  }
  int ans = dp.back();
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
	int a,b,c,d,x,y;
	
	scanf("%d%d%d%d",&a,&b,&c,&d);
	
	x=(a+b+c+d)/60;
	y=(a+b+c+d)%60;
	
	printf("%d\n%d\n",x,y);
	
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    if(n==0)
    cout<<"0";
    else
    {
        long long int h1=1000*(n/500);
        long long int h2=n-((n/500)*500);
        long long int fh2=5*(h2/5);
        
        cout<<h1+fh2;
    }
}

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

#define MOD (1000000000+7)

long long powm( long long x, long long n )
{
	long long res = 1;
	while( n > 0 ) {
		if( n & 1 ) res = res * x % MOD;
		x = x * x % MOD;
		n >>= 1;
	}
	return res;
}

int main() {
	long long N, A, B, C;

	cin >> N >> A >> B >> C;

	vector<long long> fac( 2 * N );
	fac[0] = 1;
	fac[1] = 1;
	for( int i = 2; i < 2 * N; i++ ) {
		fac[i] = fac[i - 1] * i % MOD;
	}
	vector<long long> ifac( 2 * N );
	for( int i = 0; i < 2 * N; i++ ) {
		ifac[i] = powm( fac[i], MOD - 2 );
	}
	vector<long long> a( 2 * N );
	long long aa = A * powm( A + B, MOD - 2 );
	for( int i = 0; i < 2 * N; i++ ) {
		a[i] = powm( aa % MOD, i ) ;
	}
	vector<long long> b( 2 * N );
	long long bb = B * powm( A + B, MOD - 2 );
	for( int i = 0; i < 2 * N; i++ ) {
		b[i] = powm( bb % MOD, i );
	}
	long long div = 100 * powm( A + B, MOD - 2 ) % MOD;
	long long ans = 0;
	for( long long M = N; M < 2 * N; M++ ) {
		long long c = fac[M - 1] * ifac[N - 1] % MOD * ifac[M - N] % MOD;
		ans += c * a[N] % MOD * b[M - N] % MOD * M % MOD * div % MOD;
		ans %= MOD;
		ans += c * a[M - N] % MOD * b[N] % MOD * M % MOD * div % MOD;
		ans %= MOD;
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

using int64 = long long;
const int64 LINF = 1LL << 61;
const int INF = 1 << 30;

int main()
{
  int N, Y;
  cin >> N >> Y;
  // 10000a + 5000b + 1000c = Y
  // a + b + c = N

  for(int i = 0; i <= 10000; i++) {
    for(int j = 0; j <= 10000; j++) {
      int64 sum = i * 10000 + j * 5000;
      if(sum > Y) continue;
      int64 k = (Y - sum) / 1000;
      if(i + j + k == N) {
        cout << i << " " << j << " " << k << endl;
        return (0);
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	ll n,m; cin>>n>>m;
	vector<bool> arr(n+1,0);
	vector<ll> wa(n+1,0);
	ll p,cnt=0,pen=0;
	string ch;
	for(auto i=0;i<m;++i){
		cin>>p>>ch;
		if(ch=="AC" && arr[p]==0){
			++cnt;
			arr[p]=1;
			pen+=wa[p];
		}
		else
			if(ch=="WA" && arr[p]==0){
				++wa[p];
			}
	}
	cout<<cnt<<' '<<pen<<'\n';
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

Measured memory_bytes: 1024