akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
  int N, M, C;
  cin >> N >> M >> C;

  int B[25];
  for (int i = 0; i < M; ++i) {
    cin >> B[i];
  }

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    int n = 0;
    for (int j = 0; j < M; ++j) {
      int a;
      cin >> a;
      n += a * B[j];
    }
    if (n + C > 0) {
      ++ans;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;
typedef long long int ll;
int c[4][4];

int main()
{
    int i,j;
    for(i = 1;i <= 3;i++)
    {
        for(j = 1;j <= 3;j++)
        {
            scanf("%d",&c[i][j]);
        }
    }
    int t1 = c[2][1]-c[1][1],t2 = c[2][2]-c[1][2],t3 = c[2][3]-c[1][3];
    int r1 = c[3][1]-c[1][1],r2 = c[3][2]-c[1][2],r3 = c[3][3]-c[1][3];
    int f1 = c[3][1]-c[2][1],f2 = c[3][2]-c[2][2],f3 = c[3][3]-c[2][3];
    int flag = -1;
    if(t1 == t2 && t1 == t3 && r1 == r2 && r1 == r3 && f1 == f2 && f1 == f3)
    {
        if(r1-t1 == f1) flag = 1;
        else
        {
            flag = 0;
        }
        if(flag)
        {
            int t4 = c[1][2]-c[1][3],t5 = c[2][2]-c[2][3],t6 = c[3][2]-c[3][3];
            int r4 = c[1][1]-c[1][3],r5 = c[2][1]-c[2][3],r6 = c[3][1]-c[3][3];
            int f4 = c[1][1]-c[1][2],f5 = c[2][1]-c[2][2],f6 = c[3][1]-c[3][2];
            if(t4 == t5 && t4 == t6 && r4 == r5 && r4 == r6 && f4 == f5 && f4 == f6 && r4-t4 == f4)
            {
                flag = 1;
            }
            else flag = 0;
        }
    }
    else flag = 0;
    if(flag) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vll = vector<long long>;

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

  if(a + b + c > 21){
    cout << "bust" << endl;
  }
  else{
    cout << "win" << endl;
  }
}


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

#define FOR(i, a, b) for (int i = (a); i < static_cast<int>(b); i++)
#define FORR(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) FOR (i, 0, n)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
template <typename T>
void print(const vector<vector<T>> matrix);
template <typename T>
void print(const vector<T> vec);
template <typename Arg>
void print(const Arg arg);
template <typename Head, typename... Args>
void print(const Head head, const Args... args);
template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
using ll = long long;

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

    int a, b, x;
    cin >> a >> b >> x;

    if (x > a + b or x < a)
        print("NO");
    else
        print("YES");

    return 0;
}

//---------------------------------------------
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    repall (i, vec)
        cout << i << ' ';
    cout << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}


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


void solve(long long X, long long N, std::vector<long long> p){
    vector<pair<long long, long long> > a;
    for (long long i = 0; i <= 101; i++) {
        if (find(p.begin(), p.end(), i) == p.end()) {
            a.push_back(make_pair(abs(i - X), i));
        }
    }
    sort(a.begin(), a.end());

    cout << a[0].second << endl;
}

int main(){
    long long X;
    scanf("%lld",&X);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    solve(X, N, std::move(p));
    return 0;
}


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

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	vector<pair<int, int>> bc;
	for (int i = 0; i < M; i++) {
		int b, c;
		cin >> b >> c;
		bc.emplace_back(c, b);
	}
	sort(bc.rbegin(), bc.rend());
	for (int i = 0, j = 0; i < M && j < N; i++) {
		int cnt = bc[i].second, val = bc[i].first;
		while (j < N && A[j] < val && cnt--) A[j++] = val;
	}
	cout << accumulate(A.begin(), A.end(), 0LL) << endl;
	return 0;
}


Measured memory_bytes: 1784
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;

const int MAXN=1e5+5;
char a[MAXN];

int main()
{
	string str;
	while(cin>>str){
		int cnt;
		memset(a,0,sizeof(a));
		for(int i=0;i<str.size();i++){
			cnt=str[i]-'a';
			a[cnt]++;
		}
		for(int i=0;i<=25;i++){
			if (!a[i]){
				printf("%c\n",'a'+i);
				return 0;
			}
		}
		cout<<"None"<<endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, counter = 0;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++){
    if (A.at(i) % 2 == 0) A.at(i) /= 2;
    else break;
    if (i == N - 1){
      i = 0;
      counter++;
    }
  }
  cout << counter << endl;
}

Measured memory_bytes: 256
use proconio::input;

// 1箇所に1個: シュミレーションすればいい
// 1箇所に2個以上: AならBCだとだめ。それ以外ならOK。
// 2箇所以上: OK

#[derive(PartialEq, Eq, Clone, Copy)]
enum Query {
    AB,
    AC,
    BC,
}

impl Query {
    fn to_ints(&self) -> (usize, usize) {
        use Query::*;

        match self {
            AB => (A, B),
            AC => (A, C),
            BC => (B, C),
        }
    }

    fn intersection(x: Query, y: Query) -> usize {
        use Query::*;

        match (x, y) {
            (AB, AC) | (AC, AB) => A,
            (AB, BC) | (BC, AB) => B,
            (AC, BC) | (BC, AC) => C,
            _ => x.to_ints().0,
        }
    }
}

const A: usize = 0;
const B: usize = 1;
const C: usize = 2;

const YES: &str = "Yes";
const NO: &str = "No";

fn main() {
    input! {
        n: usize,
        a: i64,
        b: i64,
        c: i64,
        mut queries: [String; n],
    }

    queries.push("AB".into());

    let mut state = vec![a, b, c];
    let mut ans = vec![];
    for i in 0..n {
        // dbg!(&state);

        let q = parse_query(&queries[i]);
        let next_q = parse_query(&queries[i + 1]);
        let (choosed, other) = match choose(&state, q, next_q) {
            Some(v) => v,
            None => {
                println!("{}", NO);
                return;
            }
        };
        state[choosed] += 1;
        state[other] -= 1;
        ans.push(int_to_char(choosed));
    }

    // dbg!(&state);

    println!("{}", YES);
    for &c in &ans {
        println!("{}", c);
    }
}

fn parse_query(s: &str) -> Query {
    use Query::*;

    match s {
        "AB" => AB,
        "AC" => AC,
        _ => BC,
    }
}

fn int_to_char(x: usize) -> char {
    match x {
        0 => 'A',
        1 => 'B',
        _ => 'C',
    }
}

fn choose(state: &Vec<i64>, q: Query, next_q: Query) -> Option<(usize, usize)> {
    let (x, y) = q.to_ints();

    if state[x] == 0 && state[y] == 0 {
        return None;
    }

    // 選択肢がない場合
    if state[x] == 0 {
        return Some((x, y));
    }
    if state[y] == 0 {
        return Some((y, x));
    }

    // そうでないなら先読みする必要がある
    if next_q == q {
        // どっちでも
        return Some((x, y))
    }
    let is = Query::intersection(q, next_q);
    let other = if x == is { y } else { x };
    Some((is, other))
}


Measured memory_bytes: 8336
#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define float long double
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define g(t, n) get<n>(t)
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M = 1e6+5;

vi v[M];
int cnt[M];

vi primeFactors(int n)
{
    vi v;
    int flag = 0;
    while (n%2 == 0)
    {
        if(!flag) v.pb(2), flag++;
        n /= 2;
    }
    for(int i=3; i<=sqrt(n); i+=2)
    {
        flag = 0;
        while (n%i == 0)
        {
            if(!flag) v.pb(i), flag++;
            n = n/i;
        }
    }
    if (n > 2) v.pb(n);
    return v;
}

void solve()
{
	string s[3] = {"pairwise coprime", "setwise coprime", "not coprime"};
	int n, f1 = 0, f2 = 0;
	cin>>n;
	int a[n], g = 0;
	f(i, 0, n)
	{
		cin>>a[i];
		g = __gcd(g, a[i]);
	}
	f(i, 0, n) for(auto x : v[a[i]]) cnt[x]++;
	f(i, 0, M) if(cnt[i] > 1) f1++;
	if(g != 1) f2++;
	if(!f1 && !f2) cout<<s[0];
	else if(f1 && !f2) cout<<s[1];
	else if(f1 && f2) cout<<s[2];
}

int32_t main()
{
    IOS
    int t = 1;
    memset(cnt, 0, sizeof cnt);
    f(i, 1, M) v[i] = primeFactors(i);
    // cin>>t;
    f(tno, 1, t+1)
    {
        // cout<<"Case #"<<tno<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 85272
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define ll long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010
 
void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}

void swapl(ll* a,ll* b){ll tmp=*a;*a=*b;*b=tmp;}
ll absl(ll a){if(a<0)return -a;return a;}
ll dupl(ll a,ll d){if(a%d==0)return a/d;else return a/d+1;}
ll modl(ll a,ll m){if(a<0)return a%m+m;else return a%m;}

ll GCD(ll a,ll b){ll c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
ll LCM(ll a,ll b){return a*b/GCD(a,b);}

ll factorial(ll n, ll m) {return n < m ? 1 : n*factorial(n-1, m);}

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct 
{
    ll index;
    ll a;
} qwe;


int cmp_qwe(const void*a, const void*b){return ((qwe*)b)->a - ((qwe*)a)->a;}

ll dp[3000][3000];
qwe u[2000];

int main(){
  ll n, b, ans=0;
  ll a;

  scanf("%lld", &n);

  for (int i = 0; i < n; i++)
  {
      scanf("%lld", &a);
      u[i].index = i;
      u[i].a = a;
  }
  
  qsort(u, n, sizeof(qwe), cmp_qwe);

  dp[0][0] = 0;
  for (int i = 0; i < n; i++)
  {
      for (int j = 0; i + j + 1 <= n; j++)
      {
        //   if (i == 0 && j==0) break;
        //   if (i == 0) dp[i][j] =  
        //   dp[i][j] = MAX(dp[i-1][j] + u[i+j].a * (u[i+j].index - i), dp[i][j-1] + u[i+j].a * (n - j - u[i+j].index) );
        dp[i+1][j] = MAX(dp[i+1][j], dp[i][j] + u[i+j].a * (u[i+j].index - i));
        dp[i][j+1] = MAX(dp[i][j+1], dp[i][j] + u[i+j].a * (n - 1 - j - u[i+j].index) );
      }
  }
  for (int i = 0; i <= n; i++)
  {
      ans = MAX(ans, dp[i][n-i]);
  }
  printf("%lld", ans);
  
  return 0;
}

Measured memory_bytes: 25364
#include<stdio.h>

int main(void)


{


 int n, i, ai, min, max;


 long sum;

 sum=0;


 min=1000000;


 max=-1000000;


 scanf("%d",&n);


 for(i=1; i<=n; i++){


  scanf("%d",&ai);


  sum+=ai;


  if(min>ai){


   min=ai;


   }


  if(max<ai){


   max=ai;


  }


 }


 printf("%d %d %lld\n",min, max, sum);


 return 0;


}

Measured memory_bytes: 600
#include <iostream>
#include <cstring>
using namespace std;

pair<int,int> dp[33][33][33][33];
int in[33][33];
int sum[33][33];
int h,w,s,whs;

int f() {
  int ts;
  for(int i=0; i<h; ++i) {
    ts = 0;
    for(int j=0; j<w; ++j) {
      ts += in[i][j];
      sum[i][j] = ts;
    }
  }

  for(int i=0; i<w; ++i) {
    ts = 0;
    for(int j=0; j<h; ++j) {
      ts += sum[j][i];
      sum[j][i] = ts;
    }
  }

  // for(int i=0; i<h; ++i) {
  //   for(int j=0; j<w; ++j)
  //     cout<<sum[i][j]<<" ";
  //   cout<<endl;
  // }

}

int sumsq(int ux,int uy,int dx,int dy) {
  return sum[dy][dx] - (uy==0?0:sum[uy-1][dx])
    - (ux==0?0:sum[dy][ux-1]) + ((uy==0||ux==0)?0:sum[uy-1][ux-1]);
}

pair<int,int> maxx(pair<int,int> p,pair<int,int> q) {
  if(p.first > q.first) return p;
  if(q.first > p.first) return q;
  if(p.second > q.second) return p;
  return q;
}

pair<int,int> f(pair<int,int> p,pair<int,int> q) {
  return make_pair(p.first+q.first, min(p.second,q.second));
}

pair<int,int> rec(int ux,int uy,int dx,int dy) {
  //  cout<<ux<<" "<<uy<<" "<<dx<<" "<<dy<<" "<<sumsq(ux,uy,dx,dy)<<endl;
  if(dp[ux][uy][dx][dy] != make_pair(-1,-1)) return dp[ux][uy][dx][dy];
  if(whs - sumsq(ux,uy,dx,dy) > s) return make_pair(-1,0);

  pair<int,int> ret = make_pair(0,0);
  for(int i=ux; i<dx; ++i) {
    pair<int,int> t1 = rec(ux,uy,i,dy);
    pair<int,int> t2 = rec(i+1,uy,dx,dy);
    if(t1.first == -1 || t2.first == -1) continue;
    ret = maxx(ret,f(t1,t2));
  }

  for(int i=uy; i<dy; ++i) {
    pair<int,int> t1 = rec(ux,uy,dx,i),t2 = rec(ux,i+1,dx,dy);
    if(t1.first == -1 || t2.first == -1) continue;
    ret = maxx(ret,f(t1,t2));
  }

  if(ret == make_pair(0,0)) {
    //    cout<<"! "<<ux<<" "<<uy<<" "<<dx<<" "<<dy<<" "<<1<<" "<<s - (whs - sumsq(ux,uy,dx,dy))<<endl;
    return dp[ux][uy][dx][dy] = make_pair(1,s - (whs - sumsq(ux,uy,dx,dy)));
  }
  //  cout<<ux<<" "<<uy<<" "<<dx<<" "<<dy<<" "<<ret.first<<" "<<ret.second<<endl;
  return dp[ux][uy][dx][dy] = ret;
}

int main() {
  while(cin>>h>>w>>s, h|w|s) {
    for(int i=0; i<33; ++i)
      for(int j=0; j<33; ++j)
        for(int k=0; k<33; ++k)
          for(int l=0; l<33; ++l)
            dp[i][j][k][l] = make_pair(-1,-1);

    memset(in, -1, sizeof(in));
    for(int i=0; i<h; ++i)
      for(int j=0; j<w; ++j)
        cin>>in[i][j];
    memset(sum, 0, sizeof(sum));
    f();
    whs = sum[h-1][w-1];
    pair<int,int> p = rec(0,0,w-1,h-1);
    cout<<p.first<<" "<<p.second<<endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <regex>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)++)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

template <class... T>
void output__(T ...a) {
  for(auto v: {a...}) {
    cout << v << " ";
  }
  cout << endl;
}

int main(){
  string in(s);
  if((s[0] == s[1] and s[1] == s[2]) or (s[1] == s[2] and s[2] == s[3]))
    out("Yes") else out("No");
}


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

int n,k,d[11];
signed main(){
  cin>>n>>k;
  rep(i,k)cin>>d[i];
  bool flag=true;
  for(int i=n;i<=999999;i++){
    flag=true;
    string s=to_string(i);
    for(int j=0;j<s.size();j++){
      for(int l=0;l<k;l++){
        if(d[l]==s[j]-'0'){
          flag=false;
          break;
        }
      }
    }

    if(flag){
      cout<<i<<endl;
      return 0;
    }
  }

  return 0;
}


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

int main() {
  long long N,A,B;
  cin >>N>>A>>B;
  if(A > 0){
  long long aa = (N/(A+B))*A;
  long long rest=N-(aa/A)*(A+B);
  if(rest >= A) aa += A;
  else aa += rest;
  cout << aa << endl;
  }
  else cout << 0 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    map<int,int> m;
    rep(i,n) {
        int a;
        cin >> a;
        m[a]++;
    }
    int ans = 0;
    for(auto p : m) {
        if(p.second >= p.first) ans += p.second-p.first;
        else ans += p.second;
    }
    cout << ans << endl;
}

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

const int MAXN = 105, mod = 998244353;

char str[MAXN];

int n;

unordered_map<string, int> dp;

vector<int> v[MAXN];

int dfs(const string &str)
{
	if (str.length() == 0) return 1;
	if (str.length() == 1) return str[0]-'0'+1;
	if (dp.count(str)) return dp[str];
	dp[str] = 0;
	int len = str.length(), ans = dfs(str.substr(1, len-1))*(str[0]-'0'+1)%mod;
	string tmp;
	for (register int i = 1; i <= len; i++) {
		for (auto j : v[i]) {
			tmp = "";
			for (register int k = 0; k < j; k++) {
				char cur = 1;
				for (register int w = 0; w < i; w += j)
					cur &= (str[w+k]-'0');
				tmp += cur+'0';
			}
			ans = (ans+(long long)dfs(tmp)*(i == len ? 1 : dfs(str.substr(i, len-i)))) % mod;
		}
	}
	return dp[str] = ans;
}

int main()
{
	string str;
	cin >> str;
	n = str.length();
	for (int i = 1; i <= n; i++)
		for (int j = i*2; j <= n; j += i)
			v[j].push_back(i);
	cout << dfs(str) << endl;
        return 0;
}


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int n, f= 0;
    cin>> n;
    string s, p;
    set < string > uni;

    cin>> p;
    uni.insert(p);
    for(int i=1; i<n; i++)
    {
        cin>> s;
        uni.insert(s);

        if (s[0]!= p[p.size()-1])
            f= -1;

        p= s;
    }


    if( f== -1 || uni.size()!= n)
        cout << "No\n";
    else
        cout << "Yes\n";

    return 0;
}




Measured memory_bytes: 3664
h,w,k=map(int,input().split())
s=[input() for _ in range(h)]
ans=[]
c=1
for si in s:
  ans.append([c]*w)
  c+=si.count('#')
ans.append([c]*w)
p=0
q=1
while q<=h:
  if ans[q][0]-ans[p][0]>=1:
    c=ans[p][0]
    for j in range(w):
      for i in range(p,q):
        ans[i][j]=c
        if s[i][j]=='#':
          c=min(c+1,ans[q][0]-1)
    p=q
    if ans[q-1][-1]==k:
      while q<h:
        ans[q]=ans[q-1]
        q+=1
  q+=1
for a in ans[:-1]:
  print(*a)

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

using namespace std;

int main()
{
    long long a,b,c;
    cin>>a>>b>>c;
    vector<int>v;
	for(int i=1;i<=min(a,b);i++)
	{
		if(a%i==0 && b%i==0)
		{
			v.push_back(i);
		}
	} 
	sort(v.begin(),v.end());
	cout<<v[v.size()-c]<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;

class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
double weight;
while((line=br.readLine())!=null){
weight=Double.parseDouble(line);
classOfBoxing(weight);
}
}
private static void classOfBoxing(double n){
if(n<=48.00){
System.out.println("light fly");
}
else if(n<=51.00){
System.out.println("fly");
}
else if(n<=54.00){
System.out.println("bantam");
}
else if(n<=57.00){
System.out.println("feather");
}
else if(n<=60.00){
System.out.println("light");
}
else if(n<=64.00){
System.out.println("light welter");
}
else if(n<=69.00){
System.out.println("welter");
}
else if(n<=75.00){
System.out.println("light middle");
}
else if(n<=81.00){
System.out.println("middle");
}
else if(n<=91.00){
System.out.println("light heavy");
}
else{
System.out.println("heavy");
}
}
}

Measured memory_bytes: 15064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		long A = scn.nextInt(), B = scn.nextInt();
		long gcd = gcd(A,B);
		System.out.println(A/gcd*B);
	}
	public static long gcd(long a,long b) {
		while(a%b!=0) {
			long buf = a%b;
			a = b;
			b = buf;
		}
		return b;
	}
}


Measured memory_bytes: 23764
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	int n, t;
	cin >> n >> t;
	vector<int>hotWater(n);
	rep(i, n)cin >> hotWater[i];
	ll waterTime = 0;
	rep(i, n - 1) {
		if ((hotWater[i + 1] - hotWater[i]) > t)waterTime += t;
		else waterTime += (hotWater[i + 1] - hotWater[i]);
	}
	cout << waterTime + t << endl;
	return 0;
}


Measured memory_bytes: 3972
val factorial = mutableListOf<Long>()
val inverse = mutableListOf<Long>()
val factorialInverse = mutableListOf<Long>()

fun main(args: Array<String>) {
    val mod = 1000000007L

    val (n, k) = readInputLine().split(" ").map { it.toInt() }

    // まず1～nの階乗、逆元を求める
    factorial.add(1L)
    factorial.add(1L)
    inverse.add(1L)
    inverse.add(1L)
    factorialInverse.add(1L)
    factorialInverse.add(1L)
    for (i in 2..n) {
        factorial.add(factorial[i - 1] * i.toLong() % mod)
        inverse.add(mod - inverse[mod.toInt() % i] * (mod / i.toLong()) % mod)
        factorialInverse.add(factorialInverse[i - 1] * inverse[i] % mod)
    }
    
    for (i in 1..k) {
        if (n - k - i + 1 < 0) {
            println(0)
            continue
        }
    
        // 赤いボール総数: n - k
        // 青いボール総数: k
        
        // まず、青いボールを並べる並べ方を求める
        // (k - i)個の青いボールと(i - 1)個の仕切りを並べる順列(i個のブロックには必ず1個青いボールがある必要があるため)
        // (k - i + i - 1)! / (k - i)! / (i - 1)! = (k - 1)! / (k - i)! / (i - 1)!
        val blueNum = factorial[k - 1] * (factorialInverse[k - i] * factorialInverse[i - 1] % mod) % mod
        
        // 次に、赤いボールを並べる並べ方を求める
        // (n - k - (i - 1)) = (n - k - i + 1)個の赤いボールとi個の仕切りを並べる順列(i個のブロックの間には必ず赤いボールがある必要があるため)
        // (n - k - i + 1 + i)! / (n - k - i + 1)! / i! = (n - k + 1)! / (n - k - i + 1)! / i!
        val redNum = factorial[n - k + 1] * (factorialInverse[n - k - i + 1] * factorialInverse[i] % mod) % mod
        
        // 答え出力
        println("${blueNum * redNum % mod}")
    }
}
 
fun readInputLine(): String {
    return readLine()!!
}


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

int main(){
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < 4; i++){
        if(s[i] == '+'){
            ans++;
        }else{
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 1
for aa in a:
    ans *= aa
    if ans == 0:
        print(0)
        exit()
    elif ans > 10**18:
        print(-1)
        exit()

print(ans)


Measured memory_bytes: 21608
#include<iostream>
#include<list>
using namespace std;
int main(){
	int n,q;
	cin>>n>>q;
	list<int>l[n];
	while(q--){
		int command, t;
		cin>>command>>t;
		if(command==0){
			int x;
			cin>>x;
			l[t].push_back(x);
		}
		else if(command==1){
			if(!l[t].empty()){
				list<int>::iterator i=l[t].begin();
				cout<<*i;
				i++;
				for(; i!=l[t].end(); i++){
					cout<<" "<<*i;
				}
				cout<<endl;
			}
			else	cout<<endl;
		}
		else if(command==2){
			int s;
			cin>>s;
			l[s].splice(l[s].end(), l[t]);
		}
	}
	return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

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

const int N = 12;

int p[N], n, m;
vector<int> b[N];

bool check(int s) {
  for (int i = 0; i < m; ++i) {
    int count = 0;
    for (int e: b[i]) {
      if (s & (1 << e)) count = !count;
    }
    if (count != p[i]) return false;
  }
  return true;
}

void solve() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int k; scanf("%d", &k);
    for (int j = 0; j < k; ++j) {
      int s; scanf("%d", &s);
      b[i].push_back(--s);
    }
  }
  for (int i = 0; i < m; ++i) {
    scanf("%d", p+i);
  }
  int ans = 0;
  for (int s = 0; s < (1 << n); ++s) {
    if (check(s)) ++ans;
  }
  printf("%d", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template<class G>
class SWAG {
    using T = typename G::T;
    vector<T> in, out, insum, outsum;
public:
    SWAG() : in(0), out(0), insum(1, G::e()), outsum(1, G::e()) {}

    void push(const T& v){
        insum.push_back(G::f(insum.back(), v));
        in.push_back(v);
    }

    void pop(){
        if(out.empty()){
            do {
                out.emplace_back(in.back());
                outsum.emplace_back(G::f(in.back(), outsum.back()));
                in.pop_back(); insum.pop_back();
            }while(!in.empty());
        }
        out.pop_back(); outsum.pop_back();
    }

    T fold(){
        return G::f(outsum.back(), insum.back());
    }
};

struct Monoid {
    using T = int;
    static T f(T a, T b) { return min(a, b); }
    static T e() { return INF<int>; }
};


int main() {
    int n, l;
    cin >> n >> l;
    SWAG<Monoid> Q;
    for (int i = 0; i < n; ++i) {
        int x;
        scanf("%d", &x);
        Q.push(x);
        if(i >= l-1) {
            if(i != l-1) printf(" ");
            printf("%d", Q.fold());
            Q.pop();
        }
    }
    puts("");
    return 0;
}


Measured memory_bytes: 4796
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, ga, sa, ba, gb, sb, bb;
    cin >> n >> ga >> sa >> ba >> gb >> sb >> bb;
    ll ma = 0;
    for(ll i = 0; i <= n / ga; i++) {
        ll s = n - i * ga;
        for(ll j = 0; j <= s / sa; j++) {
            ll k = (s - j * sa) / ba;
            chmax(ma, (gb - ga) * i + (sb - sa) * j + (bb - ba) * k);
        }
    }
    n += ma;
    vector<ll> dp(n + 10, -LINF);
    dp[0] = 0;
    ma = 0;
    for(int i = 1; i <= n; i++) {
        if(i >= gb) {
            chmax(dp[i], dp[i - gb] + ga - gb);
        }
        if(i >= sb) {
            chmax(dp[i], dp[i - sb] + sa - sb);
        }
        if(i >= bb) {
            chmax(dp[i], dp[i - bb] + ba - bb);
        }
        chmax(ma, dp[i]);
    }
    cout << n + ma << endl;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    copy_n(istream_iterator<int>(cin), n, A.begin());
    vector<map<int, int>> C(2);
    for (int j = 0; j < 2; j++){
        for (int i = j; i < n; i += 2)
            C[j][A[i]]++;
    }
    vector<vector<pair<int, int>>> ma(2);
    for (int i = 0; i < 2; i++){
        ma[i] = vector<pair<int, int>>(C[i].begin(), C[i].end());
        nth_element(ma[i].begin(), ma[i].begin() + 1, ma[i].end(), [](auto &l, auto &r){return l.second > r.second;});
        ma[i].push_back({0, 0});
    }
    if (ma[0][0].first != ma[1][0].first){    
        cout << n - ma[0][0].second - ma[1][0].second << endl;
        return 0;
    }
        
    cout << n - max(ma[0][0].second + ma[1][1].second, ma[0][1].second + ma[1][0].second) << endl;
}


Measured memory_bytes: 6520
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <cwchar>
using ll = long long;

//LLONG_MAX
//#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int N, M;

struct St
{
	int Y;
	int P;
	int I;

	bool operator < (const St &st) const
	{
		return (Y < st.Y);
	}
};

vector<St> v;

int cnt[100011];
char ans[100011][20];

signed main()
{
	cin >> N >> M;
	REP(i, M)
	{
		St st;
		cin >> st.P >> st.Y;
		st.I = i;
		v.push_back(st);
	}

	SORT(v);

	for (St& st : v)
	{
		cnt[st.P]++;
		sprintf(ans[st.I], "%06d%06d", st.P, cnt[st.P]);
		
	}

	for (int i = 0; i < M; i++)
	{
		cout << ans[i] << endl;
	}
}








Measured memory_bytes: 5108
from itertools import accumulate
import bisect

n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
cumsum = [0]+list(accumulate(a))
ans = 10 ** 18
for d in range(2,n-1):
  f_sum = cumsum[d]
  l_sum = cumsum[n]-cumsum[d]
  c = bisect.bisect_right(cumsum, f_sum//2)
  e = bisect.bisect_right(cumsum, f_sum+l_sum//2)
  for i in [c,c+1]:
    p = cumsum[i-1]
    q = f_sum - p
    if p and q:
      for j in [e,e+1]:
        r = cumsum[j-1] - f_sum
        s = l_sum - r
        if r and s:
          sums = [p,q,r,s]
          ans = min(ans,max(sums)-min(sums))
print(ans)

Measured memory_bytes: 24300
def cmb(n,r,mod):
    r=min(r,n-r)
    if r==0:
        return 1
    elif r<0:
        return 0
    else:
        X=1
        Y=1
        for i in range(r):
            X*=n-i
            X%=mod
            Y*=i+1
            Y%=mod
        Y=pow(Y,mod-2,mod)
        X*=Y
        return X%mod

if __name__ == "__main__":
    X,Y=map(int,input().split())
    if (2*Y-X)%3!=0 or (2*X-Y)%3!=0:
        print(0)
    else:
        xd=(2*X-Y)//3
        yd=(2*Y-X)//3
        print(cmb(xd+yd,yd,10**9+7))

Measured memory_bytes: 3064
#import<iostream>
#define l long
l N,M,c,n=1,i=2,o=1e9+7;l m(l a){l g=1,h=2*o-4;while(h/=2){h&1?g=g*a%o:0;a=a*a%o;}return g;}l C(l b){l r=1,d=1;for(;b;--b)r=r*(N-1+b)%o,d=d*b%o;return r*m(d)%o;}main(){for(std::cin>>N>>M;i*i<=M;++i){c=0;while(M%i<1)++c,M/=i;n=n*C(c)%o;}std::cout<<n*(M^1?N:1)%o<<std::endl;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
string s,t;
int main()
{
	cin>>s>>t;
	for(int i=s.size()-1;i>-1;i--)
	{
		string tmp="";
		for(int j=i+1;j<s.size();j++)
		{
			tmp+=s[j];
		}
		for(int j=0;j<=i;j++)
		{
			tmp+=s[j];
		}
		if(tmp==t)
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	long long int n,m;
	
	cin >> n >> m;
	cout << abs((n - 2)*(m - 2)) << endl;

	return 0;

}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  int ans = 0;
  rep(i, n){
    int a;
    cin >> a;
    ans += a - 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int a[3];
	string ans;
	
	cin >> a[0] >> a[1] >> a[2];
	
	sort(a, a+3);
	
	if(a[0]+a[1]==a[2])
		ans="Yes";
	else
		ans="No";
	
	cout << ans << endl;
	return 0;
}

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

int main(){
  long long N;
  cin >> N;
  vector<long long> A(N);
  const int M = 1e6+1;
  vector<long long> C(M);
  for(int i = 0; i < N; ++i) cin >> A[i], ++C[A[i]];
  long long ans = 0;
  vector<bool> F(M,true);
  for(int i = 1; i < M; ++i){
    if(!C[i]) continue;
    if(F[i] and C[i] == 1) ++ans;
    // cerr << i << endl;
    for(int j = 2; j*i < M; ++j){
      F[i*j] = false;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 12764
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int main(void) {
    
    

    int n,m;
    cin>>n>>m;
    vvi v(n);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        v[a-1].pb(b-1);
        v[b-1].pb(a-1);
    }
    rep(i,n)cout<<v[i].size()<<endl;
}


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

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

    for(int i=0; i<N; i++){
        ll isans=(ll)C;
        for(int j=0; j<M; j++){
            isans += (ll)A[i][j]*B[j];
        }
        if(isans>0)ans++;
    }

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


Measured memory_bytes: 256
a = input()
a = a.split(' ')
A = eval(a[0])
B = eval(a[1])
k = 0
for i in range(A, B + 1, 1):
    l = str(i)
    ok = False
    for j in range(len(l) // 2):
        if l[j] != l[len(l) - 1 - j]:
            ok = True
            break
    if not ok:
        k = k + 1
print(k)

Measured memory_bytes: 3060
import java.io.*;
import java.util.Arrays;
public class Main {

	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try {
			String line = reader.readLine();
			
			char d[] = line.toCharArray();
			long []chars = new long[26];
 			
			long sum = 0;
			long len = line.length();
			for(char c : d) {
			         chars[c-'a']++;
			}
			sum = len*(len-1)/2;
			for(long x :chars)
			{
				if(x > 1) {
					sum -= x*(x-1)/2;
				}
			}
			System.out.println(sum+1);
			
		}catch(IOException e) {
			System.out.println(e);
		}
	}
}


Measured memory_bytes: 26068
#include <iostream>

using namespace std;

void replaceAll(string &str,const string from,const string to){
  string::size_type pos = 0;
  while((pos=str.find(from))!= string::npos)
    {
      str.replace(pos,from.size(),to);
    }
}
int main(){
  int n;
  cin >> n;
  string line;
  getline(cin , line);
  while(n--){
    getline(cin, line);
    replaceAll(line, "Hoshino","Hoshina");
    cout << line << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cstdlib>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define ii pair<int, int>
#define vi vector<int>
typedef long long LL;
typedef unsigned long long ULL;
const int N = 111111;
const int inf = 1e9+10;
const LL INF = 1e18 + 10;

vector<LL> a;

int main(){
	int n;
	cin>>n;
	LL x;
	for(int i=0;i<n;i++){cin>>x;a.pb(x);}
	vector<LL> d(n, 0), s(n, 0);
	d[0] = a[0];s[n-1] = a[n - 1];
	for(int i=1;i<n;i++)d[i] = d[i-1] + a[i];
	for(int i=n-2;i>=0;i--)s[i] = s[i + 1] + a[i];
	LL ans = INF;
	for(int i=0;i<n - 1;i++){
		ans = min(ans, abs(d[i] - s[i + 1]));
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5104
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

int n,d,m,g;
int a[30][10];

bool solve(){
  int x=m-1;
  rep(i,d){
    if(x>0&&a[i][x-1])x--;
    else if(x<n-1&&a[i][x])x++;
  }
  return x==g-1;
}

void run(){
  while(cin>>n,n){
    cin>>m>>g>>d;
    MEMSET(a);
    char c;
    rep(i,d){
      rep(j,n-1){
	cin>>c;
	a[i][j]=c-'0';
      }
    }
    if(solve()){
      cout<<0<<endl;
      continue;
    }
    rep(i,d){
      rep(j,n-1){
	if(a[i][j])continue;
	if(j>0&&a[i][j-1])continue;
	if(j<n-1&&a[i][j+1])continue;
	a[i][j]=1;
	if(solve()){
	  cout<<(i+1)<<" "<<(j+1)<<endl;
	  goto BR;
	}
	a[i][j]=0;
      }
    }
    cout<<1<<endl;
  BR:;
  }
}



Measured memory_bytes: 3188
#include<stdio.h>

int main(){
  int n,i;
  scanf("%d",&n);
  int h[n];
  for(i=0;i<n;i++){
    scanf("%d",&h[i]);
  }
  int j,key;
  for(j=0;j<n;j++){
    key = h[j];
    i = j-1;
    while(i>=0&&h[i]>key){
      h[i+1]=h[i];
      i--;
    }
    h[i+1]=key;
    for(i=0;i<n;i++){
      if(i!=n-1)printf("%d ",h[i]);
      else printf("%d\n",h[i]);
  }
  }
  return 0;
}



Measured memory_bytes: 2084
n = int(input())
ac,tle,wa,re = 0,0,0,0
for i in range(n):
    s = input()
    if s == "AC":
        ac+=1
    elif s == "TLE":
        tle+=1
    elif s == "WA":
        wa+=1
    elif s == "RE":
        re+=1
print("AC x {a}\nWA x {b}\nTLE x {c}\nRE x {d}".format(a = ac,b = wa, c = tle, d = re))



Measured memory_bytes: 9192
using System;

namespace Question1
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = new Program();
            p.Run();
        }

        void Run(){
            var s = Console.ReadLine();
            var containsA = s.Contains("A");
            var containsB = s.Contains("B");

            var result = ( containsA && containsB ) ? "Yes" : "No";

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13140
import scala.io.{StdIn => in}

object Main extends App {
  val s = in.readLine.map(ch => if(ch=='0') false else true).toList
  val n0 = s.count(_==false)
  val n1 = s.count(_==true)
  val ans = s.size - (n1 - n0).abs
  println(ans)
}

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

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }



int main(){
    LL n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    reverse(s.begin(), s.end());

    if(p == 2 || p == 5){
        LL ans = 0;
        for(LL i = 0; i < n; ++i){
            if((s[i] - '0') % p == 0){
                ans += n - i;
            }
        }
        cout << ans << endl;
        return 0;
    }

    vector<LL> count(p);
    count[0] += 1;
    LL cur = 0;
    LL val = 1;
    for(LL i = 0; i < n; ++i){
        cur = (cur + val * (s[i] - '0')) % p;
        val = (val * 10) % p;
        count[cur] += 1;
    }

    LL ans = 0;
    for(LL i = 0; i < p; ++i){
        ans += count[i] * (count[i]-1) / 2;
    }

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



Measured memory_bytes: 640
#include<queue>
#include<cstdio>
#include<cstdlib>
const int N=1e5+6;
using namespace std;
struct data{
	int u,d;
	inline bool operator<(const data&rhs)const{return d>rhs.d;}
};
priority_queue<data>q;
int n,k,w[N];
bool vis[N];
vector<int>G[N];
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;++i){
		int u,v;
		scanf("%d%d",&u,&v);
		G[u].push_back(v),G[v].push_back(u);
	}
	scanf("%d",&k);
	if(!k)vis[1]=1,w[1]=11414,q.push((data){1,114514});
	while(k--){
		int u,v;
		scanf("%d%d",&u,&v),w[u]=v,vis[u]=1;
		q.push((data){u,v});
	}
	while(!q.empty()){
		int u=q.top().u;q.pop();
		for(int to:G[u])if(!vis[to])vis[to]=1,w[to]=w[u]+1,q.push((data){to,w[to]});else
		if(abs(w[to]-w[u])!=1)return puts("No"),0;
	}
	puts("Yes");
	for(int i=1;i<=n;++i)printf("%d\n",w[i]);
	return 0;
}

Measured memory_bytes: 7924
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <queue>

using namespace std;

long long x,R;

int main()
{
    cin>>x;
    R+=(x/500)*1000;
    x%=500;
    R+=(x/5)*5;
    cout<<R<<endl;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

def viol(c2, c3, l, x):
    res = False
    if x == 1:
        if not c2 < l:
            res = True
    elif x == 2:
        if not c3 < l <= c2:
            res = True
    else:
        if not l <= c3:
            res = True
    return res
MOD = 10**9+7
N, M = map(int, readline().split())
limit = [[] for _ in range(N+3)]

for _ in range(M):
    l, r, x = map(int, readline().split())
    limit[r+2].append((l+2, x))

dp = [[0, 0], [1, 0]]

for i in range(2, N+2):    
    dp2 = [[0]*(i+1) for _ in range(i+1)]
    r = i
    for g in range(r):
        for b in range(g):
            d = dp[g][b]
            dp2[g][b] = (dp2[g][b] + d)%MOD
            dp2[r][b] = (dp2[r][b] + d)%MOD
            dp2[r][g] = (dp2[r][g] + d)%MOD
    for l, x in limit[i+1]:
        r = i+1
        for g in range(r):
            for b in range(g):
                if viol(g, b, l, x):
                    dp2[g][b] = 0
    dp = [d[:] for d in dp2]
    
res = 0
for g in range(N+2):
    for b in range(g):
        res = (res + dp[g][b]) % MOD
print(res)

Measured memory_bytes: 89948
#include <stdio.h>

int main(void){
    int n;
    int i,sum;
    int maxl = 0;
    scanf("%d",&n);
    int a[100];        //何故かa[n]にしたら上手くいかない
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for (i=0;i<n;i++){
        if (a[i]>maxl){
            maxl = a[i];
        }
    }
    for (i=0;i<n;i++){
        sum += a[i];
    }
    // printf("%d\n",sum);
    if (maxl<sum-maxl){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128