akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define debug(x) cerr<<#x<<" "<<x<<endl;
#define f(i,n) for(ll i=0; i<n; i++)
#define f1(i,n) for(ll i=1; i<=n; i++)
#define fr(i,n) for(ll i=n-1; i>=0; i--)
#define f1r(i,n) for(ll i=n; i>0; i--)
#define mst(arr,val) memset(arr,val,sizeof(arr))
#define all(x) x.begin(),x.end()

typedef long long int ll;
typedef pair<ll,ll> pii;
ll M=1e9+7;
ll M2=998244353;
void show(vector<ll> v)
{
    for(int i=0; i<v.size(); i++)
        cout<<v[i]<<" ";
    cout<<"\n";
}
void showrev(vector<ll> v)
{
    for(int i=0; i<v.size(); i++)
        cout<<v[v.size()-i-1]<<" ";
    cout<<"\n";
}
void showarr(ll arr[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<arr[i]<<" ";
    cout<<"\n";
}
void showpv(vector<pair<ll,ll> > v)
{
    f(i,v.size())
        cout<<"("<<v[i].ff<<","<<v[i].ss<<")"<<" ";
    cout<<"\n";
}
void showmap(map<ll,ll> m)
{
    for(auto i:m)
        cout<<" ("<<i.ff<<","<<i.ss<<") ";
    cout<<"\n";
}
int main()
{
    IOS
    ll T = 1,Q=1;
    //cin>>T;

    while(T--)
    {
        ll n,k;   cin>>n>>k;
        ll a[n],dp[n];
        f(i,n)
            cin>>a[i];
        dp[0] = 0;
        dp[1] = abs(a[1]-a[0]);
        for(ll i=2; i<k and i<n; i++)
        {
            ll val = 999999999;
            f(j,i)
                val = min(val,abs(a[i]-a[j])+dp[j]);
            dp[i] = val;
        }
        for(ll i=k; i<n; i++)
        {
            ll val = 9999999999;
            for(ll j=i-k; j<i; j++)
                val = min(val,abs(a[i]-a[j])+dp[j]);
            dp[i] = val;
        }
        cout<<dp[n-1];
    }
    return 0;
}


Measured memory_bytes: 1792
n = gets.to_i
nums = gets.split.map(&:to_i)

valid_nums = nums.count { |i| i.even? && i % 4 == 0 }
twos = nums.count { |i| i.even? && !(i / 2).even? }
other_nums_size = n - valid_nums - (twos > 0 ? twos - 1 : 0)

if valid_nums >= other_nums_size - 1
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 8452
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=1e9+7;
vector<ll>W,V;
int main(){

ll n,w;
cin>>n>>w;
ll dp[2][w+1];

for(ll i=0;i<=w;i++)dp[0][i]=0,dp[1][i]=0;
for(ll i=0,x,y;i<n;i++)
{
	
	cin>>x>>y;
	W.push_back(x);
	V.push_back(y);
	
}
	for(ll j=1;j<=n;j++){
for(ll i=1;i<=w;i++)
{

		
		if(i<W[j-1])dp[j%2][i]=dp[(j-1)%2][i];
	else
	{
	dp[j%2][i]=max(V[j-1]+dp[(j-1)%2][i-W[j-1]],dp[(j-1)%2][i]);
	}
	
//	cout<<dp[j%2][i]<<" ";
}
//cout<<endl<<endl;
}
cout<<max(dp[0][w],dp[1][w]);
return 0;



}

Measured memory_bytes: 1792
import sys
from collections import deque


def bfs(x1, y1, d):
    q = deque([])
    q.append((d, x1, y1))

    while q:
        d, x1, y1 = q.popleft()
        M[x1][y1] = d

        if [x1, y1] == [xg, yg]:
            print(d)
            return

        for dx, dy in ((0, 1), (1, 0), (0, -1), (-1, 0)):
            for k in range(1, K + 1):
                x2 = x1 + dx * k
                y2 = y1 + dy * k
                if x2 < 0 or x2 >= H:  # 枠外
                    break
                if y2 < 0 or y2 >= W:  # 枠外
                    break
                if m[x2][y2] == '@':  # 蓮の葉
                    break
                if M[x2][y2] < d + 1:  # より良い経路を探索済み。
                    break
                if M[x2][y2] == d + 1:  # 同等の良さの経路を探索済み。　飛び越えて次のマスを探索する。
                    continue

                q.append((d + 1, x2, y2))
                M[x2][y2] = d + 1  # ここで更新しないと無駄な探索が発生する

    print(-1)


H, W, K = map(int, sys.stdin.readline().strip().split())
xs, ys, xg, yg = map(int, sys.stdin.readline().strip().split())
xg -= 1
yg -= 1

m = []
for _ in range(H):
    m.append(list(map(str, sys.stdin.readline().strip())))

M = [[float('inf')] * W for _ in range(H)]

bfs(xs - 1, ys - 1, 0)


Measured memory_bytes: 45304
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include<cfloat>

using namespace std;

typedef pair<double, double>P;

int N;
const double INF=1000000000;
P A[1000000];

bool comp_y(P a,P b){
    return a.second<b.second;
}

double closest_pair(P *a, int n){
    if(n<=1)return INF;
    int m=n/2;
    double x=a[m].first;
    double d=min(closest_pair(a,m),closest_pair(a+m,n-m));
    inplace_merge(a,a+m,a+n,comp_y);

    vector<P>b;
    for(int i=0;i<n;i++){
        if(abs(a[i].first-x)>=d)continue;
        for(int j=0;j<b.size();j++){
            double dx = a[i].first-b[b.size()-j-1].first;
            double dy = a[i].second-b[b.size()-j-1].second;
            if(dy>=d)break;
            d=min(d,dx*dx+dy*dy);
        }
        b.push_back(a[i]);
    }
    return d;
}

int main(void){
    P in;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> in.first >> in.second;
        A[i]=in;
    }
    sort(A,A+N);
    double ans=closest_pair(A,N);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 28328
#include <bits/stdc++.h>
#define rep(i, n) for(int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;

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

  int64_t ans;
  // 2人の距離が偶数の場合
  if ((b - a) % 2 == 0) {
    ans = (b - a) / 2;

  // 2人の距離の差が奇数の場合
  } else {
    if (n - b < a - 1) {
      ans = (n - b) + ((b - a) / 2) + 1;
    } else {
      ans = (a - 1) + ((b - a) / 2) + 1;
    }
  }

  cout << ans << endl;
  return 0;
}

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

#define mod 1000000007
#define pi 2 * acos(0.0)
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rloop(i, a, b) for (int i = a; i >= b; i--)
void fun()
{
    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
}

/* DON'T LIMIT YOUR CHALLENGES, CHALLENGE YOUR LIMITS */
void solve()
{
    string s, t;
    cin >> s >> t;

    vector<vector<int>> dp(s.length() + 1, vector<int>(t.length() + 1, 0));
    for (int i = 1; i <= s.length(); i++)
    {
        for (int j = 1; j <= t.length(); j++)
        {
            if (i == 0 && j == 0)
                dp[0][0] = 0;
            else if (i == 0 && j != 0)
                dp[i][j] = 0;
            else if (i != 0 && j == 0)
                dp[i][j] = 0;
            else
            {
                if (s[i - 1] == t[j - 1])
                    dp[i][j] = max(1 + dp[i - 1][j - 1], max(dp[i][j - 1], dp[i - 1][j]));
                else
                    dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }

    int i = s.length(), j = t.length();
    string res = "";
    while (1)
    {
        if (i == 0 || j == 0)
            break;
        if (s[i - 1] == t[j - 1])
        {
            res.push_back(s[i - 1]);
            i--, j--;
        }
        else
        {
            if (dp[i - 1][j] >= dp[i][j - 1])
                i--;
            else
                j--;
        }
    }

    reverse(res.begin(), res.end());
    cout << res;
}

signed main()
{
    fun();
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 73608
S = input()
T = input()

z = len(S)-len(T)

res = []
cnt = 0
if z == 0:
  for a,b in zip(S,T):
    if a != b:
      cnt += 1
  print(cnt)
  exit();
else:
  for i in range(z):
    s = S[i:i+len(T)]
    cnt = 0
    for j,k in zip(s,T):
      if j != k:
        cnt += 1
    res.append(cnt)
  print(min(res))


Measured memory_bytes: 9064
#include "bits/stdc++.h"
using namespace std;

int main(){
	int N,K,d;
	map<int,int> mp;
	cin >> N;
	cin >> K;
	for(int x = 0; x<K;x++){
		cin >> d;
		for(int y = 0; y<d; y++){
		int input;
		cin >> input;
		mp[input]++;
	}
	}
	int count = 0;
	for(int z = 1; z<N+1; z++){
		if(mp[z]==0){
			count++;
		}
	}
	cout << count;
}
	


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int P[N];
  for (int i=0;i<N;i++)cin >> P[i];
  int min = 10000000;
  int count = 0;
  for(int i=0;i<N;i++){
    if(P[i]<min){
      count++;
      min = P[i];
    }
  }
  cout << count;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(){
	int L, R, d, ctr = 0;
	scanf("%d %d %d", &L, &R, &d, &ctr);
	
	while(L <= R){
		if(L % d == 0){
			ctr += 1;
		}
		L++;
	}
	printf("%d\n", ctr);
	
	return 0;
}

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

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<ll> vi;

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define nl cout<<'\n'
#define pb push_back
#define all(s) s.begin(),s.end()
#define bs binary_search

#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a)*(b)/(__gcd((a),(b)))

const int Mod=1e9+7;
#define sum(a,b) (((a)%Mod)+((b)%Mod))%Mod
#define sub(a,b) (((a)%Mod)-((b)%Mod))%Mod
#define mul(a,b) (((a)%Mod)*((b)%Mod))%Mod
#define digit(x) floor((log10(x))+1)


#define count1(x) __builtin_popcount(x)

#define dbg(x) cout << #x <<":"<<x<<endl;

bool isPowerOfTwo (int x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
} 

ll pow(ll x, ll y, ll mod)
{
	int ans=1;
	while(y)
	{
		if(y&1)
			ans=(ans*x)%mod;
		y/=2;
		x=(x*x)%mod;
	}
	return ans;
}

int main()
{
	fast;
	ll n,m,sum,i,temp;
	cin >> n >> m;
	sum=0;
	for(i=0;i<m;i++)
	{
		cin >> temp;
		sum+=temp;
	}
	if(sum<=n)
	{
		cout << n-sum;
	}
	else
	{
		cout << -1;
	}
}

Measured memory_bytes: 3652
n = int(input())
alst = list(map(int,input().split()))
alst.insert(0,0)
alst.append(0)
p = 0
l = 0
for i in range(n+2):
  l += abs(alst[i] - p)
  p = alst[i]
for i in range(1,n+1):
  print(l - abs(alst[i] - alst[i-1]) - abs(alst[i+1] - alst[i]) + abs(alst[i-1] - alst[i+1]))


Measured memory_bytes: 13920
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define ll long long
int in() {int x; cin>>x; return x;}
ll lin() {ll x; cin>>x; return x;}
string sin() {string x;cin>>x;return x;}
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

bool ifprime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=2;i*i<=x;i++){if(x%i==0)return false;}
    return true;
}
ll mod(ll x, ll y){if(x>=0||x%y==0) return x%y;return y+x%y;} //mod including minus
ll dv0(ll x, ll y){if(x>=0||x%y==0)return x/y;return x/y-1;} //rnd down
ll dv1(ll x, ll y){if(x%y==0) return dv0(x,y);return dv0(x,y)+1;} //rnd up
ll M=1e9+7;
int quick_pow(int x,int p)
{
    int an=1,po=x;
    while(p)
    {
        if(p&1)  an=1ll*an*po%M;
        po=1ll*po*po%M;
        p>>=1;
    }
    return an;
}
//Start from Here
int main(){
    ll N, K;
    cin>>N>>K;
    ll a[K+1];
    ll r;
    for(ll i=K;i>0;i--){
        rep2(j, K/i){
            if(j==1){
                a[i]=quick_pow(K/i, N);
            }
            else{
                a[i]-=a[j*i];
                a[i]=mod(a[i],M);
            }
        }
    }

    ll sum=0;
    rep2(i, K){
        sum+=a[i]*i;
        sum%=M;
    }
    
    cout<<sum<<endl;
}

Measured memory_bytes: 4380
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int A=scan.nextInt();
    int B=scan.nextInt();
    if(A>=10||B>=10){
      System.out.println("-1");
    }else{
      System.out.println(A*B);
    }
  }
}

Measured memory_bytes: 23764
import java.util.*;
public class Main {
	
    public static int fac(int n){
        if(n==0) return 1;
        return n*fac(n-1);
    }     
    public static void main(String[] args){        
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int [] in = new int [a];
        int [] in2 = new int [a];
        int b = 1;
        int c = 1;
        for(int i=0;i<a;i++){
                             in[i] = sc.nextInt();
                            }
        for(int i=0;i<a;i++){
                             in2[i] = sc.nextInt();
                            }
		for(int i=0;i<a-1;i++){b+=(in[i]-1)*fac(a-1-i);
        for(int j=i+1;j<a;j++){if(in[j]>in[i]){in[j]--;}                                                             
                            }                                                      
                            }  
        for(int i=0;i<a-1;i++){c+=(in2[i]-1)*fac(a-1-i);
        for(int j=i+1;j<a;j++){if(in2[j]>in2[i]){in2[j]--;}                                                             
                            }                                                      
                            }                                    
		System.out.println(Math.max(b-c,c-b));
	}
}


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

using namespace std;

int main() {
    long long k, a, b, ans1 = 0, ans2 = 0;
    
    cin >> k >> a >> b;
    
    ans1 += k + 1;
    
    k -= a - 1;
    //ans2 += a - 1;
    ans2 += -1 * a * (k / 2 - 1) + b * (k / 2);
    ans2 += k & 1;
    
    cout << max(ans1, ans2) << endl;
    return 0;
}

Measured memory_bytes: 256
from functools import reduce
N, X = map(int, input().split())
x = list(map(int, input().split()))

y = [abs(i-X) for i in x]
def gcd(a, b): # 最大公約数
    while b:
        a, b = b, a % b
    return a
print(reduce(gcd,y))



Measured memory_bytes: 14596
module Main where
import qualified Data.ByteString.Char8         as BS

main :: IO ()
main = do
  s <- BS.getLine
  t <- BS.getLine
  let tl = BS.length t
  -- print [ (take tl $ drop i s) | i <- [0..length s-tl] ]
  print $ minimum [ differences (BS.take tl $ BS.drop i s) t | i <- [0..BS.length s-tl] ]

differences a b = length $ filter id $ BS.zipWith (/=) a b


Measured memory_bytes: 4700
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
string s[3], str = "ABC";
int idx[3], t;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  FOR(i, 0, 3) cin >> s[i];
  while(true){
    if(idx[t] == sz(s[t])){
      cout << str[t] << endl;
      return 0;
    }
    t = s[t][idx[t]++]-'a';
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem(arr,v) memset(arr,v,sizeof(arr))
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
ll dp[100];
ll fib(int n)
{
    if(n==0)
        return 2;
    if(n==1)
        return 1;
    if(dp[n]!=0)
        return dp[n];
    dp[n]=fib(n-1)+fib(n-2);
    return dp[n];
}
int main()
{
     ll t;
     cin>>t;
     cout<<fib(t)<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    vi a(n),b(n),c(n);
    rep(i,n)cin >> a[i],a[i]--;
    rep(i,n)cin >> b[i];
    rep(i,n-1)cin >> c[i];
    int ans = b[a[0]];
    loop(i,1,n){
        //cout << ans << endl;
        ans += b[a[i]];
        if(a[i] == a[i-1]+1)ans += c[a[i-1]];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

vll a, p;

ll f(ll n, ll x) {
    if (n == 0) if (x <= 0) return 0; else return 1;
    else if (x <= 1) return 0;
    else if (x <= a[n-1] + 1) return f(n-1, x-1);
    else if (x == a[n-1] + 2) return p[n-1] + 1;
    else if (x <= 2 + 2 * a[n-1]) return p[n-1] + 1 + f(n-1, x-a[n-1]-2);
    else return 2 * p[n-1] + 1;
}

int main()
{
    ll N, X; cin >> N >> X;
    a.push_back(1);
    p.push_back(1);
    rep(i, N) {
        a.push_back(a[i] * 2 + 3);
        p.push_back(p[i] * 2 + 1);
    }
    //for (auto elem : a) cout << elem << " "; cout << endl;
    //for (auto elem : p) cout << elem << " "; cout << endl;

    cout << f(N, X) << endl;
    return 0;
}

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

using namespace std;

#define il inline
#define re register
#define Rep(i, s, e) for (re int i = s; i <= e; ++i)

const int H = 11;
const int W = 1010;

const int MAXVAL = 1030;

il int read() {
    int x = 0; bool f = true; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = false; c = getchar();}
    while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
    return f ? x : -x;
}

int h, w, K;
char s[W];

int sum[H][W];
il int Get(int c, int l, int r) {
    return sum[r][c] - sum[l - 1][c];
}

int tot, pos[H], now[H], tp[H];
int ans = 0x3f3f3f3f;

int main() {
    h = read(), w = read(), K = read();
    Rep(i, 1, h) {
        gets(s + 1);
        Rep(j, 1, w) sum[i][j] = sum[i - 1][j] + (s[j] == '1');
    }
    int MAX = (1 << (h - 1)) - 1;
    Rep(i, 0, MAX) {
    	memset(now, 0, sizeof(now));
        tot = 0; int tp_ans = 0;
        Rep(j, 0, h - 2) {
            if (i & (1 << j)) pos[++tot] = j + 1;
        }
        tp_ans = tot, pos[++tot] = h;
        bool failed = false;
        Rep(j, 1, w) {
        	Rep(k, 1, tot) {
        		tp[k] = Get(j, pos[k - 1] + 1, pos[k]);
        		if (tp[k] > K) {failed = true; break;}
			}
			if (failed) break;
        	Rep(k, 1, tot) {
        		now[k] += tp[k];
        		if (now[k] > K) {
        			Rep(l, 1, tot) now[l] = tp[l];
        			++tp_ans; break;
				}
			}
		}
	    if (failed) continue;
        ans = min(ans, tp_ans);
    } 
    return printf("%d", ans) & 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int N, i,j,k, stop=0;
	int A[201], expon, alleven;
	scanf("%d",&N);
	for(i=1;i<=N;i++){scanf("%d",&A[i]);}
	expon=0;
	for(i=1;i<=100;i++){	
		
		if (stop==1) ;
		else
		{ alleven = 1;
			
			for (k=1;k<=N;k++)
			{ if (A[k]%2==1) alleven = 0;
			}
			if (alleven==1)
			{ expon=expon +1; 
					for (j=1;j<=N;j++)
					{ A[j]=A[j]/2; 
				}
			}
			else stop =1;				
		}
		}
	printf("%d",expon);
	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
const int N = 1e5;  // limit for array size
ll n;  // array size

int main(){
	ll a,b,n;cin>>a>>b>>n;
	
	if(n>=b){
		cout<<floor((a*(b-1))/b)<<endl;
	}
	
	else{
		cout<<floor((a*(n))/b)<<endl;
	}
	
	return 0;
}

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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  string s;
  while (cin >> s) cout << s[0];
  cout << endl;
}


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

int main() {
    int N; cin >> N;
    int A[N], B[N], C[N];
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> B[i];
    for (int i = 0; i < N; i++) cin >> C[i];
    sort(A, A + N); sort(C, C + N);

    long long ans = 0;
    for (int i = 0; i < N; i++) {
        long long cnt_A = lower_bound(A, A + N, B[i]) - A;
        long long cnt_B = C + N - upper_bound(C, C + N, B[i]);
        ans += cnt_A * cnt_B;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
 
 
int main() {
  int A,B;
  cin>>A>>B;
  
  if((A==1&&B==2)||(A==2&&B==1))
    cout<<3<<endl;
  else if((A==1&&B==3)||(A==3&&B==1))
    cout<<2<<endl;
  else
    cout<<1<<endl;
  
  return 0;
}

Measured memory_bytes: 256
# 桁DP: 

S = input()
N = len(S)
mod = 10**9+7

# dp[前方からの桁数][13で割ったあまり] := 個数 
dp = [[0] * 13 for _ in range(N+1)]

dp[0][0] = 1

for i in range(N):
    if S[i] == '?':
        for j in range(10):
            for k in range(13):
                dp[i+1][(k * 10 + j) % 13] += dp[i][k] % mod
    else:
        for k in range(13):
            dp[i+1][(k * 10 + int(S[i])) % 13] += dp[i][k] % mod

print(dp[N][5] % mod)


Measured memory_bytes: 61788
# 4?
x = int(input())
lis = list(map(int, input().split()))
count = 0

for i in range(x):
  mag=lis[i]
  for s in range(x):
    len=lis[s]
    for t in range(x):
        pas=lis[t]
        if pas == len or len == mag or mag == pas:
            count=count
        elif abs(pas-mag)<len<pas+mag:
            count = count+1
        else:
            count = count

#print(count)
ans = int(count/6)
print(ans)

Measured memory_bytes: 9204
#include<bits/stdc++.h>
#define int long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
#define endl '\n'
//#define for(i,s,n) for(int i=s;i<n;i++) 
#define vii vector<int>
int t = 1, n, OO = 1e14;
vii v, cum;
int dp[401][401];
int solve(int i, int j) {
	if (i + 1 == j) return v[i] + v[j];
	if (i == j) return 0;
	int& ret = dp[i][j];
	if (~ret) return ret;
	ret = OO;
	for (int k = i; k < j; k++) {
		ret = min(ret, (cum[j] - cum[i - 1]) + solve(i, k) + solve(k+1, j));
	}
	return ret;
}
signed main()
{
	fast;
	
	//cin>>t;
	while (t--)
	{
		cin >> n;
		v = vii(n+1);
		for (int i = 1; i <= n; i++) cin >> v[i];
		cum = vii(n + 1);
		for (int i = 1; i <= n; i++) cum[i] = cum[i - 1] + v[i];
		memset(dp, -1, sizeof dp);
		cout<<solve(1,n)<<endl;
	}
}

Measured memory_bytes: 4904
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()



int main(){
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<ll> p(a),q(b),r(1000000,0);
    rep(i,a) cin>>p[i];
    rep(i,b) cin>>q[i];
    rep(i,c) cin>>r[i];
    sort(btoe(p));
    reverse(p.begin(),p.end());
    sort(etob(q));
    sort(etob(r));
    ll ca=0,cb=0,cc=0;
    ll ans=0;
    p.resize(x);
    q.resize(y);
    r.insert(r.end(),btoe(p));
    r.insert(r.end(),btoe(q));
    sort(etob(r));
    rep(i,x+y) ans+=r[i];


    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 20224
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)

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

    int n;
    cin >> n;
    vector<int> X(n), Y(n);
    REP(i, n){
        cin >> X[i];
        Y[i] = X[i];
    }
    sort(Y.begin(), Y.end());
    
    REP(i, n){
        int idx = lower_bound(Y.begin(), Y.end(), X[i]) - Y.begin();
        if(idx < n / 2) cout << Y[n / 2] << '\n';
        else cout << Y[n / 2 - 1] << '\n';
    }
    
    return 0;
}


Measured memory_bytes: 3840
import itertools
n = int(input())
cnt = 0
for i in range(3,len(str(n))+1):
    for v in itertools.product(["3","5","7"], repeat=i):
        if len(set(v))!=3: continue
        x = int("".join(v))
        if n >= x: cnt += 1

print(cnt)

Measured memory_bytes: 9076
n = int(input())
nums = [int(input()) for _ in range(n)]

ans = -1
nxt = 1
cnt = 0
visited = [0] * 100000
while True:
    if nxt == 2:
        ans = cnt
        break
    nxt = nums[nxt - 1]
    if visited[nxt - 1] == 1:
        break
    visited[nxt - 1] = 1
    cnt += 1

print(ans)

Measured memory_bytes: 7852
#include <stdio.h>
using namespace std;
typedef long long ll;

ll mabs(ll a) {
  return a > 0 ? a : -a;
}

int main(void) {
  ll i, j, k, q, a[4], a3[4][31], now, t;
  scanf("%lld", &q);
  for(i = 0; i < q; ++i) {
    for(j = 0; j < 4; ++j) scanf("%lld", &a[j]), a[j]--;
    for(j = 0; j < 4; ++j) {
      now = a[j];
      for(k = 0; k < 31; ++k) a3[j][k] = now % 3, now /= 3;
    }
    now = -1, t = 68630377364883;
    bool b1 = false, b2 = false;
    for(j = 29; j >= 0; --j) {
      if(a3[0][j] != a3[2][j]) b1 = true;
      if(a3[1][j] != a3[3][j]) b2 = true;
      if(b1 && b2) break;
      else if((a3[0][j] == 1 && a3[2][j] == 1 && b2 && mabs(a[1] / t - a[3] / t) != 1) || (a3[1][j] == 1 && a3[3][j] == 1 && b1 && mabs(a[0] / t - a[2] / t) != 1)) {
        now = j;
        break;
      }
      t /= 3;
    }
    if(now == -1) printf("%lld\n", mabs(a[0] - a[2]) + mabs(a[1] - a[3]));
    else {
      t = 1;
      for(j = 0; j < now; ++j) t *= 3;
      if(a3[0][now] == 1) {
        if(a[0] % t + a[2] % t < t - 1) printf("%lld\n", mabs(a[1] - a[3]) + a[0] % t + a[2] % t + 2);
        else printf("%lld\n", mabs(a[1] - a[3]) + 2 * t - a[0] % t - a[2] % t);
      } else {
        if(a[1] % t + a[3] % t < t - 1) printf("%lld\n", mabs(a[0] - a[2]) + a[1] % t + a[3] % t + 2);
        else printf("%lld\n", mabs(a[0] - a[2]) + 2 * t - a[1] % t - a[3] % t);
      }
    }
  }
  return 0;
}

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

ll a[300005];

int main(){
  ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
  int n; cin >> n;
  ll tot = 0;
  ll bf = 0;
  for(int i = 1 ; i <= n ; i++){
    ll tmp; cin >> tmp;
    tmp += bf;
    tot += tmp/2;
    if(tmp/2) bf = tmp%2;
    else bf = 0;
  }
  cout << tot;
}


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

#define PI 3.14159265

int main(void){
  double a, b, C, S, L, h;
  double D;

  scanf("%lf %lf %lf", &a, &b, &C);
  D = C*PI/180;

  S = 0.5 * a * b * sin(D);
  L = a + b + sqrt(a*a + b*b - 2*a*b*cos(D));
  h = b*sin(D);

  printf("%lf\n%lf\n%lf\n", S, L, h);
  return 0;
}



Measured memory_bytes: 1940
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	while(1){
		ll n; cin >> n;
		if(n==0) break;
		vl v(n);
		rep(i,n) cin >> v[i];
		sort(all(v));
		ll s = 0;
		REP(i,1,n-1) s += v[i];
		cout << s / (n-2) << endl;
	}
}


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

signed main(){
	string S;
	int K, ans=0;
	
	cin>>S>>K;
	
	
	for(int i = 0; i < S.size(); i++){//cout<<S[i]<<endl;
		if(i+1 == K){//cout<<i<<" b "<<endl;
			ans  = S[i] - '0';
			break;
		}
		else if(S[i] != '1'){//cout<<i<<" a "<<endl;
			ans = S[i] - '0';
			break;
		}
		
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int h=s.nextInt();

		int[]dp=new int[h+1];
		Arrays.fill(dp,1,h+1,Integer.MAX_VALUE/2);

		for(int n=s.nextInt();n>0;--n) {
			int d=s.nextInt();
			int m=s.nextInt();
			for(int i=0;i<h;++i) {
				int t=Math.min(h,i+d);
				dp[t]=Math.min(dp[t],dp[i]+m);
			}
		}

		System.out.println(dp[h]);
	}
}


Measured memory_bytes: 25384
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    #根を返す
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

#初期化
# uf = Unionfind(n)
n,m = inpl()
ab = [inpl() for i in range(m)][::-1]
uf = UnionFind(n)
res = [n*(n-1)//2]
if m == 1:
    print(*res)
    quit()
cnt = 0
for a,b in ab[:m-1]:
    cnt += 1
    na = uf.size(a-1)
    nb = uf.size(b-1)
    if uf.same(a-1,b-1):
        tt = res[-1]
    else:
        tt = res[-1] - (na*nb)
    uf.union(a-1,b-1)    
    res.append(tt)

for i in res[::-1]:
    print(i)
       
    


Measured memory_bytes: 37400
#include<bits/stdc++.h>
#define lint long long int
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define arep(i,a,n) for(int i=a;i<n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define fill(a,x) fill(a.begin(),a.end(),x)
#define eb(data) emplace_back(data)
#define pb(data) emplace_back(data)
#define mp make_pair
#define ALNUM 26
#define vint vector<int>
#define vlint vector<lint>
#define F first
#define S second
#define ALL(data) data.begin(),data.end()
#define GEts(s) getline(cin,s);
#define UNIQUE(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
using namespace std;
template<typename Rast>inline void out(Rast rast){cout<<rast<<"\n";return;}
template<typename Rast>inline void in(Rast& rast){cin>>rast;return;}
template<typename T>istream& operator >> (istream& is, vector<T>& vec){for(T& x: vec) is >> x;return is;}
template<typename First, typename... Rest>void in(First& first, Rest&... rest){cin >> first;in(rest...);return;}
template<typename First, typename... Rest>void out(First first, Rest... rest){cout << first<<" ";out(rest...);return;}
template<typename T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<typename T1,typename T2>bool chmax(T1& a,T2 b){if(a<b){a=b;return true;}else{return false;}}
template<typename T1,typename T2>bool chmin(T1& a,T2 b){if(a>b){a=b;return true;}else{return false;}}
template<typename T>T lcm(T a, T b){return a * b / gcd(a, b);}
static const double pi = 3.141592653589793;
lint modpow(lint a,lint n,lint p){if(n==1)return a%p;if(n%2==1)return (a*modpow(a,n-1,p))%p;lint t=modpow(a,n/2,p);return (t*t)%p;}//a^n%p
lint MOD=pow(10,9)+7;
//lint MOD=998244353;
lint inf=pow(2,50);
int intinf=pow(2,30);
/**/int dirx[]={1,0};int diry[]={0,1};//*///右、下
/**int dirx[]={0,1,0,-1};int diry[]={-1,0,1,0};//*///四方位
/**int dirx[]={-1,0,1,1,1,0,-1,-1};int diry[]={-1,-1,-1,0,1,1,1,0};//*///八方位

class unionfind{
public:
	vector<int> table;
	vector<int> wod;
	void init(int size){
		table.resize(size);
		wod.resize(size);
		rep(i,size)table[i]=i,wod[i]=i;
	};
	int root(int index){
		if(table[index]==index)return index;
		else{
			int hoge=root(table[index]);
			table[index]=hoge;
			return hoge;
		}
	};
	bool same(int x,int y){
		return(root(x)==root(y));
	};
	int marge(int x,int y){
		int yroot=root(y);
		int xroot=root(x);
		if(xroot==yroot)return 0;
		table[yroot]=xroot;
		return 0;
	}
};


int main(){
	cin.tie(0);ios::sync_with_stdio(false);cout<<std::fixed<<std::setprecision(12);
	int n;
	in(n);
	vint ma(n+1);
	int hoge=0;
	for(int i=1;i<=100;i++)for(int j=1;j<=100;j++)for(int k=1;k<=100;k++){
		hoge=i*i+j*j+k*k+i*j+j*k+k*i;
		if(hoge>n)break;
		ma[hoge]+=1;
	}
	arep(i,1,n+1)out(ma[i]);
	return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
map<string,int>mp;
int main()
{
  int n;
  cin>>n;
  for(int i=0;i<n;i++)
  {
      string x;
      cin>>x;
    mp[x]++;
  }
  vector<string>vt{"AC","WA","TLE","RE"};
  for(auto it:vt)
  {
      cout<<it<<" x "<<mp[it]<<endl;
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;cin >> n >> m;
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(m);
	vector<int> d(m);
	rep(i,n) cin >> a[i] >> b[i];
	rep(i,m) cin >> c[i] >> d[i];
	rep(i,n){
		int ans=0,dist=1<<30;
		rep(j,m){
			int cur=abs(a[i]-c[j])+abs(b[i]-d[j]);
			if(cur<dist){
				ans=j;
				dist=cur;
			}
		}
		cout << ans+1 << endl;
	}
}

Measured memory_bytes: 256
N = int(input())
s = input()
s += s[0]

# S: 1, W: 0
for a0, a1 in ((0, 0), (0, 1), (1, 0), (1, 1)):
  l = [a0, a1]

  for c in s[1:]:
    if c == 'o':
      a0, a1 = a1, not (a0 ^ a1)
    else:
      a0, a1 = a1, (a0 ^ a1)
    l.append(a1)

  if (l[0] == l[-2]) and (l[1] == l[-1]):
    print(''.join('S' if i == 1 else 'W' for i in l[:-2]))
    exit()

print(-1)

Measured memory_bytes: 5620
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    int i,l,f=0;
    l=s.length();
    int mid=(l-1)/2;
    for(i=0;i<mid;i++)
    {
        if(s[i]!=s[l-i-1])
        f=1;
    }
    
    if(f==0)
    {
        if(mid<=2)
        {
            for(i=0;i<mid/2;i++)
            {
                if(s[i]!=s[mid-1-i])
                f=1;
            } 
        }
        else
        {
           for(i=0;i<(mid-1)/2;i++)
            {
                if(s[i]!=s[mid-1-i])
                f=1;
            } 
        }
        
    }
    if(f==1)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
    
    

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n,c;
  cin >> n >> c;
long long  int d[35][35],t[3][35];
  
  for(int i=0;i<c;i++){
    for(int j=0;j<c;j++){
      cin >> d[i][j];
    }
  }
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
     long long  int s;
      cin >> s;
      t[(i+j)%3][s-1]++;
    }
  }
  
 long long int ans=1e18;
  
  for(int i=0;i<c;i++){
    for(int j=0;j<c;j++){
      
      if(i!=j){
        for(int k=0;k<c;k++){
          if(i!=k&&j!=k){
          long long int tem=0;
            
      for(int l=0;l<c;l++) tem+=d[l][i]*t[0][l]; 
      for(int l=0;l<c;l++) tem+=d[l][j]*t[1][l];
      for(int l=0;l<c;l++) tem+=d[l][k]*t[2][l];
            
            ans=min(ans,tem);
          }
        }
      }
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(1e5)+10;
int n;
ll a[maxn],ans,B,s,b[80];
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) read(a[i]),B^=a[i];
	for (int j=0;j<=62;j++)
		if ((B>>j)&1) {
			for (int i=1;i<=n;i++)
				if ((a[i]>>j)&1) a[i]-=1LL<<j;
			s+=1LL<<j;
		}
	for (int i=1;i<=n;i++) {
		for (int j=62;j>=0;j--)
			if (a[i]>>j) {
				if (!b[j]) { b[j]=a[i]; break; }
				a[i]^=b[j];
			}
	}
	for (int i=62;i>=0;i--)
		if (!((ans>>i)&1)&&b[i]) ans^=b[i];
	printf("%lld\n",ans*2+s);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B;
    cin >> A >> B;
    cout << A*B << "\n";
}

Measured memory_bytes: 3620
N=int(input())
t=[]
x=[]
y=[]
for i in range(N):
    txy=list(map(int,input().split()))
    t.append(txy[0])
    x.append(txy[1])
    y.append(txy[2])

now_x=0
now_y=0
now_time=0
isOK=True
for i in range(N):
    dist=(x[i]-now_x)**2+(y[i]-now_y)**2
    time=t[i]-now_time

    if dist<=time**2 and dist%2 ==time%2:
        now_x=x[i]
        now_y=y[i]
        now_time=t[i]
    else:
        isOK=False
        break
        

if isOK:
    print("Yes")
else:
    print("No")


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

int main(int argc, char* argv[])
{
  int x = 0;
  cin >> x;
  if (x>=30)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  
  return 0;
}


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


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define lint long long

using namespace std;
lint n,t;
lint ans;

int main(){
  cin >> n >> t;
  lint st = 0;
  lint en = 0;

  REP(i,n){
    //cout << ans << endl;
    lint k;
    cin >> k;
    if(en >= k){
      en = k+t;
      continue;
    }
    ans += en - st;
    st = k;
    en = k+t;
  }
  ans += en - st;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
const int MOD = 1000000007;
int N, M, K, f[524288], g[524288];
inline void add(int &x, int y)
{
	x = x + y < MOD ? x + y : x + y - MOD;
}
void Sanho(const int *f, int *g, int d)
{
	if (d == 0)
	{
		g[0] = f[0];
		return;
	}
	Sanho(f, g, d - 1);
	std::vector < int > _F(1 << d - 1);
	int *F = _F.data();
	F[0] = f[0];
	for (int i = 1; i < 1 << d; i <<= 1)
		for (int j = 0; j < i; j++)
			add(F[j], f[j + i]);
	Sanho(F, g + (1 << d - 1), d - 1);
}
void Process()
{
	Sanho(f, g, N);
	std::copy(g, g + (1 << N), f);
}
std::vector < std::pair < int, int > > lim[20];
int main()
{
	scanf("%d%d%d", &N, &M, &K);
	N--;
	while (K--)
	{
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		lim[a - 1].push_back({ N - b, c });
	}
	f[0] = 1;
	for (int i = 0; i < M; i++)
	{
		Process();
		for (int j = 0; j < 1 << N; j++)
			for (auto k : lim[i])
				if ((j >> k.first & 1) != k.second)
					f[j] = 0;
	}
	int O = 0;
	for (int i = 0; i < 1 << N; i++)
		add(O, f[i]);
	printf("%d\n", O);
	return 0;
}


Measured memory_bytes: 6440
#include<bits/stdc++.h>
using namespace std;
#define MAX 100001
#define MOD 1000000007
#define ll long long
#define ld long double
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
int main() {
	fast;
	int t = 1;
	// cin >> t;
    while(t--) {
		int n, x, t;
		cin >> n >> x >> t;
		int ans = (n / x) * t;
		if(n % x != 0) ans += t;
		cout << ans << endl;
    }
}


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	string s="CODEFESTIVAL2016";
	string t; cin>>t;
	int res=0;
	rep(i,t.size()) res+=s[i]!=t[i];
	cout<<res<<endl;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
l = sorted(l)
ans = 0

for i in range(len(l)):
    for j in range(i+1,len(l)):
        for k in range(j+1,len(l)):
            if l[i] + l[j] > l[k] and l[j] + l[k] > l[i] and l[k] + l[i] > l[j] and l[i] != l[j] and l[j] != l[k] and l[k] != l[i]:
                ans += 1

print(ans)


Measured memory_bytes: 9136
N, M = map(int, input().split())
dict = {i+1:[] for i in range(N)}
for _ in range(M):
    a, b = map(int, input().split())
    dict[a].append(b)
    dict[b].append(a)
    
def DFS(visited, sight, cnt):
    if(len(visited) == N):
        return cnt+1
    for num in dict[sight]:
        if num in visited:
            continue
        cnt = DFS(visited+[num], num, cnt)
    return cnt

print(DFS([1], 1, 0))

Measured memory_bytes: 3064
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define VI(v,n) vector<int> v(n)

long nCr(int n, int r) {
	long ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans*i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}



int main() {
	
	int n, p;
	cin >> n >> p;
	VI(a, n);
	int odd = 0, even = 0;
	REP(i, n) {
		cin >> a[i];
		if (a[i] % 2 == 0) {
			even++;
		}
		else {
			odd++;
		}
	}

	if (odd == 0) {
		if (p == 0) {
			cout << (long long)pow(2, n) << endl;
		}
		else {
			cout << 0 << endl;
		}
	}
	else {
		cout <<(long long) pow(2, n - 1) << endl;
	}






	return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int N,W;
struct item
{
    int v;
    int w;
}I[110];
int V[110][10010];
int main()
{
    cin>>N>>W;
    for(int i=0;i<N;i++)
        cin>>I[i].v>>I[i].w;
    for(int i=0;i<=N;i++)
        for(int c=0;c<=W;c++)
        {
            if(i<=0||c<=0)
                V[i][c]=0;
            else if(c-I[i-1].w<0)
                V[i][c]=V[i-1][c];
            else if(c-I[i-1].w>=0)
                V[i][c]=max(V[i-1][c-I[i-1].w]+I[i-1].v,V[i-1][c]);
        }
        cout<<V[N][W]<<endl;
        return 0;
}


Measured memory_bytes: 6996
x, k, d = [int(x) for x in input().split()]
x = abs(x)
if x - k*d <= 0:
    t = x//d
    x -= (d*t)
    k -= t
else:
    x -= k*d
    print(x)
    exit()


if k % 2 == 0:
    print(x)
else:
    print(abs(x - d))

Measured memory_bytes: 61864
n = int(input())
s = 0
for i in range(1, 6, 2):
  if n >= 10 ** i:
    s += 9 * (10 ** (i - 1))
  else:
    tmp = n - (10 ** (i - 1)) + 1
    if tmp > 0:
      s += tmp
    break
print(s)

Measured memory_bytes: 2940
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define N 110
int a[N];
int main()
{
    int i,j,k,n;
    double d,t;
    scanf("%d",&n);
    d=0;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        d=d+a[i];
    }
    t=d;
    d=d/n;
    k=0;
    for(i=0;i<n;i++)
    if(fabs(d-a[i])<t)
    {
        t=fabs(d-a[i]);
        k=i;
    }
    printf("%d\n",k);
    return 0;
}


Measured memory_bytes: 128