akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
bool check[22][22];
char c[22][22];
int w,h;

int recursion(pair<int,int> pos){
  if(c[pos.first][pos.second]=='#'){return 0;}
  if(check[pos.first][pos.second]){return 0;}
  check[pos.first][pos.second]=true;
  int count=1;
  if(pos.first>0){
    count+=recursion(make_pair(pos.first-1,pos.second));
  }
  if(pos.second>0){
    count+=recursion(make_pair(pos.first,pos.second-1));
  }
  if(pos.first<w-1){
    count+=recursion(make_pair(pos.first+1,pos.second));
  }
  if(pos.second<h-1){
    count+=recursion(make_pair(pos.first,pos.second+1));
  }
  return count;
}

int main(){ _;
  pair<int,int> pos;
  while(cin>>w>>h,!(w==0&&h==0)){
    REP(y,h)REP(x,w){
      cin>>c[x][y];
      check[x][y]=false;
      if(c[x][y]=='@')
	pos=make_pair(x,y);
    }
    cout<<recursion(pos)<<endl;
  }
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int H,W,K;
  cin >> H >> W >> K;
  vector<string> S(H);
  for(int i=0;i<H;i++)  cin >> S.at(i);

  int ans=0;
  for(int bitH=0;bitH<(1<<H);bitH++){
    for(int bitW=0;bitW<(1<<W);bitW++){
      int cnt=0;
      for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
          if(bitH&(1<<i)) continue;
          if(bitW&(1<<j)) continue;
          if(S.at(i).at(j)=='#')  cnt++;
        }
      }
      if(cnt==K)  ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3576
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vec;
typedef vector<P> pvec;
typedef vector<vector<int>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<int> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<int,vector<int>,greater<int>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> DX = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> DY = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const ll INF = (1LL << 60); // 1152921504606846976
const double PI = (3.141592653589794);
const double EPS = (0.0000000001); // 10^(-10)

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }



//----------------------------------------------------------------
int nmax=200000; // 2*(10^5)
vvec G(nmax);





void solve4ts()
{
  
  
  int x;
  cin>>x;
  x=(x+1)%2;
  cout<<x<<endl;
  
  
}
//-----------------------------------------------------------------

signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
  int repeat = 1;
  // cin >> repeat;
  while(repeat--) solve4ts();
}

/*

g++ -std=c++1z code.cpp

./a.out

python3 expander.py code.cpp

*/

Measured memory_bytes: 7832
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

const ll MOD = 1e9+7;
signed main(){
    int k; cin >> k;
    string s; cin >> s;
    int l=s.size();
    if(l<=k)cout<<s<<endl;
    else{
        rep(i,k)cout<<s[i];
        cout<<"..."<<endl;
    }
}



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

int main() {
	int n;
	cin>>n;
	int arr[n];
	for (int i=0; i<n; i++){
		cin>>arr[i];
	}
	sort(arr, arr+n);
	int z = 0;
	for (int i=0; i<n; i++){
		int cnt = 0;
		for (int j=0; j<n; j++){
			if (arr[j]==arr[i]) cnt++;
			else if (arr[j] ==arr[i]-1) cnt++;
			else if (arr[j]==arr[i]+1) cnt++;
		}
		//cout << cnt << endl;
		z = max(cnt, z);
	}
	cout << z;
	

}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
int main() {
	string str;
	cin >> str;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string cmd;
		cin >> cmd;
		if(cmd=="print"){
			int a, b;
			cin >> a >> b;
			for (int j = a; j <= b; j++) {
				cout << str.at(j);
			}
			cout << endl;
		}
		else if(cmd=="replace"){
			int a, b;
			string c;
			cin >> a >> b >> c;
			str = str.substr(0, a) + c + str.substr(b + 1);
		}
		else {
			int a, b;
			cin >> a >> b;
			string zan = "";
			for (int j = b; j >= a; j--)zan += str.at(j);
			if (a == 0 && b == str.length()) {
				str = zan;
			}
			else if (a == 0) {
				str = zan + str.substr(b + 1);
			}
			else if (b == str.length()) {
				str = str.substr(0, a) + zan;
			}
			else str = str.substr(0, a) + zan + str.substr(b + 1);
		}
	}
}


Measured memory_bytes: 3216
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, m, a;
    while (cin >> n >> m >> a && n){
        vector<pair<int, P> > p(m);
        REP(i,m){
            int h, x, q;
            cin >> h >> x >> q;
            p[i] = make_pair(-h, make_pair(x, q));
        }
        sort(p.begin(),p.end());
        REP(i,m){
            if (a == p[i].second.first) a = p[i].second.second;
            else if (a == p[i].second.second) a = p[i].second.first;
        }
        cout << a << endl;
    }

    return 0;
}

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.C_Challenge
{
    class ABC_051
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int sx = int.Parse(input[0]);
            int sy = int.Parse(input[1]);
            int tx = int.Parse(input[2]);
            int ty = int.Parse(input[3]);
            string[] ss = new string[4] { "","","","" };
            for (int i = sx; i < tx; i++)
            {
                ss[0] += 'R';
                ss[2] += 'L';
            }
            for(int j = sy; j < ty; j++)
            {
                ss[1] += 'U';
                ss[3] += 'D';
            }
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (i == 1)
                    {
                        switch (j)
                        {
                            case 0:
                                Console.Write("D");
                                break;
                            case 1:
                                Console.Write("RU");
                                break;
                            case 2:
                                Console.Write("LU");
                                break;
                            case 3:
                                Console.Write("LD");
                                break;
                        }
                    }
                    Console.Write(ss[j]);
                }
            }
            Console.WriteLine("R");
        }
    }
}


Measured memory_bytes: 15184
q = input()
p = set(q)

ans = 100
for i in p:
    count = 0
    S = q
    while len(set(S)) != 1:
        count += 1
        N = len(S)
        t = ''
        for j in range(N-1):
            if S[j] == i or S[j+1] == i:
                t += i
            else:
                t += S[j]
        S = t
    ans = min(ans,count)
print(ans)


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

int main(void){

    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    
    int delta_x = tx - sx;
    int delta_y = ty - sy;
    
    for(int i=0; i<delta_y; i++) {
        cout << "U";
    }
    for(int i=0; i<delta_x; i++) {
        cout << "R";
    }
    for(int i=0; i<delta_y; i++) {
        cout << "D";
    }
    for(int i=0; i<delta_x; i++) {
        cout << "L";
    }
    cout << "L";
    for(int i=0; i<delta_y+1; i++) {
        cout << "U";
    }
    for(int i=0; i<delta_x+1; i++) {
        cout << "R"; 
    }
    cout << "DR";
    for(int i=0; i<delta_y+1; i++) {
        cout << "D";
    }
    for(int i=0; i<delta_x+1; i++) {
        cout << "L";
    }
    cout << "U" << endl;
    
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"os"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	var s string
	fmt.Scanf("%s", &s)

	if n%2 != 0 {
		fmt.Println("No")
		os.Exit(0)
	}

	for i := 0; i < len(s)/2; i++ {
		if s[i] != s[i+len(s)/2] {
			fmt.Println("No")
			os.Exit(0)
		}
	}

	fmt.Println("Yes")
}


Measured memory_bytes: 1840
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define RFOR(i,a,b) for (int k=(b)-1;k>=(a);k--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
  
  
using namespace std;
static const double PI = asin(1.0);
  
  
  
int main(){
    cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  while(cin>>n,n){
    cin >> m;
        int def_m = m;
    int begin_dec_x,begin_dec_y,end_dec_x,end_dec_y;
        vector<int> def_x(m),def_y(m);
    vector<vector<pair<int,int>>> defP(8,vector<pair<int,int> >(m));
    REP(i,m){//input
        int x,y;
        cin >> x >> y;
                def_x[i] = x;
                def_y[i] = y;
                if(i==0){
                    begin_dec_x = -x,begin_dec_y = -y;
        }else if (i==m-1){
                    end_dec_x = -x,end_dec_y = -y;
                }
                
        }

         
        REP(i,m){//memo
            int x = def_x[i];
            int y = def_y[i];
            x += begin_dec_x;y += begin_dec_y;
            REP(j,4){
                int ref_x = x*dx[j]-y*dy[j];
                int ref_y = x*dy[j]+y*dx[j];
                defP[j][i] = pair<int,int>(ref_x, ref_y);
            }
        }
        REP(i,m){//reverse memo
            int x = def_x[m-1-i];
            int y = def_y[m-1-i];
            x += end_dec_x;y += end_dec_y;
        REP(j,4){
            int ref_x = x*dx[j]-y*dy[j];
            int ref_y = x*dy[j]+y*dx[j];
            defP[j+4][i] = make_pair(ref_x, ref_y);
        }
        }


        REP(i,n){
            cin >> m;
            int jud_x[m],jud_y[m];
            REP(j,m){//input
		        int x,y;
			    cin >> x >> y;
                jud_x[j] = x;
                jud_y[j] = y;
                if(j==0){
                    begin_dec_x = -x,begin_dec_y = -y;
                }
                jud_x[j] += begin_dec_x;
                jud_y[j] += begin_dec_y;
            }
            REP(j,8){//pattern
	            if(!(def_m == m))break;
                int ct = 0;
                REP(k,defP[j].size()){//match
                    if(jud_x[k] == defP[j][k].first && jud_y[k] == defP[j][k].second){
                    	    ct++;
                	}
                }
            	if(ct == defP[j].size()){
                	cout << i+1 << endl;
                	break;
            	}
            }
        }
        cout << "+++++" << endl;
    }
  return 0;
}

Measured memory_bytes: 3112
#include <stdio.h>

int main(void) {

	int n, x;
	
	while (1) {
		scanf("%d %d", &n, &x);

		if (n == 0 && x == 0)
			break;

		int i, j, k, count = 0;

		for (i = 1; i <= n; i++) {
			for (j = 1; j <= n; j++) {
				for (k = 1; k <= n; k++) {
					if (i < j && j < k && i + j + k == x) {
						count++;
					}
				}
			}
		}

		printf("%d\n", count);

	}

	return 0;
}




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

int main()
{
    int h,w;
    cin >> h >> w;
    while(h!=0)
    {
        int i,j;
        for(i=0; i<h; i++)
        {
            for(j=0; j<w; j++)
            {
                if(i==0||i==h-1||j==0||j==w-1)
                    cout << "#";
                else
                    cout<<".";
            }
            cout << endl;
        }
        cout << endl;
        cin >> h >> w;
    }
    return 0;
}



Measured memory_bytes: 3068
import java.util.*;
class TreeNode{
	int l,r;
	int p;
	public TreeNode(){
		l = -1;
		r = -1;
		p =-1;
	}
}

public class Main {
	static int  MAX=10000;
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		TreeNode[] T= new TreeNode[MAX];
		for(int i=0;i<n;i++){
			T[i] = new TreeNode();
		}
		for(int i=0;i<n;i++){
			int v,l,r;
			v = sc.nextInt();
			l = sc.nextInt();
			r = sc.nextInt();
			T[v].l =l;
			T[v].r = r;
			if(T[v].l!=-1) T[l].p= v;
			if(T[v].r!=-1) T[r].p= v;
		}
		int root=0;
		for(int i=0;i<n;i++) if(T[i].p==-1) root=i;
		System.out.println("Preorder");
		preOrder(T,root);
		System.out.println();
		System.out.println("Inorder");
		inOrder(T,root);
		System.out.println();
		System.out.println("Postorder");
		postOrder(T,root);
		System.out.println();

		
	}
	public static void preOrder(TreeNode[] T,int u){
		if(u==-1) return;
		System.out.print(" "+u);
		preOrder(T,T[u].l);
		preOrder(T,T[u].r);
	}
	public static void	inOrder(TreeNode[] T,int u){
		if(u==-1) return;
		inOrder(T,T[u].l);
		System.out.print(" "+u);
		inOrder(T,T[u].r);
	}
	public static void	postOrder(TreeNode[] T,int u){
		if(u==-1) return;
		postOrder(T,T[u].l);
		postOrder(T,T[u].r);
		System.out.print(" "+u);
	}
}

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

A,B,C,D=map(int,input().split())

import math

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
    
def lcm(x, y):
    return (x * y) // gcd(x, y)

E=lcm(C,D)

x=B-A+1
y=B//C-(A-1)//C
z=B//D-(A-1)//D
w=B//E-(A-1)//E

print(x-y-z+w)


Measured memory_bytes: 3060
import math
#print(input().split())
N,D=list(map(int,input().split()))

cnt=0
for i in range(N):
  A,B=list(map(int,input().split()))
  if(math.sqrt(A*A+B*B)<=D):
    cnt+=1

print(cnt)
#a=int(input())
#list(map(int, input()))
#print(N,D)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> p;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, K, X, Y;
    cin >> N >> K >> X >> Y;

    ll ans = N * Y + (X - Y) * min(N, K);

    cout << ans << endl;
}

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

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;

mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    int cnt = 0, overs = 0;
    for(int i = 1; i <= n; i++){
        if(s[i - 1] == 'a'){
            if(cnt < (a + b)){
                cout << "Yes\n";
                cnt++;
            }else{
                cout << "No\n";
            }
        }else if(s[i - 1] == 'b'){
            if(cnt < (a + b) && overs < b){
                cnt++;
                overs++;
                cout << "Yes\n";
            }else{
                cout << "No\n";
            }
        }else{
            cout << "No\n";
        }
    }
    return 0;
}


Measured memory_bytes: 848
object Main extends App {
  val inputs: IndexedSeq[String] = scala.io.Source.stdin.getLines().toIndexedSeq
  
  val n = inputs(0).toInt
  val tSeq = inputs(1).split(" ").map(_.toInt)
  val m = inputs(2).toInt
  val pms = inputs.takeRight(m)

  println(solve(n, tSeq, m, pms))

  private def solve(n: Int, times: IndexedSeq[Int], m: Int, drinks: IndexedSeq[String]): String = {
    val sum = times.sum
    val resultSeq = scala.collection.mutable.ArrayBuffer.empty[Int]

    (0 until m).foreach { i =>
      val pair = drinks(i).split(" ").map(_.toInt)
      val timeIndex = pair(0) - 1
      val mTime = pair(1)

      val dis = mTime - times(timeIndex)
      resultSeq.append(scala.math.max(0, sum + dis))
    }

    resultSeq.mkString("\n")
  }
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    string s;
    cin >> s;
    int res = 0;
    for (int i = 0; i < s.length() / 2; ++i) {
        if (s[i] != s[s.length()-1-i]) res++;
    }
    cout << res << endl;
}

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

int main(int argc, const char * argv[]) {
    uint64_t K, N;
    cin >> K;
    cin >> N;
    
    vector<uint64_t> A;
    for (uint64_t i = 0; i < N; i++) {
        uint64_t tmp;
        cin >> tmp;
        A.push_back(tmp);
    }
    
    uint64_t max_dist = 0;
    for (uint64_t i = 0; i < N-1; i++) {
        uint64_t dist = A[i+1] - A[i];
        max_dist = max(max_dist, dist);
    }
    max_dist = max(max_dist, A[0] - A[N-1] + K);
    uint64_t ans = K - max_dist;
    cout << ans;
    return 0;
}

Measured memory_bytes: 2420
N = int(input())
An = list(map(int,input().split()))
An_2 = []
for i in range(N):
    if An[i] % 2 == 0:
        An_2.append(An[i])
a = 0
for i in range(len(An_2)):
    if An_2[i] % 3 == 0 or An_2[i] % 5 ==0:
        a += 1
if a == len(An_2):
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 3060
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    alpha_data={}
    S = input()
    [alpha_data.update({chr(i):0}) for i in range(97, 97+26)]
    
    for s in S:
        if s in alpha_data:
            tmp=alpha_data[s]
            tmp+=1
            alpha_data[s]=tmp
        else:
            continue
    for i,v in alpha_data.items():
        if v==0:
            print(i)
            exit()
    print("None")

if __name__=="__main__":
    main()

Measured memory_bytes: 9176
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: u64, i: u64
    }
    println!("{}", n - i + 1);
}

Measured memory_bytes: 4352
N = input()
val= []
for _ in xrange(N):
    a, b  = map(int, raw_input().split())
    val.append((a + b, a, b))
val.sort(reverse=True)

res = 0
for i, (v, a, b) in enumerate(val):
    res += a if i % 2 == 0 else -b
print res

Measured memory_bytes: 19016
#include<stdio.h>

int main(void)
{
   int n, a[10000], i, f, s=0;

   scanf("%d",&n);
   for(i=0;i<n;i++)
      scanf("%d",&a[i]);

   for(i=0;i<n;i++){
      f=2;
      while(a[i]%f==0){
         f=f*2;
         s++;
      }
   }
   printf("%d\n",s);
   return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int,int>;
const LL mod =1e9+7;
const int Max_Num=2010;

LL F[Max_Num], Finv[Max_Num];

LL modpow(LL x, LL n){
	LL r=1;
	while(n){
		if(n&1) r=r*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return r;
}

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

LL comb(LL n, LL k){
	LL res=F[n];
	res*=Finv[k]*Finv[n-k]%mod;
	return res%mod;
}

void fact(){
	F[0]=1;
	rep(i,Max_Num-1){
		F[i+1]=F[i]*(i+1);
		F[i+1]%=mod;
	}
	rep(i,Max_Num) Finv[i]=modinv(F[i]);
}

int main(){
	fact();
	LL N, K;
	cin >> N >> K;
	for(LL i=0; i<K; i++){
		if(N-K-i<0){
			cout << 0 << endl;
			continue;
		}
		LL ans=1;
		ans*=comb(K-1,i);
		ans*=F[N-K+1]*Finv[N-K-i]%mod*Finv[i+1]%mod;
		ans%=mod;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()

using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;

template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H); REP(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); REP(i, n)os << v[i] << (i == n - 1 ? "" : " "); return os; }
template <class T = int> inline T IN() { T x; cin >> x; return x; }
template<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

int main() {
	int N = IN();
	vi A(N);
	REP(i, N) {
		A[i] = IN();
	}
	sort(ALL(A));
	int ans = 0;
	REP(i, N - 1) {
		ans += A[i + 1] - A[i];
	}
	OUT(ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

fun main(args:Array<String>){

    val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    val m = cin.nextInt()

    var mat = Array(n,{ Array<Int>(m,{0}) })
    var vec = Array<Int>(m,{0})
    var result:Int = 0

    for(i in 0..n-1){
	    for(j in 0..m-1){
	        mat[i][j] = cin.nextInt()
	    }
    }

    for(i in 0..m-1) vec[i] = cin.nextInt()

    for(i in 0..n-1){
	    for(j in 0..m-1){
	        result += mat[i][j] * vec[j]
	    }
	    println(result)
	    result = 0
    }
}




Measured memory_bytes: 40804
#include <stdio.h>
int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    if(a>b)
        printf("a > b\n");
    else if(a<b)
        printf("a < b\n");
    else
        printf("a == b\n");
    
    return 0;
}




Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
const int MAXN = 500005;
const int LOG = 21;
using namespace std;

int* z_function(const char s[],int n) {
    int* z = new int[n];
    memset(z, 0, sizeof(z));
    z[0] = n;
    int L = 0, R = 1;
    for (int i=1; i<n; ++i)
       if (R <= i || z[i-L] >= R-i){
            int x = (R <= i ? i : R);
            while (x < n && s[x] == s[x-i]) x++;
            z[i] = x-i;
            if (i < x) {L = i; R = x;}
        }
        else
           z[i] = z[i-L];
    return z;
}

int jump[LOG][MAXN];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	string s, t, big;
	cin >> s >> t;
	big = t;
	big += '$';
	for (int i = 0; i < (t.size() + s.size() - 1) / s.size() + 1; i++) {
		big += s;
	}
	
	int *z = z_function(big.c_str(), big.size());
	for (int i = 0; i < s.size(); i++) {
		if (z[t.size() + 1 + i] >= t.size()) {
			jump[0][i] = (i + t.size()) % s.size();
		}
		else {
			jump[0][i] = -1;
		}
	}
	
	for (int i = 1; i < LOG; i++) {
		for (int j = 0; j < s.size(); j++) {
			if (jump[i - 1][j] != -1) {
				jump[i][j] = jump[i - 1][jump[i - 1][j]];
			}
			else {
				jump[i][j] = -1;
			}
		}
	}
	
	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		int res = 0, cur = i;
		for (int j = LOG - 1; j >= 0; j--) {
			if (jump[j][cur] != -1) {
				res += 1 << j;
				cur = jump[j][cur];
			}
		}
		ans = max(ans, res);
	}
	
	if (ans >= s.size()) {
		cout << "-1\n";
	}
	else {
		cout << ans << '\n';
	}
	
	delete[] z;
	return 0;
}

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

bool take(vector<int> &bucket, int multi, int k)
{
  size_t i = 0;
  while (i < bucket.size() && k > 0)
  {
    if (bucket[i] >= multi)
    {
      bucket[i] -= multi;
      --k;
    }
    else
    {
      ++i;
    }
  }
  return k == 0;
}

bool f(vector<int> bucket, int H, int W)
{
  int bai4 = (H/2) * (W/2);
  int bai2 = (W/2) * (H%2) + (H/2) * (W%2);

  if (!take(bucket, 4, bai4))
    return false;
  else if (!take(bucket, 2, bai2))
    return false;
  else
    return true;
}

int main()
{
  int H, W;
  cin >> H >> W;
  vector<int> bucket(26, 0);
  for (int h = 0; h < H; ++h)
  {
    string s;
    cin >> s;
    for (int w = 0; w < W; ++w)
    {
      ++bucket[s[w]-'a'];
    }
  }
  
  bool ans = f(bucket, H, W);
  cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3612
#include<stdio.h>
#include<stdlib.h>

int cmp(const void *a, const void *b) {
    int *c = *(int**)a, *d = *(int**)b;
    if(c[1] > d[1]) { return 1; }
    else if(c[1] == d[1]) { return 0;}
    else { return -1;}
}

void solve(int **list, int N){
    int sum = 0, i;
    int flag = 1;
    for(i = 0; i < N; ++i) {
        sum += list[i][0];
        if(sum > list[i][1]) { flag = 0; break;}
    }
    if(flag == 1) { printf("Yes\n"); } else {printf("No\n");}
}

int main()
{
    int N, i;
    scanf("%d", &N);
    int **list = (int**)malloc((N+6)*sizeof(int*));
    for(i = 0; i < N+6; ++i) {
        list[i] = (int*)malloc(2*sizeof(int));
    }
    for(i = 0; i < N; ++i) {
        scanf("%d %d", &list[i][0], &list[i][1]);
    }
    qsort(list, N, sizeof(int*), cmp);
    
    /*
    for(i = 0; i < N; ++i) {
        printf("%d, %d\n", list[i][0], list[i][1]);
    }
    */

    solve(list, N);
    return 0;
}

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

char f(int t){if(t==0){return 'z';}
              if(t==1){return 'a';}
              if(t==2){return 'b';}
              if(t==3){return 'c';}
              if(t==4){return 'd';}
              if(t==5){return 'e';}
              if(t==6){return 'f';}
              if(t==7){return 'g';}
  if(t==8){return 'h';}
              if(t==9){return 'i';}
              if(t==10){return 'j';}
              if(t==11){return 'k';}
              if(t==12){return 'l';}
              if(t==13){return 'm';}
              if(t==14){return 'n';}
              if(t==15){return 'o';}
              if(t==16){return 'p';}
              if(t==17){return 'q';}
              if(t==18){return 'r';}
              if(t==19){return 's';}
              if(t==20){return 't';}
              if(t==21){return 'u';}
              if(t==22){return 'v';}
              if(t==23){return 'w';}
              if(t==24){return 'x';}
              if(t==25){return 'y';}
             }

int main() {

long long n;
  cin>>n;
vector<long long> kotae;
  while(n!=0){kotae.push_back(n%26);n=(n-1)/26;}
  long long a=kotae.size();
for(long long i=0;i<a;i++){cout<<f(kotae.at(a-i-1));}
}

Measured memory_bytes: 3616
(defun alphabet-index (ch)
  (- (char-code ch) (char-code #\a)))

(let ((s (read-line))
      (seq (make-array 26 :initial-element nil)))
  (dotimes (i (length s))
    (let ((ch (char s i)))
      (setf (aref seq (alphabet-index ch))
            t)))
  (loop for i from 0 below 26
        unless (aref seq i) do
        (format t "~A~%" (code-char (+ (char-code #\a) i)))
        (return)
        finally (format t "None~%")))


Measured memory_bytes: 17508
#include<stdio.h>

int main(void){
  char str[21];
  char rev[21];
  int i,cnt=0;

  scanf("%s",str);
  while(str[cnt]){
    cnt++;
  }
  for(i=0;i<cnt;i++){
    rev[i]=str[cnt-i-1];
  }
  rev[cnt]='\0';
  printf("%s",rev);
  puts("");
  return(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

ll gcd (ll x, ll y) { return y ? gcd(y,x%y) : x; }

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  if (n == 2) {
    cout << max(a[0], a[1]) << endl;
    return 0;
  }
  vector<ll> lgcd(n+1), rgcd(n+1);
  lgcd[0] = a[0];
  rgcd[n] = a[n-1];
  for (int i = 1; i <= n; ++i) {
    lgcd[i] = gcd(a[i-1], lgcd[i-1]);
  }
  for (int i = n-1; i >= 0; --i) {
    rgcd[i] = gcd(a[i], rgcd[i+1]);
  }
  lgcd[0] = 0;
  rgcd[n] = 0;
  ll ans = 1;
  for (int i = 0; i < n; ++i) {
    chmax(ans, gcd(lgcd[i], rgcd[i+1]));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
"use strict";
let Main = input => {
    const array = input.split(" ").map(e => parseInt(e));
    const n = array.reduce((p, c) => c - p, 0);
    const lengthOfB =  n * (n + 1) / 2;
    console.log(lengthOfB - array[1]);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21828
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define mod2 1000000006
#define inf 1000000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<lli>
#define vii vector<int>
#define is indexed_set
#define eps 0.000001
#define endl '\n'
#define mo 998244353
#define pi 3.141592653589793
#define FF first
#define SS second
using namespace std ;
 
const lli dx4[] = {-1, 0, 1, 0};
const lli dy4[] = {0, 1, 0, -1};
const lli dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const lli dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};
 
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); // can give negative values too

#define N 1000004

void solve()
{
	lli n;
	cin>>n;

	if(n >= 400 && n<=599) cout<<8;
	if(n >= 600 && n<=799) cout<<7;
	if(n >= 800 && n<=999) cout<<6;
	if(n >= 1000 && n<=1199) cout<<5;
	if(n >= 1200 && n<=1399) cout<<4;
	if(n >= 1400 && n<=1599) cout<<3;
	if(n >= 1600 && n<=1799) cout<<2;
	if(n >= 1800 && n<=1999) cout<<1;

}

int main()
{
/////////////////////////////////////
    fastio;
    
/////////////////////////////////////  

    lli t;
    t=1;
    
    loopl(i,1,t+1)
    {
    	//cout<<"Case #"<<i<<": ";
    	solve();
    }  
}	
   


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int a,b; cin >> a >> b;
    string s; cin >> s;
    if (s[a] != '-')
    {
        cout << "No\n";
        return 0;
    }
    for (int i = 0; i < s.size(); i++)
    {
        if (i != a)
        {
            if (!(0 <= s[i]-'0' && s[i]-'0' <= 9)) {
                cout << "No\n";
                return 0;
            }
        } else if (s[i] != '-') {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}

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

using namespace std;

int main(void) {

	int N, A, B;
	cin >> N >> A >> B;

	cout << min(A, B) << " ";
	int ans = 0;
	ans = max(ans, A + B - N);
	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
h[0] -= 1
for i in range(1,n):
    if h[i-1] < h[i]:
        h[i] -= 1
l = list(h)
l.sort()
if h == l:
    print('Yes')
else:
    print('No')

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> voyages(m);
    for (int i=0;i<m;i++){
        vector<int> voyage(2);
        cin >> voyage[0] >> voyage[1];
        voyages[i] = voyage;
    }
    vector<int> points;
    for (int i=0;i<m;i++){
        if (voyages[i][0] == 1){
            points.push_back(voyages[i][1]);
        }else if(voyages[i][1] == n){
            points.push_back(voyages[i][0]);
        }
    }
    int points_size = points.size();
    sort(points.begin(), points.end());
    points.erase(unique(points.begin(), points.end()), points.end());
    int unique_points_size = points.size();
    if (points_size == unique_points_size){
        cout << "IMPOSSIBLE" << endl;
    } else {
        cout << "POSSIBLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 12284
a,b,c,d,e,f = map(int, input().split())

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def lcm(a, b):
    return a//gcd(a, b)*b

def sub(s, c, d):
    # k3*c + k4*d でsに近い値を作る
    k3 = s//c
    k4 = 0
    val = k3 * c + k4 * d
    best = val
    k4 += 1
    while k3>=0:
        val = k3 * c + k4 * d
        if val > s:
            k3 -= 1
        else:
            best = max(val, best)
            k4 += 1
    return best
    
best = (0, 100*a, 0)
k1 = 0
while True:
    k2 = 0
    while True:
        w = 100*k1*a + 100*k2*b
        if w==0:
            k2 += 1
            continue
        if w>f:
            break
        s = min(f - w, int(w*e / 100))
        val = sub(s, c, d)
#         print(s, c, d, val)
        if best[0] < val/(w+val):
            best = (val/(w+val), w, val)
        k2 += 1
    k1+=1
    if 100*k1*a>f:
        break
print(best[1]+best[2], best[2], sep=" ")

Measured memory_bytes: 39024
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


const ll MOD=1000000007;
const int sMOD=13;


void calc(vll&ndp, vll&cdp, int v, int u)
{
	for(int i=0;i<sMOD;i++)
	{
		int x=(i+u*v)%sMOD;

		ndp[x]=(ndp[x]+cdp[i])%MOD;
	}
}


int main(void)
{
	char s[100000+2];

	while(scanf("%100000[0-9?]\n", s)==1)
	{
		int l=strlen(s);
		vvll dp(l+1);

		for(auto&mdp:dp) mdp.resize(sMOD);
		dp[0][0]=1;

		int u=1;
		for(int i=1;i<=l;i++)
		{
			int c=s[l-i];
			if(c=='?')
			{
				for(int j=0;j<=9;j++)
				{
					calc(dp[i], dp[i-1], j, u);
				}
			}
			else
			{
				calc(dp[i], dp[i-1], c-'0', u);
			}
			u=(u*10)%sMOD;
		}

		printf("%lld\n", dp[l][5]);
	}
	return 0;
}


Measured memory_bytes: 13696
def main():

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

    d = dict()
    for v in A:
        d[v] = d.get(v, 0) + 1
    if 1 in d:
        if d[1] == 1: return 1
        else: return 0

    A = list(set(A))
    A.sort()
    s = set()
    ans = 0
    for i in range(len(A)):
        if d[A[i]] == 1:
            if A[i] not in s:
                ans += 1
        k = 1
        while k * A[i] <= A[-1]:
            s.add(k * A[i])
            k += 1

    return ans


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 110204
n,k=gets.split.map(&:to_i)
xy=n.times.map{gets.split.map(&:to_i)}

ans=10**20
xy.combination([k,4].min){|z|
  xx=-10**10
  xn=10**10
  yx=-10**10
  yn=10**10
  z.each{|a,b|
    xn = a if a < xn
    xx = a if a > xx
    yn = b if b < yn
    yx = b if b > yx
  }
  m=xy.select{|t| xn<=t[0]&&t[0]<=xx&&yn<=t[1]&&t[1]<=yx}.size
  w=xx-xn
  h=yx-yn
  ans=w*h if w*h<ans && k<=m
}

p ans

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

int main() {
  int N, ans = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    while (a % 2 == 0) {
      a /= 2;
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 1000000007LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (ll i=(a); i >= b; i--)

#define MN 200005
int n;
string s;
bool op[MN];

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

    cin >> n >> s;
    F0R(i, 2*n){
        if(s[i] == 'B'){
            op[i] = (i+1)%2;
        } else{
            op[i] = i%2;
        }
        //cout << op[i] << " ";
    }
    //cout << "\n";
    ll amt = 1;
    int cnt = 0;
    F0R(i, 2*n){
        if(op[i]) ++cnt;
        else{
            amt = (amt*cnt)%MOD;
            --cnt;
        }
        if(cnt < 0){
            cout << "0\n";
            return 0;
        }
    }
    if(cnt != 0){
        cout << "0\n";
        return 0;
    }
    FOR(i, 1, n) amt = (amt*i)%MOD;
    cout << amt << "\n";

    return 0;
}


Measured memory_bytes: 788
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 2010
int sum1[MAXN][MAXN],sum2[MAXN][MAXN],cl[MAXN][MAXN],n,m,q;
char s[MAXN][MAXN];
int main()
{
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s[i]+1);
		s[i][0]='0';
		for(int j=1;j<=m;j++)
		{
			sum1[i][j]=sum1[i][j-1];
			sum2[i][j]=sum2[i][j-1];
			if(s[i][j]=='1'&&s[i-1][j]=='1')
				sum1[i][j]++;
			if(s[i][j]=='1'&&s[i][j-1]=='0')
				sum2[i][j]++;
			if(s[i][j]=='1'&&s[i][j+1]=='1')
				cl[i][j]=1;
			cl[i][j]+=cl[i-1][j];
		}
		for(int j=1;j<=m;j++)
		{
			sum1[i][j]+=sum1[i-1][j];
			sum2[i][j]+=sum2[i-1][j];
		}
	}
	int x1,y1,x2,y2;
	while(q--)
	{
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		x1--,y1--;
		int ans=sum2[x2][y2]-sum2[x1][y2]-sum2[x2][y1]+sum2[x1][y1]+cl[x2][y1]-cl[x1][y1];
		ans-=sum1[x2][y2]-sum1[x1+1][y2]-sum1[x2][y1]+sum1[x1+1][y1];
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 52992
import sys
import numpy as np
n = int(input())

dp = list(map(int, input().split()))

for i in range(n-1):
    a, b, c = list(map(int, input().split()))
    dp0, dp1, dp2 = dp
    dp[0] = max(dp1+a,dp2+a)
    dp[1] = max(dp0+b,dp2+b)
    dp[2] = max(dp0+c,dp1+c)
print(max(dp))

Measured memory_bytes: 20780
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<numeric>
#include<algorithm>
#include<limits.h>
#define lp(i,n) for(int i=0;i<n;i++)
#define lpin(i,n,a) for(int i=0;i<n;i++)cin >> a[i]
long long int n;
using namespace std;
long long int rec(long long a,bool flag1,bool flag2,bool flag3){
static long long int ans = 0;
if(n < a)return 0;
if(flag1 && flag2 && flag3)ans++;

rec(a*10+3,true,flag2,flag3);
rec(a*10+5,flag1,true,flag3);
rec(a*10+7,flag1,flag2,true);

return ans;
}



int main(){
    cin >> n;
    cout <<rec(0,false,false,false) << endl;
    return 0;
}

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

int main(){
    int a,b;
    char op;
    cin>>a>>op>>b;
    while(op!='?'){
        int c;
        if (op=='+') c=a+b;
        if (op=='-') c=a-b;
        if (op=='*') c=a*b;
        if (op=='/') c=a/b;
        cout<<c<<endl;
        cin>>a>>op>>b;
    }return 0;
}


Measured memory_bytes: 3096
#include <cstdio>
 
using namespace std;
 
const int nil = -1;
const int MAX_N = 256;
 
struct Node {
  int l, r, cnt;
  Node() {
    l = r = nil;
    cnt = 0;
  }
};
 
Node v[MAX_N];
int nodeIndex;
 
int parse(const char *s, int n, int root) {
  v[root].cnt++;
  if (s[++n] != ',') {
    if (v[root].l == nil) v[root].l = ++nodeIndex;
    n = parse(s, n, v[root].l);
  }
  if (s[++n] != ')') {
    if (v[root].r == nil) v[root].r = ++nodeIndex;
    n = parse(s, n, v[root].r);
  }
  return n+1;
}
 
void print(int root, int cnt) {
  if (v[root].cnt < cnt) return;
  putchar('(');
  if (v[root].l != nil) print(v[root].l, cnt);
  putchar(',');
  if (v[root].r != nil) print(v[root].r, cnt);
  putchar(')');
}
 
int main() {
  char op[5], t1[1024], t2[1024];
  while (scanf("%s %s %s", op, t1, t2) == 3) {
    for (int i=0;i<MAX_N;i++) v[i] = Node();
    nodeIndex = 0;
    parse(t1, 0, 0);
    parse(t2, 0, 0);
    print(0, (op[0]=='u'?1:2)); putchar('\n');
  }
  return 0;
}


Measured memory_bytes: 2584
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    vector<int> l(n);
    for(int i=0;i<n;i++){
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    int ans=0;
    for(int i=0; i<k; i++){
        ans +=l[n-1-i];
    }
    cout << ans << endl;
}




Measured memory_bytes: 256
H, W = map(int, input().split())
S = [input() for i in range(H)]
ans = [['#' for i in range(W)] for i in range(H)]
for x in range(W):
    for y in range(H):
        num = 0
        if S[y][x] == '.':
            for dx, dy in [1, 0], [-1, 0], [0, 1], [0, -1], [1, 1], [-1, -1], [1, -1], [-1, 1]:
                if 0 <= y + dy <= H - 1 and 0 <= x + dx <= W - 1:
                    if S[y + dy][x + dx] == '#':
                        num += 1
            ans[y][x] = str(num)

for i in ans:
    print(''.join(i))

Measured memory_bytes: 3188
N = int(input())
t = [0]*N
x = [0]*N
y = [0]*N
for i in range(N):
    t[i], x[i], y[i] = map(int, input().split())
    
for i in range(N):
    if(x[i]+y[i] > t[i]):
        print("No")
        break
    if((x[i]+y[i])%2 == 0):
        if(t[i]%2 != 0):
            print("No")
            break
    else:
        if(t[i]%2 == 0):
            print("No")
            break
else:
    print("Yes")

Measured memory_bytes: 11636
#include <algorithm>
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;

    int ds = 0, x = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == '(') {
            ds++;
        } else {
            ds--;
        }

        x = min(x, ds);
    }

    for (int i = 0; i < -x; i++) {
        cout << "(";
    }

    cout << s;

    for (int i = 0; i < ds - x; i++) {
        cout << ")";
    }

    cout << endl;
}


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

def main():
    H,_ = map(int, input().split())
    a = input().strip()
    for _ in range(H-1):
        b = input().strip()
        if a.rfind("#") > b.find("#"):
            print("Impossible")
            return
        a = b
    print("Possible")

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i

ans = 0

(0..a).each do |i|
  (0..b).each do |j|
    r = x - ( 500 * i + 100 * j )
    break if r < 0
    ans += 1 if (r / 50 <= c and r % 50 == 0)
  end
end

puts ans


Measured memory_bytes: 3836