akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

bool FindDigits(int n) {
    int d[5];
    int i = 0;
    while(n > 0) {
        d[i] = n % 10;
        n /= 10;
        ++i;
    }
    if(d[0] == d[4] && d[1] == d[3]) return true;
    else return false;
}

int main() {
    int a, b;
    cin >> a >> b;
    
    int ans = 0;
    for(int i = a; i <= b; ++i) {
        if(FindDigits(i)) ++ans;
    }
    
    cout << ans << endl;
}


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

long long tmp[100000];
void solve(){
	for(int i=1;i<=100000;i++){
		tmp[i]=(i+1)*i/2;
	}
}

int main(){
	int x,ans;
	cin>>x;
	solve();
	for(int i=1;i<=100000;i++){
		if(tmp[i]>=x){
			ans=i;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
 
#define MIN 1
#define MAX 10000
#define IS_ERR(x) (x < MIN || x > MAX)
 
void swap(int *x, int *y)
{
    int swap;
 
    swap = *x;
    *x = *y;
    *y = swap;
}
 
 
int main(void)
{
 
    int a, b, c;
 
    scanf("%d %d %d", &a, &b, &c);
 
    if(IS_ERR(a) || IS_ERR(b) || IS_ERR(c))
    {
        return -1;
    }
 
    if(a > b)
    {
        swap(&a, &b);
    }
 
    if(b > c)
    {
        swap(&b, &c);
    }
 
    if(a > b)
    {
        swap(&a, &b);
    }        
 
    printf("%d %d %d\n", a, b, c);
 
    return 0;
 
}


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

int main(){
	vector<int> x(3);
  	for(auto&& u:x)cin>>u;
  	sort(begin(x),end(x));
    if(x[0]==x[1])cout<<x[2]<<endl;
         else cout<<x[0]<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
  	while(cin>>a>>b>>c){
    	if(c>a&&c<b || c>b&&c<a)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
  	return 0;
}


Measured memory_bytes: 256
import bisect

def prime_sieve(end):
    assert end > 1
    is_prime = [True for i in range(end)]
    is_prime[0], is_prime[1] = False, False
    primes = list()
    for i in range(2,end):
        if is_prime[i]:
            primes.append(i)
            for j in range(2 * i, end, i):
                is_prime[j] = False
    return primes #リスト型

x = int(input())
a = prime_sieve(150000)
ans = a[bisect.bisect_left(a,x)]
print(ans)

Measured memory_bytes: 49264
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <map>
using namespace std;
int main (){
  int N;
  cin >> N;
  map<int, int> M;
  for(int i = 0; i < N; ++i){
    int a;
    cin >> a;
    ++M[a];
  }
  
  int sum = 0;
  for(auto p : M){
	if(p.first <= p.second) sum += (p.second - p.first);
    else sum += p.second;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 4736
#include <stdio.h>
#include <string.h>

int main()
{
  char s[10005] = {};
  char alp[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  int n,i,j;

  scanf("%d",&n );
  scanf("%s", s);
  
  for(i=0; s[i] != '\0'; i++)
  {
    for(j=0;j<26;j++){
      if(s[i] == alp[j]){
        s[i] = alp[(j+n)%26];
        break;}
    }
  }

  printf("%s", s);
  return 0;
}


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

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

    int ans = 0;
    for(int i=0; i<n; ++i)
        ans += min(x[i], k - x[i]) * 2;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Tsundoku
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int MAX_M = 200000;
const int INF = 1 << 30;

/* typedef */

typedef long long ll;

/* global variables */

ll ass[MAX_N + 1], bss[MAX_M + 1];

/* subroutines */

/* main */

int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);

  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);
    ass[i + 1] = ass[i] + ai;
  }
  for (int i = 0; i < m; i++) {
    int bi;
    scanf("%d", &bi);
    bss[i + 1] = bss[i] + bi;
  }

  int maxc = 0;
  for (int i = 0, j = m; i <= n && ass[i] <= k; i++) {
    while (j > 0 && ass[i] + bss[j] > k) j--;
    int c = i + j;
    if (maxc < c) maxc = c;
  }

  printf("%d\n", maxc);
  return 0;
}


Measured memory_bytes: 6344
import bisect
 
n = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
 
ans = 0
for b in B:
    a_ind = bisect.bisect_left(A, b)
    c_ind = bisect.bisect_right(C, b)
    ans += a_ind*(n-c_ind)
print(ans)

Measured memory_bytes: 29616
N = int(input())
A = [int(a) for a in input().split()]
A.sort()

UB = 10**6

cand = set(range(1, UB + 1))
used = set()
for a in A:
    if a in used:
        cand.discard(a)
        continue
    i = 2
    while a * i <= UB:
        cand.discard(a * i)
        i += 1

    used.add(a)

count = sum(a in cand for a in A)
print(count)


Measured memory_bytes: 176084
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main{
  public static void main(String[] args){
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      String str = br.readLine();
      String[] str2 = str.split(" ");
      int w = Integer.parseInt(str2[0]);
      int h = Integer.parseInt(str2[1]);
      int x = Integer.parseInt(str2[2]);
      int y = Integer.parseInt(str2[3]);
      int r = Integer.parseInt(str2[4]);
      if (w >= (x + r) && (x - r) >= 0 && h >= (y + r) && (y -r) >= 0){
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    } catch(IOException e){
      System.err.println(e.toString());
    }
  }
}


Measured memory_bytes: 24432
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <list>
#include <unordered_map>
#include <cmath>

using namespace std;
typedef long long ll;


int main(void)
{
    int n,k;
    cin >> n >> k;
    int l = 1;
    for(int i = 1;i < 1e9;i++)
    {
        l *= k;

        if(l > n)
        {
            cout << i<<endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
// AOJ 0200: Traveling Alone: One-way Ticket of Youth
// 2017.8.9 bal4u@uu
// 2017.11.12

#include <stdio.h>
#include <string.h>

int tim[101][101], fee[101][101];
char buf[30], *bp;

int getint()
{
	int n = 0;
	while (*bp >= '0') n = (n<<3) + (n<<1) + (*bp++ & 0xf);
	return n;
}

int main()
{
	int n, m, i, j, k, a, b, c, t;
	int p, q, r;

	while (fgets(bp=buf, 30, stdin) && *bp != '0') {
		n = getint(), bp++, m = getint();
		memset(tim, 0x11, sizeof(tim)), memset(fee, 0x11, sizeof(fee));
		for (i = 0; i < m; i++) tim[i][i] = fee[i][i] = 0;
		while (n--) {
			fgets(bp=buf, 30, stdin);
			a = getint()-1, bp++, b = getint()-1, bp++;
			c = getint(), bp++, t = getint();
			if (fee[a][b] > c) fee[a][b] = fee[b][a] = c;
			if (tim[a][b] > t) tim[a][b] = tim[b][a] = t;
		}

		for (k = 0; k < m; k++) for (i = 0; i < m; i++) for (j = 0; j < m; j++) {
			if (fee[i][k] + fee[k][j] < fee[i][j]) fee[i][j] = fee[i][k] + fee[k][j];
			if (tim[i][k] + tim[k][j] < tim[i][j]) tim[i][j] = tim[i][k] + tim[k][j];
		}

		fgets(bp=buf, 10, stdin); k = getint();
		while (k-- > 0) {
			fgets(bp=buf, 30, stdin);
			p = getint()-1, bp++, q = getint()-1, bp++, r = getint();
			if (r) printf("%d\n", tim[p][q]);
			else   printf("%d\n", fee[p][q]);
		}
	}
	return 0;
}

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

int main() {
	 long t,n,d;
	 cin>>n>>d;
	 long count=0,i;
	
	     
	     for(i=0;i<n;i++){
	         long x,y;
	         cin>>x>>y;
	         if((sqrt(pow(x,2)+pow(y,2)))<=d){
	         count++;
	         }
	     }
	     
	  
	   cout<<count<<endl;
	 return 0;
}

Measured memory_bytes: 3676
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a+b==c+d)
cout<<"Balanced";
else if(a+b<c+d)
cout<<"Right";
else 
cout<< "Left";

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x=sc.nextInt();
        System.out.println(Math.abs(x-sc.nextInt())<Math.abs(x-sc.nextInt())?"A":"B");
    }
 
    
}

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

typedef long long ll;

int main() {

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

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);


    int n = 0;
    cin >> n;
    vector<ll> cnt(1e5 + 5, 0);
    ll sum = 0;

    for(int i = 0; i < n; i++) {
        int in = 0;
        cin >> in;
        cnt[in]++;
        sum += in;
    }

    int q = 0;
    cin >> q;
    while(q--) {
        int a = 0, b = 0;
        cin >> a >> b;

        sum -= (cnt[a] * a);
        sum += (b * cnt[a]);

        cnt[b] += cnt[a];
        cnt[a] = 0;

        cout << sum << endl;
    }



    
    return 0;
}

Measured memory_bytes: 4000
#include <bits/stdc++.h> 
using namespace std; 
long long int setBitNumber(long long int n) 
{ 
   
    int k = (int)(log2(n)); 
  
    // To return the the value 
    // of the number with set 
    // bit at k-th position 
    return (long long int)(pow(2, k+1)); 
} 
int setindex(long long int n) 
{ 
   
    int k = (int)(log2(n)); 
  
    // To return the the value 
    // of the number with set 
    // bit at k-th position 
    return k;
} 

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
        string s;
        cin>>s;
        if(s[1]=='R')
          cout<<"ABC"<<endl;
        else
          cout<<"ARC"<<endl;
        
        
         return 0; 
     }
      
            
        




Measured memory_bytes: 3648
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int A = Integer.parseInt(s.next());
        int B = Integer.parseInt(s.next());
        double a = 0.08;
        double b = 0.1;
        List<Integer> aRet = new ArrayList<>();
        for (int i = 1; i <= 1_000; i++) {
            int ret = (int) (i * a);
            if (ret == A) {
                aRet.add(i);
            }
            if (A < ret) {
                break;
            }
        }
        List<Integer> bRet = new ArrayList<>();
        for (int i = 1; i <= 1_000; i++) {
            int ret = (int) (i * b);
            if (ret == B) {
                bRet.add(i);
            }
            if (B < ret) {
                break;
            }
        }

        for (int br : bRet) {
            for (int ar : aRet) {
                if (ar == br) {
                    System.out.println(ar);
                    return;
                }
            }
        }
        System.out.println(-1);
        return;
    }
}

Measured memory_bytes: 23124
n,m = map(int,input().split())
a = []
for i in range(n):
    r,t = map(int,input().split())
    a.append((t,r))
a.sort(reverse = True)
#print(a)
d = {}
cd = []
dp = 0
x = 0
 
for i in range(m):
    z,c = a[i]
    dp += z
    if c in d:
        cd.append(z)
    else:
        d[c] = z
        x += 1
#print(cd)
cd.sort(reverse = True)
ans = dp + x**2
c = ans
 
for i in range(m,n):
    if len(cd) == 0:
        break
    z,v = a[i]
    if v in d:
        continue
    d[v] = z
    x += 1
    c = c - cd.pop()+z+2*x-1
    if c > ans:
        ans = c
print(ans)

Measured memory_bytes: 60120
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
#include <utility>
#include <bitset>
#include <queue>
#include <stack>
#include <limits>
#include <list>

using namespace std;
using ll = long long;
const ll INF = numeric_limits<ll>::max();
const int MOD = 1000000007;

void chmin(ll &a, ll b)
{
    if (a > b)
    {
        a = b;
    }
}
void chmax(ll &a, ll b)
{
    if (a < b)
    {
        a = b;
    }
}

int main()
{
    // max of value = 1000
    ll datalen = 100000;
    // max of n = 100
    // max of total value = 10^5
    ll N, W;
    cin >> N >> W;
    vector<ll> ws = vector<ll>(N + 1);
    vector<ll> vs = vector<ll>(N + 1);
    for (int i = 1; i <= N; i++)
    {
        ll w, v;
        cin >> w >> v;
        ws[i] = w;
        vs[i] = v;
    }

    vector<vector<ll>> dp = vector<vector<ll>>(N + 1, vector<ll>(datalen + 1, INF));
    // dp[0][0] = 0;
    for (int i = 0; i <= N; i++)
    {
        dp[i][0] = 0;
    }

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

            ll minV = INF;
            chmin(minV, dp[i - 1][j]); // i番目を利用しない
            if (vs[i] <= j)
            {
                // dp[i - 1][j - vs[i]] == INFのときに加算するとオーバーフローする
                if (dp[i - 1][j - vs[i]] <= INF - ws[i])
                {
                    chmin(minV, dp[i - 1][j - vs[i]] + ws[i]); // i番目を利用する
                }
                else
                {
                    dp[i][j] = INF;
                }
            }
            dp[i][j] = minV;
        }
    }

    ll maxV = -INF;
    for (int i = 0; i <= datalen; i++)
    {
        if (dp[N][i] <= W)
        {
            chmax(maxV, i);
        }
    }

    // int i = 0;
    // for (auto row : dp)
    // {
    //     int j = 0;
    //     for (auto cell : row)
    //     {
    //         cout << cell << "(" << i << "," << j << ")"
    //              << " ";
    //         j++;
    //     }
    //     cout << endl;
    //     cout << "===" << endl;
    //     i++;
    // }
    cout << maxV << endl;
}

Measured memory_bytes: 80256
import java.util.ArrayList;
import java.util.List;

public class Main {
  private static void solve() {
    int n = ni();
    List<int[]> edge = new ArrayList<>();
    if (n % 2 == 0) {
      for (int i = 1; i <= n; i ++) {
        for (int j = i + 1; j <= n; j ++) {
          if (i + j == n + 1) continue;
          
          edge.add(new int[] {i, j});
        }
      }
    } else {
      for (int i = 1; i <= n - 1; i ++) {
        for (int j = i + 1; j <= n - 1; j ++) {
          if (i + j == n) continue;
          edge.add(new int[] {i, j});
        }
      }

      for (int i = 1; i <= n - 1; i ++) {
        edge.add(new int[] {n, i});
      }
    }

    out.println(edge.size());
    for (int[] e : edge) {
      out.println(e[0] + " " + e[1]);
    }

  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 23508
#include<iostream>
#include<cstdio>
#include<algorithm>

#define MAX 100
using namespace std;


int main(){
	int M[MAX][MAX]={0};
	int n,k,u,v;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&u);
		scanf("%d",&k);
		for(int i=0;i<k;i++){
			scanf("%d",&v);
			M[u-1][v-1]=1;
		}
	}
	
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(j!=0)
			printf(" ");
			printf("%d",M[i][j]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    int x;
    int y;
} P;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll a[110];
    cin >> N;
    rep(i,0,N){
        cin >> a[i];
    }
    ll ave = 0;
    rep(i,0,N){
        ave += a[i];
    }
    ave /= N;
    ll ans = 1e9;
    rep(i, ave-1, ave + 2){
        ll ans_tmp = 0;
        rep(j,0,N){
            ans_tmp += (i - a[j]) * (i - a[j]);
        }
        ans = min(ans, ans_tmp);
    }
    print(ans);


}


Measured memory_bytes: 256
H, W = map(int, input().split())
field = [[i for i in input()] for j in range(H)]

b_rows = []
for row in range(H):
    if field[row].count(".") != W:
        b_rows.append(row)

b_columns = []
for column in range(W):
    memo = []
    for row in range(H):
        memo.append(field[row][column])
    if memo.count(".") != H:
        b_columns.append(column)

for i in b_rows:
    for j in b_columns:
        print(field[i][j], end="")
    print()

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

int main(){

    while(1){
        string s;
        int y,m,d;
        cin >> s;
        if(s=="#")break;
        cin >> y >> m >> d;
        if(y<=30){
            cout << s << " " << y << " " << m << " " << d << endl;
        }else{
            if(y==31&&m<5){
                cout << s << " " << y << " " << m << " " << d << endl;
            }else{
                cout << "?" << " " << y-30 << " " << m << " " << d << endl;
            }
        }
    }

    return 0;
}


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

ns = []
now_num = s[0]
cnt = 0
for i in range(n):
    if now_num == s[i]:
        cnt += 1
    else:
        ns.append((now_num, cnt))
        now_num = s[i]
        cnt = 1
ns.append((now_num, cnt))
len_ns = len(ns)
pre = [0] * (len_ns + 1)
for i in range(len_ns):
    pre[i + 1] = pre[i] + ns[i][1]

ans = 1
for i in range(len_ns - 2*k + 1):
    temp = pre[i + 2*k] - pre[i]
    if i > 0 and ns[i - 1][0] == '1':temp += ns[i - 1][1]
    if i + 2*k < len_ns and ns[i + 2*k][0] == '1':temp += ns[i + 2*k][1]
    if temp > ans:ans = temp
print(ans if len_ns - 2*k + 1 > 0 else len(s))

Measured memory_bytes: 14284
N = int(input())
A = [int(a) for a in input().split()]
for i in range(N):
    A[i] -= (i+1)
A.sort()
if N%2 == 0:
    b = A[int(N*0.5)]
else:
    b = A[int((N-1)*0.5)]
ans = 0
for j in range(N):
    ans += abs(A[j]-b)
print(int(ans))

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

int main(){
    vector<int>V;
    int n;
    cin>>n;
    int x;
    cin>>x;
    V.push_back(x);
    for(int i=1;i<n;i++){
        cin>>x;
        V.push_back(x+V[i-1]);
    }
    int r=INT_MAX;
    for(int i=0;i<(n-1);i++){
        int t = (V[n-1])-(2*V[i]);
        if(t<0)
            t*=-1;
        if(t<r)
            r=t;
    }
    cout<<r<<endl;

}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

	cout << min(a * n, b) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define sc second
typedef pair<int,int> P;
int num[26];
int main()
{
	int N,K;
	scanf("%d%d",&N,&K);
	for(int i=0;i<N;i++){
		string S;
		cin >> S;
		num[S[0]-'A']++;
	}
	int ans=0;
	while(true){
		sort(num,num+26);
		reverse(num,num+26);
		if(num[K-1]==0)break;
		for(int i=0;i<K;i++){
			num[i]--;
		}
		ans++;
	}
	printf("%d\n",ans);
	return 0;
	
}


Measured memory_bytes: 384
using System;
    class Program
    {
        static void Main(string[] args)
        {
            //入力
            string input1 = Console.ReadLine();
            string input2 = Console.ReadLine();
            //計算
            string output = "";
            for (int i = 0; i < input1.Length - 1; ++i)
            {
                output += input1.Substring(i, 1);
                output += input2.Substring(i, 1);
            }
            output += input1.Substring(input1.Length - 1, 1);
            if (input1.Length == input2.Length)
            {
                output += input2.Substring(input1.Length - 1, 1);
            }
            //出力
            Console.WriteLine(output);
        }
    }

Measured memory_bytes: 11092
while 1:
    try:
        xa, ya, xb, yb, xc, yc, xd, yd = map(float, input().split())
        if abs((yb - ya) * (yd - yc) + (xb - xa) * (xd - xc)) < 0.00000000001:
            print('YES')
        else:
            print('NO')
    except:
        break



Measured memory_bytes: 5588
# -*- coding: utf-8 -*-
# 整数の入力

if __name__ == "__main__":
    
    N = int(input())
    INPUT = list(map(int, input().split()))


    if 0 in INPUT:
        output = 0
    else:
        output = 1
        for i in INPUT:
            output = output * i
            
            if output > 10 ** 18:
                output = -1
                break

    print(output)

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

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

  char   char0 = '0', char1 = '1';
  string ans = "";

  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') {
      ans.push_back(char0);
    }
    if (s[i] == '1') {
      ans.push_back(char1);
    }
    if (0 < ans.size() && s[i] == 'B') {
      ans.pop_back();
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <map>
#include <cmath>
#define ll long long int 

using namespace std;

int n, m;
int a[100100];
int main()
{
    //freopen("a.txt", "r", stdin);
    cin >> n >> m;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    int cc = 0;
    for (int i = 0; i < n; i++) {
        if ((sum  - 4 * m * a[i]) <= 0) {
            cc++;
        }
    }
    if (cc >= m) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
//#include <vector>
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
 

 
 
int main(){
    
   int n,t,ans=0,minj;
   cin>>n;
   
   vector<int> a(n);
   rep(i,n)cin>>a.at(i);
   
   rep(i,n){
       
       minj=i;
       for(int j=i;j<n;j++){
           if(a.at(j)<a.at(minj)){
               minj=j;
               //ans++;
               
           }
       }
           if(a.at(i)>a.at(minj)){
             t=a.at(i);
             a.at(i)=a.at(minj);
             a.at(minj)=t;
             ans++;
           }
       
   }
   
   rep(i,n-1)cout<<a.at(i)<<" ";
   cout<<a.at(n-1)<<endl;
   cout<<ans<<endl;
}
  




Measured memory_bytes: 3120
#include <cstdio>

long long dp[100001][13];

int main()
{
  char s[100001];
  scanf("%s", s);
  
  dp[0][0] = 1;
  long long i;
  for (i = 0; s[i]; ++i)
  {
    for (long long j = 0; j < 13; ++j)
    {
      if (s[i] == '?')
      {
        for (long long k = 0; k <= 9; ++k)
        {
          long long r = (j * 10 + k) % 13;
          dp[i + 1][r] = (dp[i + 1][r] + dp[i][j]) % 1000000007;
        }
      }
      else
      {
        long long r = (j * 10 + s[i] - '0') % 13;
        dp[i + 1][r] = (dp[i + 1][r] + dp[i][j]) % 1000000007;
      }
    }
  }
  printf("%lld\n", dp[i][5]);
  return 0;
}

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

int main(){
  string s[101];
  int n;
  
  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 - 1].size() - 1] != s[i][0]){
      cout << "No" << endl;
      return 0;
    }
    
    for(int j = 0; j < i; j++){
      if(s[j] == s[i]){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
# include<iostream>
# include <cstdio>
# include <algorithm>
# include <cstring>
using namespace std;

char s[10000];

int main(void){
    int N,ans=0;
    cin>>N;
    cin>>s;
    for (int i=0;i<=N-2;i++){
        if (s[i]!='A') continue;
        if (s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
int n;
cin>>n;
vector<int> vec(n);
for(int i=0;i<n;i++){
cin>>vec.at(i);
}
int a=0;
for(int i=0;i<n;i++){
if(vec.at(i)==a+1){
a++;
}
}
if(a==0){
cout<<-1<<endl;
return 0;
}
cout<<n-a<<endl;
}

Measured memory_bytes: 1024
// AtCoder template
// sabaより胡蝶しのぶさんの方が可愛いのではないか？
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

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

    int n; cin >> n;
    ll a[n]; rep(i,n) cin >> a[i];
    map<ll,int> m;
    rep(i,n) m[a[i]]++;
    for(auto i:m){
        if(i.second != 1){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

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

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

  int ans = -100;
  for (int i = 0; i < N - 1; i++) {
    string X = S.substr(0, i + 1);
    string Y = S.substr(i + 1);

    int al_X[26] = {}, al_Y[26] = {};
    for (int j = 0; j < X.size(); j++) {
      al_X[X[j] - 'a']++;
    }
    for (int j = 0; j < Y.size(); j++) {
      al_Y[Y[j] - 'a']++;
    }

    int cnt = 0;
    for (int i = 0; i < 26; i++) {
      if (al_X[i] > 0 && al_Y[i] > 0) cnt++;
    }

    ans = max(ans, cnt);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))

(defparameter *hash-memo* (make-hash-table :test #'equal))

(defmacro dp (&body func)
  `(let* ((f (quote func))
          (num (gethash f *hash-memo*)))
     (if num
       num
       (setf (gethash f *hash-memo*) ,func))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
      (cons (subseq str 0 pos)
            (split x (subseq str (+ pos size))))
      (list str))))

(defun func (a b)
  (if (zerop a)
    0
    (+ 1 (func (floor a b) b))))

(princ (func (read) (read)))


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

void solve()
{        
    int h,w,m;
    cin >> h >> w >> m;
    unordered_map<int,vector<int>>arr;
    unordered_map<int,int>heights;
    unordered_map<int,unordered_map<int,int>>adj;
    unordered_map<int,int>temp;
    for (int c=0;c<m;c++)
        {
            int hi,wi;
            cin >> hi >> wi;
            arr[hi].push_back(wi);
            temp[wi]++;
            heights[hi]++;
            adj[hi][wi]=1;
        }
    vector<pair<int,int>>cols;
    for (auto it=temp.begin();it!=temp.end();it++)
        cols.push_back(make_pair(it->second,it->first));
    sort(cols.begin(),cols.end(),greater<pair<int,int>>());
    int maxi=0;
    for (int i=1;i<=h;i++)
        {
            auto it=cols.begin();
            for (int c=0;c<arr[i].size();c++,it++)
                {
                    maxi=max(maxi,heights[i]+it->first-adj[i][it->second]);
                }
            if (it!=cols.end())
                maxi=max(maxi,heights[i]+it->first-adj[i][it->second]);
        }
    cout << maxi << endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);     
    int t;
    //cin >> t;
    t=1;
    for (int tt=1;tt<=t;tt++)
        {
            solve();
        }
        return 0;
}

Measured memory_bytes: 129704
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int mod=1000000007;
LL n,a,b,c,d;
inline int read()
{
	int x=0,w=0;char ch=0;
	while(!isdigit(ch)){w|=ch=='-';ch=getchar();}
	while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return w?-x:x;
}
LL ksm(LL B,LL K,LL A=1)
{
	while(K){
		if(K&1)A=A*B%mod;
		B=B*B%mod;
		K>>=1;
	}
	return A;
}
int main()
{
	n=read();
	if(n==1)cout<<"0\n";
	else if(n==2)cout<<"2\n";
	else
		cout<<((ksm(10,n)-ksm(9,n)-ksm(9,n)+ksm(8,n))%mod+mod)%mod<<'\n';
}

Measured memory_bytes: 3636
N = gets.to_i
A, B, C = 3.times.map{ gets.split.map(&:to_i).sort }
SB = Array.new(N + 1, 0)
SC = Array.new(N + 1, 0)
N.times do |i|
  SB[i + 1] = SB[i] + (A.bsearch_index{|v| v >= B[i] } || N)
end
N.times do |i|
  j = (B.bsearch_index{|v| v >= C[i] } || N)
  SC[i + 1] = SC[i] + SB[j]
end
puts SC[N]



Measured memory_bytes: 25064
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	int n;
	cin>>n;
	vector<ll> v(n);
	cin>>v[0];
	rep(i, n-1){
		string c;
		cin>>c>>v[i+1];
		if(c=="-") v[i+1] *= -1;
	}
	ll sum = 0, sum2 = 0;
	rep(i, n){
		sum += v[i];
		if(v[i]<0) sum2 += v[i];
	}
	ll res = sum;
	rep(i, n){
		if(v[i]>0) continue;
		sum2 -= v[i];
		ll s = 0;
		while(i+1<n && v[i+1]>0){
			s += v[i+1];
			i++;
		}
		chmax(res, sum-2*s-2*sum2);
	}
	cout<<res<<endl;

	return 0;
}


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

int main(){
  int64_t N,K;
  cin>>N>>K;
  int cnt=0;
  while(N>0){
    int64_t r=N%K;
    N -= r;
    N /= K;
    ++cnt;
  }
  
  cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int unionfind[100000];

void unionfind_init(int n)
{
	for(int i = 0; i < n; ++i) { unionfind[i] = i; }
}

int unionfind_root(int x)
{
	if(x != unionfind[x])
	{
		unionfind[x] = unionfind_root(unionfind[x]);
	}
	return unionfind[x];
}

void unionfind_merge(int s, int t)
{
	unionfind[unionfind_root(s)] = unionfind_root(t);
}

int unionfind_query(int s, int t)
{
	return unionfind_root(s) == unionfind_root(t);
}

int main()
{
	int n, m, q, s, t;
	scanf("%d %d", &n, &m);
	
	unionfind_init(n);
	for(int i = 0; i < m; ++i)
	{
		scanf("%d %d", &s, &t);
		unionfind_merge(s, t);
	}
	
	scanf("%d", &q);
	for(int i = 0; i < q; ++i)
	{
		scanf("%d %d", &s, &t);
		printf(unionfind_query(s, t) ? "yes\n" : "no\n");
	}
}



Measured memory_bytes: 2712
# include <bits/stdc++.h>
# define fi first
# define se second
//# define int long long

using namespace std ;

const int N = 4000 ;
int dp[N][N], ans, se, te;
pair < int, int > pre[N][N], us[N][N];
string s, t ;

int smth( int x, int y ) {
    if( us[x][y].fi ) return us[x][y].se;

    if( x == se || y == te ) return 0 ;

    if( s[x] == t[y] ) {
        pre[x][y] = {x+1, y+1} ;
        us[x][y].se = smth(x+1, y+1 ) +1 ;
        us[x][y].fi = 1 ;
        return smth( x+1, y+1 ) + 1 ;
    }
    int r1 = smth( x+1, y ) ;
    int r2 = smth( x, y+1 ) ;
    if( r1 > r2 ) {
        pre[x][y] = {x+1,y} ;
        us[x][y].se = r1 ;
        us[x][y].fi = 1 ;
        return r1 ;
    }
    pre[x][y] = {x,y+1} ;
    us[x][y].se = r2 ;
    us[x][y].fi = 1 ;
    return r2 ;
}

int32_t main() {
    //freopen("cowsignal.in", "r", stdin ) ;
    //freopen("cowsignal.out", "w", stdout ) ;
	cin >> s >> t ;
	se = s.size() ;
	te = t.size() ;
	int tt = smth( 0, 0 ) ;
	int x = 0, y = 0, xx = 0 ;
	while( true ) {
        if( xx == tt ) break ;
        if( s[x] == t[y] ) {
            cout << s[x] ;
            xx ++ ;
        }
        auto h = pre[x][y] ;
        x = h.fi ;
        y = h.se ;
	}
}


Measured memory_bytes: 168996
while gets do
  a, b, c, d, e, f = $_.split(/\s/).map(&:to_f)
  z = (b*d - a*e)
  y = (c*d - a*f)/z + 0.000
  x = (b*f - c*e)/z + 0.000
  puts sprintf("%.3f\s%.3f", x, y)
end

Measured memory_bytes: 6140
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define MAX 200005
#define INF 200005

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(){
  int x;
  cin >> x;
  while(!IsPrime(x)){
    x++;
  }
  cout << x << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_Training
{



    public class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split(' ');

            var ts = s[1] + s[0];
            Console.WriteLine(ts);

        }
    }
}


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

int main() {
  int a,b,c; cin >> a >> b >> c;
  int n1 = abs(a-b);
  int n2 = abs(b-c);
  int n3 = abs(c-a);
  vector<int>v{n1,n2,n3};
  sort(v.begin(),v.end());
  cout << v[0]+v[1] << endl;
  return 0;
}

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

public class Main {
    static StringBuilder sb;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        sb = new StringBuilder();

        List<Long> ans = new ArrayList<>();
        ans.add(sc.nextLong());
        ans.add(~ans.get(0));
        ans.add(ans.get(0) << 1);
        ans.add(ans.get(0) >> 1);

        for (int i = 0; i < ans.size(); i++) {
            String s = String.format("%32s", Long.toBinaryString(ans.get(i))).replace(" ", "0");
            String str = s.substring(s.length() - 32, s.length());
            sb.append(str).append("\n");
        }

        PrintWriter out = new PrintWriter(System.out);
        out.print(sb);
        out.flush();
        
        sc.close();
    }
}



Measured memory_bytes: 26452
#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>;

void Main()
{
  int L,R,d; cin >> L >> R >> d;
  int ans = 0;
  for (int i = L; i <= R; i++) {
    if (i % d == 0) ans++;
  }
  cout << ans << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 3632
s = input()

i1 = int(s[:2])
i2 = int(s[2:])



def f(i):
    if (0 < i < 13):
        return 1
    elif (0 < i < 100):
        return 2
    else:
        return 0


f1 = f(i1)
f2 = f(i2)

if (f1 == 1):
    if (f2 == 1):
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if (f2 == 1):
        print("YYMM")
    else:
        print("NA")




Measured memory_bytes: 9204
#include<stdio.h>
int main(){
  int n,m;
  while(1){
    scanf("%d%d",&n,&m);
    if(n==0 && m==0)break;
    if(n<m)
      printf("%d %d\n",n,m);
    else printf("%d %d\n",m,n);
  }
  return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll aa , bb;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->aa - ((fr*)q)->aa;}

int main(void){
    // char ;
    ll h,w,d,q;
    scanf("%lld%lld%lld",&h,&w,&d);
    ll a[h][w],point[h*w][2];
    rep(i,0,h){
        rep(j,0,w) {
            scanf("%lld",&a[i][j]);
            point[a[i][j]-1][0]=i;
            point[a[i][j]-1][1]=j;
        }
    }
    scanf("%lld",&q);
    ll l[q],r[q];
    rep(i,0,q){
        scanf("%lld%lld",&l[i],&r[i]);
    }
    ll move[h*w];
    // move[0]=0;
    rep(i,0,d){
        move[i]=0;
    }
    rep(i,d,h*w){
        move[i]=move[i-d]+ ABS(point[i][0]-point[i-d][0]) + ABS(point[i][1]-point[i-d][1]);
    }
    // rep(i,0,h*w) printf("%lld ",move[i]);
    rep(i,0,q){
        printf("%lld\n", move[r[i]-1]-move[l[i]-1] );
    }
    // printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 5376
loop do
    n, m, k = gets.split.map(&:to_i)
    break if n == 0
    h = {0 => 1}
    n.times do
        h2 = Hash.new(0)
        (1..m).each do |x|
            h.each do |s, c|
                h2[s + x] += c
            end
        end
        h = h2
    end
    e = 0
    h.each do |s, c|
        e += [s - k, 1].max * c
    end
    p e.to_f / m ** n
end

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

using namespace std;

//typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)


signed main(){

	string s;
	cin >> s;
	int ans=0, n=s.length(); 
	int w = 0;
	for (int i = 0; i < n; i++){
		if (s[i] == 'W'){ 
			ans += (i - w);
			w++;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
import sys


#input
lines = [x.strip() for x in sys.stdin.readlines()]
h,w=[int(x) for x in lines[0].split()]
map=[[x for x in y] for y in lines[1:]]
memo=[[-1 for x in y] for y in lines[1:]]

def slv(lines):
    white = sum([r.count(".") for r in map])
    q=[[0,0]]
    memo[0][0]=1
    while q!=[]:
        x,y=q.pop(0)
        for pm1 in [1,-1]:
            if x+pm1>=0 and x+pm1<w:
                if map[y][x+pm1] == "." and memo[y][x+pm1]<0:
                    q.append([x+pm1,y])
                    memo[y][x+pm1]=memo[y][x]+1
            if y+pm1>=0 and y+pm1<h:
                if map[y+pm1][x] == "." and memo[y+pm1][x]<0:
                    q.append([x,y+pm1])
                    memo[y+pm1][x]=memo[y][x]+1

    goal=memo[h-1][w-1]

    if goal == -1:
        return -1
    else:
        return white - goal
    


if __name__ == "__main__":
    print(slv(lines))

Measured memory_bytes: 3064
def main():
    import sys
    input = sys.stdin.buffer.readline
    n,m = map(int, input().split())
    adj = [[] for i in range(n)]
    for i in range(m):
        a,b = map(lambda x: int(x)-1, input().split())
        adj[a].append(b)
        adj[b].append(a)
    
    que = [0]
    parent = [-1] * (n)
    while que:
        node = que.pop(0)
        for child in adj[node]:
            if parent[node] == child:
                continue
            if parent[child] == -1:
                que.append(child)
                parent[child] = node
    if -1 in parent[1:]:
        print('No')
    else:
        print('Yes')
    for i in range(1,n):
        print(parent[i]+1)





if __name__ == '__main__':
    main()

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


char buf[105];

int main(){

	scanf("%s",buf);

	int len;

	for(len = 0; buf[len] != '\0'; len++);

	printf("%c%d%c\n",buf[0],len-2,buf[len-1]);

	return 0;
}


Measured memory_bytes: 3700
import sys

def point(s, S, P, R):
    if s == "s": return S
    elif s == "p": return P
    else: return R

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    S, P, R = map(int, input().split())
    T = input()

    total = 0
    Takahashi = [None] * N
    for i in range(K):
        total += point(T[i], S, P, R)
        Takahashi[i] = T[i]
    for i in range(K, N):
        if T[i] == Takahashi[i-K]:
            Takahashi[i] = "NG"
        else:
            Takahashi[i] = T[i]
            total += point(T[i], S, P, R)
    print(total)


    return 0

if __name__ == "__main__":
    solve()

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

int main(){
    int N;
    cin>>N;
    vector<int> vec(N);
    for(int i=0; i<N; i++){
        cin>>vec.at(i);
    }
    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());

    int alice=0;
   for(int i=0; i<N; i=i+2){
       alice+=vec.at(i);
   }
   int bob=0;
   for(int i=1; i<N; i=i+2){
       bob+=vec.at(i);
   }
   cout<<alice-bob<<endl;
    
}

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

int main() {

	int ires ;
	string sres ;

	int N;
	cin >> N;

	ires = 111 * ((N-1) / 111 + 1);

	cout << ires << endl;

}

Measured memory_bytes: 256
s = int(input())
progression = [s]
n = s
count = 1
while True:
    count += 1
    if n % 2 == 0:
        n = n/2
    else:
        n = 3 * n + 1

    if n in progression:
        break
    else:
        progression.append(n)

print(count)

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

int main() {
  string A,B,C;
  int a,b,c;
  cin >>A >>B >>C;
  a = A.size()-1;
  b = B.size()-1;
  
  if(A.at(a)==B.at(0)){
    if(B.at(b)==C.at(0)){
      cout <<"YES" <<endl;
      return 0;
    }
  }
  cout <<"NO" <<endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			int n = Integer.parseInt(br.readLine());

			if(n == 0){
				break;
			}

			int[] spend = new int[n];

			for(int i = 0 ; i < n; i++){
				spend[i] = Integer.parseInt(br.readLine());
			}

			Arrays.sort(spend);
			int[] waitTime = new int[n];
			long sum = 0;
			for(int i = 1; i < n; i++){
				waitTime[i] = waitTime[i - 1] + spend[i - 1];
				sum += waitTime[i];
				//System.out.println("WT "+waitTime[i]);
			}
			System.out.println(sum);
		}
	}

}

Measured memory_bytes: 29936