akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

struct node{
	int now, dis, col;
};
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int a, b, c;
    vector<vector<int> > v(n);
    for(int i=0;i<m;i++){
    	cin >> a >> b;
    	a--;b--;
    	v[a].pb(b);
    	v[b].pb(a);
    }
    vector<int> used(n, -1), ans(n, 0);
    int q;
    cin >> q;
    vector<node> query(q);
    for(int i=0;i<q;i++){
    	cin >> a >> b >> c;
    	query[i] = {a - 1, b, c};
    }
    while(q--){
    	c = query[q].col;
    	queue<pair<int,int> > que;
    	que.push({query[q].now, query[q].dis});
    	while(!que.empty()){
    		int e = que.front().first;
    		int d = que.front().second;
    		que.pop();
    		if(d <= used[e]) continue;
    		used[e] = d;
    		if(ans[e] == 0) ans[e] = c;
    		for(auto& to: v[e]){
    			que.push({to, d - 1});
    		}
    	}
    }
    for(auto& i: ans) cout << i << endl;
    return 0;
}


Measured memory_bytes: 8988
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a > b){
		printf("a > b\n");
	}else if(a < b){
		printf("a < b\n");
	}else{
		printf("a == b\n");
	}
}



Measured memory_bytes: 2696
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef tuple<int, int, int> tiii;



int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	int a, b;
	cin >> a >> b;
	cout << max(0, a - b * 2);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<typename VAL>
struct SegT{
  using CAL = function<VAL(VAL, VAL)>;
  int len; vector<VAL> seg; const CAL f; const VAL u;
  SegT(int n, const CAL f, const VAL &u) : f(f), u(u) {
    for(len=1; len<n; ){ len<<=1; }
    seg.assign(2*len, u);
  }
  void set(int k, const VAL &x){ seg[len+k]=x; }
  void bld(){ for(int k=len-1; k>0; k--){ seg[k]=f(seg[2*k], seg[2*k+1]); } }
  void upd(int k, const VAL &x){
    k+=len; seg[k]=x;
    while(k>>=1){ seg[k]=f(seg[2*k], seg[2*k+1]); }
  }
  VAL que(int a, int b){
    VAL L=u, R=u;
    for(a+=len, b+=len; a<b; a>>=1, b>>=1){
      if(a&1) L=f(L, seg[a++]);
      if(b&1) R=f(seg[--b], R);
    }
    return f(L, R);
  }
};
int gcd(int a, int b){ if(b){ return gcd(b, a%b); }else{ return a; } }
int main(){
  int N, i; cin >> N; SegT<int> T(N, gcd, 0);
  for(i=0; i<N; i++){ int a; cin >> a; T.set(i, a); }
  T.bld();
  int ans=max(T.que(1, N), T.que(0, N-1));
  for(i=1; i<N-1; i++){ ans=max(ans, gcd(T.que(0, i), T.que(i+1, N))); } 
  cout << ans << "\n";
}

Measured memory_bytes: 1280
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>

using namespace std;
vector<int> v[101];
int d[101] = {0};
int f[101] = {0};
int t = 0;
void dfs(int id) {
    //d mark
    d[id] = t;
    t++;
    for(int adj: v[id]) {
        if(d[adj] == 0) {
            dfs(adj);
            t++;
        }
    }
    f[id] = t;
}

int main() {
    int n;
    cin >> n;
    for(int i=1; i<=n; i++) {
        int u, k;
        cin >> u >> k;
        for(int j=0; j<k; j++) {
            int adj;
            cin >> adj;
            v[i].push_back(adj);
        }
    }
    for(int i=1; i<=n; i++) {
        if(d[i] == 0) {
            t++;
            dfs(i);
        }
    }

    for(int i=1; i<=n; i++) {
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
}



Measured memory_bytes: 3152
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n;
  string s;
  cin>>n>>s;
  int cnt=0;
  for(int i=0;i<n-2;i++){
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') cnt++;
  }
  cout << cnt<<endl;
}


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

using namespace std;

const int MAXN = 1E5;
int dp[MAXN];
int h[MAXN];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> h[i];
    dp[1] = abs(h[0] - h[1]);
    for (int i = 2; i < n; i++)
    {
        dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
    }
    cout << dp[n - 1] << endl;
    return 0;
}


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

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

template <typename T, typename U>
bool chmin(T &a, const U &b){
  return (a > b ? a = b, true : false);
}

template <typename T, typename U>
bool chmax(T &a, const U &b){
  return (a < b ? a = b, true : false);
}

template <typename T, size_t N, typename U>
void fill_array(T (&a)[N], const U &v){
  std::fill((U*)a, (U*)(a + N), v);
}

template <typename T, size_t N, size_t I = N>
auto make_vector(const std::array<int, N> &a, T value = T()){
  static_assert(I >= 1);
  static_assert(N >= 1);
  if constexpr (I == 1){
    return std::vector<T>(a[N - I], value);
  }else{
    return std::vector(a[N - I], make_vector<T, N, I - 1>(a, value));
  }
}

template <typename T>
std::ostream& operator<<(std::ostream &s, const std::vector<T> &a){
  for(auto it = a.begin(); it != a.end(); ++it){
    if(it != a.begin()) s << " ";
    s << *it;
  }
  return s;
}

template <typename T>
std::istream& operator>>(std::istream &s, std::vector<T> &a){
  for(auto &x : a) s >> x;
  return s;
}


namespace haar_lib {}

namespace solver {
  using namespace haar_lib;

  constexpr int m1000000007 = 1000000007;
  constexpr int m998244353 = 998244353;

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

  void solve(){
    int N; std::cin >> N;
    for(int i = 0; i < N; ++i){
      std::cout << "ACL";
    }
    std::cout << "\n";
  }
}

int main(){
  solver::init();
  while(true){
    try{
      solver::solve();
    }catch(const std::istream::failure &e){
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3876
N = int(input())
ac=0
wa=0
tle=0
re=0
s = [input() for i in range(N)]
for i in s:
    if i == 'AC':
        ac+=1
    if i == 'WA':
        wa+=1
    if i == 'TLE':
        tle+=1
    if i == 'RE':
        re+=1
print("AC x ",ac)
print("WA x ",wa)
print("TLE x ",tle)
print("RE x ",re)


Measured memory_bytes: 16256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    double A,B,H,M;
    cin >>A>>B>>H>>M;
    
    double ans = sqrt(A*A+B*B-2*A*B*cos(abs(2*M_PI*((H+(M/60.0))/12.0-M/60.0))));
    cout << fixed << setprecision(15) << ans << endl;


    return 0;
    

}

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

int main(){

    int a[4];
    rep(i,4) cin >> a[i];

    int ans=0;

    if(a[0]<=a[1]){
        ans=a[0]*a[2];
    }else{
        ans=a[1]*a[2];
        ans+=(a[0]-a[1])*a[3];
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
    long H,ans = 0;
    double cnt =  0;
    scanf("%ld",&H);

    while(H > 0){
        H /= 2;
        cnt += 1;
        ans += pow(2.0,cnt-1);
      //printf("%ld\n",ans);
    }
    printf("%ld",ans);


    return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int H = sc.nextInt();
		Queue w = new PriorityQueue(Collections.reverseOrder());
	//	long maxthrow = 0;
		int maxatk = 0;
		int res = 0;
		for(int i = 0 ; i<N; i++){
			int atk = sc.nextInt();
			int thr = sc.nextInt();
			w.add(thr);
			maxatk = Math.max(maxatk, atk);
		//	maxthrow += thr;
		}
//		System.out.println(w);
		while(!w.isEmpty()){
			if(maxatk > (int)w.peek())break;
	//		System.out.println("TEST");
			H-=(int)w.poll();
			res++;
			if(H<=0)break;
		}
//		System.out.println(res);
		if(H>0){
		//	System.out.println("TEST");
			res+= Math.ceil(  ( (double)H/(double)maxatk ) );
		}
		
		System.out.println(res);
	}
}

Measured memory_bytes: 66176
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
const int mod = 1000000007;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
vector<int> f = {1},fi = {1};
int fact(int x){
    while((int)f.size() <=x)f.push_back((f.back()*f.size())%mod);
    return f[x];
}
int ifact(int x){
    return modpow(fact(x),mod-2,mod);
}
int C(int x,int y){
    if(x < y)return 0;
    return fact(x)*ifact(y)%mod*ifact(x-y)%mod;
}
signed main(){
    int n;cin >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    int ret = 0;
    rep(i,n)ret = (ret + a[i])%mod;;
    ret = (ret*ret)%mod;
    rep(i,n){
        ret -= (a[i]*a[i])%mod;
        ret = (ret%mod + mod)%mod;
    }
    ret = (ret * modpow(2,mod-2,mod))%mod;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 4828
n = int(input())
count = [0]*5
d = {'M': 0, 'A': 1, 'R': 2, 'C':3, 'H': 4}

for i in range(n):
  s = input()
  if s[0] in 'MARCH':
    count[d[s[0]]] += 1

ans = 0
for i in range(5):
  for j in range(i+1, 5):
    for k in range(j+1, 5):
      ans += count[i] * count[j] * count[k]
print(ans)

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/

ll MOD = 1e9+7;
int main() {
  ll n,k;
  cin >> n >> k;
  ll ak = k*(k-1)/2;
  ak %= MOD;
  ll bk = k*(k+1)/2;
  bk %= MOD;
  vl a(n);
  REP(i,n) cin >> a[i];
  ll ans = 0;
  REP(i,n){
    ll ai=0,bi=0;
    REP(j,n){
      if(j<i&&a[j]<a[i]) ai++;
      if(j>i&&a[j]<a[i]) bi++;
    }
    ll at = ak*ai%MOD;
    ll bt = bk*bi%MOD;
    ans += at;
    ans %= MOD;
    ans += bt;
    ans %= MOD;
  }
  cout << ans<< endl;
  return 0;
}


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

int main()
{
    int k;
    string s;
    cin>>k>>s;
    int n=s.size();
    if(k>=n)
        cout<<s;
    else
        cout<<s.substr(0,k)<<"...";
    return 0;
}

Measured memory_bytes: 3620
n=int(input())

ans=[]
s=0
for i in range(1,n+1):
    s+=i
    ans.append(i)
    if s>=n:
        break

if s==n:
    for a in ans:
        print(a)
else:
    ans.remove((s-n))
    for a in ans:
        print(a)


Measured memory_bytes: 9324
#include<bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 998244353;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"
#define TO_STRING(VariableName) # VariableName
template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< mod >;


bool solve(){
	ll a,b,c,d;cin>>a>>b>>c>>d;
	vector<vector<modint>>dp(c+10,vector<modint>(d+10,0));
	
	dp[a][b]=1;
	rep(i,c+5)rep(j,d+5){
		if(i==0 or j==0)continue;
		dp[i][j]+=modint(j)*dp[i-1][j]+modint(i)*dp[i][j-1]-modint((i-1)*(j-1))*dp[i-1][j-1];
	}
	cout<<dp[c][d]<<endl;
  	return false;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(15);
  solve();
}


Measured memory_bytes: 38772
"use strict"

function calc(n) {
  let sum = 0;
  while(n>0){
    sum += n%10;
    n = Math.floor(n/10,10);
  }
  return sum;
}

function Main(input) {
  input = input.trim().split(' ');
  const n = input[0];
  const a = input[1];
  const b = input[2];

  let ans = 0;
  for(let i=1; i<=n; ++i){
    let o = calc(i);
    if(a<=o && o<=b) ans+=i;
  }

  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[]A = new int[N];

		int[] rain = new int[N];
		for (int i=0; i<N; i++){
			A[i] = sc.nextInt();
			if (i % 2 ==0) {
				rain[0] += A[i];
			} else {
				rain[0] -= A[i];
			}
		}
		for (int i=1; i<N; i++) {
			rain[i] = 2 * (A[i-1] - (rain[i-1] /2));
		}
		StringBuffer sb = new StringBuffer();
		for (int i=0; i<N; i++) {
			if (i > 0){
				sb.append(" ");
			}
			sb.append(rain[i]);
		}
		System.out.println(sb.toString());
	}


}

Measured memory_bytes: 60436
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;

int main() {
    int a,b;cin>>a>>b;
    if (a<b) ct("a < b");
    if (a>b) ct("a > b");
    if (a==b) ct("a == b");
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include<fstream>
#define ll long long
#define F first
#define S second
#define mp make_pair
#define mod 1000000007
#define All(v) v.begin(),v.end()

using namespace std;

string s[51];
int main()
{
    bool w = 0, b = 0;
    int n,m;
    cin >> n >> m;
    for(int i=0; i<n; i++)
        cin >> s[i];
    bool ok = 0;
    string tot;
    for(int i=0; i<m; i++)
    {
        string t;
        cin >> t;
        tot += t;
    }

    for(int i=0; i<n-m+1; i++)
        for(int j=0; j<n-m+1; j++)
        {
            string tmp;
            for(int r=i; r<m+i; r++)
                for(int c=j; c<m+j; c++)
                    tmp += s[r][c];
         //   cout << tmp << endl;
            if(tmp == tot)
                ok = 1;
        }


    if(ok)
        cout << "Yes\n";
    else
        cout << "No\n";






    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll div_ceil(ll, ll);

int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};

int main() {
  int N, L;
  std::cin >> N >> L;
  ll sum = 0;
  ll apple[N];
  ll abs_apple[N];
  REP(i, N) {
    apple[i] = L + i;
    abs_apple[i] = abs(apple[i]);
    sum += apple[i];
  }
  ll mini = abs_apple[0];
  ll ans = sum;
  REP(i, N) {
    if (mini >= abs_apple[i]) {
      mini = abs_apple[i];
      ans = sum - apple[i];
    }
  }
  cout << ans << '\n';
}

ll div_ceil(ll a, ll b) {
  ll quotient = a / b;
  ll remainder = a % b;
  if (remainder == 0) {
    return quotient;
  } else {
    return quotient + 1;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+5;
const int mod=1e9+7;
int b[maxn];
ll k,n;
int num;
vector<int>ans;
int vis[maxn];
int flag=0;
int ans2;
void dfs(int u)
{
    if(num==k)
    {
        flag=1;
        return;
    }
    int v=b[u];
    vis[v]++;
    if(vis[v]==2)
    {
        ans.push_back(v);
    }
    if(vis[v]==3)
        return;
    ans2=v;
    num++;
    dfs(v);

}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        b[i]=x;
    }
    vis[1]++;
    dfs(1);
    if(flag)
    {
        cout<<ans2<<'\n';
    }
    else
    {
        k-=num;
        int len=ans.size();
        k%=len;
        k--;
        if(k<0)
            k=len-1;
        cout<<ans[k]<<'\n';
    }



}


Measured memory_bytes: 13760
#include <stdio.h>
  #define MAX 101
  #define INFINITY 1048576
  #define WHITE -1
  #define GRAY 0
  #define BLACK 1


  int serch(int);

  int M[MAX][MAX];



  int main(){
    int n,i,j,x,y;

    scanf("%d",&n);
    for(i = 1; i <= n; i++){
      for(j = 1; j <= n; j++){
        scanf("%d",&M[i][j]);
        if(M[i][j]==-1) M[i][j]=INFINITY;
      }
    }

    printf("%d\n",serch(n));
    return 0;
  }

  int serch(int n){

    int u, v,i, j, d[MAX], p[MAX], c[MAX],sum, min;

    for(i = 1; i <= n; i++){
      c[i] = WHITE;
      d[i] = INFINITY;
      p[i] = -1;
    }

    p[1] = -1;
    d[1] = 0;

    while(1){
      min = INFINITY;
      u = -1;
      for(i = 1; i <= n; i++){
        if(min > d[i] && c[i] != BLACK){
          u = i;
          min = d[i];
        }
      }

      if(u == -1) break;

      c[u] = BLACK;

      for(v= 1; v <= n; v++) {
        if(c[v] != BLACK && M[u][v] != INFINITY){
          if(d[v] > M[u][v]) {
            d[v] = M[u][v];
            p[v] = u;
            c[v] = GRAY;
          }
        }
      }
    }
    sum=0;

    for(i = 1; i <= n; i++){
      sum += d[i];
    }

    return sum;
  }



Measured memory_bytes: 2112
(function(input) {
    var a = parse(input);
    a = a.map(function(e) { return e.map(Number); });
    for (var i = 0; i < a.length; i++) {
        var n = a[i][0];
        var x = a[i][1];
        if (n === 0 && x === 0) {
            return;
        }
        console.log(count(n, x));
    }

})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function parse(str, sep, ter) {
    sep = sep || ' ';
    ter = ter || '\n';
    str = str.replace(/\n$/, '');
    var a = str.split(ter);
    for (var i = 0; i < a.length; i++) {
        a[i] = a[i].split(sep);
    }
    return a;
}

function count(n, x) {
    var c = 0;
    for (var i = 1; i <= n; i++) {
        for (var j = i + 1; j <= n; j++) {
            for (var k = j + 1; k <= n; k++) {
                if (i + j + k === x) {
                    c++;
                }
            }
        }
    }
    return c;
}

Measured memory_bytes: 8668
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const long double pi = (acos(-1));
#define pb push_back

//最大最小の入れ替え
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;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる

//ここから
int main(){
    ll N;
    cin>>N;
    ll count=0;
    rep2(i,1,N+1){
        if(i%2==0) continue;
        vl X;
        X=divisor(i);
        if(X.size()==8){
            count++;
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include "stdio.h"

int main(void)
{
    int a[3], b[3];
    for (int i = 0; i < 3; i++)
        scanf("%d %d", &a[i], &b[i]);

    int town_a = 0;
    int town_b = 0;
    int town_c = 0;
    int town_d = 0;

    int break_flag = 0;

    for (int i = 0; i < 3; i++)
    {
        switch (a[i])
        {
        case 1:
            town_a++;
            switch (b[i])
            {
            case 1:

                town_a++;
                break;
            case 2:
                town_b++;
                break;

            case 3:
                town_c++;
                break;

            case 4:

                town_d++;
                break;
            }
            break;
        case 2:
            town_b++;
            switch (b[i])
            {
            case 1:

                town_a++;
                break;
            case 2:
                town_b++;
                break;

            case 3:
                town_c++;
                break;

            case 4:

                town_d++;
                break;
            }
            break;

        case 3:
            town_c++;
            switch (b[i])
            {
            case 1:

                town_a++;
                break;
            case 2:
                town_b++;
                break;

            case 3:
                town_c++;
                break;

            case 4:

                town_d++;
                break;
            }
            break;

        case 4:
            town_d++;
            switch (b[i])
            {
            case 1:

                town_a++;
                break;
            case 2:
                town_b++;
                break;

            case 3:
                town_c++;
                break;

            case 4:

                town_d++;
                break;
            }

            break;
        }
        if (town_a > 2 || town_b > 2 || town_c > 2 || town_d > 2)
        {
            break_flag = 1;
            break;
        }
    }
    if (break_flag)
    {
        printf("NO");
    }
    else
    {
        printf("YES");
    }
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=1010;
int n,a[N],s;
VI d;
PII cmp(PII a,PII b) {
	if (a.fi==b.fi) return mp(0,a.se<b.se?1:-1);
	else if (a.se==b.se) return mp(a.fi<b.fi?1:-1,0);
	else assert(0);
}
vector<PII> generate(VI x) {
	if (SZ(x)==4) {
		return vector<PII>{mp(0,0),mp(1,0),mp(1,1),mp(0,1)};
	} else {
		int m=SZ(x),p=-1;
		vector<PII> c,cc;
		rep(i,0,m) if (x[i]==90&&x[(i+1)%m]==270&&x[(i+2)%m]==90) {
			VI y; rep(j,0,m-2) y.pb(x[(i+2+j)%m]);
			c=generate(y);
			p=i; break;
		}
		if (p>=0) {
			for (auto &q:c) q.fi*=2,q.se*=2;
			PII v=c[0];
			PII d1=cmp(c[0],c[m-3]),d2=cmp(c[0],c[1]);
			c.insert(c.begin(),v);
			c.insert(c.begin(),v);
			c[0].fi+=d1.fi; c[0].se+=d1.se;
			c[1].fi+=d1.fi+d2.fi; c[1].se+=d1.se+d2.se;
			c[2].fi+=d2.fi; c[2].se+=d2.se;
			d.clear();
			for (auto q:c) d.pb(q.fi); sort(all(d)); d.erase(unique(all(d)),d.end()); for (auto &q:c) q.fi=lower_bound(all(d),q.fi)-d.begin();
			d.clear();
			for (auto q:c) d.pb(q.se); sort(all(d)); d.erase(unique(all(d)),d.end()); for (auto &q:c) q.se=lower_bound(all(d),q.se)-d.begin();
			rep(j,0,m) cc.pb(c[(m-p+j)%m]);
//			for (auto p:x) printf("%d ",p); puts("");
//			for (auto p:cc) printf("%d %d\n",p.fi,p.se); puts("");
			return cc;
		}
		rep(i,0,m) if (x[i]==90&&x[(i+1)%m]==270&&x[(i+2)%m]==270) {
			VI y; rep(j,0,m-2) y.pb(x[(i+2+j)%m]);
			c=generate(y);
			p=i; break;
		}
		if (p>=0) {
			for (auto &q:c) q.fi*=2,q.se*=2;
			PII v=c[0];
			PII d1=cmp(c[0],c[m-3]),d2=cmp(c[1],c[0]);
			c.insert(c.begin(),v);
			c.insert(c.begin(),v);
			c[0].fi+=d1.fi; c[0].se+=d1.se;
			c[1].fi+=d1.fi+d2.fi; c[1].se+=d1.se+d2.se;
			c[2].fi+=d2.fi; c[2].se+=d2.se;
			d.clear();
			for (auto q:c) d.pb(q.fi); sort(all(d)); d.erase(unique(all(d)),d.end()); for (auto &q:c) q.fi=lower_bound(all(d),q.fi)-d.begin();
			d.clear();
			for (auto q:c) d.pb(q.se); sort(all(d)); d.erase(unique(all(d)),d.end()); for (auto &q:c) q.se=lower_bound(all(d),q.se)-d.begin();
			rep(j,0,m) cc.pb(c[(m-p+j)%m]);
//			for (auto p:x) printf("%d ",p); puts("");
//			for (auto p:cc) printf("%d %d\n",p.fi,p.se); puts("");
			return cc;
		}
		assert(0);
	}
}
int main() {
	scanf("%d",&n);
/*	n=10;
	rep(i,0,n/2+2) a[i]=90;
	rep(i,n/2+2,n) a[i]=270;
	random_shuffle(a,a+n);*/
	rep(i,0,n) {
		scanf("%d",a+i);
//		printf("%d ",a[i]);
		s+=a[i];
	}
	puts("");
	if (s!=180*(n-2)) {
		puts("-1");
		return 0;
	}
	vector<PII> c=generate(VI(a,a+n));
	for (auto p:c) printf("%d %d\n",p.fi,p.se);
}


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

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

    string s;
    cin >> s;

    int ans = 0;
    REP(i, s.size()){
        if(s[i] == 'p') ans--;
    }
    
    cout << ans + s.size() / 2 << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define dl 998244853
int main() {
    int n;
    cin>>n;
    vector<vector<int>> a(n,vector<int>(3,0));
    for(int i=0;i<n;i++){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    int l,m,p;
    l=a[0][0];
    m=a[0][1];
    p=a[0][2];
    for(int i=1;i<n;i++){
        int lx=max(m,p)+a[i][0];
        int mx=max(l,p)+a[i][1];
        int px=max(l,m)+a[i][2];
        l=lx,m=mx,p=px;
    }
    cout<<max(l,max(m,p))<<endl;
}

Measured memory_bytes: 5760
H, W = gets.chomp.split.map(&:to_i)
N = gets.to_i
a = gets.chomp.split.map(&:to_i)

ret = Array.new(H) { Array.new(W) }
y = x = 0
color = 1
num = a[0]

(H * W).times do
  ret[y][x] = color
  num -= 1

  if num.zero?
    color += 1
    num = a[color - 1]
  end

  if y % 2 == 0
    if x == W - 1
      y += 1
    else
      x += 1
    end
  else
    if x == 0
      y += 1
    else
      x -= 1
    end
  end
end

ret.each do |r|
  puts r.join(' ')
end


Measured memory_bytes: 2428
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;

LL n;
LL w[100005][4];
LL dp[100005][4];

int main(){
	scanf("%lld",&n);
	for(LL i = 1;i <= n;i ++)
		for(LL j = 1;j <= 3;j ++)
			scanf("%lld",&w[i][j]);
	for(LL i = 1;i <= n;i ++)
		for(LL j = 1;j <= 3;j ++)
			for(LL k = 1;k <= 3;k ++)
				if(j != k) dp[i][j] = max(dp[i][j],dp[i - 1][k] + w[i][j]);
	printf("%lld\n",max(dp[n][1],max(dp[n][2],dp[n][3])));
	return 0;
}
//

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

int main(){
    int n;
    cin>>n;
    n%=10;
    if(n==3){
        cout<<"bon"<<endl;
    }else if(n==0||n==1||n==6||n==8){
        cout<<"pon"<<endl;
    }else{
        cout<<"hon"<<endl;
    }   

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define umap unordered_map
#define RESET   "\033[0m"
#define RED     "\033[31m"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const ll lINF = 1e18+7;
const int INF = 1e9+7;

template <class T> ostream& operator<<(ostream& s, const vector<T>& v) {
    for (size_t i = 0; i < v.size(); i++) s << v[i] << ' ';
    return s;
}

template <class T> istream& operator>>(istream& s, vector<T>& v) {
    for (size_t i = 0; i < v.size(); i++) s >> v[i];
    return s;
}


//########################################################################################




void solve(int CASE=0) {
	int n;
	cin >> n;
	map<string, int> d;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		d[s]++;
	}
	cout << "AC x " << d["AC"] << "\nWA x " << d["WA"] << "\nTLE x " << d["TLE"] << 
		"\nRE x " << d["RE"];
}


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

    int TEST = 1;
    //cin >> q;
    for (int i = 1; i <= TEST; i++) 
		solve(i);
}


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

ostream& operator<<(ostream &out, string str) {
	for(char c : str) out << c;
	return out;
}
 
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}
 
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}
 
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}
 
#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
 
template<class T> int size(T && a) { return a.size(); }
 
using LL = long long;
using PII = pair<int, int>;

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

	int n;
	cin >> n;
	vector<int> layer_cnt(n);
	LL ans = 1;
	REP(i, n) {
		int d;
		cin >> d;
		if((i == 0) ^ (d == 0))
			ans = 0;
		layer_cnt[d]++;
	}

	LL mod = 998244353;
	FOR(i, 1, n - 1) {
		REP(j, layer_cnt[i]) 
			ans = ans * layer_cnt[i - 1] % mod;
	}

	cout << ans << "\n";
}


Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
using namespace std;

int a[100001];
int L[100000];

int main()
{
	int ret;
	int N;
	int len;

	ret = scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		ret = scanf("%d", &(a[i]));
	}

	len = 0;
	for (int i = 1; i <= N; i++) {
		int val = a[i];

		//len-1～0までループ j
		int j;
		j = len - 1;
		for (; j >= 0; j--) {
			if (L[j] >= val) break;
		}
		int idx = j + 1;

		L[idx] = val;
		if (idx == len) len++;
	}

	printf("%d", len);

	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>

int main()
{
    int n, h[105];
    int k[105][105] = {0};
    int maxn = -1;
    scanf("%d", &n);
    for(int i = 0; i < n; ++i)
    {
        scanf("%d", &h[i]);
        maxn = maxn > h[i] ? maxn : h[i];
        for(int j = 0; j < h[i]; ++j)
        {
            k[i][j] = 1;
        }
    }
    int ans = 0;
    for(int i = 0; i < maxn; i++)
    {
        for(int j = 0; j <= n; j++)
        {
            if(k[j][i] == 0 && j > 0 && k[j-1][i] != 0)
            {
                ans++;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main() {
	SPEED;
	int a, b;
	cin >> a >> b;
	int ans;
	if (a >b) {
		ans = a * 2 - 1;
	}
	if(b>a) {
		ans = b * 2 - 1;
	}
	if (a == b)ans = a * 2;
	cout << ans;
	ed;
	return 0;
}

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

int main(){
  int N, M;
  cin >> N;
  map<string, int> ki;
  
  for ( int i = 0; i < N; i++){
    string s;
    cin >> s;
    ki[s]++;
  }

  cin >> M;
  for ( int i = 0; i < M; i++){
    string t;
    cin >> t;
    ki[t]--;
  }
  
  int res = 0;
  for ( auto itr = ki.begin(); itr != ki.end(); itr++){
    res = max(res, itr->second);   
  }
  
  cout << res << endl;
  return 0;
    
}


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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int X,Y,Z,K;
  cin >> X >> Y >> Z >> K;
  vector<ll> A(X),B(Y),C(Z);
  rep(i,X)  cin >> A.at(i);
  rep(i,Y)  cin >> B.at(i);
  rep(i,Z)  cin >> C.at(i);
  sort(all(A));
  sort(all(B));
  sort(all(C));
  reverse(all(A));
  reverse(all(B));
  reverse(all(C));

  set<tuple<int,int,int>> S;
  priority_queue<pair<ll,tuple<int,int,int>>> pq;
  S.insert(make_tuple(0,0,0));
  pq.push(m_p(A.at(0)+B.at(0)+C.at(0),make_tuple(0,0,0)));
  while(K>0){
    K--;
    cout << pq.top().fi << endl;
    int a,b,c;
    tie(a,b,c)=pq.top().se;
    pq.pop();

    if(a+1<X && !S.count(make_tuple(a+1,b,c))){
      S.insert(make_tuple(a+1,b,c));
      pq.push(m_p(A.at(a+1)+B.at(b)+C.at(c),make_tuple(a+1,b,c)));
    }
    if(b+1<Y && !S.count(make_tuple(a,b+1,c))){
      S.insert(make_tuple(a,b+1,c));
      pq.push(m_p(A.at(a)+B.at(b+1)+C.at(c),make_tuple(a,b+1,c)));
    }
    if(c+1<Z && !S.count(make_tuple(a,b,c+1))){
      S.insert(make_tuple(a,b,c+1));
      pq.push(m_p(A.at(a)+B.at(b)+C.at(c+1),make_tuple(a,b,c+1)));
    }
  }

  return 0;
}

Measured memory_bytes: 4212
#include<stdio.h>

int main(){
  long long int a[1000000];
  long long int res, ans=100000000000000000LL, X=0LL,x=0LL;
  int i, j, n;

  scanf("%d", &n);

  for(i=0; i<n; i++){
    scanf("%lld", &a[i]);
    X+=a[i];
  }

  for(i=0; i<n-1; i++){
    x+=a[i];
    res=X-2*x;
    if(res<0){
      res*=-1;
    }
    if(res<ans){
      ans=res;
    }
  }

  printf("%lld\n", ans);

  return 0;
}


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

constexpr int MOD = 100000;


bool solve(){
    int h, w;
    cin >> h >> w;
    if(h==0) return false;
    int dp[105][105][2][2]{};
    dp[0][0][0][1] = 1;
    dp[0][0][1][1] = 1;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            for(int k=0;k<4;k++){
                dp[i][j][k&1][k>>1] %= MOD;
            }
            dp[i+1][j][0][0] += dp[i][j][0][0]+dp[i][j][0][1];
            dp[i+1][j][0][1] += dp[i][j][1][0];
            dp[i][j+1][1][0] += dp[i][j][1][0]+dp[i][j][1][1];
            dp[i][j+1][1][1] += dp[i][j][0][0];
        }
    }
    int ans = 0;
    for(int i=0;i<4;i++){
        ans += dp[h-1][w-1][i&1][i>>1];
        ans %= MOD;
    }
    cout << ans << endl;
    return true;
}

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



Measured memory_bytes: 3268
import kotlin.math.*

fun main() {
    println(solve())
}

val solve: () -> Any = {
    if (readInt() == 0) 1 else 0

}

val mod: Int = 1_000_000_007


fun readString() = readLine()!!
fun readStringList() = readLine()!!.split(" ")
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun <T> T.alsoPrintln() = also { println(this) }

fun Boolean.toYesOrNo(yes: String = "Yes", no: String = "No") = if (this) yes else no

fun <E> List<E>.toPair() = this[0] to this[1]

fun <T> readPair(t: (String) -> T) = readPair(t, t)
fun <S, T> readPair(s: (String) -> S, t: (String) -> T) =
    readLine()!!.split(" ").let { Pair(s(it[0]), t(it[1])) }

fun Int.pow(n: Int) = this.toDouble().pow(n).toInt()

fun minAndMax(a: Int, b: Int) = if (a < b) a to b else b to a

fun <T> T.ifOrThis(bool: (T) -> Boolean, trans: (T) -> T) = if (bool(this)) trans(this) else this
fun <T> T.ifOrThis(bool: Boolean, trans: (T) -> T) = if (bool) trans(this) else this

Measured memory_bytes: 34372
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#define mod 1000000007
using namespace std;



int main()
{
    int m,n,o=0,i,j,k;
    int sum=0,range=0;
    //long long int m,n,o,i,j,k=0;
    //vector <int> v;
    //float f,g,h;
    //char c,d;
    //string a;
    cin>>n;
    int *r1=new int [n];
    int *r2=new int [n];
    cin>>r1[0];
    for(i=1;i<n;i++)
    {
        cin>>r1[i];
        r1[i]+=r1[i-1];
    }
    cin>>r2[0];r2[0]+=r1[0];
    for(i=1;i<n;i++)
    {
        cin>>r2[i];
        r2[i]+=r1[i]>r2[i-1]?r1[i]:r2[i-1];
    }
    cout<<r2[n-1];
    delete [] r1;
    delete [] r2;
    return 0;
}





Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<utility>
using namespace std;
#define int long long
#define veb vector<bool>
#define vveb vector<veb>
#define vel vector<long long>
#define vvel vector<vel>
#define vvvel vector<vvel>
void mmin(int &a, int b) { a = min(a, b); }
void mmax(int &a, int b) { a = max(a, b); }
void sor(vel &v) { sort(v.begin(), v.end()); }
void rev(vel &v) { reverse(v.begin(), v.end()); }
int zero(void) { return 0; }
signed main() {
	int n, m;
	cin >> n >> m;
	vel x(n + 1); vel y(m + 1);
	cin >> x[0] >> y[0];
	for (int i = 1; i <= n; i++) { 
		cin >> x[i];
	}
	for (int i = 1; i <= m; i++) { 
		cin >> y[i];
	}
	sor(x); sor(y);
	if (x[n] < y[0]) { cout << "No War"; }
	else { cout << "War"; }
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
using namespace std::chrono;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (1LL << 31) - 1;
const ll mod = 1e9 + 7;


ll H, W, M;
pair<ll, ll> X[300005], Y[300005];
vector<ll> B;



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

	cin >> H >> W >> M;
	B.resize(M);
	FOR(i, 0, M) {
		ll x, y; cin >> y >> x;
		x--; y--;
		X[x].first++;
		Y[y].first++;

		B[i] = y * W + x;
	}
	FOR(i, 0, H) {
		Y[i].second = i;
	}
	FOR(i, 0, W) {
		X[i].second = i;
	}
	sort(B.begin(), B.end());

	sort(X, X + W);
	reverse(X, X + W);

	sort(Y, Y + H);
	reverse(Y, Y + H);

	ll maxX = X[0].first;
	ll maxY = Y[0].first;

	ll cnt = 0;
	bool judge =false;

	for (ll i = 0;i<W && X[i].first == maxX; i++) {
		for (ll j = 0;j<H && Y[j].first == maxY; j++) {

			cnt++;

			ll x = X[i].second, y = Y[j].second;

			if (!binary_search(B.begin(), B.end(), y*W + x)) {
				//cout << maxX + maxY << endl;
				judge = true;
			}

			if (cnt > M) {
				judge = true;
				break;
			}
			
		}
		if (cnt > M)break;
	}

	if (judge)cout << maxX + maxY << endl;
	else cout << maxX + maxY - 1 << endl;

	return 0;
}








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

using namespace std;

int main(){
    int n,l;
    cin >> n >> l;
    vector<string> in(n);
    for(int i=0;i<n;i++)cin >> in[i];

    string ans="";
    vector<int> frg(n);

    sort(in.begin(),in.end());
    for(int i=0;i<n;i++){
       if(frg[i]==1)continue;
        for(int j=i+1;j<n;j++){
            if(frg[j]==1)continue;

            string tmp=in[j];
            reverse(tmp.begin(),tmp.end());
            if(in[i]==tmp){
                ans+=in[i];
                frg[i]=frg[j]=1;
                break;
            }
        }
    }

    string a="";
    for(int i=0;i<n;i++){
        if(frg[i]==1)continue;
        string tmp=in[i];
        reverse(tmp.begin(),tmp.end());
        if(tmp==in[i]){
            a=in[i];
            break;
        }
    }
    string ansb = ans;
    reverse(ansb.begin(),ansb.end());

    ans += a;
    ans += ansb;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3268