akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <iostream>
#include <typeinfo>
//#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;

  vector<int> l(q), r(q);
  for (int i = 0; i < q; i++)
  {
    cin >> l.at(i) >> r.at(i);
    l.at(i)--;
    r.at(i)--;
  }

  for (int i = 0; i < n - 1; i++)
  {
    if (s.at(i) == 'A' && s.at(i + 1) == 'C')
    {
      s.at(i) = 'a';
    }
  }
  vector<int> sum(n + 1);
  for (int i = 0; i < n; i++)
  {
    if(s.at(i)=='a'){
      sum.at(i + 1) = sum.at(i) + 1;
    }else{
      sum.at(i + 1) = sum.at(i);
    }
  }

  for (int i = 0; i < q;i++){
    int ans = sum.at(r.at(i)) - sum.at(l.at(i));
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,m;
	cin>>n>>m;//n个偶数 m个奇数
	long long sum=0;
	if(m>=2){
		sum+=m*(m-1)/2;
	}
	if(n>=2){
		sum+=n*(n-1)/2;
	}
	cout<<sum<<endl;
} 

Measured memory_bytes: 256
import java.util.Scanner;

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

		int a = sc.nextInt();
	
		int b = sc.nextInt();
		if(a<=0&&0<=b) {
			System.out.println("Zero");
			System.exit(0);
		}else if(0<=a) {
			System.out.println("Positive");
			
		}else if((b-a)%2==0) {
			System.out.println("Negative");

		}else {
			System.out.println("Positive");
		}
		
		sc.close();
		
	}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define For(start,end) for(int i = (int)start;i<(int)end;i++)
using Int = long long int;
using TDim = vector<vector<int>>;
int main(){
    int L,R;
    cin>>L>>R;
    int modL=L%2019,modR = R%2019;
    bool check=(L/2019)!=(R/2019);
    if(modL>modR||check)cout<<0<<endl;
    else
    {
        int min = 2019;
        for(int tmpL=modL;tmpL<=modR-1;tmpL++)
        {

      
            for(int tmpR=tmpL+1;tmpR<=modR;tmpR++)
            {
                int current = (tmpL*tmpR)%2019;
                if(min>current)
                {
                    min=current;
                }
            }
            
           
        }
        cout<<min<<endl;

    }
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  double t,a;cin>>t>>a;
  double h[n];
  for(int i=0;i<n;i++){
    cin>>h[i];
    h[i]=t-0.006*h[i];
  }
  double m=19000;
  for(int i=0;i<n;i++){
    if(abs(a-h[i])<abs(m-a)){
      m=h[i];
    }
  }
  for(int i=0;i<n;i++){
    if(h[i]==m){
      cout<<i+1<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
#define ll long long

using namespace std;

int main(){
    ll N,x;
    cin >> N >> x;

    //2で割れれば良い
    vector <ll> a(N);

    ll cnt = 0;
    ll tmp;

    REP(i,N)
    {
        cin >> a[i];
    }

    sort(a.begin(),a.end());

    REP(i,N)
    {

        if(x >= a[i])
        {
            cnt++;
            x -=a[i];
        }
        else break;
    }

    if(cnt == N && x != 0)cnt--;

    cout << cnt << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <vector>
#include <map>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

struct Dice {
	int top, front, right, left, back, bottom;

	void toN() {
		swap(top, front);
		swap(front, bottom);
		swap(bottom, back);
	}

	void toS() {
		swap(top, back);
		swap(back, bottom);
		swap(bottom, front);
	}

	void toE() {
		swap(top, left);
		swap(left, bottom);
		swap(bottom, right);
	}

	void toW() {
		swap(top, right);
		swap(right, bottom);
		swap(bottom, left);
	}

	bool rotateTo(int toTop, int toFront) {
		if (top == toFront) {
			toS();
		} else if (front == toFront) {
			// noop
		} else if (right == toFront) {
			toW();
			toS();
		} else if (left == toFront) {
			toE();
			toS();
		} else if (back == toFront) {
			toS();
			toS();
		} else if (bottom == toFront) {
			toN();
		} else {
			return false;
		}
		if (top == toTop) {
			// noop
		} else if (right == toTop) {
			toW();
		} else if (left == toTop) {
			toE();
		} else if (back == toTop) {
			return false;
		} else if (bottom == toTop) {
			toE();
			toE();
		} else {
			return false;
		}
		return true;
	}
};

istream& operator>>(istream& in, Dice& dice) {
	in >> dice.top >> dice.front >> dice.right
		>> dice.left >> dice.back >> dice.bottom;
	return in;
}

bool operator==(const Dice& a, const Dice& b) {
	Dice aa = a;
	return aa.rotateTo(b.top, b.front)
		&& aa.top == b.top && aa.front == b.front && aa.right == b.right
		&& aa.left == b.left && aa.back == b.back && aa.bottom == b.bottom;
}

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

	vector<Dice> dices;
	copy_n(istream_iterator<Dice>(cin), n, back_inserter(dices));

	for (int i = 0; i < dices.size(); i++) {
		for (int j = i + 1; j < dices.size(); j++) {
			if (dices[i] == dices[j]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}



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

using str = string;
using ss = stringstream;

int a[100010],w[100010];
int ac,wa;

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

    int n,m;
    cin>>n>>m;

    for(int i=0;i<m;i++)
    {
        int p;
        str s;
        cin>>p>>s;

        if(s=="AC")
        {
            if(a[p]==0)ac++;
            a[p]=1;
        }
        else if(s=="WA")
        {
            if(a[p]==0)w[p]++;
        }
    }

    for(int i=1;i<=n;i++)if(a[i]==1)wa+=w[i];

    cout<<ac<<" "<<wa;

    return 0;
}


Measured memory_bytes: 4308
import java.util.*;

public class Main {
  public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
          int num = sc.nextInt();
          Set<String> present = new HashSet<String>();
          for(int i = 0; i < num; i++){
             present.add(sc.next());
          }
          System.out.println(present.size());
          }
          }


Measured memory_bytes: 76880
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;
    if(a+b >= c)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>

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

using namespace std;

int main(){
	int a, b, c;
	while(cin >> a >> b >> c){
		//cout << a << " " << b << " " << c << endl;
		if(b - a == c - b) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
typedef long long ll;
ll n;
int main(void){
	std::cin>>n;
	for(ll h=1;h<=4000;h++){
		for(ll w=1;w<=4000;w++){
			ll tmp=4*h*w-n*h-n*w;
			ll r=n*h*w;
			if(tmp>0&&r%tmp==0){
				std::cout<<h<<' '<<w<<' '<<r/tmp<<std::endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
S = input()

for i in range(1 << (len(S)-1)):
    temp = int(S[0])
    ans = str(S[0])
    for j in range(len(S)-1):
        if ((i >> j) & 1) == 1:
            temp -= int(S[j+1])
            ans = ans + '-' + str(S[j+1])
        else:
            temp += int(S[j+1])
            ans = ans + '+' + str(S[j+1])
    if temp == 7:
        break
print(ans+'=7')


Measured memory_bytes: 3060
// Rated for Me

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

int main() {
    int r;
    cin >> r;
    if (r < 1200) {
        cout << "ABC" << endl;
    } else if (r < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }


    return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)

sr = s[::-1]
ans = 'Yes'
if s != sr :
  ans = 'No'
  
s1 = s[0:(n-1)//2]
sr = s1[::-1]
if s1 != sr :
  ans = 'No'
  
s2 = s[(n+3)//2-1:n]
sr = s2[::-1]
if s2 != sr :
  ans = 'No'
  
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
void push(int);
int pop();
int s2top(int);
void s2push(int,int);
int s1[20000],s2[20000][2],t1=0,t2=0;
int main(){
  int i,sum=0,j,a,ans[20000];
  char A[20000];
  scanf("%s",A);
  for(i=0;i<strlen(A);i++){
    if(A[i]=='\\'){
      push(i);
    }
    else if(A[i]=='/' && t1>0){
      j=pop();
      sum+=i-j;
      a=i-j;
      while(t2>0 && s2top(0)>j){
        a+=s2top(1);
        t2--;
      }
      s2push(j,a);
    }
  }
  i=0;
  while(t2>0){
    t2--;
    i++;
  }
  printf("%d\n%d",sum,i);
  for(j=0;j<i;j++){
      if(j==0)printf(" ");
    printf("%d",s2[j][1]);
    if(j!=i-1)printf(" ");
  }
  printf("\n");
  return 0;
}
void push(int x){
  s1[t1]=x;
  t1++;
}
int pop(){
  t1--;
  return s1[t1];
}
void s2push(int x,int y){
  s2[t2][0]=x;
  s2[t2][1]=y;
  t2++;
}
int s2top(int x){
  return s2[t2-1][x];
}


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

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

  int n;
  cin >> n;

  vector<int> a(n);

  int gray = 0;
  int brown = 0;
  int green = 0;
  int lblue = 0;
  int blue = 0;
  int yellow = 0;
  int orange = 0;
  int red = 0;
  int free = 0;

  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }

  for (int i = 0; i < n; i++) {
    int ai = a.at(i);

    if (ai <= 399) {
      gray++;
    } else if (ai <= 799) {
      brown++;
    } else if (ai <= 1199) {
      green++;
    } else if (ai <= 1599) {
      lblue++;
    } else if (ai <= 1999) {
      blue++;
    } else if (ai <= 2399) {
      yellow++;
    } else if (ai <= 2799) {
      orange++;
    } else if (ai < 3200) {
      red++;
    } else {
      free++;
    }
  }

  int ans = 0;

  vector<int> cl = {gray, brown, green, lblue, blue, yellow, orange, red};
  for (int i = 0; i < cl.size(); i++) {
    if (cl.at(i) > 0) ans++;
  }

  int ansMin = ans;
  int ansMax = ans;

  if (free > 0) {
    ansMax += free;
  }

  if (ans == 0) {
    ansMin = 1;
  }

  cout << ansMin << " " << ansMax << endl;

  return 0;
}

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

class union_find {
  vector<int> uf;

public:
  union_find(int sz)
  {
    uf = vector<int>(sz);
    for (int i = 0; i < sz; i++)
      uf[i] = i;
  }
  
  int root(int i)
  {
    if (uf[i] == i) return i;
    return uf[i] = root(uf[i]);
  }

  void unite(int i, int j)
  {
    int ri = root(i);
    int rj = root(j);
    if (ri != rj)
      uf[rj] = ri;
  }

  bool same(int i, int j)
  {
    return root(i) == root(j);
  }
};

typedef pair<int, int> edge;
typedef pair<edge, int> V;
priority_queue<V, vector<V>, function<bool(V, V)>> que(
  [](V a, V b) { return a.second >= b.second; }
);

#define make_V(i, j, w) make_pair(make_pair((i), (j)), (w))

int solve(int n)
{
  union_find uf(n);

  int ans = 0;
  while (!que.empty()){
    int i, j, w;
    V v = que.top(); que.pop();
    i = v.first.first, j = v.first.second;
    w = v.second;

    if (uf.same(i, j)) continue;
    uf.unite(i, j);
    ans += w;

    // printf("(%d, %d) %d\n", v.first.first, v.first.second, v.second);
  }

  return ans;
}

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

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int weight; cin >> weight;
      if (j > i && weight != -1)
        que.push(make_V(i, j, weight));
    }
  }

  cout << solve(n) << endl;

  return EXIT_SUCCESS;
}




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

namespace ABC087A
{
    class Program
    {
        static void Main(string[] args)
        { 
            int x, a, b, c;
            x = int.Parse(Console.ReadLine());
            a = int.Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());
            c = (x - a) % b;
            Console.WriteLine(c);
            Console.ReadKey();
        }
    }
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		bool chk = true;
		int N = S.Length;
		for(int i=0;i<N;i++){
			if(i % 2 == 0){
				// odd
				chk &= (S[i] == 'R' || S[i] == 'U' || S[i] == 'D');
			} else {
				// even
				chk &= (S[i] == 'L' || S[i] == 'U' || S[i] == 'D');
			}
		}
		Console.WriteLine(chk ? "Yes" : "No");
		
	}
	String S;
	public Sol(){
		S = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

int main(){
    string S;
    cin >> S;
    
    long int Bcount = 0;
    long int ans = 0;
    for (int i=0; i<S.size(); i++){
        if(S.at(i) == 'B'){
            Bcount ++;
        }
        if (S.at(i) == 'W'){
            ans += Bcount;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 644
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)

ll res = 0;
void solve(std::string &S){
    if(S.empty())
        return;
    ll cnt1=0, cnt2=0;
    bool read2 = true, cut = false;
    while(1){
        if(S.empty()|| cut){
            res += min(cnt1, cnt2)*(min(cnt1, cnt2)-1)/2;
            res += max(cnt1, cnt2)*(max(cnt1, cnt2)+1)/2;
            break;
        }
        char tmp = S.back();
        if(read2){
            if(tmp == '>'){
                cnt2++;
                S.pop_back();
                continue;
            }
            if(tmp == '<'){
                cnt1++;
                read2 =false;
                S.pop_back();
                continue;
            }
        }
        else{
            if(tmp == '>'){
                cut = true;
                continue;
            }
            if(tmp == '<'){
                cnt1++;
                read2 =false;
                S.pop_back();
                continue;
            }
        }
    }
    solve(S);
}

int main(){
    std::string S;
    std::cin >> S;
    if(S.at(0)=='>') 
        S = "<" + S;
    if(S.at(S.length()-1)=='<')
        S.push_back('>');
    solve(S);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1412
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

N = int(input())
A = list(map(int, input().split()))

count = 1
mode = None
for i in range(1, N):
    if A[i-1] == A[i]:
        continue

    if mode == None:
        if A[i-1] < A[i]:
            mode = 'inc'
        if A[i-1] > A[i]:
            mode = 'dec'
        continue

    if mode == 'inc' and A[i-1] < A[i]:
        continue

    if mode == 'dec' and A[i-1] > A[i]:
        continue

    count += 1
    mode = None

print(count)

Measured memory_bytes: 15020
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include <string>
using namespace std;
long long s[1000000];
long long h[1000000];
struct one
{
    long long x,y;
}f[1000000];
bool cmp(struct one a,struct one b)
{
    if(a.x==b.x)
        return a.y<b.y;
    else
        return a.x<b.x;
}
int main()
{
    int N,M;
     cin>>N;
     for(int i=0;i<N;i++)
     {
         cin>>s[i]>>h[i];
         f[i].x=s[i]-h[i];
         f[i].y=s[i]+h[i];
     }
     sort(f,f+N,cmp);
     long long k=f[0].y;
     int t=0;
     for(int i=1;i<N;i++)
     {
         if(f[i].x<k)
         {
             if(f[i].y<k)
             k=f[i].y;
             t++;
         }
         else
         {
             k=f[i].y;
         }
     }
    printf("%d",N-t);
    return 0;
}


Measured memory_bytes: 7936
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define print(n) cout << n << endl
#define YN(c) (c)?(print("YES")):(print("NO"))
#define Yn(c) (c)?(print("Yes")):(print("No"))
#define yn(c) (c)?(print("yes")):(print("no"))
#define in(v) int v; cin >> v
#define vint vector<int>
#define pb push_back
typedef long long int ll;

int main(){
  in(n);map<int,int> m;
  rep(i,n-1){
  	in(tmp);
  	m[tmp]++;
  }
  rep(i,n){
  	print(m[i+1]);
  }
  return 0;
}

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

int main(){
  string S ; 
  cin >> S ; 
  int cnt = 0 ; 
  for(int i = 0 ; i < 3 ; i++){
    if(S.at(i) == '1') cnt++ ; 
  }
  
  cout << cnt << endl ;
}

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

int main(){
	string s;
	int n;
	cin >> s;
	n = s.size();
	long long sum = 0;


	for(int i = 0; i < (1 << (n - 1));i++){//n-1箇所の+
    //cout << s[0] << endl;
		long long m = s[0] - '0';
    //cout << m << endl;
		for(int j = 0; j < n - 1; j++){
			if( i & ( 1 << j ) ){
				sum += m;
				m = 0;
			}
			m = m*10 + s[j+1] - '0';
		}
		sum += m;
	}
	cout << sum << endl;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var AP = ReadSplitInt();
            var kakera = AP[0] * 3 + AP[1];
            Println(kakera / 2);
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}



Measured memory_bytes: 11220
#include <iostream>

using namespace std;

int main() {
    long long n, k, ans = 0;
    cin >> n >> k;
    if (k % 2 != 0){
        long long a = n / k;
        ans = a * a * a;
    }
    else {
        long long a = n / k;
        ans += a * a * a;
        long long r = k / 2;
        if (a * k + r > n) ans += a * a * a;
        else ans += (a + 1) * (a + 1) * (a + 1);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
from operator import itemgetter

def id(n):
    if len(str(n)) >= 6:
        return str(n)
    return "0"*(6-len(str(n)))+str(n)

n,m = map(int,input().split())
data = [[] for i in range(n+1)]
for i in range(m):
    p,y = map(int,input().split())
    data[p].append((i,y))
ans = []
for i in range(n+1):
    if data[i]:
        data[i].sort(key=itemgetter(1))
        for j in range(len(data[i])):
            ans.append((data[i][j][0],id(i)+id(j+1)))
ans.sort()
for i,j in ans:
    print(j)

Measured memory_bytes: 42364
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;

int main(){
    double r;
    cin >> r;

    printf("%.07lf ",PI*r*r);
    printf("%.07lf\n ",2*PI*r);

}


Measured memory_bytes: 3208
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int cardsn[101], cardsm[101];

int main() {

    int n, m, sumn, summ, diff, tn, tm, idx;
    for(; ;) {
        scanf("%d %d", &n, &m);
        if (n == 0 && m == 0) break;
        sumn = summ = 0;
        for (int i = 0; i < n; i++) {
            scanf("%d", &cardsn[i]);
            sumn += cardsn[i];
        }
        for (int i = 0; i < m; i++) {
            scanf("%d", &cardsm[i]);
            summ += cardsm[i];
        }
        sort(cardsn, cardsn+n);
        sort(cardsm, cardsm+m);
        bool flag = false;
        if (summ > sumn) {
            for (int i = 0; i < m; i++) {
                tm = summ - cardsm[i];
                tn = sumn + cardsm[i];
                if (tn <= tm || (tn - tm) % 2 != 0) continue;
                else {
                    diff = (tn - tm) / 2;
                    idx = int(lower_bound(cardsn, cardsn+n, diff)-cardsn);
                    if (idx < n && cardsn[idx] == diff) {
                        printf("%d %d\n", diff, cardsm[i]);
                        flag = true;
                        break;
                    }
                }
            }
        }
        else if (sumn >= summ) {
            for (int i = 0; i < n; i++) {
                tn = sumn - cardsn[i];
                tm = summ + cardsn[i];
                if (tm <= tn || (tm - tn) % 2 != 0) continue;
                else {
                    diff = (tm - tn) / 2;
                    idx = int(lower_bound(cardsm, cardsm+m, diff) - cardsm);
                    if (idx < m && cardsm[idx] == diff) {
                        printf("%d %d\n", cardsn[i], diff);
                        flag = true;
                        break;
                    }
                }
            }
        }
        if (!flag) printf("%d\n", -1);
    }
    return 0;
}



Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
int a, b, c;
bool vis[111];
int main (void) {
    scanf ("%d%d%d", &a, &b, &c);
    int p = 0;
    while (!vis[p]) {
        vis[p] = true;
        p = (p+a)%b;
    }
    if (vis[c]) printf ("YES\n");
    else printf ("NO\n");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  	
  	string a;
  	cin >> a;
  	long long b=a.length(), d=0;
  	for (int i=0; i<b; i++) {
      char c=a[i];
      if (i%2==0){
        if (c!='R' && c!='U' && c!='D'){
          break;}
        else {
          d++;}
      	}
      else{
        if (c!='L' && c!='U' && c!='D'){
          break;}
        else {
          d++;}
      	}
      }
  if (d==b) {
    cout << "Yes";
  }
  else {
    cout << "No";
  }
}

Measured memory_bytes: 3660
package main

import "fmt"

func main() {
	var b string
	fmt.Scan(&b)
	if b == "A" {
		fmt.Println("T")
	}
	if b == "G" {
		fmt.Println("C")
	}
	if b == "T" {
		fmt.Println("A")
	}
	if b == "C" {
		fmt.Println("G")
	}
}


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

int main() {
  
  int N, T, A;
  cin >> N >> T >> A;
  vector<int> H(N);
  for(int i=0; i<N; i++){
    cin >> H.at(i);
  }
  
  vector<double> ave(N);
  
  for(int i=0; i<N; i++){
    ave.at(i) = T-H.at(i)*0.006-A;
    if(ave.at(i) < 0){
      ave.at(i) = -ave.at(i);
    }
  }
  
  double sub = 1000000;
  for(int i=0; i<N; i++){
    if(ave.at(i) < sub){
      sub = ave.at(i);
    }
  }
   int ans;
  for(int i=0; i<N; i++){
    if(sub == ave.at(i)){
      ans = i+1;
    }
  }
  
  cout << ans << endl;
      
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a=n;
  	while(n!=0)
    {
      int rem=n%10;
      if(rem==7)
      {
        cout<<"Yes";
        return 0;
      }
      n=n/10;
    }
    cout<<"No";
  return 0;
}

Measured memory_bytes: 3624
class Integer
  def self.lucas(m, n, mod, len)
    res = 1

    len.times do |i|
      a = m[i]
      b = n[i]

      if a == 0 && b == 1
        return 0
      end
    end

    res
  end

  def combination(k)
    return 0 if self < k
    return 1 if k.zero?

    (self - k + 1..self).inject(:*) / k.factorial
  end

  def factorial
    return 1 if self.zero?

    (1..self).inject(:*)
  end
end

N = gets.to_i
A = gets.chomp.chars.map(&:to_i)
B = A.each_cons(2).map { |a, b| (a - b).abs }

if N <= 2
  puts B.first
  exit
end

def f
  len = (N - 2).to_s(2).size
  res = 0

  (N - 1).times do |i|
    j = Integer.lucas(N - 2, i, 2, len)

    next if j == 0

    if B[i].even?
      res ^= 0
    else
      res ^= 1
    end
  end

  res
end

if f == 0
  if B.include?(1)
    puts 0
  else
    B.size.times do |i|
      B[i] = B[i] / 2
    end

    puts (f == 0) ? 0 : 2
  end
else
  puts 1
end


Measured memory_bytes: 111640
#include <stdio.h>
 
int main(void){
    int a, b;
    scanf("%d%d", &a, &b);
    int ans = b;
    if(a < 6){
        ans = 0; 
    }
    else if(a < 13){
        ans = ans / 2; 
    }
    printf("%d\n", ans);
    return 0; 
}

Measured memory_bytes: 128
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
ll cnt[100005],upper[100005],a[100005];
int n;
bool f=1;


int main() {
	cin>>n;
	for(int i=0;i<=n;i++) {
		cin>>a[i];
	}
	upper[n]=0;
	for(int i=n-1;i>=0;i--) {
		upper[i]=upper[i+1]+a[i+1];
	}
	cnt[0]=1-a[0];
	ll ans=1;
	if(cnt[0]>upper[0] || a[0]>1) {
		f=0;
	}
	for(int i=1;i<=n;i++) {
		if(2*cnt[i-1]<a[i]) {
			f=0;
			break;
		}
		cnt[i]=min(upper[i],2*cnt[i-1]-a[i]);
		ans+=cnt[i]+a[i];
	}
	if(!f) {
		cout<<-1;
		return 0;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5936
#include <bits/stdc++.h>
using namespace std;
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int main(void) {
    io;
    int a; cin >> a;
    cout << ( a + a*a + a*a*a );
    return 0;
}


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

#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define f(a, b, c) for(int a = b; a < c; a++)
using namespace std;
const ll mod = 1e9 + 7;



//ll fact[1000001]; ll inv[1000001];
//ll primes[100007];
//ll arr[1000007];
//ll modPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//
//	ll halfpow = modPower(b, p / 2);
//	ll toReturn = (halfpow * halfpow) % mod;
//	if (p % 2)
//		toReturn = (toReturn * b) % mod;
//
//	return toReturn;
//}
//
//ll fastPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//	ll ans = fastPower(b, p / 2);
//	ans = (ans * ans);
//	if (p % 2 != 0)
//		ans = (ans * b);
//	return ans;
//}
//ll GcdRecursive(ll a, ll b) {
//	if (b == 0) return a;
//	return GcdRecursive(b, a % b);
//}
//ll modLCM(ll a, ll b) {
//	ll val = GcdRecursive(a, b);
//	ll tmp = ((a % mod) * (b % mod)) % mod;
//	ll finalVal = ((tmp % mod) * (arr[val] % mod)) % mod;
//	return finalVal;
//
//}
//ll LCM(ll a, ll b) {
//	return (a * b) / GcdRecursive(a, b);
//}
//void move1step(ll& a, ll& b, ll q) { // a and b by reference
//	ll c = a - q * b;
//	a = b;
//	b = c;
//}
//ll GcdIterative(ll a, ll b) {
//	while (b) move1step(a, b, a / b);
//	return a;
//}
//
//void pre(ll n) {
//
//	fact[0] = 1;
//	inv[0] = 1;
//
//	for (ll i = 1; i <= n; i++) {
//		fact[i] = (i * fact[i - 1]) % mod;
//		inv[i] = modPower(fact[i], mod - 2);
//		arr[i] = modPower(i, mod - 2);
//	}
//}
//
//ll npr(ll n, ll r) {
//	return ((fact[n] * inv[n - r]) % mod);
//}
//
//ll ncr(ll n, ll r) {
//	return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
//}
//
//void sieve(ll val) {
//	memset(primes, 1, sizeof primes);
//	primes[0] = primes[1] = false;
//	for (int i = 2; i <= val; i++) {
//		if (primes[i]) {
//			for (int j = i * i; j <= val; j += i) {
//				primes[j] = 0;
//			}
//		}
//	}
//
//}



int main()
{
    MohamedMotaz;
    
    ll n, k;
    cin >> n >> k;
    
    
    cout << min(n % k, abs(k - n % k));

   
}








Measured memory_bytes: 256
let n, m = Scanf.scanf " %d %d" @@ fun a b -> a, b
let a_s = Array.init m @@ fun _ -> Scanf.scanf " %d" (+) 0
let dp = Array.make (n + 1) 0
let os = Array.make (n + 1) true
let f i v = if os.(i) then dp.(i) <- v
let _ = Array.iter (fun a -> os.(a) <- false) a_s; f 0 1; f 1 1;
  for i = 2 to n do f i @@ (dp.(i - 1) + dp.(i - 2)) mod 1000000007 done;
  Printf.printf "%d\n" dp.(n)

Measured memory_bytes: 6144
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;
ll const mod = 1e9 + 7;

ll recursive_square(ll x, ll n) {
  x %= mod;
  if (n == 0) return 1;
  if (n % 2 == 0) {
    ll t = recursive_square(x, n / 2);
    return t * t % mod;
  }
  return x * recursive_square(x, n - 1) % mod;
}

ll comb(ll n, ll k) {
  ll x = 1;
  for (ll i = n - k + 1; i <= n; i++) {
    x = x * i;
    x = x % mod;
  }
  ll y = 1;
  for (ll i = 1; i <= k; i++) {
    y = y * i;
    y = y % mod;
  }
  y = recursive_square(y, mod - 2);
  return x * y % mod;
}

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  ll all_comb = recursive_square(2, n);
  ll nCa = comb(n, a);
  ll nCb = comb(n, b);
  ll ans = (all_comb - 1 - nCa - nCb) % mod;
  if (ans < 0) ans += mod;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
class union_find{
    public:
        int n;
        vector<T> p, rank;

        union_find(int n)
            : n(n), p(n, -1), rank(n) {}

        int find(int v){
            if(p[v] == -1){
                return v;
            }
            p[v] = find(p[v]);
            return p[v];
        }

        void unite(int u, int v){
            int u_root = find(u);
            int v_root = find(v);

            if(u_root == v_root){
                return;
            }

            if(rank[u_root] < rank[v_root]){
                swap(u_root, v_root);
            }

            if(rank[u_root] == rank[v_root]){
                rank[u_root]++;
            }

            p[v_root] = u_root;
        }
};

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

    int n, m;
    cin >> n >> m;

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

    union_find<int> uf(n);
    rep(i, m){
        int x, y;
        cin >> x >> y;
        uf.unite(x, y);
    }

    if(m == n - 1){
        cout << 0 << endl;
        return 0;
    }

    if(n < 2 * (n - m - 1)){
        cout << "Impossible" << endl;
        return 0;
    }

    priority_queue<P, vector<P>, greater<P>> pq;
    vector<bool> used(n, false);
    rep(i, n){
        pq.emplace(a[i], uf.find(i));
    }

    int ans = 0;
    int remain = 2 * (n - m - 1) - (n - m);
    rep(i, n){
        int cost = pq.top().first;
        int v = pq.top().second;
        pq.pop();

        if(not used[v]){
            used[v] = true;
            ans += cost;
            continue;
        }

        if(remain > 0){
            ans += cost;
            remain--;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4852
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <limits>

using namespace std;

int main(){
  int N,K;
  scanf("%d %d", &N, &K);

  int digit=0;
  while(N>0){
    N=N/K;
    digit++;
  }

  cout << digit << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 1000000000

#define MOD 1000000007

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

void swap2(double* a, double* b)
{
	double tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int gcd(int a, int b)  //最大公約数
{
	if (a < b)
		swap(&a, &b);

	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}

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

long power(long x, int n) { //x^n 計算量O(logn)
	long ans = 1;
	while (n > 0) {
		if ((n & 1) == 1) {
			ans = ans * x;
		}
		x = x * x; //一周する度にx, x^2, x^4, x^8となる
		n >>= 1; //桁をずらす n = n >> 1
	}
	return ans;
}

int choose(int n, int k) {
	return k == 0 ? 1 : (long long)choose(n - 1, k - 1) * n % MOD * power(k, MOD - 2) % MOD;
}

void bubble_sort(int a[], int n)
{
	int i, j, tmp;

	for (i = 0; i < n; i++)
	{
		for (int k = 0; k < n; k++)
			printf("%d ", a[k]);

		for (j = n - 1; j > i; j--)
		{
			if (a[j - 1] > a[j])
			{
				tmp = a[j];
				a[j] = a[j - 1];
				a[j - 1] = tmp;
			}
		}
		printf("\n");
	}
}

void selection_sort(int a[], int n)
{
	int i, j, tmp, min, key;

	for (i = 0; i < n - 1; i++)
	{
		min = i;
		key = a[i];

		for (int k = 0; k < n; k++)
			printf("%d ", a[k]);

		for (j = i + 1; j < n; j++)
		{
			if (a[j] < a[min])
			{
				min = j;
				key = a[j];
			}
		}

		tmp = a[i];
		a[i] = a[min];
		a[min] = tmp;

		printf("\n");
	}

	for (int k = 0; k < n; k++)
		printf("%d ", a[k]);
}

void insertion_sort(int a[], int n)
{
	int i, j, tmp;

	for (i = 1; i < n; i++)
	{
		j = i;

		while (j >= 1 && a[j - 1] > a[j])
		{
			tmp = a[j];
			a[j] = a[j - 1];
			a[j - 1] = tmp;
			j--;
		}
	}
}

void shell_sort(int a[], int n)
{
	int h, i, j;

	for (h = 1; h < n / 9; h = h * 3 + 1)
		;

	for (; h > 0; h /= 3)
	{
		for (int k = 0; k < n; k++)
			printf("%d ", a[k]);

		for (i = h; i < n; i++)
		{
			j = i;
			while (j >= h && a[j - h] > a[j])
			{
				swap(&a[j - h], &a[j]);
				j -= h;
			}
		}
		printf("\n");
	}

	for (int k = 0; k < n; k++)
		printf("%d ", a[k]);
}

int partition(int a[], int l, int r)
{
	int i, j, pivot;

	i = l - 1;
	j = r;
	pivot = a[r];

	for (;;)
	{
		while (a[++i] < pivot)
			;
		while (i < j-- && pivot < a[j])
			;

		if (i >= j)
			break;

		swap(&a[i], &a[j]);
	}

	swap(&a[i], &a[r]);
	return i;
}

void quick_sort1(int a[], int l, int r)
{
	int v;

	if (l >= r)
		return;

	v = partition(a, l, r);

	quick_sort1(a, l, v - 1);
	quick_sort1(a, v + 1, r);
}

void quick_sort(int a[], int n)
{
	quick_sort1(a, 0, n - 1);
}

int keta(int a, int n)
{
	if (n == 1)
		return a % 10;

	for (int i = 0; i < n - 1; i++)
		a /= 10;

	return a % 10;
}

int main()
{
	long long int H, W;
	long long int a, b, c;

	scanf("%lld%lld%lld", &a, &b, &c);


	
	if ((4 * a * b < (c - a - b) * (c - a - b) ) && c-a-b>0)
			printf("Yes");
	else
		printf("No");

	//printf("%f", a + b + sqrtl(a * b*4));

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N =2e5+6;
const int M =1e9+7;
const double eps =1e-7;
#define go_baby_go ios::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
#define pb push_back
#define PQ priority_queue
#define pii pair<int,int>
#define vi vector<int>
int a[N],b[N];
int Int(){int x;scanf("%d",&x);return x;}
ll Lnt(){ll x;scanf("%I64d",&x);return x;}
#define Int Int()
#define Lin Lnt()
ll Bigmod(ll A,ll B,ll C)
{
     if(B==0LL)return 1LL;
     ll x=Bigmod(A,B/2LL,C);
     x=(x*x)%C;
     if(B%2==1)
     x=(x*A)%C;
     return x;
}
struct mar
{
     int i,j;
}cr[N];
bool cmp(mar a,mar b){
     if(a.i==b.i)
     return a.j<b.j;
     return a.i<b.i;
}
bool Cmp(int a,int b){return a>b;}
void print(int n){printf("%d\n",n);}
void Print(ll n){printf("%I64d\n",n);}
void debug(int n){printf("%d ",n);}
int polygon(int p,int n)
{
     int mx=INT_MIN;
     for(int i=1;i<=p;i++)
     {
          int u=0;
          for(int j=i;j<=n;j+=p)
          {
               u+=a[j];
          }
          if(n/p>2)
          mx=max(mx,u);
     }
     return mx;
}
int ispolygon(int n)
{
     int i,sqr=sqrt(n),mx=0;
     for(i=1;i<=sqr;i++)
     {
          if(n%i==0)
          {
               mx=max(mx,polygon(i,n));
               mx=max(mx,polygon(n/i,n));
          }  
     }
     return mx;
}
void get(int n)
{
     for(int i=n;i>0;i-=2)
     debug(a[i]);
     int x=0;
     if(n&1)
     {
          x=2;
     }
     else 
     x=1;
     for(int i=x;i<n;i+=2)
          debug(a[i]);
}
int main()
{
     go_baby_go;
     int n=Int,i;
     for(i=1;i<=n;i++)
     {
          a[i]=Int;
     }
     get(n);
     
}





Measured memory_bytes: 2944
#include <stdio.h>

int main(void)
{
	int W,H,x,y,r;
	
	scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);

	if(x-r>=0&&x+r<=W&&y+r<=H&&y-r>=0)
		printf("Yes\n");
	
	else
		printf("No\n");
	
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MAXSIZE 10000000;

bool comp(const pair<int,int> a, const pair<int,int> b) {

    return a.second < b.second;
}

int Dx[6] = { 0, 0, 1, 1,-1,-1};
int Dy[6] = { 1,-1, 1, 0, 0,-1};

//priority_queue<long long int,vector<long long int>, greater<long long int>> PQ;
//priority_queue<long long int> PQ1;
int main(){

  int n;
  vector<int> list;
  int ans=0;


  cin >>n;
  for(int i = 0;i<n;i++){
    int x;
    cin >>x;
    list.push_back(x);
  }

  for(int i = 1;i<n-1;i++){
    if((list[i-1] > list[i] && list[i] > list[i+1]) || (list[i-1] < list[i] && list[i] < list[i+1]))ans++;
  }
  cout <<ans<<endl;;
  return 0;
}

/*Syakutori
while(cin >>b && b)){
      ll t = 1;
      long long int ansS = 1,ansT=0;
      long long int sum = 0;

      for(ll s = 1;s < 50000000;s++){

        while(t <  50000000 && sum+Rsum[t] < b){
          sum += Rsum[t];
          t++;
        }
        if(b == sum+Rsum[t]){
          if(ansT - ansS < t-s){
            ansS = s;
            ansT = t;
          }
          cout <<ansS<<" "<<ansT-ansS + 1<<endl;
          break;
        }
        if(t == s)++t;
        else sum -= Rsum[s];
        }
    }

*/

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC135_b solver = new ABC135_b();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC135_b {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int[] p = new int[N];
            int[] p_sorted = new int[N];

            int wk = 0;
            for (int i = 0; i < N; i++) {
                //if (i == 0) {
                //    p[i] = 0;
                //    p_sorted[i] = 0;
                //} else {
                p[i] = in.nextInt();
                p_sorted[i] = p[i];
                //}
            }
            Arrays.sort(p_sorted);
            if (Arrays.equals(p, p_sorted)) {
                out.println("YES");
                return;
            }
            for (int i = 0; i < N; i++) {
                for (int j = i + 1; j < N; j++) {
                    wk = p[j];
                    p[j] = p[i];
                    p[i] = wk;

                    if (Arrays.equals(p, p_sorted)) {
                        out.println("YES");
                        return;
                    }
                    p[i] = p[j];
                    p[j] = wk;

                }
            }
            out.println("NO");
        }

    }
}



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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  vl l(n);
  REP(i,n) cin >> l[i];
  sort(l.begin(),l.end());
  //reverse(l.begin(),l.end());
  ll ans = 0;
  REP(i,n-2){
    FOR(j,i+1,n-1){
      ll ok = j;
      ll ng = n;
      while(abs(ok-ng)>1){
        ll m = (ok+ng)/2;
        if(l[m]<l[i]+l[j]) ok = m;
        else ng = m;
      }
      ans += ok-j;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#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 each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

vector<string> s;
int cnt[26];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;
    cin >> h >> w;
    s.resize(h);
    rep(i,h){
        cin >> s[i];
    }
    rep(i,h){
        rep(j,w){
            cnt[s[i][j]-'a']++;
        }
    }
    bool ans = true;
    if(h%2 == 0 && w%2 == 0){
        rep(i,26){
            if(cnt[i] % 4 != 0){
                ans = false;
                break;
            }
        }
    }else if(h%2 == 1 && w%2 == 1){
        int hoge = 0;
        int hoge2 = 0;
        int lm = h/2 + w/2;
        rep(i,26){
            if(cnt[i] % 2 == 0){
                if(cnt[i] % 4 != 0){
                    hoge2++;
                    if(hoge2 > lm){
                        ans = false;
                        break;
                    }
                }
            }else{
                hoge++;
                if(hoge > 1){
                    ans = false;
                    break;
                }
            }
        }
    }else{
        int hoge = 0;
        int lm;
        if(h % 2 == 0){
            lm = h/2;
        }else{
            lm = w/2;
        }
        rep(i,26){
            if(cnt[i] % 2 == 0){
                if(cnt[i] % 4 != 0){
                    hoge++;
                    if(hoge > lm){
                        ans = false;
                        break;
                    }
                }
            }else{
                ans = false;
                break;
            }
        }
    }
    if(ans){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
    return 0;
}


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

using namespace std;
ifstream fin("p.in");
ofstream fout("p.out");

int main()
{
    int n;
    cin>>n;
    vector< pair<int,int> >st[nmax];
    for(int  i = 0; i < n; i++){
        int ct;
        cin>>ct;
        for(int j = 1; j <= ct; j++){
            int xj,yj;
            cin>>xj>>yj;
            st[i].push_back({xj - 1,yj});
        }
    }

    long long sol_max = 0;
    for(int bits = 0; bits < (1<<n); bits++){
        int vec[nmax] = {0};
        long long sol = 0;
        for(int i = 0; i < n; i++){
            int val = (1<<i) & bits;
            if(val != 0){
                sol++;
                vec[i] = 1;
            }
        }

        int pp = 1;
        for(int i = 0; i < n; i++)
            if(vec[i] != 0){
                for(vector< pair<int,int> >::iterator j = st[i].begin(); j != st[i].end(); j++)
                    if(vec[j->first] != j->second){
                        pp = 0;
                        break;
                    }
            }
        if(pp) sol_max=max(sol_max,sol);
    }
    cout<<sol_max;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

template<typename T> using maximum_heap = std::priority_queue<T, std::vector<T>, std::less<T>>;
template<typename T> using minimum_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
std::istream& operator>>(std::istream &is, std::vector<T> &v)
{
  for (typename std::vector<T>::size_type i = 0; i < v.size(); ++i) {
    is >> v[i];
  }
  return is;
}

using namespace std;

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

  vector<int64_t> A(N);
  cin >> A;

  uint64_t S = 0;
  map<int64_t, int64_t> P;
  N_TIMES(n, N) {
    ++P[A[n]];
    S += A[n];
  }

  uint64_t Q;
  cin >> Q;

  N_TIMES(q, Q) {
    int64_t B, C;
    cin >> B >> C;

    int64_t K = P[B];
    P[C] += P[B];
    P[B] = 0;
    S += (C - B) * K;
    cout << S << endl;
  }

  return 0;
}

Measured memory_bytes: 10016
n = int(input())

hight = list(map(int, input().split()))

humi = [0,]

for i in range(1, n):
    if (hight[i] >= hight[i-1]):
        humi.append(0)
    else:
        dif = hight[i-1] - hight[i]
        humi.append(dif)
        hight[i] = hight[i] + dif

ans = sum(humi)
print(ans)


Measured memory_bytes: 32240