akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

long long int X; // the x-coordinate on which Takahashi is
long long int K; // # of moves
long long int D; // the distance of one move


int main() {

    std::cin >> X;
    std::cin >> K;
    std::cin >> D;
    std::cerr << "X = " << X << std::endl;
    std::cerr << "K = " << K << std::endl;
    std::cerr << "D = " << D << std::endl;

    long long int pos = std::abs(X);
    long long int mov = K;

    const long long int n = pos / D;
    std::cerr << "n = " << n << std::endl;

    if (K <= n) {
        pos -= K * D;
        std::cout << pos << std::endl;
        return 0;
    }

    pos -= n * D;
    mov -= n;
    std::cerr << "pos = " << pos << std::endl;
    std::cerr << "mov = " << mov << std::endl;

    const long long int posCasePositive = pos;
    const long long int posCaseNegative = mov > 0 ? pos - D : pos;
    std::cerr << "cP = " << posCasePositive << std::endl;
    std::cerr << "cN = " << posCaseNegative << std::endl;
    const long long int posCaseFinal = (mov % 2 == 0) ? posCasePositive : posCaseNegative;

    std::cout << std::abs(posCaseFinal) << std::endl;

    return 0;

}


Measured memory_bytes: 3612
#include <iostream>

using namespace std;

int main()
{
 char s ;
 cin>> s ;
 if (s =='a')
    cout << "vowel" ;
 else if (s == 'e')
    cout << "vowel" ;
 else if (s == 'i')
    cout << "vowel" ;
 else if (s =='o')
    cout << "vowel";
 else if (s =='u')
    cout<< "vowel";
 else
    cout << "consonant" ;
  return 0 ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
                    
                    
int main(){
    int k;
    string s;
    cin >> k >> s;

    if(k >= s.size()){
        cout << s << endl;
    } else {
        cout << s.substr(0, k) + "..." << endl;
    }

    return 0;
            
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {   
    string s;
    cin >> s;
    int n = s.size();
    long long int res = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            long long int r = stoll(string(s.begin() + i, s.begin() + j + 1));
            if (i > 0) {
                r *= (1 << (i - 1));
            }
            if (j < n - 1) {
                r *= (1 << (n - j - 2));
            }
            res += r;
        }
    }
    cout << res << endl;
}




Measured memory_bytes: 3624
#include<bits/stdc++.h>
  #define f(i,a,b) for(int i=a;i<b;i++)
  #define ll long long
  #define vll vector<long long>
  #define mll map<ll,ll>
  #define pll pair<long long,long long>
  #define pb(x) push_back(x)
  #define F first
  #define S second
  #define print(v) for(auto it:v)cout<<it<<" "
  #define mod 1000000007   //10^9 +7
  #define sorty(v) sort(v.begin(),v.end())
  #define it(v) v.begin(),v.end()
using namespace std;  

int main() {
  string s,rt="",lt="";
  char ch;
  cin>>s;
  ll q,hold,cont=0,p,a=1;
  cin>>q;
  while(q--){
    cin>>hold;
    if(hold==1){
      cont=(cont+1)%2;
      a=!a;
    }  
    else{
      cin>>p>>ch;
      if((p+cont)%2==1)
      {
         lt=ch+lt;
      }
      else
      {
         rt=rt+ch;
      }
    } 
  }
  cont=cont%2;
  if(cont==1){
    reverse(s.begin(),s.end());
    reverse(rt.begin(),rt.end());
    reverse(lt.begin(),lt.end());
    s=rt+s+lt;
  }  
  else s=lt+s+rt;
  cout<<s;


	return 0;
}

Measured memory_bytes: 1512
#include <iostream>

using namespace std;

int main(){
	long long X;
	cin >> X;

	for(long long A = -118; A <= 119; A++){
		for(long long B = -119; B <= 118; B++){
			if (A*A*A*A*A - B*B*B*B*B == X){
				cout << A << " " << B << endl;
				return 0;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 3564
using System;

class Program
{
    static void Main()
    {
        string str = Console.ReadLine();
        int slength = str.Length;
        string[] convert = new string[slength];


        for (int i = 0; i < slength; i++)
        {
            char chacha = str[i];

            if (char.IsUpper(chacha))
            {
                string s = chacha.ToString();
                convert[i] = s.ToLower();
            }

            else
            {
                string s = chacha.ToString();
                convert[i] = s.ToUpper();
            }

            Console.Write("{0}", convert[i]);
        }
        Console.WriteLine();

      
    }
}

Measured memory_bytes: 9356
import java.util.*;
import java.io.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[][] a = new int[n][];
    for(int i = 0; i<n; i++) {
        a[i] = new int[]{sc.nextInt(), sc.nextInt(), sc.nextInt()};
    }
    for(int i = 1; i<n; i++) {
        a[i][0]+=Math.max(a[i-1][1], a[i-1][2]);
        a[i][1]+=Math.max(a[i-1][0], a[i-1][2]);
        a[i][2]+=Math.max(a[i-1][0], a[i-1][1]);
    }
    System.out.println(Math.max(a[n-1][0], Math.max(a[n-1][2], a[n-1][1])));
  }
}

Measured memory_bytes: 94604
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  vi a(5);
  int mn = 100;
  rep(i, 5){
    cin >> a[i];
    if(a[i] % 10 != 0){
      mn = min(mn, a[i] % 10);
      a[i] += 10 - (a[i] % 10);
    }
  }
  cout << a[0] + a[1] + a[2] + a[3] + a[4] - ((mn == 100) ? 0: (10 - mn)) << endl;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	vector<vector<pair<int,int>>> S(1001,vector<pair<int,int>>(1001,make_pair(0,0)));
	vector<vector<int>> A(1002,vector<int>(1002,0));
	LOOP(N){
		int LX=in(),LY=in(),RX=in(),RY=in();
		S[LY][LX].first++;
		S[LY][RX].second++;
		S[RY][LX].second++;
		S[RY][RX].first++;
	}

	int msum=0;
	REP(i,1001){
		REP(j,1001){
			A[i+1][j+1]+=A[i+1][j]+S[i][j].first-S[i][j].second;
			msum = max(msum,A[i+1][j+1]);
		}
	}

	REP(j,1002){
		REP(i,1001){
			A[i+1][j]+=A[i][j];
			msum = max(msum,A[i+1][j]);
		}
	}

	out(msum);
	return 0;
}


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

int main() {
    int n; cin >> n;
    int sum = 0;
    vector<int>v(n);
    for(int i = 0; i < n; i++){
        cin>>v[i];
    }
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            sum+=v[i]*v[j];
        }
    }
    cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI1 3.14159265358979311599796346854418516159057617187500

typedef long long int ll;

int main() 
{ 
    FIO
    ll t;
    t=1;

    while(t--)
    {
        ll n,m;
        cin >> n;

        ll a[n+1]={0};
        for(int i=0;i<n-1;i++)
        {
            ll x;
            cin >> x;
            a[x]++;
        }

        for(int i=1;i<=n;i++)
            cout << a[i] << endl;

    }
    return 0; 
} 


Measured memory_bytes: 5212
#include "bits/stdc++.h"
#define   LF      '\n'
#define   ALL(x)  x.begin(), x.end()
#define   iostreamBooster()  do{cin.tie(nullptr);ios::sync_with_stdio(false);}while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f'3f3f3f3fLL;


signed main()
{
  int N, K;
  cin >> N >> K;
  int cnt = 0;
  for (int i = 1; i <= N; i += 2) {
    ++cnt;
  }

  if (cnt >= K) {
    puts("YES");
  } else {
    puts("NO");
  }
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m;
const int maxn=190;
const int maxc=19;
int a[maxn][maxn],dp[maxn][maxn][maxn][20],pref[maxn][maxn];
int get(int u,int d,int l,int r){
    return pref[d][r]-pref[u-1][r]-pref[d][l-1]+pref[u-1][l-1];
}
bool monotone(int u,int l,int d,int r){
    int pom=get(u,d,l,r);
    int surface=(d-u+1)*(r-l+1);

    if(pom==0 || pom==surface)return true;
    else return false;
}
int main(){

    scanf("%d %d",&n,&m);

    for(int i=1;i<=n;i++){
        string s;
        cin>>s;
        for(int j=1;j<=m;j++){
            a[i][j]=s[j-1]=='#'?1:0;
            pref[i][j]=pref[i-1][j]+pref[i][j-1]-pref[i-1][j-1]+a[i][j];
        }
    }
    for(int i=0;i<=n+1;i++){
        a[i][0]=2;
        a[i][m+1]=2;
    }
    for(int i=0;i<=m+1;i++){
        a[0][i]=2;
        a[n+1][i]=2;
    }

    for(int i=n;i>=1;i--){
        for(int l=1;l<=m;l++){
            for(int r=l;r<=m;r++){

                if(i==n){
                    if(monotone(i,l,i,r))dp[l][r][i][0]=i;
                    else dp[l][r][i][0]=i-1;
                }
                else if(monotone(i,l,i+1,r)){
                    dp[l][r][i][0]=dp[l][r][i+1][0];
                }
                else if(monotone(i,l,i,r))dp[l][r][i][0]=i;
                else dp[l][r][i][0]=i-1;

            }
        }
    }


    if(dp[1][m][1][0]==n){
        printf("0\n");
        return 0;
    }

    for(int c=1;c<=maxc;c++){

        for(int l=1;l<=m;l++){
            for(int r=l;r<=m;r++){

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

                    int pom=dp[l][r][i][c-1]+1;
                    if(pom>n)dp[l][r][i][c]=n;
                    else dp[l][r][i][c]=dp[l][r][pom][c-1];

                }
            }
        }


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

            for(int l=1;l<=m;l++){
                int ptr=l;
                int ptr2=l;

                for(int r=l+1;r<=m;r++){

                    while(ptr<r-1 && dp[l][ptr][i][c-1]>dp[ptr+1][r][i][c-1])ptr++;
                    while(ptr2<r-1 && dp[l][ptr2][i][c-1]>=dp[ptr2+1][r][i][c-1])ptr2++;

                    dp[l][r][i][c]=max(dp[l][r][i][c],min(dp[l][ptr][i][c-1],dp[ptr+1][r][i][c-1]));
                    if(ptr>l)dp[l][r][i][c]=max(dp[l][r][i][c],min(dp[l][ptr-1][i][c-1],dp[ptr][r][i][c-1]));
                    if(ptr<r-1)dp[l][r][i][c]=max(dp[l][r][i][c],min(dp[l][ptr+1][i][c-1],dp[ptr+2][r][i][c-1]));

                    dp[l][r][i][c]=max(dp[l][r][i][c],min(dp[l][ptr2][i][c-1],dp[ptr2+1][r][i][c-1]));
                    if(ptr2>l)dp[l][r][i][c]=max(dp[l][r][i][c],min(dp[l][ptr2-1][i][c-1],dp[ptr2][r][i][c-1]));
                    if(ptr2<r-1)dp[l][r][i][c]=max(dp[l][r][i][c],min(dp[l][ptr2+1][i][c-1],dp[ptr2+2][r][i][c-1]));

               ///VOLIM TE LJUBAVI!!!
               ///VOLIM I JA TEBE!!! <3
                }

            }

        }

        if(dp[1][m][1][c]==n){
            printf("%d\n",c);
            break;
        }
    }


return 0;
}


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

int a,b;
int path[4];

int main() {
  for (int i=0;i<3;i++){
    path[i] = 0;
  }

  for (int i =0; i<3;i++){
    cin >> a >> b;
    path[a-1] += 1;
    path[b-1] += 1;
  }

  int key = 1;
  for (int i=0;i<3;i++){
    key *= path[i];
  }

  if (key==4){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>

using namespace std;


int main(int argc, char **argv) {
    int N, M; // 1 ... 100
    cin >> N >> M;

    vector<int> votes;
    int totalVotes = 0;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        votes.push_back(a);
        totalVotes += a;
    }

    double threshold = 1.0 / (4.0 * M) * totalVotes;

    int count = 0;
    for (auto a : votes) {
        if (a >= threshold)
            count++;
    }

    cout << (count >= M ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
import math
import bisect
import numpy as np
from collections import defaultdict, deque, Counter
from operator import itemgetter
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")


def main():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    c = Counter(A)
    l = [i for i in c.values()]
    l.sort()
    total = len(l)
    i = total - k
    ans = sum(l[:i])
    print(max(ans, 0))


if __name__ == '__main__':
    main()

Measured memory_bytes: 41680
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.BufferUnderflowException;

public class Main {

  public static void main(String[] args) {
    
    new Main().run();
  }

  private void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      final int MAX_INPUT_SIZE = 2_000_000;
      PriorityQueue queue = new PriorityQueue(MAX_INPUT_SIZE);
      boolean isContinue = true;
      String[] order;
      StringBuilder buf = new StringBuilder(MAX_INPUT_SIZE*5);

      while(isContinue) {
        order = br.readLine().split(" ");

        switch( order[0] ) {
          case "insert" :
            queue.insert(Integer.parseInt(order[1]));
            break;
          case "extract" :
            buf.append( queue.extract() ).append("\n");
            break;
          case "end" :
            buf.setLength(buf.length()-1);
            isContinue = false;
            break;
          default :
        }
      }

      System.out.println(buf);

    } catch(IOException e) {
      System.out.println("IOException!");
    } catch(ArrayIndexOutOfBoundsException e) {
      System.out.println("heap index out of bounds!");
    } catch(BufferUnderflowException e) {
      System.out.println("heap underflow!");
    } catch(IllegalArgumentException e) {
      System.out.println("new key is smaler than current key!");
    }
  }
}

class PriorityQueue {

  int[] heap;
  int tail;

  public PriorityQueue(int size) {
    heap = new int[size+1];
    tail = 0;
  }

  public void insert(int key) {
    heap[++tail] = Integer.MIN_VALUE;
    heapIncreaseKey(tail, key);
  }
  public int extract() {
    return heapExtractMax();
  }

  private void heapIncreaseKey(int id, int key) {
    if( key < heap[id] ) throw new IllegalArgumentException();

    int t;
    heap[id] = key;
    while( (id > 1) && (heap[parent(id)] < heap[id]) ){
      t = heap[id]; heap[id] = heap[parent(id)]; heap[parent(id)] = t;
      id = parent(id);
    }
  }
  private int heapExtractMax() {
    if(tail < 1) throw new BufferUnderflowException();

    int max = heap[1];
    heap[1] = heap[tail--];
    maxHeapify(1);

    return max;
  }
  private void maxHeapify(int id) {
    int t,left,right,largest;
    left  = nodeLeft(id);
    right = nodeRight(id);

    if( (left <= tail) && (heap[left] > heap[id]) )
      largest = left;
    else
      largest = id;
    if( (right <= tail) && (heap[right] > heap[largest]) )
      largest = right;

    if( largest != id ) {
      t = heap[id]; heap[id] = heap[largest]; heap[largest] = t;

      maxHeapify(largest);
    }
  }
  private int parent(int id) {
    return id/2;
  }
  private int nodeLeft(int id) {
    return id*2;
  }
  private int nodeRight(int id) {
    return id*2+1;
  }
}


Measured memory_bytes: 186956
#include<iostream>
#include<cstdio>
using namespace std;
char c;
bool check()
{
    return c=='a'||c=='i'||c=='u'||c=='e'||c=='o';
}
void solve()
{
    if(check())puts("vowel");
    else puts("consonant");
    return ;
}
main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin>>c;
    solve();
    return 0;
}

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


int main() {
  int n, m;
  cin >> n >> m;
  vector<tuple<int,int,int>> a(m+1);
  for(int i=1; i<=m; i++) {
    int p, y;
    cin >> p >> y;
    a[i]=make_tuple(p,y,i);
  }
  sort(rng(a));
  for(int i=1; i<=m; i++) {
    if(get<0>(a[i-1])!=get<0>(a[i])) {
      get<1>(a[i])=1;
    }
    else get<1>(a[i])=get<1>(a[i-1])+1;
  }
  for(int i=1; i<=m; i++) {
    int x=get<0>(a[i]), y=get<1>(a[i]), z=get<2>(a[i]);
    get<0>(a[i])=z;
    get<1>(a[i])=x;
    get<2>(a[i])=y;
  }
  sort(rng(a));
  for(int i=1; i<=m; i++) printf("%06d%06d\n", get<1>(a[i]), get<2>(a[i]));
  return 0;
}

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

void print_vec(vector<int> vec)
{
  cout << "[";
  for (int i = 0; i < vec.size(); i++)
  {
    if (i)
    {
      cout << ", ";
    }
    cout << vec.at(i);
  }
  cout << "]...size: " << vec.size() << endl;
}

int main()
{
  vector<char> suits = {'S', 'H', 'C', 'D'};
  vector<vector<int>> vec(4, vector<int>(13));

  int n;
  cin >> n;

  rep(i, n)
  {
    char suit;
    int rank;
    cin >> suit >> rank;

    rep(j, 4)
    {
      if (suits.at(j) == suit)
      {
        vec.at(j).at(rank - 1) = 1;
      }
    }
  }

  rep(i, 4)
  {
    rep(j, 13)
    {
      if (!vec.at(i).at(j))
      {
        printf("%c %d\n", suits.at(i), j + 1);
      }
    }
  }
}



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

int main() {

  string S, T, U;
  int A, B;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  
  if (U == S) {
  	A--;
  }
  if (U == T) {
  	B--;
  }
  
  cout << A << " "<< B << endl; 

  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);
		while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			if( a == 0 && b == 0 ) break;
			if( a > b){a^=b;b^=a;a^=b;}
			System.out.println(a+" "+b);
		}
	}
}



Measured memory_bytes: 36288
#include<bits/stdc++.h>
using namespace std;
int main(){
    int H,W;cin>>H>>W;
    vector<vector<char>> data(H,vector<char>(W));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>data.at(i).at(j);
        }
    }
    
    vector<vector<int>> ans(H,vector<int>(W));
    
  int count;
    //左にいくつ
    for(int i=0;i<H;i++){
        count=0;
        for(int j=0;j<W;j++){
            if(data.at(i).at(j)=='#'){
                count=0;
                continue;
            }
            else{
                count++;
                ans.at(i).at(j)+=count;
            }
        }
    }
  
    //右にいくつ
    for(int i=0;i<H;i++){
        count=0;
        for(int j=W-1;j>=0;j--){
            if(data.at(i).at(j)=='#'){
                count=0;
                continue;
            }
            else{
                count++;
                ans.at(i).at(j)+=count;
            }
        }
    }
  
    //下にいくつ
    for(int i=0;i<W;i++){
        count=0;
        for(int j=0;j<H;j++){
            if(data.at(j).at(i)=='#'){
                count=0;
                continue;
            }
            else{
                count++;
                ans.at(j).at(i)+=count;
            }
        }
    }
  
    //上にいくつ
    for(int i=0;i<W;i++){
        count=0;
        for(int j=H-1;j>=0;j--){
            if(data.at(j).at(i)=='#'){
                count=0;
                continue;
            }
            else{
                count++;
                ans.at(j).at(i)+=count;
            }
        }
    }
  
    int sum=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            sum=max(sum,ans.at(i).at(j));
        }
    }
    cout<<sum-3<<endl;
}

Measured memory_bytes: 22016
#include <iostream>
#include <queue>
#include <vector>

struct Edge {
  int dst;
  long long cost;
  Edge() {}
  Edge(int x, long long y) : dst(x), cost(y) {}
};

std::vector<long long> dijkstra(int sv, std::vector<std::vector<Edge>> &G) {
  const long long LINF = 1000000000000000018LL;

  int n = (int)G.size();
  std::vector<long long> dist(n, LINF);
  dist[sv] = 0;

  typedef std::pair<long long, int> PLI;
  std::priority_queue<PLI, std::vector<PLI>, std::greater<PLI>> que;

  que.push(std::make_pair(0LL, sv));

  while (!que.empty()) {
    PLI now = que.top();
    que.pop();
    long long cur_d = now.first;
    long long cur_v = now.second;

    if (dist[cur_v] < cur_d) {
      continue;
    }

    for (int i = 0; i < (int)G[cur_v].size(); i++) {
      int next_v = G[cur_v][i].dst;
      long long cost = G[cur_v][i].cost;
      if (dist[cur_v] + cost < dist[next_v]) {
        dist[next_v] = dist[cur_v] + cost;
        que.push(std::make_pair(dist[next_v], next_v));
      }
    }
  }
  return dist;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<std::vector<Edge>> g(n);
  for (int i = 0; i < n; i++) {
    int u;
    std::cin >> u;
    int k;
    std::cin >> k;
    while (k--) {
      int v, c;
      std::cin >> v >> c;
      g[u].push_back(Edge(v, c));
    }
  }

  std::vector<long long> dist = dijkstra(0, g);
  for (int i = 0; i < n; i++) {
    std::cout << i << " " << dist[i] << std::endl;
  }

  return 0;
}


Measured memory_bytes: 3208
#include <stdio.h>

int main(void)
{
	int a,b;
	
	scanf("%d %d",&a,&b);
	
	if(a > b){
		printf("a > b\n");
	}
	else if(a < b){
		printf("a < b\n");
	}
	else{
		printf("a == b\n");
	}
	
	return 0;
}

Measured memory_bytes: 580
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>   
#include <stdio.h>    
 
using namespace std;
     
#define F first
#define S second
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 123;
const ll inf = (ll)3e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n;
bool ok;
ll a[N], sum;
vector <pii> v;

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                    

inline void Solve () {
   cin >> n;
   for (int i = 1; i <= n; i ++) {
      cin >> a[i]; 
      v.pb ({abs (a[i]), i});
      sum += abs (a[i]);
      if (a[i] < 0) ok ^= 1;
   }
   sort (all (v));
   if (ok) sum -= 2ll * v[0].F;
   cout << sum;
   
}                                     

int main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
// cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}


Measured memory_bytes: 1912
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FSP(x) fixed << setprecision(x)
using namespace std;
using ll = long long;
constexpr ll INF = LLONG_MAX;
constexpr long double PI = acosl(-1);
void Yes() {cout << "Yes\n";}
void No() {cout << "No\n";}
void YES() {cout << "YES\n";}
void NO() {cout << "NO\n";}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//constexpr ll P = 1e9 + 7;
	//constexpr ll P = 998244353;

	ll x, k, d;
	cin >> x >> k >> d;
	if (x < 0) x *= -1;
	if (x / d >= k) cout << x - k * d << endl;
	else {
		k -= x / d;
		if (k % 2 == 0) cout << x % d << endl;
		else cout << abs((ll)(x % d) - d) << endl;
	}
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<ll> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){ a=min(a,b);}
template <class T> void amax(T& a,T b){ a=max(a,b);}


int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n[4];
	rep(i,4) cin >>n[i];
	bool ok=false, ng=false;
	rep(i,4) if(n[i]==1) ok=true;
	if(!ok) ng=true;
	ok=false;
	rep(i,4) if(n[i]==9) ok=true;
	if(!ok) ng=true;
	ok=false;
	rep(i,4) if(n[i]==7) ok=true;
	if(!ok) ng=true;
	ok=false;
	rep(i,4) if(n[i]==4) ok=true;
	if(!ok) ng=true;
	
	
	cout << (ng? "NO":"YES") <<"\n";
	return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
ll a,b,c,d;
ll pos=1;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>a>>b>>c>>d;
	while(1){
		if(pos&1)c-=b;
		else a-=d;
//		cout<<a<<' '<<b<<"   "<<c<<' '<<d<<'\n';
		if(a<=0){
			cout<<"No";
			return 0;
		}
		if(c<=0){
			cout<<"Yes";
			return 0;
		}
		pos++;
	}
	return 0;
}


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

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

vector<int> c(26);
vector<vector<int>> s(365 ,vector<int>(26));
vector<vector<int>> last(365 ,vector<int>(26));

int culc(int d){
    int ret;
    int maxv=0;
    rep(j,26)
    if(s[d][j]+c[j]*(d+1-last[d][j])>maxv){
        maxv=s[d][j]+c[j]*(d+1-last[d][j]);
        ret=j+1;
    }
    return ret;
}

int main(){
    int D;
    cin>>D;
    rep(i,26){ 
        cin>>c[i];
    }
    rep(d,D) rep(j,26) cin>>s[d][j];
    int t;
    int v=0;
    vector<int> kaisai_bi(26);
    int ans=18398+s[1][16];
    rep(j,26){
        if(j==16)continue;
        else if(j==0)ans-=c[j]*(2-1);
        else ans-=c[j]*(2-0);
    }
    rep(d,D) {
//        cin>>t;
        t=culc(d);
        cout<<t<<endl;
        t--;
        v+=s[d][t];
        kaisai_bi[t]=d+1;
        rep(j,26) last[d][j]=kaisai_bi[j];
        rep(j,26){ 
            v-=c[j]*(d+1-last[d][j]);
            }
    }
//    cout<<v<<endl;

    int m;
//    cin>>m;
m=0;
    rep(i,m){
        int dd,q;
        cin>>dd>>q;
        q--;
        int j=0;
        while(last[dd-1][j]!=dd || j>=26) j++;
        if(j==26){ 
            cout<<"error"<<endl;
            return 0;
        }
        v-=s[dd-1][j];
        for(int d=dd-1;d<D;d++){ 
            if(last[d][j]==dd){
                v+=c[j]*(d+1-last[d][j]);
                last[d][j]=(d==0? 0 : last[d-1][j]);
                v-=c[j]*(d+1-last[d][j]);
            }
            else{ 
                break;
            }
        }
        
        v+=s[dd-1][q];
        int before=last[dd-1][q];
        for(int d=dd-1;d<D;d++){ 
            if(last[d][q]==before){ 
                v+=c[q]*(d+1-last[d][q]);
                last[d][q]=dd;
                v-=c[q]*(d+1-last[d][q]);
            }
            else{ 
                break;
            }
        }
        cout<<v<<endl;
    }
    return 0;
}


Measured memory_bytes: 3708
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;

int main(){
	int H,W;
	scanf("%d %d",&H,&W);
	char a[H][W];
	int exH[H]={};
	int exW[W]={};
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(a[i][j]=='#')break;
			if(j==W-1)exH[i]=1;
		}
	}
	
	for(int i=0;i<W;i++){
		for(int j=0;j<H;j++){
			if(a[j][i]=='#')break;
			if(j==H-1)exW[i]=1;
		}
	}
	
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(exH[i]==1||exW[j]==1)continue;
			printf("%c",a[i][j]);
			
		}
		if(exH[i]!=1)printf("\n");
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e3+10;
const LL MOD=1e9+7;
int n,m,px[N*N],py[N*N];

int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) {
		int x; scanf("%d",&x);
		if (px[x]) { puts("0"); return 0; }
		px[x]=1;
	}
	for (int j=1;j<=m;j++) {
		int y; scanf("%d",&y);
		if (py[y]) { puts("0"); return 0; }
		py[y]=1;
	}
	
	LL ans=1,usedN=0,usedM=0;
	for (LL i=n*m;i;i--) {
		if (px[i] && py[i]) { usedN++; usedM++; continue; }
		if (px[i]) { usedN++; ans=(ans*usedM)%MOD; }
		if (py[i]) { usedM++; ans=(ans*usedN)%MOD; }
		if (!px[i] && !py[i]) ans=(ans*(usedN*usedM-(n*m-i)))%MOD;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int dr[] = {0,1,0,-1};
int dc[] = {1,0,-1,0};

struct node {
	int row;
	int col;
	int deep;
};

int main(void) {
	int H,W;
	cin >> H >> W;

	int white = 0;
	vector< vector<bool> > grid(H+2,vector<bool>(W+2,false));
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			char temp;
			cin >> temp;
			if (temp == '.') {
				grid[i+1][j+1] = true;
				++white;
			}
		}
	}

	int step = white+1;
	bool goal = false;
	queue<node> q;
	q.push({1,1,1});
	while (!q.empty() && !goal) {
		node now = q.front();
		q.pop();
		if (now.row == H && now.col == W) {
			step = now.deep;
			goal = true;
		}
		else {
			for (int d = 0; d < 4; ++d) {
				int nr = now.row + dr[d];
				int nc = now.col + dc[d];
				if (grid[nr][nc]) {
					q.push({nr,nc,now.deep+1});
					grid[nr][nc] = false;
				}
			}
		}
	}

	cout << white-step << endl;

	return 0;
}



Measured memory_bytes: 256
s=input()
letters=[]
count=[]
for i in range(len(s)):
  if s[i] in letters:
    count[letters.index(s[i])]+=1
  else:
    count.append(1)
    letters.append(s[i])
failflag=0
for i in range(len(count)):
  if count[i]%2==1:
    failflag=1
if failflag==0:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 38384
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;
int a[N];
int f[N];
int sum;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        f[a[i]]=f[a[i]-1]+1;
        sum=max(sum,f[a[i]]);
    }
    cout<<n-sum<<endl;
    return 0;
}


Measured memory_bytes: 5156
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

typedef long double ld;
const ld PI = acos(-1.0);
bool eq(ld a, ld b) { return abs(a - b) < EPS; }
typedef complex<ld> Point;

namespace std
{
	bool operator < (const Point& a, const Point& b)
	{
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}

struct Line
{
	Point a, b;
	Line() {};
	Line(Point p, Point q) :a(p), b(q) {};
	Line(ld x1, ld y1, ld x2, ld y2) :a(Point(x1, y1)), b(Point(x2, y2)) {};
};

ld dot(Point a, Point b)
{
	return real(conj(a)*b);
}

ld cross(Point a, Point b)
{
	return imag(conj(a)*b);
}

bool isis_ll(Line l, Line m)
{
	return abs(cross(l.b - l.a, m.b - m.a)) > EPS;
}

Point projection(Line l, Point p)
{
	Point base = l.b - l.a;
	ld r = dot(p - l.a, base) / norm(base);
	return l.a + base*r;
}

Point mirror(Line l, Point p)
{
	return Point(2, 0)*projection(l, p) - p;
}

Point is_ll(Line s, Line t)
{
	ld a = cross(s.b - s.a, t.b - t.a);
	ld b = cross(s.b - s.a, s.b - t.a);
	return t.a + b / a*(t.b - t.a);
}

int p; string s;

int number()
{
	assert(isdigit(s[p]) || s[p] == '-');
	int sig = 1;
	if (s[p] == '-')
	{
		sig = -1;
		p++;
	}
	int res = 0;
	while (isdigit(s[p]))
	{
		res *= 10;
		res += s[p] - '0';
		p++;
	}
	return res * sig;
}

vector<Point> parse()
{
	assert(s[p] == '(');
	p++;
	vector<Point> res;
	if (s[p] == '(')
	{
		vector<Point> lhs = parse();
		while (s[p] == '@')
		{
			p++;
			vector<Point> rhs = parse(), tmp;
			if (lhs.size() > rhs.size()) swap(lhs, rhs);
			if (lhs.size() == 1 && rhs.size() == 1)
			{
				tmp.push_back(lhs[0]);
				tmp.push_back(rhs[0]);
			}
			else if (lhs.size() == 1 && rhs.size() == 2)
			{
				Point a(lhs[0]);
				Line b(rhs[0], rhs[1]);
				tmp.push_back(mirror(b, a));
			}
			else
			{
				Line a(lhs[0], lhs[1]), b(rhs[0], rhs[1]);
				assert(isis_ll(a, b));
				tmp.push_back(is_ll(a, b));
			}
			lhs = tmp;
		}
		assert(s[p] == ')');
		res = lhs;
		p++;
	}
	else if (isdigit(s[p]) || s[p] == '-')
	{
		int x, y;
		x = number();
		assert(s[p] == ',');
		p++;
		y = number();
		assert(s[p] == ')');
		p++;
		res.emplace_back(x, y);
	}
	else assert(false);
	return res;
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	while (cin >> s, s != "#")
	{
		s.insert(0, "(");
		s.push_back(')');
		p = 0;
		vector<Point> ans = parse();
		assert(ans.size() == 1);
		cout << ans[0].real() << " " << ans[0].imag() << endl;
	}
	return 0;
}

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

public class Main {
	public static void main (String[] args)throws IOException{
		
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();		
		
		String[] x = new String[a];
		
		for(int i = 0; i < a; i++){
			x[i] = sc.next();
		}
		
		Arrays.sort(x);
		
		for(int i = 0; i < a; i++){
			System.out.print(x[i]);
		}
	}
}


Measured memory_bytes: 9932
n = gets.to_i

cnt = Hash.new(0)
gets.split.map(&:to_i).sort.each do |a|
  cnt[a] += 1
end
dp = Array.new(1000001, true)

ans = 0
cnt.each do |a, c|
  next unless dp[a]
  ans += 1 if c == 1
  i = 1
  while i * a < 1000001
    dp[i * a] = false
    i += 1
  end
end
puts ans


Measured memory_bytes: 44984
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
typedef pair<long long, long long> P;
int main(){
    long long N, C;
    cin >> N >> C;
    vector<long long> x(N + 2, 0), v(N);
    for(int i = 0; i < N; i++) {
        cin >> x[i + 1] >> v[i];
    }
    x[N + 1] = C;
    vector<long long> gya(N + 1, 0), zyu(N + 1, 0), maxzyu(N + 1, 0), maxgya(N + 1, 0);
    long long m = 0;
    long long tempd = 0;
    for(int i = 0; i < N; i++){
        zyu[i + 1] = zyu[i] + (v[i] - (x[i + 1] - tempd));
        tempd = x[i + 1];
        m = max(m, zyu[i + 1]);
        maxzyu[i + 1] = m;
    }
    tempd = C;
    m = 0;
    for(int i = 0; i < N; i++){
        gya[i + 1] = gya[i] + (v[N - 1 - i] - (tempd - x[N - i]));
        tempd = x[N - i];
        m = max(m, gya[i + 1]);
        maxgya[i + 1] = m;
    }
    long long ans = 0;
    for(int i = 0; i < N + 1; i++){
        ans = max(ans, gya[i] - (C - x[N + 1 - i]) + maxzyu[N - i]);
        ans = max(ans, zyu[i] - x[i] + maxgya[N - i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <queue>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

std::vector<int> wtf[200200];

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n, m;
	std::cin >> n >> m;
	while(n--) {
		int days, reward;
		std::cin >> days >> reward;
		int on = m - days;
		if(on >= 0) {
			wtf[on].push_back(reward);
		}
	}
	std::priority_queue<int> hp;
	long long ans = 0;
	for(int i = m; i >= 0; i--) {
		for(int j = 0; j < (int) wtf[i].size(); j++) {
			hp.push(wtf[i][j]);
		}
		if(!hp.empty()) {
			ans += hp.top();
			hp.pop();
		}
	}
	std::cout << ans << '\n';
}

Measured memory_bytes: 8064
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int yo,p;
    cin >> yo;
    cin >> p;
    if(yo <= 5){
        p = 0;
    }else if(yo <= 12){
        p /= 2;
    }
    cout << p;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
#include<string>
#include<stack>
#include<map>
#include<cmath>
#include<queue>
#include<set>
#include<string>
using namespace std;
typedef pair<int,int> P;
typedef long long LL;
typedef unsigned long long ULL;
const LL mod=1e9+7;
const LL LL_MAX=9223372036854775807;
const LL maxn=2e5+10;
const double eps=1e-9;
LL read()
{
    LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int read1()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
char s[maxn];
int n,p;
LL dp[maxn];
int main()
{
    scanf("%d%d",&n,&p);
    scanf("%s",s+1);
    LL res=0;
    if(p==2||p==5){
        for(int i=1;i<=n;i++){
            if((s[i]-'0')%p==0){
                res+=i;
            }
        }
    }
    else{
        LL tmp=0;
        LL base=1;
        for(int i=n;i>=1;i--){
            tmp=(tmp+(s[i]-'0')*base)%p;
            base=(base*10)%p;
            dp[tmp]++;
        }
        res+=dp[0]+dp[0]*(dp[0]-1)/2;
        for(int i=1;i<=p-1;i++){
            res+=(dp[i]-1)*dp[i]/2;
        }
    }
     cout<<res<<endl;
    return 0;
}



Measured memory_bytes: 512
#include<stdio.h>

int main()
{
    char ar[105];
    scanf("%s", ar);
    for(int i = 0; ar[i] != '\0'; i++)
    {
        if(ar[i] == ',')
        {
            printf(" ");
        }
        else
        {
            printf("%c", ar[i]);
        }
    }
    puts("");
    return 0;
}

Measured memory_bytes: 1592
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!

// OT.find_by_order(k-1)
// 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(998244353)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long

//////////////////////
const int N = 100005;


int32_t main() {

    ios::sync_with_stdio(false);
    cin.tie(0); 
    cout.tie(0);
	int n,q;
	cin >> n >> q;
	string st;
	cin >> st;

	vector<int> suffix(n+1);
	suffix[0+1] = 0;

	repA(i,1,n-1) {
		if(st[i-1]=='A' and st[i]=='C')
			suffix[i+1] = 1 + suffix[i];
		else
			suffix[i+1] = suffix[i];
	}
	int l,r;
	while(q --) {
		cin >> l >> r;
		// l--,r--;
		// db2(suffix[r],suffix[l-1]);
		cout << suffix[r] - suffix[l] << '\n';
	}
}

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

int main () {
  int x,a,b;
  cin >> x >> a >> b;
  if(b <= a) {
    cout << "delicious";
  } else if(b <= a + x){
    cout << "safe";
  } else {
    cout << "dangerous";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F;
		var A = G;
		var inv = new long[N + 1];
		for (var i = 1; i <= N; i++) inv[i] = Inverse(i, MOD);
		var sum = new long[N + 2];
		for (var i = 0; i <= N; i++) sum[i + 1] = (sum[i] + inv[i]) % MOD;
		var ans = 0l;
		for (var i = 0; i < N; i++)
		{
			var x = (sum[i + 2] - sum[2]) + (sum[N - i + 1] - sum[1]);
			x %= MOD;
			if (x < 0) x += MOD;
			ans += x * A[i] % MOD;
		}
		ans %= MOD;
		for (var i = 1; i <= N; i++) ans = ans * i % MOD;
		WriteLine(ans % MOD);
	}
	public static long Inverse(long a, long mod)
	{
		if (a < 0) { a %= mod; if (a < 0) a += mod; }
		var t = SolveLinear(a, mod);
		return t.Item1 > 0 ? t.Item1 : t.Item1 + mod;
	}
	public static Tuple<long, long> SolveLinear(long n, long m)
	{
		if (n < 0) { var p = SolveLinear(-n, m); return p == null ? p : new Tuple<long, long>(-p.Item1, p.Item2); }
		if (m < 0) { var p = SolveLinear(n, -m); return p == null ? p : new Tuple<long, long>(p.Item1, -p.Item2); }
		if (n < m) { var p = SolveLinear(m, n); return p == null ? p : new Tuple<long, long>(p.Item2, p.Item1); }
		long a = 1, b = 0, c = 0, d = 1;
		while (m > 0)
		{
			var r = n % m;
			var q = n / m;
			n = m;
			m = r;
			var tmp = a;
			a = -a * q + b;
			b = tmp;
			tmp = c;
			c = -c * q + d;
			d = tmp;
		}
		return n != 1 ? null : new Tuple<long, long>(d, b);
	}
}


Measured memory_bytes: 29272
using System;
//using System.Collections;
//using System.Collections.Generic;
using System.Linq;

namespace problem
{
  class Test
  {
    static void Main()
    {
      int[,,] room = new int[4, 3, 10];
      int i = int.Parse(Console.ReadLine());
      for (int a = 0; a < i; a++)
      {
        var s = Console.ReadLine().Split().Select(int.Parse).ToArray();
        room[s[0] - 1, s[1] - 1, s[2] - 1] += s[3];
      }

      for (int b = 0; b < 4; b++)
      {
        for (int f = 0; f < 3; f++)
        {
          for (int r = 0; r < 10; r++)
          {
            Console.Write(" {0}", room[b, f, r]);
          }
          Console.Write("\n");
        }
        if (b != 3) Console.WriteLine("####################");
      }
    }
  }
}


Measured memory_bytes: 9708
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int ans = 0;
		for (int i = 0; i < n; i++) {
			long a = Long.parseLong(sc.next());
			while (a % 2 == 0) {
				a /= 2;
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 30800
from fractions import gcd
from functools import reduce

N,X = map(int, input().split())
x = list(map(int,input().split()))

x.append(X)
sorted_x = sorted(x)
min_sorted_x = sorted_x[0]
dists = ([n - min_sorted_x for n in sorted_x])[1:]
print(reduce(gcd,dists))


Measured memory_bytes: 16280
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using P = pair<int, int>;
const int MX = 100005;
int n, l, r, lma, rmi = 1e9+7, larg, rarg, m1, m2, m3, ans, a1, a2, l2, k;
P ran[MX];
bool used[MX];
int main(){
	scanf("%d", &n);
	rep(i,n){
		scanf("%d%d", &l, &r);
		if(l > lma || (l == lma && r > k)){
			lma = l; k = r;
			larg = i;
		}
		if(r < rmi || (r == rmi && l < l2)){
			rmi = r; l2 = l;
			rarg = i;
		}
		if(m1 <= r-l+1){
			m3 = m2;
			m2 = m1; a2 = a1;
			m1 = r-l+1; a1 = i;
		}else if(m2 <= r-l+1){
			m3 = m2;
			m2 = r-l+1; a2 = i;
		}else if(m3 <= r-l+1) m3 = r-l+1;
		ran[i] = P(r,l);
	}
	ans = m1;
	if(rmi >= lma){
		ans = max(ans, (a1 == rarg || a1 == larg ? a2 == rarg || a2 == larg ? m3 : m2 : m1) + rmi - lma + 1);
	}
	sort(ran, ran+n);
	rep(i,n){
		if(ran[i].first < lma) l2 = max(l2, ran[i].second);
		else{
			ans = max(ans,min(ran[i].first,k) - lma + rmi - l2+2);
			l2 = max(l2, ran[i].second);
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1024