akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn=2e5+100;
int n, A[maxn];
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin>>n;
    for(int i=0; i<n; i++)cin>>A[i];
    if(A[0]!=0)return cout<<"-1\n", 0;
    for(int i=0; i<n-1; i++)
        if(A[i+1]-A[i]>1)
            return cout<<"-1\n", 0;
    ll ans=0;
    for(int i=n-1; i>=0; i--)
        if(A[i+1]<A[i]||A[i+1]==A[i])
            ans+=A[i];
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 1024
il1 = [int(k) for k in input().split()]
N = il1[0]
M = il1[1]
answered = ['WA']
answered = answered * (N+1)
result = [0, 0]
was = [0]
was = was * (N+1)

for i in range(M):
    il = input().split()
    p = int(il[0])
    s = il[1]
    if (answered[p] == 'AC'):
        pass
    else:
        if (s == 'AC'):
            result[0] = result[0]+1
            answered[p] = s
            result[1] = result[1]+was[p]
        else:
            was[p] = was[p] + 1

print(str(result[0])+" "+str(result[1]))


Measured memory_bytes: 10100
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

class BPalace {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll n,t,a;
	    in>>n>>t>>a;
	    vector<double> h(n);
	    rep(i,n) {
            double tmp;
	        in>>tmp;

	        h.at(i)=t-tmp*0.006;
	    }
	    pair<double ,int > ans;
	    ans.first=pow(10,5);
	    rep(i,n){
	        if(abs(ans.first-a)>abs(h.at(i)-a)){
	            ans.first=h.at(i);
	            ans.second=i+1;
	        }
	    }
	    out<<ans.second<<endl;

	}
};


int main() {
	BPalace solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
k()=readline()|>chomp
s()=[parse(Int,x)for x=k()|>split]
n,q=s()
t=k()
a=zeros(Int,n)
c=0
for j=2:n
a[j]=c+=t[j-1:j]=="AC"
end
for i=1:q
l,r=s()
println(a[r]-a[l])
end

Measured memory_bytes: 154888
cnt = int(input())
dict = {}

for i in range(cnt):
    vote = input()
    if vote in dict:
        dict[vote] += 1
    else:
        dict[vote] = 1
        
max_vote = max(dict.values())
a = filter(lambda x: x[1] == max_vote, dict.items())
b = map(lambda x: x[0], a)
lst = list(b)
lst.sort()
for word in lst:
    print(word)

Measured memory_bytes: 32096
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	    // write your code here
        Scanner scanner = new Scanner(System.in);

        int[] list = new int[100001];

        int n = scanner.nextInt();

        for (int i = 0; i < n; i++) {
            list[scanner.nextInt()]++;
        }

        int ans = 0;

        for (int i = 0; i <= 100000; i++) {
            int value = list[i];
            if (i > 0) {
                value += list[i - 1];
            }
            if (i < 100000) {
                value += list[i + 1];
            }

            ans = Math.max(ans, value);
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 50668
#include <bits/stdc++.h>
using namespace std;
int mid(int a,int b,int c){
  return a+b+c-max(max(a,b),c)-min(min(a,b),c);
}

int main(){
  int N;
  cin >> N;
 vector<int> D(N);
  for(int i = 0;i < N;i++){
    cin >> D.at(i);
  }
  sort(D.begin(),D.end());
      cout << D.at(N / 2) - D.at(N / 2 - 1) << endl;
}


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

int main()
{
    int n;
    string s;
    cin>>n>>s;
    int ans = 0;
    for(int i=0;i<s.size();++i)
    {
        if(s.substr(i,3) == "ABC")ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		if( A<=8 && B<=8) {
			System.out.println("Yay!");
		}else {
			System.out.println(":(");
		}
	}
}

Measured memory_bytes: 23764
N, Ma, Mb = map(int, input().split())

INF = 10 ** 8

lst = [[INF] * 401 for i in range(401)]
lst[0][0] = 0

for _ in range(N):
    a, b, c = map(int, input().split())
    for i in range(400, a - 1, -1):
        for j in range(400, b - 1, -1):
            if lst[i- a][j - b] == INF:
                pass
            else:
                lst[i][j] = min(lst[i][j], lst[i - a][j - b] + c)

ans = INF
n = 400 // max(Ma, Mb)
for i in range(1, n + 1):
    ans = min(ans, lst[Ma * i][Mb * i])

if ans == INF:
    print (-1)
else:
    print (ans)

# for i in range(7):
#     print (lst[i][:7])

Measured memory_bytes: 4852
#include <stdio.h>

int main(int argc, char const *argv[]) {
	char str[10000] = {0};
	int w;

	fgets(str, 1001, stdin);
	// sscanf(str, "%d\n", &n, &m);
	scanf("%d\n", &w);

	int i;
	for (i = 0; str[i] != 0;i+=w) {
		printf("%c", str[i]);
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 128
/*input
3 -1
*/
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

signed main() {
	IOS;
	int n,l;
	cin>>n>>l;
	int a[n+1];
	int sum = 0 ; 
	vector<pii> v;
	for(int i=1;i<=n;i++){
		a[i] = l + i - 1 ; 
		sum += a[i];
		v.pb({abs(a[i]),i});
	}
	sort(v.begin(), v.end());

	cout << sum - a[v.front().s] << endl ; 
return 0;
}


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

int n, ans;
string s;

int main() {
	cin >> n >> s;
	for (int i = 0; i + 2 < n; i++) {
		if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ans++;
	}
	cout << ans;
	return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  
  if (M == 0) cout << N*(N-1)/2 << endl;
  else if (N == 0) cout << M*(M-1)/2 << endl;
  else cout << N*(N-1)/2 + M*(M-1)/2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;


int main() {
    ll n; cin >> n;
    vl a(n);
    rep(i,n) cin >> a[i];
    vl dp(n+1,0);
    dp[0] = 1;
    vl table(200005,-1);
    rep(i,n){
        dp[i+1] = dp[i];
        if(table[a[i]] != -1){
            if(a[i-1]==a[i]) continue;
            dp[i+1] += dp[table[a[i]]+1];
            dp[i+1] %= mod;
        }
        table[a[i]] = i;
    }
    cout << dp[n] << endl;
}

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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
typedef pair<ll, ll>   pairl;
typedef vector<ll>     vl;
typedef vector<ll>     vll;
typedef vector<vector<ll> > vvl;
const   int            infi = numeric_limits<int>::max();
const   ll             infl = numeric_limits<ll>::max();
const   double         eps = 0;
const   int            ms  = 0;



int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);
    int a;
    cin >> a;
    for(int i = 1; i <=9; i++){
        for(int j = 1; j <= 9; j++){
            if(i*j == a){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;


int32_t main() {

    fast
    int n;
    cin >> n;

    vector<int>x(n);
    vector<int>y(n);
    int a, b, c, d;
    a = c = INT_MIN;
    b = d = INT_MAX;
    for(int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        a = max(a, x[i] + y[i]);
        b = min(b, x[i] + y[i]);
        c = max(c, x[i] - y[i]);
        d = min(d, x[i] - y[i]);
    }
    vector<pair<int, int>>as, bs, cs, ds;
    for(int i = 0; i < n; i++) {
        if(x[i] + y[i] == a && as.empty()) {
            as.push_back({x[i], y[i]});
        }
        if(x[i] + y[i] == b && bs.empty()) {
            bs.push_back({x[i], y[i]});
        }
        if(x[i] - y[i] == c && cs.empty()) {
            cs.push_back({x[i], y[i]});
        }
        if(x[i] - y[i] == d && ds.empty()) {
            ds.push_back({x[i], y[i]});
        }
    }
    int ans = INT_MIN;
    for(auto &i : as) {
        for(auto &j : bs) {
            ans = max(ans, abs(i.first - j.first) + abs(i.second - j.second));
        }
    }
    for(auto &i : cs) {
        for(auto &j : ds) {
            ans = max(ans, abs(i.first - j.first) + abs(i.second - j.second));
        }
    }
    cout << ans;




    return 0;
}



Measured memory_bytes: 6372
#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#include<string>
#include<cctype>
#include<queue>
#define ii pair<int,int>
#include <sstream>
#define lli long long int
#define pairs pair<int,int>
#define mod 1000000007
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
ll pows(ll a,ll n,ll m)
{
	ll res=1;
	while(n)
	{
	if(n%2!=0)
	{
		res=(res*a)%m;
		n--;
		}
		else
		{
			a=(a*a)%m;
			n=n/2;
			}	
	}
	return res%m;
}
ll  gcd(ll a,ll b)
{
	if(b==0)
	return a;
	else 
	return gcd(b,a%b);
}
bool isprime(ll n)
{
	if(n==1)
	{
		return false;
	}
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
bool istrue(string s)
{
	int i=0;
	int j=s.size()-1;
	while(i<j)
	{
	if(s[i]==s[j])
	{
		i++;
		j--;
		}
		else
		{
			return false;
			}	
	}
	return true;
}
int main()
{
   ios::sync_with_stdio(false);
	 cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    if(isprime(n)==true)
    {
    	cout<<1<<endl;
    	return 0;
	}
	if(n==1)
	{
		cout<<0<<endl;
		return 0;
	}
vector<ll>vi;
for(ll i=2;i*i<=n;i++)
{
	if(n%i==0)
	{
		int cnt=0;
		while(n%i==0)
		{
			cnt++;
			n=n/i;
		}
		vi.pb(cnt);
	}
}
if(n>1)
{
	vi.pb(1);
}
int ans=0;
for(ll i=0;i<vi.size();i++)
{
	int p=vi[i];
	for(ll j=1;j<=50;j++)
	{
		if(p<j)
		{
			break;
		}
		else
		{
			ans++;
			p=p-j;
		}
	}
}
cout<<ans<<endl;
}
 


Measured memory_bytes: 3624
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const long long INF =  999999999;
ll N,W,w[110],v[110],dp[101][101000];

int main(){
  cin >> N>>W;
  ll V=0;
  REP(i,N){
    scanf("%lld %lld",&w[i],&v[i]);
    V+=v[i];
  }
  REP(j,V+1){
      dp[0][j]=INF;
  }
  dp[0][0]=0;
  ll ans=0;
  FOR(i,0,N){
     FOR(j,0,V+1){
     if(j>=v[i]){
       dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i]);
     }
     else {
       dp[i+1][j]=dp[i][j];
     }
   }
  }
  REP(i,V+1)if(dp[N][i]<=W)ans=i;
  cout <<ans<<endl;
}


Measured memory_bytes: 79872
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>
#include <stack>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) {
    cin >> a[i];
  }
  for (ll i = k; i < n; ++i) {
    if (a[i] > a[i-k]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}


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

using Graph = vector<vector<int>>;

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

    vector<int> h(n);
    for (size_t i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    
    Graph G(n);

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

         G[a[i] - 1].push_back(b[i] - 1);
         G[b[i] - 1].push_back(a[i] - 1);
    }

    int j,ans = 0;
    for (size_t i = 0; i < n; i++)
    {
        //cout << G[i].size() << endl;
        for (j = 0; j < G[i].size(); j++)
        {
            if(h[i] <= h[G[i][j]])break;
        }
        if(j == G[i].size())ans++;
    }

    cout << ans << endl;
}


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

int main()
{
    ll t;
    cin>>t;
    ll ans=t,now=1,i=1,x=1;
    while(now*2<=t)
    {
        ll tt=t,res=x;
        tt-=now;
        for(ll j=3*i;j>=1;j/=3)
        {
            res+=tt/j;
            tt%=j;
        }
        ans=min(ans,res);
        i*=3,x+=2,now+=2*i;
    }
    cout<<ans<<"\n";
    return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main()
{
    SPEED;
    int n;
    cin>>n;
    int a[n],dp[n+1]={0};
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 5224
using System;
using System.Collections.Generic;
class Program{
	static void Main(){
		int n=int.Parse(Console.ReadLine());
		var hs=new HashSet<string>();
		char c;
		string ans="Yes";
		string s=Console.ReadLine();
		hs.Add(s);
		c=s[s.Length-1];
		for(int i=1;i<n;i++){
			s=Console.ReadLine();
			if((!hs.Contains(s))&&c==s[0]){
				hs.Add(s);
				c=s[s.Length-1];
			}
			else{ans="No";}
		}
		Console.WriteLine("{0}",ans);
	}
}

Measured memory_bytes: 11232
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define MAX 100
#define WHITE 0
#define BLACK 1
#define NIL -1

int color[MAX], d[MAX], M[MAX][MAX];

int main() {
  int n, i, j, k, x, u, v, c, min;

  scanf("%d", &n);

  for(i = 0; i < n; i++)
    for(j = 0; j < n; j++)
      M[i][j] = NIL;

  for(i = 0; i < n; i++){
    scanf("%d %d", &x, &k);

    for(j = 0; j < k; j++){
      scanf("%d %d", &v, &c);
      M[x][v] = c;
    }
  }

  for(i = 0; i < n; i++){
    d[i] = INT_MAX;
    color[i] = WHITE;
  }

  d[0] = 0;

  while(1){
    min = INT_MAX;

    for(i = 0; i < n; i++){
      if(d[i] < min && color[i] == WHITE){
        min = d[i];
        u = i;
      }
    }

    if(min == INT_MAX) break;
    color[u] = BLACK;

    for(v = 0; v < n; v++){
      if(M[u][v] == NIL) continue;
      if(d[v] > M[u][v] + d[u]) d[v] = M[u][v] + d[u];
    }
  }

  for(i = 0; i < n; i++) printf("%d %d\n", i, d[i]);

  return 0;
}

Measured memory_bytes: 640
data = {
        'S': [int(x) for x in range(1,14)],
        'H': [int(x) for x in range(1,14)],
        'C': [int(x) for x in range(1,14)],
        'D': [int(x) for x in range(1,14)],
        }

count = int(input())

for c in range(count):
    (s, r) = input().split()
    r = int(r)
    del data[s][data[s].index(r)]

for i in ('S', 'H', 'C', 'D'):
    for v in data[i]:
        print(i, v)

Measured memory_bytes: 6724
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
int cnt[7];
int main(){
    int n;
    long a[101];
    int i,j,max=0,tmp;
    cin>>n;
    for(i=0;i<n;i++) cin>>a[i];
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            tmp=abs(a[i]-a[j]);
            if(max<tmp) max=tmp;
        }
    }
    cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class E
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int H = GetInt();
		int W = GetInt();
		int[,] A = new int[H, W];
		int[,] B = new int[H, W];
		for(int i = 0; i < H; i++)
			for(int j = 0; j < W; j++)
				A[i, j] = GetInt();

		for(int i = 0; i < H; i++)
			for(int j = 0; j < W; j++)
				B[i, j] = GetInt();

		int[,] C = new int[H, W];
		for(int i = 0; i < H; i++)
			for(int j = 0; j < W; j++)
				C[i, j] = Abs(A[i, j] - B[i, j]);

		bool[,,] dp = new bool[2, W, 6401];
		dp[0, 0, C[0, 0]] = true;
		for(int i = 0; i < H; i++)
		{
			int c = i % 2;
			int n = c ^ 1;
			for(int j = 0; j < W; j++)
				for(int k = 0; k <= 6400; k++)
					dp[n, j, k] = false;

			for(int j = 0; j < W; j++)
			{
				for(int k = 0; k <= 6400; k++)
				{
					if(!dp[c, j, k])
						continue;

					if(j + 1 < W)
					{
						int m = Abs(k - C[i, j + 1]);
						if(m <= 6400)
							dp[c, j + 1, m] = true;

						int p = k + C[i, j + 1];
						if(p <= 6400)
							dp[c, j + 1, p] = true;
					}

					if(i + 1 < H)
					{
						int m = Abs(k - C[i + 1, j]);
						if(m >= 0)
							dp[n, j, m] = true;

						int p = k + C[i + 1, j];
						if(p <= 6400)
							dp[n, j, p] = true;
					}
				}
			}
		}

		for(int i = 0; i <= 6400; i++)
		{
			if(dp[(H - 1) % 2, W - 1, i])
			{
				WriteLine(i);
				return;
			}
		}
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 14048
#! python.exe
dic = {}
for idx, c in enumerate("ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"):
    dic[c] = str(format(idx,'b').zfill(5))

decode = {"101"      : " ", "0101"     : "C", "0110"     : "K", "00110"    : "S",
          "000000"   : "'", "0001"     : "D", "00100"    : "L", "00111"    : "T",
          "000011"   : ",", "110"      : "E", "10011001" : "M", "10011100" : "U",
          "10010001" : "-", "01001"    : "F", "10011110" : "N", "10011101" : "V",
          "010001"   : ".", "10011011" : "G", "00101"    : "O", "000010"   : "W",
          "000001"   : "?", "010000"   : "H", "111"      : "P", "10010010" : "X",
          "100101"   : "A", "0111"     : "I", "10011111" : "Q", "10010011" : "Y",
          "10011010" : "B", "10011000" : "J", "1000"     : "R", "10010000" : "Z"}
#print(dic)
while True:
    try:
        line = input()
    except:
        break
    s = ""
    for c in line:
        s += dic[c]
    ans = ""
    tmp = ""
    for c in s:
        tmp += c
        if tmp in decode:
            ans += decode[tmp]
            tmp = ''
#        print(ans, s)
    print(ans)

Measured memory_bytes: 7492
n = int(input())
A = list(map(int, input().split()))
S = [0]*(n+1)
for i in range(n):
    S[i+1] = S[i]+A[i]
INF = 10**18
ans = INF
for R in range(1, n):
    ans = min(ans, abs((S[R]-S[0])-(S[n]-S[R])))
print(ans)


Measured memory_bytes: 24820
h, w, d = map(int, input().split())
arr = [0] * (h * w + 1)

a = [list(map(int, input().split())) for _ in range(h)]

for i in range(h):
    for j in range(w):
        s = a[i][j]
        arr[s] = (i, j)

q = int(input())
lr = [list(map(int, input().split())) for _ in range(q)]

cnt = h * w
result = [[0] for _ in range(d)]
for i in range(d):
    l = i
    score = 0
    while l + d <= cnt:
        if l == 0:
            result[i].append(score)
            l += d
            continue
        (ux, uy) = arr[l]
        (vx, vy) = arr[l + d]
        score += (abs(vx - ux) + abs(vy - uy))
        result[i].append(score)
        l += d


for l, r in lr:
    ans = result[l % d]
    print(ans[r // d] - ans[l // d])

Measured memory_bytes: 45624
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1)/ (y))
#define MOD 1000000007ULL

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

    int N, K;
    cin >> N >> K;

    cout << ((K == 1) ? 0 : N - K) << "\n";

    return 0;
}



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

namespace Program
{
    public class ABC076D
    {
        static class Console_
        {
            private static Queue<string> param = new Queue<string>();
            public static int NextInt() => int.Parse(NextString());
            public static long NextLong() => long.Parse(NextString());
            public static string NextString()
            {
                if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item);
                return param.Dequeue();
            }
        }
        static public void Main(string[] args)
        {
            var N = Console_.NextInt();

            var vary = new int[N];
            var tary = new int[N];

            for (int i = 0; i < N; ++i)
            {
                tary[i] = Console_.NextInt();
            }
            for (int i = 0; i < N; ++i)
            {
                vary[i] = Console_.NextInt();
            }

            var l = new int[N + 2];
            var r = new int[N + 2];
            var v = new int[N + 2];
            var totalTime = 0;
            for (int i = 1; i <= N; ++i)
            {
                l[i] = totalTime;
                r[i] = totalTime + tary[i - 1];
                v[i] = vary[i - 1];
                totalTime += tary[i - 1];
            }
            l[N + 1] = r[N + 1] = totalTime;

            var beforevt = 0.0;
            var sum = 0.0;
            for (int i = 1; i <= totalTime * 2; ++i)
            {
                var t = i / 2.0;
                var minv = 1000000000.0;
                for (int j = 0; j < N + 2; ++j)
                {
                    var vt = 0.0;
                    if (t < l[j])
                    {
                        vt = v[j] + l[j] - t;
                    }
                    else if (t > r[j])
                    {
                        vt = v[j] + t - r[j];
                    }
                    else
                    {
                        vt = v[j];
                    }
                    if (minv > vt) minv = vt;
                }
                sum += 0.25 * (beforevt + minv);
                beforevt = minv;
            }
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cmath>

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

void ABC099D()
{
	int N, C;
	cin >> N >> C;
	vector<vector<int> > D(C, vector<int>(C));
	for (int i = 0; i < C; ++i)
	{
		for (int j = 0; j < C; ++j)
		{
			cin >> D[i][j];
		}
	}

	vector<int>c[3];
	for (int i = 0; i < N; ++i)
	{
		int im3 = i % 3;
		for (int j = 0; j < N; ++j)
		{
			int x;
			cin >> x;
			--x;

			++im3;
			if (im3 > 2)
				im3 %= 3;
			c[im3].push_back(x);
		}
	}

	vector<vector<ll> >cost(3, vector<ll>(C));
	for (int i = 0; i < 3; ++i)
	{
		for (int j = 0; j < C; ++j)
		{
			ll sum = 0;
			for (int k = 0; k < static_cast<int>(c[i].size()); ++k)
			{
				sum += D[c[i][k]][j];
			}
			cost[i][j] = sum;
		}
	}

	ll minCost = 100000000000;
	for (int i = 0; i < C; ++i)
	{
		for (int j = 0; j < C; ++j)
		{
			for (int k = 0; k < C; ++k)
			{
				if (i != j && i != k && j != k)
				{
					minCost = min(minCost, cost[0][i] + cost[1][j] + cost[2][k]);
				}
			}
		}
	}
	cout << minCost << endl;
}

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

Measured memory_bytes: 1524
/*input
27
18 -28 18 28 -45 90 -45 23 -53 60 28 -74 -71 35 -26 -62 49 -77 57 24 -70 -93 69 -99 59 57 -49
*/
#include "bits/stdc++.h"
#define ll long long
using namespace std;
const int MAXN = 2e5+9;
ll a[MAXN],dp[MAXN][2];
int main()
{
	ll n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		if(i%2==0)
		{
			dp[i][0]=a[i];
			if(i-2>=0)
			{
				dp[i][0]+=dp[i-2][0];
				dp[i][1]=a[i]+dp[i-2][1];
				dp[i][1]=max(dp[i][1],dp[i-1][0]);
			}
		}
		else
		{
			dp[i][0]=dp[i-1][0];
			ll res=a[i];
			if(i-2>=0)
			{
				res+=dp[i-2][0];
			}
			dp[i][0]=max(dp[i][0],res);
		}
	}
	ll fans;
	if(n%2)
	{
		fans=dp[n-1][1];
	}
	else
	{
		fans=dp[n-1][0];
	}
	cout<<fans<<endl;
	return 0;

}

Measured memory_bytes: 8264
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
typedef long long int ll;
using namespace std;
#define REP(i,n) for(int i=0;i<signed(n);i++)
const ll MOD = 1000000007;
const ll INF = 9e9;
ll N,M,ans=INF;
ll A[300010],S[301000];

int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,N){
        cin>>A[i];
        S[i]+=A[i];
        S[i+1]=S[i];
    }
    //a:右半分の区切り i:真ん中 b:左半分
    //s:右の和 t:左の和
    ll a=0,b=2,s,t;
    REP(i,N-2){
        if(i==b)b++;
        s=(S[i]-S[a])-S[a];
        t=(S[N-1]-S[b])-(S[b]-S[i]);
        bool f=true;
        if(i==0)continue;
        while(f){
            f=false;
            if(a+1==i)continue;
            if(abs(s)>abs(s-A[a+1]*2)){
                s-=A[a+1]*2;
                a++;f=true;
            }
        }
        f=true;
        while(f){
            f=false;
            if(b+1==N-1||b==N-1)continue;
            if(abs(t)>abs(t-A[b+1]*2)){
                t-=A[b+1]*2;
                b++;f=true;
            }
        }
        ans=min( ans,( max({S[a],S[i]-S[a],S[b]-S[i],S[N-1]-S[b]})
        -min({S[a],S[i]-S[a],S[b]-S[i],S[N-1]-S[b]}) ) );
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;
    int ans = 0;
    while (1) {
        if (ans * (A-1) + 1 >= B) {
            cout << ans << endl;
            return 0;
        }
        ans++;
    }
    return 0;
}


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

int cal(int a,int b,string str){
    
    if(str=="+") return a+b;
    if(str=="-") return a-b;
    if(str=="*") return a*b;
    if(str=="/") return a/b;
    
}

int main(){
    int a,b;
    string op;
    
    while(cin >> a >> op >> b){
        if(op=="?") break;
        int ans = cal(a,b,op);
        cout << ans << endl;
    }
    return 0;
}


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

int main() {
    string S;
    cin >> S;
    int cnt=0;
    for(int i=1;i<S.length();i++){
    	if(S[i]!=S[i-1]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

class Menu{
  public:
    int time;
  Menu(int t){
    time = t;
  }
  bool operator<(const Menu &another) const
  {
    return time%10 < another.time%10;
  };
};

int main(){
  vector<Menu> menuList;
  int tempT,flag = 0,sum = 0;
  for (int ite=0;ite<5;ite++){
    cin >> tempT;
    menuList.push_back(Menu(tempT));
  }
  sort(menuList.begin(),menuList.end());
  for (int ite=0;ite<5;ite++){
    if(menuList[ite].time%10 == 0){
      sum += menuList[ite].time;
    }else{
      if(flag == 0){
        sum += menuList[ite].time;
        flag++;

        continue;
      }
      menuList[ite].time = menuList[ite].time + 10 - menuList[ite].time%10;
      sum += menuList[ite].time;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    
    int x;
    
    cin >> x;
    
    int count = 0;
    
    while (x > 0) {
        count += x%10;
        x /= 10;
    }
    
    cout << count;
    
    return 0;
}

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

int main(){
    int n;
    cin>>n;
    int d,x;
    cin>>d>>x;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    ll sum=0;
    for(int i=0;i<n;i++){
        sum+=1;
        int mul=1;
        while(mul*a[i]+1<=d){
            sum++;
            mul++;
            //cout<<sum<<" ";
        }
        //cout<<endl;
        //cout<<sum<<" ";
    }
    cout<<sum+x;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char a ,b,c;
  cin  >> a >> b ;
  if ( a == 'H'){
    c = b;
  }
  if ( a == 'D'){
    if ( b == 'H'){
    c = 'D';
    }else c='H';
  }
  cout << c << endl; 
}

Measured memory_bytes: 3640
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const ll INF = 1e17;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main()
{
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> A(N), B(M);
  vector<ll> ac(N + 1), bc(M + 1);
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &A[i]);
    ac[i + 1] = ac[i] + A[i];
  }
  for (int i = 0; i < M; i++)
  {
    scanf("%lld", &B[i]);
    bc[i + 1] = bc[i] + B[i];
  }
  ll ans = 0, cnt = 0;
  for (int i = 0; i <= N; ++i)
  {
    if (ac[i] <= K)
      cnt = i;
  }
  ll itr = cnt;
  ans = cnt;
  for (int i = 1; i <= M; ++i)
  {
    while (itr >= 0 && ac[itr] + bc[i] > K)
    {
      cnt--;
      itr--;
    }
    if (itr <= 0)
      break;
    if (ac[itr] + bc[i] <= K)
    {
      cnt++;
    }
    ans = max(ans, cnt);
  }
  cnt = 0;
  for (int i = 0; i <= M; ++i)
  {
    if (bc[i] <= K)
      cnt = i;
  }
  itr = cnt;
  ans = max(ans, cnt);
  for (int i = 1; i <= N; ++i)
  {
    while (itr >= 0 && bc[itr] + ac[i] > K)
    {
      cnt--;
      itr--;
    }
    if (itr <= 0)
      break;
    if (bc[itr] + ac[i] <= K)
    {
      cnt++;
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 9572
import bisect
import itertools

A,B,Q = map(int,input().split())

# 簡略化のため常に左右に存在するようにしておく
INF = 10 ** 15
S = [-INF] + [int(input()) for _ in range(A)] + [INF]
T = [-INF] + [int(input()) for _ in range(B)] + [INF]
X = [int(input()) for _ in range(Q)]

def solve(x):
  # xの位置
  i = bisect.bisect_left(S, x)
  j = bisect.bisect_left(T, x)
  result = INF
  # どの2つを目指すのか
  for s,t in itertools.product(S[i-1:i+1], T[j-1:j+1]):
    d = min(abs(s-x),abs(t-x)) + abs(t-s)
    result = min(result,d)
  return result

for x in X:
  answer = solve(x)
  print(answer)


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

ans = [0]*n
ans[n-1] = b[-1]
for j in reversed(range(n-1)):
  b_ = b[j]
  if ans[j+1] > b_:
    ans[j+1] = b_
  ans[j] = b_
#print(ans)  
print(sum(ans))
  
    
  


Measured memory_bytes: 38256
n, m = map(int, input().split())
x_list = sorted(list(map(int, input().split())))
if n >= m:
    print(0)
    exit()
l_list = []
for i in range(1, m):
    l_list.append(x_list[i] - x_list[i - 1])
l_list = sorted(l_list)
print(x_list[-1] - x_list[0] - sum(l_list[::-1][:n - 1]))

Measured memory_bytes: 13960
#include "bits/stdc++.h"
#define int long long
#define mii map<int,int>
#define inf 1000000007 //10^9+7
#define for(i,n) for(int i=0;i<n;i++)
#define sort(vec) sort(vec.begin(),vec.end());
#define rever(vec) reverse(vec.begin(),vec.end());
#define unsort(vec) sort(vec); rever(vec);
#define in(a,b,vec,n) a n; cin>>n; vector<b>vec(n);
#define gcd __gcd
using namespace std;

signed main() {
  int n,a,b;
  cin>>n>>a>>b;
  int c=0;
  int d=0;
  int e=0;
  vector<int>vec(n);
  for(i,n) cin>>vec.at(i);
  sort(vec);
  for(i,n) {
    if(vec.at(i)<=a) {
      c++;
    }
    else if(vec.at(i)<=b) {
      d++;
    }
    else {
      e++;
    }
  }
  cout<<min(min(c,d),e)<<endl;
}

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

const int N=5010,inf=1e9;
int fa[N],a[N],b[N],f[N],n;
vector<int>g[N];

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=2;i<=n;++i)cin>>fa[i],g[fa[i]].push_back(i);
	for(int i=1;i<=n;++i)cin>>a[i];
	for(int i=n;i;--i){
		memset(f,0,sizeof f);
		for(int j:g[i]){
			for(int k=a[i];k>=0;--k){
				int tmp=inf;
				if(k>=a[j])tmp=min(tmp,f[k-a[j]]+b[j]);
				if(k>=b[j])tmp=min(tmp,f[k-b[j]]+a[j]);
				f[k]=tmp;
			}
		}
		if(f[a[i]]>=inf){
			cout<<"IMPOSSIBLE\n";
			return 0;
		}
		b[i]=f[a[i]];
	}
	cout<<"POSSIBLE\n";
	return 0;
}


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

using namespace std;

#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define f first
#define se second
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))

typedef long long ll;
#define MOD 1000000007

void solve()
{
    ll ans=1;
    int n;
    cin>>n;
    for(int i=2;i<=n;++i){
        ans=(ans*i)%MOD;
    }
    cout<<ans;
}


int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 256
let r()=List.map int_of_string(Str.split(Str.regexp_string" ")(read_line()))open Array;;match r()with|[n;m;l]->(let($)s t=let a=make_matrix s t 0in for i=0to s-1do let x=of_list(r())in for j=0to t-1do a.(i).(j)<-x.(j)done done;a in let a=n$m and b=m$l in for i=0to n-1do for j=0to l-1do let c=ref 0in for k=0to m-1do c:=!c+a.(i).(k)*b.(k).(j)done;Printf.printf(if j=0then"%d"else" %d")!c done;print_newline()done)|_->()

Measured memory_bytes: 4704
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())
alist = [A,B,C,D,E]
A_=10-A%10
B_=10-B%10
C_=10-C%10
D_=10-D%10
E_=10-E%10

mlist = [A_,B_,C_,D_,E_]
for i,m in enumerate(mlist):
    if m==10:
        mlist[i]=0
min_index = mlist.index(max(mlist))

for i in range(5):
    if i!=min_index:
        alist[i]+=mlist[i]
print(sum(alist))


Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

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

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

    int a, b; cin >> a >> b;
    
    cout << max(max(a + b, a - b), a * b) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vec = complex<double>;
double dot(vec a, vec b) { return a.real() * b.real() + a.imag() * b.imag(); }
const double EPS = 1e-9;
const double PI = acos(-1);
int main()
{
    int N; cin >> N;
    vector<vec> A(N), B;
    for (int i = 0; i < N; i++) {
        int x, y; cin >> x >> y;
        A[i] = vec(x, y);
    }
    vec b = *min_element(begin(A), end(A), [](const vec& a, const vec& b) {
        return make_pair(a.real(), a.imag()) < make_pair(b.real(), b.imag());
    });
    vec a = vec(b.real(), b.imag() - 1);
    do {
        B.push_back(b);
        double maxcos = -2;
        double maxlen = 0;
        int maxidx = -1;
        for (int i = 0; i < N; i++) {
            vec c = A[i];
            double co = dot(b - a, c - b) / abs(b - a) / abs(c - b);
            if (co > maxcos || (abs(co - maxcos) < EPS && maxlen < abs(c - b))) {
                maxcos = co;
                maxlen = abs(c - b);
                maxidx = i;
            }
        }
        a = b;
        b = A[maxidx];
    } while (b != B[0]);
    B.push_back(B[0]);
    B.push_back(B[1]);
    vector<double> ans(N);
    for (int i = 0; i < B.size()-2; i++) {
        double s = arg((B[i+1] - B[i]) * vec(0, 1));
        double t = arg((B[i+2] - B[i+1]) * vec(0, 1));
        if (s < t) s += 2 * PI;
        for (int j = 0; j < A.size(); j++) {
            if (A[j] == B[i+1]) {
                ans[j] = (s - t) / (2 * PI);
                break;
            }
        }
    }
    for (auto a : ans) cout << fixed << setprecision(16) << a << '\n';
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int A[30];
int n;
int solve(int i,int m){
    if(m == 0) return true;
    if(i == n) return false;
    int res = solve(i+1,m) || solve(i+1,m-A[i]);
    return res;
}
int main(){
    int m,q;
    cin>>n;
    for(int i=0;i<n;i++) cin>>A[i];
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>m;
        if(solve(0,m)) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}



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

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

Measured memory_bytes: 256
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

void solve() {
  int n, a, ans = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    while (a % 2 == 0) {
      ans++;
      a /= 2;
    }
  }
  
  cout << ans << endl;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <numeric>
#include <algorithm>
//#include <iomanip> : 表示桁数, ex) cout << fixed << setprecision(15) << ...
//#include <unordered_set>

#define pi 3.14159265358979323846
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using ld = long double;
using Byte = unsigned char;
using namespace std;

//string ans = "Yes";


void SetAns() {
	int n;
	string s;
	cin >> n;
	int ans[4] = { 0 ,0,0,0 };
	rep(_i, n) {
		cin >> s;
		if (s == "AC") ans[0] ++;
		if (s == "WA") ans[1] ++;
		if (s == "TLE") ans[2] ++;
		if (s == "RE") ans[3]++;
	}
	cout << "AC x " << ans[0] << endl;
	cout << "WA x " << ans[1] << endl;
	cout << "TLE x " << ans[2] << endl;
	cout << "RE x " << ans[3] << endl;
}

int main() {
	SetAns();
	//cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define debug(x) cerr << #x << ": " << x << "\n"
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;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}


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

    int r,c;
    cin>>r>>c;

    int a[101][101];

    rep(i,r)rep(j,c)cin>>a[i][j];

    for(int i=0; i<=r;i++) a[i][c]=0;
      for(int j=0;j<=c;j++) a[r][j] =0;

    rep(i,r)rep(j,c){
        a[i][c] += a[i][j];
        a[r][j] += a[i][j];
        a[r][c] += a[i][j];
    }
     for(int i=0; i<=r;i++) {
      for(int j=0;j<=c;j++){
          if(j) cout<< " ";
          cout<<a[i][j];


      }
      cout<<endl; 
     }
}


Measured memory_bytes: 3188
s = input()
L = len(s)

ans = ""

for i in range(L):
    if s[i] == '1':
        ans += "1"
    elif s[i] == '0':
        ans += "0"
    else:
        if ans == "":
            pass
        else:
            ans = ans[:-1]

print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int xdir[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
int ydir[8] = {-4, -4, -4, 0, 0, 4, 4, 4};

int func(vector<int> vec)
{
	int res = vec.size();
	
	for(int i = 0, s = vec.size(); i < s && res; i++){
		int q = i%4;
		for(int j = 0; j < 8 && res; j++){
			vector<int> v = vec;
			int p = i + xdir[j] + ydir[j];
			if((q == 3 && xdir[j] > 0) || (q == 0 && xdir[j] < 0)){
				continue;
			}
			if(0 <= p && p < s && v[i] == v[p]){
				if(j < 4){
					v.erase(v.begin()+i);
					v.erase(v.begin()+p);
				} else {
					v.erase(v.begin()+p);
					v.erase(v.begin()+i);
				}
				res = min(res, func(v));
			}
		}
	}
	
	return res;
}

int main()
{
	int n, t;
	
	while(cin>>n && n){
		while(n--){
			vector<int> vec;
			for(int i =0; i < 20; i++){
				cin >> t;
				vec.push_back(t);
			}
			
			cout << func(vec) << endl;
		}
	}
	
	return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  ll l,r;
  bool judge = true;
  ll w,h,x,y;cin>>w>>h>>x>>y;
  double a = w*h/2.0;
  cout<<a<<endl;
  if(w%2==0&&h%2==0&&w==2*x&&h==2*y)cout<<1<<endl;
  else cout<<0<<endl;

  return 0;
}

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

int main() {
    int N, ans=0;

    cin >> N;

    vector<int> A(N);
    vector<int> B(1000001, 0);

    rep(i, N) {
        cin >> A[i];
        B[A[i]]++;
    }

    rep(i, N) {
        bool ok = true;
        B[A[i]]--;
        for(int j=1; j*j<=A[i]; j++) {
            if(A[i]%j == 0) {
                if(B[j]!=0) ok = false;
                if(B[A[i]/j]!=0) ok = false; 
            }
        }
        B[A[i]]++;
        if(ok) ans++;
    }

    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 8012
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
   string S,T;
   cin>>S>>T;
   int cnt=0;
   
   rep(i,3){
       if(S[i]==T[i]){
           cnt++;
       }
   }
   cout<<cnt<<endl;
}


Measured memory_bytes: 3620