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

//多項式解法。練習2回目
public class Main {
	static final int mod = 998244353;
	static final int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int[] DX8 = { -1, -1, -1, 0, 0, 1, 1, 1 }, DY8 = { -1, 0, 1, -1, 1, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;
	static final String nextLine = "\n";

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt(), s = fs.nextInt();
		int a[] = fs.nextIntArray(n);
		int memo[] = new int[s+1];
		memo[0] = 1;
		long ans = 0;
		for(int i=0;i<n;i++) {
			int memo2[] = new int[s+1];
			memo2[0] = 1;
			for(int j=0;j<s+1;j++) {
				memo2[j] += memo[j];
				memo2[j] %= mod;
				if(j + a[i]<s+1) {
					memo2[j+a[i]] += memo[j];
					memo2[j+a[i]] %= mod;
				}
			}
			ans += memo2[s];
			ans %= mod;
			memo = memo2;
		}
		System.out.println(ans);
	}

	//MOD culculations
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

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

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

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

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

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

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 42196
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  string s, t;
  int a, b, l;
  vector<int> A, v;
  bool f;
  while (cin >> a >> l, l) {
    A.erase(A.begin(), A.end());
    A.push_back(a);
    f = false;
    for (int i = 0; i < 20; ++i) {
      if (f) break;
      for (int j = 0; j < l; ++j) {
	v.push_back(a%10);
	a /= 10;
      }
      sort(v.begin(), v.end());
      for (int j = 0; j < l; ++j) {
	a *= 10;
	a += v[l-1-j] - v[j];
      }
      v.erase(v.begin(), v.end());
      for (int j = 0; j < i+1; ++j) {
	if (a == A[j]) {
	  cout << j << " " << a << " " << i-j+1 << endl;
	  f = true;
	  break;
	}
      }
      A.push_back(a);
    }
  }
  return 0;
}

Measured memory_bytes: 3064
import Data.List (sort, foldl', group)

main :: IO ()
main = do
  getLine
  s <- getLine
  let
    s' = map (toInteger . length) . group . sort $ s
    c = foldl' step 1 s' - 1
    step a i = mod (a * (i + 1)) d
  print c

d :: Integer
d = 10 ^ 9 + 7


Measured memory_bytes: 11644
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1e9+7
#define EPS 1e-8
#define INF 1e9+10
typedef long long ll;
using namespace std;
int main()
{
  string S;
  cin >> S;
  int ans;
  if(S=="SUN"){
    ans=7;

  }
  else if(S=="MON"){
    ans=6;
  }
  else if(S=="TUE"){
    ans=5;
  }
  else if(S=="WED"){
    ans=4;
  }
  else if(S=="THU"){
    ans=3;
  }
  else if(S=="FRI"){
    ans=2;
  }
  else{
    ans=1;
  }
  cout << ans << endl;


}



Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if (i+j+k >= 1) and (i*500 + j*100 + k*50 == x):
                cnt += 1

print(cnt)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int X = sc.nextInt();
		int N = sc.nextInt();
		int[] vals = new int[N];
		for (int i = 0; i < N; i++) {
			vals[i] = sc.nextInt();
		}
		int ans = -1000;
		for (int i = 0; ans == -1000; i++) {
			for (int j = -1; j <= 1 && ans == -1000; j+=2) {
				int val = X + i * j;
				boolean can = true;
				for (int k = 0; k < N; k++) {
					if (vals[k] == val) {
						can = false;
						break;
					}
				}
				if (can) {
					ans = val;
				}
			}
		}
		out.println(ans);
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 32984
def ketasu(num):
    if num == 0:
        return 1
    else:
        ans = 0
        while num != 0:
            num = num // 10
            ans += 1
        return ans

n = int(input())
ans = 0
keta = ketasu(n)
for i in range(1, keta + 1):
    if i % 2 != 0:
        if i == keta:
            ans += n - 10 ** (i - 1) + 1
        else:
            ans += 10 ** i - 10 ** (i - 1)

print(ans)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;
int main() {

  int a=0;
  int b=0;
  cin>> a;
  int c=a;
  while (a!=0){ 
  
  b+=a%10;
  a=a/10;
  
  }
  if (c%b==0){
  cout<< "Yes";
  }

  else{
  cout<< "No";
  }
  
  return 0;
}

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

int main(){

    int a, b;
    scanf("%d%d",&a,&b);
    if(a < b){
        printf("a < b\n");
    }else if(a > b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }
}



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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int n = in();
    vll a = in(n);

    ll sump = 0, sumn = 0;
    ll pos = 0, neg = 0;
    rep(i, n)
    {
        sump += a[i];
        sumn += a[i];
        if (i % 2 == 0)
        {
            if (sump <= 0)
            {
                pos += abs(sump) + 1;
                sump = 1;
            }
            if (sumn >= 0)
            {
                neg += abs(sumn) + 1;
                sumn = -1;
            }
        }
        else
        {
            if (sump >= 0)
            {
                pos += abs(sump) + 1;
                sump = -1;
            }
            if (sumn <= 0)
            {
                neg += abs(sumn) + 1;
                sumn = 1;
            }
        }
    }
    cout << min(pos, neg) << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

long long N,lsum=0,rsum=0,mid,ans;

int main(){
    cin>>N;
    long long A[N];
    rep(i,N)cin>>A[i];
    sort(A,A+N);
    if(N%2==0){
        mid=N/2;
        rep(i,mid)lsum+=A[i];
        for(int i=mid;i<N;i++)rsum+=A[i];
        lsum*=2;
        rsum*=2;
        lsum-=A[mid-1];
        rsum-=A[mid];
        ans=rsum-lsum;
    }
    else{
        long long temp;
        mid=N/2+1;
        rep(i,mid)lsum+=A[i];
        for(int i=mid;i<N;i++)rsum+=A[i];
        lsum*=2;
        rsum*=2;
        lsum-=(A[mid-1]+A[mid-2]);
        temp=rsum-lsum;

        rsum=0;
        lsum=0;
        mid=N/2;
        rep(i,mid)lsum+=A[i];
        for(int i=mid;i<N;i++)rsum+=A[i];
        lsum*=2;
        rsum*=2;
        rsum-=(A[mid]+A[mid+1]);
        ans=max(temp,rsum-lsum);
    }
    out(ans);
}


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

int main(){
  int n,array[100000],bai4=0,bai2=0;;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>array[i];
    if(array[i]%4==0){
      bai4++;
    }else if(array[i]%2==0){
      bai2++;
    }
  }
  if(n-(bai4*2+1)<=0){
    cout<<"Yes"<<endl;
    return 0;
  }
  n-=(bai4*2);
  cout<<(n<=bai2?"Yes":"No")<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  for (int W = 0; ;W++) {
   int A, B;
   cin >> A >> B;
    if (A == 0 && B == 0) {
      break;
    }
   for (int X = 0; X < A; X++) {

    if (X == 0 || X == A - 1) {
     for (int Y1 = 0; Y1 < B; Y1++) {
      cout << "#";
     }
    }
    
    else
     for (int Y2 = 0; Y2 < B; Y2++) {
      if (Y2 == 0 || Y2 == B - 1) {
       cout << "#";
      }
      
      else
       cout << ".";

     }
     
     cout << endl;
   }
  cout << endl;
  }
 
}


Measured memory_bytes: 3096
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iterator>
#include <functional>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstdio>
using namespace std;
#define sz(a)  int((a).size())
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
#define CLR(a) memset((a), 0, sizeof(a))
#define INF (1 << 31) - 1
const int dh[8] = {-1, 1, 0, 0,1,1,-1,-1};
const int dw[8] = {0, 0, 1, -1,1,-1,1,-1};
typedef long long ll;
typedef pair<int, int> p;
typedef vector <int> VI;
typedef vector <string> VS;

vector <int> his;

int main(){

	int n,x;
	cin >> n;
	cin >> x;
	
	if(x == 1 || x == 2 * n - 1){
		cout << "No" << endl;
		return 0;
	}else{
		cout << "Yes" << endl;		
		VI ans(2*n, 0);
		VI used(2*n, 0);		

		ans[n] = x;
		used[x] = 1;
		
		if(x > n){
			ans[n+1] = x + 1;
			ans[n+2] = x - 2;
			ans[n-1] = x - 1;
			used[x+1] = 1;
			used[x-2] = 1;
			used[x-1] = 1;									
		}else{
			ans[n+1] = x - 1;
			ans[n+2] = x + 2;			
			ans[n-1] = x + 1;
			used[x-1] = 1;
			used[x+2] = 1;
			used[x+1] = 1;						
		}
		
		int usedi = 1;
		for(int i = 1; i < 2 * n; i++){
			if(ans[i] == 0){
				while(used[usedi] != 0){
					usedi++;
				}
				ans[i] = usedi;
				usedi++;				
			}			
		}
		
		for(int i = 1; i < 2 * n; i++){
			cout << ans[i] << endl;
		}				
	}
	return 0;	
}


Measured memory_bytes: 3072
#include<iostream>
#include<algorithm>

typedef long long ll;
using namespace std;

int main(){
  ll L,R;
  cin >> L >> R;
  ll i,k;
  ll min = 111111;
  ll ans;
  if(R - L >= 2019) ans = 0;
  else{
    for(i=L;i<=R-1;i++)
      for(k=i+1;k<=R;k++)
        if(min > (i*k)%2019) min = (i*k)%2019;
    ans = min;
        }
  cout << ans << endl;
} 

Measured memory_bytes: 256
X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
AB=[]
for i in range(X):
    for j in range(Y):
        AB.append(A[i]+B[j])
AB.sort(reverse=True)
k=min(K,X*Y)
AB=AB[:k]
ABC=[]
for i in range(k):
    for j in range(Z):
        ABC.append(AB[i]+C[j])
ABC.sort(reverse=True)
for i in range(K):
    print(ABC[i])


Measured memory_bytes: 147904
#include <stdio.h>
int main(void) {
    char t1,t2,ball='A';
    while (scanf("%c,%c\n",&t1,&t2)!=EOF) {
        if (ball==t1) {
            ball = t2;
        } else if (ball==t2) {
            ball = t1;
        }
    }
    printf("%c\n",ball);
    return 0;
}

Measured memory_bytes: 548
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<functional>

typedef unsigned long long LL;

using namespace std;

int main() {
	string S;
	cin >> S;
	string compare;
	for (int i = 0; i < S.length(); i++) {
		if (S[i] != 'x') {
			compare.push_back(S[i]);
		}
	}
	int tmp = 0;
	vector<int> xNum(0, 0);
	int answer = 0;
	for (int i = 0; i < compare.length()/2; i++) {
		if (compare[i] != compare[compare.length() - i - 1]) {
			answer = -1;
			goto END;
		}
	}
	
	for (int i = 0; i < S.length(); i++) {
		if (S[i] == 'x') {
			tmp++;
		}
		else {
			xNum.push_back(tmp);
			tmp = 0;
		}
	}
	xNum.push_back(tmp);

	for (int i = 0; i < xNum.size()/2; i++){
		answer += xNum[i] - xNum[xNum.size() - i - 1] > 0 ? xNum[i] - xNum[xNum.size() - i - 1] : xNum[xNum.size() - i - 1] - xNum[i];
	}

END:
	cout << answer << endl;
	
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n; cin>>n; int x=0;
  for(int k=0;k<10;k++){
     for(int i=0;i<10;i++){
        if(i*k==n) x=1;
     }
  }
  if(x==1)  cout<< "Yes"  <<endl;
  else  cout<< "No"  <<endl;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc138/tasks/abc138_d
# 下に数を最初に合計してから深さ優先探索なり、幅優先探索なりで下にカウンターを伝播させていけば良い。
# 累積和の木構造バージョン


import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


# 再帰の上限を緩和する(引数は適当)
import sys
sys.setrecursionlimit(1 << 25)
from collections import defaultdict

N, Q = read_ints()
child = defaultdict(lambda: [])  # ノード0は存在しない
score = [0] * (N + 1)
for _ in range(N - 1):
    a, b = read_ints()
    child[a].append(b)
    child[b].append(a)
for _ in range(Q):
    p, x = read_ints()
    score[p] += x

# 木を走査しながらscoreを合計していく
ans = [0] * (N + 1)


def dfs(p, u, s):  # ノードuの親pにおけるスコアs
    s += score[u]
    ans[u] = s
    for c in child[u]:
        if p == c:
            continue
        dfs(u, c, s)


dfs(-1, 1, 0)
print(*ans[1:])


Measured memory_bytes: 255904
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();

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

    if (a == 1) a = 14;
    if (b == 1) b = 14;

    if (a > b) cout << "Alice" << endl;
    if (a < b) cout << "Bob" << endl;
    if (a == b) cout << "Draw" << endl;


    return 0;
    
}

Measured memory_bytes: 256
n = STDIN.gets.to_i

m = 1.upto(n).inject({}) {|acc, i|
  k = [i.to_s[0, 1], i.to_s[-1, 1]]
  acc[k] = (acc[k] || 0) + 1
  acc
}

count = 1.upto(n).inject(0) {|cnt, i|
  k = [i.to_s[-1, 1], i.to_s[0, 1]]
  cnt + (m[k] || 0)
}

puts count

Measured memory_bytes: 3836
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

long long int INF = 1e18;
using namespace std;

typedef pair<long long int, long long int> P;

int main(){
	
	int n;
	cin >> n;
	
	list<int> lst;
	std::list<int>::iterator itr;
	
	for(int i = 0; i < n; i++){
		char str[20];
		cin >> str;
		if(str[0] == 'i'){
			int num;
			cin >> num;
			lst.push_front(num);
		}else if(str[6] == 'F'){
			lst.pop_front();
		}else if(str[6] == 'L'){
			lst.pop_back();
		}else{
			int num;
			cin >> num;
			for(itr = lst.begin(); itr != lst.end(); ){
				if(*itr == num){
					itr = lst.erase(itr);
					break;
				}else{
					itr++;
				}
			}
		}
	}
	
	itr = lst.begin();
	
	if(lst.begin() != lst.end()){
		cout << *itr;
		itr++;
	}
	
	for(; itr != lst.end(); itr++){
		cout << " " << *itr;
	}
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 34256
#include<bits/stdc++.h>
using namespace std;
char s[200010];
int len,az[30];
queue<int> q;

int main()
{
	int i,j;
	int flag = 0;
	
	scanf("%s",s);
	len = strlen(s);
	
	if(len==2)
	{
		if(s[0]==s[1]) printf("1 2\n");
		else printf("-1 -1\n");
	}
	else
	{
		for(i=0;i<len;i++)
		{
			if(i+1 < len && s[i]==s[i+1])
			{
				printf("%d %d\n",i+1,i+2);
				return 0;
			}
			if(i+2 < len && s[i]==s[i+2])
			{
				printf("%d %d\n",i+1,i+3);
				return 0;
			}
		}
		
		printf("-1 -1\n");
	}
}

Measured memory_bytes: 3888
#include <bits/stdc++.h>
const int INF = 1e9;
const int MODk = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl
#define MAXE(a,b) a=max(a,b)
#define MINE(a,b) a=min(a,b)

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    CIN(N);CIN(K);
    V<LL> vec;
    REP(a,N){
        LCIN(b);vec.pb(b);
    }
    V<LL> ruiseki;
    V<bitset<50>> kouho;
    ruiseki.push_back(0);
    REP(a,N){
        ruiseki.push_back(ruiseki.back()+vec.at(a));
    }
    for(int a = 0;a < N;a++){
        for(int b = a+1;b < N+1;b++){
            kouho.push_back(bitset<50>(ruiseki[b]-ruiseki[a]));
        }
    }
    for(int a = 49;a >= 0;a--){
        vector<bool> flag(kouho.size(),false);
        if(kouho.size() == K)break;
        int count = 0;
        REP(b,kouho.size()){
            if(kouho.at(b)[a]){
                count++;
                flag.at(b)=true;
            }
        }
        vector<bitset<50>> ins;
        if(count >= K){
            for(int b= 0;b < kouho.size();b++){
                if(flag.at(b)){
                    ins.push_back(kouho.at(b));
                }
            }
            kouho = ins;
        }
    }
    bitset<50> ans = kouho.front();
   // COUT(kouho.size());
    for(int a = 0;a < kouho.size();a++){
     //   cout<<kouho.at(a).to_ullong()<<" ";
        ans &= kouho.at(a);
    }
    COUT(ans.to_ullong());
    return 0;
}


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

int main() {
    cin.sync_with_stdio(false);
    cin.tie();

    int n;
    cin >> n;
    int prev1, prev2, cur;
    cin >> prev1 >> prev2;
    int c1, c2;
    c1 = 0;
    c2 = abs(prev1 - prev2);
    for (int i = 2; i < n; ++i) {
        cin >> cur;
        int c32 = abs(cur - prev2) + c2;
        int c31 = abs(cur - prev1) + c1;
        prev1 = prev2;
        prev2 = cur;
        c1 = c2;
        c2 = min(c32, c31);
    }
    cout << c2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
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; }
const ll INF = 1LL << 60;
int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n){
        int x;
        cin >> x;
        a[x-1]++;
    }
    sort(a.begin(),a.end());
    vector<int> s(n);
    s[0] = a[0];
    rep(i,n-1) s[i+1] = s[i] + a[i+1];

    for(int k=1; k<=n; k++){
        int l=0, r=n/k+1; //二分探索は半開区間がいい
        while(l+1<r){
            int x = (l+r)/2; //x回取れるならl=x, 取れないならr=x;
            bool ok = [&](int c){
                int i = lower_bound(a.begin(),a.end(),c) - a.begin(); //このindexからはc以上
                int sm;
                if(i) sm = s[i-1] + (n-i)*c;
                else sm = n*c;
                return sm >= k*c;
            }(x);
            if(ok) l=x; else r=x;
        }
        cout << l << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define pb  push_back
#define mod 1000000007
#define INF 1e18
typedef  long long ll;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s;
	cin>>s;
	cout<<s;
	if(s.back()!='s')
		cout<<"s";
	else
		cout<<"es";
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = (int)1e9 + 7, INF = (int)1e9;


int main(void) {
	ll q, h, s, d, n, s1, s2, s3, ans;

	scanf("%lld%lld%lld%lld%lld", &q, &h, &s, &d, &n);

	s1 = min(q * 2, h);
	s2 = min(s1 * 2, s);
	s3 = min(s2 * 2, d);

	ans = n / 2 * s3 + n % 2 * s2;

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 256
def main():
    line = input()
    deepen_x = []
    cur_x = 0
    ponds = []      # [(水たまりの最初の位置, 水量)]
    while len(line) > 0:
        #print(cur_x, ponds, deepen_x)
        tmp_char = line[0]
        if tmp_char == '\\':
            deepen_x.append(cur_x)
        elif tmp_char == '/' and len(deepen_x) != 0:
            pre_x = deepen_x.pop()
            volume = cur_x - pre_x
            if len(ponds) == 0:
                ponds.append([pre_x, volume])
            else:
                if pre_x < ponds[-1][0]:
                    # 前の水たまりと結合する
                    a = list(filter(lambda x: x[0] > pre_x, ponds))
                    pond = 0
                    for item in a:
                        pond += item[1]
                    [ponds.pop() for x in range(len(a))]
                    ponds.append([pre_x, pond + volume])
                else:
                    # 新しい水たまりを作成
                    ponds.append([pre_x, volume])
        cur_x += 1
        line = line[1:]

    print(sum([x[1] for x in ponds]))
    if len(ponds) == 0:
        print('0')
    else:
        print("{} ".format(len(ponds)) + " ".join([str(x[1]) for x in ponds]))

    return


main()


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

int main() {
  int n, a; //a:1円の枚数
  cin >> n >> a;
  
  //１円が何枚必要か
  int x;
  x = n % 500;
  
  if(x <= a){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  
  //test出力
  //cout << "1円の必要枚数" << x << endl;


}


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

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

int main() {
  int N, D, X, a;
  cin >> N >> D >> X;
  int count = 0;
  rep (i, N){
    cin >> a;
    count += ( D - 1 )/ a + 1;
  }
  cout << count + X << endl;
  return 0;
}

Measured memory_bytes: 256
/*
 *
 *   Author     : Amit Kumar
 *   Date    	: June 4 2019
 * 
 */

#include <bits/stdc++.h>

//#define FAST_INPUT_OUTPUT
//#define MORE_THAN_ONE_TESTCASE // COMMENT IT

#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define umii unordered_map<int,int>
#define umll unordered_map<long long ,long long>
#define umsi unordered_map<string , int>
#define umsl map<string , long long> 
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define pqi priority_queue<int>
#define pql priority_queue<long long>
#define ub upper_bound
#define lb lower_bound
#define bint long long int
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define iv(v) for(auto &i:v){cin>>i;}
#define ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define ovn(v) for(auto i:v){cout<<i<<endl;}
#define euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define eovn(v) for(auto i:v){cerr<<i<<endl;}
#define os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define osn(s) for(auto itr:s){cout<<itr<<endl;}
#define eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define rep(x) for(auto i=0 ; i<(x); ++i)
#define _rep(a,b) for(auto i=(a); i<(b); ++i)
#define endl '\n'
using namespace std;




auto SOLUTION_FUNCTION( void ) ->void {

    // your solution goes here 

    vi v(6);

    iv(v);

    int diff = 0;

    
    for(int i=1; i<5; ++i){
        diff += abs(v[i] - v[i-1]);
    }
    if(diff<=v[5])
        puts("Yay!");
    else
        puts(":(");




    return ;
}




int main(void){
#ifdef FAST_INPUT_OUTPUT
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#endif
#ifdef MY_LOCAL_PROJECT
    freopen("ain","r",stdin);
    freopen("aout","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { //Simulate flip processes
	//UPD: Don't always need to take max rows
 
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int M = input.nextInt();
		int K = input.nextInt();
		System.out.println(Valid(N,M,K)?"Yes":"No");
	}	
	public static boolean Valid(int N,int M,int K) {
		for (int r = 0; r <= N; r++) {
			int numB = r*M;
			for (int c = 0; c <= M; c++) {
				int leftrows = N-r;
				int net = leftrows-r;
				int total = numB+c*net;
				if (total==K) {
					return true;
				}
			}
		}
		return false;
	}
}

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

int main() {
    ll A,B,K;cin >> A >> B >> K;
    if (K > A) {
        K = K - A;
        A = 0;
        if (B - K < 0) B = 0;
        else B = B - K;
    }
    else A = A - K;
    cout << A << " " << B << endl;
}

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

int main(){
    int a;
    int b;
    int c;
    int t=0;
    int e=0;
    int d=0;
    int all=0;
    while(1){
        cin>>a>>b>>c;
        if(a+b<c||a+c<b||b+c<a){
            cout<<all<<" "<<t<<" "<<e<<" "<<d<<endl;
            break;
        }
        all = all+1;
        if((a*a)+(b*b)==(c*c)||(b*b)+(c*c)==(a*a)||(a*a)+(c*c)==(b*b)){
            t=t+1;
            
        }else if((a*a)+(b*b)<c*c||(b*b)+(c*c)<a*a||(a*a)+(c*c)<b*b){
            d=d+1;
            
        }else if((a*a)+(b*b)>c*c||(b*b)+(c*c)>a*a||(a*a)+(c*c)>b*b){
            e=e+1;
            
        }
    }
//    cout<<all<<" "<<t<<" "<<e<<" "<<d<<endl;
    return 0;
}



Measured memory_bytes: 3116
#include <stdio.h>

#define SIZE 2000000

int main() {
  int A[SIZE];
  int H=0;
  int i, l, largest, tmp, n;
  char com[21], buf[20];
  buf[19]='\0';
  char *p;
  do {
    fgets(com, 20, stdin);
    if (com[0] == 'i') {
      n = 0;
      p = com+7;
      while (*p!='\n') {
        n = n*10+*p-'0';
        p++;
      }
      A[++H] = n; //myatoi(com+7);
      for (i=H; i>1 && A[i/2]<A[i];i/=2) {
        tmp = A[i/2];
        A[i/2] = A[i];
        A[i] = tmp;
      }

    } else if (com[1]=='x') { // extract
      n = A[1];
      for (i=18; n>0; n/=10) buf[i--]=(n%10)+'0';
      puts(buf+i+1);
      A[1] = A[H];
      i = 1;
      while (1) {
        l = i*2;
        largest = i;
        if (l < H && A[l] > A[i])        largest = l;
        if (l+1 < H && A[l+1] > A[largest])  largest = l+1;
        if (largest == i) break;
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        i = largest;
      }
      H--;
    }
  } while (com[2]!='d');
  return 0;
}


Measured memory_bytes: 5480
/*
TASK: ditch
LANG: C++11
 */
//#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;
const int N = 5e3 + 3, M = 2 * 3e4 + 3;

int v[20],c[20];
int main() {
    //freopen("test.in", "r", stdin);
    int n;
    while(cin>>n){
        int res=INT_MIN;
        for(int i=0;i<n;i++)cin>>v[i];
        for(int i=0;i<n;i++)cin>>c[i];
        for(int i=0;i<1<<n;i++){
            int s=0;
            for(int j=0;j<n;j++)
                if((i>>j)&1)
                    s+=v[j]-c[j];
             res=max(res,s);
        }
        cout<<res<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
def gcd(a,b) :
    if a % b == 0 :
    	return b
    return gcd(b,a%b)
     
def lcm(a,b) :
    return a//gcd(a,b)*b
     
N = int(input())
res = 1
for i in range(N) :
    res = lcm(res, int(input()))
print(res)

Measured memory_bytes: 3060
//package april2020;

import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

public class Main {
//	static long[] dp;
	static int d;
	static long MOD = (long)1e9+7;
//	static ArrayList<Integer>[] graph;
//	static HashSet<Integer> visited;
//	static long[][] dp;
//	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws IOException {
		FastReader scn = new FastReader();
		OutputStream out = new BufferedOutputStream ( System.out );
		
		char[] k=scn.next().toCharArray();
		d = scn.nextInt();
		long[][] dp = new long[d][2];
		
		dp[0][0]= 1;
		
		for(int where =0;where<k.length;where++) {
			long[][] new_dp = new long[d][2];
			
			for(int sum=0;sum<d;sum++) {
				for(int sm_already=0;sm_already<2;sm_already++) {
					for(int digit =0;digit<10;digit++) {
						if(digit>k[where]-'0'&&sm_already==0) {
							break;
						}
						new_dp[(sum+digit)%d][(sm_already==1||(digit<k[where]-'0'))?1:0]=(new_dp[(sum+digit)%d][(sm_already==1||(digit<k[where]-'0'))?1:0]+dp[sum][sm_already])%MOD;
					}
				}
			}
			dp = new_dp;
		}
		long ans = (dp[0][0]+dp[0][1])%MOD;
		ans--;
		if(ans==-1) {
			ans = MOD-1;
		}
		out.write((ans+"\n").getBytes());
		out.close();
	}
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
}


Measured memory_bytes: 42196
def isSequence?(x)
  return x[0] + 1 == x[1] && x[1] + 1 == x[2]
end

def isSameNumber?(x)
  return x[0] == x[1] && x[1] == x[2]
end


# ????????????????????????????????????????????????????????????????????? 
def permutation(_x)
  @res = []
  m = []
  _x.uniq.map{|i| m << _x.count(i)}
  x = _x.uniq
  def perm(x, m, result=[])
    if m.all?{|n| n == 0 }
      @res << result
    else
      (m.length).times{|i|
        if m[i] > 0
          m[i] -= 1
          perm(x, m, result+[x[i]])
          m[i] += 1
        end
      }
    end
  end
  perm(x, m)
  return @res
end

cl = {"R"=>0, "G"=>10,"B"=>100}
k = 9
t = gets.to_i
t.times do |i|
  n = gets.split.map(&:to_i)
  c = gets.split
  k.times do |j|
    n[j] += cl[c[j]]
  end
  n.sort!


  if((n[3] - n[2]).between?(0, 2) || (n[6] - n[5]).between?(0, 2))
  nnew = permutation(n)
  tres = nnew.any?{|v|
    res = []
    3.times do |k|
      res << [v[k * 3], v[k * 3 + 1], v[k * 3 + 2]]
    end
    res.all?{|x| isSequence?(x) || isSameNumber?(x)}
  }
  p tres ? 1: 0
  else
    res = []
    3.times do |k|
      res << [n[k * 3], n[k * 3 + 1], n[k * 3 + 2]]
    end
    p (res.all?{|x| isSequence?(x) || isSameNumber?(x)}) ? 1 : 0
  end
end

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

int numb;
void setsp(int h,int w,int turn,int n,vector<vector<int>> &sp){
    for(int i=0;i<turn+2;i++){
        if(numb>n) return;
        sp[h][w]=numb;
        numb++;
        w++;
    }
    w--;
    h--;
    for(int i=0;i<turn*2+1;i++){
        if(numb>n) return;
        sp[h][w]=numb;
        numb++;
        h--;
    }
    h++;
    w--;
    for(int i=0;i<turn*2+2;i++){
        if(numb>n) return;
        sp[h][w]=numb;
        numb++;
        w--;
    }
    w++;
    h++;
    for(int i=0;i<turn*2+2;i++){
        if(numb>n) return;
        sp[h][w]=numb;
        numb++;
        h++;
    }
    h--;
    w++;
    for(int i=0;i<turn;i++){
        if(numb>n) return;
        sp[h][w]=numb;
        numb++;
        w++;
    }
    
    setsp(h,w,turn+1,n,sp);
}
vector<int> isPrime;
void setPrime(){
    isPrime.assign(1e6+1,1);
    isPrime[0]=isPrime[1]=false;
    for(int i=2;i<isPrime.size();i++){
        if(isPrime[i]){
            for(int j=i*2;j<isPrime.size();j+=i){
                isPrime[j]=false;
            }
        }
    }
}

pair<int,int> merge(pair<int,int> val,int num){
    if(num>0 && isPrime[num]){
        return {val.first+1,num};
    }
    return val;
}
int main(){
    int n,m;
    setPrime();
    while(cin>>n>>m,n){
        const int SIZE=1200;
        vector<vector<int>> sp(SIZE,vector<int>(SIZE,-1));
        numb=1;
        setsp(SIZE/2,SIZE/2,0,n,sp);
        
        const int INF=1e9;
        vector<vector<pair<int,int>>> dp(SIZE,vector<pair<int,int>>(SIZE,{-INF,INF}));
        int h,w;
        for(int i=0;i<sp.size();i++){
            for(int j=0;j<sp[i].size();j++){
                if(sp[i][j]==m){
                    h=i,w=j;
                }
            }
        }
        dp[h][w]={isPrime[m],isPrime[m] ? m : 0};
        for(int i=0;i<sp.size()-1;i++){
            for(int j=0;j<sp[i].size();j++){
                if(j>0) dp[i+1][j-1]=max(dp[i+1][j-1],merge(dp[i][j],sp[i+1][j-1]));
                dp[i+1][j]=max(dp[i+1][j],merge(dp[i][j],sp[i+1][j]));
                if(j<sp[i].size()-1) dp[i+1][j+1]=max(dp[i+1][j+1],merge(dp[i][j],sp[i+1][j+1]));
            }
        }   
        pair<int,int> res=dp[0][0];     
        for(int i=0;i<sp.size();i++){
            res=max(res,*max_element(dp[i].begin(),dp[i].end()));
        }
        cout<<res.first<<" "<<res.second<<endl;
    }

    return 0;
}

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

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

int main(){
  int N,M;
  cin>>N>>M;
  int K[N];
  vector<vector<int>> A(N);
  map<int,int> m;
    rep(i,N){
    cin>>K[i];
    rep(j,K[i]){
      int t;
      cin>>t;
      A[i].push_back(t);
      m[t]++;
	}  }
    int count=0;
    for(int i=1;i<M+1;i++){
      if(m[i]==N)
	count++;
    }
    cout<<count<<endl;

  return 0;
}


Measured memory_bytes: 256
s=input()
n=len(s)
res=0
for i in range(n):
  if s[i]=='A' or s[i]=='C' or s[i]=='G' or s[i]=='T':
    ans=1
    j=i+1
    while j<n:
      if s[j]=='A' or s[j]=='C' or s[j]=='G' or s[j]=='T':
        ans+=1
        j+=1
      else:
        break
  else:
    continue
  res=max(res,ans)
print(res)

Measured memory_bytes: 9092
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 100000  //check the limits, man
int main()
{
    int a,b;
    in2(a,b);
    int ans=0;
    ans+=max(4-a,0);
    ans+=max(4-b,0);
    if(a==1 && b==1)
        ans+=4;
    llout(ans*N);
}





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

int main(void)
{
	char s[20],t[20];
	scanf("%s %s",s,t);
	for(int i=0;i<strlen(s);i++){
		if(s[i]!=t[i]){
		       printf("No\n");
		       return 0;
		      }
	}
	printf("Yes\n");
	return 0;
}



Measured memory_bytes: 1636
import java.util.Scanner;

//Dividing Students
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			while(n--!=0){
				int m = sc.nextInt();
				int e = sc.nextInt();
				int j = sc.nextInt();
				char a = 'C';
				if((m==100||e==100||j==100)||((m+e)/2>=90)||(m+e+j)/3>=80)a='A';
				else if((m+e+j)/3>=70||(m+e+j)/3>=50&&(m>=80||e>=80))a='B';
				System.out.println(a);
			}
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

  int n = sz(s);

  if (s[0] != 'A') {
    puts("WA");
    return 0;
  }

  bool C = false;
  int iC;
  for (int i = 2; i <= n-2; ++i) {
    if (!C && s[i] == 'C') {
      iC = i;
      C = true;
    }
    else if (C && s[i] == 'C') {
      puts("WA");
      return 0;
    }
  }
  if (!C) {
    puts("WA");
    return 0;
  }

  rep(i,n) {
    if (i == 0) continue;
    if (i == iC) continue;
    if (!('a' <= s[i] && s[i] <= 'z')) {
      puts("WA");
      return 0;
    }
  }

  puts("AC");
  return 0;
}

Measured memory_bytes: 256
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
//use permutohedron::LexicalPermutation as _;
use proconio::input;
//use proconio::marker::Chars;
//use proconio::marker::Usize1;
//use std::collections::HashSet;
//use std::collections::HashMap;
//use std::collections::BTreeMap;
//use std::cmp::*;
// use std::num;
const MOD: i64 = 1_000_000_007;
fn main() {
    input! {
        n:usize,m:usize
    }
    let mut fact = vec![1i64; m + 1];
    for i in 2..(1 + m) {
        fact[i] = fact[i - 1] * (i as i64) % MOD;
    }
    let perm = |m, n| fact[m] * modInv(fact[m - n]) % MOD;
    let comb = |m, n| fact[m] * modInv(fact[m - n]) % MOD * modInv(fact[n]) % MOD;
    //let comb2 = |m| n * (n - 1) * modInv(2) % MOD;
    // Aを固定して、Bを考える。
    // 求めたいパターンは、全てのパターン(0個以上が同じ) - 1個以上が同じ + 2個以上が同じ - ...
    // all = m P n
    // k以上が同じケース。
    let mut ans = 0;
    for i in 0..n + 1 {
        if i % 2 == 0 {
            ans += comb(n, i) * perm(m, i) % MOD * modPow(perm(m - i, n - i), 2) % MOD;
        } else {
            ans -= comb(n, i) * perm(m, i) % MOD * modPow(perm(m - i, n - i), 2) % MOD;
        };
    }
    ans = (ans % MOD);
    // println!("{},{}", fact[2], modInv(fact[2]));
    // println!("{}", x);
    println!("{}", (ans + MOD) % MOD);
}

fn modPow(a: i64, n: i64) -> i64 {
    let mut res = 1;
    let mut a = a;
    let mut n = n;
    while n > 0 {
        if n % 2 != 0 {
            res = res * a % MOD;
        }
        a = a * a % MOD;
        n = n / 2;
    }
    return res;
}
fn modInv(a: i64) -> i64 {
    modPow(a, MOD - 2)
}


Measured memory_bytes: 5912
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()

    # 引き出せる金額リスト
    l = [1]
    a = 6
    b = 9
    while a <= N or b <= N:
        if a < b:
            l.append(a)
            a *= 6
        else:
            l.append(b)
            b *= 9

    # ナップザック
    dp = [INF] * (N + 1)
    dp[0] = 0
    for i in range(1, N + 1):
        for j in l:
            if i - j >= 0:
                dp[i] = min(dp[i - j] + 1, dp[i])

    print(dp[-1])

if __name__ == '__main__':
    resolve()


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

int main() {
int n;
   cin>>n;
  int va[n];
  int co[n];
  rep(i, n){
    cin>>va[i];}
  rep(i, n){
    cin>>co[i];}
  
  int cnt=0;
  rep(i, n){
    if(va[i]-co[i]>=0){
      cnt+=va[i]-co[i];}
  }
  
  cout<<cnt<<endl;
  
}

Measured memory_bytes: 256