akhauriyash/Code-Regression huggingface dataset:
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size=[1]*(n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y]=self.size[x]+self.size[y]
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.size[x]=self.size[x]+self.size[y]

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def Size(self,x):
        return self.size[self.find(x)]

n,m=map(int,input().split())
a_list=[]
b_list=[]
for i in range(m):
    a,b=map(int,input().split())
    a_list.append(a)
    b_list.append(b)
ans=[n*(n-1)//2]
U=UnionFind(n)
for i in range(m-1,0,-1):
    if U.same_check(a_list[i],b_list[i]):
        ans.append(ans[-1])
    else:
        ans.append(ans[-1]-U.Size(a_list[i])*U.Size(b_list[i]))
        U.union(a_list[i],b_list[i])
for i in range(m-1,-1,-1):
    print(ans[i])
    


Measured memory_bytes: 115288
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
using namespace std;
int main(){
    char a[5];
    for(int i=0;i<3;i++){
        cin >> a[i];
    }

    for(int i=0;i<3;i++){
        if(a[i]=='1'){
            a[i]='9';
        }else if(a[i]=='9'){
            a[i]='1';
        }
    }

    for(int i=0;i<3;i++){
        cout << a[i];
    }

    cout << endl;

}

Measured memory_bytes: 256
//atcoder clange
#include <stdio.h>

int main(void){
    int N;
    
     scanf("%d", &N);
    char S[N];
    scanf("%s", S);
   int K;
	scanf("%d", &K);
  int i;
  for(i=0;i<N;i++){
	if(S[K-1] != S[i]){
      S[i] = '*';
    }
  }
  
	printf("%s",S);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main(void){
	ll x;
	cin >> x;
	int cnt = 0;
	for (int i = 0; i < 10000000; ++i){
		cnt += (i + 1);
		if(cnt >= x){
			printf("%d\n", i + 1);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const int N=1e6+1;
ll a,b,n;
int main(){
	ios::sync_with_stdio(false);
	cin >>  a >> b >> n;
	n=min(n,b-1);
	cout << (a*n)/b-a*(n/b) << '\n';
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
 
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

const int mod = 998244353;
 
void solve() {
    int N, K;
    cin >> N >> K;

    vector<int> imos(N);
    vector<int> acc(N);
    
    vector<pii> I;   
    for(int i = 0; i < K; i++) {
        int l, r;
        cin >> l >> r;
        r++;
        I.push_back({l, r});
    }

    acc[0] = 1;
    for(int i = 0; i < N; i++) {
        if (i > 0) {
            imos[i] += imos[i - 1]; 
            imos[i] %= mod;
        }

        acc[i] += imos[i];
        acc[i] %= mod;

        for(int k = 0; k < K; k++) {
            int l = I[k].first;
            int r = I[k].second;
            if (i + l < N) {
                imos[i + l] += acc[i];
                imos[i + l] %= mod;
            }
            if (i + r < N) {
                imos[i + r] += mod - acc[i];
                imos[i + r] %= mod;
            }

        }
    }

    cout << acc.back() << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 4772
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

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

    for (int i = 0; i < 3; i++) {
        if (str[i] == str[i + 1]) {
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 256
from math import gcd
from collections import defaultdict

N, P = map(int, input().split())
S = list(map(int, input()))

answer = 0
if P == 2 or P == 5:
    for j in range(N - 1, -1, -1): # enumerate right endpoint
        if S[j] % P == 0:
            answer += j + 1
else:
    cnts = defaultdict(int)
    suffix = 0
    base = 1
    for i in range(N - 1, -1, -1):
        suffix = (suffix + S[i] * base) % P
        answer += cnts[suffix]  # Substr with length >= 2
        answer += 1 if suffix == 0 else 0 # Substr with length = 1
        cnts[suffix] += 1
        base = base * 10 % P

print(answer)

Measured memory_bytes: 11404
N, W = map(int, input().split())
v = [0] * N
w = [0] * N
for i in range(N):
    v[i], w[i] = map(int, input().split())

dp = [[0] * (W+1) for _ in range(N+1)]

for i in range(N):
    for sum_w in range(W+1):
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])
        if sum_w + w[i] > W:
            continue
        dp[i+1][sum_w+w[i]] = max(dp[i+1][sum_w+w[i]], dp[i][sum_w] + v[i])

print(max(dp[N]))



Measured memory_bytes: 41896
N = int(input())
d = [0] * (10**4+2)
for x in range(1, 10**2):
    xx = x**2
    for y in range(1, 10**2):
        yy = y**2
        for z in range(1, 10**2):
            i = xx + yy + z**2 + x*y + y*z + z*x 
            if 1 <= i <= N+1:
                d[i] += 1
print(*d[1:N+1], sep='\n')

Measured memory_bytes: 68428
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

const int INF = 1e7;
size_t N, M;
vector<vector<int>> edge;
vector<vector<int>> dist;


void init()
{
    cin >> N >> M;
    edge.resize(N + 1);
    dist.resize(N + 1);
    for (size_t i = 1; i <= N; i++) {
        edge[i].resize(N + 1);
        dist[i].resize(N + 1);
        for (size_t j = 0; j <= N; j++) {
            if (i == j) {
                dist[i][j] = edge[i][j] = 0;
            } else {
                dist[i][j] = edge[i][j] = INF;
            }
        }
    }

    size_t a, b;
    int c;
    for (size_t i = 0; i < M; i++) {
        cin >> a >> b >> c;
        edge[a][b] = edge[b][a] = c;
    }
}


void min_dist(size_t s)
{
    vector<bool> used(N + 1, false);
    for (size_t i = 0; i < N; i++) {
        size_t minv = 0;
        for (size_t v = 1; v <= N; v++) {
            if (dist[s][v] < dist[s][minv] && !used[v]) {
                minv = v;
            }
        }
        // cout << minv << endl;
        used[minv] = true;

        for (size_t j = 1; j <= N; j++) {
            dist[s][j] = min(dist[s][j], dist[s][minv] + edge[minv][j]);
            // cout << "(" << s << ", " << j << ") : " << dist[s][j] << endl;
        }
    }
    return;
}


bool judge(size_t i, size_t j)
{
    for (size_t s = 1; s <= N; s++) {
        if (dist[s][i] + edge[i][j] == dist[s][j]) {
            return false;
        }
    }

    // cout << "(" << i << ", " << j << ")" << endl;
    return true;
}


int main()
{
    init();
    // cout << "Init finished" << endl;

    for (size_t s = 1; s <= N; s++) {
        min_dist(s);
    }
    // cout << "dist calculated" << endl;

    int cnt = 0;

    for (size_t i = 1; i < N; i++) {
        for (size_t j = i + 1; j <= N; j++) {
            if (edge[i][j] < INF) {
                cnt += judge(i, j);
            }
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 384
n = gets.to_s.to_i
a = gets.to_s

if a[/\D0/]
  puts 0
  exit
end

a = a.split.map{|e|e.to_i}
ans = 1
inf = 1_000_000_000_000_000_000
a.each do |t|
  ans *= t
  if ans > inf
    puts "-1"
    exit
  end
end

puts ans

Measured memory_bytes: 21640
import java.util.ArrayList;
import java.util.Scanner;
public class Main {


	static int n;
	static ArrayList<String> str;
	static ArrayList<Integer> slong;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
//		int n;
//		ArrayList<String> str;
//		ArrayList<Integer> slong;
		
		while(true) {
		n = Integer.parseInt(sc.nextLine());
		if(n == 0) {break;}
		if(n == 1) {
			System.out.println(sc.nextLine());
			continue;
		}
		str = new ArrayList<String>();
		slong = new ArrayList<Integer>();
		for(int i=0;i<n;i++) {
			str.add(sc.nextLine());
			slong.add(str.get(i).length()-1);
			str.set(i, str.get(i).substring(slong.get(i)));
		}

		str.add("");
		slong.add(-1);
		
		while(n > 2) {
			calc();
		}
		System.out.println(str.get(1));
		
		}
		sc.close();
	}

	public static void calc() {
		int longest=0;
		int pos=0;
		for(int i=0;i<n;i++) {
			if(slong.get(i) > longest) {
				longest =  slong.get(i);
				pos = i;
			}
		}
		
		if(slong.get(pos+1) == slong.get(pos)) {
			if(str.get(pos-1).equals("+")) {
				str.set(pos, String.valueOf(Integer.parseInt(str.get(pos)) + Integer.parseInt(str.get(pos+1))));
			}else {
				str.set(pos, String.valueOf(Integer.parseInt(str.get(pos)) * Integer.parseInt(str.get(pos+1))));
			}
			str.remove(pos+1);
			slong.remove(pos+1);
			n --;
		}else {
			str.remove(pos-1);
			slong.set(pos, slong.get(pos)-1);
			slong.remove(pos-1);
			n--;
		}
		
		
	}
	
}



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

int main(){
  int n;
  string s;
  cin >> n >> s;
  if (n % 2 != 0){
    cout << "No" << endl;
    return 0;
  }

  string hoge = s.substr(0, n/2);
  string fuga = s.substr((n/2), n/2);
  if (hoge == fuga){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

using namespace std;

#define debug(x) cout << #x << "==" << x << endl;

const int inf = 100000000;

typedef long long ll;

class UnionFind {
private:
  int N;
  vector<int> par;
  vector<int> rank;

  void init(int n)  {
    for (int i = 0; i < n; i++) {
      par[i] = i; rank[i] = 0;
    }
}
public:
  UnionFind(int n) {
    N = n;
    par.resize(n);
    rank.resize(n);
    init(n);
  }
  int  root(int x) {
    if( par[x] == x ) { return x; }
    else { return par[x] = root(par[x]); }
  }
  bool same(int x, int y) { return root(x) == root(y); }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if( x == y) return;
    if( rank[x] < rank[y] ) {  par[x] = y; }
    else {
      par[y] = x;
      if(rank[x] == rank[y]) { rank[x]++; }
    }
  }
};



struct edge{ int u, v, cost; };
bool comp(const edge& e1, const edge& e2) {
  return e1.cost < e2.cost;
}

#define MAX_E 100000
edge es[MAX_E];

int main() {
  ios::sync_with_stdio(false);

  int V, E;
  cin >> V >> E;
  for(int i = 0; i < E; i++) {
    int u, v, cost;
    cin >> u >> v >> cost;
    edge e = {u, v, cost};
    es[i] = e;
  }

  sort(es, es + E, comp);
  UnionFind uf(V);
  int res = 0;

  for(int i = 0; i < E; i++) {
    edge e = es[i];
    if( not uf.same(e.u, e.v) ) {
      uf.unite(e.u, e.v);
      res += e.cost;
    }
  }

  cout << res << "\n";

  return 0;
}

Measured memory_bytes: 4404
def main():
    formula = input().split()
    stack = []
    for f in formula:
        if f == '+':
            stack.append(stack.pop() + stack.pop())
        elif f == '-':
            a = stack.pop()
            b = stack.pop()
            stack.append(b - a)
        elif f == '*':
            stack.append(stack.pop() * stack.pop())
        else:
            stack.append(int(f))
    print(stack.pop())


if __name__ == "__main__":
    main()



Measured memory_bytes: 5596
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
#define PP 1000000007
using namespace std;

ll N, Q, Ans = 0;
vector<ll> Parent;

ll root(ll p){

  ll Pp = Parent[p];

  if(p == Pp)return Pp;

  return Parent[p] = root(Pp);

}

void Unify(ll a, ll b){

  ll Ra = root(a), Rb = root(b);

  if(Ra == Rb)return;

  Parent[Rb] = Ra;

}

int main(){
ll N, M, Answer = 0;cin >> N >> M;
Parent.resize(N + 1);
map<ll, bool> Ans;

rep(i, 1, N + 1)Parent[i] = i;

rep(i, 0, M){
 
  ll a , b;cin >> a >> b;
 
  Unify(a, b);

}

rep(i, 1, N + 1){
  
  Parent[i] = root(Parent[i]);
  
  Ans[Parent[i]] = 1;//cout << Parent[i] << endl;
  
}
  
  for(auto x : Ans)Answer++;
  
  cout << Answer - 1;

}

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

int main()
{
    string S;
    cin >> S;
    if((S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) ||
       (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) ||
       (S[0] == S[3] && S[1] == S[2] && S[0] != S[1])) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  
  if(n==100000){
    cout << 90909 << endl;
  }else if(n>=10000){
    cout << 909 + n-10000 + 1 << endl;
  }else if(n>=1000){
    cout << 909 << endl;
  }else if(n>=100){
    cout << 9 + n-100 + 1 << endl;
  }else if(n>=10){
    cout << 9 << endl;
  }else{
    cout << n-1 + 1 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int[] A = new int[N];
    for(int i=0; i<N; i++) {
      A[i] = scan.nextInt();
    }
    scan.close();

    long[] B = new long[N];
    for(int i=0; i<N; i++) {
      B[A[i]-1]++;
    }

    long[] C = new long[N];
    long sum = 0;
    for(int i=0; i<N; i++) {
      C[i] = B[i] * (B[i] - 1) / 2;
      sum += C[i];
    }

    for(int i=0; i<N; i++) {
      System.out.println(sum - B[A[i]-1] + 1);
    }
  }
}

Measured memory_bytes: 90668
#include <iostream>

using namespace std;

int main()
{
    int x,y,i,ans;
    cin>>x>>y;
    ans=0;
    for(i=0;i<=x;i++)
    {
        if((2*i+(x-i)*4)==y)ans=1;
    }
    if(ans==1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}


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

int main(){
    long s;
    long x1,x2,y1,y2;
    cin >> s;
    x1 = 1;
    while(s >= pow(10,x1)){
        x1++;
    }

    x1 = pow(10,x1/2);
    y2 = s/x1 + 1;
    x2 = y2*x1 - s;
    y1 = 1;

    if(y2 == 1000000001){
        y2 =1000000000;
        x2 = 0;
    }

    cout << 0 << " " << 0 << " " << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] ary = new int[n];
        long sum = 0;
        for(int i = 0;i < n; i++){
        	ary[i] = sc.nextInt();
        	sum += ary[i];
        }
        sc.close();
        int m2 = 0;
        for(int i = 0;i < n; i++){
        	if(ary[i]*(4*m) >= sum){
        		m2++;
        	}
        }
        System.out.println(m2>=m?"Yes":"No");

    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define SYNC                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define inf 0x3f3f3f3f
#define INF 1000111000111000111LL
#define mod 1000000007s
#define all(c) c.begin(), c.end()
#define endl '\n'

typedef long long int lli;

int main()
{
    SYNC

        string s;

    cin >> s;

    for (int i = 1; i <= s.length(); i++)
    {
        if (i % 2 == 0)
        {

            if (s[i-1] == 'L' || s[i-1] == 'U' || s[i-1] == 'D')
                continue;
            else
            {
                // cout << i;
                cout << "No" << endl;
                return 0;
            }
        }
        else
        {
            if (s[i-1] == 'R' || s[i-1] == 'U' || s[i-1] == 'D')
                continue;
            else
            {
                // cout << i;
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
valid :: [Int] -> [Int] -> [Int] -> String
valid r1 r2 r3 = if same (delta r1 r2) && same (delta r2 r3) then "Yes" else "No" 

delta :: [Int] -> [Int] -> [Int]
delta [] [] = []
delta (x:xs) (y:ys) = (x-y):(delta xs ys)

same :: [Int] -> Bool
same []  = True
same [x] = True
same (x:y:xs)
    | x == y = same (y:xs)
    | otherwise = False

readData :: IO [Int]
readData = do
    line1 <- getLine
    let xs = map (\x -> read x :: Int) (words line1)
    return xs

main :: IO() 
main = do
    r1 <- readData
    r2 <- readData
    r3 <- readData
    let ans = valid r1 r2 r3
    putStrLn ans

Measured memory_bytes: 508
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>

#define LP(i,n) for(int i=0;i<n;i++)
#define Mset(x,v) memset(x,v,sizeof(x))

using namespace std;
using LL=long long;

int s[105];

int main(){
    int n,ans=0;
    cin>>n;
    for(int i=0;i<n;i++) cin>>s[i];
    for(int i=1;i<n;i++){
        if(s[i-1]==s[i]){
            s[i]=-1;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

const int INF = (1 << 30) - 1;

int main()
{
	int N, K;
	int H[100005];

	cin >> N >> K; --K;

	for ( int i = 0; i < N; i++ ) {
		cin >> H[i];
	}
	sort(H, H + N);
	
	int minv = INF;
	for ( int i = K; i < N; i++ ) {
		minv = min(minv, H[i] - H[i - K]);
	}

	cout << minv << endl;

	return ( 0 );
}


Measured memory_bytes: 640
(defvar *n* (read))
(defvar *m* (read))

(defvar *as*
  (loop repeat *n* collect (read)))

(defun modM-+ (a b)
  (mod (+ a b) *m*))

(defvar *sums*
  (loop for x in *as*
        with psum = 0
        collect (setf psum (modM-+ x psum))))

(defvar *mods* (make-hash-table))

(dolist (psum *sums*)
  (let ((prev (gethash psum *mods*)))
    (setf (gethash psum *mods*)
          (if prev (1+ prev) 1))))

(defun patterns (n)
  (/ (* n (1- n)) 2))

(format t "~a~%"
        (+ (loop for pnum being the hash-values in *mods*
                 sum (patterns pnum))
           (or (gethash 0 *mods*) 0)))


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

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

  cout<<a<<" "<<b<<" "<<c<<endl;
  return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;    
  cout << ((B-1) + (A-1) - 1)/(A-1) << endl;
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stdlib.h>
#include <algorithm>
#include <list>
#include <math.h>

using namespace std;

int main(void){
	int i,j,k,cnt=0;
	char s[16],c[16] = {'C','O','D','E','F','E','S','T','I','V','A','L','2','0','1','6'};
	
	scanf("%s" ,s);
	for(i=0;i<16;i++){
		if(s[i] !=c[i]) cnt++;
	}
	printf("%d\n",cnt);
	
	return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a = list(map(int, input().split()))

    b = [0]
    for x in a:
        b.append(b[-1] + x)

    c = count(b)

    s = 0
    for key, val in c.items():
        if val >= 2:
            s += val * (val - 1) // 2
    print(s)

def count(xs):
    d = dict()
    for x in xs:
        if x in d:
            d[x] += 1
        else:
            d[x] = 1
    return d


main()

Measured memory_bytes: 41312
N = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
div_arr = make_divisors(N)

if len(div_arr) == 1:
    print(1)
elif len(div_arr) == 2:
    ans_num = max(div_arr)
    print(len(str(ans_num)))
else:
    memo = []
    if len(div_arr) % 2 == 0:
        last_idx = -1
        count = 0
        for i in range(len(div_arr)):
            count += 1
            if N == div_arr[i] * div_arr[last_idx] and count != len(div_arr) // 2:
                last_idx -= 1
                memo.append(len(str(div_arr[last_idx])))
            else:
                break
    else:
        target_index = len(div_arr) // 2
        memo.append(len(str(div_arr[target_index])))
    print(min(memo))

Measured memory_bytes: 9356
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();
        long m = sc.NextLong();

        long answer = 0;

        while (true)
        {
            if (n == 0 && m >= 2)
            {
                n += m / 4;
                m -= (m / 4) * 2;
            }
            if (n == 0 && m <= 3)
            {
                break;
            }
            if (m <= 1)
            {
                break;
            }
            if (n * 2 == m) // sとcが同じ
            {
                answer += n;
                break;
            }
            if (n * 2 < m) // cが多い
            {
                answer += n;
                m -= 2 * n;
                n = 0;
                continue;
            }
            if (n * 2 > m) // sが多い
            {
                answer += m / 2;
                n -= m / 2;
                m -= (m / 2) * 2;
                continue;
            }
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

int check (int N){
    int d[5];
    int i=4;
    while (N>0){
        d[i] = N % 10;
        N /= 10;
        i--; 
    }

    if (d[0] == d[4]){
        if (d[1] == d[3]) return 1;
    }
    else return 0;
}

int main(){
    int A, B;
    cin >> A >> B;

    int num=0;

    for (int i=A; i<=B; i++) {
        if(check(i)) num++;
    }

    cout << num << endl;


}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int N;
vector<int> s;

int main(){
  cin >> N;
  s.resize(N);
  int sum =0;
  REP(i, N){
    cin >> s[i];
    sum+=s[i];
  }

  if(sum % 10){
    cout << sum << endl;
  }
  else{
    int mins=102;
    REP(i, N){
      if(s[i]%10 != 0){
        mins = min(mins, s[i]);
      }
    }

    if(mins == 102){
      cout << 0 << endl;
    }
    else if((sum - mins) % 2 == 0){
      cout << mins << endl;
    }
    else{
      cout << sum - mins << endl;
    }
  }


  return 0;
}


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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    for (auto& e : a) cin >> e;
    cout << string(w+2, '#') << endl;
    for (auto& e : a) cout << '#' << e << '#' << endl;
    cout << string(w+2, '#') << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N,K;
	cin >> N;
	bool there = false;
	FOR(i,1,100000){
		if((i*(i-1))==(2*N)){
			there=true;
			K = i;
		}
	}
	if(not there){
		cout << "No" << endl;
		return 0;
	}
	vector< vector<ll> > S;
	S.resize(K+1);
	bool same[K+1][K+1] = {};
	FOR(i,1,K+1){
		FOR(j,1,K+1){
			if(j==i)continue;
			if(not same[i][j]){
				same[i][j] = same[j][i] = true;
				S[i].push_back(N);
				S[j].push_back(N);
				N--;
			}
		}
	}
	cout << "Yes" << endl << K << endl;
	FOR(i,1,K+1){
		cout << S[i].size() << " ";
		FOR(j,0,S[i].size()){
			cout << S[i][j] << " ";
		}
		cout << endl;
	}
}

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

using namespace std;
long long n,a,b,ans;
int main()
{
 cin>>n;
 for(int i=0;i<n;i++)
 {
     cin>>a>>b;
     ans+=b-a+1;
 }
 cout<<ans<<endl;
 return 0;
}

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

int main(){
    long N;
    cin >> N;
    long rootN;
    rootN = sqrt(N);

    long optI=1000000000000, optQ=optI;
    for(long q,r,i=1; i <= rootN; i++) {
        q = N/i;
        r = N%i;
        if (r == 0) {
            if (q + i < optI + optQ) {
                optI = i;
                optQ = q;
            }
        }
    }

    cout << optI + optQ - 2 << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace AOJ_Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = double.Parse(Console.ReadLine());
            var area = r * r * Math.PI;
            var circumference = 2.0 * Math.PI * r;
            Console.WriteLine($"{area.ToString("F5")} {circumference.ToString("F5")}");
        }
    }
}



Measured memory_bytes: 19976
def f(e):
 a=list(list(map(int,input().split())) for _ in range(int(e)))
 s,t=a[0]
 b={tuple(map(int,input().split())) for _ in range(int(input()))}
 for x,y in b:
  for u,v in a[1:]:
   if(x+u-s,y+v-t)not in b:break
  else:return print(x-s,y-t)
for e in iter(input,'0'):f(e)


Measured memory_bytes: 5904
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 2e5+10;
char str[maxn];
int dp[maxn][2];
int main(){
    scanf("%s",str);
    int len = strlen(str);
    dp[0][0]=1;dp[0][1]=0;
    if(str[0]==str[1])dp[1][0]=0;
    else dp[1][0]=2;
    dp[1][1]=1;
    for(int i=2;i<len;i++){
        if(str[i]==str[i-1]){
            dp[i][0]=dp[i-1][1]+1;
        }
        else 
            dp[i][0]=max(dp[i-1][0],dp[i-1][1])+1;
        if(i>=3&&str[i-3]==str[i-1]&&str[i-2]==str[i]){
            dp[i][1]=dp[i-2][0]+1;
        }
        else 
            dp[i][1]=max(dp[i-2][0],dp[i-2][1])+1;
    }
    printf("%d\n",max(dp[len-1][0],dp[len-1][1]));
    return 0;
}

Measured memory_bytes: 1920
let N=Int(readLine()!)!
let a=(1..<N).map{_ in readLine()!.characters.split(" ").map{Int(String($0))!}},C=a.map{$0[0]},S=a.map{$0[1]},F=a.map{$0[2]}
for i in 0..<N{print((i..<N-1).reduce(0){max(S[$1],$0+(F[$1]-$0%F[$1])%F[$1])+C[$1]})}

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

typedef unsigned long long ll;
#define mod 1000000007
#define all(x) (x).begin(),(x).end()

void solve(){
	string s;
	cin>>s;
	if(s[0] == 'R' and s[1] == 'R' and s[2]=='R')
		cout<<3<<endl;
	else if((s[0] == 'R' and s[1] == 'R') || (s[1] == 'R' and s[2]=='R'))
		cout<<2<<endl;
	else if(s[0]=='R' || s[2]=='R' || s[1] == 'R')
		cout<<1<<endl;
	else
		cout<<0<<endl;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
  return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long int ll;
ll gcd(ll a , ll b ){
    if(a % b == 0){
        return b ;
    }else{
        return gcd(b , a % b ) ;
    }
}
int main(void){
    int n;
  cin >> n;
  vector<long long>data(n);
  for(int i = 0;i < n;i++){
    cin >> data[i];
  }
  sort(data.begin(),data.end());
  for(long long i = data[1];i > 0;i--){
    int c = 0;
    for(int j = 0;j < n;j++){
      if(data[j]%i != 0) c++;
      if(c == 2) break;
    }
    if(c < 2){
      cout << i << endl;
      return 0;
    }
  }
}
    

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"math"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	pp := make([]P, 2)
	for i := 0; i < 2; i++ {
		pp[i].x = getNextFloat64(scanner)
		pp[i].y = getNextFloat64(scanner)
		pp[i].r = 0.0
	}
	n := getNextInt(scanner)

	for i := 0; i < n; i++ {
		x := getNextFloat64(scanner)
		y := getNextFloat64(scanner)
		r := getNextFloat64(scanner)
		pp = append(pp, P{
			x: x,
			y: y,
			r: r,
		})
	}

	costs := make([][]float64, n+2)
	for i := 0; i < n+2; i++ {
		costs[i] = make([]float64, n+2)
	}
	for i := 0; i < n+2; i++ {
		for j := i + 1; j < n+2; j++ {
			cost := math.Sqrt(math.Pow(pp[i].x-pp[j].x, 2)+math.Pow(pp[i].y-pp[j].y, 2)) - pp[i].r - pp[j].r
			if cost < 0 {
				cost = 0
			}
			costs[i][j] = cost
			costs[j][i] = cost
		}
	}

	dd := make([]float64, n+2)
	for i := 1; i < n+2; i++ {
		dd[i] = math.MaxFloat64
	}

	visited := make([]int, n+2)
	hp := &HH{}
	heap.Init(hp)

	heap.Push(hp, HP{
		i:    0,
		cost: 0,
	})
	for hp.Len() > 0 && visited[1] == 0 {
		p := heap.Pop(hp).(HP)
		visited[p.i] = 1
		for i := 0; i < n+2; i++ {
			if visited[i] == 1 {
				continue
			}
			if dd[i] < p.cost+costs[p.i][i] {
				continue
			}
			dd[i] = p.cost + costs[p.i][i]
			heap.Push(hp, HP{
				i:    i,
				cost: p.cost + costs[p.i][i],
			})
		}
	}

	fmt.Fprintln(writer, dd[1])
	writer.Flush()
}

type HP struct {
	i    int
	cost float64
}
type HH []HP

func (h HH) Len() int           { return len(h) }
func (h HH) Less(i, j int) bool { return h[i].cost < h[j].cost }
func (h HH) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }
func (h *HH) Push(x interface{}) {
	*h = append(*h, x.(HP))
}
func (h *HH) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

type P struct {
	x, y, r float64
}


Measured memory_bytes: 28032
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
Bs = list(mapint())

if sum(As)<sum(Bs):
    print(-1)
else:
    minus = 0
    cnt = 0
    lis = []
    for a, b in zip(As, Bs):
        if a<b:
            minus += (b-a)
            cnt += 1
        else:
            lis.append(a-b)
    lis.sort(reverse=True)
    if minus==0:
        print(0)
    else:
        for l in lis:
            minus -= l
            cnt += 1
            if minus<=0:
                break
        print(cnt)

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    vector<int> w(n), e(n);
    for (int i = 1; i < n; i++)
    {
        w[i] = w[i-1] + (s[i-1]=='W');
    }
    for (int i = n-2; i >= 0; i--)
    {
        e[i] = e[i+1] + (s[i+1]=='E');
    }
    int ans = INT_MAX;
    rep(i,n) {
        ans = min(ans, w[i]+e[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define MAX 3652425
#define NUM 100005

struct Info{
	bool operator<(const struct Info &arg) const{

		return w < arg.w;
	}
	ll w,t,x,index;
};

struct Data{
	Data(ll arg_finish_day,ll arg_minus_A,ll arg_minus_B,ll arg_minus_C){
		finish_day = arg_finish_day;
		minus_A = arg_minus_A;
		minus_B = arg_minus_B;
		minus_C = arg_minus_C;
	}
	bool operator<(const struct Data &arg) const{

		return finish_day > arg.finish_day; //終了日の昇順(PQ)
	}

	ll finish_day,minus_A,minus_B,minus_C;
};

ll N,num_query;
ll A,B,C;
ll REC_DAY[NUM],Y[NUM],value[MAX+1];
Info info[NUM];


int main(){

	scanf("%lld %lld",&N,&num_query);

	for(int i = 0; i < N; i++){

		REC_DAY[i] = BIG_NUM;
	}

	for(int i = 0; i < N; i++){

		scanf("%lld %lld %lld",&info[i].w,&info[i].t,&info[i].x);
		info[i].index = i;
	}

	sort(info,info+N);

	for(int i = 0; i < num_query; i++){

		scanf("%lld",&Y[i]);
	}

	ll recovery = 0,num_recover = 0;
	ll L,R,mid,max_index;
	A = 0, B = 0, C = 0;

	priority_queue<Data> Q;

	for(ll day = 0; day <= MAX; day++){

		//終了情報を反映
		while(Q.empty() == false && Q.top().finish_day == day){

			A -= Q.top().minus_A;
			B -= Q.top().minus_B;
			C -= Q.top().minus_C;
			Q.pop();
		}

		recovery += A*day*day + B*day + C;
		value[day] = recovery;

		if(num_recover < N){

			//二分探索で、新たに復旧したサービスを調べる
			L = num_recover,R = N-1,mid = (L+R)/2;
			max_index = num_recover-1;

			while(L <= R){

				if(info[mid].w <= recovery){

					max_index = mid;
					L = mid+1;
				}else{

					R = mid-1;
				}
				mid = (L+R)/2;
			}

			for(int i = num_recover; i <= max_index; i++){

				REC_DAY[info[i].index] = day;

				switch(info[i].t){
				case 0:
					C += 1;
					Q.push(Data(day+1+info[i].x,0,0,1));
					break;
				case 1:
					B += 1;
					C -= day;
					Q.push(Data(day+1+info[i].x,0,1,-day));
					break;
				case 2:
					A += 1;
					B -= 2*day;
					C += day*day;
					Q.push(Data(day+1+info[i].x,1,-2*day,day*day));
					break;
				}
			}

			num_recover = max_index+1;

		}
		recovery++;
	}

	for(int i = 0; i < N; i++){

		if(REC_DAY[i] == BIG_NUM){

			printf("Many years later\n");
		}else{

			printf("%lld\n",REC_DAY[i]);
		}
	}

	for(int i = 0; i < num_query; i++){

		printf("%lld\n",value[Y[i]]);
	}

	return 0;
}



Measured memory_bytes: 39408
#include <stdio.h>
 
int main(void) {
    double bmi;
    int id;
    double weight,height;
    while(scanf("%d,%lf,%lf",&id,&weight,&height)==3) {
        bmi=weight/height/height;
        if(bmi>=25)printf("%d\n",id);
    }
    return 0;
}

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

int calc(int *a,int n){
  int i=0;
  int ans=0;
  while(i<n){
    ans++;
    int j=i+1;
    while(j<n && a[j]==a[i]) j++;
    if(j>=n) break;
    int sign=a[j]-a[j-1]>0?1:-1;;
    while(j<n && sign*(a[j]-a[j-1])>=0) j++;
    i=j;
  }
  return ans;
}

void run(void){
  int n;
  scanf("%d",&n);
  int *a=(int *)calloc(n,sizeof(int));
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  int x=calc(a,n);
  printf("%d\n",x);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M, Q;
  cin >> N >> M >> Q;
  vector<int> a(Q);
  vector<int> b(Q);
  vector<int> c(Q);
  vector<int> d(Q);
  
  for(int i=0;i<Q;i++){
    cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
    a.at(i)--;
    b.at(i)--;
  }
  
  vector<int> A(10);
  long long maximum = 0;
  
  for(A.at(9)=1;A.at(9)<=M;A.at(9)++){
    for(A.at(8)=1;A.at(8)<=A.at(9);A.at(8)++){
      for(A.at(7)=1;A.at(7)<=A.at(8);A.at(7)++){
        for(A.at(6)=1;A.at(6)<=A.at(7);A.at(6)++){
          for(A.at(5)=1;A.at(5)<=A.at(6);A.at(5)++){
            for(A.at(4)=1;A.at(4)<=A.at(5);A.at(4)++){
              for(A.at(3)=1;A.at(3)<=A.at(4);A.at(3)++){
                for(A.at(2)=1;A.at(2)<=A.at(3);A.at(2)++){
                  for(A.at(1)=1;A.at(1)<=A.at(2);A.at(1)++){
                    for(A.at(0)=1;A.at(0)<=A.at(1);A.at(0)++){
                      long long sum = 0;
                      for(int i=0;i<Q;i++) if(A.at(b.at(i)) - A.at(a.at(i)) == c.at(i)) sum += d.at(i);
                      if(sum > maximum) maximum = sum;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout << maximum << endl;
  return 0;
}


Measured memory_bytes: 3624
w, h, n = map(int,input().split())
xy = [list(map(int,input().split())) for _ in range(n)]

def view(now):
    s = ''
    now = list(reversed(now))
    for i in range(h):
        for j in range(w):
            s += str(now[i][j])
        else:
            s += '\n'
    return s
mapp = [[1]*(w)] * (h)

for i in range(n):
    if xy[i][2] == 1 or xy[i][2] == 2:
        for j in range(h):
            if xy[i][2] == 1:
                mapp[j][:xy[i][0]] = [0]*xy[i][0]

            elif xy[i][2] == 2:
                mapp[j][xy[i][0]:] = [0]*(w-xy[i][0])

    elif xy[i][2] == 3:
        for s in range(xy[i][1]):
            mapp[s] = [0] * w

    elif xy[i][2] == 4:
        for s in range(xy[i][1],h):
            mapp[s] = [0] * w

    #print(view(mapp))
ans = 0
for i in range(h):
    ans += mapp[i].count(1)
print(ans)

Measured memory_bytes: 3188
m = str(input())
n = len(m)
s = 0

for i in range(0, n):
    if(i % 2 == 0) and (m[i] == "0"):
        s += 1
    if(i % 2 == 1) and (m[i] == "1"):
        s += 1

if(2 * s > n):
    s = n - s
    
print(s)

Measured memory_bytes: 3188
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-19 11:58:19
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  int h, w, d; cin >> h >> w >> d;
  vector<vector<int>> a(h, vector<int>(w)); cin >> a;
  
  map<int, pair<int, int>> mp;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      mp[a[i][j]] = {i, j};
    }
  }

  vector<int> dis(h * w + 1, 0);
  
  for (int i = d + 1; i <= h * w; ++i) {
    dis[i] = dis[i - d] + abs(mp[i].first - mp[i - d].first) + abs(mp[i].second - mp[i - d].second); 
  }

  int q; cin >> q;
  while (q--) {
    int l, r; cin >> l >> r;
    cout << dis[r] - dis[l] << '\n';
  }

  return 0;
}

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

const int N = (int) 1e4 + 5;

int n;
int a[N];
int ans = 0;

void solve(int a) {
	while (a % 2 == 0) {
		a /= 2;
		ans++;
	}
}

int main() {
	//freopen(".inp", "r", stdin); freopen(".out", "w", stdout);
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		int a; scanf("%d", &a);
		solve(a);
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<queue>
#define FOR(i,l,r) for(int i=(l),i##R=(r);i<=i##R;i++)
#define DOR(i,r,l) for(int i=(r),i##L=(l);i>=i##L;i--)
#define loop(i,n) for(int i=0,i##R=(n);i<i##R;i++)
#define mms(a,x) memset(a,x,sizeof a)
using namespace std;
typedef long long ll;
template<typename A,typename B>inline void chkmax(A &x,const B y){if(x<y)x=y;}
template<typename A,typename B>inline void chkmin(A &x,const B y){if(x>y)x=y;}
const int N=2e5+5;
int n;
int a[N],p,mx,se;
int main(){
	scanf("%d",&n);
	FOR(i,1,n)scanf("%d",&a[i]);
	FOR(i,1,n){
		if(a[i]>mx)se=mx,mx=a[i],p=i;
		else if(a[i]>se)se=a[i];
	}
	FOR(i,1,n){
		printf("%d\n",p==i?se:mx);
	}
	return 0;
}

Measured memory_bytes: 2432
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
   
   string s;
   cin >> s;
   bool flg = true;
   for (char ch = 'a'; ch <= 'c'; ch++) {
      if (s[0] == ch || s[1] == ch || s[2] == ch);
      else flg = false;
   }

   if (flg) cout << "Yes" << endl;
   else cout << "No" << endl;
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string s;
    cin>>s;
    n=s.size();
    string c(s.rbegin(),s.rend());
    string s1(s.begin(),s.begin()+n/2);
    string c1(s1.rbegin(),s1.rend());
    string s2(s.begin()+1+n/2,s.end());
    string c2(s2.rbegin(),s2.rend());
   // cout<<c<<" "<<s1<<" "<<c1<<" "<<s2<<" "<<c2<<endl;

   if(s==c && s1==c1 && s2==c2) cout<<"Yes"<<"\n";
   else cout<<"No"<<"\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
 
int main(){
    signed long long int a, b, c;
    signed long long int left, right;
    cin >> a >> b >> c;

    left = (c - a - b)*(c - a - b);
    right = 4*a*b;

    if(c - a - b <= 0){
        cout << "No";
    }
    else{
        if (left > right){
            cout << "Yes";
        }
        else{
            cout << "No";
        }
    }
}

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

public class Main{
	public static void main(String[] args){
		Scanner stdIn= null;
		stdIn = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		
		double[][] x = new double[10000][6];
		int i = 0;
		while( stdIn.hasNext() ){
			if( stdIn.hasNextDouble() ){
				for(int j = 0; j < 6; j++){
					x[i][j] = stdIn.nextDouble();
				}
			}else{
				stdIn.next();
			}
			i++;
		}
		for(int j = 0; j < i; j++){
			double denom = x[j][0]*x[j][4] - x[j][1]*x[j][3];
			double numX = x[j][2]*x[j][4] - x[j][1]*x[j][5];
			double numY = x[j][0]*x[j][5] - x[j][2]*x[j][3];
			
			double ansX = numX == 0 ? Math.abs(numX/denom) : numX/denom;
			double ansY = numY == 0 ? Math.abs(numY/denom) : numY/denom;
			System.out.printf("%.3f %.3f%n",ansX, ansY);
		}
	}
}

Measured memory_bytes: 13000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        System.out.println(s.nextInt()*s.nextInt()/2);

    }




}


class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25080