akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  long long N, c = 0;

  std::cin >> N;

  std::cerr << "N=" << N << std::endl;

  std::vector<long long> a;

  for (long long i = 1; i * i <= N; i ++) {
    long long j = N / i;

    a.push_back(i);
    a.push_back(j);
  }

  std::sort(ALL(a));

  a.erase(std::unique(ALL(a)), std::end(a));

  for (const auto& i : a) {
    long long n = N - i;
    
    if (n % i == 0) {
      long long x = n / i;

      if (x && N / x == i && N % x == i)
        c += x;
    }
  }

  std::cout << c << std::endl;
  
  return 0;
}


Measured memory_bytes: 18664
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    cin.tie(nullptr); ios::sync_with_stdio(false);
    Int N; cin >> N;
    Int A[5]; for (auto &a : A) cin >> a;
    Int X = *min_element(begin(A), end(A));
    cout << (N + X - 1) / X + 4 << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi >
const int N=1000010;

int main()
{
  double x,y;
  cin>>x>>y;
  cout<<x+y/2;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){ 
for (int k = 0; k < 114514; ++k){
int H, W; 
cin >> H >> W; 
  if(H == 0 && W == 0){
   break; 
  }
for (int i = 0; i < H; ++i) {
  for (int j = 0; j < W; ++j) { 
    if((i + j) % 2 == 0) cout << "#"; 
    else cout << "."; 
   }
  cout << endl; 
  }
  cout << endl; 
}
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, sum = 0;
  cin >> n;
  vd a(n);
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
    a[i] *= n;
  }
  ll ans, d = 1e18;
  rep(i, n) {
    ll nd = abs(sum - a[i]);
    if(nd < d) {
      d = nd;
      ans = i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define int long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<ll, ll> pii;
typedef vector<vector<ll>> mat;
const ll mod = 1e9+7;
const int MAXN = 1*1e5+5;
 
int32_t main() {
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	if(s[k-1] <= 'Z') s[k-1] += 32;
	cout << s << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ll n;
	cin>>n;
	ll d[n];
	for(ll i=0;i<n;i++){
		cin>>d[i];
	}
	sort(d,d+n);
	if(n%2==0){
		cout<<d[n/2]-d[n/2-1];
	}
	else cout<<"0";
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
	"math"
	"math/big"
)

func main() {
	var n, x int
	fmt.Scan(&n, &x)
	var tmp int
	fmt.Scan(&tmp)
	tmp -= x
	tmp = abs(tmp)
	g := tmp
	for i := 0; i < n - 1; i++ {
		fmt.Scan(&tmp)
		tmp -= x
		tmp = abs(tmp)
		g = gcd(g, tmp)
	}
	fmt.Println(g)
}


func gcd(m, n int) int {
	x := new(big.Int)
	y := new(big.Int)
	z := new(big.Int)
	a := new(big.Int).SetUint64(uint64(m))
	b := new(big.Int).SetUint64(uint64(n))
	return int(z.GCD(x, y, a, b).Uint64())
}

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

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

bool isOK(int &index, ll &x, vector<ll> &v){
  if(v[index] <= x) return true;
  else return false;
}

int nibutan(ll &x, vector<ll> &v){
  int ok=-1;
  int ng=(int)v.size();

  while (abs(ok-ng)>1){
    int mid = (ok+ng)/2;

    if(isOK(mid,x,v)) ok = mid;
    else ng = mid;
  }
  return ok;//max_ok_index
}

int main(){
  int n,m,k;
  cin>>n>>m>>k;
  vector<ll> ra(n+1),rb(m+1);
  ra[0]=0; rb[0]=0;
  rep(i,n){
    int a;cin>>a;
    ra[i+1]=ra[i]+a;
  }
  rep(i,m){
    int b;cin>>b;
    rb[i+1]=rb[i]+b;
  }
  int ans=0;
  rep(i,n+1){
    ll now_k=k-ra[i];
    if(now_k<0)continue;
    int j=nibutan(now_k,rb);
    ans=max(ans,i+j);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 6344
#include "stdio.h"

int main(int argc, char const *argv[]) {
  int A,B,C;
  scanf("%d%d%d",&A,&B,&C);
  int N=B/A;
  if (N>C) {
    printf("%d", C);
    return 0;
  }
  printf("%d", N);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		for(int i = 0; i < data.length(); i++) {
			if (data.charAt(i) == 'o') {
				count++;
			}
		}

		count = 700 + (100 * count);
		System.out.println(count);
	}
}

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

int main() {
  int n, a, b, c; cin >> n >> a >> b >> c;
  vector<int> bamboos(n);
  for (int i = 0; i < n; i++) cin >> bamboos.at(i);
  int answer = 4000;
  
  for (int i = 0; i < pow(2, n * 2); i++) {
    vector<int> av;
    vector<int> bv;
    vector<int> cv;
    
    for (int j = 0; j < n * 2; j = j + 2) {
      if (i & (1 << j) && i & (1 << (j + 1))) av.push_back(bamboos.at(j / 2));
      if (i & (1 << j) && !(i & (1 << (j + 1)))) bv.push_back(bamboos.at(j / 2));
      if (!(i & (1 << j)) && i & (1 << (j + 1))) cv.push_back(bamboos.at(j / 2));
    }
    
    int suma = accumulate(av.begin(), av.end(), 0);
    int sumb = accumulate(bv.begin(), bv.end(), 0);
    int sumc = accumulate(cv.begin(), cv.end(), 0);
    
    if (suma == 0 || sumb == 0 || sumc == 0) continue;
    
    int synthesis = (av.size() + bv.size() + cv.size() - 3) * 10;
    
    answer = min(answer, synthesis + max(a, suma) - min(a, suma) + max(b, sumb) - min(b, sumb) + max(c, sumc) - min(c, sumc));
    answer = min(answer, synthesis + max(a, suma) - min(a, suma) + max(b, sumc) - min(b, sumc) + max(c, sumb) - min(c, sumb));
    answer = min(answer, synthesis + max(a, sumb) - min(a, sumb) + max(b, suma) - min(b, suma) + max(c, sumc) - min(c, sumc));
    answer = min(answer, synthesis + max(a, sumb) - min(a, sumb) + max(b, sumc) - min(b, sumc) + max(c, suma) - min(c, suma));
    answer = min(answer, synthesis + max(a, sumc) - min(a, sumc) + max(b, suma) - min(b, suma) + max(b, sumb) - min(c, sumb));
    answer = min(answer, synthesis + max(a, sumc) - min(a, sumc) + max(b, sumb) - min(b, sumb) + max(c, suma) - min(c, suma));
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 256
/******************************************************************************
 
                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
 
*******************************************************************************/
 
#include <iostream>
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{   
    int n = 0, m = 0, a = 0, b = 0,x = 0 ;
    cin >> n >> m; 
    
    int array[n];
    
    for (int i = 0; i < n ; i++){ 
        array[i] = 10; 
    } 
    
 
    vector<pair<int,int>> cor;
    for(int i = 0; i < m; i ++){
        cin >> a >> b; 
        cor.push_back(make_pair(a,b));
    }
    
    for(int i = 0; i < cor.size(); i++){
        if(array[cor[i].first - 1] == 10 || array[cor[i].first - 1] == cor[i].second){
 
            array[cor[i].first - 1] = cor[i].second;
            
            
        }else{
            cout << -1;
            return 0;
        }
    }
    
    if(array[0] == 0 && n == 1){
        cout << 0; 
        return 0; 
    }
        
    
    if(array[0] == 0){
        cout << -1;
        return 0;
    }else{
        
        if(array[0] == 10 && n != 1){
            cout << 1; 
            x = 1; 
        }
            
        for(int i = x; i < n; i++){
            if(array[i] == 10){
                cout << 0;
            }else{
              cout << array[i];
            }
        }
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int prime[999999];
int sum[999999]={0};

void isprime(int n) {
    int i, k;
    for(i = 2; i <= n; i++) {
        prime[i] = 1;
    }
    for(i = 2; i*i <= n; i++) {
        if(prime[i]) {
            for(k = 2 * i; k <= n; k += i) {
                prime[k] = 0;
            }
        }
    }
    for(i = 0; i <= n; i++){
        sum[i+1]= sum[i] + prime[i];
    }
}
 
int main() {
    int n, i, count;
    isprime(999999);
    while(scanf("%d", &n) != EOF) {
        count = sum[n+1];
        printf("%d\n", count);
    }
    return 0;
}

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

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int[] arrayS = new int[n];
      int i=0;
      for (String val : br.readLine().split(" ")) {
        arrayS[i++] = Integer.parseInt(val);
      }

      MergeSort merge = new MergeSort(arrayS);
      int cnt = merge.mergeSort(0, n);

      merge.dispIntArray();
      System.out.println(cnt);
    }
  }
}

class MergeSort {

  static private final int SENTINEL = Integer.MAX_VALUE;

  private int[] target;
  private int[] bufL;
  private int[] bufR;

  public MergeSort(int[] target) {
    this.target = target;
    bufL = new int[target.length/2+2];
    bufR = new int[target.length/2+2];

  }

  public int mergeSort(int left, int right) {
    int cnt =0;

    if(left+1 < right){
      int mid = (left + right) / 2;
      cnt += mergeSort(left, mid);
      cnt += mergeSort(mid, right);
      cnt += merge(left, mid, right);
    }

    return cnt;
  }

  private int merge(int left, int mid, int right) {
    int cnt = 0;
    int n1 = mid - left;
    int n2 = right - mid;
    
    for(int i=0; i<n1; i++)
      bufL[i] = target[left+i];
    bufL[n1] = MergeSort.SENTINEL;

    for(int i=0; i<n2; i++)
      bufR[i] = target[mid+i];
    bufR[n2] = MergeSort.SENTINEL;

    for(int i=0,j=0,k=left; k<right; k++) {
      if(bufL[i] <= bufR[j])
        target[k] = bufL[i++];
      else
        target[k] = bufR[j++];
      cnt++;
    }

    return cnt;
  }

  public int[] getArray() {
    return target;
  }

  public void dispIntArray() {
    StringBuilder s = new StringBuilder();

    for (int i : target) { s.append(i).append(" "); }
    s.setLength(s.length()-1);

    System.out.println(s);
  }
}


Measured memory_bytes: 142600
s = input()
if s == "SUN":
  print (7)
elif s == "MON":
  print (6)
elif s == "TUE":
  print (5)
elif s == "WED":
  print (4)
elif s == "THU":
  print (3)
elif s == "FRI":
  print (2)
else:
  print (1)

Measured memory_bytes: 3060
// --------------
// Tejas Pandey  |
// 11 - 04 - 20  |
// Atcoder BC 162|
// --------------

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

#define mod 1000000007
#define vi vector<int>
typedef long long int ll;

int main (void)
{
  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  //cin >> t;
  while(t--){
  	//cout << "Case :" << c - t << ": ";
  	int n;
  	cin >> n;
  	ll ans = 0;
  	for(int i = 1;i <= n;i++) if((i%3) && (i%5)) ans += i;
  	cout << ans << "\n";
  }
  return 0;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <unordered_map>

int main()
{
    int H;
    std::cin >> H;

    int A[H+1] = {0};

    for (int i = 1; i <= H; ++i) {
        std::cin >> A[i];
    }

    int parent, left, right;
    for (int i = 1; i <= H; ++i) {
        parent = A[i/2];

        if (i * 2 <= H) {
            left = A[i * 2];
        } else {
            left = 0;
        }

        if ((i * 2 + 1) <= H) {
            right = A[i * 2 + 1];
        } else {
            right = 0;
        }

        std::printf("node %d: key = %d, ", i, A[i]);
        if (parent != 0) {
            std::printf("parent key = %d, ", parent);
        }

        if (left != 0) {
            std::printf("left key = %d, ", left);
        }

        if (right != 0) {
            std::printf("right key = %d, ", right);
        }

        std::printf("\n");
    }

    return 0;
}


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

using namespace std;
inline void
prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
//printf("%.12lf\n",mid);
// __builtin_popcount(int) count 1's in binary
int mod;

int mymod(int num){
  if (num< 0){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

double eps = .0000000001;

int main ()
{
  prep ();
  int n;
  cin >> n;
  cout << (n-2)*180;
  return 0;
}
// in dp problems think: up until here, intervals, or "what if there's 1, 2, 3..."
// in math problems write out equations
// also in math problems to change multiplication/division to addition/subtraction use logs, add/subtract something to make the multiplication easier (like if it's 3*f(x)+2, change it to 3*(f(x)+1)-1)
// if printint pow function, put an (int) or (long long) next to it
// if checked everything check for bugs (like sorting wrong way or not putting a break in a loop)
// if n is 10^7 try brute force if the operations are simple
// if can't do dp do brute force/greedy
// to save time don't copy maps/vectors into variables if it already exists
// only use long long if need to
// if wrong on decimal problem, check if program rounds or if you can round to a certain amt of decimals
// if decimals too, if can subtract instead of divide
// in grid traversal problems check if doing sideways or not
// if TLE try to take away loop
// in recursion looking math problems look at things from the point of view of both sides (the start and the end sections of the recursion)
// think about how many possible answers there are to the problem
// try to set the answer to the problem and see if it's possible (like w/ binary search)
// if it makes it easier use +1 indexing
// think twice when writing things down that you're going to use later
// for conversions think if you can compute them w/ only one conversion
// if the problem involves two things moving at the same time, see if you can generalise it to just one thing moving
// if nt think primes

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

int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  int m = 0, M = 0;
  for(int i = 0; i < N; ++i){
    if(A[i] < A[m]) m = i;
    if(A[i] > A[M]) M = i;
  }
  if(abs(A[m]) < abs(A[M])){
    cout << 2*N << endl;
    cout << M+1 << " " << 1 << endl;
    cout << M+1 << " " << 1 << endl;
    A[0] += 2*A[M];
    for(int i = 1; i < N; ++i){
      cout << i << " " << i+1 << endl;
      cout << i << " " << i+1 << endl;
      A[i] += A[i-1]*2;
    }
    //for(int i = 0; i < N; ++i) cerr << A[i] << " "; cerr << endl;
  }else{
    cout << 2*N << endl;
    cout << m+1 << " " << N << endl;
    cout << m+1 << " " << N << endl;
    A[N-1] += 2*A[m];
    for(int i = N; i > 1; --i){
      cout << i << " " << i-1 << endl;
      cout << i << " " << i-1 << endl;
      A[i-2] += A[i-1]*2;
    }
    //for(int i = 0; i < N; ++i) cerr << A[i] << " "; cerr << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using llong = long long;
using vi    = vector<int>;
using vvi   = vector<vi >;
using vvvi  = vector<vvi >;
using pii   = pair<int,int>;
constexpr int    INF=1e9;
constexpr double EPS=1e-9;
constexpr int    MOD=1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a){cerr<<(cnt++?' ':'>');cerr<<elem;}cerr<<endl;}

using vl   = vector<long long>;
using vvl  = vector<vl >;
using vvvl = vector<vvl >;

template<typename T>
class SegmentTree{
	using F=function<T(T,T)>;
	int n,offset;	//n:=(葉の数（2の階乗数）),offset:=(n-1).
	const T e;		//e:=(単位元).
	vector<T> node;
	const F f;		//f:=(二項演算処理).
	
	int bufsize(int n_){//木に必要なノード数を返す.
		n=1;
		while(n<n_) n<<=1;
		offset=n-1;
		return 2*n-1;
	}
	void build(int l=0,int r=-1){//木を構築する. O(N).
		if(r<0) r=n;
		l+=offset, r+=offset;
		do{
			l=(l-1)/2, r=(r-1)/2;
			for(int i=l;i<r;++i) node[i]=f(node[2*i+1],node[2*i+2]);
		}while(l>0);
	}
	
public:
	/*constructor.*/
	SegmentTree(int n_,T e_,F f_):node(bufsize(n_),e_),e(e_),f(f_){}
	SegmentTree(const vector<T> &v_,T e_,F f_):node(bufsize(v_.size()),e_),e(e_),f(f_){
		copy(ALL(v_),node.begin()+offset);//<algorithm>.
		build();
	}
		
	void init(){fill(ALL(node),e);}//初期化する.
	void update(int k,T a){//k番目の要素をaに更新する. O(log N).
		k+=offset;
		node[k]=a;
		while(k>0){
			k=(k-1)/2;//parent.
			node[k]=f(node[2*k+1],node[2*k+2]);
		}
	}
	void add(int k,T a){update(k,node[k+offset]+a);}//k番目の要素にaを加算する.
	/*[a,b)間のクエリ結果を返す. O(log N).
	（後ろの3つの引数は計算の簡単のための引数. kはノード番号,lとrはそのノードが[l,r)に対応づいているかを表す. 外からはquery(a,b,0,0,n)と呼ぶ.）*/
	T query(int a,int b,int k=0,int l=0,int r=-1){
		if(r<0) r=n;
		if(b<=l or r<=a) return e;			//[a,b)と[l,r)が交差しなければe.
		if(a<=l and r<=b) return node[k];	//[a,b)が[l,r)を完全に含んでいれば,この節点の値.
		T vl=query(a,b,2*k+1,l,(l+r)/2);
		T vr=query(a,b,2*k+2,(l+r)/2,r);
		return f(vl,vr);					//交差する場合,2つの子をクエリ処理して比較.
	}
	
	typename vector<T>::reference operator[](int i){return node[i+offset];}
};

int main(){
	llong n;
	int x,m;
	cin>>n>>x>>m;
	
	vi next(m);
	REP(i,m) next[i]=(llong)i*i%m;
	
	int p=x;
	vl v;
	vi seen(m,-1);
	for(int i=0;;++i){
		v.push_back(p);
		seen[p]=i;
		
		p=next[p];
		if(seen[p]>=0) break;
	}
	
	llong ans=0LL;
	if(n<=seen[p]){
		REP(i,n){
			ans+=x;
			x=next[x];
		}
	}else{
		using Type=llong;
		auto f=[](Type a,Type b)->Type{return a+b;};
		SegmentTree<Type> tree(v,0LL,f);
		
		ans+=tree.query(0,seen[p]);
		n-=seen[p];
		ans+=tree.query(seen[p],v.size())*(n/(v.size()-seen[p]));
		ans+=tree.query(seen[p],seen[p]+n%(v.size()-seen[p]));
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5624
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, A, B;
  cin >> N >> A >> B;
  cout << min(N * A, B) << endl;
  return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int n , a[200],sum;
main ()
{
    cin >> n;
    for(int i = 1 ;i <= n; ++i)
    {
        cin >> a[i];
        sum+=a[i];
    }
    sort(a+1,a+n+1 );
    if(sum%10!=0)
    {
        cout << sum;
        return 0 ;
    }
    for(int i = 1 ; i <= n; ++i)
    {
        if( ( sum - a[i]  ) % 10 !=0)
        {
            cout << sum-a[i];
            return 0;
        }
    }
    cout << 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

int main (void)
{
    int N, ans = 0, cnt = 1;
    scanf("%d", &N);
    int tmp = N;
    while (tmp > 9) {
        tmp /= 10;
        cnt++;
    }
    for (int i = cnt; i > 0; i--) {
        if (i == cnt)
            tmp = N - (pow(10, i-1) - 1);
        else 
            tmp = pow(10, i) - pow(10, i-1);
        if (i % 2 == 1)
            ans += tmp;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

std::vector<std::string> split(const std::string &s, const std::string &delim) {
  using string = std::string;
  std::vector<string> v;
  string::size_type pos = 0;
  while (pos != string::npos) {
    string::size_type p = s.find(delim, pos);
    if (p == string::npos) {
      v.push_back(s.substr(pos));
      break;
    }
    v.push_back(s.substr(pos, p - pos));
    pos = p + delim.size();
  }
  return v;
}

main {
  int n;
  cin >> n;
  while (n--) {
    double h, m;
    {
      string s;
      cin >> s;
      vs v = split(s, ":");
      h = stod(v[0]);
      m = stod(v[1]);
    }
    double ah = h * 30 + m / 2, am = m * 6;
    double arg = min(abs(ah - am), 360.0 - abs(ah - am));
    if (0.0 <= arg && arg < 30.0) cout << "alert" << endl;
    if (30.0 <= arg && arg < 90.0) cout << "warning" << endl;
    if (90.0 <= arg && arg <= 180.0) cout << "safe" << endl;
  }
}

Measured memory_bytes: 3108
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 9e18
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


int main(void) {
	string s;
	cin >> s;
	rep(i, s.size() - 1) {
		if (s[i] == 'A'&&s[i + 1] == 'C') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

	return 0;
}

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

int main(void)
{
	ll n, k;
	cin >> n >> k;
	if (n%k == 0) cout << 0 << endl;
	else cout << min(n, abs(k-n%k)) << endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>

using namespace std;


class Solution{

public:
    int min_to_win(const string& s){

        int res = -1;
        for(int start = 0, i = start + 1; i <= s.size(); i ++)
            if(i == s.size() || s[i] != s[start]){
                res ++;
                start = i;
                i = start;
            }
        return res;
    }
};

int main() {

    string s;
    cin >> s;
    printf("%d\n", Solution().min_to_win(s));

    return 0;
}


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

typedef long long LL;

using namespace std;

int N,L;
int A[100010]; 

int main()
{
	scanf("%d%d",&N,&L);
	for (int i=1;i<=N;i++)
	{
		scanf("%d",&A[i]);
	}
	bool ok = false;
	int last;
	for (int i=1;i<N;i++)
	{
		if (A[i] + A[i+1] >= L) 
		{
			ok = true;
			last = i;
		}
	}
	if (!ok)
		puts("Impossible");
	else
	{
		puts("Possible");
		for (int i=1;i<last;i++)printf("%d\n",i);
		for (int i=N-1;i>last;i--)printf("%d\n",i);
		printf("%d\n",last);
	}
}

Measured memory_bytes: 1152
package main

import (
        "fmt"
        "sort"
)

func solution(n int, p, q []int) int {
        i := dictionaryOrder(p)
        j := dictionaryOrder(q)
        return abs(i, j)
}

func abs(x, y int) int {
        z := x - y
        if z < 0 {
                return z * -1
        }
        return z
}

func dictionaryOrder(nums []int) int {
        var ans int
        l := len(nums)
        for i := 0; i < l; i++ {
                n := nums[i]
                arr := make([]int, len(nums)-i)
                copy(arr, nums[i:])
                a := ascNumber(arr, n) - 1
                if a == 0 {
                        ans += 0
                } else {
                        ans += a * factorical(l-i-1)
                }
        }
        ans++
        return ans
}

func ascNumber(nums []int, n int) int {
        sort.Ints(nums)
        var i int = 1
        for _, v := range nums {
                if v == n {
                        break
                }
                i++
        }
        return i
}

func factorical(n int) int {
        if n == 0 || n == 1 {
                return 1
        }
        return n * factorical(n-1)
}

func main() {

        var n int
        fmt.Scan(&n)
        p := make([]int, n)
        for i := range p {
                fmt.Scan(&p[i])
        }
        q := make([]int, n)
        for i := range q {
                fmt.Scan(&q[i])
        }
        fmt.Println(solution(n, p, q))
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
	int N;
	int W;
	cin>>N>>W;
	int w[N];
	int v[N];
	for(int i=0;i<N;i++)
	cin>>v[i]>>w[i];
	int dp[N+1][W+1];
	for(int j=0;j<=W;j++)
		dp[0][j]=0;
	for(int i=1;i<=N;i++)
		for(int j=0;j<=W;j++)
			if(j<w[i-1])
				dp[i][j]=dp[i-1][j];
			else{
				if(dp[i-1][j]>dp[i-1][j-w[i-1]]+v[i-1])
					dp[i][j]=dp[i-1][j];
				else
					dp[i][j]=dp[i-1][j-w[i-1]]+v[i-1];
			}
			cout<<dp[N][W]<<endl;
		return 0;
}

Measured memory_bytes: 7048
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

const int M=200005;
ll F[M];

void Init(){
	F[0]=1;
	for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod;
}

ll Div(ll n,ll m){
	return n*Pow(m,mod-2)%mod;
}

ll nCk(ll n,ll k){
	return Div(F[n],F[n-k]*F[k]%mod);
}

int h,w,n;
vp a;
vl dp;

int main(){
	Init();
	cin>>h>>w>>n;
	a=vp(n+2);
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		a[i]={x,y};
	}
	a[n]={1,1};
	a[n+1]={h,w};
	sort(a.begin(),a.end());
	dp=vl(n+2);
	dp[0]=mod-1;
	for(int i=0;i<n+2;i++) for(int j=0;j<i;j++){
		ll x=a[i].first-a[j].first,y=a[i].second-a[j].second;
		if(y<0) continue;
		(dp[i]+=(mod-1)*nCk(x+y,x)%mod*dp[j])%=mod;
	}
	cout<<dp[n+1]<<endl;
}

Measured memory_bytes: 1920
import Data.List
import Data.Ratio

main = do
  n <- readLn
  print $ phi n

phi :: Int -> Int
phi 1 = 1
phi n = numerator $ foldl (\acc x -> acc * (1 - (1 % x)))
                          (n % 1) $ nub $ primeFactor n

factors :: Int -> [Int]
factors n = [d | d <- [1..n], n `mod` d == 0]

isPrime :: Int -> Bool
isPrime x = null [y | y <- [2..sqr x], x `mod` y == 0]
  where sqr a = floor $ sqrt $ fromIntegral a

primeFactor :: Int -> [Int]
primeFactor n
  | isPrime n = [n]
  | otherwise = reverse $ go [] n
  where
    go res 1 = res
    go res n = go (d : res) (n `div` d)
      where d = factors n !! 1

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

int main() {
  int n;
cin>>n;
  int ans=0;
  rep(i,n+1){
  ans+=i;
  }
  cout<<ans<<endl;


}

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

int main() {
    string s;
    cin >> s;
    int zero = 0;
    int one = 0;
    for (char i : s) {
        if (i == '0') zero++;
        else one++;
    }
    cout << 2 * (min(zero, one)) << endl;
}


Measured memory_bytes: 512
H, W = map(int, input().split())

ans = H * W
s = [0] * 3

for i in range(2):
	for h in range(1, H):
		# 縦割り
		s[0] = h * W
		s[1] = (H - h) * (W // 2)
		s[2] = H * W - (s[0] + s[1])
		s.sort()
		ans = min(ans, s[2] - s[0])

		# 横割り
		s[0] = h * W
		s[1] = ((H - h) // 2) * W
		s[2] = H * W - (s[0] + s[1])
		s.sort()
		ans = min(ans, s[2] - s[0])

	# 縦と横の入れ替え
	H, W = W, H

print(ans)


Measured memory_bytes: 42732
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
using namespace std;
 
long long A[100000];
long long dp[100000][2];
int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    dp[0][0] = A[0] + A[1];
    dp[0][1] = - A[0] - A[1];
    for(int i = 1; i < N - 1; i++){
        dp[i][0] = max(dp[i - 1][0] + A[i + 1], 
                        dp[i - 1][1] + A[i + 1]);
        dp[i][1] = max(dp[i - 1][0] - 2 * A[i] - A[i + 1],
                        dp[i - 1][1] + 2 * A[i] - A[i + 1]);
    }
    cout << max(dp[N - 2][0], dp[N - 2][1]) << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn= 1e5+10;
struct Node
{
    ll a,b;
} s[maxn];
int vis[maxn];
priority_queue<ll,vector<ll>,greater<ll> >que;
bool cmp(Node a,Node b)
{
    return a.b>b.b;
}
int main()
{
    int  n,k;
    scanf("%d%d",&n,&k);
    for(int i=0; i<n; i++)
        scanf("%lld%lld",&s[i].a,&s[i].b);
     ll t=0;
    sort(s,s+n,cmp);
    ll sum=0,ans=0;
    for(int i=0; i<k; i++)
    {
        sum+=s[i].b;
        if(vis[s[i].a]==0)
        {
            vis[s[i].a]=1;
            t++;

        }
        else
            que.push(s[i].b);

    }
     ans=sum+t*t;
    for(int i=k; i<n; i++)
    {
        if(vis[s[i].a])
            continue;
       if(que.empty()||t==k)
           break;
        ll qq=que.top();
          t++;
          sum-=qq;
          sum+=s[i].b;
        que.pop();
        vis[s[i].a]=1;
    ans=max(ans,sum+t*t);
    }
        
        cout<<ans<<endl;
        return 0;
    }


Measured memory_bytes: 2812
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
struct Edge {
  int from, to, cost, rev;
  Edge(int from, int to, int cost, int rev)
      : from(from), to(to), cost(cost), rev(rev) {}
};
struct Graph {
  int V;
  vector<vector<Edge>> G;
  vector<int> used;
  Graph(int V) : V(V) {
    used = vector<int>(V, 0);
    G = vector<vector<Edge>>(V);
  }
  void add_edge(int from, int to, int cost = 1) {
    G[from].push_back(Edge(from, to, cost, G[to].size()));
    G[to].push_back(Edge(to, from, 0, G[from].size() - 1));
  }
  int augment_path(int s, int t, int f) {
    if (s == t)
      return f;
    used[s] = true;
    rep(i, 0, G[s].size()) {
      Edge &e = G[s][i];
      if (!used[e.to] && e.cost > 0) {
        int d = augment_path(e.to, t, min(f, e.cost));
        if (d > 0) {
          e.cost -= d;
          G[e.to][e.rev].cost += d;
          return d;
        }
      }
    }
    return 0;
  }
  int max_flow(int s, int t) {
    int flow = 0;
    while (1) {
      used = vector<int>(V, 0);
      int f = augment_path(s, t, INF);
      if (f == 0)
        break;
      flow += f;
    }
    return flow;
  }
};

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

  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, 0, N) { cin >> a[i]; }
  int score = 0;
  rep(i, 0, N) score += max(0ll, a[i]);

  Graph g(N + 2);
  int s = N, t = s + 1;
  rep(i, 0, N) {
    if (a[i] > 0)
      g.add_edge(i, t, a[i]);
    else if (a[i] < 0)
      g.add_edge(s, i, -a[i]);
  }
  rep(i, 0, N) rep(j, 0, N) {
    if ((j + 1) % (i + 1) == 0) {
      g.add_edge(i, j, INF);
    }
  }
  cout << score - g.max_flow(s, t) << endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
 
int main(void){
    int a, b, ans=0;

    // 入力
    std::cin >> a >> b;

    while(1){
        int temp = (int)(a/b);
        ans++;
        if(temp == 0) break;
        a = temp;
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void){
	int n;
	int i;
	int x[1000],y[1000];
	double p2,p3;
	double max=0;
	double Dp1,Dp2,Dp3;

	scanf("%d", &n);

	for(i=0; i<n; i++){
		scanf("%d",&x[i]);
	}
	for(i=0; i<n; i++){
		scanf("%d",&y[i]);
	}
	for(i=0; i<n; i++){
		Dp1 += abs(x[i]-y[i]);
		p2 += pow((x[i]-y[i]),2);
		p3 += pow(abs(x[i]-y[i]),3);
	}
	Dp2 = sqrt(p2);
	Dp3 = cbrt(p3);
	for(i=0; i<n; i++){
		if(max < abs(x[i]-y[i]))
			max = abs(x[i]-y[i]);
	}
	printf("%.6f\n%.6f\n%.6f\n%.6f\n",Dp1,Dp2,Dp3,max);

	return 0;
}

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



void solve(long long N, long long M, long long K, std::vector<long long> A, std::vector<long long> B){

    vector<ll>sum_A(N+1,0),sum_B(M+1,0);
    sum_A[0] = 0;
    sum_B[0] = 0;
    for (size_t i = 1; i <= N; i++)
    {
        sum_A[i] = sum_A[i-1] + A[i-1];
    }
    for (size_t i = 1; i <= M; i++)
    {
        sum_B[i] = sum_B[i-1] + B[i-1];
    }
    
    ll ans = 0;
    ll max_B = M;
    for (ll i = 0; i <= N; i++)
    {
        // Aの本からi冊読むとき、Bから何冊読めるか -> j
        for (ll j = max_B; j >= 0; j--)
        {
            if( sum_A[i] + sum_B[j] <= K ){
                max_B = j;
                ans = max(ans,i+j);
                break;
            }
        }
         
    }

    cout << ans << endl;
    
    
    





}

signed main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&B[i]);
    }
    solve(N, M, K, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<cstdio>
using namespace std;
long long l[90];
int main()
{
	int n;
	scanf("%d",&n);
	l[0]=2;l[1]=1;
	for(int i=2;i<=n;i++)
	{
		l[i]=l[i-1]+l[i-2];
	}
	cout<<l[n]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    float l,i,p=100000000;
    string s;cin>>s;
    for(i=0;i<s.size()-2;i++){
        l=(int(s[i])-48)*100+(int(s[i+1])-48)*10+(int(s[i+2])-48);
        if(p>abs(753.0-l)){
            p=abs(753.0-l);
        }
    }
    cout<<p<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int num = 0;
    int sum = 0;
    
    int sub_man = 0;
    int sub_gosen = 0; 

    scanf("%d",&num);
    scanf("%d",&sum);
    
    // printf("man:%d gosen:%d\n",sub_man,sub_gosen);

    for(int num_man=num; num_man>=0; num_man--){

        for(int num_gosen=0; num_gosen<=num; num_gosen++){

            if(sum > num_man*10000+num*5000 || num_man*10000>sum){
                // printf("break\n");
                break;
            }

            for(int num_sen=0; num_sen<=num; num_sen++){

                if(sum > num_man*10000+num_gosen*5000+num*1000){
                    // printf("break\n");
                    break;
                }

                // printf("sum:%d 1万:%d 5千:%d 1千:%d\n",10000*num_man+5000*num_gosen+1000*num_sen,num_man,num_gosen,num_sen);

                if(10000*num_man+5000*num_gosen+1000*num_sen == sum 
                    && num_man+num_gosen+num_sen == num){
                    printf("%d %d %d\n",num_man,num_gosen,num_sen);
                    return 0;
                }
            }
        }
     }

    printf("-1 -1 -1\n");

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
	while(true){
		int n;
		cin>>n;
		int a[4001][2]={};
		if(n==0){
			break;
		}
		int e,p,q;
		for(int w=0;w<n;w++){
			cin>>e>>p>>q;
			for(int l=0;l<w;l++){
				if(a[l][0]==e){
					a[l][1]+=p*q;
				}
			}
			a[w][0]=e;
			a[w][1]+=p*q;
		}
		bool ans=true;
		for(int m=0;m<4000;m++){
			if(a[m][1]>=1000000){
				cout<<a[m][0]<<endl;
				ans=false;
			}
		}
		if(ans){
			cout<<"NA"<<endl;
		}
	}
}


Measured memory_bytes: 3100
n,m,q = [int(i) for i in input().split()]
lr = [[int(x)-1 for x in input().split()] for i in range(m)]
pq = [[int(x)-1 for x in input().split()] for i in range(q)]
m = [[0]*501 for _ in range(501)]
for l,r in lr:
    m[0][r]+=1
    m[l+1][r]-=1
for i in range(500):
    for j in range(1,500):
        m[j][i]+=m[j-1][i]
for i in range(500):
    for j in range(1,500):
        m[i][j]+=m[i][j-1]
for p,q in pq:
    print(m[p][q])

Measured memory_bytes: 54452
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n,k;
  cin >> n >> k;
  vec a(n);
  for(ll i=0;i<n;i++) cin >> a[i];
  mat dp(n+1,vec(k+10));
  dp[0][0]=1;
  for(ll i=0;i<n;i++) {
    vec sum(k+10);
    for(ll j=0;j<=k;j++) {
      (sum[j+1]=sum[j]+dp[i][j])%=mod;
    }
    for(ll j=0;j<=k;j++) {
      dp[i+1][j]=(sum[j+1]-sum[max(0LL,j-a[i])]+mod)%mod;
    }
  }
  cout << dp[n][k] << endl;
}

Measured memory_bytes: 80256
#include <algorithm>
#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 n, m, x;
ll const MAX_MONEY = 9999999;
ll MEMO[13][MAX_MONEY];

ll solve(int book_cnt, ll money, vector<ll> U, set<ll> R, vector<ll> &C,
         vector<vector<ll>> &A) {
  if (MEMO[book_cnt][money] != 0) return MEMO[book_cnt][money];
  bool flag = true;
  for (int i = 0; i < m; i++) {
    if (U[i] < x) {
      flag = false;
      break;
    }
  }
  if (flag) return money;
  ll min_m = MAX_MONEY;
  for (int i = 0; i < n; i++) {
    if (R.find(i) != R.end()) continue;
    set<ll> new_R = R;
    new_R.insert(i);
    ll new_m = money + C[i];
    vector<ll> new_U = U;
    for (int j = 0; j < m; j++) new_U[j] += A[i][j];
    min_m = min(min_m, solve(book_cnt + 1, new_m, new_U, new_R, C, A));
  }
  MEMO[book_cnt][money] = min_m;
  return min_m;
}

int main() {
  cin >> n >> m >> x;
  vector<ll> C(n);
  vector<vector<ll>> A(n, vector<ll>(m, 0));
  for (int i = 0; i < n; i++) {
    cin >> C[i];
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }
  ll min_m = INF;
  for (int i = 0; i < n; i++) {
    ll money = C[i];
    vector<ll> U(m, 0);
    for (int j = 0; j < m; j++) U[j] += A[i][j];
    set<ll> R;
    R.insert(i);
    min_m = min(min_m, solve(1, money, U, R, C, A));
  }
  ll ans = min_m;
  if (min_m == MAX_MONEY) ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 12172
#include <bits/stdc++.h>
#define eb emplace_back
using namespace std;

const int MAXN = 100055;

vector<int> G[MAXN], RG[MAXN];
queue<int> PQ;

int A[MAXN], dp[MAXN];

int N, M;

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

	cin >> N >> M;
	for(int i = 0, a, b; i < M; i++) {
		cin >> a >> b;
		G[a].eb(b);
		RG[b].eb(a);
		A[a]++;
	}

	for(int i = 1; i <= N; i++) if(!A[i]) PQ.push(i);
	for(int i; !PQ.empty();) {
		i = PQ.front(); PQ.pop();
		for(int v : G[i]) {
			int t = dp[v] + 1;
			if(dp[i] < t) dp[i] = t;
		}
		for(int v : RG[i]) if(!--A[v])
			PQ.push(v);
	}

	cout << *max_element(dp+1, dp+N+1) << endl;
	return 0;
}

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

int remi(int cost) {
  int ans = 0;
  ans += cost/500;
  cost %= 500;
  ans += cost/100;
  cost %= 100;
  ans += cost/50;
  cost %= 50;
  ans += cost/10;
  return ans;
}

int main() {
  int coin[4], use[4], cost, f=0;
  int ccoin[4] = { 10, 50, 100, 500 };
  while(cin>>cost, cost) {
    if(f) cout<<endl;
    cin>>coin[0]>>coin[1]>>coin[2]>>coin[3];
    int ans = 1000000;
    use[0] = use[1] = use[2] = use[3] = 0;
    int sum = coin[0]+coin[1]+coin[2]+coin[3];
    for(int i=0; i<=coin[0]; ++i) {
      for(int j=0; j<=coin[1]; ++j) {
	for(int k=0; k<=coin[2]; ++k) {
	  for(int l=0; l<=coin[3]; ++l) {
	    int ca = i*10+j*50+k*100+l*500;
	    if(ca < cost) continue;
	    int ta = sum-i-j-k-l+remi(ca-cost);
	    if(ans > ta) {
	      use[0] = i,use[1] = j,use[2] = k,use[3] = l;
	      ans = ta;
	    }
	  }
	}
      }
    }
    for(int i=0; i<4; ++i)
      if(use[i]) cout<<ccoin[i]<<" "<<use[i]<<endl;
    f++;
  }
}

Measured memory_bytes: 864
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node
{
	int p,left,right;
};
struct Node T[MAX];
int n;

void preParse(int u)
{
	if(u==NIL)
	{
		return;
	}
	printf(" %d",u);
	preParse(T[u].left);
	preParse(T[u].right);
}

void inParse(int u)
{
	if(u==NIL)
	{
		return;
	}
	inParse(T[u].left);
	printf(" %d",u);
	inParse(T[u].right);
}

void postParse(int u)
{
	if(u==NIL)
	{
		return;
	}
	postParse(T[u].left);
	postParse(T[u].right);
	printf(" %d", u);
}

int main()
{
	int i,v,left,right,root;

	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		T[i].p=NIL;
	}

	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&v,&left,&right);
		T[v].left=left;
		T[v].right=right;
		if(left!=NIL)T[left].p=v;
		if(right!=NIL)T[right].p=v;
	}

	for(i=0;i<n;i++)
	{
		if(T[i].p == NIL)
		{
			root=i;
		}
	}

	printf("Preorder\n");
	preParse(root);
	printf("\n");
	printf("Inorder\n");
	inParse(root);
	printf("\n");
	printf("Postorder\n");
	postParse(root);
	printf("\n");

	return 0;
}


Measured memory_bytes: 2760
#include<iostream>
using namespace std;
int abs(int i){
    if(i>=0){
        return i;
    }
    else{
        return (-1*i);
    }
}
int main(){
    int n,m;
    cin >> n >> m;
    int A[n][m]={};
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>A[i][j];
        }
    }
    int w=0,min=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            w=0;
            for(int a=0;a<n;a++){
                for(int b=0;b<m;b++){
                    if(abs(i-a)<=abs(j-b)){
                        w+=abs(i-a)*A[a][b];
                    }
                    else if(abs(i-a)>abs(j-b)){
                        w+=abs(j-b)*A[a][b];
                    }
                }
            }
            if(i==0&&j==0){
                min=w;
            }
            else if(w<min){
                min=w;
            }
        }
    }
    cout<<min<<endl;
    return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int i,x;
	
	for(i=1;;i++){
		x=0;
		cin>>x;
		if(x==0)break;
		
		cout<<"Case "<<i<<": "<<x<<endl;
	}
		
	return 0;
}


Measured memory_bytes: 3080
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;



int dp[100001];

int lgpath(map<int ,vector<int> >&g,int m,int n,int node)
{
if(dp[node]!=-1)
{
	return(dp[node]);
}	
else
{
	int ans=-1;
	for(auto nbr:g[node])
	{
		ans=max(ans,lgpath(g,m,n,nbr));
	}
	if(ans==-1)
	{
		return(dp[node]=0);
	}
	return(dp[node]=ans+1);
}
}
int main()
{
	int n,m,x,y,i;
	cin>>n>>m;
	map<int ,vector<int> >g;
	for(i=0;i<=100000;i++)
	{
		dp[i]=-1;
	}
	for(i=0;i<m;i++)
	{
		cin>>x>>y;
		g[x].push_back(y);
	}
	int ans=-1;
	for(i=1;i<=n;i++)
	{
		ans=max(ans,lgpath(g,m,n,i));
	}
	cout<<ans<<"\n";
}

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

#define MAX(a,b) (a > b) ? a : b
#define MIN(a,b) (a < b) ? a : b
const int inf = 1000000000; // 10^9

int main(){
   double a,b;scanf("%lf%lf",&a,&b);
   if(a > b)printf("GREATER\n");
   else if(a < b)printf("LESS\n");
   else printf("EQUAL\n");
   return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define ll long long 
const int MAX=1e9+7;
const int mod=1e9+7;


int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	string s;
	cin>>s;
	int sum=0;char c=s[0];
	for(int i=1;i<s.size();i++)
	{
		if(c!=s[i])
		sum++;
	}
	if(sum>0)
	cout<<"Yes";
	else cout<<"No";
	
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <numeric>

int main()
{
  long long n, k;
  scanf("%lld%lld", &n, &k);
  long long a[50];
  for (long long i = 0; i < n; ++i)
  {
    scanf("%lld", a + i);
  }
  long long je[50];
  long long ans = 0;
  for (long long l = 0; l <= n; ++l)
  {
    for (long long r = 0; r <= n; ++r)
    {
      if (l + r > n || l + r > k) continue;
      memcpy(je, a, sizeof(long long) * l);
      memcpy(je + l, a + n - r, sizeof(long long) * r);
      std::sort(je, je + l + r);
      long long *p = je;
      for (long long i = k - (l + r); i > 0 && p < je + l + r; --i)
      {
        if (*p < 0) ++p;
        else break;
      }
      ans = std::max(ans, std::accumulate(p, je + l + r, 0LL));
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 128