akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string S, T;
    cin >> S >> T;
    vint sumS(S.size() + 1), sumT(T.size() + 1);
    REP(i, 1, S.size() + 1) {
        sumS[i] = sumS[i - 1] + ((S[i - 1] == 'A') ? 1 : 2);
    }
    REP(i, 1, T.size() + 1) {
        sumT[i] = sumT[i - 1] + ((T[i - 1] == 'A') ? 1 : 2);
    }
    int q;
    cin >> q;
    rep(i, q) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        if ((sumS[b] - sumS[a - 1]) % 3 == (sumT[d] - sumT[c - 1]) % 3) {
            printf("YES\n");
        }
        else {
            printf("NO\n");
        }
    }

    return 0;
}

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

#define ll long long
#define db double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 2e5 + 123;
int n, a[N], cnt[N];

ll f(int x) {
	return (ll)x * (x - 1) / 2;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif

	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	ll ans = 0;
	for (int i = 1; i < N; i++) {
		ans += f(cnt[i]);
	}
	for (int i = 1; i <= n; i++) {
		cout << ans - f(cnt[a[i]]) + f(cnt[a[i]] - 1) << '\n';
	}
}


Measured memory_bytes: 3840
n, k = map(int, input().split())
res = (n - k) * (n - k + 1) // 2
for i in range(k + 1, n + 1):
    if i == 1:
        continue
    a, b = divmod(n - i, i)
    res += a * (i - k) + max(b - k + 1, 0)
print(res)

Measured memory_bytes: 3060
n,m=map(int,input().split())
lists=[list(map(int,input().split())) for x in range(n)]
ans=[0]*m
for x in range(n):
  k=lists[x][0]
  for t in range(k):
    ans[lists[x][t+1]-1]+=1
count=0
for y in range(m):
  if ans[y]==n:
    count+=1
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <iomanip>
#include <queue>
#include <utility>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, char> pci;

int main() {
  std::ios_base::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> a(n);
  for (int& x : a) { cin >> x; --x; }
  int cnt = 0;
  for (int i = 0; i + 1 < n; ++i) {
    if (a[i] == i) { swap(a[i], a[i + 1]); ++cnt; }
  }
  if (a[n - 1] == n - 1) {
    ++cnt;
  }
  cout << cnt << '\n';
  return 0;
}


Measured memory_bytes: 640
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
#define enl "\n";
using namespace std;
using ll=long long;
using ld=long double;
ll mod = ll(1e9)+7;
ll inf = ll(1e18);
void bl(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void bl2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) for (auto vvv : vv) cout << vvv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

using dbg::Debug;
Debug debug;

class CStreamline {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int n, m;
	    in >> n >> m;
	    vector<int> x(m);
	    for(int i=0; i<m; i++){
	        in >> x[i];
	    }

	    sort(x.begin(), x.end());

        if(n >= m) out << 0 << endl;
        else {
            vector<ll> diff;
            for(int i=0; i<m-1; i++){
                diff.push_back(x[i+1]-x[i]);
            }
            sort(diff.begin(), diff.end());
            ll cnt = m-n;
            ll res = 0, cur=0;
            while(cnt > 0){
                res += diff[cur++];
                cnt--;
            }
            out << res << endl;
        }
	}
};


int main() {
	CStreamline solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1784
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

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

const int mod = INF+7;
int main(){
    int n,m;cin>>n>>m;
    vector<P>p;
    rep(i,n){
        int a,b;cin>>a>>b;
        p.emplace_back(a,b);
    }
    sort(ALL(p));
    int j = 0;
    ll res = 0;
    priority_queue<int>pq;
    REP(i,0,m){
        while(j<n){
            int f = p[j].first,s = p[j].second;
            if(i>=f)pq.push(s);
            else break;
            j++;
        }
        if(pq.empty())continue;
        int q = pq.top();pq.pop();
        res += q;
    }
    cout<<res<<endl;
}



Measured memory_bytes: 1908
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    int n;
    string s;
    cin>>n;
    cin>>s;
    int open=0;
    int close=0;
    rep(i,n)
    {
        if(s[i]=='(' )
        {
            open++;
        }
        else
        {
            if(open==0)
            {
                close++;
            }
            else
            {
                open--;
            }
            
        }
        

    }
    if(close>0)
    {
        s=string(close,'(')+s;
    }
    if(open>0)
    {
        s+=string(open,')');
    }
    cout<<s;

}


Measured memory_bytes: 256
list=[]
cup={'A':1,'B':0,'C':0}
while True:
    try:
        x,y=map(str, input().split(','))
    except:
        keys=[k for k,v in cup.items() if v==1]
        for i in range(len(keys)):
            print(keys[i])
        break
    if cup[x]==1:
        cup[y]=1
        cup[x]=0
    elif cup[y]==1:
        cup[y]=0
        cup[x]=1
        



Measured memory_bytes: 5568
def S(x1,y1,x2,y2,x3,y3):
    return ((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/2.0
import sys
for dataset in sys.stdin:
    x1,y1,x2,y2,x3,y3,xp,yp=map(float,dataset.split(" "))
    ABP=S(x1,y1,x2,y2,xp,yp)
    BCP=S(x2,y2,x3,y3,xp,yp)
    CAP=S(x3,y3,x1,y1,xp,yp)
    if ABP>0 and BCP>0 and CAP>0:
        print 'YES'
    elif ABP<0 and BCP<0 and CAP<0:
        print 'YES'
    else:
        print 'NO'

Measured memory_bytes: 4256
public class Main {
	public static void main(String[] args) {
		java.util.Scanner in = new java.util.Scanner(System.in);
		while(in.hasNext()) {
			double[] a = new double[10];
			double sum = a[0] = in.nextDouble();
			for(int i=1; i<10; i++) {
				if(i%2 == 0) {
					a[i] = a[i-1] / 3;
				} else {
					a[i] = a[i-1] * 2;
				}
				sum += a[i];
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 19256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  cout << a*b/2 << endl;
  
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#define MAX 100
#define INFTY 1e+9
#define BLACK 2
#define WHITE 0
#define GRAY 1
int prim();
int N,A[MAX][MAX],color[MAX];
int main(){
  int i,j,e;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      scanf("%d",&e);
      A[i][j]=(e==-1)?INFTY:e;
      
    }
  }
  printf("%d\n",prim());
  return 0;
}
int prim(){
  int d[MAX],p[MAX],i,mincost,u,v;
  for(i=0;i<N;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }
  d[0]=0;
  while(1){
    mincost=INFTY;
    u=-1;
    for(i=0;i<N;i++){
      if(color[i]!=BLACK&&d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }
    if(u==-1)break;
    color[u]=BLACK;
    for(v=0;v<N;v++){
      if(color[v]!=BLACK&&A[u][v]!=INFTY){
	if(d[v]>A[u][v]){
	  d[v]=A[u][v];
	  p[v]=u;
	  color[v]=GRAY;
	}
      }
    }
  }
  int sum=0;
  for(i=0;i<N;i++){
    if(p[i]!=-1)sum+=A[i][p[i]];
  }
  return sum;
}



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

#define CIN2(a,b) long long a,b;cin >> a >> b;
#define CIN3(a,b,c) long long a,b,c;cin >> a >> b >> c;
#define rep(i,n) for(int i=0,i##_len=(n); i<i##_len; ++i)
#define MAX(p,q)((p)>(q)?(p):(q))
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long lli;

int main(){
    vector<int> v(5);
    int ans = 0;
    rep(i,5){
        int tmp;cin >> tmp;
        v[i] = (tmp%10)?10 - tmp % 10:0;
        ans += (tmp/10)*10 + ((v[i]%10)?10:0);
    }
    int m = *max_element(v.begin(),v.end());
    cout << ans - m << endl;
}



Measured memory_bytes: 256
#include <stdio.h>

int	abs(int a)
{
	if (a < 0)
		a *= -1;
	return (a);
}

int	main()
{
	char	S[11];
	int	min;
	int	nb, i;

	i = 0;
	min = 800;
	scanf("%s\n", S);
	for (int i = 0; S[i] != 0; i++)
		S[i] -= '0';
	while (S[i + 2])
	{
		nb = S[i] * 100 + S[i + 1] * 10 + S[i + 2];
		if (abs(nb - 753) < min)
			min = abs(nb - 753);
		i++;
	}
	printf("%d\n", min);
	return (0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define lb lower_bound
#define ub upper_bound
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T> inline T mpow(T a, T n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,k,r,s,p,ans=0;cin>>n>>k>>r>>s>>p;
  string t;cin>>t;
  V<char> v(k,'a');
  rep(i,0,n){
    char win;
    if(t[i]=='r')win='p';
    else if(t[i]=='s')win='r';
    else win='s';

    if(win!=v[i%k]){
      if(t[i]=='r')ans+=p;
      else if(t[i]=='s')ans+=r;
      else ans+=s;
      v[i%k]=win;
    }else{
      v[i%k]='a';
    }
    
  }
  cout<<ans<<ENDL;

}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 512
#include <iostream>
#include <stack>

using namespace std;

int main() {
  stack<int> stk;
  int t;
  
  while(cin >> t) {
    if(t == 0) {
      cout << stk.top() << endl;
      stk.pop();
    }
    else stk.push(t);
  }

  return 0;
}

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

int main() {
    int N,K;
    string S;
    cin >> N >> K;
    cin >> S;
    
    vector<int> Nums;
    int now = 1;
    int cnt = 0;
    int ans = 0;
    rep(i, N) {
        if(S[i] == (char)('0')+now) cnt++;
        else {
            Nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if (cnt!=0) Nums.push_back(cnt);
    if (Nums.size()%2==0) Nums.push_back(0);
    int Add = 2*K+1;
    for(int i = 0; i < Nums.size(); i+=2) {
        int tmp = 0;
        int left = i;
        int right = min(i+Add, (int)Nums.size());
        for(int j = left; j < right; j++) {
            tmp+= Nums[j];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
  string s,t;
  cin >> s >>t;
  int ans = 0;
  rep(i,3){
    if(s[i]==t[i]) ++ans;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline void read(long long &x)
{
    x=0;
    static long long p;p=1;
    static char c;c=getchar();
    while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
    while(isdigit(c)) {x=(x<<1)+(x<<3)+(c-48);c=getchar();}
    x*=p;
}
long long a,b,c,x,y;
int main()
{
	cin>>a>>b>>c>>x>>y;
	long long half=c*2;
	long long s[100];
	s[1]=a*x+b*y;
	s[2]=half*max(x,y);
	s[3]=a*x+y*half;
	s[4]=b*y+x*half;
	s[5]=half*min(x,y)+(max(x,y)-min(x,y))*(max(x,y)==x?a:b);
	sort(s+1,s+5+1);
	cout<<s[1]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    long long int mul = a*b, add = a+b, sub = a-b;
    vector<long long int> num = {mul, add, sub};
    cout << *std::max_element(num.begin(), num.end()) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int n,r;
    cin>>n>>r;
    if(n%r==0)
    {
        cout<<0<<nl;
        return 0;
    }
    cout<<1<<nl;
    return 0;
}



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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if((abs(a-b)<=d && abs(b-c)<=d) || abs(a-c)<=d){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		double n = sc.nextInt();
		double gp = 100000.0;

		for (int i = 0; i < (int) n; i++) {
			gp += gp * 0.05;
			gp = (Math.ceil(gp / 1000)) * 1000;
		}


		System.out.println((int) gp);

	}

}

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

int main (void) {
  int k, x;
  cin >> k >> x;
  
  int leftPos = x - (k - 1);
  int rightPos = x + (k - 1);
  
  for (int i = leftPos; i < rightPos; i++) {
    cout << i << " ";
  }
  cout << rightPos << endl;
  
}

Measured memory_bytes: 256
#![allow(clippy::needless_range_loop)]
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use proconio::input;
use proconio::marker::*;
use itertools::Itertools;

fn main() {
    input! {
        n: usize,
        k: usize,
        p: [Usize1; n],
        c: [isize; n],
    }

    let mut sum = vec![vec![0; n + 1]; n];
    let mut ll = vec![0; n];

    for i in 0..n {
        let mut acc = 0;
        let mut pos = i;
        for j in 1..=n {
            pos = p[pos];
            acc += c[pos];
            sum[i][j] = acc;
            if pos == i {
                ll[i] = j;
                break;
            }
        }
    }

    let mut ans = -1_000_000_000_000_000_000isize;

    for i in 0..n {
        let ld = sum[i][ll[i]] * ((k - 1) / ll[i]) as isize;
        let md = if k % ll[i] == 0 {
            ll[i]
        } else {
            k % ll[i]
        };
        let mut mx1 = -1_000_000_000_000_000_000isize;
        let mut mx2 = -1_000_000_000_000_000_000isize;
        for j in 1..=std::cmp::min(k, ll[i]) {
            if mx1 < sum[i][j] {
                mx1 = sum[i][j];
            }
            if md >= j && mx2 < sum[i][j] {
                mx2 = sum[i][j];
            }
            let ians = std::cmp::max(
                mx1,
                mx2 + ld
            );
            ans = std::cmp::max(ans, ians);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 197872
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<time.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int n,m,k, l[202020], r[202020], u[202020], d[202020];
string s[2020];
int a[2020][2020],b[2020][2020],c[2020][2020];

int main(){
	cin >> n >> m >> k;
	for(int i = 0; i < n; i++){
		cin >> s[i];
	}
	for(int i = 0; i < k; i++){
		cin >> u[i] >> l[i] >> d[i] >> r[i];
	}
	
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(i != 1){
				if(s[i-1][j-1] == '1' && s[i-2][j-1] == '1') a[i][j]++;
				a[i][j] += a[i-1][j];
			}
			a[i][j] += a[i][j-1];
			a[i][j] -= a[i-1][j-1];
		}
	}
	for(int j = 1; j <= m; j++){
		for(int i = 1; i <= n; i++){
			if(j != 1){
				if(s[i-1][j-1] == '1' && s[i-1][j-2] == '1') b[i][j]++;
				b[i][j] += b[i][j-1];
			}
			b[i][j] += b[i-1][j];
			b[i][j] -= b[i-1][j-1];
		}
	}
	
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			c[i][j] += c[i-1][j];
			c[i][j] += c[i][j-1];
			c[i][j] -= c[i-1][j-1];
			if(s[i-1][j-1] == '1') c[i][j]++;
		}
	}
	
	
	for(int i = 0; i < k; i++){
		int A = a[d[i]][r[i]]-a[u[i]][r[i]]-a[d[i]][l[i]-1]+a[u[i]][l[i]-1];
		int B = b[d[i]][r[i]]-b[u[i]-1][r[i]]-b[d[i]][l[i]]+b[u[i]-1][l[i]];
		int C = c[d[i]][r[i]]-c[u[i]-1][r[i]]-c[d[i]][l[i]-1]+c[u[i]-1][l[i]-1];
		cout << C - (A + B) << endl; 
	}
	
	return 0;
}

Measured memory_bytes: 56832
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod2=1000000007;
ll mod=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    ll k;cin>>k;
    ll a[50];
    fill(a,a+50,49-k);
    ll cnt=0;
    rep(i,0,49){
        if(49-k>=0)continue;
        
        
        cnt+=k/50;
        a[i]+=(k/50)*51;
    }
    a[49]+=(k-cnt)*(51);
    ll now=0;
    while(a[49]>=10000000000000000+1000){
        a[49]-=51;
        a[now]+=51;
        now=(now+1)%50;
    }
    cout<<50<<endl;
    rep(i,0,50)cout<<a[i]<<" ";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef double dl;
#define mp make_pair
#define pb emplace_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define dst distance
#define INF 1000000000
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define MAXN 310
ll MOD = 1e9+7;

string S;
ll N,M;

vi V;

ll lsb(unsigned int x){return 32-__builtin_ctz(x);}

struct trie{
	ll depth;
	trie *l, *r;
	trie(ll d){
		l=nullptr;
		r=nullptr;
		depth=d;
	}
	void insert(){
		if (SZ(S) == 0)return;
		ll t=S.back();S.pop_back();
		if (t == '1'){
			if (r==nullptr)r = new trie(depth+1);
			r->insert();
		}else{
			if (l==nullptr)l=new trie(depth+1);
			l->insert();
		}
	}
	void dfs(){
		ll num_child = 0;
		if (r!=nullptr)++num_child;
		if (l!=nullptr)++num_child;
		ll newd = M-depth;
		if(num_child==1&&newd!=0)V.pb(newd);
		if (l!=nullptr)l->dfs();
		if (r!=nullptr)r->dfs();
	}
}*root;

int main(){
	root = new trie(0);
	cin>>N>>M;
	if (N==1){cout<<"Alice";return 0;}
	for (ll i=0;i<N;++i){
		cin>>S;
		reverse(ALL(S));
		root->insert();
	}
	root->dfs();
	ll t=0;
	for (auto i : V){t^=(1<<lsb(i));}
	if (t==0)cout<<"Bob";
	else cout<<"Alice";
}

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

using namespace std;

#define il inline
#define re register
#define Rep(i, s, e) for (re int i = s; i <= e; ++i)
#define Dep(i, s, e) for (re int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)

const int N = 110;

il int read() {
    int x = 0; bool f = true; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = false; c = getchar();}
    while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
    return f ? x : -x;
}

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

int main() {
    n = read(), m = read();
    Rep(i, 1, n) gets(s[i] + 1);
    Rep(i, 1, n) {
		Rep(j, 1, m) {
			if (i + j == 2) {f[1][1] = (s[1][1] == '#'); continue;}
			f[i][j] = 0x3f3f3f3f;
			if (i > 1) f[i][j] = min(f[i][j], f[i - 1][j] + (s[i - 1][j] == '.' && s[i][j] == '#'));
			if (j > 1) f[i][j] = min(f[i][j], f[i][j - 1] + (s[i][j - 1] == '.' && s[i][j] == '#'));
		}
	}
	printf("%d", f[n][m]);
    return 0;
}

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

//各桁の位の和を計算する
int findKuraiSum(int n){
    int sum = 0;
    while (n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
        
}

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    int total = 0;
    for (int i = 1; i <= N; ++i){
        int sum = findKuraiSum(i);
        if (sum >= A && sum <= B){
            total += i;
        }
    }
    cout << total << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;

int main() {
	char ch;
	while (1) {
		if (ch == '\n')break;
		scanf("%c", &ch);
		if ('a' <= ch && ch <= 'z')printf("%c", ch - 32);
		else if ('A' <= ch && ch <= 'Z')printf("%c", ch + 32);
		else printf("%c", ch);
	}
}


Measured memory_bytes: 3124
//#define _GLIBCXX_DEBUG//実行時、何も出なかったらこれを使う
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<numeric>
#include<climits>
#include<limits>//
#include <stdio.h>//

using namespace std;

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

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

int dy[] = {1,0,-1,0,1,-1,-1,1}; //次に行くところ
int dx[] = {0,1,0,-1,1,1,-1,-1}; //上に同じ

const int mod = 1e9 + 7;

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

  long long n, m;
  cin >> n >> m;
  vector<long long> a(m), dp(n+1);
  vector<bool> ng(n+1);

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

  for(int i = 0; i < m; ++i){
    ng[a[i]] = true;
  }

  dp[0] = 1;

  for(int i = 1; i <= n; ++i){
    if(ng[i]) continue;
    int sum = 0;
    for(int j = 1; j <= 2; ++j){
      if(i - j >= 0){
        sum += dp[i - j];
      }
    }
    dp[i] = sum;
    dp[i] %= mod;
  }

  cout << dp[n] << '\n';

  return 0;
}

Measured memory_bytes: 4688
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
for i in range(N):
    C = B[i] - A[i]
    if C>0:
        ans += A[i] + min(C, A[i+1])
        A[i+1] = max(A[i+1]-C, 0)
    else:
        ans += B[i]
print(ans)

Measured memory_bytes: 18624
#include<stdio.h>
int main(void)
{
    int a,b,c,d,t,min,max;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a<c) min=c;
    else    min=a;
    if(b<d) max=b;
    else    max=d;
    t=max-min;
    if(t>=0)    printf("%d",t);
    else    printf("0");
    return 0;
}


Measured memory_bytes: 128
let rec power ( * ) one m = function
  | 0 -> one
  | n when n mod 2 = 0 ->
      power ( * ) one (m * m) (n / 2)
  | n ->
      m * power ( * ) one m (n - 1)

let p = 998244353
let ( *^ ) x y = (x * y) mod p
let ( +^ ) x y = (x + y) mod p

let () = Scanf.scanf "%d %d %d %d" @@ fun n a b k ->
  let comb =
    let fact = Array.make (n + 1) 1 in
    for i = 2 to n do
      fact.(i) <- i *^ fact.(i - 1)
    done;
    let inv_fact = Array.map (fun i -> power ( *^ ) 1 i (p - 2)) fact in
    fun n r -> fact.(n) *^ inv_fact.(r) *^ inv_fact.(n - r) in
  Array.init (n + 1) (fun i ->
    let j = (k - a * i) / b in
    if a * i + b * j = k && 0 <= j && j <= n then [(i, j)]
    else [])
  |> Array.fold_left (fun xs ys -> ys @ xs) []
  (* Ai + Bj = K *)
  |> List.rev_map (fun (i, j) -> comb n i *^ comb n j)
  |> List.fold_left ( +^ ) 0
  |> Printf.printf "%d\n"

Measured memory_bytes: 31744
#include <iostream>
#include <vector>

using namespace std;

int main() {
    vector<int> a(5);
    int gap = 10;
    int index = 0;
    for (int i=0; i<5; i++) {
        cin >> a[i];
        if (a[i]%10 != 0 && a[i]%10 <= gap) {
            gap = a[i]%10;
            index = i;
        }            
    }
    
    int ans = 0;
    for (int i=0; i<5; i++) {
        if (i == index) continue;
        ans += a[i]%10?a[i]+(10-a[i]%10):a[i];
    }
    ans += a[index];
    cout << ans << endl;
}


Measured memory_bytes: 256
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> II;
typedef pair<LL, II> III;
typedef priority_queue<III, vector<III>, greater<>> Queue;
static const LL INF = 1LL << 60;

static const long long MOD = 998244353;
static const size_t MAX_N = 1000001;

struct modll {
	long long x;
	modll() { }
	modll(int _x) : x(_x) { }
	operator int() const { return (int)x; }
	modll operator+(int y) { return (x + y + MOD) % MOD; }
	modll operator+=(int y) { x = (x + y + MOD) % MOD; return *this; }
	modll operator-(int y) { return (x - y + MOD) % MOD; }
	modll operator-=(int y) { x = (x - y + MOD) % MOD; return *this; }
	modll operator*(int y) { return (x * y) % MOD; }
	modll operator*=(int y) { x = (x * y) % MOD; return *this; }
	modll operator/(int y) { return (x * modpow(y, MOD - 2)) % MOD; }
	modll operator/=(int y) { x = (x * modpow(y, MOD - 2)) % MOD; return *this; }
	static modll modinv(int a) { return modpow(a, MOD - 2); }
	static modll modpow(int a, int b) {
		modll x = a, r = 1;
		for (; b; b >>= 1, x *= x) if (b & 1) r *= x;
		return r;
	}
};

class MODBIT {
	std::vector<modll> bit;
	int size;
public:
	MODBIT() { }
	MODBIT(int sz) { init(sz); }
	void init(int sz) {
		bit = std::vector<modll>((size = sz) + 1, 0);
	}
	int sum(int i) {
		modll s = 0;
		while (i > 0) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
	void add(int i, int x) {
		while (i <= size) {
			bit[i] += x;
			i += i & -i;
		}
	}
};


void solve(long long N, long long K, std::vector<long long> &L, std::vector<long long> &R) {
	MODBIT bit(200001);
	bit.add(1, 1);
	bit.add(2, -1);
	for (LL i = 1; i < N; ++i) {
		LL r = N - i;
		modll curr = bit.sum(i);
		for (LL j = 0; j < K; ++j) {
			LL s = L[j];
			if (s > r) continue;
			LL e = min(R[j], r);
			bit.add(i + s, curr);
			bit.add(i + e + 1, -curr);
		}
	}
	modll ans = bit.sum(N);
	cout << ans << endl;
}

int main() {
    long long N;
	std::cin >> N;
	long long K;
	std::cin >> K;
	std::vector<long long> L(K);
	std::vector<long long> R(K);
	for (int i = 0; i < K; i++) {
		std::cin >> L[i]; // L[i]--;
		std::cin >> R[i]; // R[i]--;
	}
	solve(N, K, L, R);
	return 0;
}


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

#include <iostream>


#define MOD 1000000007

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
auto f=[]()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
};

int main()
{
	f();
	int n,m;
	cin>>n>>m;
	vector<P> d;

	while(m--)
	{
		int idx,nm;cin>>idx>>nm;
		d.push_back({idx,nm});
	}

	for(int i=0;i<1000;++i)
	{
		string s=to_string(i);
		if(s.size()==n)
		{
			bool ok=true;
			for(size_t j=0;j<d.size();++j)
			{
				if((s[d[j].first-1]-'0')!=d[j].second)
					ok=false;
			}
			if(ok){
				cout<<s<<"\n";
				return 0;
			}
		}
	}
	cout<<-1<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  string s;
  cin >> s;
  int n = s.size();
  if (n % 2 == 1) {
    cout << "No\n";
    return 0;
  }
  bool fl = true;
  for (int i = 0; i < n; i += 2) {
    fl &= s[i] == 'h';
    fl &= s[i + 1] == 'i';
  }
  cout << (fl ? "Yes" : "No") << '\n';
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




int main()
{
    int N,M;
    cin >> N >> M;
    vector<vector<int>> s(M);
    vector<int> k(M);
    rep(i,M){
        cin >> k[i];
        rep(j,k[i]){
            int sw;
            cin >> sw;
            sw--;
            s[i].push_back(sw);
        }
    }
    vector<int> p(M);
    rep(i,M){
        cin >> p[i];
    }

    int ans = 0;
    for (int tmp = 0; tmp < (1 << N); tmp++) {
        bitset<10> sw(tmp);
        int sum_m = 0;        
        rep(j,M){
            int sum_k = 0;
            rep(l,k[j]){                
                rep(i,N){
                    if(s[j][l] == i && sw.test(i)){
                        sum_k++;
                    }
                }
            }
            if(sum_k%2 == p[j]) sum_m++;
        }
        if(sum_m == M) ans++;
    }

    cout << ans << endl;

    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
#define sbs(i,j) substr(i,j)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    while(cin>>n){
        if(n%1000==0)puts("0");
        else cout<<1000-n%1000<<endl;
    }
    //system("pause");
    return 0;
}

Measured memory_bytes: 3608
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,K;cin>>n>>K;
	cout<<(n+1>=K+K?"YES":"NO")<<endl;
	return 0;
}


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

int main(){
	// sengen
	int n,x;
	// nyuryoku
	cin >> n >> x;
	int l[n];
	for(int i=0;i<n;i++){
		cin >> l[i];
	}
	int d = 0;
	// keisan
	int ans = 0;
	for(int i=0;i<n;i++){
		if(d <= x){
			ans++;
		}
		d += l[i];
	}
	if(d <= x) ans++;
	// syutsuryoku
	cout << ans << endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(n); ++i)



int main()
{
	int N, K; cin >> N >> K;
	vector<int> A(N);
	rep(i, N) cin >> A[i];
	sort(A.begin(), A.end());

	ll ans = 1, sign = 1;
	int l = 0, r = N - 1;
	if (K % 2) {
		ans = A[r--];
		--K;
		if (ans < 0) sign = -1;
	}
	while (K) {
		ll x = (ll)A[l] * A[l + 1];
		ll y = (ll)A[r] * A[r - 1];
		if (x * sign > y* sign) {
			ans = x % MOD * ans % MOD;
			l += 2;
		}
		else {
			ans = y % MOD * ans % MOD;
			r -= 2;
		}
		K -= 2;
	}
	cout << (MOD + ans) % MOD << endl;
	return 0;
}


Measured memory_bytes: 3660
# Decayed Bridges
from collections import deque

class UnionFind():
    def __init__(self, x):
        self.parent = [-1] * x

    def Find(self, x):
        if self.parent[x]<0:
            return x
        else:
            self.parent[x] = self.Find(self.parent[x])
            return self.parent[x]
    
    def Union(self, x, y):
        x = self.Find(x)
        y = self.Find(y)
        if x==y:
            return False
        if x>y:
            x, y = y, x
        self.parent[x] += self.parent[y]
        self.parent[y] = x
        return True

    def isSameGroup(self, x, y):
        return self.Find(x)==self.Find(y)

    def Size(self, x):
        return self.parent[self.Find(x)]*-1

N, M = map(int, input().split())
AB = deque()
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    AB.append([a, b])

uf = UnionFind(N)

ans = deque()
tmp = N*(N-1)//2
ans.append(tmp)
for i in range(M-1):
    a, b = AB.pop()
    if uf.isSameGroup(a, b):
        ans.append(tmp)
    else:
        tmp -= uf.Size(a) * uf.Size(b)
        ans.append(tmp)
        uf.Union(a, b)

for i in range(M):
    print(ans.pop())


Measured memory_bytes: 21888
#include <cstdio>
#include <list>
using namespace std;

int main() {
    int n, x;
    char com[20];
    list<int> v;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%s", com);
        if (com[0] == 'i') {
            scanf("%d", &x);
            v.push_front(x);
        } else if (com[6] == 'L') {
            v.pop_back();
        } else if (com[6] == 'F') {
            v.pop_front();
        } else if (com[0] == 'd') {
            scanf("%d", &x);
            for (list<int>::iterator it = v.begin(); it != v.end(); it++) {
                if (*it == x) {
                    v.erase(it);
                    break;
                }
            }
        }
    }

    int i = 0;
    for (list<int>::iterator it = v.begin(); it != v.end(); it++) {
        if (i > 0) {
            printf(" ");
        }
        printf("%d", *it);
        i++;
    }
    printf("\n");
}



Measured memory_bytes: 34012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const ll INF = 1e17;
// https://atcoder.jp/contests/abc143/submissions/8034843

ll N, M, L, Q;
ll fuel[305][305];
ll dist[305][305];
ll s[105000], t[105000];
ll A[100000], B[100000], C[100000];

void input() {
    cin >> N >> M >> L;
    for(int i = 1; i <= M; i++) cin >> A[i] >> B[i] >> C[i];
    cin >> Q;
    for(int i = 1; i <= Q; i++) cin >> s[i] >> t[i];
}

void solve() {
    // ワーシャルフロイド法
    // 初期化
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            fuel[i][j] = INF;
            dist[i][j] = INF;
        }
        fuel[i][i] = 0;
        dist[i][i] = 0;
    }
    // 与えられたinputを触接表現したグラフ
    for(int i = 1; i <= M; i++) {
        chmin(fuel[A[i]][B[i]], C[i]);
        chmin(fuel[B[i]][A[i]], C[i]);
    }
    // 最短燃料のグラフ
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            for(int k = 1; k <= N; k++) {
                chmin(fuel[j][k], fuel[j][i] + fuel[i][k]);
            }
        }
    }
    // 1回で行けるところをグラフ作成
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            if(i == j) continue;
            if(fuel[i][j] <= L) chmin(dist[i][j], 1LL);
        }
    }
   // 最小到達回数更新    
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            for(int k = 1; k <= N; k++) {
                chmin(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
    // クエリ対処
    for(int i = 1; i <= Q; i++) {
        if(dist[t[i]][s[i]] < INF) cout << dist[t[i]][s[i]] - 1 << "\n";
        else cout << -1 << "\n";
    }
    return;
}

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


Measured memory_bytes: 4864
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

if __name__  == "__main__":
    c1 = list(map(int,input().split()))
    c2 = list(map(int,input().split()))
    c3 = list(map(int,input().split()))
    a1 = 0
    b1 = c1[0]
    b2 = c1[1]
    b3 = c1[2]
    b = [b1,b2,b3]
    a2 = c2[0] - b1 
    for i in range(3):
        d = c2[i] - b[i]
        if a2 != d:
            print("No")
            sys.exit()
    a3 = c3[0] - b1
    for i in range(3):
        d = c3[i] - b[i]
        if a3 != d:
            print("No")
            sys.exit()
    print("Yes")

Measured memory_bytes: 3444
/*include*/
	#include <stdio.h>
	#include <stdlib.h>
	#include <math.h>
	#include <time.h>
	#include <assert.h>
	#include <ctype.h>
	#include <locale.h>
	#include <setjmp.h>
	#include <string.h>
	#include <signal.h>
	#include <limits.h>
	#include <stdarg.h>
	#include <stdbool.h>

/*typedef */
	typedef long long ll;
	typedef char  string[1000];
	
/*define*/

	/*scan*/
		#define scan_d(a) scanf("%d",&a);
		#define scan_c(a) scanf("%c",&a), getchar();
		#define scan_f(a) scanf("%f",&a);
		#define scan_s(a) scanf("%s",a);

	/*define funcs*/
		#define sort_d(array,size)	qsort(array,size,sizeof(int),intcmp)  
		#define sort_c(array,size)	qsort(array,size,sizeof(char),charcmp)  
		#define rand_range(min,max) (min)+(rand())%((max)-(min)+(1))
		#define rep(i,j) for(int i=0;i<j;i++)

/*functions in funcs.h*/
	int intcmp(const void *a,const void *b);
	int charcmp(const void *a,const void *b);
	bool is_sorted(int *start,int *end);


/*main program*/
int main(void)
{
	int d;
	scan_d(d);
	printf("%d\n",(int)pow(d,3));
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		num = nextInt()
		nums = append(nums, num)
	}
	return
}

func checkUpper(nums []int, n int) bool {
	for i := 0; i < n-1; i++ {
		if nums[i] > nums[i+1] {
			return false
		}
	}
	return true
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	p := scanNums(n)
	upper := false

	if checkUpper(p, n) {
		fmt.Println("YES")
		return
	}

	for i := 0; i < n-1; i++ {
		if p[i] > p[i+1] {
			for j := 0; j < n; j++ {
				var tmp int
				if i != j {
					p2 := make([]int, n)
					copy(p2, p)
					tmp = p2[i]
					p2[i] = p2[j]
					p2[j] = tmp
					// fmt.Println(p2)
					upper = checkUpper(p2, n)
					if upper {
						fmt.Println("YES")
						return
					}
				}
			}
		}
	}
	fmt.Println("NO")
}


Measured memory_bytes: 1152
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define int long long

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

int N, A[2000];

int dp[2][2001][2001];

int rec(int turn, int l, int r)
{
    if (turn == N - 1) {
        return 0;
    }

    bool is_joi = turn % 2;

    if (~dp[is_joi][l][r]) return dp[is_joi][l][r];

    int nxl = l - 1 < 0 ? N - 1 : l - 1;
    int nxr = r + 1 >= N ? 0 : r + 1;

    if (is_joi) {
        int res = 0;

        chmax(res, rec(turn + 1, nxl, r) + A[nxl]);
        chmax(res, rec(turn + 1, l, nxr) + A[nxr]);
        
        return dp[is_joi][l][r] = res;
    } else { // IOI
        int res = 0;

        if (A[nxl] > A[nxr]) {
            chmax(res, rec(turn + 1, nxl, r));
        } else {
            chmax(res, rec(turn + 1, l, nxr));
        }

        return dp[is_joi][l][r] = res;
    }
}

signed main()
{
    cin >> N;

    rep(i, N) {
        cin >> A[i];
    }

    memset(dp, -1, sizeof(dp));

    int ma = 0;

    rep(i, N) {
        chmax(ma, rec(0, i, i) + A[i]);
    }

    cout << ma << endl;
}

Measured memory_bytes: 63896
#include <bits/stdc++.h>
using namespace std;
const int N=200005,mod=1e9+7;
int read(){
	int x=0;
	char ch=getchar();
	while (!isdigit(ch))
		ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x;
}
int INF;
int n,x,y;
int c[N],w[N];
int Min[N],cnt[N];
int Fac[N],Inv[N];
int id[N];
int Pow(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=1LL*x*x%mod)
		if (y&1)
			ans=1LL*ans*x%mod;
	return ans;
}
bool cmp(int a,int b){
	return Min[a]<Min[b];
}
int main(){
	n=read(),x=read(),y=read();
	INF=max(x,y)+1;
	for (int i=0;i<N;i++)
		Min[i]=INF;
	for (int i=1;i<=n;i++){
		c[i]=read(),w[i]=read(),id[i]=i;
		Min[c[i]]=min(Min[c[i]],w[i]);
	}
	for (int i=1;i<=n;i++)
		if (w[i]+Min[c[i]]<=x)
			w[i]=Min[c[i]];
	sort(id+1,id+n+1,cmp);
	int allcnt=0;
	memset(cnt,0,sizeof cnt);
	for (int i=1;i<=n;i++){
		if (id[1]!=c[i]){
			if (w[i]+Min[id[1]]<=y)
				allcnt++,cnt[c[i]]++;
		}
		else if (w[i]+Min[id[2]]<=y)
			allcnt++,cnt[c[i]]++;
	}
	for (int i=Fac[0]=1;i<=n;i++)
		Fac[i]=1LL*Fac[i-1]*i%mod;
	Inv[n]=Pow(Fac[n],mod-2);
	for (int i=n;i>=1;i--)
		Inv[i-1]=1LL*Inv[i]*i%mod;
	int ans=Fac[allcnt];
	for (int i=0;i<N;i++)
		ans=1LL*ans*Inv[cnt[i]]%mod;
	cout << ans;
	return 0;
}

Measured memory_bytes: 5760
N,K,C = map(int,input().split())
S = input()
L = []
R = []
i = 0
while i < N:
    if S[i] == "o":
        L.append(i)
        if len(L) == K:
            break
        i += C+1
    else:
        i += 1
i = N-1
while i >= 0:
    if S[i] == "o":
        R.append(i)
        if len(R) == K:
            break
        i -= C+1
    else:
        i -= 1
R.reverse()
for i in range(K):
    if L[i] == R[i]:
        print(L[i]+1)


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

int main(){
  int n;
  cin >> n;
  int t = n;
  int r = 0;
  while(t > 0) {
    r += t % 10;
    t /= 10;
  }
  if (n % r == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3592