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

using namespace std;
const int maxn=1e3+111;
const int inf=0x3f3f3f3f;
struct node{
    int x, y;
};
int h, w, times[maxn][maxn];
int Ci, Cj, Di, Dj;
int dx[]={-1, 1, 0, 0}, dy[]={0, 0, -1, 1};
string mp[maxn];

int bfs(){
    deque<node> q;
    q.push_front({Ci, Cj});
    times[Ci][Cj]=0;
    while (!q.empty()){
        node cnt=q.front(); q.pop_front();
        int x=cnt.x, y=cnt.y;
        if (x==Di&&y==Dj) return times[x][y];
        for (int i=0; i<4; i++){
            int nx=x+dx[i], ny=y+dy[i];
            if (nx<0||nx>=h||ny<0||ny>=w) continue;
            if (mp[nx][ny]=='.'&&(times[nx][ny]==-1||times[nx][ny]>times[x][y])){
                times[nx][ny]=times[x][y];
                q.push_front({nx, ny});
            }
        }
        int sx=x-2, sy=y-2;
        for (int i=0; i<5; i++){
            for (int j=0; j<5; j++){
                int nx=i+sx, ny=j+sy;
                if (nx<0||nx>=h||ny<0||ny>=w) continue;
                if (mp[nx][ny]=='.'&&times[nx][ny]==-1){
                    times[nx][ny]=times[x][y]+1;
                    q.push_back({nx, ny});
                }
            }
        }
    }
    return -1;
}


int main(){
    memset(times, -1, sizeof(times));
    scanf("%d%d", &h, &w);
    scanf("%d%d", &Ci, &Cj);
    Ci--, Cj--;
    scanf("%d%d", &Di, &Dj);
    Di--, Dj--;
    for (int i=0; i<h; i++){
        cin>>mp[i];
    }
    printf("%d", bfs());
}


Measured memory_bytes: 10592
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 1005
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;


int main()
{
    FASTIO
    /*
    //double start_time = clock();
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
//*/
    int T;
    //cin >> T;
    T = 1;
    for (int cs = 1; cs <= T; cs++) {
        int n;
        cin >> n;
        int x = 0;
        for (int i = 0; i < n; i++) {
            int a;
            cin >> a;
            x = x ^ a;
        }
       // cerr << x << endl;
        if (!x) cout << "Yes\n";
        else cout << "No\n";
    }

    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
    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 n = sc.nextInt();
        long[] A = new long[n];
        long ans = 0;
        for (int i=0;i<n;i++){
            A[i]=sc.nextInt()-i-1;
        }
        Arrays.sort(A);
        if (n%2==0){
            for (int i=0;i<n;i++) ans += Math.abs(A[i]-(A[n/2-1]+A[n/2])/2);
        }else {
            for (int i=0;i<n;i++) ans += Math.abs(A[i]-(A[(n-1)/2]));
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 62772
import java.util.*;
public class Main{
    public static void main(String args[]) {
        Scanner sc= new Scanner(System.in);
        String s1= sc.next();
        String s2= sc.next();
        br:
        for(int i=0;i<s2.length();i++){
            for(int j=0;j<s1.length();j++){
                if(s1.charAt(j) != s2.charAt((i+j)%s2.length())){
                    continue br;
                }
            }
            System.out.println("Yes");
            return ;
        }
        System.out.println("No");
            return ;
    }
}


Measured memory_bytes: 24916
#include <stdio.h>

int main()
{
    int N,d[100],tmp,i,j,count;

    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&d[i]);
    }

    for(i=0;i<N;i++){
        for(j=i+1;j<N;j++){
            if(d[i]<d[j]){
                tmp = d[i];
                d[i] = d[j];
                d[j] = tmp;
            }
        }
    }

    count=1;

    for(i=0;i<N-1;i++){
        if(!(d[i] == d[i+1])) count++;
    }

    printf("%d\n",count);

    return 0;

}

Measured memory_bytes: 128
h,w=map(int,input().split())
T=[list(input()) for i in range(h)]
while ["."]*w in T:
  T.remove(["."]*w)
  h-=1
T=list(list(i) for i in zip(*T))
while ["."]*h in T:
  T.remove(["."]*h)
T=list(list(i) for i in zip(*T))
for t in T:
  print("".join(t))

Measured memory_bytes: 3188
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char c;
    cin >> c;
    char a = c+1;
    print(a);

    

}

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

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int main(void){
  int n;
  cin >> n;
  vector<int> ans(n+1);
  for (int x = 1; x <= 100; x++) {
    for (int y = 1; y <= 100; y++) {
      for (int z = 1; z <= 100; z++) {
        int s = x*x + y*y + z*z;
        s += x*y + y*z + z*x;
        if (s > n) continue;
        ans[s]++;
      }
    }
  }
 
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << endl;
  }
}

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

typedef struct Node{
  int key;
  Node *prev, *next;
} Node;

Node *nil;

void insert_cell(int key)
{
  Node *x;
  x = new Node;
  x->key = key;
  x->prev = nil;
  x->next = nil->next;
  x->next->prev = x;
  nil->next = x;
}

void deleteNode(Node *t)
{
  if(t != nil){
    t->prev->next = t->next;
    t->next->prev = t->prev;
    t->prev = NULL;
    t->next = NULL;
    delete t;
  }
}

void delete_cell(int x)
{
  Node *cell;
  cell = new Node;
  cell = nil->next;
  while(cell->key != x && cell != nil)
    cell = cell->next;
  deleteNode(cell);
}

void deleteFirst()
{
  deleteNode(nil->next);
}

void deleteLast()
{
  deleteNode(nil->prev);
}
  

int main()
{
  nil = new Node;
  nil->prev = nil;
  nil->next = nil;
  int n, k;
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    char s[20], c;
    scanf("%s%d", s, &k);
    if(s[0] == 'i'){
      insert_cell(k);
    }else{
      if(s[6] == 'F')
	deleteFirst();
      else if(s[6] == 'L')
	deleteLast();
      else
	delete_cell(k);
    }
  }
  Node *p;
  p = new Node;
  p = nil->next;
  for(int i = 0; p != nil; i++, p = p->next)
    if(i)
      cout << " " << p->key;
    else
      cout << p->key;  
  delete p;
  cout << endl;
}

Measured memory_bytes: 32364
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
typedef long double ld;
using namespace std;
///////////////////////////
#define INF 1000000000000000009
#define MAX_V 100001
typedef pair<ll, ll> p;
struct edge{ll to, cost;};
std::vector<vector<edge> > G(MAX_V);
std::vector<ll> pre(MAX_V,-1);
priority_queue<p, std::vector<p>, greater<p> > que; //class, inner, compair
std::vector<ll> d(MAX_V+1, INF);
std::vector<ll> ds(MAX_V, 0), dt(MAX_V, 0), DS(MAX_V, 0), DT(MAX_V, 0);
ll P = 1000000007;
void dijkstra(int start, int mode){
  d[start]=0;
  que.push(p(0, start));
  while(!que.empty()){
    p p_now=que.top(); que.pop();
    ll v = p_now.second;
    if(d[v]<p_now.first) continue;
    for(int i=0;i<G[v].size();i++){
      edge e = G[v][i];
      if(d[e.to]==d[v]+e.cost) (mode==1?ds[e.to]:dt[e.to]) = ((mode==1?ds[e.to]:dt[e.to]) +  (mode==1?ds[v]:dt[v]))%P;
      if(d[e.to]>d[v]+e.cost){
        (mode==1?ds[e.to]:dt[e.to]) = (mode==1?ds[v]:dt[v]);
        d[e.to]=d[v]+e.cost;
        pre[e.to] = v;
        que.push(p(d[e.to], e.to));
      }
    }
  }
}
ll pm(ll a, ll b){return (a - b + P)%P;}
ll pp(vector<ll> a){
  ll ret = 1;
  for(int i=0;i<a.size();i++) ret = (ret * a[i])%P;
  return ret;
}
/////////////////////////////////////////////
int main(int argc, char const *argv[]) {
  ll N, M, S, T, a, b, c, ans = 0;
  std::cin >> N >> M;
  std::cin >> S >> T;
  vvl eg = vv(0, 3, 0, ll);
  for(int i=0;i<M;i++){
    scanf("%lld %lld %lld", &a, &b, &c);
    eg.push_back(std::vector<ll> {a, b, c});
    eg.push_back(std::vector<ll> {b, a, c});
    G[a].push_back(edge{b, c});
    G[b].push_back(edge{a, c});
  }

  ds[S] = dt[T] = 1;
  dijkstra(S, 1);
  for(int i=1;i<=N;i++) DS[i] = d[i];
  for(int i=1;i<=N;i++) d[i] = INF;
  dijkstra(T, -1);
  for(int i=1;i<=N;i++) DT[i] = d[i];
  if(DS[T]==INF){
    std::cout << 0 << '\n';
    return 0;
  }
  ans = (ds[T]*ds[T])%P;
  for(int i=1;i<=N;i++){
    if(DS[T] == 2 * DS[i]){
      ans = pm(ans, pp(vector<ll> {ds[i], ds[i], dt[i], dt[i]}));
    }
  }
  for(int i=0;i<eg.size();i++){
    if(2*DS[eg[i][0]]<DS[T]&&2*DS[eg[i][1]]>DS[T]&&DS[eg[i][0]]+eg[i][2]+DT[eg[i][1]]==DS[T]){
      ans = pm(ans, pp(vector<ll> {ds[eg[i][0]], ds[eg[i][0]], dt[eg[i][1]], dt[eg[i][1]]}));
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 43688
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
 
public class Main {
  
    private static final int MAX_INPUT_LIMIT_COUNT = 2;
 
    private static final int YEAR = 2019;
 
    private static final int ARR_INDEX_MONTH = 0;
    private static final int ARR_INDEX_DAY = 1;
  
  public static void main(String[] args) {
    
    List<String> inputList = null;
    
 		try {
          inputList = readInputList();
        } catch(IOException e) {
          e.printStackTrace();
          return;
        }
        
 
        byte maxDayFlag = 0;
 
        int[] arr = readYearAndMonth(inputList.get(0));
 
        Calendar cal = convertCalender(arr);
        if (cal.getActualMaximum(Calendar.DAY_OF_MONTH) == arr[ARR_INDEX_DAY])
            maxDayFlag = 1;
 
        System.out.println(maxDayFlag);
  }
 
    private static List<String> readInputList() throws IOException {
 
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
 
            List<String> inputList = new ArrayList<>();
 
            for (int i = 0; i < MAX_INPUT_LIMIT_COUNT; i++) {
                inputList.add(br.readLine());
            }
 
            return inputList;
    }
 
    private static int[] readYearAndMonth(String inputStr) {
        int[] yearAndMonthArr = new int[2];
        String[] strArr = inputStr.split("\\s");
 
        yearAndMonthArr[ARR_INDEX_MONTH] = Integer.valueOf(strArr[ARR_INDEX_MONTH]);
        yearAndMonthArr[ARR_INDEX_DAY] = Integer.valueOf(strArr[ARR_INDEX_DAY]);
 
        return yearAndMonthArr;
    }
 
    private static Calendar convertCalender(int[] yearAndMonthArr) {
        return new Calendar.Builder()
                .setLenient(true)
                .set(Calendar.YEAR, YEAR)
                .set(Calendar.MONTH, yearAndMonthArr[ARR_INDEX_MONTH] - 1)
                .set(Calendar.DAY_OF_MONTH, yearAndMonthArr[ARR_INDEX_DAY])
                .build();
    }
 
}

Measured memory_bytes: 21712
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        Dice dice = new Dice(sc, x);
        if(check(dice)){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
    
    public static boolean check(Dice dice) {
        char[] pat = {'N','N','E','E','E','N'};
        for(int j = 0; j < dice.data.length; j++){
            for(int k = 0; k < dice.data[j].length; k++){
                if(j == k){ break; }
                for(char p:pat){
                    if(Arrays.equals(dice.data[j], dice.data[k])){
                        return true;
                    }
                    dice.roll(0, p);
                    for(int i = 0; i < 4; i++){
                        if(Arrays.equals(dice.data[j], dice.data[k])){
                            return true;
                        }
                        dice.roll(0, 'Z');
                    }
                }
            }
        }
        return false;
    }
}

class Dice {
    static int[][] data;

    public Dice(Scanner sc, int x){
        data = new int[x][6];
        for(int i = 0; i < data.length; i++){
            for(int j = 0; j < data[i].length; j++){
            data[i][j] = sc.nextInt();
            }
        }
    }

    public static void roll(int n, char p) {
        int temp = data[n][0];
        switch(p){
            case 'E':
                data[n][0] = data[n][2];
                data[n][2] = data[n][5];
                data[n][5] = data[n][3];
                data[n][3] = temp; break;
            case 'W':
                data[n][0] = data[n][3];
                data[n][3] = data[n][5];
                data[n][5] = data[n][2];
                data[n][2] = temp; break;
            case 'S':
                data[n][0] = data[n][1];
                data[n][1] = data[n][5];
                data[n][5] = data[n][4];
                data[n][4] = temp; break;
            case 'N':
                data[n][0] = data[n][4];
                data[n][4] = data[n][5];
                data[n][5] = data[n][1];
                data[n][1] = temp; break;
            case 'Z':
                temp = data[n][1];
                data[n][1] = data[n][2];
                data[n][2] = data[n][4];
                data[n][4] = data[n][3];
                data[n][3] = temp; break;
            default:
        }
    }
}

Measured memory_bytes: 28364
A,B,C,X,Y = map(int,input().split())

# a,b,c=0,0,0
# min_nedan=5000*(X+Y)
# tmp_nedan=0
# for a in range(X+1):
#     for b in range(Y+1):
#         c = 2*max(X-a,Y-b)
#         tmp_nedan = a*A+b*B+c*C
#         if tmp_nedan < min_nedan:
#             min_nedan = tmp_nedan
#
# print(min_nedan)

min_nedan=5000*(X+Y)
tmp_nedan=0
if A+B > 2*C:
    tmp_nedan += 2*C*min(X,Y)
    if X > Y:
        if A > 2*C:
            tmp_nedan+=2*C*(X-Y)
        elif A <= 2*C:
            tmp_nedan+=A*(X-Y)
    elif X<= Y:
        if B > 2*C:
            tmp_nedan+=2*C*(Y-X)
        elif B <= 2*C:
            tmp_nedan+=B*(Y-X)
elif A+B <= 2*C:
    tmp_nedan += A*X+B*Y

print(tmp_nedan)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstdlib>

using namespace std;
int  N, A, B, C;
int l[8];

int min(int a, int b, int c, int d){
  int x[4];
  x[0] = a; x[1] = b; x[2] = c; x[3] = d;
  sort(x, x+4);
  return x[0];
}

int dfs(int cur, int a, int b, int c){
  int tmp1, tmp2, tmp3, tmp4;
  if(cur == N){
    if(a == 0 || b == 0 || c == 0) return 10000000;
    return abs(a-A) + abs(b-B) + abs(c-C) - 30;
  }
  tmp1 = dfs(cur+1, a, b, c);
  tmp2 = dfs(cur+1, a+l[cur], b, c) + 10;
  tmp3 = dfs(cur+1, a, b+l[cur], c) + 10;
  tmp4 = dfs(cur+1, a, b, c+l[cur]) + 10;
  return min(tmp1, tmp2, tmp3, tmp4);
}

int main(){
  int i;
  cin >> N >> A >> B >> C;
  for(i=0; i<N; i++) cin >> l[i];
  cout << dfs(0, 0, 0, 0) <<endl;
  return 0;
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    const int N=1000000;
    vector<int> sieve(N+1,0);
    for(int i=1;i<=N;i++) sieve[i]=i;
    for(ll i=2;i<=N;i++)
    {
        if(sieve[i]!=i) continue;
        for(ll j=i*i;j<=N;j+=i) if(sieve[j]==j) sieve[j]=i;
    }
    int n;
    cin >> n;
    int g=0;
    set<int> s;
    bool p=1;
    while(n--)
    {
        int a;
        cin >> a;
        vector<int> v;
        g=gcd(g,a);
        while(a>1)
        {
            int tmp=sieve[a];
            v.push_back(tmp);
            while((a%tmp)==0) a/=tmp;
        }
        for(int b:v)
        {
            if(s.find(b)!=s.end()) p=0;
            s.insert(b);
        }
    }
    if(p==1) cout << "pairwise coprime\n";
    else if(g==1) cout << "setwise coprime\n";
    else cout << "not coprime\n";
    return 0;
}


Measured memory_bytes: 10848
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {n: i32};
    let mut n = n;

    while n > 0 {
        n -= 1000;
    }

    if n == 0 {
        println!("0")
    } else {
        println!("{}", n.abs());
    }
}


Measured memory_bytes: 2152
M=9;main(n,i,j,k,a,b,c){
	float p=atan(1)*4,X[100],Y[100],x,y;
	for(;scanf("%d",&n),n;printf("%d\n",a)){
		for(i=0;i<n;i++)scanf("%f,%f",X+i,Y+i);
		for(a=i=0;i<n;a=a>b?a:b,i++)for(b=k=0;k<M;b=b>c?b:c,k++)for(x=X[i]+cos(p*k/M),y=Y[i]+sin(p*k/M),c=j=0;j<n;j++)
			if(hypot(X[j]-x,Y[j]-y)<1+1e-3)c++;
	}
exit(0);}

Measured memory_bytes: 652
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	v := 1
	as := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&as[i])
		as[i] /= 2
		v = lcm(v, as[i])
	}

	c := count(as[0])
	for i := 1; i < n; i++ {
		if c != count(as[i]) {
			fmt.Println(0)
			return
		}
	}

	ans := (m/v + 1) / 2
	fmt.Println(ans)
}

func count(n int) int {
	c := 0
	for n%2 == 0 {
		n /= 2
		c++
	}
	return c
}

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

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}


Measured memory_bytes: 6312
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
// 標準入力からデータを読み込む準備
		try (Scanner sc = new Scanner(System.in)) { 
			String line = sc.nextLine();
			String answer = "";
			int length = line.length();
			for (int i = 0; i < length; i++) {
				char ch = line.charAt(i);  // 文字列(line)からi番目の文字を取り出す 
				if(Character.isLowerCase(ch) == true){// Character.isLowerCase で小文字かどうか判断可能
					answer += Character.toUpperCase(ch);// Character.toUpperCase, Character.toLowerCase で変換
				}else{
					answer += Character.toLowerCase(ch);
				}
			}
			System.out.println(answer); 
		}
	} 
}


Measured memory_bytes: 31376
#include <iostream>
#include <string>
using namespace std;
bool skip(char ch)
{
	if(ch=='.' || ch==',' || ch==' ') return true;
	return false;
}
int main() {
	string str; getline(cin,str);
	int cnt=0;
	for(int i=0;i<str.size();i++)
	{
		string tmp="";
		while(!skip(str[i])) tmp+=str[i++];
		if(tmp!="" && 3<=tmp.size() && tmp.size()<=6)
		{
			if(cnt++) cout << ' ' ;
			cout << tmp ;
		}
	}
	cout << '\n' ;
}

Measured memory_bytes: 1180
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
const int inf = 1e9;

//range min
struct segmentTree{
	vector<int> node;
	int n;
	
	segmentTree(vector<int> v){
		int s = v.size();
		n = 2;
		while(n < s) n *= 2;
		node = vector<int>(2*n -1, inf);
		for(int i=0; i<s; i++){
			node[i +n-1] = v[i];
		}
		for(int i=n-2; i>=0; i--){
			node[i] = min(node[2*i +1], node[2*i +2]);
		}
	}
	segmentTree(){}
	
	void Set(int val, int pos){
		int idx = n-1 + pos;
		node[idx] = val;
		do{
			idx = (idx -1)/2;
			node[idx] = min(node[2*idx +1], node[2*idx +2]);
		}while(idx != 0);
	}
	int Get(int l, int r){
		if(l == r) return inf;
		return _get(l, r, 0, 0, n);
	}
	int _get(int l, int r, int k, int cl, int cr){
		if(l <= cl && cr <= r){
			return node[k];
		}
		if(r <= cl || cr <= l){
			return inf;
		}
		int m = (cl +cr)/2;
		return min(_get(l, r, 2*k+1, cl, m), _get(l, r, 2*k+2, m, cr));
	}
};

vector<vector<int> > tree, query, mark;
vector<int> dep2idx;
segmentTree segtree;
long long int solve(int node, int depth){
	long long int ret = 0;
	for(int i=0; i<(int)mark[node].size(); i++){
		segtree.Set(-depth, mark[node][i]);
		dep2idx[depth] = node;
	}
	for(int i=0; i<(int)query[node].size(); i++){
		ret += dep2idx[-segtree.Get(0, query[node][i])];
	}
	for(int i=0; i<(int)tree[node].size(); i++){
		ret += solve(tree[node][i], depth+1);
	}
	for(int i=0; i<(int)mark[node].size(); i++){
		segtree.Set(0, mark[node][i]);
		dep2idx[depth] = 0;
	}
	return ret;
}

int main(){
	while(1){
		int n,q;
		cin >> n >> q;
		if(n==0) break;
		
		vector<vector<int> > vvi(n+1);
		tree = query = mark = vvi;
		for(int i=2; i<=n; i++){
			int par;
			cin >> par;
			tree[par].push_back(i);
		}
		mark[1].push_back(0);
		for(int i=1; i<=q; i++){
			char c;
			int node;
			cin >> c >> node;
			if(c=='Q') query[node].push_back(i);
			else mark[node].push_back(i);
		}
		segtree = segmentTree(vector<int>(q+1, inf));
		dep2idx = vector<int>(n, 0);
		cout << solve(1, 0) << endl;
	}
	return 0;
}


Measured memory_bytes: 40760
#include <iostream>
#include <sstream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main(){
	int a[100][50];
	string s;
	int c = 0;
	while(getline(cin,s)){
		istringstream is(s);
		is >> a[c][0];
		char b;
		int n = 1;
		while(is >> b >> a[c][n++]){}
		c++;
	}
	int d = (c+1)/2;
	int dp[c][d];
	dp[0][0] = a[0][0];
	for(int i=1;i<d;i++){
		for(int j=0;j<=i;j++){
			if(j==0) dp[i][j] = a[i][j] + dp[i-1][j];
			else if(j==i) dp[i][j] = a[i][j] + dp[i-1][j-1];
			else dp[i][j] = a[i][j] + max(dp[i-1][j],dp[i-1][j-1]);
		}
	}
	for(int i=d;i<c;i++){
		for(int j=0;j<c-i;j++){
			dp[i][j] = a[i][j] + max(dp[i-1][j],dp[i-1][j+1]);
		}
	}
	cout << dp[c-1][0] << endl;
}

Measured memory_bytes: 1264
#include<iostream>	// 入出力
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列
#include<map>		// 連想配列
#include<stack>		// スタック
#include<queue>		// キュー
#include<algorithm> // ソートとか


using namespace std;


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

	vector<int> ans;

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

		if (i % 2 == 0) {
			ans.emplace_back(num);
		}
		else {
			ans.insert(ans.begin(), num);
		}
	}

	if (n % 2 != 0) {
		for (int i = ans.size() - 1; i >= 0; --i) {
			cout << ans[i] << " " << flush;
		}
		cout << endl;
	}
	else {
		for (int i = 0; i < ans.size(); ++i) {
			cout << ans[i] << " " << flush;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3060
x,n=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
if n==0:
    print(x)
else:
    if x in p:
        i=1
        while True:
            if not x-i in p:
                print(x-i)
                break
            if not x+i in p:
                print(x+i)
                break
            i+=1
    else:
        print(x)


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

int main() {
  int N, M, count = 0;
  cin >> N >> M;
  vector<int> road(M * 2);
  
  for (int i = 0; i < road.size(); i++) {
    cin >> road.at(i);
  }

  for (int i = 0; i < N; i++) { //i:都市
    for (int j = 0; j < road.size(); j++) { //j:配列の要素の数
      if (road.at(j) == i + 1) {
        count++;
      }
    }
    cout << count << endl;
    count = 0;
  }
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS

main = do
    -- numbers <- map (BS.unpack) . BS.words <$> BS.getLine
    -- numbers <- map (read . BS.unpack) . BS.words <$> BS.getLine
    [a,b] <- map (read . BS.unpack) . BS.words <$> BS.getLine :: IO [Int]
    -- let num_i = (read . BS.unpack) num :: In
    -- putStrLn $ show $ a * b
    putStrLn $ show $ max (a - b * 2) 0
    -- putStrLn $ show $ numbers !! 0

Measured memory_bytes: 508
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main(int argc, char const *argv[])
{
    /* code */
    char S[10], T[10];
    scanf("%s %s", &S, &T);
    int A, B;
    scanf("%d %d", &A, &B);
    char U[10];
    scanf("%s", &U);
    if(strcmp(S, U) == 0)
    {
        printf("%d %d", A - 1, B);
    }
    else if(strcmp(T, U) == 0)
    {
        printf("%d %d", A, B - 1);
    }
    else
    {
        printf("%d %d", A, B);
    }
    return (0);
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(p,a,b)    for(int p=a;p<b;p++)
#define INF 0x3f3f3f3f
#define mul(x) x*x*(x-=1)


int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("o2.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int a,b,c,k,sum=0;
    cin>>a>>b>>c>>k;

    sum=min(a,k);
    k-=sum;
    if(k)k-=min(k,b);
    if(k)sum-=min(k,c);

    cout<<sum;
    
    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<vector>
#include<algorithm>
#include<string.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << x << endl;
using namespace std;

int main(){
    int stu[30] = {0};
    int n;

    rep(i,28){
        cin >> n;
        stu[n-1] = 1;
    }
    rep(i, 30){
        if(stu[i] != 1){
            cout << i + 1 << endl;
        }
    }
}

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

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    vector<int> p(n);
    for(int i = 0; i <n; i++){
        cin >> p[i];
    }
    int cnt1 = 0, cnt2 = 0, cnt3 = 0;
    for(int i = 0; i <n; i++){
        p[i] <= a ? cnt1++ :p[i] > a && p[i] <= b ? cnt2++ : cnt3++;
    }
    cout << min({cnt1,cnt2,cnt3});
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNextInt()) {
            int n = scan.nextInt();

            int sosu = 0;
            if( n >= 2 ){
                sosu++;
            }
            for (int x = 3; x <= n; x+=2) {
                int notSosuFlag = 0;
                for (int i = 3; i*i <= x && notSosuFlag == 0; i+=2) {
                    if (x % i == 0) {
                        notSosuFlag = 1;
                    }
                }

                if (notSosuFlag == 0) {
                    sosu++;
                }
            }

            System.out.println(sosu);

        }
    }
}



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

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
// *st.find_by_order(index), 0-based
// order_of_key(e)

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N; cin>>N;
	vector<int> ct(N+1,0);
	for (int x=1; x<=100; x++) {
		for (int y=1; y<=100; y++) {
			for (int z=1; z<=100; z++) {
				int cur=x*x+y*y+z*z+x*y+y*z+z*x;
				if(cur<=N)
					ct[cur]++;
			}
		}
	}
	for (int i=1; i<=N; i++)
		cout<<ct[i]<<"\n";
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;
template <typename T>
void vecin(vector<T> &v, int n = 0)
{
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
}
template <typename T>
void vecout(vector<T> &v, int n = 0)
{
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n - 1; ++i)
    {
        cout << v[i] << " ";
    }
    cout << v[n - 1] << endl;
}


int main()
{
    ciosup;
    vector<vector<int>> G(100005);
    vector<vector<pint>> G2(100005);
    vector<int> inrank(100005);
    unordered_map<int,int> topsort;
    queue<int> zeronode;
    int n, m;
    cin >> n >> m;
    REP(i,n-1+m){
        int a, b;
        cin >> a >> b;
        G[a].emplace_back(b);
        G2[a].emplace_back(make_pair(b, 0));
        G2[b].emplace_back(make_pair(a, 1));
        ++inrank[b];
    }
    FOR(i ,1, n+1){
        if (inrank[i] == 0){
            zeronode.emplace(i);
        }
    }
    int rank = 0;
    while (zeronode.size())
    {
        int curnode = zeronode.front();
        zeronode.pop();
        topsort[curnode] = rank++;
        for (int elem : G[curnode])
        {
            if (--inrank[elem] == 0){
                zeronode.emplace(elem);
            }
        }
    }
    vint ans(n+1, 0);
    FOR(i, 1, n+1)
    {
        int in = 0, rnk = -1;
        for (pint elem:G2[i]){
            if (elem.SE == 1 && rnk < topsort[elem.FI])
            {
                rnk = topsort[elem.FI];
                ans[i] = elem.FI;
            }
        }
    }
    FOR(i,1,n+1){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 16676
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N = int(input())
e = dd(list)
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)

s = [1]
order = []
parent = [-1] * (N + 1)
vis = [0] * (N + 1)
while len(s):
  x = s.pop()
  vis[x] = 1
  order.append(x)
  for y in e[x]:
    if vis[y]: continue
    s.append(y)
    parent[y] = x

dp = [0] * (N + 1)
esize = [0] * (N + 1)
for x in order[N - 1: 0: -1]: esize[parent[x]] += 1
#print(esize)
#print(order)
for x in order[N - 1: 0: -1]:
  y = parent[x]
  dp[y] += (dp[x] + 1) / esize[y]
#print(dp)
res = [0] * (N + 1)
res[1] = dp[1]
for x in order[1: ]:
  y = parent[x]
  t = 0
  if y != 1 or (esize[y] > 1): t = (res[y] * (esize[y] + (y != 1)) - (dp[x] + 1)) / (esize[y] - (y == 1))
  #print(x, t)
  res[x] = ((t + 1) / (esize[x] + 1)) + (dp[x] * esize[x] / (esize[x] + 1))
for r in res[1: ]: print(r)

Measured memory_bytes: 103368
#include <stdio.h>

int main(void) {
  int prime[10000], n, i, j, count = 0, flag = 0;
  prime[0] = 2;
  prime[1] = 3;

  while (scanf("%d", &n) != EOF) {
    count = 0;

    for (i = 2; i <= n; i++) {
      flag = 0;
      if (i == 2) 
	count++;
      else if (i == 3) 
	count++;
      else if (i % 2 != 0){
	for (j = 0; prime[j] * prime[j] <= i; j++) {
	  if (i % prime[j] == 0) {
	    flag = 1;
	    break;
	  }
	}
	if (!flag) {
	  if (count < 10000)
	    prime[count] = i;
	  count++;
	}
      }
    }

    printf("%d\n", count);

  }
  return 0;
}

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

using namespace std;

class Cake
{
	private:
		int w, d, id;
	public:

	Cake()
	{
	}
	Cake(int w, int d)
	{
		this->w = w;
		this->d = d;
	}
	Cake(int w, int d, int id)
	{
		this->w = w;
		this->d = d;
		this->id = id;
	}
       	void splitCake(int point, Cake *c1, Cake *c2, int lstid)
	{
		int w1, d1, w2, d2;
		if( (point%(w+d)) < w )
		{
			w1 = point%(w+d);
			w2 = w - (point%(w+d));
			d1 = d2 = d;
		}else
		{
			w1 = w2 = w;
			d1 = (point%(w+d)) - w;
			d2 = d - ((point%(w+d)) - w);
		}
		c1->setwd(w1, d1);
		c2->setwd(w2, d2);
		c1->setId((c1->getArea() <= c2->getArea()?lstid:lstid+1));
		c2->setId((c1->getArea() <= c2->getArea()?lstid+1:lstid));
	}
	void setId(int id)
	{
		this->id = id;
	}
	void setwd(int w, int d)
	{
		this->w = w;
		this->d = d;
	}
	int getId()
	{
		return id;
	}
	int getArea()
	{
		return w*d;
	}
};
bool compare(Cake c1, Cake c2)
{
	return (c1.getArea()) < (c2.getArea());
}
int main()
{
	int n, w, d, i, j, point, cuttag, tmpid;
	Cake c1, c2;
	vector<Cake> cake;
	do
	{
		cin >> n >> w >> d;
		cake.clear();
		c1.setwd(w, d);
		c1.setId(1);
		cake.push_back(c1);
		for(i = 1; i <= n; i++)
		{
			cin >> cuttag >> point;
			for(j = 0; j < i; j++)
			{
				if(cake[j].getId() == cuttag)
				{
					cake[j].splitCake(point, &c1, &c2, i);
					cake.erase(cake.begin()+j);
				}
				if(cake[j].getId() > cuttag)
				{
					tmpid = cake[j].getId();
					cake[j].setId(tmpid-1);
				}
			}
			cake.push_back(c1);
			cake.push_back(c2);
		}
		sort(cake.begin(), cake.end(), compare);
		if(!( n == 0 && w == 0 && d == 0))
		{
			for(i = 0; i < n+1; i++)
			{
				cout << cake[i].getArea();
				if(i != n)
					cout << " ";
				else if(1)
					cout << endl;
			}
		}
	}while(!(n == 0 && w == 0 && d == 0));
	return 0;
}



Measured memory_bytes: 3024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main(void){
int s[2],t[2],i;
scanf("%d %d %d %d",&s[0],&s[1],&t[0],&t[1]);
for(i=0;i<2;i++)
    t[i]-=s[i];
for(i=0;i<t[1];i++)
  printf("U");
for(i=0;i<t[0];i++)
  printf("R");
for(i=0;i<t[1];i++)
  printf("D");
for(i=0;i<1+t[0];i++)
  printf("L");
for(i=0;i<1+t[1];i++)
  printf("U");
for(i=0;i<1+t[0];i++)
  printf("R");
  printf("DR");
for(i=0;i<1+t[1];i++)
  printf("D");
for(i=0;i<t[0]+1;i++)
  printf("L");
printf("U\n");
  return 0;
}



Measured memory_bytes: 128
n500, n100, n50, x = 4.times.map { gets.to_i }

c = 0
(0..n500).each do |i500|
  (0..n100).each do |i100|
    (0..n50).each do |i50|
      c += 1 if 500 * i500 + 100 * i100 + 50 * i50 == x
    end
  end
end

puts c

Measured memory_bytes: 1788
import sys
input = sys.stdin.readline
from collections import deque

mod = 10 ** 9 + 7
N = int(input())
X = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)

P = [-1] * N
Q = deque([0])
R = []
while Q:
    i = deque.popleft(Q)
    R.append(i)
    for a in X[i]:
        if a != P[i]:
            P[a] = i
            X[a].remove(i)
            deque.append(Q, a)

##### Settings
unit = 1
merge = lambda a, b: a * b % mod
adj_bu = lambda a, i: a * inv(SIZE[i]) % mod
adj_td = lambda a, i, p: a * inv(N-SIZE[i]) % mod
adj_fin = lambda a, i: a * fa[N-1] % mod
#####

nn = 200200
mod = 10**9+7

fa = [1] * (nn+1)
fainv = [1] * (nn+1)
for i in range(nn):
    fa[i+1] = fa[i] * (i+1) % mod
fainv[-1] = pow(fa[-1], mod-2, mod)
for i in range(nn)[::-1]:
    fainv[i] = fainv[i+1] * (i+1) % mod

inv = lambda i: fainv[i] * fa[i-1] % mod

SIZE = [1] * N
for i in R[1:][::-1]:
    SIZE[P[i]] += SIZE[i]

ME = [unit] * N
XX = [0] * N
TD = [unit] * N
for i in R[1:][::-1]:
    XX[i] = adj_bu(ME[i], i)
    p = P[i]
    ME[p] = merge(ME[p], XX[i])
XX[R[0]] = adj_fin(ME[R[0]], R[0])

for i in R:
    ac = TD[i]
    for j in X[i]:
        TD[j] = ac
        ac = merge(ac, XX[j])
    ac = unit
    for j in reversed(X[i]):
        TD[j] = adj_td(merge(TD[j], ac), j, i)
        ac = merge(ac, XX[j])
        XX[j] = adj_fin(merge(ME[j], TD[j]), j)

print(*XX, sep = "\n")

Measured memory_bytes: 109844
#include <iostream>

int main(){

                int a, b ;
                std::cin >> a >> b ;
                int max  = 0;
                if (2 * a - 1 > max) {
                                max = 2*a-1;
                }
                if ( a + b > max ) {

                                max = a + b;
                }
                if ( 2* b -1 > max ){
                                max  = 2*b -1 ;
                }
                std::cout << max << std::endl;

                return 0;
}

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

int main()
{
	int res[3], ma, mi, a0;
	size_t L;
	bool flag;
	string str;
	vector<string> a;
	while (cin >> a0 >> L, a0 || L) {
		str = to_string(a0);
		if (str.size() < L)
			str = string(L - str.size(), '0') + str;
		a.push_back(str);
		flag = true;
		do {
			sort(str.begin(), str.end());
			mi = stoi(str);
			sort(str.begin(), str.end(), greater<char>());
			ma = stoi(str);
			str = to_string(ma - mi);
			if (str.size() < L)
				str = string(L - str.size(), '0') + str;
			a.push_back(str);
			for (size_t j = 0; j < a.size() - 1; j++) {
				if (a[j] == a.back()) {
					res[0] = j;
					res[1] = stoi(a[j]);
					res[2] = a.size() - j - 1;
					flag = false;
				}
			}
		} while (flag);
		cout << res[0] << ' ' << res[1] << ' ' << res[2] << endl;
		a.clear();
	}
	return 0;
}

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

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define f first
#define s second
#define uint unsigned int

using namespace std;

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

int main() {
#define FILE_INPUT 0
#define FILE ""
#ifndef DEBUG
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#if FILE_INPUT == 1
#warning "FREOPEN is on"
    freopen(FILE".in", "r", stdin);
    freopen(FILE".out", "w", stdout);
#endif
#endif
	ll n, m;
	cin >> n >> m;
	string s, t;
	cin >> s >> t;
	ll d = gcd(n, m);
		ll l = n*1ll*m/d;
		bool f = false;
		ll e = m/d;
		ll q = n/d;
		for (int i = 0; i*q*(l/n) < l && i*e*(l/m) < l; ++i) {
			if (i*q >= n || i*e >= m)
				break;
			f |= s[i*q] != t[i*e];
			//cerr << i;
		}
		if (!f)
			cout << l;
		else
			cout << -1;
	
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  long number=1,times;
  cin >> times;
  long p=1000000007;
  for (int i=1;i<(times+1);i++){
    number=number*i;
    if (number>p){
    		number=number%p;
    }
  }
  cout << number<<endl;
}

Measured memory_bytes: 256
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 110000;

int n,m;
int d[maxn];

int main()
{
	scanf("%d%d",&n,&m);
	while(m--)
	{
		int x,y;scanf("%d%d",&x,&y);
		d[x]++;d[y]++;
	}
	for(int i=1;i<=n;i++) if(d[i]&1) return puts("NO"),0;
	puts("YES");
	
	return 0;
}


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

vector<int> gr[100001];
int res = 0, dp[100001];

void dfs(int src, bool *visited, int len) {
    if(dp[src] != 0) {
        res = max(res, len + dp[src]);
        return ;
    }
    visited[src] = true;
    for(auto x: gr[src]) {
        if(!visited[x]) {
            len++;
            dfs(x, visited, len);
            dp[src] = max(dp[src], 1+dp[x]);
            len--;
        }
    }
    res = max(res, len);
    visited[src] = false;
}

void solve(int N) {
    bool visited[N+1];
    memset(visited, false, sizeof visited);
    memset(dp, 0, sizeof dp);
    for(int i=1;i<=N;i++) dfs(i, visited, 0);
}

int main() {
    int N, M; cin>>N>>M;
    for(int i=0; i<M; i++) {
        int x, y; cin>>x>>y;
        gr[x].push_back(y);
    }

    solve(N);
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 13624
#include<bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int n,m;
    cin>>n>>m;
    int A[n][m];
    int b[m][1];
    rep(i,n){
        rep(j,m){
            cin>>A[i][j];
        }
    }
    rep(i,m)cin>>b[i][0];
    rep(i,n){
        int d=0;
        rep(j,m){
            d+=A[i][j]*b[j][0];
        }
        cout<<d<<endl;
    }
    return 0;
}


Measured memory_bytes: 3084
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;

			int[] num = new int[n];
			for (int i = 0; i < n; i++) {
				num[i] = scanner.nextInt();
			}
			int count = 0;
			while (true) {
				int[] newnum = Arrays.copyOf(num, num.length);
				Map<Integer, Integer> memo = new HashMap<Integer, Integer>();
				for (int i = 0; i < n; i++) {
					if (!memo.containsKey(num[i])) {
						memo.put(num[i], 1);
					} else {
						int oldv = memo.get(num[i]);
						memo.put(num[i], oldv + 1);
					}
				}
				for (int i = 0; i < n; i++) {
					num[i] = memo.get(num[i]);
				}

				if (Arrays.equals(newnum, num)) {
					break;
				}
				count++;
			}
			System.out.println(count);
			for (int i = 0; i < n; i++) {
				if (i != 0) {
					System.out.print(" ");
				}
				System.out.print(num[i]);
			}
			System.out.println();

		}
	}
}

Measured memory_bytes: 23708
#include<bits/stdc++.h>
//using namespace std;
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb push_back
#define mp std::make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
const ll MOD=1e9+7;
//const ll MOD=998244353;
//const ll MOD=100000;
const ll MAX=1e7;
const ll INF=(1ll<<55);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
struct Binary_indexed_tree{
    int N;
    vi bit;
    Binary_indexed_tree(int n):N(n){
        bit.resize(N+1,0);
    }
    void add(int x,int a){
        for(x;x<=N;x+=(x&-x)) bit[x]+=a;
    }
    ll sum(int x){
        ll ret=0;
        for(x;x>0;x-=(x&-x)) ret+=bit[x];
        return ret;
    }
};
struct Union_Find{
    ll N;
    vi par;
    vi siz;
    Union_Find(int n):N(n){
        par.resize(N);
        siz.resize(N,1);
        rep(i,0,N) par[i]=i;
    }
    ll root(ll X){
        if(par[X]==X) return X;
        return par[X]=root(par[X]);
    }
    bool same(ll X,ll Y){
        return root(X)==root(Y);
    }
    void unite(ll X,ll Y){
        X=root(X);
        Y=root(Y);
        if(X==Y) return;
        par[X]=Y;
        siz[Y]+=siz[X];
        siz[X]=0;
    }
    ll size(ll X){
        return siz[root(X)];
    }
};
ll modpow(ll X,ll Y){
    ll sum=X,cnt=1;
    vi A;
    while(cnt<=Y){
        A.pb(sum);
        sum*=sum;
        sum%=MOD;
        cnt*=2;
    }
    int M=A.size();
    ll ret=1;
    REP(i,1,M){
        if(Y>=(1ll<<M-i)){
            Y-=(1ll<<M-i);
            ret*=A[M-i];
            ret%=MOD;
        }
    }
    return ret;
}
ll fac[MAX],finv[MAX],inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n,ll r){
    if(n<r||n<0||r<0) return 0;
    return fac[n]*finv[r]%MOD*finv[n-r];
}
signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll N; cin>>N;
    vi A(N),B(N);
    rep(i,0,N) cin>>A[i]>>B[i];
    sort(ALL(A));
    sort(ALL(B));
    ll ans;
    if(N%2==0){
        ans=B[N/2]+B[N/2-1]-A[N/2]-A[N/2-1]+1;
    }
    else ans=B[N/2]-A[N/2]+1;
    cout<<ans<<endl;
}


Measured memory_bytes: 6368
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl

using namespace std;

template<typename S,typename T>auto&operator<<(auto&o,pair<S,T>p){return o<<"{"<<p.fi<<","<<p.se<<"}";}
template<typename T>auto&operator<<(auto&o,set<T>s){for(auto&e:s)o<<e<<" ";return o;}
template<typename S,typename T,typename U>
auto&operator<<(auto&o,priority_queue<S,T,U>q){while(!q.empty())o<<q.top()<<" ",q.pop();return o;}
template<typename K,typename T>auto&operator<<(auto&o,map<K,T>&m){for(auto&e:m)o<<e<<" ";return o;}
template<typename T>auto&operator<<(auto&o,vector<T>v){for(auto&e:v)o<<e<<" ";return o;}
void ashow(){cout<<endl;}template<typename T,typename...A>void ashow(T t,A...a){cout<<t<<" ";ashow(a...);}
template<typename S,typename T,typename U>
struct TRI{S fi;T se;U th;TRI(){}TRI(S f,T s,U t):fi(f),se(s),th(t){}};
template<typename S,typename T,typename U>
auto& operator<<(auto& o,TRI<S,T,U>& t){return o<<"{"<<t.fi<<","<<t.se<<","<<t.th<<"}";}

typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef TRI<int, int, int> tri;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<string> vs;

const int MAX_N = 505;

int ans[MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    if(H % h == 0 && W % w == 0){
        cout << "No\n";
        return 0;
    }
    bool flag = false;
    if(W % w == 0){
        flag = true;
        swap(H,W), swap(h,w);
    }
    for(int j = w-1; j < W; j += w){
        ans[j] = -125000*(w-1)-1;
    }
    rep(j,W){
        if(ans[j] == 0) ans[j] = 125000;
    }
    cout << "Yes\n";
    if(flag){
        rep(i,W){
            rep(j,H){
                cout << ans[i] << " ";
            }
            cout << "\n";
        }
    }else{
        rep(i,H){
            rep(j,W){
                cout << ans[j] << " ";
            }
            cout << "\n";
        }
    }
    return 0;
}


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

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

int main() {
	ios::sync_with_stdio(false);
	
	int x=0, y=0;
	
	rep(i, 4) {
		cin>>x;
		y+= x;
	}
	
	x =  y/60;
	y %= 60;
	
	cout<<x<<endl;
	cout<<y<<endl;
	
	return 0;
}

Measured memory_bytes: 1192
/* 最初に取り除く橋のある範囲は、
要求の終点の最小値より左。
さらに、その範囲の中では最も右を取り除くのがよい。
したがって終点ソートして小さい方から被らないものを取り除いていく。
*/

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

int main(){
    int n, m;
    cin >> n >> m;
    pair<int, int> itv[m];
    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        itv[i].second = a - 1;
        itv[i].first = b - 1;
    }

    sort(itv, itv + m);

    int ans = 0;
    int t = 0;
    for (int i = 0; i < m; i++){
        if (t <= itv[i].second){
            ans++;
            t = itv[i].first;
        }
    }

    cout << ans << endl;    

    return 0;
}

Measured memory_bytes: 1024