akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#include <sstream>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const int INF=0x7ffffff;
const int magic=348;

int n;
int a[100048];

int main ()
{
	int i,ans=0;
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	for (i=1;i<=n;i++)
	{
		if (a[i]!=i) continue;
		swap(a[i],a[i+1]);ans++;
	}
	printf("%d\n",ans);
	return 0;
}

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




int main(void) {
    
    int x;
    cin>>x;
    if(x==7||x==5||x==3){
        fin("YES");
    } else {
        fin("NO");
    }

}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

int n,m;
char s[105][105];
int f[105][105];

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
	
	if(s[1][1]=='.')f[1][1]=0;
	else f[1][1]=1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			if(i==1 && j==1) continue;
			if(i==1){
				if(s[i][j]=='.') f[i][j]=f[i][j-1];
				else f[i][j]=f[i][j-1]+(s[i][j-1]=='.');
			}
			else if(j==1){
				if(s[i][j]=='.') f[i][j]=f[i-1][j];
				else f[i][j]=f[i-1][j]+(s[i-1][j]=='.');
			}
			else{
				if(s[i][j]=='.') f[i][j]=min(f[i-1][j],f[i][j-1]);
				else 
					f[i][j]=min(f[i-1][j]+(s[i-1][j]=='.'),f[i][j-1]+(s[i][j-1]=='.'));
			}
		}
	printf("%d\n",f[n][m]);
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int data1[4][3][10] = {};

int main()
{
	int n, b, f, r, v;
	int i, j, k;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> b >> f >> r >> v;
		data1[b - 1][f - 1][r - 1] += v;
	}
	//
	for (i = 0; i < 4; i++)
	{
		for (j = 0; j < 3; j++)
		{
			for (k = 0; k < 10; k++)
			{
				if (data1[i][j][k] != 0)
				{
					cout << " " << data1[i][j][k];
				}
				else
				{
					cout << " 0";
				}
			}
			cout << endl;
		}
		if (i != 3)
		{
			cout << "####################" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3048
import sys
from operator import itemgetter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
MOD = 998244353


class SegmentTree1():
    """
    1-indexed Segment Tree
    """
    def __init__(self, n_, ele_id, op_func):
        self.n = 1 << (n_ - 1).bit_length()  # size
        self.data = [ele_id] * (2 * self.n)  # binary tree (1-indexed)
        self.ele_id = ele_id  # identity element
        self.op_func = op_func  # binary operation of monoid

    def __getitem__(self, i):
        return self.data[i + self.n]

    def build(self, data_init):
        for i in range(len(data_init)):
            self.data[i + self.n] = data_init[i]  # set data in leaf
        for i in reversed(range(self.n)):
            self.data[i] = self.op_func(self.data[2 * i], self.data[2 * i + 1])

    def update(self, i, x):
        # change i-th element to x (i : 0-indexed)
        i += self.n
        self.data[i] = x
        while i > 1:
            i = i >> 1  # go to parenet-node
            self.data[i] = self.op_func(self.data[2 * i], self.data[2 * i + 1])

    def query(self, l, r):
        # query for interval [l, r) (l, r : 0-indexed)
        l += self.n
        r += self.n
        ret = self.ele_id
        while l < r:
            if l & 1:  # right child
                ret = self.op_func(ret, self.data[l])
                l += 1
            if r & 1:  # right child
                r -= 1
                ret = self.op_func(ret, self.data[r])
            # go to parent-nodes
            l = l >> 1
            r = r >> 1
        return ret


n = int(input())
robot = [tuple(map(int, input().split())) for _ in range(n)]
robot.sort(key=itemgetter(0))
x = [robot[i][0] for i in range(n)]

# dp[i] = (i番目のロボットを起動すると最終的にdp[i]番目まで起動する)
dp = [0] * n
dp[n - 1] = n - 1

st_rmq = SegmentTree1(n, 0, max)
st_rmq.update(n - 1, dp[n - 1])
for i in reversed(range(n - 1)):
    r = bisect_left(x, x[i] + robot[i][1])
    dp[i] = max(i, st_rmq.query(l=i + 1, r=r))
    st_rmq.update(i, dp[i])

# print(robot)
# print(dp)

dp2 = [0] * (n + 1)
dp2[n] = 1
for i in reversed(range(n)):
    dp2[i] = dp2[i + 1] + dp2[dp[i] + 1]
    dp2[i] %= MOD
# print(dp2)

print(dp2[0])


Measured memory_bytes: 101640
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main(){
    ll n,m;
    cin>>n>>m;
    ll ans=1;
    for(ll i=1;i<=sqrt(m);i++) {
        if (m % i == 0&&(m/i)>=n) {
           ans=max(ans,i);
        }
        if(m%i==0&&i>=n){
            ans=max(ans,m/i);
        }
    }
    //cout<<m/31250;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
code = r"""
# distutils: language=c++
from libcpp.set cimport set
from libcpp.vector cimport vector
from libcpp.iterator cimport iterator
from cython.operator cimport dereference as deref, predecrement as dec
cdef int n = int(input()), i
cdef long c
cdef iterator it, jt
cdef vector[long] a = [*map(int, input().split())]
cdef vector[long] l = [0] * n
for i in range(n): l[a[i] - 1] = i
cdef set[long] s = set[long]([-1, n])
for i in range(n):
    c += (deref(s.lower_bound(l[i])) - l[i]) * (l[i] - deref(dec(s.lower_bound(l[i])))) * (i + 1)
    s.insert(l[i])
print(c)
"""
import os, sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    open('solve.pyx', 'w').write(code)
    os.system('cythonize -i -3 -b solve.pyx')
import solve

Measured memory_bytes: 34512
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, M;
  cin>>N>>M;
  vector<ll> x(N), y(M);
  for(int i=0;i<N;++i){
    cin>>x[i];
  }
  for(int i=0;i<M;++i){
    cin>>y[i];
  }
  ll tmpans = 0;
  for(int j=0;j<M-1;++j){
    tmpans += (y[j+1]-y[j])*(j+1)*(M-j-1);
    tmpans %= mod;
  }
  ll ans = 0;
  for(int i=0;i<N-1;++i){
    ans += (x[i+1]-x[i])*(i+1)%mod*(N-i-1)%mod*tmpans%mod;
    ans %= mod;
  }
  cout<<ans<<endl;
}



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

int main() {
    int n, m, a[100][100], b[100];
    int i, j;

    cin >> n >> m;
    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    for (i = 0; i < m; i++) {
        cin >> b[i];
    }

    for (i = 0; i < n; i++) {
        int c = 0;
        for (j = 0; j < m; j++) {
            c += a[i][j] * b[j];
        }
        cout << c << endl;
    }

    return 0;
}

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

int main()
{
	int N, Y;
	cin >> N >> Y;
	int Z = Y / 5000;
	int a[3] = { -1, -1, -1 };
	for (int i = 0; i <= Z / 2; i++) {
		for (int j = 0; j <= Z; j++) {
            int n = (Y - i * 10000 - j * 5000) / 1000;
			if (n == N - i - j && n >= 0) {
				a[0] = i;
				a[1] = j;
				a[2] = N - i - j;
				break;
			}
		}
	}
	cout << a[0] << " " << a[1] << " " << a[2] << endl;
}

Measured memory_bytes: 256
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [, , X] = input[0].map(Number);
  const A = input[1].map(Number);

  const right = A.findIndex((num) => num > X);

  if (right === -1) {
    return 0;
  }

  return Math.min(right, A.length - right);
};

console.log(main(read()));


Measured memory_bytes: 29600
#define DEBUG 0
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::vector<lint> a(n); std::cin>>a;
  debug(a);
  rep(i,0,n) {
    a.at(i) -= i;
  }
  debug(a);
  std::sort(all(a));
  debug(a);
  lint mid = *(a.begin()+n/2);
  lint ans = 0;
  for (lint x : a) {
    lint now = x - mid;
    if (now < 0) now = -now;
    ans += now;
  }
  std::cout << ans << std::endl;
  return 0;
}

/*
予め各成分から添字分引いておくことで、abs(A_i-b) の和を最小化する問題になります。
こちらは中央値を取ればよいです。
*/

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;


int main(void) {
    int n, i, j, l[30] = {};
    ll ans = 1;
    string a;

    cin >> a;

    n = a.size();

    for (i = 0; i < n; i++) {
        l[a[i] - 'a']++;
    }

    for (i = 0; i < 26; i++) for (j = i + 1; j < 26; j++) {
        ans += (ll)l[i] * l[j];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
 
int main() {
  int a,b;
  cin >> a >> b;
  
  if(b%a==0){
    cout << a+b <<endl;
  } else {
    cout << b-a<< endl;
  }
 
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=true;
/*---------------------------------------------------*/

int imos[1265];
//plog[????????????][PC??????]
int plog[1005][10005];

void init(){
  rep(i,1265)imos[i]=0;
}

int main(){
  int N,M;
  int r,q;
  int t,n,m,s;
  while(cin>>N>>M){
    if(N==0&&M==0)break;
    vector<pi> data[M+1];
    cin>>r;
    rep(i,r){
      //input data
      cin>>t>>n>>m>>s;
      if(s){
	plog[n][m]=t;
      }else{
	data[m].pb(mp(plog[n][m],t));
	plog[n][m]=0;
      }
    }
    //question
    cin>>q;
    rep(i,q){
      int ts,te;
      init();
      cin>>ts>>te>>m;
      rep(j,data[m].size()){
	imos[data[m][j].first]+=1;
	imos[data[m][j].second+1]-=1;
      }
      REP(j,1,1265)imos[j]+=imos[j-1];
      int ans=0;
      int cnt=0;
      REP(j,ts,te+1){
	if(imos[j])cnt++;
	else {ans+=max(cnt-1,0);cnt=0;}
      }
      ans+=max(cnt-1,0);
      cout<<ans<<endl;
    }
  }
}

Measured memory_bytes: 11436
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int N;
char S;
int main(){
  int Lj4PdHRW, res=3;
  rd(N);
  for(Lj4PdHRW=0;Lj4PdHRW<(N);Lj4PdHRW++){
    rd(S);
    if(S=='Y'){
      res = 4;
    }
  }
  if(res==3){
    wt_L("Three");
    wt_L('\n');
  }
  else{
    wt_L("Four");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190822-2

// --- original code ---
// int N;
// char S;
// {
//   int res = 3;
//   rd(N);
//   rep(N){
//     rd(S);
//     if(S=='Y') res = 4;
//   }
//   wt( if[res==3, "Three", "Four"] );
// }


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define REP(i,n) for(int i = 1; i < (n); i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n")

using ll = long long;
using P = pair<int,int>;
using vi = vector<int>; 
using vii = vector<vi>;

const int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int dy[8] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1; 


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

  int n;
  cin >> n;
  vi x(n);
  rep(i,n) cin >> x[i];
  vector<int> y = x;
  sort(all(y));
  int lm = y[n/2-1];
  int rm = y[n/2];
  rep(i,n){
    if(x[i] <= lm) cout << rm << endl;
    else cout << lm << endl;
  }
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int h1,h2,m1,m2,k,ans;
int main(){
    scanf("%d %d %d %d %d",&h1,&m1,&h2,&m2,&k);
    if(m1>m2) h2--,m2+=60; 
    if(h1>h2) h2+=24;
    ans=(h2-h1)*60+m2-m1-k;
    printf("%d\n",ans);
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  int a = 10*(s[0]-'0')+s[1]-'0';
  int b = 10*(s[2]-'0')+s[3]-'0';
  if(a == 0 or a > 12){
    if(b == 0 or b > 12) cout << "NA";
    else cout << "YYMM";
  }
  else{
    if(b == 0 or b > 12) cout << "MMYY";
    else cout << "AMBIGUOUS";
  }
  return 0;
}


Measured memory_bytes: 256
#include<set>
#include<map>
#include<ctime>
#include<queue>
#include<cmath>
#include<climits>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
    int f=1,x=0;char s=getchar();   
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}  
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
    return x*f;
}
#define MAXN 100
#define INF 0x3f3f3f3f
int can[MAXN+5];
int main(){
	int n=read(),x=read();
	LL sum=0;int t=0;
	for(int i=1;i<=n;i++)
		can[i]=read(),sum+=can[i];
	sort(can+1,can+n+1);
	if(sum<x){
		printf("%d\n",n-1);
		return 0;
	}
	sum=0;
	while(t<n&&sum+can[t+1]<=x){
		sum+=can[t+1],t++;
		if(sum==x) break;
	}
	printf("%d\n",t);
	return 0;
}

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

using namespace std;
const string YES = "Yes";
const string NO = "No";

void solve(int N) {
  REP(i, N / 7 + 1)
    if ((N - i * 7) % 4 == 0) {
      cout << YES << endl;
      return;
    }
  cout << NO << endl;
}

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

  int N;
  cin >> N;

  solve(N);

  return 0;
}


Measured memory_bytes: 3664
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>

using namespace std;
typedef long long LL;
const int maxn = 2005;
const int mod = 924844033;

int h[maxn][maxn];
int g[maxn][maxn];
int f[maxn],e[maxn],v[maxn];
int n,fac[maxn],inc[maxn],sz[maxn],K;

LL fpm(LL p,LL k) {
	LL res=1ll;
	while (k) {
		if (k&1) (res*=p)%=mod;
		(p*=p)%=mod;k>>=1;
	}
	return res;
}
LL comb(int n,int m) {
	return (LL)fac[n]*inc[m]%mod*(LL)inc[n-m]%mod;
}
int main()
{
	#ifdef Amberframe
		freopen("agc005d.in","r",stdin);
		freopen("agc005d.out","w",stdout);
	#endif
	scanf("%d %d",&n,&K);fac[0]=inc[0]=1;
	for (int i=1;i<=n;i++)
	{
		if (i-2*K<=0) {
			sz[i]=1;g[i][0]=1;g[i][1]=(i>K);h[i][1]=(i+K<=n);
		}
		else {
			int o=i-2*K;sz[i]=sz[o]+1;
			for (int j=0;j<=sz[i];j++)
				g[i][j]=(g[o][j]+h[o][j])%mod;
			for (int j=1;j<=sz[i];j++)
				g[i][j]=(g[i][j]+g[o][j-1])%mod;
			if (i+K>n) continue;
			for (int j=1;j<=sz[i];j++)
				h[i][j]=(g[o][j-1]+h[o][j-1])%mod;
		}
	}
	
	for (int i=1;i<=n;i++) fac[i]=(LL)fac[i-1]*i%mod;
	inc[n]=fpm(fac[n],mod-2);
	for (int i=n;i>=2;i--) inc[i-1]=(LL)inc[i]*i%mod;
	
	f[0]=1;int sum=0;
	for (int i=1;i<=n;i++)
	if (i+2*K>n) {
		for (int k=sz[i];k>=0;k--)
			e[k]=(h[i][k]+g[i][k])%mod;
		for (int k=sum+sz[i];k>=0;k--) v[k]=0;
		for (int j=sum;j>=0;j--)
		for (int k=sz[i];k>=0;k--)
			v[j+k]=(v[j+k]+(LL)f[j]*e[k])%mod;
		for (int k=sum+sz[i];k>=0;k--) f[k]=v[k];
		sum+=sz[i];
	}
	
	for (int i=0;i<=n;i++)
		f[i]=(LL)f[i]*fac[n-i]%mod;
	for (int i=n-1;i>=0;i--)
	for (int j=i+1;j<=n;j++)
		f[i]=(f[i]-(LL)f[j]*comb(j,i))%mod;
	printf("%d",f[0]<0?f[0]+mod:f[0]);
	return 0;
}

Measured memory_bytes: 30720
#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>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;

vector<ll> A(200005);
vector<ll> d;
map<ll, ll> mp;

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

	ll N, K; cin >> N >> K;

	FOR(i, 0, N)cin >> A[i + 1];

	ll cur = A[1];
	ll len = 1;
	d.emplace_back(1);
	mp[1] = 1;

	while (mp[cur] == 0) {

		d.emplace_back(cur);
		mp[cur] = ++len;
		cur = A[cur];

	}

	cur = mp[cur];
	if (K < len)cout << d[K] << endl;
	else {
		K -= cur - 1;
		cout << d[cur - 1 + K % (len - cur + 1)] << endl;
	}


	return 0;
}


Measured memory_bytes: 18176
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <stdlib.h>
#include <stdint.h>

using namespace std;

int main()
{
	intmax_t A, B, ans = -1;
   //uintmax_t ;
 //long double ;

	  //string ;
	cin >> A >> B;

	if (A <= 9 && B <= 9)
		ans = A * B;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vector<int>>;  // int <=> ll
using P = pair<int, int>;
const int INFTY = 1e9+7;

int main() {
  int N, M;
  cin >> N >> M;
  Graph edge(N);
  rep(i,M) {
    int u, v;
    cin >> u >> v;
    --u; --v;
    edge[u].push_back(v);
  }
  int S, T;
  cin >> S >> T;
  --S; --T;

  Graph path(N, vi(3, INFTY));
  queue<int> que;
  que.push(S);
  path[S][0] = 0;

  while (!que.empty()) {
    int v = que.front(); que.pop();
    for (auto nv : edge[v]) {
      bool visited = false;
      rep(i,3) {
        int j = (i+1) % 3;
        if (path[v][i] + 1 < path[nv][j]) {
          path[nv][j] = path[v][i] + 1;
          visited = true;
        }
      }
      if (visited) que.push(nv);
    }
  }

  if (path[T][0] == INFTY) cout << -1 << endl;
  else cout << path[T][0] / 3 << endl;
  return 0;
}


Measured memory_bytes: 11136
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
vector<int> a[MAXN],b[MAXN];
int col[MAXN];
bool flaga[MAXN],flagb[MAXN];
void add_edge(int x,int y){
	b[x].push_back(y);
	b[y].push_back(x);
}
int n,las;
int st[MAXN],top;
int dfn[MAXN],tot;
void dfs(int x,int flag){
	dfn[x]=++tot;
	if(a[x].size()%2==0){
		st[++top]=x;
		if(flag==0)
			flaga[x]=1;
		else
			flagb[x]=1;
	}
	for(int i=0;i<int(a[x].size());i++)
		dfs(a[x][i],flag);
	while(top>1&&dfn[st[top-1]]>=dfn[x]){
		add_edge(st[top],st[top-1]);
		top-=2;	
	}
}
queue<int> q;
void bfs(int x){
	col[x]=1;
	q.push(x);
	while(!q.empty()){
		int x=q.front();
		q.pop();
		for(int i=0;i<int(b[x].size());i++){
			int u=b[x][i];
			if(col[u]!=0)
				continue;
			col[u]=-col[x];
			q.push(u);	
		}
	}
}

int main(){
	SF("%d",&n);
	int u,rt;
	for(int i=1;i<=n;i++){
		SF("%d",&u);
		if(u!=-1)
			a[u].push_back(i);	
		else
			rt=i;
	}
	dfs(rt,0);
	las=0;
	for(int i=1;i<=n;i++) 
		a[i].clear();
	for(int i=1;i<=n;i++){
		SF("%d",&u);
		if(u!=-1)
			a[u].push_back(i);	
		else
			rt=i;
	}
	top=0;
	dfs(rt,1);
	for(int i=1;i<=n;i++)
		if(flaga[i]!=flagb[i]){
			PF("IMPOSSIBLE");
			return 0;
		}
	PF("POSSIBLE\n");
	for(int i=1;i<=n;i++)
		if(col[i]==0&&flaga[i]==1)
			bfs(i);
	for(int i=1;i<=n;i++)
		PF("%d ",col[i]);
}

Measured memory_bytes: 15872
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
import numpy as np
def resolve():
    N, M = lr()
    A, B, L, R = [], [], [], []
    for i in range(N):
        a, b = lr()
        A.append(a)
        B.append(b)
    A = np.array(A, np.int64)
    B = np.array(B, np.int64)
    idx = np.argsort(A)
    A = A[idx]
    B = B[idx]
    for i in range(M):
        l, r = lr()
        L.append(l)
        R.append(r)
    L = np.array(L, np.int64)
    R = np.array(R, np.int64)
    L = np.searchsorted(A, L, 'left').tolist()
    R = np.searchsorted(A, R, 'right').tolist()
    B = np.append(B, 0)
    C = np.zeros(len(B), np.int64)
    # 差分列
    C[1:] = B[:-1]^B[1:]
    C[0] = B[0]
    C = C.tolist()

    graph = [[] for _ in range(N+1)]
    for i, (l, r) in enumerate(zip(L, R)):
        if l < r:
            graph[l].append(r)
            graph[r].append(l)
    order = []
    parent = [0]*(N+1)
    close = [0]*(N+1)
    for v in range(N):
        if close[v]:
            continue
        stack = [v]
        order.append(v)
        parent[v] = -1
        close[v] = 1
        while stack:
            v = stack.pop()
            for w in graph[v]:
                if close[w]:
                    continue
                stack.append(w)
                order.append(w)
                close[w] = 1
                parent[w] = v

    E = []
    failed = False
    for v in order[::-1]:
        if C[v]:
            p = parent[v]
            if p == -1:
                failed = True
                break
            E.append((p,v))
            C[v] = 0
            C[p] ^= 1
    
    if failed:
        print(-1)
    else:
        I = {leri: i for i, leri in enumerate(zip(L, R), 1)}
        answer = []
        for v, w in E:
            if v > w:
                v, w = w, v
            answer.append(I[(v, w)])
        answer.sort()
        print(len(answer))
        if len(answer) > 0:
            print(*answer)
resolve()

Measured memory_bytes: 89008
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
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; }
const long long INF = 1LL << 60;

int main(){
  string s;
  cin >> s;
  if(s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2]){
    cout << "Yes" << endl;
  }
  else if(s[0]==s[2]&&s[1]==s[3]&&s[0]!=s[1]){
    cout << "Yes" << endl;
  }
  else if(s[0]==s[3]&&s[1]==s[2]&&s[0]!=s[1]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <cstring>

using namespace std;

int main()
{
    int N,i,cou=0;
    string S;
    cin>>N;
    cout<<endl;
    cin>>S;
   if(N>=3&&N<=50){
        for(i=0;i<N;i++){
            S[i]=toupper(S[i]);}
    for(i=0;i + 2<N; i++) {
    if(((char)S[i]=='A')&&((char)S[i+1]=='B')&&((char)S[i+2]=='C') ) {
                cou++;
                i=i+2;
            }}

    }
    cout<<cou;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 101000;

void solve(long long n, vector<long long> v){
    vector<int> odd_hist(MAX, 0), even_hist(MAX, 0);
    for(int i = 0; i < n; ++i){
        if(i % 2 == 0) even_hist[v[i]]++;
        else odd_hist[v[i]]++;
    }
    vector<pair<int, int> > odd, even;
    for(int i = 0; i < MAX; ++i){
        odd.push_back(pair<int, int>(odd_hist[i], i));
        even.push_back(pair<int, int>(even_hist[i], i));
    }
    sort(odd.begin(), odd.end(), greater<pair<int, int>>());
    sort(even.begin(), even.end(), greater<pair<int, int>>());
    if(odd[0].second != even[0].second){
        cout << n - odd[0].first - even[0].first << endl;
    }
    else{
        cout << n - max(odd[0].first + even[1].first, odd[1].first + even[0].first) << endl;
    }
    return;
}

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


Measured memory_bytes: 6684
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[1010][1010];
int main(){
	int n,m,A,B;
	cin>>n>>m>>A>>B;
	if(A*2>m||B*2>n)return puts("-1"),0;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++){
		if(i<=B&&j<=A)putchar('1');
		else if(i>B&&j>A)putchar('1');
		else putchar('0');
		if(j==m)puts("");
	}
	return 0;
}


Measured memory_bytes: 1280
# ABC 56 A

def resolve():
    a, b = input().split()
    if a == 'H' and b == "H":
        print("H")
    elif a == "H" and b == "D":
        print("D")
    elif a == 'D' and b == "H":
        print("D")
    elif a == "D" and b == "D":
        print("H")


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
static const double pi = 3.141592653589793;

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

	int A, B, H, M;
	scanf("%d %d %d %d", &A, &B, &H, &M);

	double H_rad = ((double)H + (double)M / (double)60) * ((double)2 * pi / (double)12);
	double M_rad = ((double)M / (double)60) * ((double)2 * pi);

	// cout << H_rad / pi << "\n";
	// cout << M_rad / pi << "\n";

	double result_result;

	result_result = (double)A * (double)A + (double)B * (double)B - (double)2 * (double)A * (double)B * cos(abs(H_rad - M_rad));

	// cout << sqrt(result_result);
	printf("%.20f", sqrt(result_result));

	return 0;
}

Measured memory_bytes: 4292
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct UnionFind{
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int size){init(size);}
  void init(int size){
    r.resize(size,0);
    p.resize(size,0);
    for(int i=0;i<size;i++) r[i]=1,p[i]=i;
  }
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};
bool solve(int odd,int eve){
  int msz=odd+eve;
  if(!odd) return 1;
  if(msz==2) return odd==0;
  if(msz%2==0) return 1;
  if((msz-2)/2>=odd/2) return 1; 
  return 0;
}
signed main(){
  int n;
  cin>>n;
  string s[n];
  for(int i=0;i<n;i++) cin>>s[i];
  UnionFind uf(n);
  int cnt=0;
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
      if(s[i][j]=='Y') uf.unite(i,j),cnt++;
  map<int,int> m;
  for(int i=0;i<n;i++) m[uf.find(i)]++;
  int step=n*(n-1)/2;
  int sz=0;
  for(int i=0;i<n;i++) if(uf.find(i)==i) sz++;
  //step-=(cnt+(sz-2));
  step-=cnt;
  //cout<<step<<":"<<sz<<":"<<cnt<<endl;
  if(n%2){
    cout<<(step%2==1?"Taro":"Hanako")<<endl;
    return 0;
  }
  int odd=0,eve=0,flg=0;
  for(auto p:m){
    if(p.second%2) odd++;
    else eve++;
  }
  
  map<int,int> c;
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
      if(s[i][j]=='Y') c[uf.find(i)]++;
  for(auto p:c){
    int k=m[p.first];
    flg|=k*(k-1)/2>p.second;
    //cout<<k*(k-1)/2<<" "<<p.second<<endl;
  }
  //cout<<step<<" "<<sz<<":"<<odd<<" "<<eve<<":"<<flg<<endl;
  if(step%2==0){
    cout<<(solve(odd,eve)==0?"Taro":"Hanako")<<endl;
  }else{
    bool f=(odd==0&&eve==2);
    //f|=solve(odd,eve);
    if(eve>=1&&odd+eve-1>=2) f|=solve(odd,eve-1);
    if(odd>=2&&odd+eve-1>=2) f|=solve(odd-2,eve+1);
    cout<<(f?"Taro":"Hanako")<<endl;
  }
  return 0;
}

Measured memory_bytes: 4192
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

int main(void) {
	int n, d; cin >> n >> d;
	vector<vector<int>> x(n, vector<int>(d));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			cin >> x[i][j];
		}
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int norm = 0;
			for (int k = 0; k < d; k++) {
				int diff = abs(x[i][k] - x[j][k]);
				norm += diff * diff;
			}
			bool flag = false;
			for (int k = 0; k <= norm; k++) {
				if (k * k == norm) flag = true;
			}
			if (flag) ans++;
		}
	}

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

Measured memory_bytes: 256
//C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

//ここまで毎回include
//以下プログラム

using namespace std;

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	string turn = a.substr(0, 1);
	while (a.size() != 0 || b.size() != 0 || c.size() != 0) {
		if (turn == "a") {
			if (a.size() == 0) {
				cout << "A" << endl;
				return 0;
			}
			turn = a.substr(0, 1);
			a.erase(0, 1);
		}
		else if (turn == "b") {
			if (b.size() == 0) {
				cout << "B" << endl;
				return 0;
			}
			turn = b.substr(0, 1);
			b.erase(0, 1);
		}
		else {
			if (c.size() == 0) {
				cout << "C" << endl;
				return 0;
			}
			turn = c.substr(0, 1);
			c.erase(0, 1);
		}
	}
}



Measured memory_bytes: 256
/*
Looking from a window above
It's like a story of love
Can you hear me?
Came back only yesterday
I'm moving further away
Want you near me
All I needed was the love you gave
All I needed for another day
And all I ever knew
Only you
Sometimes when I think of her name
When it's only a game
And I need you
Listen to the words that you say
It's getting harder to stay
When I see you
All I needed was the love you gave
All I needed for another day
And all I ever knew
Only you, only you
Uh uh uh only you, only you
Only you, only you, only you
This is going to take a long time
And I wonder what's mine
Can't take no more
Wonder if you'll understand
It's just the touch of your hand
Behind a closed door
And all I needed was the love you gave
All I needed for another day
And all I ever knew
Only you, only you, only you
All I needed was the love you gave
All I needed for another day
And all I ever knew
Only you, only you, only you
Only you
*/

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ld long double
#define endl '\n'
#define rep(x,s,e) for(int x=s;x<=(e);x++)
#define repn for(int x=0;x<n;x++)
#define rep1n for(int x=1;x<=n;x++)
#define rep1m for(int y=1;y<=m;y++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define bits(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) ((int)(x.size()))
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define see(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define see(x...)
#endif

const int inf = 3e18;
const int N = 5e5 + 100;




int32_t main(){ 
   FAST;
  int n; cin >> n;
  cout << (n+1)/2;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vdbl;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int> > vvint;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef priority_queue<int, vector<int>, greater<int> > spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll> > spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int> > bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll> > bpqll;        //大きい順に取り出し

#define REP(i, n) for (int(i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, b) for (int(i) = a; (i) < (int)b; i++)
#define IREP(i, v) for (auto i = v.begin(); i != v.end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, 1, -1};
const int dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
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; }     //最小公倍数

void yes()
{
    cout << "Yes" << endl;
}
void no()
{
    cout << "No" << endl;
}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w ;
    cin >> h >> w ;
    vector<string> s(h) ;
    REP(i,h){
        cin >> s[i] ;
    }
    vvint cnt(h,vint(w,0)) ;
    if(s[0][0]=='#'){
        cnt[0][0]++; 
    }

    FOR(i,1,w){
        if(s[0][i]=='#' && s[0][i-1]=='.'){
            cnt[0][i] = cnt[0][i-1] + 1 ;
        }
        else{
            cnt[0][i] = cnt[0][i-1] ;
        }
    }

    FOR(i,1,h){
        if(s[i][0]=='#' && s[i-1][0]=='.'){
            cnt[i][0] = cnt[i-1][0] + 1 ;
        }
        else{
            cnt[i][0] = cnt[i-1][0] ;
        }
    }


    FOR(i,1,h){
        FOR(j,1,w){
            int a, b ;
            a = cnt[i-1][j] ;
            b = cnt[i][j-1] ;
            if(s[i][j]=='#' && s[i-1][j]=='.'){
                a++ ;
            }
            if(s[i][j]=='#' && s[i][j-1]=='.'){
                b++ ;
            }
            cnt[i][j] = min(a,b) ;
        }
    }

    cout << cnt[h-1][w-1] <<endl ;





    

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
#include<climits>
#include<cmath>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

typedef unsigned int uint;
typedef long long ll;

using namespace std;
int sumall(char *buff){
  bool flag = false;
  int ret = 0;
  int tmp = 0;
  while(*buff != '\0'){
    while(*buff != '\0' && !isdigit(*buff))
      buff++;
    tmp = 0;
    while(*buff != '\0' && isdigit(*buff)){
      tmp *= 10;
      tmp += *buff - '0';
      buff++;
    }
    ret += tmp;
  }
  return ret;
}

int main(){
  char buff[256];
  int ans = 0;
  while(cin>>buff){
    ans += sumall(buff);
  }
  cout << ans << endl;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
typedef long long ll;

#define MAX(x, y)	(((x) > (y))? (x) : (y))
#define MIN(x, y)	(((x) < (y))? (x) : (y))
#define ABS(x)		(((x) < 0)? (-1*(x)) : (x))
#define REPI(x,y)	for (i=(x);i<(y);i++)
#define REPJ(x,y)	for (j=(x);j<(y);j++)
#define MEMCLR(X)	memset((X),0,sizeof((X)))

using namespace std;
int X,A,B;

int main() {
	cin >> X;
	cin >> A;
	cin >> B;
	
	cout << ((X-A)%B) << endl;
	
	return 0;
}

Measured memory_bytes: 256
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

a,b,t = m()

aa = l()

bb = l()

co = 0

ccc = 0

ans = 0

no = 0

aaa = [0 for i in range(a+1)]

for i in range(1,a+1):
	aaa[i] += aa[i-1] + aaa[i-1]

for i in range(b+1):
	if i != 0:
		no += bb[i-1]
	if t-no >= 0:
		popopo = bs.bisect_left(aaa,t-no)
		if popopo <= a and aaa[popopo] == t-no:
			popopo += 1
		
		ans = max(ans,i + popopo-1)

print(ans)


Measured memory_bytes: 115628
n=int(input())
a=[input() for _ in range(n)]
m=int(input())
t=[input() for _ in range(m)]

maxlist=[0]
for i in range(n):
    mx=0
    for j in range(n):
        if a[i]==a[j]:
            mx+=1
    for k in range(m):
        if a[i]==t[k]:
            mx-=1
    maxlist.append(mx)

print(max(maxlist))


Measured memory_bytes: 3064
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll int i,n,t,j=0,p,x,a=0,b,l=0,r=0,y,k,c,sum=0,m,d;
    cin>>n;
    string s,sm;
    a=0;b=0;c=0;d=0;
    for(i=0;i<n;i++){
        cin>>s;
        if(s[0]=='W'){
            a++;
        }
        else if(s[0]=='A'){
            b++;
        }
        else if(s[0]=='T'){
            c++;
        }
        else if(s[0]=='R'){
            d++;
        }
    }
    cout<<"AC x "<<b<<endl;
    cout<<"WA x "<<a<<endl;
    cout<<"TLE x "<<c<<endl;
    cout<<"RE x "<<d<<endl;

    return EXIT_SUCCESS;
}



Measured memory_bytes: 3656
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i=0; i<n; i++) cin >> a[i];

    copy(a.begin(), a.end(), b.begin());
    sort(b.begin(), b.end());

    int max = b[n-1], max2 = b[n-2];

    for(int i=0; i<n; i++) {
        if(a[i] == max)
            cout << max2 << endl;
        else
            cout<< max << endl;
    }

    return 0;
}

Measured memory_bytes: 3200
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int A, B, C, K;
    cin >> A >> B >> C >> K;
    if(K<=A){
        cout << K;
    }
    else if(A+B>=K){
        cout << A <<endl;
    }
    else{
        cout << A-(K-A-B) <<endl;
    }
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <limits>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <complex>
using namespace std;


int main() {
	int N;
	int t[3];
	int x[3];
	int y[3];

	int n = 0;

	cin >> N;
	for (int i = 0; i < N; i++) {
		n = i % 2;
		cin >> t[n] >> x[n] >> y[n];
		if (n >= 1) {
			if ((t[n] - t[n-1]) < abs(x[n] + y[n] - x[n-1] - y[n-1]) || ( (t[n] - t[n-1]) - abs(x[n] + y[n] - x[n-1] - y[n-1]) ) % 2 != 0 ) {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			if (t[n] < x[n] + y[n] || (t[n] - (x[n] + y[n])) % 2 != 0) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256