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

using namespace std;
typedef long long ll;

const int N=100005;
const ll inf=1e18;

namespace Task{
	int L[N],R[N],n,P,arr[N<<1],m;
	map<int,int>dat;
	inline void ins(ll l,ll r){++n,L[n]=(r%P+P)%P,R[n]=(l%P+P)%P;}
	
	ll mv[N<<3];
	void cover(int x,int l,int r,int s,int t){
		if(l==s&&r==t){mv[x]=inf;return;}
		int ls=x<<1,rs=ls|1,mid=(l+r)>>1;
		if(mv[x]==inf)mv[ls]=mv[rs]=inf;
		if(t<=mid)cover(ls,l,mid,s,t);
		else if(s>mid)cover(rs,mid+1,r,s,t);
		else cover(ls,l,mid,s,mid),cover(rs,mid+1,r,mid+1,t);
		mv[x]=min(mv[ls],mv[rs]);
	}
	void modify(int x,int l,int r,int p,ll u){
		if(l==r){mv[x]=min(mv[x],u-arr[l]);return;}
		int ls=x<<1,rs=ls|1,mid=(l+r)>>1;
		if(mv[x]==inf)mv[ls]=mv[rs]=inf;
		if(p<=mid)modify(ls,l,mid,p,u);
		else modify(rs,mid+1,r,p,u);
		mv[x]=min(mv[ls],mv[rs]);
	}
	ll query(int x,int l,int r,int s,int t){
		if(mv[x]==inf)return inf;
		if(l==s&&r==t)return mv[x];
		int ls=x<<1,rs=ls|1,mid=(l+r)>>1;
		if(t<=mid)return query(ls,l,mid,s,t);
		if(s>mid)return query(rs,mid+1,r,s,t);
		return min(query(ls,l,mid,s,mid),query(rs,mid+1,r,mid+1,t));
	}
	ll dfs(int x,int l,int r){
		if(mv[x]==inf)return inf;
		if(l==r)return mv[x]+arr[l];
		int ls=x<<1,rs=ls|1,mid=(l+r)>>1;
		return min(dfs(ls,l,mid),dfs(rs,mid+1,r));
	}
	
	ll solve(){
		if(n==0)return 0;
		for(int i=1;i<=n;i++)dat[L[i]]=dat[R[i]]=0;
		for(auto&v:dat)v.second=++m,arr[m]=v.first;
		cover(1,1,m,1,m);
		int c1=dat[L[1]],c2=dat[R[1]];
		if(c1<=c2){
			for(int i=c1;i<=c2;i++)modify(1,1,m,i,0);
		}else{
			for(int i=1;i<=c2;i++)modify(1,1,m,i,0);
			for(int i=c1;i<=m;i++)modify(1,1,m,i,0);
		}
		for(int i=2;i<=n;i++){
			int u=dat[L[i]],v=dat[R[i]];
			ll a=inf,b=inf;
			if(u>1)a=min(a,query(1,1,m,1,u-1)+arr[u]);
			if(u<m)a=min(a,query(1,1,m,u+1,m)+arr[u]+P);
			if(v>1)b=min(b,query(1,1,m,1,v-1)+arr[v]);
			if(v<m)b=min(b,query(1,1,m,v+1,m)+arr[v]+P);
			modify(1,1,m,u,a),modify(1,1,m,v,b);
			if(u>v){
				if(v+1<=u-1)cover(1,1,m,v+1,u-1);
			}else{
				if(u>1)cover(1,1,m,1,u-1);
				if(v<m)cover(1,1,m,v+1,m);
			}
		}
		return dfs(1,1,m);
	}
};

int n,K,a[N],b[N];
ll ans,s[N];

int main(){
	scanf("%d%d",&n,&K);
	Task::P=K;
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a[i],&b[i]);
		s[i]=s[i-1]+a[i];
		if(b[i]==1){
			if(a[i]*2>K)puts("-1"),exit(0);
			Task::ins(-2*s[i],-2*s[i-1]);
		}
	}
	ans=s[n]*2+Task::solve();
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 11904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S;cin>>S;
    if(S=="AAA"||S=="BBB"){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
}



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

int main() {
	int a[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 }, k = 0;
	cin >> k;
	cout << a[k - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
//****************************//
/**********  main *************/
//****************************//
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <math.h> 

using namespace std;
typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i, n) for (i = 0; i < n; i++)
#define FOR(i, a, b) for (i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())

double pi = 3.141592653589793;

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

int main()
{

    std::cin.tie(0);

    int h1,h2,m1,m2,k;
    cin >> h1 >> m1 >> h2 >>m2 >> k;
    int h,m,tmp,res;
    int amari;

    if(m1>=m2){
        m = 60 + (m2 - m1);
        h = h2 - h1 -1;
    }
    if(m2>m1){
        m = m2 - m1;
        h = h2 - h1;
    } 

    if(h>0){
        tmp = (60*h + m) / k;
        amari = (60*h + m) % k;
        res = (tmp-1)*k + amari;
        
    }

    if(h==0){
        tmp = m / k;
        amari = m % k;
        res = (tmp-1)*k + amari;
    }

    cout << res << endl;

    return 0;

}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x) ((x) * (x))
#define bit(n) (1LL<<(n))
#define pcnt(x) __builtin_popcountll(x)
#define PB push_back
#define MP make_pair
#define endl "\n"
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int dp[20100][256];
const int MAX = 1001001001;

int main() {
  while(1){
    int n,m; cin >> n >> m;
    if(n==0 && m==0) break;

    FOR(i,0,n){
      FOR(j,0,255){
        dp[i][j] = MAX;
      }
    }

    int c[m],x[n];
    FOR(i,0,m-1) cin >> c[i];
    FOR(i,0,n-1) cin >> x[i];
    dp[0][128] = 0;

    FOR(i,0,n-1){
      FOR(j,0,255){
        if(dp[i][j]==MAX) continue;
        FOR(k,0,m-1){
          int to = j + c[k];
          // cout << i << " " << to << "\n";
          chmax(to,0);
          chmin(to,255);
          chmin(dp[i+1][to], dp[i][j] + (x[i]-to) * (x[i]-to));
        }
      }
    }

    int ans = 1001001001;
    FOR(i,0,255) chmin(ans,dp[n][i]);
    cout << ans << "\n";
  }
}



Measured memory_bytes: 23136
import java.util.Scanner;

public class Main {
    int D;
    int D1;
    int[] C;
    int[][] S;
    long score;

//    int[] bestContestOfDay;
    

    // スケジュール
    int[] schedule;

    private void debugPrint() {
        for (int i = 1; i <= 26; i++) {
            System.out.print(C[i] + " ");
        }
        System.out.println();

        for (int j = 1; j <= D; j++) {
            for (int i = 1; i <= 26; i++) {
                System.out.print(S[j][i] + " ");
            }
            System.out.println();
        }
    }

    private void init() {
        // read & init solution
        Scanner sc = new Scanner(System.in);
        D = sc.nextInt();
        D1 = D + 1;
        
        schedule = new int[D1];
        score = 0;

        C = new int[27];
        for (int i = 1; i <= 26; i++) {
            C[i] = sc.nextInt();
        }
        S = new int[D1][27];
        //bestContestOfDay = new int[D1];
        for (int j = 1; j <= D; j++) {
            int max = 0;
            for (int i = 1; i <= 26; i++) {
                S[j][i] = sc.nextInt();
                if (S[j][i] > max) {
                    max = S[j][i];
                    //bestContestOfDay[j] = i;
                    schedule[j] = i;
                }
                score += max;
            }
        }

        // minus score calc
    }

    private void output() {
        for (int i = 1; i <= D; i++) {
            System.out.println(schedule[i]);
        }
    }

    public void run() {
        init();

        output();
    }

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

Measured memory_bytes: 38032
#include <iostream>
#include <string>

using namespace std;

int main(int argc, const char *argv[])
{
  string a, b;
  cin >> a >> b;

  int n = stoi(a + b);
  for (int i = 1; i * i <= n; i++) {
    if (i * i == n) {
      cout << "Yes" << '\n';
      return 0;
    }
  }

  cout << "No\n" << '\n';
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    int[][] card = new int[3][3];

    //card input
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
        card[i][j] = nextInt();
      }
    }

    //bingo
    int n = nextInt();
    for(int k=0;k<n;k++){
      int b = nextInt();
      //////////////////////////////
      for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
          if(b==card[i][j]){
            card[i][j] = 0;
          }
        }
      }
      //////////////////////////////
    }

    boolean ok = false;

    for(int i=0;i<3;i++){
      if((card[i][0]+card[i][1]+card[i][2])==0){
        ok = true;
      }
    }

    for(int j=0;j<3;j++){
      if((card[0][j]+card[1][j]+card[2][j])==0){
        ok = true;
      }
    }

    if((card[0][0]+card[1][1]+card[2][2])==0){
      ok = true;
    }

    if((card[0][2]+card[1][1]+card[2][0])==0){
      ok = true;
    }

    if(ok){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }

  }
  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

  static int nextInt(){
    return Integer.parseInt(sc.next());
  }

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


Measured memory_bytes: 23380
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int num = 0;

int w, h;
bool arr[100][100] = {};
bool ar_arr[102][102] = {};


struct P { int x, y; };


int dir[2][6][2] = {
    {{-1, -1},{0, -1},{1, 0},{0, 1},{-1, 1},{-1, 0}},
    {{0, -1},{1, -1},{1, 0},{1, 1},{0, 1},{-1, 0}}
};


void outer_group( vector<P>& v, int const x, int const y )
{
    ar_arr[x][y] = true;

    if ( x >= 1 && y >= 1 && x <= w && y <= h ) {
        P pt = { x-1, y-1 };
        v.push_back( pt );
    }

    for( int i=0; i<6; ++i ) {
        int const nx = x + dir[y%2][i][0], ny = y + dir[y%2][i][1];
        if ( nx < 0 || ny < 0 || nx > w+1 || ny > h+1 )
            continue;

        if ( ar_arr[nx][ny] == false )
            outer_group( v, nx, ny );
    }
}


int main()
{
    cin >> w >> h;

    for( int y=0; y<h; ++y ) {
        for( int x=0; x<w; ++x ) {
            int is;
            cin >> is;
            if ( is == 1 ) {
                arr[x][y] = true;
                ar_arr[x+1][y+1] = true;
            }
        }
    }



    vector<P> outer;
    outer_group( outer, 0, 0 );
    bool bbb[100][100] = {};

    for( size_t j=0; j<outer.size(); ++j ) {
        bbb[outer[j].x][outer[j].y] = true;
    }


    for( int y=0; y<h; ++y ) {
        for( int x=0; x<w; ++x ) {
            if ( !arr[x][y] )
                continue;

            for( int i=0; i<6; ++i ) {
                int const nx = x + dir[(y+1)%2][i][0], ny = y + dir[(y+1)%2][i][1];
                if ( nx < 0 || ny < 0 || nx >= w || ny >= h ) {
                    ++num;
                    continue;
                }

                if ( !arr[nx][ny] && bbb[nx][ny] ) {
                    ++num;
                }
            }
        }
    }

    cout << num << endl;
}

Measured memory_bytes: 1796
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i< (int)(n); i++)
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define pb(e) push_back(e)
#define foreach(c, i) for(iter(c) i = (c).begin(); i != c.end(); ++i)
#define mp(a, b) make_pair(a, b)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

vector<int> factor(int n){
  int num = n;
  vector<int> res;
  
  for(int i = 2; i * i <= n; i++){
    if(num % i == 0){
      while(num % i == 0) num /= i;
      res.pb(i);
    }
  }
  if(num > 1) res.pb(num);
  return res;
}

int main(){
  int a, b;
  while(cin >> a >> b && (a || b)){
    vector<int> va = factor(a);
    vector<int> vb = factor(b);
    
    int suma = accumulate(all(va), 0);
    int sumb = accumulate(all(vb), 0);
    int maxa = *max_element(all(va));
    int maxb = *max_element(all(vb));

    int keya = 2 * maxa - suma;
    int keyb = 2 * maxb - sumb;
    cout << (keya > keyb ? "a" : "b") << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include<stdio.h>
#include<string>
#include<string.h>
#include<iostream>

using namespace std;

char str1[] = {'.','#','.','#'};
char str2[] = {'.','.','#','#'};

int main()
{
	int n;
	scanf("%d",&n);
//	cin >> n;
	
	string s1,s2;
	
	int toright = 1;
	
	while(1)
	{
		
		int f = 0;
		for(int i = 0; i < 4; i++)
		{
			
			string temp1 = s1;
			string temp2 = s2;
			
			if (toright)
			{
				temp1 += str1[i];
				temp2 += str2[i];
			}
			else
			{
				temp1 = str1[i] + temp1;
				temp2 = str2[i] + temp2;
			}
			
			cout << temp1 << "\n" << temp2 << "\n" << flush;
			char s[6];
			scanf("%s",s);
			
			if (!strcmp(s,"end"))
				return 0;
			
			if (!strcmp(s,"T"))
			{
				f = 1;
				s1 = temp1;
				s2 = temp2;
				break;
			}
			
//			string s;
//			cin >> s;
//			
//			if (s == "end")
//				return 0;
//			
//			if (s == "T")
//			{
//				f = 1;
//				s1 = temp1;
//				s2 = temp2;
//				break;
//			}
			
		}
		
		if (!f)
		 	toright = 0;
	}

	return 0;
}

Measured memory_bytes: 724
#define _USE_MATH_DEFINES	//M_PI
#include <iostream>			//std::cout, std::cin
#include <string>			//std::string
#include <vector>			//std::vector
#include <valarray>			//std::valarray	??°????????????????¬???????
#include <algorithm>		//std::sort
#include <time.h>			//localtime_s
#include <cstdlib>			//abs
#include <cmath>			//abs, pow, sqrt, sin, cos,
#include <fstream>			//std::ifstream
#include <iomanip>			//std::setprecision

int main(void) {

	//test??¨
	//std::ifstream in("test.txt");
	//std::cin.rdbuf(in.rdbuf());

	int dice[6] = {};
	for (int i = 0; i < 6; i++) {
		std::cin >> dice[i];
	}

	int temp[6] = {};

	std::string order;
	std::cin >> order;
	for (int i = 0; i < order.length(); i++) {
		switch (order[i]) {
		case 'E':
			temp[0] = dice[3];
			temp[1] = dice[1];
			temp[2] = dice[0];
			temp[3] = dice[5];
			temp[4] = dice[4];
			temp[5] = dice[2];
			for (int j = 0; j < 6; j++) {
				dice[j] = temp[j];
			}
			break;
		case 'N':
			temp[0] = dice[1];
			temp[1] = dice[5];
			temp[2] = dice[2];
			temp[3] = dice[3];
			temp[4] = dice[0];
			temp[5] = dice[4];
			for (int j = 0; j < 6; j++) {
				dice[j] = temp[j];
			}
			break;
		case 'S':
			temp[0] = dice[4];
			temp[1] = dice[0];
			temp[2] = dice[2];
			temp[3] = dice[3];
			temp[4] = dice[5];
			temp[5] = dice[1];
			for (int j = 0; j < 6; j++) {
				dice[j] = temp[j];
			}
			break;
		case 'W':
			temp[0] = dice[2];
			temp[1] = dice[1];
			temp[2] = dice[5];
			temp[3] = dice[0];
			temp[4] = dice[4];
			temp[5] = dice[3];
			for (int j = 0; j < 6; j++) {
				dice[j] = temp[j];
			}
			break;
		default:;
		}
	}
	std::cout << dice[0] << std::endl;

}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> V;

#define _ cin.tie(0);ios::sync_with_stdio(false);

int n;
int main(){ _;
  cin>>n;
  V a(n);
  REP(i,n) cin>>a[i];
  VSORT(a);
  llong ans=0;
  REP(i,n-1)
    ans+=(a[i+1]-a[i]);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/


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


int main(void) {
  ll i, j, k;
  ll N, K;
  cin >> N >> K;
  
  ll g=0;
  ll ma=0;
  for(i=0; i<N; i++) {
    ll a;
    cin >> a;
    g=gcd(g, a);
    chmax(ma, a);
  }
  
  if(ma>=K && K%g==0) pt("POSSIBLE");
  else pt("IMPOSSIBLE");
  
}



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

int main()
{
    while (true) {
        int h, w;
        cin >> h >> w;
        
        if (!h && !w) break;
        
        string s1(w, '#');
        
        string s2(w, '.');
        s2[0] = '#';
        s2[s2.size() - 1] = '#';
        
        cout << s1 << "\n";
        if (h > 2)
            for (int i = 1; i < h - 1; i++)
                cout << s2 << "\n";
        cout << s1 << "\n";
            
        cout << "\n";
    }
}

Measured memory_bytes: 1160
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define pi pair<int,int> 
#define pii pair<pi,int>
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a >= mod)a %= mod;
}
ll dist[310][310];
ll d[310][310];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,m,l;
	cin>>n>>m>>l;
	ll inf = 1e18 + 2;
	repa(i,1,n+1){
		repa(j,1,n+1){
			dist[i][j] = inf;
			d[i][j] = inf;
		}
	}
	// cout<<dist[1][1]<<"\n";
	rep(i,m){
		int x,y,z;
		cin>>x>>y>>z;
		if(z <= l){
			dist[y][x] = dist[x][y] = z;
		}
	}
	for (int k = 1; k <= n; k++)  
    {    
        for (int i = 1; i <= n; i++)  
        {  
            for (int j = 1; j <= n; j++)  
            {  
                if (dist[i][k] + dist[k][j] < dist[i][j])  	
                    dist[i][j] = dist[i][k] + dist[k][j];

            }  
        }  
    }
    repa(i,1,n+1){
    	repa(j,1,n+1){
    		if(dist[i][j] <= l){
				d[i][j] = 1;    			
    		}
    	}
    }
    for (int k = 1; k <= n; k++)  
    {    
        for (int i = 1; i <= n; i++)  
        {  
            for (int j = 1; j <= n; j++)  
            {  
                if (d[i][k] + d[k][j] < d[i][j])  	
                    d[i][j] = d[i][k] + d[k][j];

            }  
        }  
    }
    int q;
    cin>>q;
    while(q--){
    	int s,t;
    	cin>>s>>t;
    	ll ans = d[s][t];
    	// cout<<dist[s][t]<<"\n";
    	// cout<<ans<<"\n";
    	if(ans >= inf)ans = 0;
    	// else{
    	// 	if(ans%l == 0)ans--;
    	// 	ans /= l;
    	// }
    	cout<<ans-1<<"\n";
    }  
	return 0;
}

Measured memory_bytes: 5036
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
long long GCD(long long a,long long b){
    if(b==0)return a;
    return GCD(b,a%b);
}
long long LCM(long long a,long long b){
    return a*b/GCD(a,b);
}
long long modMult(long long a, long long b, long long m) {
  long long res = 0;
  long long exp = a % m;
  while (b) {
    if (b & 1) {
      res += exp;
      if (res > m) res -= m;
    }
    exp <<= 1;
    if (exp > m) exp -= m;
    b >>= 1;
  }
  return res;
}
long long powMod(long long a, long long b, long long m) {
  long long res = 1;
  long long exp = a % m;
  while (b) {
    if (b & 1) res = modMult(res, exp, m);
    exp = modMult(exp, exp, m);
    b >>= 1;
  }
  return res;
}
//powMod(a,b,MOD)
//O(log(b))?
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    string s;
    cin>>s;
    V dp(s.size());
    reverse(all(s));
    dp[0]=s[0]-'0';
    rep3(i,1,s.size()){
        dp[i]=((s[i]-'0')*powMod(10,i,2019)+dp[i-1])%2019;
    }
    dp.push_back(0);
    map<ll,ll> mp;
    for(auto i:dp){
        mp[i]++;
    }
    ll res=0;
    rep(i,2019){
        res+=(mp[i]*(mp[i]-1))/2;
    }
    cout<<res<<endl;
}


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

int main(void){
    int numtable[8]={-1,9,99,999,9999,99999,999999,9999999};
    int data[200][2];
    int result=-1;
    for(int i=0;i<200;++i){
        data[i][0]=-1;
        data[i][1]=-1;
    }
    for(int i=0;i<200;++i){
        if(0 == scanf("%d %d",&data[i][0],&data[i][1]))
            break;
    }
    for(int i=0;i<200;++i){
        if(data[i][0]!=-1&&data[i][1]!=-1){
            result=data[i][0]+data[i][1];
            for(int j=1;j<8;++j){
                if(result<=numtable[j]){
                    printf("%d\n",j);
                    break;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3176
import sys
from collections import deque
s=sys.stdin.readlines()
q=int(s[0].split()[1])
f=lambda x,y:(x,int(y))
d=deque(f(*e.split())for e in s[1:])
t,a=0,[]
while d:
 k,v=d.popleft()
 if v>q:v-=q;t+=q;d.append([k,v])
 else:t+=v;a+=[f'{k} {t}']
print('\n'.join(a))


Measured memory_bytes: 17732
#include<stdio.h>

char N[5];

int main(void){
  scanf("%s", N);

 if((N[0] == N[1] && N[1] == N[2]) || (N[1] == N[2] && N[2] == N[3])){
   printf("Yes");
 }else{
  printf("No");
 }

  return 0;
}

Measured memory_bytes: 128
n = gets.chomp.to_i
card_arr = gets.chomp.split(" ").map(&:to_i).sort { |a, b| b <=> a}
alice = 0
bob = 0
(0 .. n - 1).each do |i|
    if i % 2 == 0 then 
        alice += card_arr[i].to_i
    else
        bob += card_arr[i].to_i
    end
end

print ("#{alice - bob}\n")

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


int x(int n){
  int sum=0;
  while(n>0){
    sum+=n%10;
    n/=10;
  }
  return sum;
}




int main(){
  int n,a,b;
  cin >> n >> a >> b;
  int ans=0;
  int sum=0;
  
  for(int i=1;i<=n;i++){
    int sum=x(i);
    if(sum>=a && sum<=b) ans+=i;
  }
  
  cout << ans << endl;
}
              
    

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>

const int MAXN = 1e5 + 5;

int n, m, p, u, v, k;
int dist[MAXN], num[MAXN];
bool flag[MAXN], inQueue[MAXN];

struct graph {
    int vertex, val;

    graph(int vv = 0, int vval = 0) {
        vertex = vv;
        val = vval;
    }
};

std::vector<graph> con[MAXN], reverse[MAXN];
std::queue<int> q;

void ins(int start, int end, int key, std::vector<graph> a[]) {
    a[start].push_back(graph(end, key));
}

void init(int key) {
    flag[key] = true;
    for (int i = 0; i < reverse[key].size(); ++i) {
        int nxt = reverse[key][i].vertex;
        if (flag[nxt] == false)
            init(nxt);
    }
}

int spfa() {
    for (int i = 2; i <= n; ++i) {
        dist[i] = -(1e9 + 7);
    }
    dist[1] = 0;
    q.push(1);
    inQueue[1] = true;
    while (!q.empty()) {
        int cur = q.front();
        q.pop();
        inQueue[cur] = false;
        for (int i = 0; i < con[cur].size(); ++i) {
            int nxt = con[cur][i].vertex, cost = con[cur][i].val;
            if (flag[nxt] && dist[nxt] < dist[cur] + cost) {
                dist[nxt] = dist[cur] + cost;
                if (!inQueue[nxt]) {
                    q.push(nxt);
                    inQueue[nxt] = true;
                    ++num[nxt];
                    if (num[nxt] > n)
                        return -1;
                }
            }
        }
    }
    return std::max(dist[n], 0);
}

int main() {
    scanf("%d%d%d", &n, &m, &p);
    for (int i = 1; i <= m; ++i) {
        scanf("%d%d%d", &u, &v, &k);
        ins(u, v, k - p, con);
        ins(v, u, 1, reverse);
    }
    init(n);
    printf("%d", spfa());
    return 0;
}

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int N;
    cin >> N;
    vector<int> v(N);
    REP(i, N) {
        cin >> v[i];
    }
    /*
    int N = 4;
    vector<int> v = {2, 5, 4, 6};
    */

    LL l = 0;
    LL r = 0;
    LL c = 0;
    LL s = 0;
    LL res = 0;

    for(;r < N;r++) {
        c ^= v[r];
        s += v[r];
        for(;c != s;l++) {
            c ^= v[l];
            s -= v[l];
        }
        res += r - l + 1;
    }
    cout << res << endl;
    return 0;
}


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

int main()
{
    int $=1;
    //cin>>$;
    while($--)
    {
        ll d,t,s;
        cin>>d>>t>>s;
        if(d<=t*s) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}


/*
8888888888888888888888888888
    Md. Masud Mazumder
    University of Chittagong
    Department of CSE
8888888888888888888888888888
*/


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
long long int a[200010],pref[200010];
int main()
{
cout << fixed << setprecision(10);
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++)
{
    cin>>a[i];
}
pref[0]=0;
pref[1]=a[1];
for(int i=2;i<=n;i++)
{
    pref[i]=a[i]+pref[i-1];
}
int s=n;
vector<  double>v;
while(s-k>=0)
{
    v.push_back(pref[s]-pref[s-k]);
    s--;
}
sort(v.begin(),v.end());
double ans=(v[v.size()-1]+k);
ans /= 2.0;
cout<<ans;
return 0;
}

Measured memory_bytes: 5492
/*
 *  Author : Jun_SH
 *  Solution for ABC 140 E
 */
#include<bits/stdc++.h>
#define int long long
#define sd(a) scanf("%lld",&a)
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=1e5+10;
int a[maxn];
int pos[maxn];
int lmax[maxn];
int rmax[maxn];
main(){
    int n;
    sd(n);
    for(int i=1;i<=n;++i){
        sd(a[i]);
        pos[a[i]]=i;
        lmax[i]=i-1;
        rmax[i]=i+1;
    }
    int ans=0;
    for(int i=1;i<=n;++i){
        int l1=lmax[pos[i]];
        int l2=lmax[l1];
        int r1=rmax[pos[i]];
        int r2=rmax[r1];
        if(l1)ans+=(l1-l2)*(r1-pos[i])*i;
        if(r1!=n+1)ans+=(r2-r1)*(pos[i]-l1)*i;
        lmax[r1]=l1;
        rmax[l1]=r1;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3328
#include <iostream>
#define TEST cout << endl << "test "
using namespace std;

int main(void){
  int n,s[10001],q,t[501],count = 0;
  cin >> n; for(int i = 0; i < n; i++)cin >> s[i];
  cin >> q; for(int i = 0; i < q; i++)cin >> t[i];

  for(int i = 0; i < q; i++){
    s[n] = t[i];
    int j = 0;
    while(s[j] != t[i])j++;
    if(j != n)count++;
  }
  cout << count << endl;
  return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a1,b1,a2,b2;
  cin >>a1>>b1>>a2>>b2;
  int kotae=a1*b1-a2*b1-a1*b2+a2*b2;
  cout <<kotae<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define int long long
#define pb push_back
using namespace std;
int dp[3001][3001];
int n;
int solve(int *a, int i, int j)
{
    if(i>j)
        return 0;
    if(i==j)
        return a[i];
    if(dp[i][j]!=-1)
        return dp[i][j];
    return dp[i][j]=max(a[i]+min(solve(a,i+2,j),solve(a,i+1,j-1)),a[j]+min(solve(a,i,j-2),solve(a,i+1,j-1)));
}
int32_t main()
{
    int t;
    //cin>>t;
    //while(t--)
    {   
        int k;
        cin>>n;
        memset(dp,-1,sizeof(dp));
        int a[100001];
        int sum=0;
        for(int i=0;i<n;i++)
            cin>>a[i], sum+=a[i];
        cout<<2*solve(a,0,n-1)-sum;
    }
}






Measured memory_bytes: 74160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double x1 = sc.nextDouble();
		double y1 = sc.nextDouble();
		double x2 = sc.nextDouble();
		double y2 = sc.nextDouble();
		
		double a=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
		double sqrt_num=Math.sqrt(a);
		System.out.println(sqrt_num);
			}
	}



Measured memory_bytes: 27912
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	ll n,k;
 	cin>>k>>n;
 	ll a[n];
 	set<ll>st;
 	for(ll i=0;i<n;i++)
 	{
 		cin>>a[i];
 	}	
 	for(ll i=1;i<n;i++)
 		st.insert(a[i]-a[i-1]);
 	st.insert(a[0]+(k-a[n-1]));
 	cout<<k-*st.rbegin()<<endl;
    return 0;
}

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

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    const int MOD = 'Z' + 1;
    string S;
    int N;
    cin >> N >> S;

    for (int i = 0; i < S.length(); i++) {
        if ((S[i] + N) < MOD) S[i] = S[i] + N;
        else S[i] = 'A' + (S[i] + N)%MOD;
    }
    
    cout << S;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//Fast io
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
//Class shorthands
#define ll long long
#define db long double
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
//Function Shorthands
#define fi first
#define se second
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair
#define po pop_back
#define eb emplace_back
//Code Shorthands
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
//Constants
#define hell 1000000007
#define PI acos(-1.0)
using namespace std;

void solve(){
	ll n;
	cin>>n;
	ll dp[n+1];
	mem0(dp);
	dp[0] = 1;
	for(int i=3;i<n+1;i++){
		for(int j=3;j<=i;j++){
			dp[i]+=dp[i-j];
			dp[i]%=hell;
		}
	}
	cout<<dp[n]<<endl;

}

int main(){
	io;
	int t = 1;
	//cin>>t;
	while(t--){
		solve();
	}
}

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

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<int>zone(n);
    rep(i, 0, n){
        cin >> zone[i];
        zone[i]--;
    }
    vector<int> m(n);
    vector<ll> m2;
    vector<int> m3;
    int a = 0;
    bool j = true;
    int count = 0, count2 = 0;
    rep(i, 0, 2*n){
        m[a]++;
        count++;
        if(j)m3.push_back(a+1);
        if(m[a] == 2){
            count2++;
            m2.push_back(a+1);
            j = false;
        }
        if(m[a] == 3){
            count--;
            m[a]--;
            goto end;
        }
        a = zone[a]; 
    }
    end:
    int count3 = count - 2*count2;
    if(k>=count3){
        ll count4 = (k - count3) % count2;
    cout << m2[count4] << endl;}
    else{
        cout << m3[k] << endl;
    }
    //cout << count << " " << count2 << " " << count3 << " " << count4 << " " << m2[0] << m2[1] << m2[2] <<endl;
}

Measured memory_bytes: 7568
m = []
s = []
line = input()
h, w = list(map(int, line.split()))
s = [ [0] * w for _ in range(0, h)]
for _ in range(0, h):
    line = input()
    c = list(map(int, line.split()))
    m += [c]

def solve(h, w):
    ans = 0
    for y in range(0, h):
        for x in range(0, w):
            if m[y][x] == 1:
                s[y][x] = 0
            else:
                u = s[y - 1][x] if y > 0 else 0
                l = s[y][x - 1] if x > 0 else 0
                ul = s[y - 1][x - 1] if x > 0 and y > 0 else 0
                s[y][x] = 1 + min(u, l, ul)
            ans = max(ans, s[y][x])
    return ans * ans

ans = solve(h, w)
print(ans)


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

long F[50],L[50];

long func(int n,long x){
    if(n==0){
        return 1;
    }else if(x==1){
        return 0;
    }else if(x==F[n]){
        return L[n];
    }else if(x==F[n-1]+2){
        return L[n-1]+1;
    }else if(x<=F[n-1]+1){
        return func(n-1,x-1);
    }else{
        return func(n-1,x-F[n-1]-2)+L[n-1]+1;
    }
}

int main(){
    int N;long X;
    cin>>N>>X;
    F[0]=1;L[0]=1;
    for(int i=1;i<=N;i++){
        F[i]=2*F[i-1]+3;
        L[i]=2*L[i-1]+1;
    }cout<<func(N,X)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"
#define  st first
#define  nd second
#define int long long 


template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef cc_hash_table<int, int, hash<int > > ht;

const int  M    = 1000000007;
const int  maxn =  100005 ;
const long long   inf  =  LONG_LONG_MAX    ;
const long double eps = 1.084202e-19;

int modular_pow(int  base, int exponent, int modulus=M)
{
    int result = 1;
    while (exponent > 0)
    {
        if (exponent % 2 == 1)
            result = (result * base) % modulus;
        exponent = exponent >> 1;
        base = (base * base) % modulus;
    }
    return result;
}


int32_t main(){
     ios_base::sync_with_stdio(false);
     cin.tie(NULL); 
     int n ; 
     cin >> n ; 
     int a[n] ; 
     int ans = 0 ; 
     int k= 0 ;
     for ( int i = 0 ; i < n ; i++){
           cin >> a[i] ; 
           ans = (((ans - ((a[i]*a[i])%M))%M) + M)%M;
           k = (k +a[i])%M;
     }
     k = (k *k)%M;
     ans  = (ans + k)%M;
     ans = (ans * modular_pow(2,M-2))%M;
     cout << ans ;  

}
/*

*/

Measured memory_bytes: 5216
#include <iostream>

using namespace std;

void solve()
{
	int a;
	cin >> a;
	while(a--)
	{
		int X, Y, W, H;
		cin >> X >> Y >> W >> H;
		int N;
		cin >> N;
		int count = 0;
		for(int i = 0; i < N; ++i)
		{
			int x, y;
			cin >> x >> y;
			if((X <= x && x <= X + W) && (Y <= y && y <= Y + H))
			{
				++count;
			}
		}
		cout << count << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1160
from collections import deque

s = list(input())
d = deque(s)
# d.append(s)
# print(d)

Q = int(input())
dir = 1


def func(f, c, dir):
    # print(f, c, dir)
    # dir = 1のとき
    if dir == 1:
        if f == 1:
            d.appendleft(c)
        else:
            d.append(c)
    # dir = -1のとき
    if dir == -1:
        if f == 1:
            d.append(c)
        else:
            d.appendleft(c)
    # print(d)


for i in range(Q):
    q = input()
    if q[0] == "1":
        dir *= -1
    else:
        z, f, c = q.split()
        func(int(f), c, dir)

if dir == -1:
    d.reverse()
print(*d, sep="")



Measured memory_bytes: 13040
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

ll gcd(ll a, ll b){
    if(a%b==0) return b;
    else return gcd(b,a%b);
}
ll ngcd(vector<ll> a){
    ll res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}

int main(){
    ll a,b,c,d;
    ll min1, max1;
    ll cnt1,cnt2,cnt3;
    cin>>a>>b>>c>>d;
    if(a%c!=0) min1 = c*(a/c+1);
    else min1 = c*(a/c);
    max1 = c*(b/c);
    if(min1<=max1) cnt1 = (max1 - min1)/c + 1;
    else cnt1 = 0;
    if(a%d!=0) min1 = d*(a/d+1);
    else min1 = d*(a/d);
    max1 = d*(b/d);
    if(min1<=max1) cnt2 = (max1 - min1)/d + 1;
    else cnt2 = 0;
    ll e = c*d/gcd(max(c,d),min(c,d));
    if(a%e!=0) min1 = e*(a/e+1);
    else min1 = e*(a/e);
    max1 = e*(b/e);
    if(min1<=max1) cnt3 = (max1 - min1)/e + 1;
    else cnt3 = 0;
    cout<<b-a+1-cnt1-cnt2+cnt3<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#define ll long long
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
using namespace std;



int main() {
    ll S, W;
    cin >> S >> W;
    if (S > W) cout << "safe" << endl;
    else cout << "unsafe" << endl;
    return 0;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
typedef long long ll;
using ll = long long;
using vi = vector<int>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;

    ll ans = k;
    FOR(i, 1, n) {
        ans *= k - 1;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import collections
import sys

input = sys.stdin.readline

n, m = map(int, input().split())
es = [collections.deque() for _ in range(n)]
for _ in range(m):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    es[l].append((l, r, d))
    es[r].append((r, l, -d))

visited = [False] * n
for i in range(n):
    if not visited[i]:
        visited[i] = True
        if len(es[i]) == 0:
            continue
        distances = [float('inf')] * n
        distances[i] = 0
        q = collections.deque()
        for e in es[i]:
            q.append(e)
        while q:
            j, k, d = q.popleft()
            if visited[k] and distances[k] != distances[j] + d:
                print('No')
                exit()
            distances[k] = distances[j] + d
            visited[k] = True
            while es[k]:
                ee = es[k].popleft()
                if len(es[ee[1]]) > 0:
                    q.append(ee)
print('Yes')

Measured memory_bytes: 116844
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <climits>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Set         std::set
#define PQueue      std::priority_queue
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define UMap        std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    llong power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    llong power ( llong x, llong n ) { return power( x, n, 1000000007 ); }
    llong gcd   ( llong x, llong y ) { return x % y ? gcd( y, x % y ) : y; }
    llong lcm   ( llong x, llong y ) { return ( x / gcd(x, y) * y ); }
    llong abs   ( llong n )          { return ( n < 0 ) ? -n : n; }
    template<class A, class B>inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B>inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    int cnt;

    signed call_of_Cthulhu( signed datum ) {

        int k, s;
        read k >> s;
        for ( int i = 0; i <= k; i++ ) {
            for ( int j = 0; j <= k; j++ ) {
                if ( 0 <= s-i-j && i+j <= s && s-i-j <= k ) cnt++;
            }
        }
        echo cnt fin;

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); echo std::fixed << std::setprecision(8); int main_result = Rlyeh::call_of_Cthulhu(114514); return main_result;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
//const ll mod = 1000000007;

int n;

signed main() {
    cin >> n;
    string ans = "No";
    for (int i=0;i<=n/4;i++) {
        for (int j=0;j<=n/7;j++) {
            if (4*i+j*7 == n) ans = "Yes";
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/dp/tasks/dp_a
//A - Frog 1
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N; cin>>N;
    vector<ll> hn(N+1,0);
    FOR(i,1,N+1){
        cin>>hn.at(i);
    }
    vector<ll> ans(N+1,INT64_MAX);
    ans[1]=0;
    auto get_val = [&](ll p,ll ofs)->ll{
        if(p-ofs<=0) return INT64_MAX;
        ll a=abs(hn[p]-hn[p-ofs]);
        return a+ans[p-ofs];
    };

    FOR(i,2,N+1){
        ll a=get_val(i,1);
        ll b=get_val(i,2);
        chmin(ans[i],a);
        chmin(ans[i],b);
    }
    cout<<ans[N]<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>

template <class T>
inline void read(T &x) {
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return;
}

typedef long long LL;

LL n, k;

int main() {
    read(n), read(k);
    if (n <= k) {
        printf("%lld\n", std::min(n, k - n));
    } else {
        LL m = n % k;
        printf("%lld\n", std::min(m, k - m));
    }
    return 0;
}

Measured memory_bytes: 256