akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>              //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
int main()
{
 	ios::sync_with_stdio(0);
    cin.tie(0);
    lli n,m;
    cin>>n>>m;
    vp temp;
    for(lli i=0;i<n;i++){
    	lli x,y;cin>>x>>y;
    	temp.pb(mp(x,y));
	}
    sort(temp.begin(),temp.end());
    lli ans=0,req=m;
    lli i=0;
    while(req!=0){
    	if(req>=temp[i].se)
    	{
    		ans+=temp[i].se*temp[i].fi;
    		req=req-temp[i].se;
    		i++;
		}
    	else
    	{
    		ans+=req*temp[i].fi;
    		req=0;
		}
    	
	}
    cout<<ans;
    
    
    return 0;
}


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

using namespace std;

int main(void){
	int N;
	cin >> N;
	vector<int> h(N);
	for(int i=0;i<N;i++)cin >> h[i];
	int ans = 0;
	while(true){
		if(*max_element(h.begin(),h.end())==0)break;
		int i=0;
		while(i<N&&h[i]==0){
			i++;
		}
		ans ++;
		while(i<N&&h[i]>0){
			h[i]--;
			i++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */

int main() {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    rep(i, n) {
        int a;
        cin >> a;
        ans += 2 * min(a, k - a);
    }
    cout << ans << endl;
}

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

int main(){
	int n, m;
	cin >> n >> m;
	int a[n][m], b[n]{};
	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++){
		cin >> a[i][j];
		a[i][j]--;
	}
	bool c[m]{};
	int ans = 1 << 30;
	for(int i = 0; i < m; i++){
		int d[m]{};
		for(int j = 0; j < n; j++){
			while(c[a[j][b[j]]]) b[j]++;
			d[a[j][b[j]]]++;
		}

		for(int j = 0; j < m; j++) cerr << d[j] << ' ';
		cerr << endl;

		int maxi = -(1 << 30), p;
		for(int j = 0; j < m; j++) if(maxi < d[j]){
			maxi = d[j];
			p = j;
		}
		c[p] = true;
		ans = min(ans, maxi);
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
n,k=map(int,input().split())

mod=10**9+7

ans=0
for i in range(k,n+2):
#  print(i,(i-1)*i//2, (n+1)*n//2)
  sigma1=(i-1)*i//2
  sigma2=(n-i)*(n-i+1)//2
  sigma3=n*(n+1)//2
#  print(i,sigma1,sigma3-sigma2)

  ans+=sigma3-sigma2-sigma1+1
  ans%=mod
print(ans)

Measured memory_bytes: 9200
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val r = Array.fill(n)(sc.nextInt())

    var minv = r(0)
    var maxv = r(1) - r(0)

    (1 until n).foreach { j =>
      maxv = Math.max(maxv, r(j) - minv)
      minv = Math.min(minv, r(j))
    }

    println(maxv)
  }

}



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

    void add_edge(int x,int y){
        v[x].push_back(y);
        rv[y].push_back(x);
    }
    void dfs(int x){
        used[x]=true;
        for(auto to:v[x])if(!used[to])dfs(to);
        vs.push_back(x);
    }

    void rdfs(int x,int k){
        cmp[x]=k;
        for(auto to:rv[x])if(cmp[to]==-1)rdfs(to,k);
    }

    int scc(){
        rep(i,used.size())if(!used[i])dfs(i);
        reverse(vs.begin(),vs.end());
        int k=0;
        for(auto x:vs)if(cmp[x]==-1)rdfs(x,k++);
        return k;
    }
    void build(vector<vector<int>> &g){
        int k=scc();
        g.resize(k);
        set<pair<int,int>> used;
        rep(i,v.size()){
            for(auto& to:v[i]){
                int x=cmp[i],y=cmp[to];
                if(x==y||used.count({x,y}))continue;
                g[x].push_back(y);
                used.emplace(x,y);
            }
        }
    }
};

void solve(int n){
    map<pair<int,int>,int> mp;
    StronglyConnectedComponents scc(2*n);
    int d[]{1,0,-1,0,1};
    rep(i,n){
        int x,y;
        cin>>x>>y;
        char dir;
        cin>>dir;
        int nx=x,ny=y;
        if(dir=='x')++nx;
        else ++ny;
        rep(j,4){
            if(mp.count({x+d[j],y+d[j+1]})){
                scc.add_edge(2*i, mp[{x+d[j],y+d[j+1]}]);
                scc.add_edge(mp[{x+d[j],y+d[j+1]}],2*i);
                scc.add_edge(2*i+1, mp[{x+d[j],y+d[j+1]}]^1);
                scc.add_edge(mp[{x+d[j],y+d[j+1]}]^1,2*i+1);
            }
            if(mp.count({nx+d[j],ny+d[j+1]})){
                scc.add_edge(2*i+1, mp[{nx+d[j],ny+d[j+1]}]);
                scc.add_edge(mp[{nx+d[j],ny+d[j+1]}],2*i+1);
                scc.add_edge(2*i, mp[{nx+d[j],ny+d[j+1]}]^1);
                scc.add_edge(mp[{nx+d[j],ny+d[j+1]}]^1,2*i);
            }
        }
        mp[{x,y}]=2*i;
        mp[{nx,ny}]=2*i+1;
    }
    scc.scc();
    rep(i,n){
        if(scc.cmp[2*i]==scc.cmp[2*i+1]){
            cout<<"No"<<endl;
            return ;
        }
    }
    cout<<"Yes"<<endl;
    return ;
}
int main(){
    int n;
    while(cin>>n,n)solve(n);
    return 0;
}



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

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

    vector<int> a;
    int a_max=0;
    int ans=0;

    for(int i=0; i<n; i++){
        int tmp;
        cin>>tmp;

        a.push_back(tmp);
        if(a_max<tmp){
            a_max=tmp;
        }
    }
    

    sort(a.begin(), a.end());
    
    vector<bool> b(a_max+1);
    vector<int> cnt(a_max+1, 0);

    for(int i=0; i<n; i++){
        cnt[a[i]]++;
        for(int j=2; j<=a_max; j++){
            if(a[i]*j>a_max){
                break;
            }
            b[a[i]*j]=true;
        }
    }

    for(int i=0; i<n; i++){
        if(!b[a[i]] && cnt[a[i]]==1){
            ans++;
        }
    }


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

Measured memory_bytes: 7864
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string c, s;
    cin >> c >> s;
    int ans = 0;
    if(c[0] == s[0]) ans++;
    if(c[1] == s[1]) ans++;
    if(c[2] == s[2]) ans++;
    cout << ans << endl;
        
    
   
    
    
    
    
    
}


Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <tuple>
 
using namespace std;
 
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define cina(s, n, a) for(int i = s; i < n; i++) cin >> a[i]
#define couta(n, a) for(int i = 0; i < n; i++) cout << a[i] << ' '
#define copy(s, n, a, b) for(int i = s; i < n; i++) b[i] = a[i]
#define yesno(ok) cout << (ok ? "YES" : "NO")
#define mod(a, b) (b + (a % b)) % b
#define MOD (ll)1e9 + 7
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;


void solve(){
    ll n;
    cin >> n;
    int ans = INT_MAX;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            ans = min(max((int)log10(n / i) + 1, (int)log10(i) + 1), ans);
        }
    }
    cout << ans;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int q = 1;
    //cin >> q;
    for(int i = 1; i <= q; i++){
        solve();
    }
}


Measured memory_bytes: 512
#include <iostream>
#include <queue>
#include <functional>
#include <vector>
using namespace std;

int n, k;
int c[5000], r[5000];
int a[10000], b[10000];
vector<int> et[5000];		//???????????°??????
bool table[5000][5000];		//??°????????°??????

void input() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> c[i] >> r[i];
	for (int i = 0; i < k; i++) { cin >> a[i] >> b[i]; a[i]--; b[i]--; }
	for (int i = 0; i < k; i++) { et[a[i]].push_back(b[i]); et[b[i]].push_back(a[i]); }
}

void bfs(int start) {
	queue<int> que;
	int minCost[5000], i;
	
	for (i = 0; i < n; i++) minCost[i] = 114514;
	minCost[start] = 0;
	que.push(start);
	
	while (!que.empty()) {
		int v = que.front(); que.pop();
		for (int i = 0; i < et[v].size(); i++) {
			if (minCost[et[v][i]] > minCost[v] + 1) {
				minCost[et[v][i]] = minCost[v] + 1;
				que.push(et[v][i]);
			}
		}
	}
	for (i = 0; i < n; i++) table[start][i] = (minCost[i] <= r[start]);
}

int dijkstra() {
	int minCost[5000], i;
	bool updated[5000];
	
	for (i = 0; i < n; i++) {
		minCost[i] = 1145141919;
		updated[i] = false;
	}
	minCost[0] = 0;
	
	while (true) {
		int id = -1;
		for (i = 0; i < n; i++) {
			if (updated[i]) continue;
			if (id == -1 || minCost[id] > minCost[i]) {
				id = i;
			}
		}
		if (id == -1) { break; }
		
		updated[id] = true;
		for (i = 0; i < n; i++) {
			if (table[id][i] && minCost[i] > minCost[id] + c[id]) {
				minCost[i] = minCost[id] + c[id];
			}
		}
	}
	return minCost[n - 1];
}

int main() {
	input();
	for (int i = 0; i < n; i++) bfs(i);
	cout << dijkstra() << endl;
	return 0;
}

Measured memory_bytes: 27984
def solve():
    N, *A = map(int, open(0).read().split())

    B = [0] * N
    for i, a in enumerate(A):
        B[i] = a - (i + 1)
    B.sort()

    b = 0
    if N % 2 == 1:
        b = B[N // 2]
    else:
        b = (B[N // 2] + B[N // 2 - 1]) // 2

    ans = 0
    for i, a in enumerate(A):
        ans += abs(a - (b + i + 1))
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 25180
#include<iostream>
#include<vector>
#include<algorithm>
#define INF 1<<30
using namespace std;

int main(){
  int n,m;
  while(cin>>n>>m,n+m){
    vector<int> cn(m);
    vector<int> xn(n);
    for(int i=0;i<m;i++) cin>>cn[i];
    for(int i=0;i<n;i++) cin>>xn[i];
    vector<vector<int> > dp(n+1,vector<int>(256,INF));
    dp[0][128]=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<256;j++){
	if(dp[i][j] == INF) continue;
	for(int k=0;k<m;k++){
	  int calc=j+cn[k];
	  if(calc < 0) calc = 0;
	  if(calc > 255) calc= 255;
	  int t=(xn[i]-calc)*(xn[i]-calc)+dp[i][j];
	  dp[i+1][calc]=min(dp[i+1][calc],t);
	}
      }
    }
    int _min=1<<30;
    for(int i=0;i<256;i++){
      _min=min(_min,dp[n][i]);
    }
    cout<<_min<<endl;
  }

  return 0;
}

Measured memory_bytes: 22000
use std::fmt::Debug;
use std::io;
use std::io::{Read, Stdin};
use std::str;
use std::str::FromStr;

fn main() {
    let mut sc = Scanner::new();
    let (x, y) = (sc.parse(), sc.parse());
    if solve(x, y) {
        println!("Yes");
    } else {
        println!("No");
    }
}


fn solve(x: u32, y: u32) -> bool {
    fn group(n: u32) -> usize {
        match n {
            1 | 3 | 5 | 7 | 8 | 10 | 12 => 0,
            4 | 6 | 9 | 11 => 1,
            2 => 2,
            _ => panic!(),
        }
    }
    group(x) == group(y)
}


struct Scanner {
    stdin: Stdin,
    buf: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            buf: Vec::with_capacity(256),
        }
    }

    fn parse<T: FromStr>(&mut self) -> T
        where <T as FromStr>::Err: Debug
    {
        self.buf.clear();
        let mut it = self.stdin.lock().bytes();
        let mut c = it.next().unwrap().unwrap();
        while c == ' ' as u8 || c == '\n' as u8 {
            c = it.next().unwrap().unwrap();
        }
        while !(c == ' ' as u8 || c == '\n' as u8) {
            self.buf.push(c);
            c = it.next().unwrap().unwrap();
        }
        str::from_utf8(&self.buf).unwrap().parse::<T>().unwrap()
    }
}


Measured memory_bytes: 4352
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//cout<<setprecision(20)
const llint mod=1000000007;
const llint big=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int LBI(vector<lldo>&ar,lldo in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
int UBI(vector<lldo>&ar,lldo in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	//寿司を解く
	int n,i,j,Q;cin>>n>>Q;
	set<pair<int,llint>>hen;
	hen.ins(mp(0,big));
	hen.ins(mp(n,0));
	while(Q--){
		int a;llint b;cin>>a>>b;
		llint num=hen.lower_bound(mp(a,-big))->sec;
		while(-1){
			auto p=prev(hen.lower_bound(mp(a,big)));
			int ter=p->fir;
			llint sa=p->sec - num;
			if((a-ter)==0 || b/(a-ter)>=sa){
				b-=sa*(a-ter);
				num=p->sec;
				hen.erase(p);
			}else{
				num+=b/(a-ter);
				b%=a-ter;
				hen.ins(mp(a,num));
				if(b>0){hen.ins(mp(ter+b,num+1));}
				break;
			}
		}
	}
	vector<llint>ans(n);
	for(auto itr=hen.rbegin();itr!=hen.rend();itr++){
		if(itr->fir==0){break;}
		maxeq(ans[itr->fir -1],itr->sec);
	}
	for(i=n-1;i>0;i--){maxeq(ans[i-1],ans[i]);}
	for(i=0;i<n;i++){cout<<ans[i]<<endl;}
	return 0;
}

Measured memory_bytes: 8448
'use strict'

function main(s) {
  s = s.split('\n');

  const arr = s[1].split(' ').map(n => Number(n));
  const ans = Math.abs(Math.max(...arr) - Math.min(...arr));
  
  console.log(ans);
}

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


Measured memory_bytes: 11468
import sys
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10*5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

class UnionFind():

    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)

        if(x == y):
            return 

        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1


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

    def Count(self, x):
        return -self.root[self.Find_Root(x)]

n, k, l = MAP()
road = [0]*k
train = [0]*l
for i in range(k):
    p, q = MAP()
    road[i] = (p,q)
for i in range(l):
    r, s = MAP()
    train[i] = (r,s)

ans = [0]*n

uf_road = UnionFind(n)
uf_train = UnionFind(n)

for i in range(k):
    uf_road.Unite(road[i][0]-1, road[i][1]-1)
for i in range(l):
    uf_train.Unite(train[i][0]-1, train[i][1]-1)

roots = [(0,0)]*n
for i in range(n):
    a = uf_road.Find_Root(i)
    b = uf_train.Find_Root(i)
    roots[i] = (a, b)

c = Counter(roots)
for i in range(n):
    ans[i] = c[roots[i]]

for i in range(n):
    print(str(ans[i]) + " ", end = "")

    

Measured memory_bytes: 121948
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main() {
  int k,s; cin >> k >> s;
  
  int ans = 0;
  rep(i,k+1)rep(j,k+1){
    if(s-i-j >= 0 && s-i-j <= k) ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s; cin >> s;
    ll n = s.size();
    vl val(2019,0);
    ll cur = 0;
    ll fac = 1;
    val[cur]++;
    for(int i=0; i<n; ++i) {
        ll add = s[n-1-i]-'0';
        cur = (cur+add*fac)%2019;
        fac = (fac*10)%2019;
        val[cur]++;
    }
    ll res = 0;
    rep(i,2019) {
        res += val[i]*(val[i]-1)/2;
    }
    ct(res);
}


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

int main(){
    string n;
    cin >> n;
    if(n[0] == '7' || n[1] == '7' || n[2] == '7'){
        cout << "Yes" << endl;
        return 0;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3640
# coding:utf-8

in1 = input().split()

in1 = [int(i) for i in in1]
cnt = 0

for i in range(in1[0],in1[1]+1):
    a = i%10
    b = int((i/10)%10)
    c = int(i/100)%10
    d = int(i/1000)%10
    e = int(i/10000)

    if(a==e and b==d):
        cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int X, Y, A, B, C;
int p[100000];
int q[100000];
int r[100000];
int sr[100001];

signed main() {
	int i;
	
	cin >> X >> Y >> A >> B >> C;
	rep(i, A) cin >> p[i];
	rep(i, B) cin >> q[i];
	rep(i, C) cin >> r[i];
	
	sort(p, p + A, greater<int>());
	sort(q, q + B, greater<int>());
	sort(r, r + C, greater<int>());
	
	rep(i, C) sr[i + 1] = sr[i] + r[i];
	
	int ans = 0;
	if (C >= X + Y) { ans = sr[X + Y]; }
	
	int corP = 0;
	int corQ = 0;
	int hoge = 0;
	for (i = X + Y - 1; i >= 0; i--) {
		int eP = 0, eQ = 0;
		if (corP < X) eP = p[corP];
		if (corQ < Y) eQ = q[corQ];
		if (eP > eQ) {
			hoge += p[corP];
			corP++;
		}
		else {
			hoge += q[corQ];
			corQ++;
		}
		int res = hoge + sr[i];
		ans = max(ans, res);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
#pragma GCC optimize("Ofast")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC target("fma","avx2")
#pragma GCC target("xop","fma4")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#pragma GCC diagnostic error "-std=c++14"

#include<bits/stdc++.h>
#include<tr1/unordered_map>

using namespace std;

inline int read(){
	int x=0,f=1;
	char p=getchar();
	while(!isdigit(p)){
		if(p=='-') f=-1;
		p=getchar();
	}
	while(isdigit(p)) x=(x<<3)+(x<<1)+(p^48),p=getchar();
	return x*f;
}

const int maxn=85,bas=1e9+7,N=81*81;

int a[maxn][maxn],b[maxn][maxn],n,m,ans=1e9;
bitset<2*N> vec[maxn][maxn]; 

int main(){
	n=read();m=read();
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) a[i][j]=read();
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) b[i][j]=read();
	vec[1][1][N+a[1][1]-b[1][1]]=1;
	vec[1][1][N+b[1][1]-a[1][1]]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(i==1&&j==1) continue;
			int x=abs(a[i][j]-b[i][j]);
			vec[i][j]|=(vec[i-1][j]>>(x)),vec[i][j]|=(vec[i][j-1]>>(x));
			vec[i][j]|=(vec[i-1][j]<<(x)),vec[i][j]|=(vec[i][j-1]<<x);			
		}
	}
	for(int i=0;i<=N;i++){
		if(vec[n][m][i+N]||vec[n][m][N-i]){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}



Measured memory_bytes: 11136
N = 8
FREE = -1
NOT_FREE = 1


def printBoard():
    for i in range(N):
        for j in range(N):
            if X[i][j]:
                if not Y[i][j]:
                    return
    for i in range(N):
        for j in range(N):
            if Y[i][j]:
                print("Q", end = "")
            else:
                print(".", end = "")
        print("")

def recursive(i):
    if i == N:
        printBoard()
        return 

    for j in range(N):
        if col[j] == NOT_FREE or dpos[i + j] == NOT_FREE or dneg[i-j + N -1] == NOT_FREE:
            continue
        row[i] = NOT_FREE
        col[j] = NOT_FREE
        dpos[i + j] = NOT_FREE
        dneg[i-j + N -1] = NOT_FREE
        Y[i][j] = True
        
            
        recursive(i + 1)
        
        row[i] = FREE
        col[j] = FREE
        dpos[i + j] = FREE
        dneg[i-j + N -1] = FREE
        Y[i][j] = False

row = [FREE] * N
col = [FREE] * N
dpos = [FREE] * (2 * N - 1)
dneg = [FREE] * (2 * N - 1)
X = [[False for i in range(N)] for j in range(N)]
Y = [[False for i in range(N)] for j in range(N)]

n = int(input())
for i in range(n):
    nums=list(map(int,input().split()))
    X[nums[0]][nums[1]] = True



recursive(0)









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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){
  ll n;
  cin >> n;
  ll ans = 0;
  ll t = 1;
  while(n){
    ans += t;
    t *= 2;
    n /= 2;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
memo = {}

bases = [2, 3, 5]
baseCost = [-1, -1, -1]
d = -1

def getAns(x):
    if x == 0:
        return 0
    if x in memo:
        return memo[x]
    memo[x] = -1
    ans = x * d
    for k in range(3):
        for delta in range(-bases[k] + 1, bases[k]):
            afterMul = x + delta
            if afterMul >= 0 and afterMul % bases[k] == 0:
                if afterMul // bases[k] in memo and memo[afterMul // bases[k]] == -1:
                    continue
                ans = min(ans, getAns(afterMul // bases[k]) + abs(delta) * d + baseCost[k])
    memo[x] = ans
    return ans

t = int(input())
for i in range(t):
    memo = {}
    n, a, b, c, dx = map(int, input().split())
    baseCost = [a, b, c]
    d = dx
    print(getAns(n))


Measured memory_bytes: 78860
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int t = N;
		int f = 0;
		while(true) {
			if (t>0) {
				f += t%10;
				t = t/10;
			}else break;
		}
		if (N%f == 0) System.out.println("Yes");
		else System.out.println("No");
	}
}


Measured memory_bytes: 21972
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string abc,ijk;
    cin >> abc >> ijk;
    int count = 0;
    if (abc[0] == ijk[0]){
        count++;
    }
    if (abc[1] == ijk[1]){
        count++;
    }
    if (abc[2] == ijk[2]){
        count++;
    }
    cout << count <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<climits>
#include<deque>
#include<queue>
#include <utility>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

typedef queue<int> IntQueue;

int H,W,sx,sy,gx,gy;
const int MAX=512;


void BFS(){
  
  cin>>H>>W;
  int c[H][W];
  int d[H][W];
  deque<int> Qx;
  deque<int> Qy;
  char a;
  rep(i,H){
    rep(j,W){
      cin>>a;
      if (a=='#'){
        c[i][j]=1;
      }  
      else{
        c[i][j]=0;
      }
    }
  }
  rep(i,H)rep(j,W)d[i][j]=100*100+1;
  int is_s_=0;
  if (c[0][0]==1)is_s_=1;
  sx=0;sy=0;gx=H-1;gy=W-1;
  d[sx][sy]=0;
  Qx.push_back(sx);
  Qy.push_back(sy);
  int ux,uy,ans=100*100+1;
  int seq=-1;//-1:reset,0:right,1:down
  while (!Qx.empty()){
    ux=Qx.front();
    uy=Qy.front();
    Qx.pop_front();
    Qy.pop_front();
    IntQueue adjx;
    IntQueue adjy;
    int px[2]={0,1};
    int py[2]={1,0};
    int push_cnt=0;
    int vx,vy;
    rep(i,2){
      vx=ux+px[i];
      vy=uy+py[i];
      if (!(vx>=0 && vx<H && vy>=0 && vy<W))continue;
      
      int isseq=0;
      int iswall=c[vx][vy];
      int d2=d[ux][uy];
      if (iswall){
        if(c[vx][vy]!=c[ux][uy]){//一個前が壁じゃない
          d2++;
        }
      }
      
      if(d2<d[vx][vy]){
        if (!iswall){
          d[vx][vy]=d2;
          Qx.push_front(vx);
          Qy.push_front(vy);
        }
        else{
          d[vx][vy]=d2;
          Qx.push_back(vx);
          Qy.push_back(vy);
          }
      }
    }
  }
  cout<<d[gx][gy]+is_s_<<endl;
}

int main(){
  BFS();
  return 0;
}


Measured memory_bytes: 384
/*input
20 3
4 5 6


*/

#include <bits/stdc++.h>

using namespace std;

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

	long long h, n;
	cin >> h >> n;
	long long a;
	long long sum = 0;
	for(int i = 0; i < n; i++) {
		cin >> a;
		sum += a;
	}
	if(sum >= h) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}

	return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())

path = []
for i in range(H):
    y = i+1
    row = list(map(int, input().split()))
    if i%2==0:
        for j, coin in enumerate(row):
               x = j+1
               path.append([y, x, coin])
    else:
        for j, coin in enumerate(row[::-1]):
               x = W-j
               path.append([y, x, coin])

ans = []
cnt = 0
for k in range(len(path)-1):
    c = path[k][2]
    if c%2==0:
        continue
    else:
        cnt += 1
        y, x = path[k][:2]
        ny, nx = path[k+1][:2]
        ans.append((y, x, ny, nx))
        path[k+1][2] += 1

print(cnt)
for a in ans:
    print(a[0], a[1], a[2], a[3])

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

int main(int argc, char const *argv[])
{
	int a, b;
	cin >> a >> b;

	string ans = "No";
	for(int i = 0; i <= a; i++)
		if(4*i + 2*(a-i) == b)
		{
			ans = "Yes";
			break;
		}

	cout << ans;
	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using P = pair<int, int>;

int main(){
    string s,t;
    cin >> s >> t;
    int sn = s.size(), tn = t.size();
    
    if(tn > sn){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    vector<string> S;
    rep(begin, sn-tn+1){
        bool flag=true;
        rep(i,tn){
            if(s[begin+i] != t[i] && s[begin+i] != '?') flag = false;
        }
        if(flag){
            string sc = s;
            rep(i,sn){
                if(begin <= i && i < begin + tn){
                    sc[i] = t[i-begin];
                }else if(s[i] == '?'){
                    sc[i] = 'a';
                }
            }
            S.push_back(sc);
            // cout << sc << endl;
        }
    }

    if(S.empty()){
        cout << "UNRESTORABLE" << endl;
    }else{
        sort(S.begin(), S.end());
        cout << S.at(0) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val ss = mutableMapOf<String, Int>()

    var max = 0

    repeat(n) {
        val s = readLine()!!
        val i = (ss[s] ?: 0) + 1
        ss[s] = i

        if (i > max) {
            max = i
        }
    }

    ss.toList().filter { it.second == max }.sortedBy { it.first }.forEach {
        println(it.first)
    }
}

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

enum {
    B10 = 10000, B5 = 5000, B1 = 1000
};

inline int maxNumber(long yen, int bill){
    return int(yen / bill);
}

inline bool isCorrect(int x10, int x5, int x1, int n, long y){
    bool isPositive = ((x10 >= 0) && (x5 >= 0) && (x1 >=0));
    bool isCorrectN = (n == x10 + x5 + x1);
    bool isCorrectY = (y - B10*x10 - B5*x5 - B1*x1 == 0);

    return isPositive && isCorrectN && isCorrectY;
}

void fastAns(int& x10, int& x5, int& x1, int n, long y){
    x10 = min(n, maxNumber(y, B10));
    for(; x10 >= 0; x10--){
        x5 = min(n - x10, maxNumber(y - B10*x10, B5));
        for(; x5 >= 0; x5--){
            x1 = min(n - x10 - x5, maxNumber(y - B10*x10 - B5*x5, B1));

            if(isCorrect(x10, x5, x1, n, y)) return;
        }
    }
}

void simplyAns(int& x10, int& x5, int& x1, int n, long y){
    for(x10 = 0; x10 <= n; x10++){
        for(x5 = 0; x5 <= n - x10; x5++){
            x1 = n - x5 - x10;
            if(isCorrect(x10, x5, x1, n, y)) return;
        }
    }
}

int main(){
    int  n; cin >> n;
    long y; cin >> y;

    int x10 = -1, x5 = -1, x1 = -1;
    fastAns(x10, x5, x1, n, y);

    if(isCorrect(x10, x5, x1, n, y)){
        cout << x10 << " " << x5 << " " << x1 << endl; 
    } else {
        cout << "-1 -1 -1" << endl;
    }
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;

typedef pair<ll,ll> pll;



#define rep(i,m,n) for(ll i=m;i<n;i++)

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

 ll n,sum=0;
  cin >> n;
  vll a(n);
  rep(i,0,n) {
    cin >> a[i];
    sum+=a[i];
  }
  if(sum%(n*(n+1)/2)) {
    cout << "NO" << endl;
    return 0;
  }
  
  ll k=sum/(n*(n+1)/2);
  
  vll d(n,-k);
  rep(i,0,n-1) d[i]+=a[i+1]-a[i];
    d[n-1]+=a[0]-a[n-1];
  
  
  
  bool flag=true;
  ll num=0;
  rep(i,0,n) {
    if(d[i]>0||d[i]%n) flag=false;
    else num-=d[i]/n;
  }
  if(num!=k) flag=false;
  
  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  
  
}

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c;
    long x = sc.nextLong();
    if(a%x == 0) {
      c = a / x -1;
    }else {
      c = a / x;
    }
    System.out.println(b/x-c);
  }
}


Measured memory_bytes: 23764
for a in iter(input,'0 0'):
 m=[input()for _ in[0]*int(a.split()[0])]
 y=x=0;s={(0,0)}
 while 1:
  u,v=x,y
  c=m[y][x]
  if c=='>':x+=1;
  if c=='v':y+=1;
  if c=='<':x-=1;
  if c=='^':y-=1;
  if c=='.':print(x,y);break
  if (x,y)in s:print('LOOP');break
  else:s|={(x,y)}


Measured memory_bytes: 5628
import Foundation

func readInts() -> [Int] {
    readLine()!.split(separator: " ").map {Int($0)!}
}

func main(){
    let lrd = readInts()
    let (l,r,d) = (lrd[0], lrd[1], lrd[2])
    var ans = 0
    for i in l...r {
        if i % d == 0 {
            ans += 1
        }
    }
    
    print(ans)
}
main()


Measured memory_bytes: 13280
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s=="SUN")
    	cout<<"7";
    else if(s=="MON")
    	cout<<"6";
    else if(s=="TUE")
    	cout<<"5";
    else if(s=="WED")
    	cout<<"4";
    else if(s=="THU")
    	cout<<"3";
    else if(s=="FRI")
    	cout<<"2";
    else
    	cout<<"1";
    cout<<endl;
}

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

Measured memory_bytes: 1732
import java.util.Scanner;

public class Main {
    static int n;
    static String s;
    static int[] a;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
//        n = sc.nextInt();
        s = sc.next();
        System.out.println(s.contains("A")&&s.contains("B")?"Yes":"No");
    }
}

Measured memory_bytes: 22100
#include <stdio.h>

int main(void) {
  int a,b,c,d,e;
  for(e=1;;e++){
  scanf("%d %d",&b,&d);
  if(b==0&&d==0)break;
  for(a=1;a<=b;a++){
  for(c=1;c<=d;c++){
    if(a%2==1){
      if(c%2==1)
      printf("#");
      else
      printf(".");
    }
    else{
      if(c%2==1)
      printf(".");
      else
      printf("#");
    }
  }
  printf("\n");
  }
  printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2104
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        over:
        while(true){
            String line = sc.next();
            int a = line.length();
            int b = 0;
            char x;
            for(int i= 0; i < a; i++){
                x = line.charAt(i);
                if(a == 1 && x == 48) {
                    break over;
                }
                b = b + (x - 48);
            }
            System.out.println(b);
        }
    }
}


Measured memory_bytes: 26100
#include <string>
#include <map>
#include <vector>
#include <iostream>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    int mozi[26] = {}; 
    cin >> n >> s;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 26; j++) {
            char c = s.substr(i, 1)[0];
            if (c - 'a' == j)
                mozi[j]++;
        }
    }   
    long long ans = 1;
    for (int i = 0; i < 26; i++) {
        ans *= (mozi[i] + 1); 
        ans %= 1000000007;
    }   
    ans--;
    cout << ans;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̒萔 (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    vector<int> dp(n);
    dp[0] = 0;
    for (int i = 1; i < n; i++) {
        if (i == 1) {
            dp[i] = abs(h[i] - h[0]);
            continue;
        }

        dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    cout << dp[n - 1] << endl;
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

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

signed main() {
  int N;
  cin >> N;

  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (a % 2 == 1) {
      cout << "first" << endl;
      return 0;
    }
  }

  cout << "second" << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
h, w, m = map(int, input().split())
targets = defaultdict(int)
targets_count_yoko = defaultdict(int)
targets_count_tate = defaultdict(int)
for _ in range(m):
    y, x = map(int, input().split())
    y -= 1
    x -= 1
    targets_count_yoko[x] += 1
    targets_count_tate[y] += 1
    targets[(y, x)] = -1

max_row = max(targets_count_yoko.values())
max_line = max(targets_count_tate.values())
y_idx = defaultdict(bool)
x_idx = defaultdict(bool)
max_count_x = 0
max_count_y = 0
for i in range(w):
    if targets_count_yoko[i] == max_row:
        x_idx[i] = True
        max_count_x += 1
for i in range(h):
    if targets_count_tate[i] == max_line:
        y_idx[i] = True
        max_count_y += 1


ans = max_line + max_row
kumi = max_count_x*max_count_y
for key_y, key_x in targets.keys():
    if y_idx[key_y] and x_idx[key_x]:
        kumi -= 1
    if kumi == 0:
        break

if kumi == 0:
    print(ans-1)
else:
    print(ans)



Measured memory_bytes: 241176
using System;
using System.Linq;
using System.Collections.Generic;




namespace ConsoleApplication1 {

    

    class ClassMain {

        public static bool[] primes = Enumerable.Repeat(true, 1500000 + 1).ToArray();

        public static void sieve() {
            primes[0] = false; primes[1] = false;
            for (int i = 2; i < primes.Length / 2 + 1; i++) {
                if (primes[i]) {
                    for (int j = 2; j * i < primes.Length; j++) {
                        primes[i * j] = false;
                    }
                }
            }
        }


        public static void Main(String[] args) {
           string line;
           sieve();
            while ((line = Console.ReadLine()) != null) {
                //int[] ints = line.Split(' ').Select(int.Parse).ToArray();
                //int n = ints[0];
                int n = int.Parse(line);                
                if (n == 0) { break; }
                
                int cnt = 0;
                for (int i = 2; i <= n/2; i++) {
                    if (primes[i] == false) { continue; }
                    if(primes[n-i]){cnt++;}
                }
                Console.WriteLine(cnt);
                
            }
        }

    }

    


}

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

bool cmp(int a,int b){
        return a>b;
}


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

    //Insert code
    
    ll n,m;
    cin>>n>>m;
    ll res[50];
    memset(res,0,sizeof(res));
    ll ress=0;
    for (int i=0;i<n;i++){
        int k;
        cin>>k;
        for (int j=0;j<k;j++){
            int x;
            cin>>x;
            res[x]++;
        }
    }
    for (int i=1;i<=m;i++){
        if (res[i]==n) ress++;
    }
    cout<<ress;
    
    //End code


    cerr << "\nTime elapsed: " << 1000*clock() / CLOCKS_PER_SEC << "ms\n";
    
}

Measured memory_bytes: 256
H, W = map(int, input().split())
X = [[int(a) for a in input().split()] for _ in range(10)]
for k in range(10):
    for i in range(10):
        for j in range(10):
            X[i][j] = min(X[i][j], X[i][k] + X[k][j])
print(sum([sum([0 if a == "-1" else X[int(a)][1] for a in input().split()]) for _ in range(H)]))

Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll S, W;
    cin >> S >> W;
    if(W >= S) cout << "unsafe";
    else cout << "safe";
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  int X, Y;
  cin >> X >> Y;
  int t = (4 * X - Y);
  int k = (Y - 2 * X);
  if (t >= 0 && t % 2 == 0 && k >= 0 && k % 2 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define ALL(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

map<char,vector<ll>> M;

int main() {
  ll N,K,v[57],sum=0,ans=0;
  vector<ll> V;
  cin >> N >> K;
  rep(i,N){
    cin >> v[i];
  }
  rep(A,K+1){
    rep(B,K+1){
      if(A+B>K || A+B>N){
        continue;
      }
      rep(i,A){
        V.push_back(v[i]);
        sum+=v[i];
      }
      rep(i,B){
        V.push_back(v[N-i-1]);
        sum+=v[N-i-1];
      }
      if(A+B>0){
        sort(ALL(V));
      }
      for(int i=0;i<K-A-B && i<A+B ;i++){
        if(V[i]<0){
          sum-=V[i];
        }
      }
      if(sum>ans){
        ans=sum;
      }
      sum=0;
      V.clear();
    }
  }
  cout << ans << endl;
}

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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define PB push_back
#define F first
#define S second

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

ll basis[62]; // basis[i] keeps the mask of the vector whose f value is i

int sz; // Current size of the basis

void insertVector(ll mask) {
	for (ll i = 0; i < 62; i++) {
		if ((mask & (1LL << i)) == 0) continue; // continue if i != f(mask)

		if (!basis[i]) { // If there is no basis vector with the i'th bit set, then insert this vector into the basis
			basis[i] = mask;
			++sz;
			
			return;
		}

		mask ^= basis[i]; // Otherwise subtract the basis vector from this vector
	}
}

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

	int t; cin >> t;
	while(t--){
		FOR(i, 62) basis[i] = 0;
		sz = 0;

 		int n; cin >> n;
		vector<ll> v(n); FOR(i, n) cin >> v[i];
		string s; cin >> s;
		if(s.back() == '1'){
			cout << "1\n";
			continue;
		}

		bool ok = true;
		for(int i = n-1; i >= 0; i--){
			if(s[i] == '0'){
				insertVector(v[i]);
			}else{
				for(int j = 0; j < 62; j++){
					if(v[i]&(1LL<<j)){
						v[i] ^= basis[j];
					}
				}
				if(v[i]) ok = false;
			}
		}

		if(ok) cout << "0\n";
		else cout << "1\n";
	}


	return 0;
}


Measured memory_bytes: 3648
from itertools import combinations_with_replacement
#a, b = list(map(int, input().split(" ")))
x = int(input())

fivelist = dict()
for i in range(-1000, 1000):
    fivelist[i] = i**5

for a, ma in fivelist.items():
    for b, mb in fivelist.items():
        if ma - mb == x:
            print(f"{a} {b}")
            exit(0)





Measured memory_bytes: 9324
#include <iostream>
#include <string.h>
using namespace std;
long long w[105];
long long v[105];
long long dp[100005];
int main() {
	int N, W; cin >> N >> W;
	for (int i = 1; i <= N; i++) cin >> w[i] >> v[i];
	memset(dp, 0x3f, sizeof(dp));
	dp[0] = 0;
	int maxv = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 100000; j >= v[i]; j--) {
			if (~dp[j - v[i]] and dp[j - v[i]] + w[i] <= W) {
				dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
				maxv = max(maxv, j);
			}
		}
	}
	cout << maxv << endl;
}


Measured memory_bytes: 1024