akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for i in range(n - m + 1):
    for j in range(n - m + 1):
        flag = True
        for k in range(m):
            if a[k + j][i:i + m] != b[k]:
                flag = False
                break
        if flag:
            print("Yes")
            exit()
print("No")



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
 int a,b,c,yf=0;
 cin >> a >> b >> c;
 if( a >= b && a >= c){
  if(a == b+c){
   yf++;
  }
 } else if(b >= a && b >= c){
  if(b == a+c){
   yf++;
  }
 } else if( c >= a && c >= b){
   if(c == a+b){
    yf++;
   }
  }
if(yf == 1){
cout << "Yes" << endl;
} else{
cout << "No" << endl;
}
return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
using namespace std;
using ll=long long;
#define MOD  1000000007

int cnta=0,cntb=0,cntc=0;

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

	vector<string>s(3);
	cin >>s[0]>>s[1]>>s[2];
	int p = 0;
	while(1) {
		if (s[p].size() == 0) {
			if (p == 0) {
				cout << "A" << endl;
        break;
			}
			else if (p == 1) {
				cout << "B" << endl;
        break;
			}
			else if (p == 2) {
				cout << "C" << endl;
        break;
			}
		}
        if (s[p][0] == 'a') {
			
			s[p].erase(0, 1);
			p = 0;
		}
		else if (s[p][0] == 'b') {
			s[p].erase(0, 1);
			p = 1;
		}else if (s[p][0] == 'c') {

			s[p].erase(0, 1);
			p = 2;

		}
	}  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {

int a,b[30],c;
   cin >> a;

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

 c = 0;
for (int i = 0; i < a; ++i) {
bool abc = true;
for (int j = 0; j < i; ++j) {
if (b[j] > b[i]) {
 abc = false;
break;
}
}
if (abc) {
++c;
}
}

cout << c << endl;
}


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

int main() {
int a,b;
cin >> a >> b;
cout << a*b<<endl;


}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

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

int main() {
  int N;
  cin >> N;
  int64_t result = 0;
  for (int i = 1; i <= N; i++) {
    if (((i % 3) != 0) && ((i % 5) != 0)) {
      result += i;
    }
  }
  cout << result << endl;
}

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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}

int main(){
    std::ios_base::sync_with_stdio(false); cin.tie(0);
    ll x;
    cin >> x;
    ll res = (x / 11LL) * 2;
    x %= 11;
    if (x){
        if (x <= 6) res++;
        else res += 2;
    }
    cout << res << endl;

}


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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  int N,M; cin >> N >> M;
  ll K; cin >> K;
  vector<ll> A(N+1,0), B(M+1,0);

  for(int i = 1; i <= N; i++){
    ll tmp = 0; cin >> tmp;
    A[i] = tmp + A[i-1];
  }

  for(int i = 1; i <= M; i++){
    ll tmp = 0; cin >> tmp;

    B[i] = tmp + B[i-1];
  }


  int max_val = 0;
  for(int i = 0; i <= N; i++){
    ll time = A[i]; 
    ll r = K - A[i];

    if(r < 0) break;

    int index = upper_bound(B.begin(), B.end(), r) - B.begin() - 1;
    max_val = max(max_val, i + index);
  }
  cout << max_val << endl;

}


Measured memory_bytes: 6436
import sys
input=sys.stdin.readline
n=int(input())
A=[list(map(int,input().split())) for _ in range(n)]
P=[0]*(1<<n)
for s in range(1,1<<n):
    for i in range(n):
        if s&(1<<i):
            break
    p=P[s-(s&(1<<i))]
    for j in range(i+1,n):
        if s&(1<<j)!=0:
            p+=A[i][j]
    P[s]=p
DP=[0]*(1<<n)
for s in range(1<<n):
    DP[s]=P[s]
    t=s
    while t:
        DP[s]=max(DP[s],DP[t]+DP[s^t])
        t=(t-1)&s
print(DP[-1])

Measured memory_bytes: 43740
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
public:
  ll *fac,*finv,*inv;
//public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

ll gcd(ll x,ll y){
  if(x%y == 0) return y;
  else return gcd(y,x%y);
}

int main(){
  string s;
  cin >> s;
  int now = 1;
  int q;
  cin >> q;
  deque<char> dq;
  for(int i=0;i<s.length();i++){
    dq.push_back(s[i]);
  }
  for(int i=0;i<q;i++){
    int t;
    cin >> t;
    if(t == 1) now *= -1;
    else{
      int f;
      char c;
      cin >> f >> c;
      if(now == 1){
        if(f == 1) dq.push_front(c);
        else dq.push_back(c);
      }
      else{
        if(f == 2) dq.push_front(c);
        else dq.push_back(c);
      }
    }
  }
  string ans="";
  while(!dq.empty()){
    char temp;
    if(now == 1){
      temp = dq.front();
      dq.pop_front();
    }
    else{
      temp = dq.back();
      dq.pop_back();
    }
    cout << temp;
  }
  cout << endl;
  return 0;

}


Measured memory_bytes: 896
s = list(input())
t = input()
#文字列の長さ
a = len(s)
b = "No"
#適当なx
x = a
for _ in range(a):
  x =s[0]
  for i in range(a-1):
    s[i]=s[i+1]
  s[-1]=x
  s = "".join(s)
  if s==t:
    b='Yes'
    break
  else:
    s = list(s)
print(b)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long unsigned int ll;
 
int main() {
 
  char a,b;
  cin >> a;
  cin >>b;
  
  if(a>b){
    cout << ">" << endl;
  }else if(a==b){
    cout << "=" << endl;
  }else{
    cout << "<" << endl;
  }
  
   return 0;
}


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

using namespace std;

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main()
{
	while(1){
		int h, w;
		cin >> h >> w;
		if(h == 0 && w == 0){
			break;
		}
		rep(i, h){
			rep(j, w){
				if(i == 0 || j == 0 || i == h-1 || j == w-1){
					cout << '#';
				}else{
					cout << '.';
				}
			}
			cout << endl;
		}
		cout << endl;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}



Measured memory_bytes: 3164
//! Bismillahi-Rahamanirahim.
/** ========================================**
 ** @Author: Md. Abu Farhad ( RUET, CSE'15)
 ** @Category:
/** ========================================**/

#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;

#define ll long long

#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scd(x) scanf("%lf",&x)
#define scc(x) scanf("%[^\n]s",x); // For charecter string input , It will  read all charecter untill Enter new line .

#define pfi(x) printf("%d",x)
#define pfl(x) printf("%lld\n",x)
#define pfd(x) printf("%lf",x)
#define pfc(x) printf("Case %d: ",x)
#define ps printf(" ")
#define pn printf("\n")
#define pb(x) push_back(x)
#define ppb(x) pop_back(x)
#define pf(x) push_front(x)
#define ppf(x) pop_front(x)

#define Pi               2*acos(0.0)
#define ms(a,b)       memset(a, b, sizeof(a))
#define EPS           10E-10
#define ff              first
#define ss              second
#define sqr(x)        (x)*(x)



ll v[5005];

ll max_subarray( ll n)
{
    ll ans=-1000000, curr_max=0;
    for(ll i=0; i<n; i++)
    {
        curr_max=max(v[i], curr_max+v[i]);
        ans=max(ans, curr_max);
    }
    return ans;
}



int main()
{

    ll m,n,t,b,c,d,i,j,k,x=0,y,z;
    while(1)
    {
        cin>>n;
        if(n==0) return 0;
        else
        {
            for(i=0; i<n; i++)
            {
                cin>>v[i];
            }
            cout<<max_subarray( n )<<endl;
            for(i=0; i<n; i++) v[i]=0;
        }
    }

    return 0;
}



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

signed main() {
  int h,w,a,b;cin>>h>>w>>a>>b;

  vector<string> ans(h,string(w,'0'));

  for(int hi=0;hi<b;++hi){
    for(int wi=0;wi<a;++wi){
      ans[hi][wi] = '1';
    }
  }

  for(int hi=b;hi<h;++hi){
    for(int wi=a;wi<w;++wi){
      ans[hi][wi] = '1';
    }
  }

  for(int hi=0;hi<h;++hi){
    cout<<ans[hi]<<endl;
  }
  
  return 0;
}


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

/*** Template Begins ***/

struct custom_hash {static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;x = (x ^ (x >> 27)) * 0x94d049bb133111eb;return x ^ (x >> 31);}
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();return splitmix64(x + FIXED_RANDOM);}};
// USE : unordered_map<int, int, custom_hash> m;
//     : unordered_set<int, custom_hash> s;

typedef long long    ll;
typedef pair<ll,ll>  PII;
typedef pair<ll, PII> PIII;
#define endl         '\n'
#define pb           push_back
#define INF          ll_MAX/10
#define F            first
#define S            second
#define mp           make_pair
#define ios          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define hell         1000000007
#define all(a)       (a).begin(),(a).end()
ll power(ll x, ll y, ll p){ ll res = 1;x = x % p;while (y > 0){ if (y & 1) res = (res*x) % p;y = y>>1;x = (x*x) % p;} return res; } 

// Constants //

const int N = 1e5+7;

/*** Template Ends ***/

ll x, y;





int main(){
	
	ios;
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	cin >> x >> y;
	cout << x + (y+1)/2;

	return 0;
}














Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;
ll gcd( ll m, ll n )
{
    if (n == 0){
        return m;
    }else{
        return gcd(n, m % n);
    }
}

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,X;
    ll x[100010];
    cin >> N >> X;
    rep(i,0,N){
        cin >> x[i];
    }
    ll d[100010] = {};
    rep(i,0,N){
        d[i] = abs(X - x[i]);
    }
    ll ans = d[0];
    rep(i,1,N){
        ans = gcd(ans, d[i]);
    }
    print(ans);
    // if(N % 2 == 0){
    //     rep(j,0,N/2){
    //         d_tmp[j] = my_gcd(d[2*j],d[2*j+1]);
    //     }
    //     rep(j,0,N/2){
    //         ans = my_gcd(ans, d_tmp[j]);
    //     }
    // }else{
    //     rep(j,0,(N-1)/2){
    //         d_tmp[j] = my_gcd(d[2*j],d[2*j+1]);
    //     }
    //     rep(j,0,(N-1)/2){
    //         ans = my_gcd(ans, d_tmp[j]);
    //     }
    //     ans = my_gcd(ans, d[N-1]);

    // }



}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(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 fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

#define MAX 110000


int main() {
	int n,ans=0,input;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> input;
		ans += input - 1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
parseline(str=readline()) = parse.(Int, split(str))
function DiceInLine()
    N, K = parseline()
    p = parseline()
    temp = sum(p[1:K])
    ans = (temp+K)/2.0
    for i in 2:length(p)-K+1
        temp = temp - p[i-1] + p[i+K-1]
        ans = max(ans, (temp+K)/2.0)
    end
    println(ans)
end
DiceInLine()

Measured memory_bytes: 209020
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,a[220001],b[220001];
main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i],a[i]-=b[i];
	sort(a,a+n);
	memcpy(b,a,sizeof a);
	for(int i=0,j=n-1;i<j;)
		if(a[i]>=0)break;
		else if(a[i]+a[j]>=0)a[j]+=a[i],a[i]=0,i++;
		else a[i]+=a[j],a[j]=0,j--;
	int ans=0;
	for(int i=0;i<n;i++)
		if(a[i]<0)return puts("-1"),0;
		else if(a[i]!=b[i])ans++;
	cout<<ans<<'\n';
}


Measured memory_bytes: 2688
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
//using Graph = vector<vector<pair<ll,ll>>>;
const int mod =1e+9+7;

const int dy[4]={0,1,0,-1};
const int dx[4]={1,0,-1,0};
const ll INF=1e10;

int main(){
    ll n; string s1,s2; cin>>n>>s1>>s2;
    ll ans=1;
    ll cnt=0;
    if(s1[0]==s2[0])ans*=3;
    else {
        ans*=6;
        cnt++;
    }
    //cout<<ans<<endl;
    for( ll i=cnt;i<n-1;i++){
        if(s1[i]==s2[i]){
            if(s1[i+1]==s2[i+1]){
                ans*=2;
            }
            else{
                ans*=2;
                i++;
            }
        }
        else{
            if(s1[i+1]==s2[i+1]){
                ans*=1;
            }
            else{
                ans*=3;
                i++;
            }
        }
        ans%=mod;
    }
    cout<<ans<<endl;
}











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

int main()
{
    string S;
    char* c;
 //   const char* date[7] = { "SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN" }; //文字列リテラルはconst char*で宣言しないといけない
    int ans = 0;

    /*入力処理*/
    cin >> S;

    /*判断*/


    if (S == "SAT") {
        ans = 1;
    }
    else if (S == "FRI") {
        ans = 2;
    }
    else if (S == "THU") {
        ans = 3;
    }
    else if (S == "WED") {
        ans = 4;
    }
    else if (S == "TUE") {
        ans = 5;
    }
    else if (S == "MON") {
        ans = 6;
    }
    else if (S == "SUN") {
        ans = 7;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T f=0,x=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
namespace run{
	const int N=1e5+9;
	int head[N],nex[N<<1],to[N<<1],cnt;
	inline void add(int u,int v){
		nex[++cnt]=head[u];
		head[u]=cnt,to[cnt]=v;
	}

	int dep[N],sum[N],fa[N];
	inline void dfs(int u,int _f){
		dep[u]=dep[_f]+1,sum[u]=(dep[u]&1)*2-1;
		for(int i=head[u];i;i=nex[i])
			if(to[i]^_f) dfs(to[i],u),sum[u]+=sum[to[i]];
	}

	int vis[N],S,T;
	inline void dfs1(int u,int _f){
		vis[u]=1,dep[u]=dep[_f]+1,sum[u]=(dep[u]&1)*2-1,fa[u]=_f;
		for(int i=head[u];i;i=nex[i]) if(to[i]^_f){
			if(!vis[to[i]]) dfs1(to[i],u),sum[u]+=sum[to[i]];
			else S=u,T=to[i];
		}
	}
	
	int k[N];
	inline void dfs2(int u,int _f){
		vis[u]=1;
		for(int i=head[u];i;i=nex[i]) if(to[i]^_f){
			if(!vis[to[i]]) dfs2(to[i],u),k[u]+=k[to[i]];
		}
	}

	int n,m,st[N],top,ans;
	int main(){
		n=read<int>(),m=read<int>();
		for(int i=1;i<=m;i++){
			int u=read<int>(),v=read<int>();
			add(u,v),add(v,u);
		}

		if(m==n-1){
			dfs(1,0);
			if(sum[1]) puts("-1"),exit(0);
			int ans=0;
			for(int i=1;i<=n;i++) ans+=abs(sum[i]);
			printf("%d\n",ans);
		}else{
			dfs1(1,0);
			if((dep[S]&1)==(dep[T]&1)){
				if(sum[1]&1) puts("-1"),exit(0);
				int del=sum[1]/2;
				ans=abs(del);
				for(int i=S;i;i=fa[i]) sum[i]-=del;
				for(int i=T;i;i=fa[i]) sum[i]-=del;

				for(int i=1;i<=n;i++) ans+=abs(sum[i]);
			}else{
				if(sum[1]) puts("-1"),exit(0);
				for(int i=1;i<=n;i++) vis[i]=0;
				k[S]=1,k[T]=-1,dfs2(1,0);
				for(int i=1;i<=n;i++)
					if(k[i]) st[++top]=k[i]*sum[i];
					else ans+=abs(sum[i]);
				st[++top]=0;
				sort(st+1,st+top+1);

				int pos=st[(top+1)>>1];
				for(int i=1;i<=top;i++) ans+=abs(st[i]-pos);
			}
			printf("%d\n",ans);
		}
		return 0;
	}
}
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}

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

//Short code
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

//Macros
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i < b; i++)

int main ()
{
  //freopen ("input.txt","r",stdin);
  //freopen ("output.txt","w",stdout);

  /* Code here */
  int n; cin>>n;
  if(n==1)
    cout<<"Hello World";
  else if(n==2){
    int a,b;
    cin>>a>>b;
    cout<<a+b;
  }


  //fclose (stdin);
  //fclose (stdout);
  return 0;
}




Measured memory_bytes: 256
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=21;
const int p=1e9+7;

int q[N][1<<20];
int dp[2][1<<20],f[2][1<<20];
int A[N][N];
int n,m,k,a,b,c,c2,ans;

inline void upd(int &x,int y){
	x=(x+y>=p?x+y-p:x+y);
}

int main(){
	memset(A,-1,sizeof(A));
	n=IN(),m=IN(),k=IN();
	For(i,0,k){
		a=IN(),b=IN(),c=IN();
		A[a-1][b-1]=c;
	}
	For(t,0,1<<n-1){
		int tmp=0;
		for (int i=n-1;~i;i--){
			if (t>>i&1) tmp=1<<i;
			q[i][t]=(t^tmp)|(1<<i);
		}
	}
	dp[c][0]=1;
	For(i,0,m){
		memset(dp[c^1],0,sizeof(dp[c^1]));
		For(t,0,1<<n-1) f[c2][t]=dp[c][t];
		For(u,0,n-1){
			For(t,0,1<<n-1) if (f[c2][t]){
				if (!(t>>u&1)&&A[i][u]!=1) upd(f[c2^1][t],f[c2][t]);
				if (A[i][u]!=0) upd(f[c2^1][q[u][t]],f[c2][t]);
				f[c2][t]=0;
			}
			c2^=1;
		}
		For(t,0,1<<n-1) if (f[c2][t]){
			upd(dp[c^1][t],f[c2][t]);
			f[c2][t]=0;
		}
		c^=1;
		//dprintf("%d\n",i);
	}
	For(t,0,1<<n-1) upd(ans,dp[c][t]);
	printf("%d\n",ans);
}

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

int main(){
  string str;
  cin >> str;
  sort(str.begin(), str.end());
  
  vector<int> time(str.size());
  int now=0;
  time[0]++;
  for(int i=1; i<str.size(); i++){
    if(str[i]==str[i-1]) time[now]++;
    else{
      now++;
      time[now]++;
    }
  }
  for(int i=0; i<=now; i++){
    if (time[i]%2!=0){
      cout << "No" <<endl;
      return 0;
    }
  }
  cout << "Yes"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	int a[100][100],b[100],c[100]={0};
	for(int x=0;x<n;x++){
		for(int y=0;y<m;y++){
			scanf("%d",&a[x][y]);
		}
	}
	for(int x=0;x<m;x++){
		scanf("%d",&b[x]);
	}
	for(int x=0;x<n;x++){
		for(int y =0;y<m;y++){
			c[x]=c[x]+(a[x][y]*b[y]);
		}
		printf("%d\n",c[x]);
	}
	return 0;
}

Measured memory_bytes: 2736
import scala.annotation.tailrec
import scala.collection.mutable
object Main extends App {
  import scala.io.StdIn._
  val t = readLong
  val n = readInt
  val events = Array.tabulate(n){_ ⇒
    val Array(s, t) = readLine.trim.split(' ').map(_.toLong)
    Event(s, t)
  }
  val eventTimeSum = BigInt(0) +: events.map(e ⇒ BigInt(e.end - e.start))
  for (i ← eventTimeSum.indices.tail) eventTimeSum(i) += eventTimeSum(i - 1)
  var max = BigInt(0)
  for ((event, i) ← events.zipWithIndex){
    val until = lowerBound(events, event.start + t)
    if (until < n){
      if (events(until).start < event.start + t) {
        if (max < eventTimeSum(until) - eventTimeSum(i) + event.start + t - events(until).start) max = eventTimeSum(until) - eventTimeSum(i) + event.start + t - events(until).start
      }else {
        if (max < eventTimeSum(until) - eventTimeSum(i)) max = eventTimeSum(until) - eventTimeSum(i)
      }
    } else if (until == n && max < eventTimeSum(until) - eventTimeSum(i)) max = eventTimeSum(until) - eventTimeSum(i)
  }
  println(max)

  def lowerBound(array: Array[Event], time: Long): Int = {
    var left = 0
    var right = array.length
    while (left < right){
      val mid = (left + right) / 2
      if (array(mid).end < time){
        left = mid + 1
      } else {
        right = mid
      }
    }
    right
  }
  case class Event(start: Long, end: Long)
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
  }
}



Measured memory_bytes: 191908
import bisect

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N):
    a = L[i]
    for j in range(i+1, N):
        b = L[j]
        ans += bisect.bisect_left(L, a+b)-j-1
print(ans)

Measured memory_bytes: 43628
#include <iostream>
#include <unordered_set>
using namespace std;

int dp[100000];
unordered_set<int> conns[100000];

int out(int id) {
    if (dp[id] != -1) {
        return dp[id];
    }
    int t = 0;
    for (auto iter = conns[id].begin(); iter != conns[id].end(); iter++) {
        t = max(t, 1+out(*iter));
    }
    return dp[id] = t;
}

int main() {
    int n, m;
    cin >> n >> m;
    
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        conns[x-1].insert(y-1);
    }
    
    for (int i = 0; i < n; i++) {
        dp[i] = -1;
    }
    int yeet = 0;
    for (int i = 0; i < n; i++) {
        yeet = max(yeet, out(i));
    }
    cout << yeet << endl;
}

Measured memory_bytes: 13696
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    double xp0, xp1, yp0, yp1, xp2, yp2, xp3, yp3;
    int q;
    int i;
    double min, d;

    q = sc.nextInt();
    for(i = 0;i < q;i++){
      xp0 = sc.nextDouble();
      yp0 = sc.nextDouble();
      xp1 = sc.nextDouble();
      yp1 = sc.nextDouble();
      xp2 = sc.nextDouble();
      yp2 = sc.nextDouble();
      xp3 = sc.nextDouble();
      yp3 = sc.nextDouble();

      min = cross(xp0, xp1, xp2, xp3, yp0, yp1, yp2, yp3);

      d = dist(xp0, yp0, xp1, yp1, xp2, yp2);
      if(min > d)min = d;
      d = dist(xp0, yp0, xp1, yp1, xp3, yp3);
      if(min > d)min = d;
      d = dist(xp2, yp2, xp3, yp3, xp0, yp0);
      if(min > d)min = d;
      d = dist(xp2, yp2, xp3, yp3, xp1, yp1);
      if(min > d)min = d;

      System.out.println(Math.sqrt(min));
    }
    sc.close();
  }

  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }

  private static double dist(
  double p0x, double p0y, double p1x, double p1y, double px, double py){
    double t, d0, d1, x, y;

    t = (p1x - p0x) * (px - p0x) + (p1y - p0y) * (py - p0y);
    t = t / ((p1x - p0x) * (p1x - p0x) + (p1y - p0y) * (p1y - p0y));
    x = p0x + t * (p1x - p0x);
    y = p0y + t * (p1y - p0y);

    if((x - p0x) * (x - p1x) > 0 || (y - p0y) * (y - p1y) > 0){
      d0 = (p0x - x) * (p0x - x) + (p0y - y) * (p0y - y);
      d1 = (p1x - x) * (p1x - x) + (p1y - y) * (p1y - y);
      if(d0 < d1){
        return (px - p0x) * (px - p0x) + (py - p0y) * (py - p0y);
      }else{
        return (px - p1x) * (px - p1x) + (py - p1y) * (py - p1y);
      }
    }else{
      return (px - x) * (px - x) + (py - y) * (py - y);
    }

  }

  private static double cross(
    double xp0, double xp1, double xp2, double xp3,
    double yp0, double yp1, double yp2, double yp3
    ){
    double s1x0, s1y0, s2x0, s2y0, s3x0, s3y0, s10, s20;
    double s1x1, s1y1, s2x1, s2y1, s3x1, s3y1, s11, s21;

    s1x0 = xp1 - xp0;
    s1y0 = yp1 - yp0;
    s2x0 = xp2 - xp0;
    s2y0 = yp2 - yp0;
    s3x0 = xp3 - xp0;
    s3y0 = yp3 - yp0;

    s10 = s1x0 * s2y0 - s1y0 * s2x0;
    s20 = s1x0 * s3y0 - s1y0 * s3x0;

    s1x1 = xp3 - xp2;
    s1y1 = yp3 - yp2;
    s2x1 = xp0 - xp2;
    s2y1 = yp0 - yp2;
    s3x1 = xp1 - xp2;
    s3y1 = yp1 - yp2;

    s11 = s1x1 * s2y1 - s1y1 * s2x1;
    s21 = s1x1 * s3y1 - s1y1 * s3x1;

    if(s10 * s20 > 0 || s11 * s21 > 0){
      return 800000000.0;   //no cross
    }else if(s10 == 0 && s20 == 0 &&
             (s1x0 * s2x0 < 0 || s1y0 * s2y0 < 0) &&
             (s1x0 * s3x0 < 0 || s1y0 * s3y0 < 0)
            ){
              return 800000000.0;   //no cross
    }else if(s10 == 0 && s20 == 0 &&
      ((s1x0 * s1x0) + (s1y0 * s1y0) < (s2x0 * s2x0) + (s2y0 * s2y0)) &&
      ((s1x0 * s1x0) + (s1y0 * s1y0) < (s3x0 * s3x0) + (s3y0 * s3y0))
            ){
              return 800000000.0;   //no cross
    }else{
      return 0.0;   //cross
    }

  }
}

Measured memory_bytes: 46488
#include <bits/stdc++.h>
#include <queue>
#define REP(i, n) for (ll i = 1; i <= n; i++)
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ll long long
#define ld long double
using namespace std;

int main()
{
    ll N, M, X;
    ll ans = INT_MAX;
    bool flag = false;
    cin >> N >> M >> X;
    vector<ll> C(N);
    vector<vector<ll>> A(N, vector<ll>(M));

    rep(i, N)
    {
        cin >> C[i];
        rep(j, M)
        {
            cin >> A[i][j];
        }
    }
    //Ciはi冊目(1<=i<=N)の値段
    //Aijはi冊目j(1<=j<=M)番目のアルゴリズムの理解度の上昇値

    for (int tmp = 0; tmp < (1 << N); tmp++)
    {
        bitset<12> bs(tmp);
        string cut = bs.to_string().substr(12 - N);
        vector<int> data(M, 0);
        ll cost = 0;
        rep(i, N)
        {
            if (cut.at(i) == '1')
            {
                cost += C[i];
                rep(j, M)
                {
                    data[j] += A[i][j]; //理解度アップ
                }
            }
        }

        int counter = 0;
        rep(i, M)
        {
            if (data[i] >= X)
            {
                counter++;
            }
        }

        if (counter == M)
        {
            ans = min(ans, cost);
            flag = true;
        }
    }
    if (flag)
    {
        cout << ans << endl;
    }
    else
    {
        cout << "-1" << endl;
    }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
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; }
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;}
int const INF = 1001001001;
ll const MOD = 1000000007;


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

string s;
cin >> s;

int N = s.size();
int Left[N];
int cur = 0;

int ans = 0;

rep(i,N) {
    if(s[i] != 'A' && s[i] != 'G' && s[i] != 'C' && s[i] != 'T') cur = 0;
    else cur++;
    Left[i] = cur;
    ans = max(ans , Left[i]);
}

cout << ans << endl;

return 0;
}

Measured memory_bytes: 256
import sys
mapin = lambda: map(int, sys.stdin.readline().split())
listin = lambda: list(map(int, sys.stdin.readline().split()))
inp = lambda: sys.stdin.readline()

N = int(inp())
mp = {}
for i in range(N):
    S = inp()
    S = S[:-1]
    if S in mp:
        mp[S] += 1
    else:
        mp[S] = 1
ans = 0
vec = []
for i in mp.values():
    if ans < i:
        ans = i
for i in mp.keys():
    if mp[i] == ans:
        vec.append(i)
vec.sort()
for i in vec:
    print(i)

Measured memory_bytes: 35416
defmodule Main do
  def main do
    [_n, k] = IO.gets("") |> String.trim() |> String.split() |> Enum.map(&String.to_integer/1)

    IO.gets("")
    |> String.trim()
    |> String.split()
    |> Enum.map(&String.to_integer/1)
    |> Enum.sort()
    |> Enum.take(k)
    |> Enum.sum()
    |> IO.puts()
  end
end

Measured memory_bytes: 30816
import sys
input = sys.stdin.readline

input()
A = list(map(int, input().split()))
N = len(A)

if N <= 2:
    print(max(A))
    exit()

def gcd(a, b):
    if b == 0: return a
    return gcd(b, a%b)

ans = 1
left_gcd = [0]
left_gcd[0] = A[0]
right_gcd = [0]
right_gcd[0] = A[N-1]

for i in range(1,N):
    if left_gcd[i-1] > A[i]:
        left_gcd.append(gcd(left_gcd[i-1], A[i]))
    else:
        left_gcd.append(gcd(A[i], left_gcd[i-1]))
    if right_gcd[i-1] > A[N-1-i]:
        right_gcd.append(gcd(right_gcd[i-1], A[N-1-i]))
    else:
        right_gcd.append(gcd(A[N-1-i], right_gcd[i-1]))
right_gcd.reverse()

g = [left_gcd[N-2], right_gcd[1]]

for i in range(1,N-1):
    l = left_gcd[i-1]
    r = right_gcd[i+1]
    if l > r:
        g.append(gcd(l,r))
    else:
        g.append(gcd(r,l))

print(max(g))

Measured memory_bytes: 14080
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}



int main(){
#ifdef LOCAL_REDIR
  freopen("/home/hog/Dropbox/pg/working/in.txt","r",stdin);
#endif
  int N;cin>>N;
  double want=4.0/N;
  const double EPS=1e-4;
  const double EPS2=1e-10;
  REPN(i,3505,1) REPN(j,3505,1){
      double rest=want-1.0/i-1.0/j;
      if(rest>EPS){
        int K=1.0/rest+EPS2;
        int L=1.0/rest+1-EPS2;
        if(K==L){
          printf("%d %d %d\n",i,j,K);
          return 0;
        }
      }
    }

  return 0;
}






Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    if(m < n)
        swap(n, m);

    long long ans = 0;
    if(n == 1){
        if(m == 1)
            ans = 1;
        else if(m > 2)
            ans = m - 2;
    }
    else if(n > 2){
        ans = (n - 2LL) * (m - 2LL);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
import java.io.*;

public class Main{
	public static void main(String[] args)throws IOException, NumberFormatException{
		BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();
		
		while(true){
			String[] s = br.readLine().split(" ");
			int h = Integer.parseInt(s[0]);
			int w = Integer.parseInt(s[1]);
			if( h==0 && w==0 ) break;
			
			// ???????????°?????????
			for( int i=1 ; i<=h ; i++ ){
				// ????????°?????????
				for( int j=1 ; j<=w ; j++ ){
					if( i%2==1 ){
						if( j%2==1 ){					
							builder.append("#");
						}else{
							builder.append(".");
						}
					}else{
						if( j%2==0 ){
							builder.append("#");
						}else{
							builder.append(".");
						}
					}
				}//???
				builder.append("\n");
			}//??????
			builder.append("\n");
		}
		System.out.print(builder);
	}
}

Measured memory_bytes: 25236
#include <atcoder/convolution>
#include <atcoder/modint>
#include <cstdio>

using namespace std;
using namespace atcoder;

using mint = modint998244353;

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    vector<mint> a(n), b(m);
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        a[i] = x;
    }
    for (int i = 0; i < m; i++) {
        int x;
        scanf("%d", &x);
        b[i] = x;
    }

    auto c = convolution(a, b);

    for (int i = 0; i < n + m - 1; i++) {
        printf("%d ", c[i].val());
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 18992
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let k: usize = read();
    let mut xs = vec![0 as i64; n];
    let mut ys = vec![0 as i64; n];
    for i in 0..n {
        xs[i] = read();
        ys[i] = read();
    }
    let mut sorted_xs = xs.clone();
    let mut sorted_ys = ys.clone();
    sorted_xs.sort();
    sorted_ys.sort();
    let mut ans = 1i64 << 62;
    for yleft in 0..n {
        for yright in yleft + 1..n {
            for xleft in 0..n {
                for xright in xleft + 1..n {
                    let mut sum = 0;
                    for i in 0..n {
                        if sorted_xs[xleft] <= xs[i] && xs[i] <= sorted_xs[xright]
                            && sorted_ys[yleft] <= ys[i]
                            && ys[i] <= sorted_ys[yright]
                        {
                            sum += 1;
                        }
                    }
                    if sum == k {
                        let area = (sorted_xs[xright] - sorted_xs[xleft])
                            * (sorted_ys[yright] - sorted_ys[yleft]);
                        ans = std::cmp::min(ans, area);
                    }
                }
            }
        }
    }
    println!("{}", ans);
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const int INF = 1e9;

int main() {
  ll n, k, t = 0;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll l = 0, r = 1e9 + 1, m;
  while (r - l > 1) {
    m = (l + r) / 2;
    t = 0;
    rep(i, n) t += (a[i] - 1) / m;
    if (t <= k)
      r = m;
    else
      l = m;
  }

  cout << r << endl;
  return 0;
}


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

int gcd2(int a, int b) {
  if(a > b) {
    int hold = a;
    a = b;
    b = hold;
  }

  if(b % a == 0) return a;
  else {
    int hold = a;
    a = b % a;       
    b = hold;
    return gcd2(a, b);
  }
}

int gcd3(int a, int b, int c) {
  return gcd2(gcd2(a, b), c);
}

int main() {
  int K;
  cin >> K;
  long result = 0;

  for(int i=1; i<=K; i++) {
    for(int j=1; j<=K; j++) {
      for(int k=1; k<=K; k++) {
        result += gcd3(i, j, k);
      }
    }
  }

  cout << result << endl;
  return 0;
}


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

#define max(a,b) (a>b?a:b)

int main() {
  int n, s, r, ans;
  vector<int> rv;
  while(cin >> n >> s && n && s) {
    rv.clear();
    for(int i=0; i<n; ++i) {
      cin >> r;
      rv.push_back(r);
    }
    sort(rv.begin(), rv.end());
    int idx = 0; ans = 0;
    for(int i=0; i<n; ++i) {
      while(i<n-idx-1 && rv[i]+rv[n-idx-1]>s) idx++;
      ans += n - max(i, n-idx-1) - 1;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1324
#include<stdio.h>
int main()
{
	char s[16];
	int a,b,i;
	for(i=0;i<9;i++){
		scanf("%s%d%d",s,&a,&b);
		printf("%s %d %d\n",s,a+b,a*200+b*300);
	}
	return 0;
}

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

class UnionFind
{
    public:
        const int n;
        vector<int> rank;
        vector<int> parent;
    
        UnionFind(int num_node): n(num_node)
        {
            rep(i, 0, n)
            {
                rank.push_back(0);
                parent.push_back(i);
            }
        }

        int root(int x)
        {
            if (parent[x] == x)
                return x;
            else
                return parent[x] = root(parent[x]);
        }

        void unite(int x, int y)
        {
            x = root(x);
            y = root(y);

            if (x == y) return;

            if (rank[x] > rank[y])
                parent[y] = x;
            else if(rank[x] == rank[y])
            {
                parent[x] = y;
                rank[y]++;
            }
            else
                parent[x] = y;
            return;
        }

        bool is_same(int x, int y)
        {
            return root(x) == root(y);
        }
};

int main()
{
    int n, q;
    cin >> n >> q;
    UnionFind uf_tree(n);

    rep(i, 0, q)
    {
        int c, x, y;
        cin >> c >> x >> y;

        if (c)
            cout << int(uf_tree.is_same(x, y)) << endl;
        else
            uf_tree.unite(x, y);

        // rep(j, 0, uf_tree.parent.size())
        //     cout << uf_tree.parent[j] << ' ';
        // cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3280
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
void READ() {
#define R READ();
#define INFI 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MEMX(x,num) memset(x,num,sizeof(x))
#define prln(x) cout<<#x<<"="<<x<<endl
#define prt(x) cout<<x<<endl
#define prk(x) x<<" "
#define sz(x) int(x.size())
#define PB(x) push_back(x)
#define LINK(x,y) G[x].PB(y),G[y].PB(x)
#ifndef ONLINE_JUDGE
    freopen("A.in", "r", stdin);
#endif
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(3);
}
///////////////////////////
const int N = 5 + 1e5;
const int MOD = 1e9 + 7;
int n;
LL c, s4[N], s1[N], s2[N], s3[N], ma1[N], ma2[N], ma3[N], ma4[N],x[N],v[N] ,ans;
int main() {

    cin >> n >> c;
    for(int i = 1; i <= n; i++) {
        cin >> v[i] >> x[i];
    }
    for(int i = 1; i <= n; i++) {
        s1[i] = s1[i - 1] + x[i];
    }
    for(int i = n; i; i--) {
        s2[i] = s2[i + 1] + x[i];
    }
    for(int i = 1; i <= n; i++) {
        s1[i] -= v[i];
        s3[i] = s1[i] - v[i];
        s2[i] -= c - v[i];
        s4[i] = s2[i] - (c - v[i]);
    }
    for(int i = 1; i <= n; i++) {
        ma1[i] = max(ma1[i - 1], s1[i]);
        ma3[i] = max(ma3[i - 1], s3[i]);
        ans = max(ans, ma1[i]);
    }
    for(int i = n; i; i--) {
        ma2[i] = max(ma2[i + 1], s2[i]);
        ma4[i] = max(ma4[i + 1], s4[i]);
        ans = max(ans, ma2[i]);
    }
    for(int i = 0; i <= n; i++) {
        ans = max(ans, max(ma1[i] + ma4[i+1], ma2[i+1]+ ma3[i]));
    }
    cout << ans;
    return 0;
}



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

struct P
{
    int x,y;

    bool operator<(const P &a)const{
              return x>a.x;
    }

};

vector<P> v[101103];
//bitset<4001000> b;
int a,c,i,b,k,n,d,m;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int o[100130];
int l[101103];
double j[1030];
int e[110];
int dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long x,y,mod=998244353;
long long z;
double pi=3.14159265;
P u[10600];
stack<int> s;

//set<int> s;
queue<int> q;

//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p,p1;
//list<int> l;

string r;
//char r[133];
//deque<int> de;
bool as(P a,P b)
{
    if(o[a.x]!=o[b.x])
    return o[a.x]<o[b.x];
    return a.y<b.y;
}


int main()
{
    scanf("%d %d",&a,&b);
    if(a+b==15) puts("+");
    else if(a*b==15) puts("*");
    else puts("x");
}


Measured memory_bytes: 2560
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int max = 0;
		int min = 123;
		int x;
		for (int i=0; i<5;i++) {
			x = sc.nextInt();
			max  =Math.max(max,x);
			min = Math.min(min,x);
		}
		int k = sc.nextInt();
		if (max - min > k)
			System.out.println(":(");
		else
			System.out.println("Yay!");
	}
}


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

long long func(long long N, long long x){
	if(N<0){
		return 0;
	}
	return N/x + 1;
}

int main(void){
	long long a,b,x,ans;
	cin>>a>>b>>x;
	ans = func(b,x)-func(a-1,x);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(lambda a: int(a) - 1, input().split()))

T = [A]
for _ in range(64):
    prev = T[-1]
    T.append([prev[a] for a in prev])

now = 0
for d, P in enumerate(T):
    if ((1 << d) & K) > 0:
        now = P[now]
print(now + 1)


Measured memory_bytes: 120296
let (x, y) = readInts().mapToTuple()
let odd = y.isMultiple(of: 2)
let c = (2*x ... 4*x).contains(y)
print(odd && c ? "Yes" : "No")


// MARK: -----------------------------------------------------------------------


func readInts() -> [Int] {
    readLine()!.split(separator: " ").map { Int($0)! }
}

extension Collection {
    func mapToTuple() -> (Element, Element) {
        var i = makeIterator()
        return (i.next()!, i.next()!)
    }
    func mapToTuple() -> (Element, Element, Element) {
        var i = makeIterator()
        return (i.next()!, i.next()!, i.next()!)
    }
    func mapToTuple() -> (Element, Element, Element, Element) {
        var i = makeIterator()
        return (i.next()!, i.next()!, i.next()!, i.next()!)
    }
}

struct DP<Argument: Hashable, Element> {
    var dictionary = [Argument: Element]()
    
    var expression: (Argument, (Argument) -> Element) -> Element
    
    init(expression: @escaping (_ argument: Argument, _ note: (Argument) -> Element) -> Element) {
        self.expression = expression
    }
    
    subscript(_ argument: Argument) -> Element {
        mutating get {
            if let note = dictionary[argument] {
                return note
            } else {
                let result = expression(argument) { self[$0] }
                dictionary[argument] = result
                return result
            }
        }
    }
}


Measured memory_bytes: 8244
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
	//freopen("input.txt", "r", stdin);
	char a,b;
		scanf("%c %c",&a,&b);
		if(a=='H'&&b=='H') printf("H\n");
		else if(a=='H'&&b=='D') printf("D\n");
		else if(a=='D'&&b=='H') printf("D\n");
		else printf("H\n");
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
dp = [0, -10**20]
tmp = [0, 0]

for i in range(N):
    tmp[0] = max(dp[0] + A[i], dp[1] - A[i])
    tmp[1] = max(dp[0] - A[i], dp[1] + A[i])
    dp[0], dp[1] = tmp[0], tmp[1]
print(dp[0])

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

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

}



Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
typedef long long ll;

int N, M;
typedef vector<vector<int> > Mat;

Mat pow(Mat A, Mat B)
{
	vector<vector<int> > nmat(N);
	nmat.assign(N, vector<int>(N));
	
	
	for (int i=0; i<N; i++) {
		for (int j=0; j<N; j++) {
			nmat[i][j] = 0;
			for (int k=0; k<N; k++) {
				nmat[i][j] += A[i][k]*B[k][j];
				nmat[i][j] %= M;
			}
		}
	}
	
	return nmat;
}



Mat pow_mod(Mat x, ll y)
{
	vector<vector<int> > res(N); 
	res.assign(N, vector<int>(N));
	
	for (int i=0; i<N; i++) {
		for (int j=0; j<N; j++) {
			res[i][j] = i==j?1:0;
		}
	}
	
	for (; y>0; y>>=1, x=pow(x, x)) {
		if (y&1) res=pow(res, x);
	}
	
	return res;
}

int main()
{
	int  A, B, C; ll T;
	while (cin>>N>>M>>A>>B>>C>>T, N||M||A||B||C||T) {
		Mat mat(N); 
		mat.assign(N, vector<int>(N));
		
		int S[N];
		
		for (int i=0; i<N; i++) {
			cin>>S[i];
		}
		
		int base=-1;
		for (int i=0; i<N; i++) {
			for (int j=0; j<N; j++) {
				if (j==base)
					mat[i][j] = A;
				else if (j==base+1)
					mat[i][j] = B;
				else if (j==base+2)
					mat[i][j] = C;
				else
					mat[i][j] = 0;
			}
			base++;
		}
		
		mat = pow_mod(mat, T);
		// cerr << "mat = " << endl;
#if 0
		for(int i = 0; i < N; ++i) {
			for(int j = 0; j < N; ++j) {
				cerr << mat[i][j] << " ";
			}
			cerr << endl;
		}
#endif
		
		// cerr << "ans = " << endl;
		for (int i=0; i<N; i++) {
			int t=0;
			for (int j=0; j<N; j++) {
				t += S[j]*mat[i][j];
				t %= M;
			}
			if (i!=0) cout << " ";
			cout << t;
		}
		cout << endl;
	} 
}

Measured memory_bytes: 1320
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
//#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
bool prime(int n){
	for(int i=2;i*i<=n;i++){
		if(n%i==0)
			return 0;
	}
	return 1;
}
int main(){
	int num=0;
	int N;
	cin>>N;
	vint ans;
	for(int i=2;num<N;i++){
		if(prime(i)==0)
			continue;
		if(i%5==2){
			ans.pb(i);
			num++;
		}
	}
	for(int i=0;i<ans.size()-1;i++)
		cout<<ans[i]<<" ";
	cout<<ans.back()<<endl;
	return 0;
}

Measured memory_bytes: 256