akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <sys/time.h>
#include <time.h>


using namespace std;



int main(){
  int a,b,c;
  std::cin >> a>>b>>c;
  std::cout << (a-c)/(b+c) << '\n';
}


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

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

double const pi = 3.1415926535;
int const mod = 1000000007;
int const inf = 2147483647;

int yesno(bool f, string yes, string no) {
	if (f)cout << yes << endl;
	else cout << no << endl;
	return 0;
}

int main() {

	long long a, b;
	cin >> a >> b;
	if (a < b)swap(a, b);
	if (b >= 2) {
		cout << (a - 2)*(b - 2) << endl;
		return 0;
	}
	else if (a >= 2 && b <= 1) {
		cout << a - 2 << endl;
		return 0;
	}
	else cout << 1 << endl;
	
	return 0;
}

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

int main() {
    int N, l, r;
    int sum = 0; // 合計
    
    cin >> N;
    
    for (int i = 0; i < N; i++) {
        cin >> l >> r;
        sum += r - l + 1;
    }
    
    cout << sum << endl;
}


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

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static String minS = "";
	public static void main(String[] args) throws Exception {

		int N=nextInt();
		int L=nextInt();
		String[] S = new String[N];
		for(int i=0;i<N;i++){
			S[i]=nextString();
			minS+=S[i];
		}
		Arrays.sort(S);


		System.out.println(String.join("", S));
	}
	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 25428
n = int(input())
A = tuple(map(int, input().split()))
c4 = 0
c2 = 0
cn = 0
for a in A:
    if a%4==0:
        c4 += 1
    elif a%2==0:
        c2 += 1
    else:
        cn += 1

if c2 == 0 or c2 == 1:
    if cn+c2 <= c4 + 1:
        print('Yes')
    else:
        print('No')
else:
    if cn <= c4:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 20336
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main(){
    int N, M;
    while(cin >> N >> M){
        vector<vector<int>> g(N);
        for(int i=0;i<M;i++){
            int a, b; cin >> a >> b;
            --a; --b;
            g[a].push_back(b);
            g[b].push_back(a);
        }
        vector<vector<int>> visit(2, vector<int>(N, 0));
        queue<pair<int,int>> qu;
        qu.emplace(0, 0);
        visit[0][0] = 1;
        while(!qu.empty()){
            auto p = qu.front(); qu.pop();
            for(auto t : g[p.second]){
                if(visit[1-p.first][t]) continue;
                visit[1-p.first][t] = 1;
                qu.emplace(1-p.first, t);
            }
        }
        int cnt[2] = {0, 0};
        for(int i=0;i<2;i++){
            for(int j=0;j<N;j++) cnt[i] += visit[i][j];
        }
        if(cnt[0] + cnt[1] == N){
            long long res = cnt[0] * (long long)cnt[1];
            for(int i=0;i<N;i++){
                for(int t : g[i]){
                    if(i > t) continue;
                    if(visit[0][i]+visit[0][t] == 1) --res;
                }
            }
            cout << res << endl;
        } else {
            cout << (long long)N*(N-1)/2 - M << endl;
        }
    }
}

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

vector<string> YAML;

struct Node{
    string key, value;
    vector<Node> children;
    Node(string k,string v){
        key=k;
        value=v;
    }
};

int line = 0;
Node mapping(int n,string key);
Node mapping_item(int n);

int count_indent(string &s){
    int ret=0;
    while(s[ret]==' ') ret++;
    return ret;
}

Node mapping(int n,string key=""){
    Node node(key,"");
    while(line<YAML.size()&&n==count_indent(YAML[line])){
        node.children.push_back(mapping_item(n));
    }
    return node;
}

Node mapping_item(int n){
    string S = YAML[line++];
    string key;
    int i;
    for(i=n;i<S.size();i++){
        if(S[i]==':'){
            key=S.substr(n,i-n);
            // cout<<"key: "<<node.key<<endl;
            break;
        }
    }
    i+=2;
    if(i<S.size()){
        // node.value=S.substr(i,S.size()-i);
        // cout<<"value: "<<node.value<<endl;
        return Node(key,S.substr(i,S.size()-i));
    }else{
        return mapping(count_indent(YAML[line]),key);
    }
}
void dfs(Node &node, int dep=0){
    cout<<string(dep,' ')+"key: "+node.key+" value: "+node.value+" children: "<<int(node.children.size())<<endl;
    for(auto c:node.children){
        dfs(c,dep+1);
    }
    return;
}

int main(){
    string s;
    getline(cin,s);
    vector<string> keys;
    for(int i=1;i<s.size();i++){
        int j=i+1;
        while(s[j]!='.'&&j<s.size())j++;
        keys.push_back(s.substr(i,j-i));
        i=j;
    }
    while(getline(cin,s)) YAML.push_back(s);
    Node root = mapping(0);
    // dfs(root);
    Node *p = &root;
    string property;
    for(auto k:keys){
        bool found = false;
        for(auto &c:p->children){
            if(c.key==k){
                found=true;
                if(c.value!=""){
                    property="string \""+c.value+"\"";
                }else{
                    property="object";
                }
                p=&c;
                break;
            }
        }
        if(!found){
            cout<<"no such property"<<endl;
            return 0;
        }
    }
    cout<<property<<endl;
    return 0;
}

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

int main() {
  int n; cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];

  vector<int> c(3, 0);
  for (int k : a) {
    if (k % 4 == 0) c[0]++;
    else if (k % 2 == 0) c[1]++;
    else c[2]++;
  }

  if (c[1] > 0) c[2]++;
  cout << (c[0] >= c[2] - 1 ? "Yes" : "No") << endl;
}

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

int main() {
  int n;
  cin >>n;
  long long kotae=0;
  for(int i=1;i<=n;i++){
    if(i%3==0)continue;
    else if(i%5==0)continue;
    else kotae+=i;
  }  
  cout<<kotae<<endl;
  return 0;
}

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

int main()
{

    int N, M, yen = 0;

    cin >> N;
    vector<string> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    cin >> M;
    vector<string> B(M);
    for (int i = 0; i < M; i++)
    {
        cin >> B.at(i);
    }

    for (int i = 0; i < N; i++)
    {
        int score = 0;
        for (int j = 0; j < N; j++)
        {
            if (A.at(i) == A.at(j))
            {
                score++;
            }
        }
        for (int k = 0; k < M; k++)
        {
            if (A.at(i) == B.at(k))
            {
                score--;
            }
        }

        yen = max(yen, score);
    }
    cout << yen << endl;

    return 0;
}

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


int main(){
	string s,t="ooooooooooooooooooo";
	cin>>s;
	s+=t;
	ll cnt=0;
	
	for(int i=0;i<15;i++)if(s[i]=='o')cnt++;
	cout<<(cnt>=8?"YES":"NO");
	return 0;
}


Measured memory_bytes: 256
def depth(id):
    depth = 0
    target_id = id
    while nodes[target_id][0] !=-1:
        depth += 1
        target_id = nodes[target_id][0]
    return depth

nodes = dict()
n = int(input())
for _ in range(n):
    id,k,*c_list = list(map(int, input().split()))
    if id not in nodes:
        nodes[id] = (-1, list())
    node = nodes[id]
    node = (node[0], c_list)
    nodes[id] = node
    for child_id in c_list:
        if child_id not in nodes:
            nodes[child_id] = (-1, list())
        child_node = nodes[child_id]
        child_node = (id, child_node[1])
        nodes[child_id] = child_node

for id, node in sorted(nodes.items()):
    node_type = "root" if node[0] == -1 else "internal node" if node[1] else "leaf"
    print(f"node {id}: parent = {node[0]}, depth = {depth(id)}, {node_type}, {node[1]}")


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


int main(){
    ll N, K; cin >> N >> K;
    vector<int> A(N);
    rep(i,N) {
        cin >> A[i];
        A[i]--;
    }
    deque<int> a;
    vector<bool> seen(N, false);
    int cur = 0;
    while(true){
        if(seen[cur]){
            while(a[0] != cur){
                //loopに入るまでの余計を除去
                --K;
                a.pop_front();
                if(K == 0){
                    cout << a[0] + 1 << endl;//1-indexed
                    return 0;
                }
            }
            break;
        }
        a.push_back(cur);
        seen[cur] = true;
        cur = A[cur];
    }
    cout << a[K % a.size()] + 1 << endl;//loop内でどこか
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
#define Int int64_t
#define ll long long
#define pb push_back
using namespace std;
const Int MAXN=2005;
const int ALPHA=26;

Int N,K,M;
Int X,Y,Z;
Int A,B,C;
vector<Int> ID;
vector<Int> SZ;
int find(int x){
    if(ID[x]==x) return x;
    return find(ID[x]);
}
void Union(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(SZ[x]>SZ[y]){
        ID[y]=x;
        SZ[x]+=SZ[y];
    }
    else{
        ID[x]=y;
        SZ[y]+=SZ[x];
    }
    return;
}
string common_prefix(string s,string t){
    string ans="";
    for(int i=0;i<min(s.length(),t.length());++i){
        if(s[i]==t[i]) ans.pb(s[i]);
        else break;
    }
    return ans;
}
string LCP(vector<string> A,int l,int r){
    if(l>r) return "";
    if(l==r) return A[l];
    int mid=(l+r)/2;
    string left=LCP(A,l,mid);
    string right=LCP(A,mid+1,r);
    return common_prefix(left,right);
}
int main()
{
    int t;
    t=1;
    while(t--){
       cin>>A>>B>>C;
       cin>>K;
       int secondB=B;int Bcount=0;
       while(secondB<=A){
           secondB<<=1LL;
           ++Bcount;
       }
       int secondC=C;int Ccount=0;
       while(secondC<=secondB){
           secondC<<=1LL;
           ++Ccount;
       }
       int total=Ccount+Bcount;
       cout<<(total>K ? "No\n":"Yes\n");
    }
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);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()
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);}
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int BinarySearch(int key,int n,int S[]){
  int l=0,r=n;
  while(r-l>1){
    int mid=(l+r)/2;
    if(S[mid]>key)r=mid;
    else l=mid;
  }
  return S[l]==(key?1:0);
}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
  ll N,C=0;
  vector<string> S;
  cin >> N;
  rep(i,N){
    string s;cin >> s;
    S.push_back(s);
    if(i>0 && S[i-1][S[i-1].length()-1]!=S[i][0]){
      C++;
    }
  }
  sort(All(S));
  rep(i,N){
    if(i>0 && S[i-1]==S[i]){
      C++;
    }
  }
  cout << (C==0 ? "Yes" : "No") <<endl;
}

Measured memory_bytes: 1016
n = int(input())
dic = {"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(n):
    s = input()
    if s[0] in ["M","A","R","C","H"]:
        dic[s[0]]+=1
l = [dic["M"],dic["A"],dic["R"],dic["C"],dic["H"]]
count = 0
for i in range(5):
    for j in range(5):
        for k in range(5):
            if i<j and j<k:
                count += l[i]*l[j]*l[k]
print(count)

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

int n, k, q;

int split_by(int x, const vector<int> &a) {
  vector<vector<int>> v;
  vector<int> cur;
  for (int i = 0; i < int(a.size()); ++i) {
    if (a[i] < x) {
      v.push_back(cur);
      cur.clear();
    } else {
      cur.push_back(a[i]);
    }
  }
  v.push_back(cur);
  vector<int> candidates;
  for (auto z : v) {
    sort(z.begin(), z.end());
    for (int i = 0; i + k - 1 < int(z.size()); ++i)
      candidates.push_back(z[i]);
  }
  sort(candidates.begin(), candidates.end());
  return (q - 1 < int(candidates.size()) ? candidates[q - 1] - x : int(2e9));
}

int main() {
  scanf("%d %d %d", &n, &k, &q);
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    scanf("%d", &a[i]);
  vector<int> b(a);
  sort(b.begin(), b.end());
  b.erase(unique(b.begin(), b.end()), b.end());
  int ans = -1;
  for (int x : b) {
    int z = split_by(x, a);
    if (ans == -1 || ans > z)
      ans = z;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int n = 0;
    int maxtime = 0;
    int mincost = 9999;
    cin >> n >> maxtime;

    for (int i = 0; i < n; ++i) {
        int cost = 0;
        int time = 0;

        cin >> cost;
        cin >> time;
        if (time <= maxtime){
            mincost = min(cost,mincost);
        }
    }

    if (mincost == 9999) {
        cout << "TLE";
    } else {
        cout << mincost;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main{

	//static long[] a;
	static	int N ;
	static	int M ;
	static long[][] dp;
	static int ans = 100000000;
	static	boolean[] flag ;

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		int[] lx = new int[n];
		int[] ly = new int[n];
		for(int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			lx[i] = x[i];
			ly[i] = y[i];
		}
		Arrays.sort(lx);
		Arrays.sort(ly);
 
		Long ans = 1L * (lx[n-1]-lx[0]) * (ly[n-1]-ly[0]);
		for(int xl = 0;xl < n;xl++){
			for(int xr = 0;xr < n;xr++){
				for(int yl = 0;yl < n;yl++){
					for(int yr =0 ;yr < n;yr++){
						int num = 0;
						Long XL = (long)lx[xl];
						Long XR = (long)lx[xr];
						Long YL = (long)ly[yl];
						Long YR = (long)ly[yr];

						for(int i = 0;i < n;i++){
							if(XL <= x[i] && XR >= x[i] && YL >= y[i] && YR <= y[i]){
								num++;
							}
						}
						if(num >= k){
							ans = Math.min(ans,(XR -XL)*1L*(YL-YR));
						}
						
						
					}
				}
			}
		}
		System.out.println(ans);




	}

}
class Bridge{
	int p;			//自分の場所
	ArrayList<Integer> town = new ArrayList<Integer>();				//辺でつながっている町
	public Bridge(int n) {
		p = n;
	}
	void addtown(int t){
		town.add(t);
	}

	int townnum(){
		return town.size();
	}





}




Measured memory_bytes: 151304
//itp1_7-d
#include <iostream>
#include <vector>
using namespace std;

int main(){
 int n,m,l;
 
 cin>>n>>m>>l;
 vector< vector<long long> > a(n, vector<long long>(m));
 vector< vector<long long> > b(m, vector<long long>(l));
 vector< vector<long long> > c(n, vector<long long>(l));

 for(int i=0;i<n;i++)
  for(int j=0;j<m;j++)
   cin>>a[i][j];
 for(int i=0;i<m;i++)
  for(int j=0;j<l;j++)
   cin>>b[i][j];

 for(int i=0;i<n;i++)
  for(int j=0;j<l;j++)
   for(int k=0;k<m;k++)
    c[i][j]+=a[i][k]*b[k][j];

 for(int i=0;i<n;i++){
  for(int j=1;j<l;j++){
   cout<<c[i][j-1]<<" ";
  }
  cout<<c[i][l-1]<<endl;
 }
 return 0;
}

Measured memory_bytes: 1424
keyinputs = raw_input()
 
output = ''
for i in xrange(len(keyinputs)):
    keyinput = keyinputs[i]
    if keyinput == '1' or keyinput == '0':
        output+= keyinput
    elif keyinput == 'B':
        if not output == '': 
            output = output[:-1]
print output

Measured memory_bytes: 2568
fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let n: usize = iter.next().unwrap().parse().unwrap();
    let x: i64 = iter.next().unwrap().parse().unwrap();
    let xs: Vec<i64> = (&mut iter).take(n).map(|x| x.parse().unwrap()).collect();
    
    let mut abs_dists = vec![];
    for k in xs {
        abs_dists.push((x - k).abs());
    }
    let mut ret = abs_dists[0];
    for i in 1..n {
        ret = gcd(ret, abs_dists[i]);
    }
    println!("{}", ret);
}

#[allow(dead_code)]
pub fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}
#[allow(dead_code)]
pub fn lcm(a: i64, b: i64) -> i64 {
    a / gcd(a, b) * b
}
#[allow(dead_code)]
#[doc = " ax + by = gcd"]
#[doc = " (gcd, x, y)"]
pub fn extgcd(a: i64, b: i64) -> (i64, i64, i64) {
    if b == 0 {
        (a, 1, 0)
    } else {
        let (gcd, x, y) = extgcd(b, a % b);
        (gcd, y, x - (a / b) * y)
    }
}

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

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

  ll ans = 0;
  if (a[0] > x) {
    ans += a[0] - x;
    a[0] = x;
  }
  for (int i = 1; i < n; ++i) {
    if (a[i-1] + a[i] > x) {
      ans += a[i-1] + a[i] - x;
      a[i] = x - a[i-1];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3792
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5000005;
struct ab{int f,t;}t[N];
int a[N],size[N],id[N],hh[N],h,tot;
map<int,int>mp;
void make(int x,int y){t[++h].f=hh[x],t[h].t=y,hh[x]=h;}
int cmp(int x,int y){return a[x]>a[y];}
void dfs(int x,int y,int z)
{
	tot+=z;
	for(int i=hh[x];i;i=t[i].f)
	{
		int j=t[i].t;
		if(j==y) continue;
		dfs(j,x,z+1);
	}
}
signed main()
{
	int n;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++) scanf("%lld",a+i),mp[a[i]]=i,size[i]=1,id[i]=i;
	sort(id+1,id+1+n,cmp);
	for(int i=1;i<n;i++)
	{
		int x=id[i],y=a[x]-(n-size[x])+size[x];
		if(!mp[y]||y>=a[x]) return printf("-1\n"),0;
		y=mp[y];
		make(x,y),make(y,x);
		size[y]+=size[x];
	}
	dfs(id[n],0,0);
	if(tot!=a[id[n]]) return printf("-1\n"),0;
	for(int i=1;i<=n;i++)
	{
		for(int j=hh[i];j;j=t[j].f)
		{
			if(t[j].t>i) printf("%lld %lld\n",i,t[j].t);
		}
	}
	return 0;
}

Measured memory_bytes: 20992
use proconio::{input, marker::Usize1};

fn main() {
    input! {
        h: usize,
        w: usize,
        b: [(Usize1, Usize1)]
    }

    let mut row = vec![0; h];
    let mut col = vec![0; w];

    for &(i, j) in &b {
        row[i] += 1;
        col[j] += 1;
    }

    let mr = *row.iter().max().unwrap();
    let mc = *col.iter().max().unwrap();

    let cr = row.iter().filter(|&&c| c == mr).count();
    let cc = col.iter().filter(|&&c| c == mc).count();
    let bc = b
        .iter()
        .filter(|&&(i, j)| row[i] == mr && col[j] == mc)
        .count();

    let ans = if bc < cr * cc { mr + mc } else { mr + mc - 1 };
    println!("{}", ans);
}


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

template <class T> using V = vector<T>;
template <class S, class T> using P = pair<S, T>;
template <class... T> using TP = tuple<T...>;

using ll = long long;
using db = double;
using ldb = long db;
using str = string;
using vll = V<ll>;
using vvll = V<V<ll>>;
using pll = P<ll,ll>;
using tpll = TP<ll,ll,ll>;
using vpll =V<pll>;
using vst = V<str>;
using vch = V<char>;

#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl
#define ci(a) cin>>a
#define pb(a) push_back(a)
#define pob pop_back()
#define mp make_pair
#define mt make_tuple
#define pbmp(a,b) push_back(mp(a,b))
#define subs(a,b) substr(a,b)
#define cfs(a) cout<<fixed<<setprecision(a)
#define INF 1e16
#define mod 1e9+7


int main() {
  str s;
  cin>>s;
  bool D=false;
  FOR(i,0,3){
 //   FOR(j,i+1,4){
      if(s[i]==s[i+1]){
        D=true;
      }
  //  }
  }
  if(D){
    co("Bad");
  }
  else{
    co("Good");
  }
}


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

int main(){
    int H,W,i,j;
    vector<vector<char>> a(100,vector<char>(101));
    vector<vector<char>> b(102,vector<char>(102));
    
    cin >> H >> W;
    
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            cin >> a.at(i).at(j);
        }
    }

    for(i=0;i<H+2;i++){
        for(j=0;j<W+2;j++){
            b.at(i).at(j)='#';
        }
    }

    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            b.at(i+1).at(j+1)=a.at(i).at(j);
        }
    }

    for(i=0;i<H+2;i++){
        for(j=0;j<W+2;j++){
            cout << b.at(i).at(j);
        }
        cout << endl;
    }
}

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

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

bool eval(string & s) {
	int n=s.size();
	for (int i=0; i<n/2; i++)
	if (s[i]!=s[n-i-1]) 
		return false;
	return true;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	int n=s.size();
	int l=(n-1)/2; 
	string a=s.substr(0,l);
	string b=s.substr((n+1)/2,l);
	cout<<(eval(a)&&eval(b)&&eval(s)?"Yes":"No")<<endl;
	return 0;
}


Measured memory_bytes: 3612
def d201(a):
    count=0
    N=len(a)
    for i in range(N):
        if(i%2==0):
            if(a[i]=='0'):
                count+=1
        else:
            if(a[i]=='1'):
                count+=1
    return count

                
def d210(a):
    count=0
    N=len(a)
    for i in range(N):
        if(i%2==0):
            if(a[i]=='1'):
                count+=1
        else:
            if(a[i]=='0'):
                count+=1
    return count

a=input()
print(min(d210(a),d201(a)))
                




Measured memory_bytes: 3188
#include<cstdio>
#include<algorithm>
using namespace std;

const int Maxn=30;

int N,M;
int cnt[Maxn+5];

int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%d %d",&N,&M);
	for(int i=1;i<=N;i++) {
		int k;scanf("%d",&k);
		for(int j=1;j<=k;j++) {
			int x;scanf("%d",&x);
			cnt[x]++;
		}
	}
	int ans=0;
	for(int i=1;i<=M;i++)
		if(cnt[i]==N)
			ans++;
	printf("%d\n",ans);
	return 0;
}

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

int main() {
    long long int N;
    cin >> N;
    long long int answer = 0;

    for(long long int i=1;;i++){
        // これや
        if((N-i)/i <= i){
            break;
        }
        if((N-i)%i == 0){
            answer += (N-i)/i;
        }
    }
    cout << answer << endl;
    return 0;
}

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

int main()
{
  i64 n, m;
  cin >> n >> m;
  i64 ll = 0, rr = 1e9;
  for (i64 i = 0; i < m; i++)
  {
    i64 l, r;
    cin >> l >> r;
    ll = max(ll, l);
    rr = min(rr, r);
  }
  cout << max(0LL, rr - ll + 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int josep(int n,int k)
{
  if(n==1) return 0;
  else return (josep(n-1,k)+k)%n;
}
int main(void)
{
  for(;;){
    int n,k,m;
    cin >> n >> k >> m;
    if(!n&&!k&&!m) return 0;
    cout << (josep(n,k)+(m-k)%n+n)%n+1 << endl;
  }
}

Measured memory_bytes: 1468
#include <stdio.h>

int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (a >= b && a >= c) {
		printf("%d\n", b + c);
	}
	else if (b >= a && b >= c) {
		printf("%d\n", a + c);
	}
	else {
		printf("%d\n", a + b);
	}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    set<string> kind;
    string s;
    cin>>s;
    INT(k);
    char c='a';
    int i,n=s.length();
    while(kind.size()<k){
        vector<pair<string,int>> point;
        for(i=0;i<n;i++){
            if(s[i]==c){
                if(i+1<n)point.push_back(make_pair(s.substr(i,2),i));
                else point.push_back(make_pair("zz",i));
            }
        }
        sort(all(point));
        for(int i=0;i<point.size();i++){
            if(kind.size()>k&&point[i].first!=point[0].first)break;
            for(int j=1;point[i].second+j<=n;j++){
                kind.insert(s.substr(point[i].second,j));
                if(j>=5)break;
            }
        }
        c++;
    }
    skip: 
    i=0;
    for(auto key:kind){
        i++;
        if(i==k){
            out(key);
            return 0;
        }
    }
}

Measured memory_bytes: 3744
#include <iostream>
#include <cstdio>
const int A=1000000007;
using namespace std;

int main()
{
    long long b=1;
    long long c=A;

    int n;
    scanf("%d",&n);

    for(int i=1;i<=n;i++)
    {
    b*=i;
    b%=c;
    }
    printf("%lld",b);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int i;
	int a[100005], b;
	for (i = 0; i < 100005; i++)
		a[i] = 0;
	for (i = 0; i < m; i++)
	{
		scanf("%d", &b);
		a[b] = 2000;
	}
	int ans[100005];
	ans[0] = 1;
	if (a[1] > 0)
		ans[1] = 0;
	else
		ans[1] = 1;
	for (i = 2; i <= n; i++)
	{
		if (a[i] > 0)
			ans[i] = 0;
		else
			ans[i] = ans[i - 1] + ans[i - 2];
		ans[i] %= 1000000007;
	}
	printf("%d\n", ans[n]);
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
using namespace std;

int const MAX = 100005;
int const P_MAX = 20000006;
vector<int> v[MAX];
int p[MAX];
int parent[MAX];
stack<int> st,ack;

struct high_low
{
	int high; int low;
};

high_low hl[MAX];
int value[MAX];

int main() {
	int n, k;
	cin >> n;
	for (int i = 1; i <= n - 1; i++) {
		int a, b;
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	cin >> k;
	for (int i = 1; i <= n; i++) {
		p[i] = -P_MAX;
	}
	for (int i = 1; i <= k; i++) {
		int s, t;
		cin >> s >> t;
		p[s] = t;
	}
	st.push(1); ack.push(1);
	for (int i = 1; i <= n; i++) {
		parent[i] = -1;
	}
	parent[1] = 0;
	while (!st.empty()) {
		int t = st.top();
		st.pop();
		for (int i = 0; i < v[t].size(); i++) {
			int next = v[t][i];
			if (parent[next] == -1) {
				parent[next] = t;
				st.push(next); ack.push(next);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		hl[i] = { P_MAX,-P_MAX };
	}
	while (!ack.empty()) {
		int t = ack.top();
		ack.pop();
		if (t == 0) { break; }
		for(int i=0;i<v[t].size();i++){
			if (v[t][i] != parent[t]) {
				int child = v[t][i];
				if (hl[child].high != P_MAX) {
					int x,y,z,w;
					x = hl[child].high + 1;
					y = hl[child].low - 1;
					z = hl[t].high;
					w = hl[t].low;
					if (z != P_MAX && ((x - z) % 2 == 1 || z < y || x < w)) {
						cout << "No" << endl;
						return 0;
					}
					hl[t].high = min(x, z);
					hl[t].low = max(y, w);

					//cout << t << " " << hl[t].high << " " << hl[t].low << endl;
				}
			}
		}
		if(p[t] != -P_MAX) {
			int c = p[t];
			if (hl[t].high != P_MAX && ((hl[t].high - c) % 2 == 1 || c < hl[t].low || c>hl[t].high)) {
				cout << "No" << endl;
				return 0;
			}
			hl[t] = { c,c };
		}
	}/*
	for (int i = 1; i <= n; i++) {
		cout << hl[i].low << " " << hl[i].high << endl;
	}
	*/
	cout << "Yes" << endl;
	for (int i = 1; i <= n; i++) {
		value[i] = -P_MAX;
	}
	st.push(1);
	while (!st.empty()) {
		int t = st.top();
		st.pop();
		if (t == 1) {
			value[1] = hl[1].high;
		}
		else {
			int x = value[parent[t]];
			if (x+1 > hl[t].high) {
				value[t] = x-1;
			}
			else {
				value[t] = x+1;
			}
		}
		for (int i = 0; i < v[t].size(); i++) {
			int next = v[t][i];
			if (next != parent[t]) {
				st.push(next);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << value[i] << endl;
	}
}

Measured memory_bytes: 9592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Graph vector<vector<ll>>
constexpr ll INF=(1ll<<60);
constexpr ll mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<typename T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}

int main(){
    ll a,b,c;cin>>a>>b>>c;
    cout<<max(0ll,c-(a-b))<<endl;
	return 0;
}

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

#define  int        long long int
#define    bp(x)           __builtin_popcountll(x)
 #define  ld         long double
 #define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)       for(int i = n; i >= j; i--)
 #define  all(container)       container.begin() , container.end()
#define  sz(container)   (int)container.size()
 #define  ff             first
#define  ss             second
 #define  pii      pair <int , int>
#define  sp(x)       setprecision(x)
 #define  endl    "\n"
#define  mod  1000000007
 #define  pb    push_back
#define  mp    make_pair
 #define  T     int ttt; cin >> ttt; while(ttt--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}

int32_t main()
{
    fast
    string s;
    cin>>s;
    int c=0,ans=0;
    f(i,0,sz(s)-1)
    {
        if(s[i]=='R')
            c++;
        else
        {
            ans=max(c,ans);
            c=0;
        }
         ans=max(c,ans);
    }
    cout<<ans;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define mod 1000000007
#define maxn 2000005
#define f(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rf(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);i--)
#define pb push_back
#define pf(x) push_front((ll)(x))
#define nl cout << "\n";
 
// struct Data{
// 	ll hi,lo;
// };

void ini(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
}

// bool comp(Data &a,Data &b){
// 	return (a.val<b.val);
// }


int main(){
	ini();
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	string s,t;
	cin >> s >> t;
	ll ans=0;
	f(i,0,s.size()){
		if(s[i]!=t[i]){
			ans++;
		}
	}

	cout <<ans;
}

Measured memory_bytes: 3784
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    map<ll, ll> a;
    for (ll i = 0; i < n; i++) {
        ll tmpa; cin >> tmpa;
        a[tmpa]++;
    }
    
    ll ai = 0;
    while (true) {
        auto it = a.upper_bound( ai );
        if (it == a.end()) break;
        ai = it->first;
        for (ll j = ai + ai; j <= 1000000; j += ai) {
            a.erase(j);
        }
        if (a[ai] > 1) a.erase(ai);
    }

    cout << a.size() << "\n";
    return 0;
}


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

const int MD = 1000000007;
const int MX = 100005;

int mod_mult(int a, int b) {
	return (a * 1LL * b) % MD;
}

int exp(int a, int b) {
	int res = 1;
	while (b) {
		if (b % 2 == 1) {
			res = mod_mult(res, a);
		}
		a = mod_mult(a, a);
		b /= 2;
	}
	return res;
}

int inv(int x) {
	return exp(x, MD - 2);
}

int P[MX];
int coef[MX];

int main()
{
	int n;
	ignore = scanf("%d", &n);
	
	for (int i = 1; i <= n; i++) {
		P[i] = (P[i - 1] + inv(i)) % MD;
	}
	
	int nfact = 1;
	for (int i = 2; i <= n; i++) { 
		nfact = mod_mult(i, nfact);
	}
	
	for (int x = 1; x <= n; x++) {
		coef[x] = P[x] + P[n - x + 1] - P[1];
		coef[x] = mod_mult(nfact, coef[x]);
	}
	
	int ans = 0;
	
	for (int i = 1; i <= n; i++) {
		int a;
		ignore = scanf("%d", &a);
		a = mod_mult(a, coef[i]);
		ans = (ans + a) % MD;
	}
	
	printf("%d", ans);
}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<long long int> p(n), q(n+1);
    for(auto& e : p) cin >> e;
    q[0] = 0;
    for(int i = 0;i < n; i++){
        q[i+1] = q[i] + p[i];
    }
    long long int res = 0;
    for(int i = 0; i <= n - k; i++){
        res = max(res, q[i+k] - q[i]);
    }
    cout << fixed << setprecision(10) << (res + k) / 2.0f << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  vector<vector<ll>> x(3,vector<ll>(n));
  rep(i,n)rep(j,3) cin>>x[j][i];
  ll ans=0;
  rep(i,1<<3){
    ll cnt=0;
    vector<ll> sum(n);
    rep(k,n){
      ll now=0;
      rep(j,3){
        if(i & (1<<j)) now+=x[j][k];
        else now+=-x[j][k];
        sum[k]=now;
      }
    }
    sort(begin(sum),end(sum),greater<ll>());
    rep(j,m) cnt+=sum[j];
    ans=max(ans,cnt);
  }
  cout<<ans<<endl;
}

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

using namespace std;

vector <int> v[100001];

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

	long long int res = 0;
	int n,m,a,b;
	priority_queue <int> pque;

	cin >> n >> m;

	for(int i=0;i<n;i++)
	{
		cin >> a >> b;
		if(m-a>=0)
		{
			v[m-a].push_back(b);
		}
	}

	for(int i=m-1;i>=0;i--)
	{
		for(auto it : v[i])
		{
			pque.push(it);
		}
		if(!pque.empty())
		{
			res += pque.top();
			pque.pop();
		}
	}

	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 8840
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> w(n);
	vector<int> left(n, 0);
	vector<int> right(n, 0);
	int ans = INT_MAX;

	for (int i = 0; i < n; i++)
	{
		cin >> w[i];
		left[i] += (i == 0 ? w[i] : left[i - 1] + w[i]);
	}

	for (int i = 0; i < n; i++)
	{
		right[i] = (i == 0 ? w[n - 1] : right[i - 1] + w[n - i - 1]);
	}
	reverse(right.begin(), right.end());

	for (int i = 0; i < n - 1; i++)
		ans = min(ans, abs(left[i] - right[i + 1]));

	// cout << "right";
	// for (int i = 0; i < n; i++)
	// 	cout << right[i] << " ";
	// cout << endl;

	cout << ans << endl;

	//この方法だと，indexとそれぞれの和の大小関係を管理する必要があるのでめんどくさい．
	// int pre, rear;
	// int prei, reari;
	// prei = 0;
	// reari = n - 1;
	// pre = w[prei];
	// rear = w[reari];

	// while (abs(prei - reari) > 1)
	// {
	// 	if (pre < rear)
	// 	{
	// 		prei++;
	// 		pre += w[prei];
	// 	}
	// 	else
	// 	{
	// 		reari--;
	// 		rear += w[reari];
	// 	}
	// cout << "pre : " << pre << endl;
	// cout << "rear : " << rear << endl;
	//}	// cout << abs(pre - rear) << endl;
}


Measured memory_bytes: 384
import java.util.Scanner;

class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int res = Integer.MIN_VALUE;
		
		int [][] mat = new int[n][n];
		
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < n; ++j){
				mat[i][j] = sc.nextInt();
			}
		}
		
		int [][] sum = new int[n][n];
		
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < n; ++j){
				for(int k = 0; k <= i; ++k){
					for(int l = 0; l <= j; ++l){
						sum[i][j] += mat[k][l];
					}
				}
			}
		}
		
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < n; ++j){
				for(int k = i; k < n; ++k){
					for(int l = j; l < n; ++l){
						
						int A = 0,B = 0,C = sum[k][l],D = 0;
						
						if( i - 1 >= 0 )
						{
							A = sum[i-1][l];
							if( j > 0 ) D = sum[i-1][j-1];
						}
						
						if( j - 1 >= 0 )
						{
							B = sum[k][j-1];
							if( i > 0 ) D = sum[i-1][j-1];
						}
						
						int csum = C + D - A - B;
						if( csum > res ) res = csum;
					}
				}
			}
		}
		
		System.out.println(res);
		
	}
}

Measured memory_bytes: 41720
// A_i に C_iを加えて A_i + C_i にする。
// このとき、B_iの倍数にするので、 C_i = (B_i - A_i%B_i) + B_i * k (0 <= k)
// 以上のCiを並べると、
// C_0 >= C_1 >= C_2 >= C_3 >= .... >= C_(N-1)
// を満たせば良くて、ボタンを押す回数は、
// (C_0 - C_1) + (C_1 - C_2) + (C_2 + C_3) + ... + (C_(N-2) - C_(N-1)) + C_(N-1)
// = C_0
// この値を最小にする
// C_(N-1)から貪欲に決めていける？
#include <bits/stdc++.h>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<long long> A(N,0),B(N,0);
    for (int i = N - 1; i >= 0; i--)
    {
        cin >> A[i] >> B[i];
    }

    vector<long long> C(N+1,0);
    // C[i] := A[i-1]に加える数
    C[0] = 0;
    for(int i = 0; i < N; ++i) {
        A[i] += C[i];
        long long amari = A[i] % B[i];
        long long need = 0;
        if (amari != 0) need = B[i] - amari;
        C[i+1] = C[i] + need;
    }
    cout << C[N] << endl;
    return 0;
}

Measured memory_bytes: 2560
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

type person struct {
	id int
	x  []int
	y  []int
}

// bit全探索の練習
// https://atcoder.jp/contests/abc147/tasks/abc147_c

func main() {
	N := nextInt()
	people := make([]person, N)
	var ans int
	for i := 0; i < N; i++ {
		A := nextInt()
		for j := 0; j < A; j++ {
			people[i].x = append(people[i].x, nextInt()-1)
			people[i].y = append(people[i].y, nextInt())
		}
	}
	for bit := 0; bit < 1<<uint(N); bit++ {
		var cnt int
		ok := true
		for i := 0; i < N; i++ {
			// i人目が1であることを前提に調べているので、
			// i人目が0の場合は見なくて良い
			if uint(bit)>>uint(i)&1 == 1 {
				for j := 0; j < len(people[i].x); j++ {
					if uint(people[i].y[j])^uint(bit)>>uint(people[i].x[j])&1 == 1 {
						ok = false
						break
					}
					// if people[i].y[j] == 1 && uint(bit)>>uint(people[i].x[j])&1 == 0 {
					// 	ok = false
					// 	break
					// }
					// if people[i].y[j] == 0 && uint(bit)>>uint(people[i].x[j])&1 == 1 {
					// 	ok = false
					// 	break
					// }
				}
			}
			if !ok {
				break
			}
		}
		if ok {
			for i := 0; i < N; i++ {
				if uint(bit)>>uint(i)&1 == 1 {
					cnt++
				}
			}
			ans = MaxOf(ans, cnt)
		}
	}
	fmt.Println(ans)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

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

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws Exception {
		FastScanner scanner = new FastScanner(System.in);
		int n = (int) scanner.nextInt();
		StringBuffer str = new StringBuffer();
		str.append(n +":");
		for (int i = 2; i * i <= n; i++) {
			while (n%i==0) {
				n = n/i;
				str.append(" "+ i);
			}
		}
		if (n>1) {
			str.append(" "+ n);
		}
		PrintWriter printWriter = new PrintWriter(System.out);
		printWriter.printf("%s\n", str.toString());
		printWriter.close();
	}

	static class FastScanner {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;

		public FastScanner(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
			tokenizer = null;
		}

		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}


		public long nextInt() {
			return Integer.parseInt(next());
		}

	
	}
}

Measured memory_bytes: 24760
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using node = tuple<ll,int,int>;
const ll inf = numeric_limits<ll>::max()/3;

int main(void){
  vector<string> grid;
  vector<vector<vector<node>>> G;
  int d[5] = {0,1,0,-1,0};
  ll dist[60][60];
  int h,w;
  cin >> h >> w;
  grid.resize(h);
  G.resize(h);
  for(int i = 0;i < h;++i){
    cin >> grid[i];
    G[i].resize(w);
  }
  int cnt = 0;
  for(int i = 0;i < h;++i){
    for(int j = 0;j < w;++j){
      if(grid[i][j] == '.'){
        ++cnt;
        for(int k = 0;k < 4;++k){
          int y = i + d[k];
          int x = j + d[k+1];
          if(0 <= y && y < h &&
             0 <= x && x < w){
            if(grid[y][x] == '.'){
              G[i][j].push_back((node){1LL,y,x});
            }
          }
        }
      }
    }
  }
  priority_queue< node, vector<node>, greater<node> > que;
  que.push((node){0LL,0,0});
  fill(dist[0],dist[0]+60*60,inf);
  while(!que.empty()){
    ll now;
    int y,x;
    tie(now,y,x) = que.top();
    que.pop();
    if(now < dist[y][x]){
      dist[y][x] = now;
      for(node n : G[y][x]){
        ll cost;
        int ny,nx;
        tie(cost,ny,nx) = n;
        if(now + cost < dist[ny][nx]){
          que.push((node){now+cost,ny,nx});
        }
      }
    }
  }
  if(dist[h-1][w-1] == inf)
    cout << "-1" << endl;
  else
    cout << (cnt - 1) - dist[h-1][w-1] << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	if (S[2] == S[3] && S[4] == S[5]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}






Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = Integer.parseInt(in.nextLine().trim());
        int[] h = new int[n];
        int count = 0;
        for(String a : in.nextLine().trim().split("\\s")){
            h[count++] = Integer.parseInt(a);
        }
        int[] dp = new int[n];
        for(int i = 1; i < n; i++){
            int cost = Integer.MAX_VALUE;
            if(i-2 > -1){
                cost = dp[i-2] + Math.abs(h[i]-h[i-2]);
            }
            dp[i] = Math.min(cost,dp[i-1] + Math.abs(h[i]-h[i-1]));
        }
        System.out.println(dp[n-1]);
    }
}

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

int main() {
  int n, k; cin >> n >> k;
  string s; cin >> s;
  int cnt = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (s[i] == s[i + 1]) ++cnt;
  }
  cout << min(n - 1, cnt + 2 * k) << endl;

 return 0;
}

Measured memory_bytes: 512