akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std ;

int main(){
  long long N , K ; 
  cin >> N >> K ; 
  vector<int> a(N) , b(N) ; 
  for(int i = 0 ; i < N ; i++) cin >> a.at(i) >> b.at(i) ; 
  
  long long cnt = 0 ; 
  long long ans = 0 ; 
  vector<pair<int , int>> ab(N) ; 
  
  for(int i = 0 ; i < N ; i++){
    ab.at(i) = make_pair(a.at(i) , b.at(i)) ; 
  }
  sort(ab.begin() , ab.end()) ; 
  for(auto p : ab){
    cnt += p.second ; 
    ans =  p.first ; 
    if(cnt >= K){
      cout << ans << endl;
      return 0 ; 
    }
  }
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int mmax(int a,int b,int c){
  if(a<b){
    return max(b,c);
  }else{
    return max(a,c);
  }
}

long long modinv(long long a) {
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}

long long devide(long long a,long long b){return (a*modinv(b))%mod;}


long long euclidean_gcd(long long a, long long b) {
  if(a < b) return euclidean_gcd(b, a);
  long long r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

long long ncr(long long n,long long r){
  long long i,plus=1;
  for(i=0;i<r;i++){
    plus=(plus*(n-i))%mod;
    plus=devide(plus,i+1);
  }
  return plus;
}


int main(){
  long long i,cnt=0,N,M,ans=1;
  scanf("%lld",&N);
  scanf("%lld",&M);
  if(N==1){
    printf("1\n");
    return 0;
  }
  for(i=2;i<M*M;i++){
    if(M%i==0){
      while(M%i==0){
        M/=i;
        cnt++;
      }
      if(N<cnt){ans=(ans*ncr(N+cnt-1,N))%mod;}
      else{ans=(ans*ncr(N+cnt-1,cnt))%mod;}
      //printf("%lld %lld\n",cnt,ans);
      cnt=0;
    }
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rg register
#define rep(i,a,b) for (rg int i=a;i<=b;i++)
#define per(i,a,b) for (rg int i=b;i>=a;i--)
#define pb push_back
#define lowbit(x) (x&(-x))
#define mk make_pair
#define VI vector<int>
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define fi first
#define se second
#define il inline
#define ll long long
#define db double
#define ld long double
#define inf 0x3f3f3f3f
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<15,stdin),p1==p2)?EOF:*p1++)
char buf[1<<15],*p1 = buf,*p2 = buf;
inline ll read(){
    #define num ch-'0'
    char ch;bool flag=0;ll res;
    while(!isdigit(ch=getc()))
    (ch=='-')&&(flag=true);
    for(res=num;isdigit(ch=getc());res=res*10ll+num);
    (flag)&&(res=-res);
    #undef num
    return res;
}
inline void write(ll x){
	if (x < 0) x = ~x + 1ll, putchar('-');
	if (x > 9) write(x / 10ll);
	putchar(x % 10ll + '0');
}
#define mid ((l + r)>>1)
#define ls (x<<1)
#define rs ((x<<1)|1)
#undef mid
#undef ls
#undef rs
#define maxn 101000
pii a[maxn];
void solve()
{
	int n = read();
	rep(i,1,n) a[i].fi = read(),a[i].se = i;
	sort(a+1,a+1+n);
	rep(i,1,n) cout<<a[i].se<<" ";
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("data.txt","r",stdin);
	#endif
//	int T = read();
//	while(T--)
	solve();
}

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

using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 2e5 + 5;

void debug_out() {
    cerr << endl;
}

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main() {
    FAST
    string h;
    cin>>h;
    if(h=="ABC")
        cout<<"ARC"<<endl;
    else
        cout<<"ABC"<<endl;
    return 0;
}


Measured memory_bytes: 3616
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define INF 10000000

int mp[18][18];
int main(){
	int a,b;
	while(cin>>a>>b){
		if(a==0&&b==0)break;
		CLR(mp);
		int n;
		cin>>n;
		REP(i,n){
			int x,y;
			cin>>x>>y;
			mp[x][y]=-1;
		}
		mp[1][1]=(mp[1][1]==-1)?-1:1;
		FOR(i,0,b+1)FOR(j,0,a+1){
			if(mp[j+1][i+1]!=-1){
				mp[j+1][i+1]+=((mp[j+1][i]==-1)?0:mp[j+1][i])+((mp[j][i+1]==-1)?0:mp[j][i+1]);
			}
		}
		if(mp[a][b]!=-1)cout<<mp[a][b]<<endl;
		else cout<<"0"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    String s=sc.next();
    int count=0;
    for (int i=0;i<3;i++) {
      if (s.charAt(i)=='1') {
        count++;
      }
    }

    System.out.println(count);
  }
}


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

using namespace std;
#define N 100100
#define SIGMA 26

const string answer[2] = {"No\n", "Yes\n"};

long long a, b, c, x, y, z;
int main()
{
    cin >> a >> b >> c;
    if (c - b - a < 0){
        cout << answer[0];
        return 0;
    }
    if (4 * a * b < (c - b - a) * (c - b - a))
        cout << answer[1];
    else
        cout << answer[0];
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> P;
typedef pair<long long,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
long long n,h[100005];
ll dp[100005];
#define ALL(v)  (v).begin(),(v).end()
std::set<long long> st;
//#define MAX(a,b) if(a>b)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))

    /*  ペア関連
    //vector<pair<long long, long long> > pairs(N);
    for(long long i=0; i<N; i++){
        long long a, b;
        cin >> a >> b;
        pairs[i] = make_pair(a, b);
    }
    
    //sort(pairs.begin(), pairs.end(),greater<pair<long long,long long> >());
	sort(pairs.begin(), pairs.end());
    */

 	//stack<long long> sta;   
    //queue<long long> que;


int main(){
	
	long long N,M,K;
	string s;
    long long sum,sum1;
	sum=0;
	sum1=0;
	long long flg,flg1,cnt,cnt1;
	flg=0;
	flg1=0;
	cnt=0;
	cnt1=0;
	long long max;
	long long max1;
	max=0;
	max1=0;
	long long min;
	long long min1;
	min=INF;
	min1=INF;

	long long work1,work2,work3,work4;
	work1=0;
	work2=0;
	work3=0;
	work4=0;
    
	//std::cin >> N;
    //std::cin >> N >> M;
    //std::cin >> N >> M >> K;
    
	//std::vector<long long> v(N);
	//std::vector<long long> w(N);
    std::cin >> s;
    
    
    // 配列入力1
    /*
    for(long long i=0; i<N; i++){
		std::cin >> v[i];
	}
	*/
	// 配列入力2
	/*
	for(long long i=0; i<N; i++){
		std::cin >> w[i];
	}
	*/
    
	
	//通常
	/*
    for(long long i=0; i<N; i++){
		
	}
	*/
	

	//文字列入力
	
	for(long long i=0; i<s.length(); i++){
		
		if(s[i]=='1'){
			cnt++;
		}
		else{
			cnt1++;
		}
	}
	

	
	
	//ソート
    //std::sort(v.begin(),v.end());//昇順ソート
    //std::sort(v.begin(),v.end(),std::greater<long long>());//降順ソート
    //std::sort(w.begin(),w.end());//昇順ソート
    //std::sort(w.begin(),w.end(),std::greater<long long>());//降順ソート
    /*
    
    //S.substr(i, 5);
    //S.size();
    
    for(long long i=0; i<N; i++){
		std::cin >> v[i];
		if(st.find(v[i])==st.end()){
			st.insert(v[i]);
		}
		else{
			st.erase(v[i]);
		}
	}
	*/


	/*
	long long a[4];
	long long value;
	value=0;
	
	a[0] = (value % 10); 
	value /= 10;// 1桁目を取り出す
	a[1] = (value % 10); 
	value /= 10;// 2桁目を取り出す
	a[2] = (value % 10); 
	value /= 10;// 3桁目を取り出す
	a[3] = (value % 10); 
	value /= 10;// 4桁目を取り出す
    work1=a[0]+10*a[1];
    work2=a[2]+10*a[3];
    */
	
	
    if(cnt>cnt1){
    	printf("%d",cnt1*2);
    	//printf("%lld",N);
    	//puts("Yes");
    	//printf("%d",st.size());
    	//文字列の出力
    	//std::cout << s << std::endl;
    	//printf("%.12f\n",ret);
    	//cout << sum << endl;
	}
	else{
		printf("%d",cnt*2);
	}
	return 0;
}


Measured memory_bytes: 512
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int y[100],a,b,c,n,x;
  while(cin>>n>>a>>b>>c>>x&&n+a+b+c+x){
    for(i=0;i<n;i++)
      cin>>y[i];
    j=0;
    for(i=0;i<10001;i++){
      if(y[j]==x){
	j++;
	if(j==n)
	  break;
      }
      x=(a*x+b)%c;
    }
    if(i==10001)
      cout<<-1<<endl;
    else
      cout<<i<<endl;
  }
  return 0;
}

Measured memory_bytes: 864
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

const int N_MAX = 5010;
int N,K;
ll v[N_MAX];

//v[index]を使わずにk-v[index]<= Sum < kとなる挿話が作れるならfalse
bool isNoNeed(int index){
  //i枚目まで使った時にjにできるか
  //trueできる，falseできない
  bool dp[2][K];
  bool *prev, *next;
  prev = dp[0];
  next = dp[1];
  rep(j,K){
    prev[j] = false;
    next[j] = false;
  }
  prev[0] = true;

  rep(i,N){
    rep(j,K){
      next[j] = (prev[j]||next[j]);
      if(i==index)continue;
      if(prev[j]){
        if(j+v[i]<K-v[index]) next[j+v[i]] = true;
        else if(j+v[i] < K) return false;
        else break;
      }
    }
    swap(prev,next);
  }
  return true;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int n;cin >> n >> K;
  N=0;
  rep(i,n){
    int x;cin >> x;
    if(x>=K)continue;
    else v[N++]=x;
  }
  sort(v,v+N);
  int l = 0, r=N;
  if(!isNoNeed(l)){
    cout << 0 << endl;
    return 0;
  }
  while(r-l>1){
    int m = (r+l)/2;
    bool isnoneed = isNoNeed(m);
    if(isnoneed) l = m;
    else r = m;
  }
  cout << r << endl;
  return 0;
}



Measured memory_bytes: 256
a,i,j,n,m,c,s,x,b[20];
main(){
	scanf("%d%d%d",&n,&m,&c);
	for(i=0;i<m;i++)scanf("%d",b+i);
	for(i=0;i<n;i++){
		s=c;
		for(j=0;j<m;j++)scanf("%d",&x),s+=x*b[j];
		a+=s>0;
	}
	printf("%d",a);
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
typedef int ___;
#define int long long
const int N = 2e6+100;
char str[N];
int len;

int replace()
{
	int ans = 0;
	int actr = 0;
	for (int i=0; i+1 < len; ++i) {
		if (str[i] == 'A') ++actr;
		else if (str[i] == 'B' && str[i+1]=='C'){
			++i;
			ans += actr;
		} else actr = 0;
	}
	return ans;
}

___ main()
{
	while (scanf("%s", str) != EOF) {
		len = strlen(str);
		int ans = 0, tmp;
		/*(
		do {
			tmp = replace(str);
			ans += tmp;
		} while (tmp);
		*/
		if (len >= 3) ans = replace();
		printf("%lld\n", ans);
	}
}


Measured memory_bytes: 888
main :: IO()
main = do
    [s,t] <- words <$> getLine
    [a,b] <- map read . words <$> getLine
    u <- getLine
    if s == u
        then
            putStrLn $ show (a - 1) ++ " " ++ show b
        else
            putStrLn $ show a ++ " " ++ show (b - 1)


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))


int main(){
	string s;
	int ans=0;
	int N;
	cin >> N >> s;
	FOR(i,0,N-2){
		if(s.substr(i,3) == "ABC")ans++;
	}
	cout << ans << endl;
}



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

int main()
{
  int N, ary[210];
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> ary[i];

  int cnr;

  while (true)
  {
    bool is_odd = false;
    for (int i = 0; i < N; i++)
    {
      if (ary[i] % 2 != 0)
      {
        is_odd = true;
      }
    }
    if (is_odd == true)
      break;

    for (int i = 0; i < N; i++)
    {
      ary[i] /= 2;
    }
    cnr++;
  }
  cout << cnr << endl;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  string s;
  cin >> s;
  cout << (s.find("9") != string::npos? "Yes": "No") << endl;
  

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin >> s;
  int N = s.size();

  int ans = 1000;
  for(int i=0;i<26;i++){
    char wrd = 'a' + i;
    vector<int> pos;
    for(int j=0;j<N;j++){
      if(s[j] == wrd) pos.push_back(j);
    }

    int M = pos.size();
    if(M==0) continue;

    //cout << wrd << endl;
    int mx = pos[0];
    for(int j=1;j<M;j++){
      mx = max(mx, pos[j] - pos[j-1] - 1);
    }
    mx = max(mx, N - pos[M-1] - 1);


    ans = min(ans,mx);
  }

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
    int N;
    string S;
    cin >> N >> S;
    vector<int> E(N);

    if (S.at(0) == 'E')
        E.at(0) = 1;
    else
        E.at(0) = 0;

    for (int i = 1; i < N; i++)
    {
        if (S.at(i) == 'E')
            E.at(i) = E.at(i - 1) + 1;
        else
            E.at(i) = E.at(i - 1);
    }

    int cnt = E.at(N - 1) - E.at(0);     // 一番左がリーダ
    cnt = min(cnt, N - 1 - E.at(N - 2)); // 一番右がリーダ
    for (int i = 1; i < N - 1; i++)
    {
        int c = (i - E.at(i - 1)) + (E.at(N - 1) - E.at(i));
        cnt = min(c, cnt);
    }

    cout << cnt;
}

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


def typical_stairs():
    n, m = map(int, input().split())
    dangerous = set(int(input()) for _ in range(m))
    mod = 1000000007
    dp = [0] * (n + 1)
    dp[0] = 1
    if 1 not in dangerous:
        dp[1] = 1
    for i in range(2, n + 1):
        if i not in dangerous:
            dp[i] = (dp[i - 2] + dp[i - 1]) % mod
    print(dp[-1])


if __name__ == '__main__':
    typical_stairs()


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

//r,s,p

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,k;
    cin>>n>>k;
    int rr,ss,pp;
    cin>>rr>>ss>>pp;
    map<char,int>mp;
    mp['s'] = rr;
    mp['p'] = ss;
    mp['r'] = pp;
    string t;
    cin>>t;

    ll sum = 0;
    vector<char> temp(n);
    for(int i = 0; i < n; i++){
        if(temp[i%k] == t[i]){
            temp[i%k] = 'e';
        }else{
            sum += mp[t[i]];
            temp[i%k] = t[i];
        }
    }
    cout<< sum <<endl;
    return 0;
}

Measured memory_bytes: 640
K, S = map(int, input().split())

ans = 0
for x in range(min(K+1, S+1)):
    if K < (S - x) //2:
        ans +=  0
    elif K < (S - x):
        ans += K * 2 - (S - x) + 1
    else:
        ans += (S - x) + 1

print(ans)


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

using namespace std;

int main(){
  int n, temp;
  vector<int> data;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> temp;
    data.push_back(temp);
  }

  reverse(data.begin(), data.end());
  for (vector<int>::size_type i = 0; i < data.size(); i++)
  {
    if(i == data.size()-1){
      cout << data[i];
    }else{
      cout << data[i] << " ";
    }
  }
  cout << endl;
  
  
  return 0;
}


Measured memory_bytes: 3164
#include <stdio.h>
#include <utility>

using std::swap;

int main(){
    int x, y;
    scanf("%d %d", &x, &y);
    while(!(x == 0 && y == 0)){
        if(y < x) swap(x, y);
        printf("%d %d\n", x, y);
        scanf("%d %d", &x, &y);
    }
    return 0;
}

Measured memory_bytes: 2592
#include<iostream>
#include<vector>
#include<map>
#include<utility>
#include<set>
#include<functional>
#include<cmath>
#include<algorithm>
using namespace std;
using ll = long long;

int main(){
    int h;
    int w;
    int n;
    cin >> h >> w >> n;
    int max = std::max(h,w);
    int min = std::min(h,w);

    for(int i=1;i<=min;i++){
        if(max*i>=n){
            cout << i;
            return 0;
        }
    }
    cout << 0;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main
{
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

	public static void main (String[] args)
	{
		FastReader reader = new FastReader();
		int n = reader.nextInt();
		int m = reader.nextInt();
		int x = reader.nextInt();

		int[] arr = new int[n+2];
		int[] par = new int[n+2];
		int[] sar = new int[n+2];

		for (int i=0;i<m; i++)
		 	arr[reader.nextInt()] = 1;

		for (int i=1; i<n+2; i++)
			par[i] = par[i-1] + arr[i];

		for (int i=n; i>=0; i--)
			sar[i] = sar[i+1] + arr[i];

		System.out.println (Math.min (par[x-1], sar[x+1]));

	}
}


Measured memory_bytes: 21204
#include <iostream>
#include <string>
using namespace std;
string a,b;
int ans=0;

int main()

{
	cin>>a>>b;
	for (int i=0;i<a.size();i++){
		if (a[i]==b[i]) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

int N;
string node[1111];
vector<lld> edge[1111];
lld dp[1111];

lld solve(lld now){
  if(dp[now] != -1) return dp[now];
  lld ret = 1;
  if(node[now][0] == 'E'){
    for(int i=0;i<edge[now].size();i++){
      ret = (ret*solve(edge[now][i]))%MOD;
    }
    if(node[now].size() != 1) ret++;
  } else if(node[now][0] == 'A'){
    ret = 0;
    for(int i=0;i<edge[now].size();i++){
      ret = (ret+solve(edge[now][i]))%MOD;
    }
    if(node[now].size() != 1) ret++;
  } else {
    ret = 0;
    if(node[now].size() != 1) ret++;
    for(int j=1;j<=(int)(pow(2.0,(double)(edge[now].size()))-1);j++){
      long long next=1;
      long long d=1;
      for(int i=0;i<edge[now].size();i++){
	if((j&d)!=0){
	  next = (next*solve(edge[now][i]))%MOD;
	}
	d=d<<1;
      }
      ret+=next;
    }
  }    
  return dp[now] = ret%MOD;
}

int main(){
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> node[i];
  }
  for(int i=0;i<N-1;i++){
    lld a,b;
    cin >> a >> b;
    a--; b--;
    edge[a].push_back(b);
  }
  memset(dp,-1,sizeof(dp));
  cout << solve(0) << endl;
}

Measured memory_bytes: 3400
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define reverse(x) reverse(x.begin(), x.end())
#define pb push_back
#define pii pair<int, int>
#define pll pair<long long,long long>
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
int a[100005], n, m;

int main(){
	int i, j=0, k;
	cin >> n >> k;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a, a+n);
	for(i=0;i<k;i++){
		j += a[i];
	}
	cout << j;
}


Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int> > adj[MAX];

void dijkstra() {
	priority_queue<pair<int, int> > PQ;
	int color[MAX];
	int d[MAX];
	for (int i = 0; i < n; i++) {
		d[i] = INFTY;
		color[i] = WHITE;
	}
	d[0] = 0;
	PQ.push(make_pair(0, 0));
	color[0] = GRAY;
	while (!PQ.empty()) {
		pair<int, int>f = PQ.top();
		PQ.pop();
		int u = f.second;
		color[u] = BLACK;
		if (d[u] < f.first * (-1)) continue;
		for (int j = 0; j < adj[u].size(); j++) {
			int v = adj[u][j].first;
			if (color[v] == BLACK)continue;
			if (d[v] > d[u] + adj[u][j].second) {
				d[v] = d[u]+adj[u][j].second;
				PQ.push(make_pair(d[v] * (-1), v));
				color[v] = GRAY;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
	}
}
int main() {
	int k, u, v, c;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v >> c;
			adj[u].push_back(make_pair(v, c));
		}
	}
	dijkstra();
	return 0;
}


Measured memory_bytes: 7996
#include<stdio.h>


int len(char a[]){
	
	int x, i, flag =0;
	
	for(i=0; a[i]!=0; i++){
		flag++;
	}
	
	
	return flag+1;
}


int main(){
	int i, flag, j; 
	char box, s[1000];
	scanf("%s", s);
	
	int l = len(s);
	
	//printf("%d", l);
	
	for(i=0; i<l; i++){
		box = s[i];
		
		flag=0;
		
		for(j=0; s[j]!='\0'; j++){
			if(box=='0'){
				break;
			}
			if(s[j]==box){
				flag++;
				s[j]='0';
			}	
		}	
		if(flag%2!=0){
				printf("No\n");
				return 0;
			}	
	}
	
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using  namespace std;
#define ll      long long int
#define pai     pair<int,int>
#define vi      vector<long long int>
#define vb      vector<bool>
#define vm      vector<vector<int> >
#define vd      vector<double>
#define vs      vector<string>
#define vp      vector< pair <string,int> >
#define mpi     map<int,int>
#define mps     map<char,int>
#define sti     stack<int>
#define stc     stack<char>
#define sei     set<int>
#define ses     set<string>
#define multii  multiset<int>
#define forn(i,n)    for (int i = 0; i < n; i++)
#define fork(i,k,n)  for (int i = k; i <= n; i++)
#define forkr(i,k,n) for (int i = k; i >= n; i--)
const int MAX=1e5+1;

 int main()
{
 ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
ll n;
cin>>n;
vi v(n);
forn(i,n){
cin>>v[i];
}
ll m=v[0];
ll c=0;
for(int i=1;i<n;i++){
if(m>v[i]){
   c+=m-v[i];
}
else{
  m=v[i];
}
}
cout<<c<<endl;
}






Measured memory_bytes: 4792
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        while (true) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            int total = 0;
            ArrayList<Integer> list = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                int x = sc.nextInt();
                total += x;
                list.add(x);
            }
            boolean flag = false;
            int idx = 1;
            while (idx * (idx + 1) / 2 <= total) {
                if (idx * (idx + 1) / 2 == total) {
                    flag = true;
                    break;
                }
                idx++;
            }
            if (!flag) {
                sb.append(-1).append("\n");
                continue;
            }
            int ans = -1;
            for (int i = 0; i <= 10000; i++) {
                boolean match = true;
                for (int j = 0; j < list.size(); j++) {
                    if (j + 1 != list.get(j)) {
                        match = false;
                        break;
                    }
                }
                if (match) {
                    ans = i;
                    break;
                }
                int added = list.size();
                for (int j = list.size() - 1; j >= 0; j--) {
                    if (list.get(j) == 1) {
                        list.remove(j);
                    } else {
                        list.set(j, list.get(j) - 1);
                    }
                }
                list.add(added);
            }
            sb.append(ans).append("\n");
        }
        System.out.print(sb);
    }
}



Measured memory_bytes: 241376
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 130000, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzll((tmp & ma0) ^ ma0) : 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	return tmp;
}

int H[100001];
bool NG[100001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint(), M = getint();
	rep1(i, N) H[i] = getint();
	rep(i, M) {
		int a = getint(), b = getint();
		if (H[a] >= H[b]) NG[b] = 1;
		if (H[a] <= H[b]) NG[a] = 1;
	}
	int kotae = N;
	rep1(i, N) kotae -= NG[i];

	printf("%d", kotae);

	Would you please return 0;
}

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

const long long MOD = 1000000007;

int main() {
    int N, K;
    cin >> N >> K;

    long long ans = 0;
    for (long long i = K; i < N + 2; i++)
    {
        long long sum = 0;
        long long minTotal = i * ( i - 1 ) / 2;
        long long maxTotal = i * ( 2 * N - i + 1) / 2;
        sum = (maxTotal - minTotal + 1) % MOD;
        ans += sum;
        ans %= MOD;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;

const int INF = 1001001001;

int main(){
    int n, x, y; cin >> n >> x >> y;
    --x, --y;
    vector<vector<int>> dist(n, vector<int>(n, -1));
    for(int s = 0; s < n; ++s){
        queue<int> q;
        q.push(s);
        dist[s][s] = 0;
        while(!q.empty()){
            auto v = q.front(); q.pop();
            vector<int> nvs;
            if(v > 0) nvs.push_back(v-1);
            if(v < n-1) nvs.push_back(v+1);
            if(v == x) nvs.push_back(y);
            if(v == y) nvs.push_back(x);
            for(auto nv : nvs){
                if(dist[s][nv] == -1){
                    dist[s][nv] = dist[s][v] + 1;
                    q.push(nv);
                }
            }
        }
    }
    vector<int> res(n, 0);
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            res[dist[i][j]]++;
        }
    }
    for(int d = 1; d < n; ++d) cout << res[d] << endl;
    return 0;
}

Measured memory_bytes: 17024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[100010];
int main() {
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		x--;
		a[i]=x;
	}
	ll ans=0;
	for(int i=0;i<n-1;i++){
		if(a[i]==i){
			swap(a[i],a[i+1]);
				ans++;
		}
	}
	if(a[n-1]==n-1){
		ans++;
	}
	cout << ans;
    // your code goes here
	return 0;
}

Measured memory_bytes: 1024
int minus[200010],plus[200010];
int a[200010];
int main(){
	int n;
	scanf("%d",&n);
	long long ans=0;
	for(int i=0;i<n;i++)scanf("%d",a+i);
	for(int i=0;i<n;i++){
		if(i+a[i]<=n)ans+=minus[i+a[i]];
		if(i-a[i]>=0)ans+=plus[i-a[i]];
		if(i+a[i]<=n)plus[i+a[i]]++;
		if(i-a[i]>=0)minus[i-a[i]]++;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 3980
import math
import sys
input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n%i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return sorted(divisors, reverse=True)

def main():
    N, M = map(int, input().split())

    divisors = make_divisors(M)

    for d in divisors:
        tmp = M - d * N
        if tmp >= 0 and tmp % d == 0:
            print(d)
            break
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>

using namespace std;

int N;
vector < pair <int, int> > v;

long double maxAns;

inline bool cmp(const pair <int, int> A, const pair <int, int> B)
{
    return atan2(A.second, A.first) < atan2(B.second, B.first);
}

int main()
{
    cin >> N;

    for(int i = 1; i <= N; i++)
    {
        int x, y;
        cin >> x >> y;
        v.push_back({x, y});
    }

    sort(v.begin(), v.end(), cmp);

    for(int i = 0; i < N; i++)
        v.push_back(v[i]);

    for(int start = 0; start < N; start++)
    {
        long long x = 0LL, y = 0LL;

        for(int l = 1; l <= N; l++)
        {
            x += 1LL * v[start + l - 1].first;
            y += 1LL * v[start + l - 1].second;

            maxAns = max(maxAns, sqrtl(1LL * x * x + y * y));
        }
    }

    cout << fixed << setprecision(60) << maxAns << '\n';
    return 0;
}


Measured memory_bytes: 256
import numpy as np

N,M = map(int, input().split())
An = np.array(input().split(), dtype=int)

vote_sum = np.sum(An)
judge = np.where(An >= vote_sum /(4 * M), 1, 0)
judge_sum = np.sum(judge)

if(judge_sum >= M):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 12504
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int main()
{
  long long int N,M;
  long long int i,j,k;
  char buff[256];
  
  scanf("%s",buff);
  if(strstr(buff,"7")){
    printf("Yes\n"); 
  }
  else{
    printf("No\n");
  }
 
 

   
  return 0; 
  
}

Measured memory_bytes: 1652
n,m=map(int,input().split())
lr=[]
ma=1
mb=n

for i in range(m):
    a,b=map(int,input().split())
    ma=max(ma,a)
    mb=min(mb,b)
if ma>mb:
    print(0)
else:
    print(mb-ma+1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#include "string"
#define int long long




int32_t main() { 
   boost;
   int a,b,c;
   cin>>a>>b>>c;
   int d = c - a  - b;
   if(d>0 && 4*a*b < d*d)
      cout<<"Yes"<<endl;
   else
      cout<<"No"<<endl; 

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;



int main(){
  int N; ll K; cin >> N >> K;
  if(N<2*K-1){
    cout << -1 << endl; return 0;
  }
  rep(i, K){
    cout << K+i << " " << 2*N + i << " " << K+ 2*N + 2*i << endl;
  }
  rep(i, min(K, (ll)N/2)){
    cout << 2*K+i << " " << K+N+i << " " << K + 2*N + 1 + 2*i << endl;
  }
  rep(i, N-2*K){
    cout << 3*K+i << " " << 2*K+N+i << " " << 3*K + 2*N + i << endl;
  }
}

Measured memory_bytes: 2304
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    C=LIN(N)
    RLE = []
    for c in C:
        if not RLE or RLE[-1]!=c-1:
            RLE.append(c-1)
    
    N=len(RLE)
    cumsum = [0]*(2*(10**5))
    DP = [1]+[0]*N

    for i,c in enumerate(RLE):
        DP[i+1] += DP[i]
        DP[i+1] += cumsum[c]
        cumsum[c] += DP[i]
        DP[i+1]%=mod
    print(DP[-1])
if __name__ == '__main__':
    main()

Measured memory_bytes: 95960
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define MAXN ((ll)1e3+5)
#define MOD ((ll)1e9 + 7)
#define INF ((ll)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define TRACE(x) if(DEBUG) cerr << #x << " = " << x << endl;
// #define TRACE2(x,y) if(DEBUG) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<ll,ll>
#define mid ((l+r)/2)

ll n,k;
ll d[MAXN];
ll sum;
ll lim;
ll ans = 1;
map <ll,ll> mp;

ll gcd(ll a, ll b){return (a == 0) ? b : gcd(b%a, a);}

ll check(ll x)// make everting xt
{
	vector <ll> v(n);
	for (ll i = 0; i < n; ++i)
		v[i] = (d[i]%x);

	sort(all(v));

	// return 0;
	ll high[MAXN];
	ll highsuf[MAXN];
	ll lowpre[MAXN];

	for (ll i = 0; i < n; ++i)
		high[i] = x-v[i];

	lowpre[0] = v[0];
	for (ll i = 1; i < n; ++i)
		lowpre[i] = lowpre[i-1] + v[i];

	highsuf[n-1] = high[n-1];
	for (ll i = n-2; i >= 0; --i)
		highsuf[i] = highsuf[i+1] + high[i];

	ll minmoves = LLONG_MAX;

	for (ll i = 0; i < n-1; ++i)
		if(lowpre[i] == highsuf[i+1])
			minmoves = min(minmoves, lowpre[i]);

	if(lowpre[n-1] == 0 or highsuf[0] == 0) 
		minmoves = 0;

	// TRACE2(x,minmoves);
	if(minmoves <= k)
		return x;
	return LLONG_MIN;
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	cin >> n >> k;
	for (ll i = 0; i < n; ++i)
	{
		cin >> d[i];
		sum += d[i];
		// gc = gcd(gc, d[i]);
	}	

	for (ll i = 2; i*i <= sum; ++i)
		if(sum%i==0)
		{
			ans = max(ans, check(i));
			ans = max(ans, check(sum/i));
		}
	ans = max(ans, check(sum));
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int H, W;
int a[512][512];

void get(int* y, int* x, int idx) {
	int yy = idx / W, xx = idx % W;
	*y = yy + 1;
	*x = yy % 2 == 0 ? (xx + 1) : (W - xx);
}

int asumisu;
int mizuhasu[512 * 512];

int main(void) {
	int i, j;
	if (scanf("%d%d", &H, &W) != 2) return 1;
	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) {
			if (scanf("%d", &a[i][j]) != 1) return 1;
		}
	}
	asumisu = 0;
	for (i = 1; i < H * W; i++) {
		int py, px, y, x;
		get(&py, &px, i - 1);
		get(&y, &x, i);
		if (a[py][px] % 2 != 0) {
			mizuhasu[asumisu++] = i;
			a[py][px]--;
			a[y][x]++;
		}
	}
	printf("%d\n", asumisu);
	for (i = 0; i < asumisu; i++) {
		int py, px, y, x;
		get(&py, &px, mizuhasu[i] - 1);
		get(&y, &x, mizuhasu[i]);
		printf("%d %d %d %d\n", py, px, y, x);
	}
	return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

double a, b, x;

double binary_search(double, double);
bool isOK(double);

int main() {
    cin >> a >> b >> x;
    double theta = binary_search(0, 90);
    printf("%.7f\n", theta);
    return 0;
}

double binary_search(double ok, double ng) {
    const double EPS = 1e-8;
    while (abs(ok - ng) > EPS) {
        double mid = (ok + ng) / 2;
        if (isOK(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}

bool isOK(double theta) {
    double theta_rad = theta * M_PI / 180;
    double v;
    if (a * sin(theta_rad) < b * cos(theta_rad)) v = a * a * b - 0.5 * a * a * a * tan(theta_rad);
    else v = 0.5 * b * b * a / tan(theta_rad);
    return x <= v;
}

Measured memory_bytes: 4176
#include <iostream>
#include <vector>
#include <bitset>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	while(1){
		int t,d,l; cin >> t >> d >> l;
		if(t==0&&d==0&&l==0)break;
		vector<int> x(t);
		vector<int> s(t);
		for(int i=0;i<t;i++){
			cin >> x[i];
			if(x[i]>=l){
				s[i]++;
				s[min(t-1,i+d)]--;
			}
		}
		for(int i=0;i<t-1;i++){
			s[i+1]+=s[i];
		}
		int ans=0;
		for(int i=0;i<t;i++){
			if(s[i]>0)ans++;
		}
		cout << ans << endl;
	}
}


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

int mod_pow(int a,int N){
	if(N==0)return 1;
	if(N%2==1)return (a*mod_pow(a,N-1))%2019;
	int tmp=mod_pow(a,N/2);
	return (tmp*tmp)%2019;
}

signed main(){
	string S; cin>>S;
	int N=S.size();
	vector<int> dp(N+1);
	map<int,int> dic;
	dic[0]=1;
	dp[0]=0;
	for(int i=N-1;i>=0;i--){
		int p=S[i]-'0';
		if(i!=N-1){
			dp[i]=mod_pow(10,N-i-1)*p+dp[i+1];
		}
		else{
			dp[i]=p;
		}
		dp[i]%=2019;
		dic[dp[i]]++;
		//cout<<dp[i]<<endl;
	}
	int ans=0;
	for(auto p : dic){
		ans+=(p.second*(p.second-1))/2;
	//	cout<<p.first<<";"<<p.second<<endl;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 5244
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int maxn = 200 + 5;
const int maxp = (1 << 15) + 5;
const int oo = 0x3f3f3f3f;
const int mod = 1e9 + 7;
 
template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

inline bool chk(int s) {
    return (s & 3) == 0 || (s & 3) == 3;
}

int n, m;
LL dp[maxp], pw[maxn];
int to[maxn], cnt[maxn][maxp];

int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif

    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; ++i) {
        static int u, v;
        scanf("%d%d", &u, &v); -- u, -- v;
        to[u] |= 1 << v;
    }

    pw[0] = 1;
    for(int i = 1; i <= m; ++i) pw[i] = (pw[i-1] << 1) % mod;

    int all = 1 << n;
    for(int i = 0; i < n; ++i) {
        for(int s = 0; s < all; ++s) {
            cnt[i][s] = __builtin_popcount(to[i] & s);
        }
    }

    dp[0] = 1;
    for(int s = 1; s < all; ++s) if(chk(s)) {
        for(int sub = s; sub; sub = (sub-1) & s) if(chk(sub)) {
            int res = s ^ sub, delta = dp[res];

            for(int i = 0; i < n; ++i) if(sub >> i & 1) 
                delta = 1LL * delta * pw[cnt[i][res]] % mod;

            for(int i = 0; i < n; ++i) if(res >> i & 1) 
                delta = 1LL * delta * (pw[cnt[i][sub]]-1) % mod;

            (dp[s] += delta) %= mod;
        }
    }
    //cerr << dp[all-1] << endl;
    
    printf("%lld\n", (mod + pw[m] - dp[all-1]) % mod);

    return 0;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define rep(i, a, b) for(int i=a; i<=b; ++i)
using namespace std;
int a[10];
int main(){
	rep(i, 1, 3) cin >> a[i];
	sort(a+1, a+4);
	if(a[1]==a[2]) cout << a[3]<<endl;
	else cout << a[1] <<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define VAL 100000
#define ll  long long 
#define INF 10000000000000000LL
#define pll pair<long long , long long>
const int MAX=1e7+9;
const ll MOD=1e9+7;
const int TOT_PRIMES=19;
const int MAX_A=70;
using namespace std;
int main() 
{

	  ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    string s;
    int n , m , k;
    cin>>n; 
    map<string, int>mp;
    for(int i=0;i<n;i++){
      string s;
      cin>>s;
      mp[s]=mp[s]+1;
    }
    cout<<"AC"<<" x "<<mp["AC"]<<endl;
    cout<<"WA"<<" x "<<mp["WA"]<<endl;
    cout<<"TLE"<<" x "<<mp["TLE"]<<endl;
    cout<<"RE"<<" x "<<mp["RE"]<<endl;
  
}

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

int main(){
  bool flag=true;
  vector<int> v(26,0);
  string w;
  cin >> w;
  r(i,w.length()){
    v.at(w.at(i)-'a')++;
  }
  r(i,26){
    if(v.at(i)%2==1)flag=false;
  }
  if(flag)cout << "Yes"<<endl;
  else cout << "No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	cin>>a;
	for(int i=0;i<=a.size()-1;i++)
	{
		if(i%2==0)
		{
			if(a[i]=='L')
			{
				cout<<"No";
				return 0;
			}
		}
		if(i%2==1)
		{
			if(a[i]=='R')
			{
				cout<<"No";
				return 0;
			}
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
import itertools
n = int(input())
l = list(map(int, input().split()))
nums = [i for i in range(len(l))]
ans = 0
for ptr in itertools.combinations(nums, 3):
    table = dict()
    cand = []
    for j in ptr:
        table[j] = l[j]
        cand.append(l[j])
    if len(set(cand)) == 3:
        k = sorted(table.items(), key=lambda x:x[1])
        if k[2][1] < k[0][1] + k[1][1]:
            ans += 1
print(ans)

Measured memory_bytes: 74116