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

#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define FORD(i,a,b) for(int i=a;i>=b;--i)
#define maxn 3010

typedef long long ll;
using namespace std;

int n, A[maxn];
ll F[maxn][maxn][2];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	FOR(i, 1, n) cin >> A[i];
    FORD(i, n, 1)
    FOR(j, i, n) {
        if (i == j) {
            F[i][j][0] = A[i];
            F[i][j][1] = -A[i];
            continue;
        }
        F[i][j][0] = max(F[i+1][j][1] + A[i], F[i][j-1][1] + A[j]);
        F[i][j][1] = min(F[i+1][j][0] - A[i], F[i][j-1][0] - A[j]);
    }
    cout << F[1][n][0];
	return 0;
}


Measured memory_bytes: 141568
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    vector<string> Days{
        "SUN", "MON", "TUE", "WED", "THU",
        "FRI", "SAT"
    };

    string s;
    cin >> s;

    for (int i = 0; i < Days.size(); ++i) {
        if (Days[i] == s) {
            for (int j = 1; j < 10; ++j) {
                if (Days[(i + j) % 7] == "SUN") {
                    cout << j << "\n";
                    return 0;
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
/*

0 1 2 3 4 5

0 5
1 3
2 4

01234567

0..2n-1
n(2n-1 + 2k)

2n..3n-1
n((5n-1)/2 + k)


k <= (n+1)/2

n=3
k=2

234 567 8910

n=5
k=3
3 4 5 6 7 8 9 10 11 12 / 13 14 15 16 17


17, 12 5
16, 9 7
15, 11 4
14, 8 6
13, 10 3
 
*/
// use std::cmp;
// use std::collections::HashMap;
// use std::collections::HashSet;
// use std::collections::VecDeque;
// use std::collections::BTreeSet;


// const INF: i64 = 1_000_000_000;
// const MOD: i64 = 998244353;

fn main() {
    let cin = stdin();
    let mut sc = Scanner::new(cin.lock());
    let n: i64 = sc.read();
    let k: i64 = sc.read();
    if 2 * k > n + 1 {
        println!("{}", -1);
    } else {
        for i in 0..n {
            let c = 2*n + i;
            let (a, b) = if i % 2 == 0 {
                (i/2, n + n/2 + i/2)
            } else {
                (n - n/2 + i/2, n + i/2)
            };
            println!("{} {} {}", k+a, k+b, k+c);
        }
    }
}

// thanks, ir5
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


Measured memory_bytes: 6268
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int a, b;

int main()
{
    cin >> a >> b;
    if ( a > b) cout << a - 1 << endl;
    else cout << a << endl;
    return 0;

}

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

const int M = 1000000007;

int main() {
    int n, h, d; cin >> n >> h >> d;
    long long coeff = 0;
    for (int i = n; i >= 1; i--) coeff = i * (1 + coeff) % M;
    vector<long long> dp(h, 0), acc(h+1, 0);
    dp[0] = 1;
    for (int i = 2; i <= n; i++) dp[0] = dp[0] * i % M;
    acc[1] = dp[0];
    for (int i = 1; i < h; i++) {
        dp[i] = (acc[i] - acc[max(0, i-d)]) * coeff % M;
        acc[i+1] = (acc[i] + dp[i]) % M;
    }
    cout << ((acc[h] - acc[h-d]) % M + M) % M << endl;
}


Measured memory_bytes: 18516
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Collections;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            ArrayList<Integer> a = new ArrayList<>();
            for (int i = 0; i < n; i++) a.add(in.nextInt());
            a.sort(Collections.reverseOrder());

            int sumA = 0;
            int sumB = 0;
            for (int i = 0; i < n; i++) {
                if (i % 2 == 0) sumA += a.get(i);
                else sumB += a.get(i);
            }

            out.println(sumA - sumB);
        }

    }
}



Measured memory_bytes: 22996
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main {
    public static void main (String[] args) throws IOException {
	BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
	int[] days = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	String[] dayOfWeek = {"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"};
	String line;
	String[] input;
	int month, day, numMonth, numDay;
	while ((line = br.readLine()) != null) {
	    input = line.split(" ");
	    month = Integer.parseInt(input[0]);
	    day = Integer.parseInt(input[1]);
	    if (month == 0 && day == 0) {
		break;
	    }
	    numMonth = month - 1;
	    numDay = day;
	    for (int i = 0; i < numMonth; i++) {
		numDay += days[i];
	    }
	    System.out.println(dayOfWeek[(numDay - 1) % 7]);
	}
    }
}

Measured memory_bytes: 24184
#include <string>
#include <iostream>
#include <vector>

int main() {
  std::string s;
  std::cin >> s;
  int n = (int) s.size();
  std::vector<std::vector<int>> dp(n + 1, std::vector<int>(5, -1));
  dp[0][0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int pr = 0; pr <= 4; ++pr) {
      if (dp[i][pr] == -1) continue;
      for (int ne = 1; ne <= 4 && i + ne <= n; ++ne) {
	if (s.substr(i, ne) == s.substr(i - pr, pr)) continue;
	dp[i + ne][ne] = std::max(dp[i + ne][ne], dp[i][pr] + 1);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= 4; ++i) {
    ans = std::max(ans, dp[n][i]);
  }
  std::cout << ans << std::endl;
}


Measured memory_bytes: 11396
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int Mod=1000000007;
int fpow(int a,int b)
{
	int ans=1,t=a;
	while(b)
	{
		if(b&1)ans=1ll*ans*t%Mod;
		t=1ll*t*t%Mod;
		b>>=1;
	}
	return ans;
}
int fac[3000010],inv[3000010];
void init()
{
	int N=3000000;
	fac[0]=1;
	for(int i=1;i<=N;i++)
		fac[i]=1ll*fac[i-1]*i%Mod;
	inv[N]=fpow(fac[N],Mod-2);
	for(int i=N;i>=1;i--)
		inv[i-1]=1ll*inv[i]*i%Mod;
	return ;
}
int C(int n,int m)
{
	if(n<0||m<0||n-m<0)return 0;
	return 1ll*fac[n]*inv[m]%Mod*inv[n-m]%Mod;
}
int F(int n,int m)
{
	return C(n+m,m);
}
int G(int x1,int y1,int x2,int y2)
{
	return F(abs(x2-x1),abs(y2-y1));
}
struct Point{
	int x,y,t;
	Point(int a=0,int b=0,int c=0){
		x=a;
		y=b;
		t=c;
	}
}p1[4],p2[4];
int x[6],y[6];
int solve(Point a,Point b)
{
	int ans=0;
	int x1=x[2],x2=x[3];
	int y1=y[2],y2=y[3];
	for(int i=x1;i<=x2;i++)
	{
		ans=(ans-1ll*G(a.x,a.y,i,y1-1)*G(i,y1,b.x,b.y)%Mod*(i+y1))%Mod;
		ans=(ans+1ll*G(a.x,a.y,i,y2)*G(i,y2+1,b.x,b.y)%Mod*(i+y2+1))%Mod;
	}
	for(int i=y1;i<=y2;i++)
	{
		ans=(ans-1ll*G(a.x,a.y,x1-1,i)*G(x1,i,b.x,b.y)%Mod*(x1+i))%Mod;
		ans=(ans+1ll*G(a.x,a.y,x2,i)*G(x2+1,i,b.x,b.y)%Mod*(x2+i+1))%Mod;
	}
	ans=ans*a.t*b.t;
	if(ans<0)ans+=Mod;
	return ans;
}
int main()
{
	init();
	for(int i=0;i<6;i++)
		scanf("%d",&x[i]);
	for(int i=0;i<6;i++)
		scanf("%d",&y[i]);
	p1[0]=Point(x[0]-1,y[0]-1,1);
	p1[1]=Point(x[0]-1,y[1],-1);
	p1[2]=Point(x[1],y[0]-1,-1);
	p1[3]=Point(x[1],y[1],1);
	p2[0]=Point(x[5]+1,y[5]+1,1);
	p2[1]=Point(x[5]+1,y[4],-1);
	p2[2]=Point(x[4],y[5]+1,-1);
	p2[3]=Point(x[4],y[4],1);
	int ans=0;
	for(int i=0;i<4;i++)
		for(int j=0;j<4;j++)
			ans=(ans+solve(p1[i],p2[j]))%Mod;
	printf("%d\n",ans);
	return 0;
}

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

#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define ALL(obj) (obj).begin(),(obj).end()
#define space <<" "<<
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
#define FIX <<fixed<<setprecision(10)<<
using namespace std;

using ll = long long; using ull = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;

const ll MOD = 1e9+7;
int face[6];
int sw;
class dice{
public:
    void operate(char order);
};

void dice::operate(char order){
if(order=='E'){
    sw=face[5];
    face[5]=face[2];
    face[2]=face[0];
    face[0]=face[3];
    face[3]=sw;
}else if(order=='W'){
    sw=face[5];
    face[5]=face[3];
    face[3]=face[0];
    face[0]=face[2];
    face[2]=sw;
}else if(order=='N'){
    sw=face[5];
    face[5]=face[4];
    face[4]=face[0];
    face[0]=face[1];
    face[1]=sw;
}else if(order=='S'){
    sw=face[5];
    face[5]=face[1];
    face[1]=face[0];
    face[0]=face[4];
    face[4]=sw;
}
}

int main(){

int q;
int quest1,quest2;
dice dice;
REP(i,6){
    cin>>face[i];
}
cin>>q;
REP(i,q){
    cin>>quest1>>quest2;
    if(quest1==face[1])dice.operate('N');
    else if(quest1==face[2])dice.operate('W');
    else if(quest1==face[3])dice.operate('E');
    else if(quest1==face[4])dice.operate('S');
    else if(quest1==face[5]){
        dice.operate('N');
        dice.operate('N');
    }
    if(quest2==face[1])cout<<face[2]<<endl;
    else if(quest2==face[2])cout<<face[4]<<endl;
    else if(quest2==face[4])cout<<face[3]<<endl;
    else if(quest2==face[3])cout<<face[1]<<endl;
}
}



Measured memory_bytes: 3104
from collections import deque
S = input()
aaa = list(S)
aaa.reverse()
sss = "".join(aaa)

Q = int(input())
d = deque()
d.append(S)
rev = 1
cnt = 0

for i in range(Q):
  List = list(input().split())
  a = int(List[0])
  if a == 1:
    rev = rev * -1
  else:
    b = int(List[1])
    if (b == 1 and rev == 1) or (b == 2 and rev == -1):
      d.appendleft(List[2])
      cnt = cnt + 1
    else:
      d.append(List[2])

if rev == -1:
  d[cnt] = sss
  d.reverse()
string = "".join(list(d))
print(string)


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

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

    int ans1 = min(a, b);
    int ans2 = max(0, a + b - n);
    cout << ans1 << ' ' << ans2 << endl;

    return 0;
}


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

int main(void){
    int n;
    cin >> n;

    int count, ans = 0;
    for(int i=1; i<=n; i+=2){
        count = 0;
        for(int j=1; j<=i; j+=2){
            if(i%j == 0){
                count++;
            }
        }
        if(count == 8){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

typedef long long ll;

ll f(ll n) {
	if (n == 1)
		return 1;
 	return f(n / 2) * 2 + 1;
}

int main() {
	ll n;
  	cin >> n;
  	cout << f(n);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
#define MAX 5100000
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;

int main(){
  ll N,K,C,ans=0;
  string S;
  cin>>N>>K>>C>>S;
  
  ll L[K],R[K]; // L[i]=仕事iが可能な日にちの最小値,R[i]=仕事iが可能な日にちの最大値
  ll cnt=0;
  for(ll i=0; i<N; ++i){
    if(S[i]=='o'){
      L[cnt]=i;
      cnt++;
      i+=C;
    }
    if(cnt==K) break;
  }
  cnt=K-1;
  for(ll i=N-1; i>=0; --i){
    if(S[i]=='o'){
      R[cnt]=i;
      cnt--;
      i-=C;
    }
    if(cnt==-1) break;
  }
  
  REP(i,K){
    if(L[i]==R[i]) co(L[i]+1);
  }
  cout<<endl;
  return 0;
}

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

#define ff              first
#define ss              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
//mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}

int main()
{
	c_p_c();
	int n, W;
	cin >> n >> W;
	int weights[105];
	ll values[105];
	for (int i = 1; i <= n; i++) {
		cin >> weights[i] >> values[i];
	}
	int max_val = 0;
	for (int i = 1; i <= n; i++) {
		max_val += values[i];
	}
	ll *prev = new ll[max_val + 1];
	ll *curr = new ll[max_val + 1];
	for (int i = 1; i <= max_val; i++) {
		prev[i] = INT_MAX;
	}
	prev[0] = curr[0] = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= max_val; j++) {
			ll inc = INT_MAX , exc;
			exc = prev[j];
			if (j - values[i] >= 0) {
				inc = weights[i]  + prev[j - values[i] ];
			}
			if (inc < exc) {
				curr[j] = inc;
			} else {
				curr[j] = exc;
			}
		}
		ll* temp = prev;
		prev = curr;
		curr = temp;
	}
	int res;
	for (int i = 0; i <= max_val; i++) {
		if (prev[i] <= W) {
			res = i;
		}
	}
	cout << res << endl;
	delete [] prev;
	delete [] curr;
	return 0;
}


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



int main(){

while(1){
    int d,w;
    cin >> d >>w;
    if(d==0 && w==0)break;
    int ground[d][w];
    for(int i=0;i<d;i++){
        for(int j=0;j<w;j++){
            cin >>ground[i][j];
        }
    }
    int ans=0;
    vector<int> lake(0);
    vector<int> wall(0);
    for(int dstart=0;dstart<d-2;dstart++){
        for(int dend=dstart+2;dend<d;dend++){
            for(int wstart=0;wstart<w-2;wstart++){
                for(int wend=wstart+2;wend<w;wend++){
                    lake.clear();
                    wall.clear();
                    for(int dd=dstart;dd<=dend;dd++){
                        for(int ww=wstart;ww<=wend;ww++){
                            if(dd==dstart || dd==dend || ww==wstart|| ww==wend){
                                wall.push_back(ground[dd][ww]);
                            }
                            else lake.push_back(ground[dd][ww]);
                        }
                    }
                    if(wall.size()!=0)sort(wall.begin(),wall.end());
                    if(lake.size()!=0){
                        sort(lake.begin(),lake.end());
                        reverse(lake.begin(),lake.end());
                        }
                    int temp=0;
                    for(int pl=0;pl<lake.size();pl++)temp+=(wall[0]-lake[pl]);
                    if(wall[0]<=lake[0])temp=0;
                    ans=max(ans,temp);
                }
            }
        }
    }
    cout << ans <<endl;
    }

}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int main(){
long long int n,count=0;
  cin >> n;
  long long int a[n];
  for(int i=0;i<n;i++)cin >> a[i];
  for(int i=0;i<n;i++){
    if(a[a[i]-1]-1==i)count++;
  }
  cout <<count/2 <<endl;
}

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



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









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

const int MOD = 1000000007;

int main(){
    ll n; cin>>n;
    
    ll power = 1;
    for(int i=1; i<=n; i++){
        power *= i;
        power %= MOD;
    }
    
    cout << power << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>


int main()
{
	int answer, W,a,b;
	scanf("%d %d %d",&W, &a, &b);
	if ((b+W)<=a)
		answer = a-(b+W);
	else
		answer = b-(a+W);
	if (answer<0)
		answer = 0;
	printf("%d",answer);
	
	return 0;
}

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

int arr[100009];
vector<int> G[100009];
bool visited[100009];

int main() {

  	int x, y, n, m;
  	cin>>n>>m;
  	for(int i = 0; i <n; i++)
  		cin>>arr[i];
  	while(m--) {
  		cin>>x>>y;
  		G[x].push_back(y);
  		G[y].push_back(x);
  	}
  	int ans = 0;
  	
  	for(int i = 1; i <= n; i++) {
  		if(visited[i])	continue;
  		else {
  			visited[i] = true;
  			bool flag = true;
  			for(auto u: G[i]) {
  				if(arr[i - 1] > arr[u - 1]) {
  					visited[u] = true;	
  				} else {
  					// cout<<"breaking for "<<i<< " and u = "<<u<< endl;
  					flag = false;
  					break;
  				}
  			}
  			if(flag) ans++;
  		}
  	}
  	
  	cout<<ans<<endl;
  	
}
	

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define pll pair<ll,ll>
#define vll vector<ll>
#define forn(i,n) for(ll i=0; i<n; ++i)
#define pb push_back
#define MOD 1000000007
#define range(c) c.begin() , c.end()
#define Print(a) for(auto it : a)cout << (it) <<" ";cout << endl;
#define test ll t;cin >> (t);while(t--)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : ";cout << arg1 <<" ";}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {const char *comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : ";
cout << arg1 <<" ";cout << " | ";__f(comma + 1, args...);}
char local ='O';
#define db(...) if(local=='L') {__f(#__VA_ARGS__, __VA_ARGS__); cout<<endl;}
//////////////////////////////////////////////////////////////
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
	local = 'L';
#endif

	ll h,w,m;
	cin >> h >> w>> m;
	map<int,int> r,c;
	set<pll> s;
	forn(i,m)
	{
		ll x,y;
		cin >> x >> y;
		s.insert({x,y});
		r[x]++;
		c[y]++;
	}
	ll ans = 0;
	for(auto it:r)
	{
		if(it.second > ans)
		{
			ans = it.second;
		}
	}
	vll xmax;
	for(auto it:r)
	{
		if(it.second == ans)
			xmax.pb(it.first);
	}
	ll ans2 = 0;
	for(auto it:c)
	{
		if(it.second > ans2)
		{
			ans2 = it.second;
		}	
	}
	vll ymax;
	for(auto it:c)
	{
		if(it.second == ans2)
			ymax.pb(it.first);
	}
	for(ll xx : xmax)
	{
		for(ll yy : ymax)
		{
			if(s.find({xx,yy}) == s.end())
			{
				cout << ans + ans2;
				return 0;
			}
		}
	}

	cout << ans + ans2 -1;

}


Measured memory_bytes: 58424
using System;

namespace algo
{
    class Program
    {
        static void Main(string[] args)
        {
            var result = false;
            var s = Console.ReadLine();
            foreach (var item in s)
            {
                if(item == '7') result = true;
            }
            if(result) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 25864
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int nm = 1e5;
int n, inf, sup, a[nm];

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		if (!i) {
			inf = a[0];
			sup = a[0];
		}
		inf = min(inf, a[i]);
		sup = max(sup, a[i]);
	}

	if (sup - inf > 1) {
		cout << "No" << endl;
		return 0;
	}

	if (inf == sup) {
		cout << (inf == n - 1 || inf <= n / 2 ? "Yes" : "No") << endl;
		return 0;
	}

	int c = 0;
	for (int i = 0; i < n; ++i)
		if (a[i] == inf)
			++c;
	cout << (c < sup && sup - c <= (n - c) / 2 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 4016
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){
  unsigned long long int X, ans = 0, year = 0, money = 100 ;
  cin >> X ;
  while(X > money){
    year++ ;
    money += money / 100 ;
  }
  cout << year << endl ;
  return 0 ;
}  

Measured memory_bytes: 3636
#include<stdio.h>

int main(){
  int j,i,n,min,max;
  int a[200000];
  
  scanf("%d",&n);

  for(i=0;i<n;i++) scanf("%d",&a[i]); //配列に入力

  min = a[0]; 
  max = a[1] - min;
  
  for(j=1;j<n;j++){ // 利益の算出
    if(a[j-1]<min)
      min = a[j-1];
    if(max < a[j] - min)
      max = a[j] - min;
  }
  
  printf("%d\n",max);

  

  return 0;
}



Measured memory_bytes: 2576
#include<iostream>
#include<cstdio>
#include<string>

using namespace std;

int main(void){
	int num=0,res=0,type=0,flag;
	string str;
	cin >> str;
	for(int i=0;i<str.size();i++){
		res*=10;
		res+=str[i]-'0';
	}
	while(1){
		cin >> str;
		if(str=="=")break;
		else if(str=="+")type=1;
		else if(str=="-")type=2;
		else if(str=="*")type=3;
		else if(str=="/")type=4;
		else{
			num=0,flag=0;
			for(int i=0;i<str.size();i++){
				if(str[i]=='-')flag=1;
				else{
					num*=10;
					num+=str[i]-'0';
				}
			}
			if(flag==1)num=-num;
			if(type==1)res+=num;
			else if(type==2)res-=num;
			else if(type==3)res*=num;
			else if(type==4)res/=num;
		}
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <string>

using namespace std;

bool is_easy_to_dance(string s) {
    for (int i = 0; i < s.length(); i += 2) {
        if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') {
            return false;
        }
    }
    for (int i = 1; i < s.length(); i += 2) {
        if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D') {
            return false;
        }
    }
    return true;
}

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

    if (is_easy_to_dance(s))
        cout << "Yes\n";
    else
        cout << "No\n";
}


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

int main(){
  string s;
  cin>>s;
  for(int i=0; i<5; i++){
    cout<<s.at(i);
  }
  cout<<" ";
  for(int i=6; i<13; i++){
    cout<<s.at(i);
  }
  cout<<" ";
  for(int i=14; i<19; i++){
    cout<<s.at(i);
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#define INF 1000000000
using namespace std;
int main() {

	int n, m; cin >> n >> m;
	if (n == m) { cout << "Yes" << endl;}
	else { cout << "No" << endl; }

	return 0;
}

Measured memory_bytes: 256
A,B,K = map(int,input().split())
s = set()
for i in range(K):
    if A+i > B:
        break
    s.add(A+i)
for i in range(K):
    if B-i < A:
        break
    s.add(B-i)
s = list(s)
s.sort()
for i in s:
    print(i)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef long long ll;
#define loop(n)      for(int i=0;i<(n);i++)
#define lp(x,s,e)    for(int x=(s);x<(e);x++)
#define lpe(x,s,e)    for(int x=(s);x<=(e);x++)
#define MP make_pair
#define PB push_back
#define all(a)  a.begin(),a.end()
#define clr(x,val) memset((x),(val),sizeof(x))
#define endl '\n'

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    string s[n];
    set<string>freq;
    loop(n){
    cin>>s[i];
    freq.insert(s[i]);}
    if(freq.size()!=n){
        cout<<"No";
        return 0;}
    for(int i=0;i<n-1;i++){
    int x1=s[i].size();
    int x2=s[i+1].size();
    if(s[i][x1-1]!=s[i+1][0]){
        cout<<"No";
        return 0;
    }
   }
   cout<<"Yes";
   return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

struct Edge {
	int from;
	int to;
	int cost;
};

vector< Edge > e;
int d[MAX_N];

signed main() {
  INIT;
	VAR(int, n, m);
	REP(i, m) {
		VAR(int, a, b, c);
		a--; b--;
		e.push_back(Edge{a, b, -c});
	}
	fill(d, d + n, LINF);

	d[0] = 0;
	REP(i, n) {
		EACH(t, e) {
			if (d[t.from] != LINF && d[t.to] > d[t.from] + t.cost) {
				// 更新できる時は更新
				d[t.to] = d[t.from] + t.cost;

				if (i == n - 1 && t.to == n - 1) {
					// 閉路ができちゃってるとき
					OUT("inf")BR;
					return 0;
				}
			}
		}
	}
	int ans = -d[n - 1];
	OUT(ans)BR;
  
  return 0;
}


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

using namespace std;

#define INF (1ll << 62)
#define pb push_back
#define ii pair<int,int>
#define OK (cerr <<"OK"<< endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define endl '\n'

signed main () {
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n = 3;

  int mat[n][n];

  for(int i = 0; i < n; i++)  
    for(int j = 0; j < n; j++)  
      cin >> mat[i][j];

  int q;
  cin >> q;
  while(q--) {
    int x;
    cin >> x;

    for(int i= 0; i < n; i++)
      for(int j = 0; j < n; j++) {
        if(mat[i][j] == x)
          mat[i][j] = -x;
      }
  }

  // row
  string ans = "No";
  for(int i = 0; i < n; i++) {
    bool valid = true;
    for(int j = 0; j < n; j++) {
      if(mat[i][j] > 0)
        valid = false;
    }
    if(valid)
      ans = "Yes";
  }

  for(int j= 0; j < n; j++) {
    bool valid = true;
    for(int i = 0; i < n ; i++) {
      if(mat[i][j] > 0)
        valid = false;
    }
    if(valid)
      ans = "Yes";
  }

  {
    bool valid = true;
    for(int i = 0; i < n; i++) {
      if(mat[i][i] > 0)
        valid = false;
    }
    if(valid)
      ans = "Yes";
  }

  {
    bool valid = true;
    for(int i = 0, j = n - 1; i < n; i++, j--) {
      if(mat[j][i] > 0)
        valid = false;
    }
    if(valid)
      ans = "Yes";
  }

  cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int h, w;

  while(1){
    cin >> h >> w;
    if(h == 0 && w == 0){ break; }
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	if(i%2){
	  if(j%2){ cout << "#"; }
	  else { cout << "."; }
	}
	else{
	  if(j%2){ cout << "."; }
	  else { cout << "#"; }
	}
      }
      cout << endl;
    }
    cout << endl;
  }

  return 0;
}



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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll n;
  cin >> n;
  llvec a(n);
  rep(i, n)cin >> a[i];
  llvec d(n, 0);
  ll cur = 0;
  while(d[a[cur]-1]==0){
    d[a[cur]-1] = d[cur]+1;
    cur = a[cur]-1;
  }
  //DUMP(i, d);cerr << endl;
  ll ans = d[1];
  if(ans==0)cout << -1;
  else cout << ans;
  return 0;
}


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

int main(){
    int w,h,n;
    cin>>w>>h>>n;
    vector<pair<int,int>> a(n);
    for (int i = 0; i < n; ++i) {
        cin>>a[i].first;
        cin>>a[i].second;
    }
    int cx=a[0].first;
    int cy=a[0].second;
    int ans=0;
    for (auto i:a){
        int dx=i.first-cx;
        int dy=i.second-cy;

        ans+=abs(dx)+abs(dy);
        if(dx*dy>0){
            ans-=min(abs(dx),abs(dy));
        }
        cx=i.first;
        cy=i.second;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3120
N = int(input())
A = 0
B = 0
AB = 0
ans = 0
for _ in range(N):
    s = list(input())
    if s[0] == "B" and s[-1] == "A":
        AB += 1
    elif s[0] == "B":
        B += 1
    elif s[-1] == "A":
        A += 1
    for i in range(len(s) - 1):
        if s[i:i + 2] == list("AB"):
            ans += 1
if A == 0 and B == 0 and AB > 0:
    ans -= 1
print(ans + AB + min(A, B))

Measured memory_bytes: 3064
// Problem : 
// 			B - Minesweeper
// 			Editorial
// 		
// Contest : AtCoder - AtCoder Beginner Contest 075
// URL : https://atcoder.jp/contests/abc075/tasks/abc075_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;i<n;i++) 
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define vec(x)          vector<x>
#define matrix(x)       vector<vector<x>>
#define sz(x)             (int)x.size()
#define mem(a,b)        memset(a, b, sizeof a)
#define vii             vector<pair<int,int>>
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        (a*(b/gcd(a,b)))
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define MOD             998244353
#define deb(x)          cerr <<#x<<" = "<<x<<"\n"
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for (int i = a; i<b; ++i)
#define len(s)          s.length()
#define watch(x)         cout << #x << " = " << x << endl
#define trace(x)         cerr << #x << " = " << x << endl
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}

void angshuGod()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

const int N = 1e5+1;
const double pi = acos(-1);

char grid[52][52];
char ans[52][52];

int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 }; 
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 }; 

int n,m; 
bool isvalid(int x,int y){
	return (x>=0 and x<n and y>=0 and y<m);
}

void solve(){
    
	cin>>n>>m;
	fo(i,n){
		fo(j,m)
			cin>>grid[i][j];
	}
	for(int i = 0;i<n;i++){
		for(int j = 0;j<m;j++){
			if(grid[i][j]=='.'){
				int cnt = 0;
				for(int k = 0;k<8;k++){
					int nx = i + dx[k];
					int ny = j + dy[k];
					if(isvalid(nx,ny) and grid[nx][ny]=='#') cnt++;			
				}
				ans[i][j] = (char)(cnt+'0');
			}
			else ans[i][j] = '#';
		}
	}
	fo(i,n){
		fo(j,m){
			cout<<ans[i][j];
		}
		cout<<"\n";
	}
}

 
int32_t main()
{
    angshuGod();

    int t;

    t = 1;
    //cin>>t;

    while(t--){
        solve();
    }
    
    return 0;
}

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

int main(void) {
	int x, y;
	while(1){
		cin >> x >> y;
		if (x > y) {
			cout << y << " " << x << endl;
		}
		else if (x == 0, y == 0) break;
		else {
			cout << x << " " << y << endl;
		}
	}
	return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL){
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL){
    x = x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){

  if(u==NIL||k==u->key) return u;
  if(k<u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);

}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL) return treeMinimum(x->right);

  y = x->parent;
  while(y!=NIL && x==y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL||z->right==NIL) y=z;
  else y=treeSuccessor(z);
  
  if(y->left!=NIL) x=y->left;
  else x=y->right;
  
  if(x!=NIL) x->parent=y->parent;
  
  if(y->parent==NIL) root=x;
  else if(y==y->parent->left) y->parent->left=x;
  else y->parent->right=x;

  if(y!=z) z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if(z->key<x->key) x=x->left;
    else x=x->right;
  }
  z->parent = y;

  if(y==NIL) root=z;
  else if(z->key<y->key) y->left=z;
  else y->right=z;
}

void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){

  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }
    else if (com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  
  return 0;
}

Measured memory_bytes: 19364
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		long d = scan.nextInt();
		long[] x = new long[n];
		long[] y = new long[n];
		for(int i = 0;i < n; ++i){
			x[i] = scan.nextInt();
			y[i] = scan.nextInt();
		}
		int count = 0;
		for(int i = 0;i < n; ++i){
			long distance = x[i]*x[i] + y[i]*y[i];
			count += distance <= d*d? 1 : 0;
		}

		System.out.print(count);
	}
}


Measured memory_bytes: 63208
#[allow(unused_imports)]
use std::cmp::{max, min};

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    // from kenkoooooo
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.read()).collect()
    }

    fn usize_read(&mut self) -> usize {
        self.read()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}

fn main() {
    let mut sc = Scanner::new();
    let s: String = sc.read();
    let mut ret = s.chars().filter(|x| x == &'+').count() as i64;
    ret -= s.chars().filter(|x| x == &'-').count() as i64;
    println!("{}", ret);
}


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

using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define lin "\n"
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(0)
#define mod 1000000007
ll dp[2005];

void khelo() {
    dp[3] = dp[4] = dp[5] = 1;
    for (int i = 6; i <= 2000; ++i) {
        dp[i] = (dp[i - 1] + dp[i - 3]) % mod;
    }
}

void solve() {
    int n;
    cin >> n;
    cout << dp[n];
}

int main() {
//        fast_io;
    khelo();
    int t = 1;
    //    cin >> t;
//    scanf("%d", &t);
    int c = 1;
    while (t--) {
//        printf("Case %lld:\n", c);
        //        cout<<"Case "<<c<<": ";
        solve();
        c++;
    }
}

Measured memory_bytes: 3660
from collections import Counter
n = int(input())
nums = input()
A =[int(x.strip()) for x in nums.split()]

S = [0]
for i in range(n):
    S.append(S[i]+A[i])

co = Counter(S)
# print(S)
# print(co)

ans = 0
for i in co.values():
    if i > 1:
        ans += i*(i-1) /2

print(int(ans))


Measured memory_bytes: 43508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX=1001001;
const ll MOD=1000000007;
int main()
{
    ll INF=10000000;
    ll n, m;
    cin>>n>>m;
    ll ans=0;
    vector<vector<char>> maze(n, vector<char>(m));
    rep(i, n) {
        rep(j, m) {
            cin>>maze[i][j];
        }
    }

    vector<vector<ll>> d(n, vector<ll>(m));
    ll dx[4]={ 1, 0, -1, 0 }, dy[4]={ 0, 1, 0, -1 };

    rep(i, n) {
        rep(j, m) {
            d[i][j]=INF;
        }
    }
    queue<P> que;
    rep(i, n) {
        rep(j, m) {
            if (maze[i][j]=='#') {
                que.push(pair<int, int>(i, j));
                d[i][j]=0;
            }
        }
    }
    while (!que.empty()) {
        P p=que.front();que.pop();
        for (ll i=0; i<4;i++) {
            ll nx=p.first+dx[i], ny=p.second+dy[i];

            if (0<=nx&&nx<n&&0<=ny&&ny<m) {

                if (d[nx][ny]==INF) {
                    d[nx][ny]=d[p.first][p.second]+1;
                    que.push(P(nx, ny));
                }
            }
        }
    }
    rep(i, n) {
        rep(j, m) {
            ans=max(ans, d[i][j]);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 28336
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int A[] = new int[n];
        for(int i = 0; i < n; i++){
          A[i] = sc.nextInt();
        }
        for(int x = 0; x < n; x++){
          if(x == n-1){
            System.out.println(A[x]);
          }else{
            System.out.print(A[x]);
            System.out.print(" ");
          }
        }
        for(int i = 1; i < n; i++){
          int v =A[i];
          int j = i -1;
          while(j>=0 && A[j]>v){
            A[j+1] = A[j];
            j = j-1;
            A[j+1] = v;
          }
          for(int x = 0; x < n; x++){
            if(x == n-1){
              System.out.println(A[x]);
            }else{
              System.out.print(A[x]);
              System.out.print(" ");
            }
          }
        }
      }
    }


Measured memory_bytes: 34024
N,A,B = map(int,input().split())
if((B-A)%2==0):
    print((B-A)//2)
else:
    ans = min(B-1,N-A)
    ans = min(ans,(B-A+1)//2+(A-1))
    A,B = N-B+1,N-A+1
    ans = min(ans,(B-A+1)//2+(A-1))
    print(ans)



Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>
 
using namespace std;
 
typedef long long int lld;
 
const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;
 
int main()
{
	lld a,b,c,d;
	cin >> a >> b >> c >> d;
 
	if (a*b > c*d)
	{
		cout << a*b << endl;
	}else
	{
		cout << c*d
 << endl;	}
 
	return 0;
}

Measured memory_bytes: 764
#!/usr/bin/python
# -*- coding: utf-8 -*-

# 入力はstringで入る．
# intにしたければ int(input())
# floatで受け取ると 1.0 になる．

# 入力
N, K = map(int,input().split()) 
Aori = list(map(int,input().split()))
A = [x-1 for x in Aori]

Arrival = [0]*N
NowTown = 0
Arrival[NowTown] = 1
ArrivalStep = [0]*N

Step = 0

if K <= N:
    for i in range(K):
        NowTown = A[NowTown]
    print(NowTown+1)
    exit()

while True:
    Step += 1
    NowTown = A[NowTown]
    if Arrival[NowTown] == 1:
        break
    ArrivalStep[NowTown] = Step
    Arrival[NowTown] = 1

RoopNumper = Step - ArrivalStep[NowTown]

Rest = K-Step

Rest %= RoopNumper

if Rest == 0:
    print(NowTown+1)
else:
    for i in range(Rest):
        NowTown = A[NowTown]
    print(NowTown+1)


Measured memory_bytes: 33672
while True:
    H,W=map(int,input().split())
    if  H==0 and  W==0:
        break
    else:
        for i in range(1,H+1):
            for l in range(1,W+1):
                if (i+l)%2==0:
                    print("#",end="")
                else:    
                    print(".",end="")
            print()
        print()


Measured memory_bytes: 7004
#include <bits/stdc++.h>
using namespace std;
unsigned long long upper, lower;
int main(){
    cin >> lower >> upper;
    int cnt = 1;
    while (1){
        if (lower * 2 <= upper){
            lower *= 2;
            ++cnt;
        }else{
            break;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class  Main {
	public static void main(String[] args) {
		double r;
		double area;
		Scanner scanner = new Scanner(System.in);
		
		r = scanner.nextDouble();
		
		area = r * 3.14 * 2;
		
		System.out.println(area);
	}
}

Measured memory_bytes: 37428
n = int(input())
a = list(map(int, input().split()))
ans = 1
x = 1000000000000000000
for i in range(n):
    if a[i] == 0:
        print(0)
        exit()
for i in range(n):
    ans *= a[i]
    if ans > x:
        print(-1)
        exit()
print(ans)


Measured memory_bytes: 21468