akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int ans=0;
  int v[50],c[50];
  rep(i,n) cin>>v[i];
  rep(i,n) cin>>c[i];
  rep(i,n){
    if(v[i]>c[i]) ans+=v[i]-c[i];
  }
  cout<<ans<<endl;


  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct Graph {
    struct Vertex { int n, d; };
    struct Edge { int i, n; };
    Graph(int n, int m) : v(n, { -1 }), e(m), q(n), n(n), m(0) {}
    void add_edge(int i, int j) {
        e[m] = { j, v[i].n };
        v[i].n = m;
        m++;
    }
    void bfs(int i0) {
        for (int i = 0; i < n; i++) {
            v[i].d = -1;
        }
        v[i0].d = 0;

        int j0 = 0, j1 = 0;
        q[j1++] = i0;

        while (j0 < j1) {
            int i = q[j0++];
            for (int j = v[i].n; j >= 0; j = e[j].n) {
                Edge& o = e[j];
                if (v[o.i].d >= 0) continue;

                v[o.i].d = v[i].d + 1;
                q[j1++] = o.i;
            }
        }
    }
    void solve() {
        vector<int> r(n);
        for (int i = 0; i < n; i++) {
            bfs(i);
            for (int j = 0; j < n; j++) {
                if (i != j) r[v[j].d]++;
            }
        }
        for (int i = 1; i < n; i++) {
            cout << r[i] / 2 << '\n';
        }
    }
    vector<Vertex> v;
    vector<Edge> e;
    vector<int> q;
    int n, m;
};

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

    int n, x, y;
    cin >> n >> x >> y;
    x--; y--;

    Graph g(n, n * 2);
    for (int i = 0; i < n - 1; i++) {
        g.add_edge(i, i + 1);
        g.add_edge(i + 1, i);
    }
    g.add_edge(x, y);
    g.add_edge(y, x);

    g.solve();

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
#define REP(a,b,c) for(register int a=(b),a##end=(c);a<=a##end;++a)
#define DEP(a,b,c) for(register int a=(b),a##end=(c);a>=a##end;--a)
const int MAXN=200+10;
int n,a[MAXN],ans;
template<typename T> inline void read(T &x)
{
	T data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
	x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
	if(ch!='\0')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
int main()
{
	read(n);n<<=1;
	REP(i,1,n)read(a[i]);
	std::sort(a+1,a+n+1);
	for(register int i=n-1;i>=1;i-=2)ans+=a[i];
	write(ans,'\n');
	return 0;
}


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

using namespace std;

int trans(char c){
if('0' <= c && c <= '9') return (c-'0');
  return -1;


}

int main(){
    string s;
    cin>>s;
    int size=s.size();
    int mi=10000;
    int kouho;
    
    for(int k100=0;k100<size-2;k100++)
        {
            kouho=100*trans(s.at(k100))+10*trans(s.at(k100+1))+trans(s.at(k100+2));
            mi=min(abs(753-kouho),mi);

        }
    cout<<mi<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define QSIZE (100000)

struct proc *Qu[QSIZE];
int soq=0,eoq=0;

struct proc{
  char name[11];
  int ti;
};

struct proc *enQ(struct proc *data){
  Qu[eoq] = data;
  eoq = (eoq+1)%QSIZE;
  return data;
}

struct proc *deQ(){
  int oldSt;
  if(soq==eoq){
    return NULL;
  }
  oldSt = soq;
  soq = (soq+1)%QSIZE;
  return Qu[oldSt];
}

int main(){
  int n,q;
  int i;
  int total = 0;
  struct proc *data;
  scanf("%d %d",&n,&q);
  for(i=0;i<n;i++){
    data = (struct proc*)malloc(sizeof(struct proc));
    scanf("%s %d",(*data).name,&((*data).ti));
    enQ(data);
  }
  while(n>0){
    data = deQ();
    if(data->ti > q){
      total+=q;
      data->ti -=q;
      enQ(data);
    }else{
      total += data->ti;
      printf("%s %d\n",data->name,total);
      n--;
    }
  }
}

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

typedef long long ll;
typedef pair<int,int> pii;

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 5e3 + 9, M = 5e3 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int n, k, a[N], dp[N][N], temp;

//int solve(int i, int sum){
//    if(i == n)  return (sum >= k - temp && sum < k);
//
//    int &ret = dp[i][sum];
//    if(~ret)    return ret;
//
//    return ret = solve(i + 1, sum) | solve(i + 1, min(k, sum + a[i]));
//}

int solve(){
    for(int i = 0;i < N;i++)
        for(int sum = 0;sum < N;sum++)
            dp[i][sum] = (sum >= k - temp && sum < k);

    for(int i = N - 2;i >= 0;i--){
        for(int sum = N - 2;sum >= 0;sum--){
            dp[i][sum] = dp[i + 1][sum] | dp[i + 1][min(k, sum + a[i])];
        }
    }

    return dp[0][0];
}

int main(){
    init();

    cin >> n >> k;
    for(int i = 0;i < n;i++)    cin >> a[i];

    sort(a, a + n);
    while(n - 1 >= 0 && a[n - 1] >= k)  n--;

    int l = 0, r = n - 1;
    while(l <= r){
        int i = (l + r) >> 1;

        temp = a[i];    a[i] = 0;
//        memset(dp, -1, sizeof dp);
        int ok = !(solve());
        a[i] = temp;

        if(ok == 1)
            l = i + 1;
        else
            r = i - 1;
    }

    cout << l;
}

Measured memory_bytes: 98432
#include <iostream>
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7;

int main(){
    string s;
    ll i,j,k;
    cin >> s;
    ll ss=s.size();
    ll tcnt=0,ret=0;
    ll times2[200000],times3[200000];
    times2[0]=times3[0]=1LL;
    for(i=1;i<200000;i++){
        times2[i]=(times2[i-1]*2)%MOD;
        times3[i]=(times3[i-1]*3)%MOD;
    }
    for(i=0;i<ss;i++){
        if(s[i]=='1'){
            ret+=(times2[tcnt]*times3[ss-i-1])%MOD; //i番目を0とすると上位の1をどちらに振り分けるか(2通り)と下位の振り分けるか分けないか(3通り)
            ret%=MOD;
            tcnt++; //1の数を数える
        }
    }
    ret+=times2[tcnt];//最後に1をすべて使う場合を足しこむ
    ret%=MOD;
    cout << ret << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    int N;
    cin >> N;
    if(N>=400&&N<=599) cout << 8 << endl;
    if(N>=600&&N<=799) cout << 7 << endl;
    if(N>=800&&N<=999) cout << 6 << endl;
    if(N>=1000&&N<=1199) cout << 5 << endl;
    if(N>=1200&&N<=1399) cout << 4 << endl;
    if(N>=1400&&N<=1599) cout << 3 << endl;
    if(N>=1600&&N<=1799) cout << 2 << endl;
    if(N>=1800&&N<=1999) cout << 1 << endl;
    return 0;

}


Measured memory_bytes: 3616
N = int(input())
h = list(map(int, input().split()))

dp = [10**9 for _ in range(N)]

dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))

ans = dp[N-1]
print(ans)

Measured memory_bytes: 13976
#include<iostream>
using namespace std;
int d[100005];
int dp(int arr[],int n,int i) {
    if(i==n-2)return abs(arr[n-2]-arr[n-1]);
    if(i==n-1)return 0;
    
    if(d[i]!=-1)return d[i];
    int ans= min(abs(arr[i]-arr[i+1])+dp(arr,n,i+1),
                 abs(arr[i]-arr[i+2])+dp(arr,n,i+2));
    d[i]=ans;
    return d[i];
}
int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0; i<n; i++) {
        cin>>arr[i];
        d[i]=-1;
    }

    cout<<dp(arr,n,0)<<endl;
    return 0;
}

Measured memory_bytes: 8228
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.IOException;

public class Main {

    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String input;
        while (!(input = br.readLine()).equals("0")) {
            int count = 0;
            for (char c : input.toCharArray()) {
                count += (c - '0');
            }
            bw.append(count + "\n");
        }
        bw.flush();
    }


}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

struct edge
{
  ll w,s,t;
};
bool sorter(const edge& a,const edge& b){
  return a.w > b.w;
}

struct UnionFind{
  vector<int> v;
  UnionFind(int n) : v(n, -1) {}
  void init(){ for(int i = 0;i < v.size();i++)v[i]=-1; }
  int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (-v[x] < -v[y]) swap(x, y);
    v[x] += v[y]; v[y] = x;
    return true;
  }
  bool root(int x) { return v[x] < 0; }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -v[find(x)]; }
};

ll n;
vector<edge> es;
ll sum[200020];
vector<ll> g[200020];
ll par[200020];
ll res[200020];

void dfs(ll v,ll par,ll nsum){
  if(v<n){
    res[v]=nsum+sum[v];
    return;
  }
  for(ll nv : g[v]){
    if(par==nv)continue;
    dfs(nv,v,nsum+sum[v]);
  }
}

int main(){
  cin>>n;
  UnionFind uf(n);
  rep(i,n-1){
    ll a,b,c;
    cin>>a>>b>>c;
    a--; b--;
    es.push_back((edge){c,a,b});
  }
  sort(all(es),sorter);
  ll V=n;
  rep(i,n)par[uf.find(i)]=i;
  rep(i,n-1){
    ll sx=uf.size(es[i].s);
    ll sy=uf.size(es[i].t);
    //dbg(sx); dbg(sy);
    ll px=par[uf.find(es[i].s)];
    ll py=par[uf.find(es[i].t)];
    //dbg(px); dbg(py);
    sum[px]+=es[i].w*sy;
    sum[py]+=es[i].w*sx;
    g[px].push_back(V); g[V].push_back(px);
    g[py].push_back(V); g[V].push_back(py);
    uf.unite(es[i].s,es[i].t);
    par[uf.find(es[i].s)]=V++;
  }
  //rep(i,V)dbg(sum[i]);
  dfs(V-1,-1,0);
  rep(i,n)cout<<res[i]<<endl;
	return 0;
}


Measured memory_bytes: 26096
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main() {
    int N; cin >> N;
    VI a(N), ra(N+1);
    REP(i,N)
    {
     cin >> a[i];
     ra[a[i]] = i;
    }

    set<int> s;
    s.insert(-1); s.insert(N);
    LL ans = 0;

    for(int i = 1; i <= N; i++)
    {
        int d = ra[i];
        auto it = s.lower_bound(d);
        int r = *it;
        dump(r)
        it--;
        int l = *it;
        dump(l)
        ans += 1LL * i * (d-r) * (l-d);
        dump(ans)
        s.insert(d);
    }
    cout << ans << endl;
}    



Measured memory_bytes: 11136
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std ;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define per(i,b,a) for(int i=b; i>=a; i--)
#define sz(v) (int)v.size()
#define len(s) (int)s.length()
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
typedef pair<int, int> pi ;
typedef vector<pair<int,int> > vpi ;
typedef vector<int> vi ;
typedef long long ll ;
typedef double db ;
typedef long double ldb ;
const int mod = 1e9 + 7;
const int cmod = 998244353 ;
const ll inf = 1e18 + 5;
const db cpi = 3.14159265358 ;
ll powmod(ll a, ll b) { ll ret = 1 ; while(b) { if(b&1) ret = (ret*a)%mod ;  a = (a*a)%mod ; b >>= 1 ; }  return ret ; }
const int maxn = 4e5 + 5 ;
string s ;
int dp[maxn][3] ;
int main()
{
    ios::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    cin >> s ;
    int n = len(s) ;
    dp[0][1] = 1 ;
    rep(i,1,n-1)
    {
        dp[i][1] = dp[i-1][2] + 1 ;
        if(s[i] != s[i-1]) dp[i][1] = max(dp[i][1], dp[i-1][1] + 1) ;
        if(i < 2) continue ;
        dp[i][2] = dp[i-2][1] + 1;
        if(i < 3) continue ;
        string a, b ;
        a = s[i] + s[i-1] ;
        b = s[i-2] + s[i-3] ;
        if(a != b) dp[i][2] = max(dp[i][2], dp[i-2][2] + 1) ;
    }
    int best = max(dp[n-1][1], dp[n-1][2]) ;
    cout << best << "\n" ;
    return 0 ;
}


Measured memory_bytes: 4628
import os

def main():
	string = input()
	lists = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
	ans = ""
	count = 0
	for i in lists:
		if string == i:
			ans = lists[count+1]
			break
		count += 1
	print(ans)

if __name__ == '__main__':
	main()


Measured memory_bytes: 3060
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        mut h: [usize;n],
    }

    let mut counter = 0;
    let mut current = 0;

    for i in h {
        if i > current {
            counter += i - current;
        }
        current = i;
    }
    println!("{}", counter);
}


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


int c[4][4];

int a1, a2, a3, b1, b2, b3;
int main() {
    ios::sync_with_stdio(false);
    
    for (int i = 1; i <= 3; i++)
        for (int j = 1; j <= 3; j++)
            cin >> c[i][j];
    
    a1 = 0;
    b1 = c[1][1];
    b2 = c[1][2];
    b3 = c[1][3];
    a2 = c[2][1] - b1;
    a3 = c[3][1] - b1;
    
    c[0][1] = b1;
    c[0][2] = b2;
    c[0][3] = b3;
    
    c[1][0] = a1;
    c[2][0] = a2;
    c[3][0] = a3;
    
    
     for (int i = 1; i <= 3; i++) {
        for (int j = 1; j <= 3; j++) {
            if (c[i][j] != c[i][0]+c[0][j]) {
                cout << "No\n";
                return 0;
                
            }
        }
    }
    cout << "Yes\n";;
    return 0;
    
    
    
    
    return 0;
}



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

using namespace std;

int main(void){
    int K, S;
    cin >> K >> S;
    int cnt = 0;
    for(int x=0; x <= K && x <= S; x++){
        for(int y=0; y <= K && y <= S-x; y++){
            int z = S-x-y;
            if(z <= K){
                cnt++;
            }
        }
    }
    cout << cnt;
    return 0;
}

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

ll N;
int Bit[100];
ll dp[100][3];

int main(){

cin>>N;

int k=0;
while(N>0){
    if(N%2==1){
        Bit[k]=1;
    }
    N/=2;
    k++;
}

dp[0][0]=1LL; 

for(int i=0; i<k; i++){
    if(Bit[k-(i+1)]){
        dp[i+1][0]=dp[i][0]%MOD;
        dp[i+1][1]=(dp[i][0]+dp[i][1])%MOD;
        dp[i+1][2]=(2*dp[i][1]+3*dp[i][2])%MOD;
    }else{
        dp[i+1][0]=(dp[i][0]+dp[i][1])%MOD;
        dp[i+1][1]=dp[i][1]%MOD;
        dp[i+1][2]=(dp[i][1]+3*dp[i][2])%MOD;
    }
}

ll ans=(dp[k][0]+dp[k][1]+dp[k][2])%MOD;

cout<<ans<<endl;

return 0;
 
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define int long long
const int MAX=200000;
signed main(){
    int n,max_a=0,a[MAX]={},b[MAX]={};
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(max_a<a[i]){
            max_a=a[i];
        }
    }
    for(int i=0;i<n;i++){
        b[a[i]]=b[a[i]]+1;
    }
    int ret=0;
    for(int j=1;j<=max_a;j++){
        ret+=(b[j])*(b[j]-1)/2;
    }
    int retk=0;
    int k=0;
    int k1=0;
    for(int i=0;i<n;i++){
        if(b[a[i]]>1){
            retk=ret-b[a[i]]+1;
        }else{
            retk=ret;
        }
        cout<<retk<<endl;
    }
    
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define FAST_INPUT ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long

using namespace std;

const int mod = 1e9 + 7;

void add_self(int& a, int b) {
	a += b;
	if (a > mod) {
		a -= mod;
	}
}

void solve() {
	int n;
	cin >> n;
	vector<vector<int>> can(n, vector<int>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> can[i][j];
		}
	}
	vector<int> dp(1 << n); // 2 ^ n
	dp[0] = 1;

	for (int mask = 0; mask < (1 << n) - 1; mask++) {
		int a = __builtin_popcount(mask);
		for (int b = 0; b < n; b++) {
			if (can[a][b] && !(mask & (1 << b))) {
				int m2 = mask ^ (1 << b);
				add_self(dp[m2], dp[mask]);
			}
		}
	}

	cout << dp[(1 << n) - 1] << endl;
}

int main() {
    FAST_INPUT;

    solve();

    return 0;
}


Measured memory_bytes: 8448
import sys
N = int(sys.stdin.buffer.readline())
AB = list(map(int, sys.stdin.buffer.read().split()))
A = AB[::2]
B = AB[1::2]
ans = min(sum(A), sum(B))
AB.sort()
pivot = AB[N-1]
pivot2 = AB[N]
pivot_idxs = []
pivot2_idxs = []
ans2 = sum(AB[:N])
for i, (a, b) in enumerate(zip(A, B)):
    if a <= pivot and b <= pivot:
        ans = min(ans, ans2)
        print(ans)
        exit()
    if a == pivot or b == pivot:
        pivot_idxs.append(i)
    if a == pivot2 or b == pivot2:
        pivot2_idxs.append(i)

if len(pivot_idxs) == len(pivot2_idxs) == 1 and pivot_idxs[0] == pivot2_idxs[0]:
    ans2 = min(
        ans2 - pivot + AB[N+1],
        ans2 - AB[N-2] + pivot2
    )
else:
    ans2 = ans2 - pivot + pivot2
ans = min(ans, ans2)
print(ans)


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

#define MAX_N 500000
#define INF 2139062143

int x[MAX_N][3], cnt;//num,left,right
int n, a;
string S;

void inorder(int u) {
	if (u == -1) { return; }
	inorder(x[u][1]);
	cout << ' ' << x[u][0];
	inorder(x[u][2]);
}
void preorder(int u) {
	if (u == -1) { return; }
	cout << ' ' << x[u][0];
	preorder(x[u][1]);
	preorder(x[u][2]);
}

int main() {
	int root = -INF;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> S;
		if (S == "print") {
			inorder(root);
			cout << endl;
			preorder(root);
			cout << endl;
		}
		if (S == "find") {
			cin >> a;
			int v = root;
			while (true) {
				if (a == x[v][0]) {
					cout << "yes" << endl;
					goto D;
				}
				if (a < x[v][0]) {
					if (x[v][1] == -1) {
						goto C;
					}
					v = x[v][1];
				}
				if (a > x[v][0]) {
					if (x[v][2] == -1) {
						goto C;
					}
					v = x[v][2];
				}
			}
		C:;
			cout << "no" << endl;
		D:;
		}
		if (S == "insert") {
			cin >> a;
			if (root == -INF) {
				root = cnt;
			}
			else {
				int v = root;
				while (true) {
					if (a < x[v][0]) {
						if (x[v][1] == -1) {
							x[v][1] = cnt;
							goto E;
						}
						v = x[v][1];
					}
					else {
						if (x[v][2] == -1) {
							x[v][2] = cnt;
							goto E;
						}
						v = x[v][2];
					}
				}
			E:;
			}
			x[cnt][0] = a; x[cnt][1] = -1; x[cnt][2] = -1;
			cnt++;
		}
	}
	return 0;
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

const int N = 1e5 + 10, M = 1e5 + 10;

int n, m;

bool flag;

VI edge[N];

int co[N];

int O, P, Q;

void dfs(int i, int x)
{
	co[i] = x;
	for (auto j : edge[i])
	{
		if (co[j])
		{
			if (co[j] != (co[i] ^ 1)) flag = 0;
		}
		else
		{
			dfs(j, x ^ 1);
		}
	}
}

int main()
{
	gii(n, m);
	for (int i = 1; i <= m; ++i)
	{
		int u, v;
		gii(u, v);
		edge[u].pb(v);
		edge[v].pb(u);
	}
	for (int i = 1; i <= n; ++i)
	{
		if (!co[i])
		{
			if (!SZ(edge[i]))
			{
				++O;
				continue;
			}
			flag = 1;
			dfs(i, 2);
			if (flag) ++Q;
			else ++P;
		}
	}
	long long ans = 2LL * O * n - 1LL * O * O + 1LL * P * P + 2LL * P * Q + 2LL * Q * Q;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 9984
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def f(a, b):
    if a == 0 or b == 0:
        return 0
    if a > b:
        q, r = divmod(a, b)
        return 2*q*b + f(a % b, b)
    else:
        return a+b+f(b-a, a)

N, X = map(int, read().split())

print(X + f(X, N - X))

Measured memory_bytes: 9036
data = []
while True:
    a, op, b = map(str, input().split())
    if op == "?":
        break
    data.append([a, op, b])

for i in range(len(data)):
    if data[i][1] == "+":
        print(int(data[i][0]) + int(data[i][2]))
    elif data[i][1] == "-":
        print(int(data[i][0]) - int(data[i][2]))
    elif data[i][1] == "*":
        print(int(data[i][0]) * int(data[i][2]))
    elif data[i][1] == "/":
        print(int(data[i][0]) // int(data[i][2]))



Measured memory_bytes: 5600
#include <bits/stdc++.h> 
using namespace std; 
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long int ll;


int main() 
{ 
    FIO
    ll x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;

    ll a1[a];
    for(ll i=0;i<a;i++)
        cin >> a1[i];
    sort(a1,a1+a);
    ll b1[b];
    for(ll i=0;i<b;i++)
        cin >> b1[i];
    sort(b1,b1+b);
    ll c1[c];
    for(ll i=0;i<c;i++)
        cin >> c1[i];
    sort(c1,c1+c);
    
    multiset<ll> m1,m2,m3;
    for(ll i=a-1;i>=0;i--)
    {
        m1.insert(a1[i]);
        if(m1.size()==x)
            break;
    }
    for(ll i=b-1;i>=0;i--)
    {
        m2.insert(b1[i]);
        if(m2.size()==y)
            break;
    }

    for(ll i=c-1;i>=0;i--)
    {
        auto p1 = m1.begin();
        auto p2 = m2.begin();

        if(c1[i]>*p1 && c1[i]>*p2)
        {
            ll dif1 = c1[i] - *p1;
            ll dif2 = c1[i] - *p2;
            if(dif1>dif2)
            {
                m1.erase(p1);
                m1.insert(c1[i]);
            } 
            else
            {
                m2.erase(p2);
                m2.insert(c1[i]);
            }
        }
        else if(c1[i]>*p1)
        {
            m1.erase(p1);
            m1.insert(c1[i]);
        }
        else if(c1[i]>*p2)
        {
            m2.erase(p2);
            m2.insert(c1[i]);
        }
        else
            break;
    }

    ll ans = 0;

    for(auto i=m1.begin();i!=m1.end();i++)
        ans += *i;
    
    for(auto i=m2.begin();i!=m2.end();i++)
        ans += *i;

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


Measured memory_bytes: 11008
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, string.sub(k, i, i)) end local r = io.read local u = table.unpack return function() return r(u(a)) end end})
-- A
local a, _, s = read.nll()
if a >= 3200 then print(s)
else print("red") end

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

int psum(int a,int b,vector<int> A) {
  int k = 0;
  for (int i = a; i < b+1; i++) {
    k += A[i];
  }
  return k;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N),B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (psum(0,i,A) + psum(i,N-1,B) > ans) {
      ans = psum(0,i,A) + psum(i,N-1,B);
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

template <typename T>
struct UnionFind{
	Vec1<T> par;

	UnionFind(T n){
		par.resize(n);
		rep(i, n) par[i] = i;
	}

	T root(T x){
		if(par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(T x, T y){
		x = root(x), y = root(y);
		if(x != y) par[x] = y;
	}

	bool same(T x, T y){
		return root(x) == root(y);
	}
};

int main(void){
	ll n, m, k;
	cin >> n >> m >> k;

	UnionFind<ll> uf(n);
	Vec f(n);
	rep(i, m){
		ll a, b;
		cin >> a >> b;
		a--, b--;
		uf.unite(a, b);
		f[a]++, f[b]++;
	}
	Vec cnt(n);
	rep(i, n) cnt[uf.root(i)]++;
	//co(cnt);
	Vec ans(n);
	rep(i, n) ans[i] = cnt[uf.root(i)]-1;
	//co(ans);
	rep(i, n) ans[i] -= f[i];
	rep(i, k){
		ll c, d;
		cin >> c >> d;
		c--, d--;
		if(uf.same(c, d)){
			ans[c]--;
			ans[d]--;
		}
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
	int N;
	cin >> N;
	vector<long long>A(N);
	for (size_t i = 0; i < N; i++)
	{
		cin >> A.at(i);
	}
	sort(A.begin(), A.end());
	vector<long long>sum(N+1);
	for (size_t i = 0; i < N; i++)
	{
		sum.at(i+1) = sum.at(i) + A.at(i);
		//cout << sum.at(i);

	}
	int ans=1;
	for (int i = N-1; i >= 0; i--)
	{
		if (sum.at(i)*2 <  A.at(i)) {
			cout << ans;
			return 0;
		}
		ans++;
	}
}

Measured memory_bytes: 1792
import java.util.*;
class Main{
	static Scanner s = new Scanner(System.in);
	public static void main(String[] args) {
		int[] in = new int[s.nextInt()*2];
		for(int i=0;i<in.length;i++)
			in[i]=i+1;
		int b;
		for(int i=s.nextInt();i>0;--i)
			if((b=Integer.parseInt(s.next()))==0)
				riffle(in);
			else
				cut(in, b);
		System.out.println(Arrays.toString(in).replaceAll("[^0-9,]","").replaceAll(",","\n"));
	}
	static void cut(int[] in,int k) {
		int[] b = Arrays.copyOfRange(in, 0, k);
		for(int i=0;i<in.length-b.length;i++)
			in[i]=in[i+b.length];
		for(int i=0;i<b.length;i++)
			in[in.length-b.length+i]=b[i];
	}
	static void riffle(int[] in) {
		int[] b = Arrays.copyOfRange(in, 0, in.length/2);
		int[] bb= Arrays.copyOfRange(in, in.length/2, in.length);
		for(int i=0;i<b.length;i++) {
			in[i*2  ]=b [i];
			in[i*2+1]=bb[i];
		}
	}
}

Measured memory_bytes: 29952
loop{
  a,b,c=STDIN.gets.split
  a=a.to_i
  c=c.to_i
  
  case b
  when '+' then
    puts a+c
  when '-' then
    puts a-c
  when '*' then
    puts a*c
  when '/' then
    puts a/c
  else
    break
  end
}

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

namespace SplitPile
{
    class Program
    {
        
        public static void Main(string[] args)
        {
            var num = int.Parse(Console.ReadLine());
            var curdNums = Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();

            var absDiffs = new long[num - 1];
            long xSum = curdNums[0];
            long ySum = curdNums.Sum() - curdNums[0];
            absDiffs[0] = Math.Abs(xSum - ySum);

            for (int i = 1; i < absDiffs.Length; i++)
            {
                xSum += curdNums[i];
                ySum -= curdNums[i];
                absDiffs[i] = Math.Abs(xSum - ySum);
            }

            Console.WriteLine(absDiffs.Min());
        }

    }
}


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

int main()
{
    int maisuu = 0;
    cin >> maisuu;


    if(maisuu % 2 == 0)
        cout << maisuu / 2 << endl;
    else
        cout << maisuu / 2 + 1 << endl;
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

int man(ii a, ii b) {
	return abs(a.ff - b.ff) + abs(a.ss - b.ss);
}

void solve() {
	int h, w, d;
	cin >> h >> w >> d;
	
	vii pos(h * w + 1);
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			int tmp;
			cin >> tmp;
			pos[tmp] = {i, j};
		}
	}
	
	vi dist(h * w + 1);
	for(int i = 1; i <= d; i++) {
		dist[i] = 0;
		for(int j = i + d; j <= h * w; j += d) {
			dist[j] = dist[j - d] + man(pos[j - d], pos[j]);
		}	
	}
	
	int q;
	cin >> q;
	while(q--) {
		int l, r;
		cin >> l >> r;
		cout << dist[r] - dist[l] << endl;
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

Measured memory_bytes: 4224
#include <stdio.h>
int main(){
    int S,h,m,s;
    scanf("%d",&S);
    
    h=S/3600;
    S%=3600;
    m=S/60;
    S%=60;
    s=S;
    
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


Measured memory_bytes: 2028
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k,a,b;
	cin>>k>>a>>b;
	for(int i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			cout<<"OK";
			return 0;
		}
	}
	cout<<"NG";
	return 0;
}

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

ll solve(int n,int W,vector<ll>val,vector<ll>wgt)
{
    vector<vector<ll>> dp(n+1,vector<ll>(W+1,0));

    for (ll i=0;i<=n;i++)
    {
        for(ll w=0;w<=W;w++)
        {
            if (i==0 or w==0)
            {
                dp[i][w] = 0;
            }

            else if (wgt[i-1]<=w)
            {
                dp[i][w] = max(val[i-1]+dp[i-1][w-wgt[i-1]],dp[i-1][w]);
            }
            else
            {
                dp[i][w] = dp[i-1][w];
            }
        }
    }

    return dp[n][W];
}

int main()
{
    int n,W; cin >> n >>W;
    vector<ll> val(n);
    vector<ll> wgt(n);

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

    cout<<solve(n,W,val,wgt);
    return 0;
}



Measured memory_bytes: 80256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N, D; scanf("%d%d", &N, &D);
    vector<ll> X(N), Y(N);
    int ans = 0;
    for(int i=0; i<N; i++) {
        scanf("%lld%lld", &X[i], &Y[i]);
        ll dist = X[i]*X[i] + Y[i]*Y[i];
        if(dist <= 1LL*D*D) ans++;
    }
    printf("%d\n", ans);
    return 0;
}


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

const int MAX_N	= 100;
int t[ MAX_N + 5 ];
int v[ MAX_N + 5 ];
int A[ MAX_N + 5 ];

int main()
{
int i;
int j;
int N;
int T;
int L;
int R;
int iSum;
int iTop;

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

	cin >> N;

	for( i = 0; i < N; i++ )
	{
		cin >> t[ i ];

		t[ i ] *= 2;
	}

	A[ 0 ] = 0;
	for( i = 0; i < N; i++ )
	{
		cin >> v[ i ];

		v[ i ] *= 2;
		A[ i ] = min( A[ i ], v[ i ] );
		A[ i + 1 ] = min( A[ i ] + t[ i ], v[ i ] );
	}

	A[ N ] = 0;
	for( i = N - 1; i > 0; i-- )
		A[ i ] = min( A[ i ], A[ i + 1 ] + t[ i ] );

	iSum = 0;
	for( i = 0; i < N; i++ )
	{
		iTop = ( A[ i ] + t[ i ] + A[ i + 1 ] ) / 2;
		R = ( A[ i ] + t[ i ] - A[ i + 1 ] ) / 2;
		L = t[ i ] - R;
		iSum += L * ( A[ i ] * 2 + L ) + R * ( A[ i + 1 ] * 2 + R );
		if( iTop > v[ i ] )
		{
			iTop -= v[ i ];
			iSum -= iTop * iTop * 2;
		}
	}

	iSum /= 2;
	i = iSum % 4;
	if( i == 0 )
		cout << iSum / 4 << endl;
	else if( i == 1 )
		cout << iSum / 4 << ".25" << endl;
	else if( i == 2 )
		cout << iSum / 4 << ".5" << endl;
	else if( i == 3 )
		cout << iSum / 4 << ".75" << endl;

	return 0;
}




Measured memory_bytes: 256
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using INT=mp::cpp_int;
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
INT LCM(INT x,INT y){
  INT z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
INT modinv(INT a, INT m) {
    INT b = m, u = 1, v = 0;
    while (b) {
        INT t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main() {
  cout << fixed << setprecision(30);
  ll n;
  cin>>n;
  vec a(n);
  loop(i,n)cin>>a[i];
  ll sum=0;
  ll ans=1e18;
  Loop(i,-100,101){
    sum=0;
    ll center=i;
  loop(j,n){
    sum+=(a[j]-center)*(a[j]-center);
  }
    ans=min(ans,sum);
  }
  putout(ans);
}

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

int main(){ 
    int n;
    cin >> n;
    bool flag = false;
    
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
        if(n == i*j) flag = true;
        }
    }
    
    if(flag){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    
    return 0;
} 


Measured memory_bytes: 256
// --霊長類の暇つぶし競プロ
// --（飲んだくれ中 @ 飲み屋）
// -- 生中１杯目
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

typedef long long LL;
typedef unsigned int UI;

#define rSort(a) 		sort(a.rbegin(),a.rend())
#define Sort(a) 		sort(a.begin(),a.end())
#define Reverse(a) 		reverse(a.begin(),a.end())
#define Sum(a)  		accumulate(a.begin(), a.end(), 0)
#define REP(i, n) 		for(UI i = 0;i < n;i++)
#define REPR(i, n) 		for(UI i = n;i >= 0;i--)
#define FOR(i, m, n) 	for(UI i = m;i < n;i++)
#define pb(i) 			push_back(i)
#define SWAP(x,y) 		((x!=y)&&(x^=y,y^=x,x^=y))

#define MOD  			(LL)1e9 + 7;
#define INF  			(LL)1 << 62;

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

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

	string A, B, C;
	int state;
	int lengthA, lengthB, lengthC;
	int cntA, cntB, cntC;

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

	lengthA = A.size();
	lengthB = B.size();
	lengthC = C.size();

	cntA = 0;
	cntB = 0;
	cntC = 0;

	state = 0;

	while (lengthA >= cntA && lengthB >= cntB && lengthC >= cntC) {

		switch (state) {

		case 0:
			state = A[cntA] - 'a';
			cntA++;
			break;

		case 1:
			state = B[cntB] - 'a';
			cntB++;
			break;

		case 2:
			state = C[cntC] - 'a';
			cntC++;
			break;

		default:
			break;

		}

	}

	if (cntA > lengthA) {
		cout << "A" << endl;
	}
	else if (cntB > lengthB) {
		cout << "B" << endl;
	}
	else if (cntC > lengthC) {
		cout << "C" << endl;
	}

	return 0;
}



Measured memory_bytes: 256
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()
d = III()

ans = 0
for i in range(N):
    for j in range(i+1,N):
        ans += d[i]*d[j]

print(ans)

Measured memory_bytes: 39024
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

int main(int argc, char* argv[]) {
  int N, M;

  map<string, int> m;

  cin >> N;
  for (int i = 0; i < N; ++i) {
    string s;
    cin >> s;
    if (m.find(s) == m.end())
      m[s] = 0;
    ++m[s];
  }

  cin >> M;
  for (int i = 0; i < M; ++i) {
    string t;
    cin >> t;
    if (m.find(t) == m.end())
      m[t] = 0;
    --m[t];
  }

  int ret = 0;
  for (map<string, int>::iterator i = m.begin(); i != m.end(); ++i) {
    ret = max(ret, i->second);
  }

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

const int H = 300;
const int W = 300;

int main()
{
    int H, W;

    while (scanf("%d %d", &H, &W))
    {
        if (H == 0 && W == 0)
            break;
        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


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

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    
    int k,r=0;
    cin>>k;
    
    while(a>=b)
    {
        b*=2;
        r++;
    }
    while(b>=c)
    {
        c*=2;
        r++;
    }
    (r<=k)?cout<<"Yes\n":cout<<"No\n";
    return 0;
}

Measured memory_bytes: 3628
/// __Macro's__
// #pragma GCC optimize("-O2")
#include <bits/stdc++.h>
using namespace std;
#define ll                   long long
#define II                   pair<int,int>
#define III                  pair<int, II>
#define VL                   vector<ll>
#define VI                   vector<int>
#define VII                  vector<II>
#define VIII                 vector<III>
#define VVI                  vector<vector<int>>
#define VVII                 vector<vector<II>>
#define fr                   first
#define sc                   second
#define mkpr                 make_pair
#define PQ                   priority_queue
#define pb                   push_back
#define eb                   emplace_back
#define all(v)               v.begin(), v.end()
#define LINE                 putc('\n', stdout)
#define SPACE                putc(' ' , stdout)
#define TAB                  putc('\t', stdout)
#define fillarr(arr, val)    fill((int*)arr, (int*)arr+(sizeof(arr)/sizeof(int)), val)
#define Log2(x)              (31^__builtin_clz(x))
#define inf                  2000000007 
#define MOD                  1000000007 
#define getint ReadInt()
const char IO_MODE = 3; // in-->00<--out (MSB-->LSB) | 0: Norm, 1: Fast 
inline ll ReadInt(){ll x=0,s=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')s=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';
c=getchar();}return s*x;}inline void WriteInt(ll x){char c[20];if(!x){putchar('0');return;}if(x<0)putchar('-'),x=-x;int i=0;while(x>0)
c[++i]=x%10,x/=10;while(i)putchar(c[i--]+48);}template <typename T>inline void out(T x){if(IO_MODE&1)WriteInt(x);else if(typeid(x)==typeid(int))
printf("%i", x);else printf("%lld", (ll)x);}template<typename T, typename... Args>inline void out(T x,Args...args){out(x);SPACE;out(args...);}
template <typename T>inline void in(T &x){if(IO_MODE&2) x=ReadInt();else if(typeid(x)==typeid(int))scanf("%i",&x);else if(typeid(x)==typeid(ll))
scanf("%lld",&x);}template<typename T, typename... Args>inline void in(T &x,Args&...args){in(x);in(args...);}
int aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,mm,nn,oo,pp,qq,rr,ss,tt,uu,vv,ww,xx,yy,zz;
int tc;
///

#define nax 100100


int main()
{
  int a = getint;
  int b = getint;
  int have = 1;
  while(have<b)
  {
    have--;
    have+=a;
    tt++;
  }
  cout << tt << endl;
}

Measured memory_bytes: 256
#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<int, int>;

int gcd (int a, int b) 
{
	int v0 = a, v1 = b, v2 = a % b;
	while (v2 != 0) 
	{
		v0 = v1;
		v1 = v2;
		v2 = v0 % v1;
	};
	return v1;
}

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

	int	n;
	cin >> n;
	ll sum;
	sum = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			for (int k = 1; k <= n; k++)
			{
				sum += gcd(gcd(i, j), k);
			}
		}
	}
	cout << sum << endl;
}


Measured memory_bytes: 3636
a, b, c, d = map(int, input().split())

def gcd(x,y):
  while y:
    x, y = y, x%y
  return x
lcm = c*d // gcd(c,d)

cnt = lambda z: z - z//c - z//d + z//lcm
print(cnt(b)-cnt(a-1))

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    string N; cin >> N;
    if (N[0] == N[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    vector<int> num;
    int now=1;
    int cnt=0;
    rep(i,n){
      if(s[i]==(char)(now+'0')){
        cnt++;
      }else{
        num.push_back(cnt);
        now=1-now;
        cnt=1;
      }
    }
    if(cnt!=0) num.push_back(cnt);
    if(len(num)%2==0) num.push_back(0);
    int ans=0;
    vector<int> sum(len(num),0);
    sum[0]=num[0];
    FOR(i,1,len(num)){
      sum[i]+=sum[i-1]+num[i];
    }
    for(int i=0;i<len(num);i+=2){
      int right=i;
      int left=min(i+2*k,(int)len(num)-1);
      int check=0;
      if(i==0){
        check=sum[left];
      }else{
        check=sum[left]-sum[right-1];
      }
      ans=max(ans,check);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1272