akhauriyash/Code-Regression huggingface dataset:
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():
    s = S()
    t = S()
    c = 0
    for i in range(len(s)):
        if s[i] == t[i]:
            c += 1
    print(c)

main()



Measured memory_bytes: 5556
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m=LI()
  d=[]
  for _ in range(10):
    d.append(LI())

  for k in range(10):
    for i in range(10):
      for j in range(10):
        d[i][j]=min(d[i][j],d[i][k]+d[k][j])

  ans=0
  for _ in range(n):
    l=LI()
    for x in l:
      if x not in (1,-1):
        ans+=d[x][1]

  return ans

# main()
print(main())


Measured memory_bytes: 6736
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
using namespace std;
inline bool cmp(pll x,pll y){return x.second*y.first<y.second*x.first;}
ll dp[32],n,T,ans,del;
vector<int>all;vector<pll>v;
int main(){
	ios_base::sync_with_stdio(false);cin>>n>>T;
	for(int i=0,x,y;i<n;++i){
		cin>>x>>y;
		y+=x+1;
		if(!x)all.push_back(y);
		else v.push_back(pll(x,y));
	}
	sort(v.begin(),v.end(),cmp);
	for(int i=1;i<32;++i)dp[i]=T+1;
	for(int i=0;i<v.size();++i){
		pll p=v[i];
		for(int j=30;~j;--j)if(dp[j]<=T)dp[j+1]=min(dp[j+1],(p.first+1)*dp[j]+p.second);
	}
	sort(all.begin(),all.end());
	for(int i=0;i<32;++i){
		if(dp[i]>T)continue;
		del=T-dp[i];int pos=0;
		for(;pos<all.size() and del>=all[pos];del-=all[pos++]);
		ans=max(ans,(ll)(pos+i));
	}
	cout<<ans<<'\n';
}

Measured memory_bytes: 6256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		long ans = 0;
		ArrayList<Integer>array = new ArrayList<Integer>();

		for(int i=1 ; i<=n ; i++) {
			if( (i % 3 != 0) && (i % 5 != 0) ) {
				array.add(i);
			}
		}

		for(int i=0 ; i<array.size() ; i++) {
			ans += array.get(i);
		}

		System.out.println(ans);

		sc.close();


	}

}


Measured memory_bytes: 61552
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>
#include <bitset>

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

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

const int MAX = 510000; //nCrのr
//const ll INF = (ll)1e18 + 1;

#include <cassert>
long long fac[MAX], finv[MAX], inv[MAX], facn[MAX];
class mint {
public:
    long long x;
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    //mint operator-() const{ return mint(-x);}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

};

template<class T>
struct combination {
    vector<T> fact_, ifact_;
    combination(long long n):fact_(n+1),ifact_(n+1) {
      assert(n < MOD);
      fact_[0] = 1;
      for (int i = 1; i <= n; ++i) fact_[i] = fact_[i-1]*i;
      ifact_[n] = fact_[n].inv();
      for (int i = n; i >= 1; --i) ifact_[i-1] = ifact_[i]*i;
    }
    T com(long long n, long long k) {
      if (k < 0 || k > n) return 0;
      return fact_[n]*ifact_[k]*ifact_[n-k];
    }
    T fact(ll n){
      if (n < 0) return 0;
      return fact_[n];
    }
};

int N, K;
vector<vector<int>> G;
combination<mint> C(1000000);

void dfs(int v, int p, mint& ans, int depth){
  int chs = 0;
  for (auto ch: G[v]){
    if (ch == p) continue;
    ++chs;
    dfs(ch, v, ans, depth + 1);
  }
  if (depth == 0) ans *= C.com(K - 1, chs) * C.fact(chs);
  else ans *= C.com(K - 2, chs) * C.fact(chs);
}

int main(){
  cin >> N >> K;
  G.assign(N, vector<int>());
  for (int i = 0; i < N - 1; ++i){
    int a, b; cin >> a >> b;
    --a, --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  mint ans = K;
  dfs(0, -1, ans, 0);
  cout << ans.x << endl;
}


Measured memory_bytes: 27264
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  ll n;
  cin>>n;
  ll arr[n];
  for(int i=0;i<n;i++)
	cin>>arr[i];
  ll dp[n];
  dp[0]=0;
  for(int i=1;i<n;i++)
  {
  	if(i==1)
  	{
  		dp[i] = dp[i-1]+abs(arr[i-1]-arr[i]);
  		continue;
	}
    dp[i] = min(dp[i-1]+abs(arr[i-1]-arr[i]),dp[i-2]+abs(arr[i-2]-arr[i]));
  }
  cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1792
H, W = map(int, input().split())
G = [list(map(lambda x: x == '#', input().strip())) for _ in range(H)]
Takahashi = [[False]*W for _ in range(H)]
Aoki = [[False]*W for _ in range(H)]

for h in range(H):
    for w in range(W):
        if w == 0:
            Takahashi[h][w] = True
        elif not h & 1:
            Aoki[h][w] = True
        if w == W-1:
            Aoki[h][w] = True
        elif h & 1:
            Takahashi[h][w] = True
        
        if G[h][w]:
            Takahashi[h][w] = True
            Aoki[h][w] = True

print('\n'.join([''.join(['#' if s else '.' for s in Takahashi[i]]) for i in range(H)]))
print('')
print('\n'.join([''.join(['#' if s else '.' for s in Aoki[i]]) for i in range(H)]))
#print('\n'.join([''.join(['#' if s1 & s2 else '.' for s1, s2 in zip(Aoki[i], Takahashi[i])]) for i in range(H)]))


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

int n, W, w[101], v[101];
int t[4][101], cnt[4];

long long prefix[4][101];
void pre(){
	for(int val=0; val<4; val++)
		for(int i=1; i<=cnt[val]; i++)
			prefix[val][i]=prefix[val][i-1]+t[val][i];
}

long long get(int val, int k){
    return prefix[val][k];
}

int main(){
	scanf("%d %d", &n, &W);
	for(int i=1; i<=n; i++){
		scanf("%d %d", &w[i], &v[i]);
		int val=w[i]-w[1];
		t[val][++cnt[val]]=v[i];
	}
	for(int val=0; val<4; val++){
		sort(t[val]+1, t[val]+1+cnt[val]);
		reverse(t[val]+1, t[val]+1+cnt[val]);
	}
	pre();
	long long valmax=0;
	for(int i=0; i<=cnt[0]; i++){
		for(int j=0; j<=cnt[1]; j++){
			for(int k=0; k<=cnt[2]; k++){
				long long nowsum=0;
				nowsum += w[1]*1ll*i;
				nowsum += (w[1]+1)*1ll*j;
				nowsum += (w[1]+2)*1ll*k;
				if(nowsum > W) break;

				int s=1, e=cnt[3], ans=0;
				while(s<=e){
					int mid=(s+e)/2;
					if(nowsum + (w[1]+3)*1ll*mid <= W)
						ans=mid, s=mid+1;
					else e=mid-1;
				}

                long long valsum=0;
                valsum += get(0, i);
                valsum += get(1, j);
                valsum += get(2, k);
                valsum += get(3, ans);
                valmax = max(valmax, valsum);
			}
		}
	}
	printf("%lld", valmax);
	return 0;
}


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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define SORT(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> p;

int main(){
	vector<int> A(3);
	rep(i,3){
		cin>>A[i];
	  }
	  SORT(A);
	  if(A[0]+A[1]==A[2]){
		  cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		  }

}
	 


Measured memory_bytes: 256
s = input()
res = 0
m = 1
p =[0]*2019
for i in map(int,s[::-1]):
    res +=i*m
    res %=2019
    p[res] +=1
    m *=10
    m %=2019
print(p[0]+sum([i*(i-1)//2 for i in p]))

Measured memory_bytes: 9064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin >> s;
  ll w = 0;
  ll res = 0;
  for(int i = (int)s.size() - 1;i >= 0;i--){
    if(s[i] == 'W')w++;
    else res += w;
  }
  cout << res << endl;
}

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

int main()
{
  string s = "ACL";
  string ss = "";
  int k = 0;
  cin >> k;
  
  for(int i = 0; i < k; ++i)
  {
    ss += s;
  }
  cout << ss;  
}

Measured memory_bytes: 3628
n = int(input())
dd = {}
for d in map(int, input().split()):
  if d in dd:
    dd[d] += 1
  else:
    dd[d] = 1
m = int(input())
td = {}
for t in map(int, input().split()):
  if t in td:
    td[t] += 1
  else:
    td[t] = 1

ans = True
for k, v in td.items():
  if k not in dd:
    ans = False
    break
  else:
    if dd[k] < v:
      ans = False
      break
if ans:
  print('YES')
else:
  print('NO')


Measured memory_bytes: 67424
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
//static const long double pi = 3.1415926535897932;

using namespace std;
using ll = long long int;
using ull = unsigned long long;

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ll combination(ll n, ll r) { // nCr の計算
	if (n < 0 || r < 0 || r > n) return -1;

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> num(r);
	vector<ll> den(r);

	for (ll i = 0; i < r; i++) {
		num[i] = n - r + i + 1;
		den[i] = i + 1;
	}

	for (ll p = 2; p <= r; p++) {
		ll pivot = den[p - 1];
		if (pivot > 1) {
			ll offset = (n - r) % p;
			for (ll k = p - 1; k < r; k += p) {
				num[k - offset] /= pivot;
				den[k] /= pivot;
			}
		}
	}
	ll result = 1;
	for (ll k = 0; k < r; k++) {
		if (num[k] > 1) result *= num[k];
	}
	return result;
}

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

int main() {
	string s, t;
	cin >> s >> t;
	int ans = 0;
	for (int i = 0; i < t.length(); i++) {
		if (s[i] != t[i]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3900
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <cmath>
using namespace std;
int mp[555][555];
struct node
{
    int x1,y1,x2,y2;
    node(int x,int y,int xx,int yy):
        x1(x),y1(y),x2(xx),y2(yy){}
};

int main()
{
    vector<node> ans;
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            scanf("%d",&mp[i][j]);
    for(int i=1;i<=n;i++){
        for(int j=1;j<m;j++){
            if(mp[i][j]&1){
                ans.push_back(node(i,j,i,j+1));
                mp[i][j+1]++;
            }
        }
    }
    for(int i=1;i<n;i++){
        if(mp[i][m]&1)
            ans.push_back(node(i,m,i+1,m)),mp[i+1][m]++;
    }
    printf("%d\n",ans.size());
    for(int i=0;i<ans.size();i++){
        printf("%d %d %d %d\n",ans[i].x1,ans[i].y1,ans[i].x2,ans[i].y2);
    }
}


Measured memory_bytes: 5232
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#define ll long long
#define ull unsigned long long
using namespace std;

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

	int n;
	cin >> n;
	vector<vector<int>> V(n, vector<int>(3));
	vector<vector<int>> DP(n, vector<int>(3, INT32_MIN));
	for (auto &v : V) for (int &a : v) cin >> a;
	DP.at(0).at(0) = V.at(0).at(0);
	DP.at(0).at(1) = V.at(0).at(1);
	DP.at(0).at(2) = V.at(0).at(2);

	for (int i = 1; i < n; i++){
		for (int j = 0; j < 3; j++){
			for (int k = 0; k < 3; k++){
				if (k != j) DP.at(i).at(j) = max(DP.at(i).at(j), 
					DP.at(i - 1).at(k) + V.at(i).at(j));
			}
		}
	}

	int mx = -1;
	for (int x : DP.back()) mx = max(x, mx);
	cout << mx;

	return 0;
}


Measured memory_bytes: 11136
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;


typedef struct link {
	link* next = NULL;
	link* pre = NULL;
	int a;
}*node;


node  R = new link;
node Creation() {
	node L = new link;
	L->next = R;
	R->pre = L;
	return L;
}

void insert(node& L , int e) {
	node s = new link;
	s->a = e;

		s->pre = L;
		s->next = L->next;
		L->next->pre = s;
		L->next = s;
	

	
}

void del(node &L , int e ) {
	node p = L;
	while (p && p->a != e) {
		p = p->next;
	}
	if (!p) return;
	if (p->next) {
		p->next->pre = p->pre;
		p->pre->next = p->next;
	}
	else {
		p->pre->next = NULL;
	}
	delete p;
}

void deletFirst(node & L) {
	int e = L->next->a;
	node p = L;
	del(L, e);
}

void deletLast(node& L) {
	node p = R->pre;
	p->pre->next = R;
	R->pre = p->pre;
	delete p;
}

int main() {

	char s[20];
	int n;
	int e;
	cin >> n;
	node L = Creation();
	for (int i = 0; i < n; i++) {
		scanf("%s %d", s, &e);
		if (s[0] == 'i') {
			insert(L, e);

		}
		else if (s[0] == 'd') {
			if (strlen(s) <= 6) del(L, e);
			else if (s[6] == 'F') {
				deletFirst(L);
			}
			else {
				deletLast(L);
			}
		}




	}		
   node p = L->next;
		int isf = 0;
		while (p != R) {
			if (isf++ > 0) printf(" ");
			printf("%d", p->a);
			p = p->next;
		}
		cout << endl;
}









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

int dp[1000000];
int dpodd[1000000];
int num[200];
int INF = 10000000;
int main(){
	for(int i = 0; i < 200; i++){
		num[i] = (i + 1) * (i + 2) * (i + 3)/ 6;
	}
	dp[0] = 0;
	dpodd[0] = 0;
	for(int i = 1; i < 1000000; i++){
		dp[i] = INF;
		dpodd[i] = INF;
		for(int j = 0; num[j] <= i; j++){
			dp[i] = min(dp[i], dp[i - num[j]] + 1);
			if(num[j] % 2 == 1){
				dpodd[i] = min(dpodd[i], dpodd[i - num[j]] + 1);
			}
		}
	}
	int N;
	while(cin >> N, N){
		cout << dp[N] << " " << dpodd[N] << endl;
	}
}

Measured memory_bytes: 8972
package main

import (
	"fmt"
	"sort"
)

var ans []int

func dfs(n int) {
	if 3234566667 < n {
		return
	}
	ans = append(ans, n)
	d := n % 10
	if d != 0 {
		dfs(n*10 + d - 1)
	}
	if d != 9 {
		dfs(n*10 + d + 1)
	}
	dfs(n*10 + d)
}

func main() {
	var k int
	fmt.Scan(&k)
	for i := 0; i < 9; i++ {
		dfs(i + 1)
	}
	sort.Ints(ans)
	fmt.Println(ans[k-1])
}


Measured memory_bytes: 5248
function main(input) {
  const s = Number(input.trim());
  const map = {};
  map[s] = true;
  let result = 1;
  let num = s;
  while(true) {
    result++;
    if (num%2 === 0) {
      num /= 2;
    } else {
      num = 3*num + 1;
    }
    if (map[num]) break;
    map[num] = true;
  }
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

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





string lcs(const string& a, const string& b) {
    const int n = a.size(), m = b.size();
    vector< vector<int> > X(n+1, vector<int>(m+1));
    vector< vector<int> > Y(n+1, vector<int>(m+1));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (a[i] == b[j]) {
                X[i+1][j+1] = X[i][j] + 1;
                Y[i+1][j+1] = 0;
            } else if (X[i+1][j] < X[i][j+1]) {
                X[i+1][j+1] = X[i][j+1];
                Y[i+1][j+1] = +1;
            } else {
                X[i+1][j+1] = X[i+1][j];
                Y[i+1][j+1] = -1;
            }
        }
    }
    string c;
    for (int i = n, j = m; i > 0 && j > 0; ) {
        if      (Y[i][j] > 0) --i;
        else if (Y[i][j] < 0) --j;
        else { c.push_back(a[i-1]); --i; --j; }
    }
    reverse(c.begin(), c.end());
    return c;
}

void solve(string s, string t){
   cout << lcs(s,t)<< endl;
}

int main(){
    string s;
    cin >> s;
    string t;
    cin >> t;
    solve(s, t);
    return 0;
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    int n,m;
    cin >> n >> m;
    map<int,bool> mp;
    int ac = 0;
    map<int,int> wa;
    for(int i = 0; i < m; i++){
        int p;
        string s;
        cin >> p >> s;
        if(s == "AC" && !mp[p]){
            mp[p] = true;
            ac++;
        } else if (s == "WA" && !mp[p]) {
            wa[p]++;
        }
    }
    int WA = 0;
    for(auto p:mp){
        if(p.second) WA += wa[p.first];
    }
    cout << ac << " " << WA << endl;
    return 0;
}

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

int main() {
  
  int A, B, C, D; cin >> A >> B >> C >> D;
  
  while (true) {
    
    C -= B;
    
    if (C <= 0) {
      cout << "Yes" << endl;
      return 0;
    }
    
    A -= D;
    
    if (A <= 0) {
      cout << "No" << endl;
      return 0;
    }
    
  }
  
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define all(v) v.begin(),v.end()
#define MP make_pair
#define pb push_back


int main(){
    int N;
    cin >> N;
    vector<int> P(N);
    rep(i,N) cin >> P[i];
    P.emplace_back(0);
    int ans = 0;
    rep(i,N)if(P[i] == i+1) ++ans,++i;

    cout << ans << endl;
}

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

int main(){
  vector<int> l(3);
  for(int i = 0;i < 3;i++){
    cin >> l[i];
  }
  sort(l.begin(),l.end());
  cout << l[0]*l[1] / 2 << endl;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int x, ans, xx;
int main ()
{
	cin >>x;
	xx = x % 500;
	x = x - xx;
	ans += x * 2;
	xx = (xx - xx % 5);
	ans += xx; 
	cout <<ans;
	return 0;
}

Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.util.Scanner;

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

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	int S = sc.nextInt();
    	int W = sc.nextInt();

    	if(W>=S) {
    		System.out.println("unsafe");
    	} else {
    		System.out.println("safe");
    	}

    }

}

Measured memory_bytes: 35672
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  int n;
  cin>>n;
  int b=n;
  int a=0;
  for(int i=0;n>0;n/=10){
    a+=(n%10);
  }
  if(b%a==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

int main() {
  int N, M, Q, l, r, p, q;
  cin >> N >> M >> Q;
  vector< vector<int> > s(N+1, vector<int>(N+1));
  for (int i=0; i<M; i++) {
    scanf("%d %d", &l, &r);
    s[l][r]++;
  }
  for (int i=1; i<=N; i++) {
    for (int j=1; j<=N; j++) {
      s[i][j] += s[i][j-1] + s[i-1][j] - s[i-1][j-1];
    }
  }
  for(int i=0; i<Q; i++) {
    scanf("%d %d", &p, &q);
    cout << s[q][q] - s[q][p-1] - s[p-1][q] + s[p-1][p-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 1920
import java.util.*;
public class Main{
	static public void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int tmp;
		if(a>b){
			tmp=a;
			a=b;
			b=tmp;
		}
		if(b>c){
			tmp=b;
			b=c;
			c=tmp;
		}
		if(a>b){
			tmp=a;
			a=b;
			b=tmp;
		}
		System.out.println(a+" "+b+" "+c);
	}
}


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

using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

bool dp[100100];

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

    vector<int>A(N);
    rep(i,N)cin >> A[i];

    int ans=1;
    for(int i =0; i<N-1;){
        //差が0ならスルー
        if(A[i+1]-A[i] ==0){
        i +=1;
        continue;
        }

        //増加
        if(A[i+1]-A[i] >0){
            repr(j,i,N-1){
                i=j+1;
                if(A[j+1]-A[j] < 0){
                    ans+=1;
                    break;
                }
            }
        }

        //減少
        if(A[i+1]-A[i] < 0){
            repr(j,i,N-1){
                i=j+1;
                if(A[j+1]-A[j] > 0){
                    ans+=1;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 640
#include <stdio.h>

int main(int argc, char const *argv[]) {
    int a,b,r,d;
    double f;

    scanf("%d %d",&a,&b);
    d = a / b;
    r = a % b;
    f = 1.00000 * a / b;
    printf("%d %d %.5lf\n",d,r,f);
    return 0;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
typedef long long int lint;

int main(){
    int p, q, r;
    cin >> p >> q >> r;
    vector <int> v;
    v.push_back(p+q);
    v.push_back(q+r);
    v.push_back(p+r);
    sort(v.begin(), v.end());
    cout << v[0];
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }


void run() {
	int n; scanf("%d",&n);
	printf("%d\n",(n-2)*180);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <boost/math/constants/constants.hpp>
#include <boost/math/common_factor_rt.hpp>

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

int main(){
  int K, X;
  cin >> K >> X;
    
  for(int i=0;i<2*K-1;i++) cout << X-K+1+i << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; 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(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  string s;
  cin >> s;
  int l=0;
  while(s[l]!='A') l++;
  int r=sz(s)-1;
  while(s[r]!='Z') r--;
  cout << r-l+1 << endl;
  return 0;
}

Measured memory_bytes: 640
def main():
    import sys
    input = sys.stdin.readline

    N, K = map(int, input().split())

    d = [0]*K
    A = [0]*K
    for i in range(K):
        d[i] = int(input())
        A[i] = list(map(int, input().split()))

    have = []
    for a in A:
        have[len(have):] = set(a)
    print(N - len(set(have)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9264
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define pii 3.14
#define mod (ll)(1e9+7)
#define inf (ll)(1e18)
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ordered_set tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
#define pi pair<int,int>
#define N (ll)(1e7 + 5)

ll dp[N];

void solve()
{
    ll n;
    cin>>n;

    if(n==1)
    {
        cout<<"1\n";
        return;
    }


    for(ll i=1;i<=n;i++)
        dp[i] = i;
    dp[2] = 2;

    for(ll i=2;i*i<=n;i++)
    {
        if(dp[i] == i)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                if(dp[j] == j)
                    dp[j] = i;
            }
        }
    }

    ll ans = 1;
    for(ll i=2;i<=n;i++)
    {
        ll cur = 1;
        ll x = i;
        ll p = 0;
        while(x > 1)
        {
            p=0;
            ll cp = dp[x];
            while(x%cp==0)
                x/=cp , p++;
            cur*=(p+1);
        }
        ans += (cur*i);
        //cout<<ans<<"\n";
    }

    cout<<ans;
}

int main()
{
    fio;
    ll tc = 1;
    //cin>>tc;
    while(tc--)
    {
        solve();
    }
}


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

using ll=long long;
 
 
 
void solve(){
    vector<int > a(3);
    for(int i=0; i<3; i++)cin>>a[i];
    sort(a.begin(), a.end());
    cout<<a[0]+a[1]<<endl;
}
 
signed main(){
    //while(1)
    solve();
}

Measured memory_bytes: 256
def count_black(c)
  count = 0
  c.each do |cc|
    count += cc.select { |item| item == '#' }.length
  end
  
  count
end

def fill_and_count_black(c, xs, ys)
  temp = Marshal.dump(c)
  cc = Marshal.load(temp)

  xs.each do |i|
    a = cc[i].length
    a.times do |j|
      cc[i][j] = 'a'
    end
  end

  ys.each do |i|
    a = cc.length
    a.times do |j|
      cc[j][i] = 'a'
    end
  end
  


  count = count_black(cc)
  
  #p xs
  #p ys
  #pp cc
  #p count
  #p ''
  
  count
end

h, w, k = gets.chomp.split(' ').map(&:to_i)

c = []
h.times do |i|
  c[i] = gets.chomp.split('')
end

xs = []
h.times { |i| xs << i }
ys = []
w.times { |i| ys << i }


count = 0
count += 1 if count_black(c) == k


h.times do |i|
  xs.combination(i + 1).to_a.each do |xxs|
    count += 1 if fill_and_count_black(c, xxs, []) == k
  end
end

w.times do |j|
  ys.combination(j + 1).to_a.each do |yys|
    count += 1 if fill_and_count_black(c, [], yys) == k
  end
end

h.times do |i|
  xs.combination(i + 1).to_a.each do |xxs|
    w.times do |j|
      ys.combination(j + 1).to_a.each do |yys|
        count += 1 if fill_and_count_black(c, xxs, yys) == k
      end
    end
  end
end

puts count


Measured memory_bytes: 14340
from bisect import*
n,k,*a=map(int,open(0).read().split())
if 0 in a:
    k-=1
    a.remove(0)
#print(a)
ans=[]

x=bisect(a,0)
for i in range(-k,1):
    p=x+i
    q=x+i+k-1

    if 0<=p<n and 0<=q<n:
        #print(p,q)
        c=a[p]
        d=a[q]
        ans.append(abs(c)+abs(d-c))
        ans.append(abs(d)+abs(d-c))
#print(ans)
print(min(ans or [0]))

Measured memory_bytes: 69672
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9
 
typedef long long ll;
 
using namespace std;
 
const ll inf = 1e18;
const ll mod = 1e9+7;
const int N = 2e5+5;
//int a[N];

int main()
 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 	
 	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

    int x;

    cin >> x;

    if (x) cout << 0;
    else cout << 1;

    return 0;
}

Measured memory_bytes: 3628
ip = input()# your code goes here
lis = ip.split(" ")
for i in range(len(lis)):
	lis[i] = int(lis[i])
lis = sorted(lis)
ans = 1e9
su = 0
for i in range(0,len(lis)-1):
	su+=abs(lis[i+1]-lis[i])
ans = min(ans,su)

print(ans)
	

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <vector>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <ctime>
#include <fstream>
#include <stdarg.h>
using namespace std;
const bool debug=false;
const bool INJUDGE=false;
#define FASTERCIN cin.tie(0);ios_base::sync_with_stdio(false)
typedef long long ll;
/*Time:
Status:
Type:
Author:*/
ll a[200005];
ll sum;
ll n,ans; 
map<ll,int> m;
ll C(ll num){
	return (num*(num-1)/2);
} 
int main(){
	scanf("%lld",&n);
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	for(int i=0;i<n;i++){
		sum+=a[i];
		m[sum]++;
	}
	for(map<ll,int>::iterator it=m.begin();it!=m.end();it++){
		if(it->first==0ll){
			ans+=it->second+C(it->second);
		}
		else if(it->second>=2){
			ans+=C(it->second);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 14336
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

int main(){
	int n;
	
	while(cin>>n,n){
		int totalA=0,totalB=0;
		for(int i=0;i<n;i++){
			int a,b;
			cin>>a>>b;
			if(a>b){
				totalA+=a+b;
			}
			else if(b>a){
				totalB+=a+b;
			}
			else{
				totalA+=a;
				totalB+=b;
			}
		}
		cout<<totalA<<" "<<totalB<<endl; 
	}
	return 0;
}

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

int main() {
	
	     ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	  
	   long long n,i,j,k,count=0,ans=0,x,a,b,c;
	   string s;
	   cin>>s;
	   n=s.length();
	   if(n==1)
	   {
	       cout<<"Yes"; return 0;
	   }
	   for(i=0;i<n/2;i++)
	   {
	       if(s[i]!=s[n-i-1])
	       count=1;
	   }
	   if(n<=3)
	   {
	       if(count==1)
	   cout<<"No";
	   else
	   cout<<"Yes"; return 0;
	   }
	   x=(n-1)/2;
	   for(i=0;i<x/2;i++)
	   {
	       if(s[i]!=s[x-i-1])
	       count=1;
	   }
	   x=(n+3)/2;
	   x--;
	   i=x;
	   j=n-1;
	   while(i>=j)
	   {
	       if(s[i]!=s[j])
	       count=1;
	       i++;
	       j--;
	   }
	   if(count==1)
	   cout<<"No";
	   else
	   cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long L;
int main() {
	L m,n;
	L a = 1;
	for (int i = 0; i < 10; i++)a *= 60;
	a *= 9;
	while (cin >> m, m) {
		cin >> n;
		int ans = 0;
		for (L i = m; i <= n; i++) {
			if (a%i==0)ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3088
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	ctr := 0
	for i := 0; i < n; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		if a == b {
			ctr++
		} else {
			ctr = 0
		}
		if ctr == 3 {
			fmt.Print("Yes")
			return
		}
	}
	fmt.Print("No")
}


Measured memory_bytes: 1836
Q, H, S, D = map(int, input().split())
N = int(input())
m1 = min(Q*4, H*2, S)

if N%2:
    print(N//2*D+m1 if D < 2*m1 else N*m1)
else:
    print(N*min(Q*8, H*4, S*2, D)//2)

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

int main() {
  ios::sync_with_stdio(false);
  int N;
  long long K;
  cin >> N >> K;
  vector<pair<int, int>> AB(N);
  for (int i = 0, a, b; i < N && cin >> a >> b; i++) AB.at(i) = {a, b};
  sort(AB.begin(), AB.end());

  long long sum = 0;
  for (int i = 0; i < N; i++) {
    sum += AB.at(i).second;
    if (sum >= K) {
      cout << AB.at(i).first << "\n";
      break;
    }
  }
}

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> k(m);
	vector<vector<int>> s(m);
	rep(i, m){
		cin >> k[i];
		rep(j, k[i]) {
			int tmp;
			cin >> tmp;
			tmp--;
			s[i].push_back(tmp);
		}
	}
	vector<int> p(m);
	rep(i, m) cin >> p[i];
	int ans = 0;
	for(int bit = 0; bit < (1<<n); bit++) {
		// 各スイッチの状態について
		bool ok = true;
		rep(i, m) {
			// 各電球のON条件を見る
			int cnt = 0;
			rep(j, k[i]) {
				if(bit & 1 << s[i][j]) cnt++;
			}
			if(p[i] == (cnt%2)) ;
			else {
				ok = false;
				break;
			}
			if(!ok) break;
		}
		if(ok) ans++;
	}
	cout << ans << endl;
	return 0;
}

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

struct BTNode{
  int key;
  BTNode *parent;
  BTNode *left;
  BTNode *right;
};

BTNode *root = NIL;

void insert(int value){
  BTNode *x = root;
  BTNode *y = NIL;
  BTNode *z = new BTNode;
  z->key = value;
  z->left = NIL;
  z->right = NIL;
  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

BTNode* find(BTNode *x, int k){
  while(x != NIL && x->key != k){
    if(x->key > k) x = x->left;
    else x = x->right;
  }
  return x;
}

void inorder(BTNode *x){
  if(x == NIL) return;
  inorder(x->left);
  cout << " " << x->key;
  inorder(x->right);
}

void preorder(BTNode *x){
  if(x == NIL) return;
  cout << " " << x->key;;
  preorder(x->left);
  preorder(x->right);
}

int main(){
  int n, v;
  string cmd;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> cmd;
    if(cmd == "insert"){
      cin >> v;
      insert(v);
    }
    else if(cmd == "find"){
      cin >> v;
      if(find(root, v)) cout << "yes" << endl;
      else cout << "no" << endl;
    }
    else if(cmd == "print"){
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 21828
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair 
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
typedef pair<int,int> pii;
typedef long long ll;	

string s;


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

	
	cin >> s;
	if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') {
		cout << 3 << "\n";
	}
	else if ((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R')){
		cout << 2 << "\n";
	}
	else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R'){
		cout << 1 << "\n";
	}
	else  {
		cout << 0 << "\n";
	}
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main(void){
    int S;

    cin >> S;

    int h = S/3600;
    int m = (S % 3600) / 60;
    int s = (S % 3600) % 60;

    cout << h << ":" << m << ":" << s <<endl;

    return 0;
    
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>

using namespace std;

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

int main() {
    long long x;
    cin>>x;
    x=abs(x);
    int ans,ans2;
    for(long long i=-500;i<500;++i){
        long long a=i*i*i*i*i-x;
        for(long long j=-500;j<500;++j){
            if(a==j*j*j*j*j){
                cout<<i<<" "<<j;
                return 0;
            }
        }
    }
}

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

int main(){
    string s;
    cin >> s;
    
    if(s == "a" ||s == "i" ||s == "u" ||s == "e" ||s == "o"){
        cout << "vowel" << endl;
    }else{
        cout << "consonant" << endl;
    }
}

Measured memory_bytes: 256
n,x=map(int,input().split())

#レベルNの層とパティの数を求める
a,p=[1],[1]
for i in range(n):
    a.append(2*a[i]+3)
    p.append(2*p[i]+1)

def cnt(n,x):
    #レベルNのバーガーのX層までに含まれるパティを数える
    if n==0:
        return 1 if x>=1 else 0

    elif x<=1+a[n-1]:
        return cnt(n-1,x-1)

    elif 2+a[n-1]<=x:
        return cnt(n-1,x-(a[n-1]+2))+p[n-1]+1

print(cnt(n,x))

Measured memory_bytes: 3064
from sys import stdin
import sys

[W, H, N] = list(map(int, stdin.readline().rstrip().split()))


Ws = 0
We = W

Hs = 0
He = H


A = []
for i in range(N):
    A.append(list(map(int, stdin.readline().rstrip().split())))

for i in range(N):
    [x, y, a] = A[i]
    if a == 1:
        Ws = max(Ws, x)
    elif a == 2:
        We = min(We, x)
    elif a == 3:
        Hs = max(Hs, y)
    elif a == 4:
        He = min(He, y)

if (We - Ws) <= 0 or (He - Hs) <=0:
    print(0)
else:
    print((We - Ws) * (He - Hs))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n,m;
    cin>>n>>m;
    vector<int> s(n),t(m);
    rep(i,n) cin>>s[i];
    rep(i,m) cin>>t[i];
    
    auto dp=make_vec<ll>(n+10,m+10);
    //dp[i][j] -> s[i],t[i]までみたときの共通部分列の個数
    dp[0][0]=1;
    rep(i,n+1) {
        rep(j,m+1) {
            if(i-1>=0) dp[i][j]+=dp[i-1][j];
            if(j-1>=0) dp[i][j]+=dp[i][j-1];
            if(i-1>=0 && j-1>=0 && s[i-1]!=t[j-1]) dp[i][j]-=dp[i-1][j-1];
            dp[i][j]=(dp[i][j]+MOD)%MOD;
        }
    }
    //rep(i,n+1) rep(j,m+1) cout<<"dp["<<i<<"]["<<j<<"]:"<<dp[i][j]<<endl;
    cout<<dp[n][m]<<endl;
}


Measured memory_bytes: 31872
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 410000;

int n,m=800;

int fa[maxn];
int findfa(const int x){return fa[x]==x?x:fa[x]=findfa(fa[x]);}

int d[maxn],v[maxn],ok[maxn];

int main()
{
    scanf("%d%*d",&n);
    for(int i=1;i<m;i++) fa[i]=i;
    for(int i=1;i<=n;i++)
    {
        int a,b,c,D,l,r; scanf("%d%d%d%d",&a,&b,&c,&D);
        l=!c?a:-c;
        r=!D?-b:D;
        l+=400,r+=400;
        d[l]++,d[r]--; v[l]=v[r]=1;
        fa[findfa(l)]=findfa(r);
    }
    for(int i=1;i<=400;i++) if(d[i]>0) return puts("NO"),0;
    for(int i=400;i<m;i++)  if(d[i]<0) return puts("NO"),0;

    for(int i=1;i<m;i++) if(d[i]) ok[findfa(i)]=1;

    for(int i=1;i<m;i++) if(i==findfa(i)&&v[i]&&!ok[i]) 
        return puts("NO"),0;
    puts("YES");

    return 0;
}

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

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

#define vint(v, n) vector<int> v(n); REP(i,n) cin >> v[i];

int main(void){

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

  int A, B, C;
  cin >> A >> B >> C;

  REPS(i, 1, B+1){
    if(i*A%B == C){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include <stdio.h>
#include<unordered_map>
#define Amr_Abdelazim ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define vll vector<ll>
#define vvll vector<vector<ll> >
#define vpll vector<pair<ll,ll> >
#define P complex<ld>
#define X real()
#define Y imag()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define rep(i,n)   for(int i=0;i<n;i++)
#define repp(i,s,n)   for(int i=s;i<=n;i++)
#define print(v) {for(auto i:v)cout<<i<<" ";cout<<"\n";}
#define mkp make_pair
#define clr(ar,v) memset(ar,v,sizeof(ar));
#define TC ll amr_abdelazim;cin>>amr_abdelazim;while(amr_abdelazim--)
#define popcnt(x) __builtin_popcount(x)
#define EPS 1e-9
#define INF 1000000000000000009
using namespace std;
//freopen("output.txt", "w", stdout);
//freopen("input.txt", "r", stdin);
const int mod = 1000000007;
const int N = 2 * 100000 + 9;
const double pi = acos(-1);
class cmp{
public:
	bool operator() (ll &A, ll &B){
		return A > B;
	}
};
bool by_sec(const pll &a, const pll &b){
	if ((abs(a.first) == abs(b.first)))
		return (abs(a.second) < abs(b.second));
	return (abs(a.first) < abs(b.first));
}
bool byth(const tuple<ll, ll, ld>& a, const tuple<ll, ll, ld>& b){
	return (get<2>(a) < get<2>(b));
}
ld dist(P a, P b){
	return (ld)abs(a - b);
}
ll fact[1000009], inv[1000009];
ll fp(ll a, ll b){
	if (b == 0)
		return 1;
	ll ans = fp(a, b / 2);
	ans = (ans * ans) % mod;
	if (b % 2 != 0)
		ans = (ans * (a % mod)) % mod;
	return ans;
}
void FacInv(ll n){
	fact[0] = inv[0] = 1;
	for (ll i = 1; i <= n; i++)
	{
		fact[i] = ((i%mod) * fact[i - 1] % mod) % mod;
		inv[i] = fp(fact[i], mod - 2);
	}
}
ll ncr(ll n, ll r){
	return (((fact[n] * inv[r]) % mod) * inv[n - r]) % mod;
}
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a%b);
}
ll max(ll a, ll b){
	if (a >= b)return a;
	else return b;
}
ll min(ll a, ll b){
	if (a <= b)return a;
	else return b;
}



int main()
{
	Amr_Abdelazim

		ll n,ans=INF,k;
	cin >> n>>k;
	vll a(n);
	rep(i, n)cin >> a[i];
	sort(all(a));
	for (int i = 0; i+k-1 < n;i++){
		ans = min(ans, a[i + k-1] - a[i]);
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3976
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
	char s[1024];
	
	while (scanf("%s", s) && s[0] != '#'){
		int p[3], q[3] = {0, 0, 0};
		int ctr = 0;
		
		for (int i = 0; s[i]; i++){
			if (ctr == 3){
				if (!((p[0] == p[1] && q[0] != q[1]) ||
					  (p[0] == p[2] && q[0] != q[2]) ||
					  (p[1] == p[2] && q[1] != q[2]))){
					  	printf("yes\n");
						goto end;
					}
				memset(p, 0, sizeof(p));
				memset(q, 0, sizeof(q));
				ctr = 0;
			}
			if (s[i] == '(' || s[i] == ')' || s[i] == '&' || s[i] == '|') continue;
			if (s[i] == '~') q[ctr] = 1;
			else p[ctr++] = s[i];
		}
		printf("no\n");
		end:;
	}
	
	return (0);
}

Measured memory_bytes: 948
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 #define int long long

#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second



using namespace __gnu_pbds;
using namespace std;
const int mod=1e9+7;
 // const int mod=998244353;
 // const int mod=1e9+9;
const int INF=4e18+10;
// const int INF=1e9+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i;

template<typename T1,typename T2>
void set_min(T1& a, T2 b)
{
    a=min(a, (T1)b);
}


int multiply(int a, int b, int in_mod){return (a*b)%in_mod;}
int mult_identity(int a){return 1;}


auto power(auto a, int b, int in_mod)
{
    auto prod=mult_identity(a);
    auto mult=a%in_mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod=multiply(prod,mult, in_mod);

        }
        mult=multiply(mult, mult,in_mod);
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod-2,in_mod);
}


void solve()
{
    int n;
    cin>>n;
    int rn = 1<<n;
    readv(a,rn);

    vector<vector<int> > dp(rn, vector<int>());
    for(int i=0;i<1<<n;i++)
    {
        dp[i].pb(a[i]);
    }
    for(int i=0;i<n;i++)
    {
        for(int mask=0;mask<1<<n;mask++)
        {
            if(mask&(1<<i))
            {
                for(auto j:dp[mask^(1<<i)])
                    dp[mask].pb(j);
                sort(all(dp[mask]));
                //take the two largest
                reverse(all(dp[mask]));
                dp[mask].resize(min((int)dp[mask].size(),(int)2));
            }


        }
    }



    //prefix sum and a bit more mess then done


    vector<int> ans(rn+1);
    for(int i=0;i<rn;i++)
    {
        ans[i+1]=max(ans[i], accumulate(all(dp[i]), (int)0));
        if(i!=0)
        cout<<ans[i+1]<<" ";
    }



}
signed main()

{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    auto clk=clock();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------

    int t=1;
    // cin>>t;
    for(int test=1;test<=t;test++)
    {
        // cout<<"Case #"<<test<<": ";
        // cout<<endl;
        solve();
        // cout<<endl;

    }

    // -------------------------------------Code ends here------------------------------------------------------------------


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    return 0;
}


Measured memory_bytes: 26112
def main():
    n = int(input())
    s = sorted(int(input()) for _ in range(n))
    sum_s = sum(s)
    if sum_s % 10 != 0:
        print(sum_s)
        return
    for i in s:
        if i % 10 != 0:
            print(sum_s - i)
            return


    print(0)


main()

Measured memory_bytes: 3060