akhauriyash/Code-Regression huggingface dataset:
import java.io.*;

public class Main {

    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String input;
        while (!(input = br.readLine()).equals("0 0")) {
            String[] st = input.split(" ");
            int a = Integer.parseInt(st[0]);
            int b = Integer.parseInt(st[1]);
            bw.append((a < b ? st[0] + " " + st[1] : st[1] + " " + st[0]) + "\n");
        }
        bw.flush();
    }

}



Measured memory_bytes: 27384
#include <iostream>
#include <vector>

using namespace std;

int main(){
  vector< vector<int> > c(3, vector<int>(3,0));
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      int temp;
      cin >> temp;
      c[i][j] = temp;
    }
  }

  bool ans = false;
  for(int a=0; a<=100; a++){
    int b1 = c[0][0] - a;
    int b2 = c[0][1] - a;
    int b3 = c[0][2] - a;
    if( c[1][0] - b1 == c[1][1] - b2 && c[1][1] - b2 == c[1][2] ){
      if( c[2][0] - b1 == c[2][1] - b2 && c[2][1] - b2 == c[2][2] ){
        ans = true;
        break;
      }
    }
  }

  if(ans){
    cout << "Yes";
  }else{
    cout << "No";
  }
}


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

bool isprime(int64_t n){
  for(int64_t i=2; i*i<=n; i++){
    if(n%i==0) return false;
  }
  return true;
}    

int main(){
  int64_t x;
  cin>> x;
  while(!isprime(x)){
    x++;
  }
  cout<<x<<endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

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

signed main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, 0, n) cin >> a[i];
    bool p = 1, s = 1;

    set<int> st;
    rep(i, 0, n) {
        int q = a[i];
        for (int j = 2; j * j <= q; j++) {
            if (q % j == 0) {
                if (*st.find(j) == j) {
                    p = 0;
                    break;
                }
                st.insert(j);
                while (q % j == 0) {
                    q /= j;
                }
            }
        }
        if (q != 1) {
            if (*st.find(q) == q) p = 0;
            st.insert(q);
        }
        if (!p) break;
    }

    // for (auto p : st) cout << p << " ";

    int now = a[0];
    rep(i, 0, n) { now = gcd(now, a[i]); }
    if (now != 1) s = 0;

    if (p) {
        cout << "pairwise coprime\n";
    } else if (s) {
        cout << "setwise coprime\n";
    } else {
        cout << "not coprime\n";
    }
}


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

bool cmp(char a,char b)
{
	return a>b;
}

int main() {
	string s,t;
	
	cin>>s;
	cin>>t;
	
	sort(s.begin(),s.end());
	sort(t.begin(),t.end(),cmp);
	
	if(s<t)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner stdIn = new Scanner(System.in);
		
		for (; ;) {
			int h = stdIn.nextInt();
			int w = stdIn.nextInt();
			
			if (h == 0 && w == 0) break;
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if (i == 0 || i == h - 1 || j == 0 || j == w - 1) {
						System.out.print("#");
					} else {
						System.out.print(".");
					}
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}



Measured memory_bytes: 34516
#include <cstdio>
#include <algorithm>
  
long long int a[10010];
int main() {
    int N;
    while(1) {
        scanf("%d", &N);
        if(N == 0) break;
      
        for(int i=0; i<N; i++) {
            scanf("%lld", &a[i]);
        }
          
        std::sort(a, a+N);
        long long int ans = 0;
        for(int i=0; i<N-1; i++) {
            if(i > 0) a[i] += a[i-1];
            ans += a[i];
        }
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 2728
#include<stdio.h>
#include<float.h>



#define p 4
#define q 9
#define r 5

#define c 0



int check( int P ,int Q ,int R ,int C ,int *lim )
{
	if( P > lim[ p ] )
	{
		return 1 ;
	}

	if( Q > lim[ q ] )
	{
		return 1 ;
	}

	if( R > lim[ r ] )
	{
		return 1 ;
	}

	if( C > lim[ c ] )
	{
		return 1 ;
	}


	return 0 ;
}



int main()
{
	int n ;

	while( 1 )
	{
		scanf( "%d" ,&n ) ;


		if( n == 0 )
		{
			return 0 ;
		}



		int cal[ 1000 ][ 10 ] ;

		int P[ 1000 ] ;

		int i ;
		for( i = 0 ; i < n ; ++i )
		{
			scanf( "%d %d %d %d" ,&P[ i ] ,&cal[ i ][ p ] ,&cal[ i ][ q ] ,&cal[ i ][ r ] ) ;
		}

		int limit[ 10 ] ;

		scanf( "%d %d %d %d" ,&limit[ p ] ,&limit[ q ] ,&limit[ r ] ,&limit[ c ] ) ;


		int checker = 0 ;


		for( i = 0 ; i < n ; ++i )
		{
			int C = ( cal[ i ][ p ] * p ) + ( cal[ i ][ q ] * q ) + ( cal[ i ][ r ] * ( r - 1 ) ) ;


			if( check( cal[ i ][ p ] ,cal[ i ][ q ] ,cal[ i ][ r ] ,C ,limit ) == 1 )
			{
				++checker ;
			}

			else
			{
				printf( "%d\n" ,P[ i ] ) ;
			}
		}


		if( checker == n )
		{
			puts( "NA" ) ;
		}
	}
}

Measured memory_bytes: 656
int main(void)

{

int a,b; 

 scanf("%d",&a); 

 scanf("%d",&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
#include <bits/stdc++.h>
using namespace std;
    

int main(){
    int flag=1;
    int task[3];
    int ans=0;

    cin >>task[0]>>task[1]>>task[2];
    sort(task,task+3);

    ans += abs(task[1]-task[0]) +abs(task[2]-task[1]);
    
    cout << ans <<endl;
    //cout <<fixed<<setprecision(16)<< ans <<endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m;
int main()
{
	cin >>n>>m;
	for (int i=max(-1000000,m-n+1);i<=min(1000000,n+m-1);i++)
		cout <<i<<" ";
	return 0;
}

Measured memory_bytes: 256
//FIRST THINK THEN CODE.

  #include <bits/stdc++.h>


  using namespace std;

  typedef long long ll;

  #define rep(i,a,b) for(ll i=a;i<b;++i)
  #define rrep(i,a,b) for(ll i=a;i>b;--i)
  #define FOR(i,n)  for(ll i=0;i<n;i++)
  #define vi vector<int>
  #define vl vector<ll>
  #define ld long double
  #define vld vector<ld>
  #define vvi vector<vector<int>>
  #define vvl vector<vector<long long>>
  #define vvld vector<vector<ld>>
  #define pii pair<int,int>
  #define pll pair<long,long>
  #define vpii vector<pii>
  #define vpll vector<pll>
  #define ff first
  #define ss second
  #define pb push_back
  #define pf push_front
  #define mp make_pair
  #define lb lower_bound
  #define ub upper_bound
  #define bs binary_search
  #define d1(x) cout<<(x)<<endl
  #define d2(x,y) cout<<(x)<<" "<<(y)<<endl
  #define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
  #define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
  #define PI 3.1415926535897932384626433832795
  #define fix(f,n) fixed<<setprecision(n)<<f
  #define all(x) x.begin(),x.end()
  #define rev(p) reverse(p.begin(),p.end());
  #define endl "\n"
  #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  #define popcount(x) __builtin_popcountll(x)
  #define sz(x) ((ll)x.size())
  const ll M=1000000007;
  const ll MM=998244353;
  ll begtime = clock();
  #define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
  //#define _Find_next 
  //#define _Find_first 



  ll newmod(ll a,ll b)
  {
  return ((a%b)+b)%b;
  }


  ll powM(ll a,ll b,ll m )
  { 
  if(a<=0)return 0;
  a%=m;
  if(!b)return 1;
  ll ans=1LL;
  while(b)
  {
  if(b&1)ans=ans*a%m;
  a=a*a%m;
  b>>=1;
  }

  return ans;
  }



  ll poww(ll a,ll b)
  { 

  ll ans=1;
  while(b)
  {
  if(b&1)ans=ans*a;
  a=a*a;
  b>>=1;
  }

  return ans;

  }

  template<typename T,typename F>
  void chmax( T &a,F b){
  if(b>a)a=b;
  }

  template<typename T,typename F>
  void chmin( T &a,F b){
  if(b<a)a=b;
  }

string tostring(ll x){
  stringstream sss;
  sss<<x;
  string ans=sss.str();
  return ans;
}


  const ll N=1e6+5;


  int main()
  { 

    IOS;

string s,t;
cin>>s>>t;

ll n1=sz(s);
ll n2=sz(t);

ll ans=1e18;

for(ll i=0;i<=n1-n2;i++){
  string temp=s.substr(i,n2);
  ll c=0;
  for(ll j=0;j<sz(temp);j++){
    if(t[j]!=temp[j])c++;
  }
  chmin(ans,c);
}
cout<<ans;
//end_routine();

  return 0;

  }

Measured memory_bytes: 3664
n = int(input())
c = list(input())

L = 0
R = n - 1
swaps = 0
while L < R:
    if c[L] == 'W' and c[R] == 'W':
        R -= 1
    elif c[L] == 'W' and c[R] == 'R':
        swaps += 1
        c[L], c[R] = c[R], c[L]
    elif c[L] == 'R' and c[R] == 'W':
        R -= 1
        L += 1
    elif c[L] == 'R' and c[R] == 'R':
        L += 1

print(swaps)
    
    


Measured memory_bytes: 10784
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
void in(){}
template<typename F, typename... R>
bool in(F& f, R&... r){
    if(cin >> f){in(r...);return true;}
    else return false;
}
#define out(x) cout << (x)
#define space() cout << " "
#define indent() cout << '\n'
void print(){}
template<typename F, typename... R>
void print(F f, R... r){out(f), indent(), print(r...);}
#define debughead(x) cerr << "Line " << __LINE__ << ": " << #x << ": "
#define debugout(x) cerr << (x) << " "
#define debugindent() cerr << '\n'
#define debug(x) debughead(x), debugout(x), debugindent()
const int INF = 1e18, MOD = 1e9 + 7;
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

main(){
    INCANT;
    int n, tmp, res = 0;
    string s;
    in(n);
    if(n == 1){
        print(0);
        return 0;
    }
    res = n - 1;
    for(int i = 2; (n - i) / i > 1 && i < sqrt(n); i++){
        if((n - i) % i == 0){
            res += (n - i) / i;
            tmp = i;
        }
    }
    if((int)(sqrt(n)) * ((int)(sqrt(n)) + 1) == n){
        print(res - (int)(sqrt(n)));
    }else{
        print(res);
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 35;
const int MAXK = 510;
const int MAXQ = 200010;

int n, f[MAXN];
string s;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    cin >> s;
    FOR(i,1,n)
        if (s[i-1] == '(') f[i] = f[i-1] + 1;
        else f[i] = f[i-1] - 1;
    int Min = 1000000000;
    FOR(i,1,n) Min = min(Min, f[i]);
    if (Min < 0) {
        FOR(i,1,-Min) s = "(" + s;
    }
    FOR(i,1,SZ(s))
        if (s[i-1] == '(') f[i] = f[i-1] + 1;
        else f[i] = f[i-1] - 1;
    if (f[SZ(s)] > 0) {
        int g = f[SZ(s)];
        FOR(i,1,g) s = s + ")";
    }
    cout << s;
    return 0;
}

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


public class Main {
	
	boolean isPrime(final int n){
		for(int i=n-1; 2<=i; --i){
			if(n%i==0){ return false; }
		}
		return true;
	}
	
	String solve(final int n){
		String str = "";
		
		for(int i=n-1; 2<=i; --i){
			if(isPrime(i)){
				str += i;
				break;
			}
		}
		for(int i=n+1;;++i){
			if(isPrime(i)){
				str += " " + i;
				break;
			}
		}
		
		return str;
	}
	
	void io(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			final int n = sc.nextInt();
			System.out.println(solve(n));
		}
	}
	
	public static void main(String[] args) {
		new Main().io();
	}
	
	void debug(Object... os){
		System.out.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define ll long long
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int read()
{
    char ch = getchar();
	int x = 0, f = 1;
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
int main()
{
int n=rr;
int a[105]={0};
int count=0,maxx=0;;
rep(i,0,n)
{
	a[i]=rr;
	if(a[i]>=maxx)
	{
		count++;
		maxx=a[i];
	}
}
printf("%d\n",count);
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }


int main() {
    string s, t;
    cin >> s >> t;
    rep(i, s.size()) {
        if (s[i] != t[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int x[4], n, cnt; string S;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++){
		memset(x, 0, 16);
		while (true) {
			cin >> S;
			if (S == "HIT") {
				x[0] += x[3]; x[3] = 0;
				x[3] += x[2]; x[2] = 0;
				x[2] += x[1]; x[1] = 0;
				x[1] += 1;
			}
			if (S == "OUT") {
				cnt++; if (cnt % 3 == 0) { goto E; }
			}
			if (S == "HOMERUN") {
				x[0] += x[3] + x[2] + x[1] + 1;
				x[3] = 0; x[2] = 0; x[1] = 0;
			}
		}
	E:;
		cout << x[0] << endl;
	}
}

Measured memory_bytes: 1208
n, q = map(int, input().split())
queue = list()
for i in range(n):
    p = input().split()
    queue.append({"name": p[0], "time": int(p[1])})

t = 0
while len(queue) > 0:
    proc = queue.pop(0)
    if q < proc["time"]:
        proc["time"] -= q
        t += q
        queue.append(proc)
    else:
        t += proc["time"]
        print(proc["name"], t)

Measured memory_bytes: 26052
#include <bits/stdc++.h>
#include <vector>
using namespace std;
 
int main(){
  //入力
  int a,b;
  cin>>a>>b;
  //出力
  if(a==b){
    for(int i=0;i<a;i++){
     cout<<a;
    }
    cout<<endl;
  }else if(a>b){
    for(int i=0;i<a;i++){
     cout<<b;
    }
    cout<<endl;
  }else{
    for(int i=0;i<b;i++){
     cout<<a;
    }
    cout<<endl;    
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    struct S{
        string s;
        int p;
        int id;
    };
    vec<S> A(N);
    for(int i=0;i<N;i++){
        string s;
        int p;
        cin >> s >> p;
        A[i] = {s,p,i};
    }
    sort(A.begin(),A.end(),[](S& a,S& b){
        if(a.s!=b.s) return a.s<b.s;
        else return a.p>b.p;
    });
    for(int i=0;i<N;i++) cout << A[i].id+1 << "\n";
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

int N, T;
int c[1010], t[1010];

int main()
{
    cin >> N >> T;
    int ans = inf;
    rep(i, 0, N)
    {
        cin >> c[i] >> t[i];
        if (t[i] <= T)
        {
            chmin(ans, c[i]);
        }
    }
    if (ans == inf)
    {
        cout << "TLE" << endl;
        return 0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)

h,w = [int(i) for i in input().split()]
board = [input() for _ in range(h)]

used = [[0]*w for _ in range(h)]
dx=[ 0, 1, 0,-1]
dy=[ 1, 0,-1, 0]

def dfs(x, y):
    global numb, numw #numbたちがグローバル変数だと教えてあげる
    #(x,y)地点を訪問済みにする
    used[x][y] = 1
    #(x,y)地点での処理を行う（マスの色をカウントするなど）
    if board[x][y] == '#':
        numb += 1
    else:
        numw += 1
    #foreach((nx,ny) \in (x,y)のお隣さん){(nx,ny)に訪問していないとき、dfs(nx,ny)} 
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if nx < 0 or nx >= h or ny < 0 or ny >= w or used[nx][ny] == 1: continue #範囲外参照 or (nx,ny)は確認済み スキップ
        if board[x][y]!=board[nx][ny]: #さらに(nx,ny)と(x,y)がつながっている場合(nx,ny)を訪問
            dfs(nx,ny)
    return #情報をもらうとき：返り値、各地点の情報のみで更新：グローバル変数、情報を送るとき：引数

ans=0
for i in range(h):
    for j in range(w):
        numw = 0
        numb = 0
        if used[i][j] == 1: continue #すでに確認した地点は見ない
        dfs(i,j)
        ans += numw*numb

print(ans)



Measured memory_bytes: 148196
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
int a,s,d,f,g;
scanf("%d %d %d",&a,&s,&d);
if(a<=d&&s>=d)	printf("Yes\n");
else printf("No\n");
return 0;
}

Measured memory_bytes: 128
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long

using namespace std;
const int MAXN=101,mod=1000000007;
int n,m,K;
int dp[1<<8][10][101];
int p[1<<8],cnt;
int main()
{
	scanf("%d%d%d",&n,&m,&K);
	int SJ=(1<<(m-1));
	for(int i=0;i<SJ;i++)
	{
		if(!(i&(i<<1)))
		{
			p[++cnt]=i;
		}
	}
	
	dp[0][1][0]=1;
	
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=cnt;j++)
		{
			int u=p[j];
			for(int k=1;k<=cnt;k++)
			{
				int v=p[k];
				for(int loc=1;loc<=m;loc++)
				{
					if((1<<(loc-1))&v)
					{
						dp[v][loc+1][i]=(dp[v][loc+1][i]+dp[u][loc][i-1])%mod;
						continue;
					}
					if((1<<(loc-2))&v)
					{
						dp[v][loc-1][i]=(dp[v][loc-1][i]+dp[u][loc][i-1])%mod;
						continue;
					}
					dp[v][loc][i]=(dp[v][loc][i]+dp[u][loc][i-1])%mod;
				}
			}
		}
	}
	int ANS=0;
	for(int i=0;i<SJ;i++)
	{
		ANS=(ANS+dp[i][K][n])%mod;
	}
	printf("%d\n",ANS);
	
	
	return 0;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

struct Point {
  ll x;
  ll y;
};

// ====================================================================

int main() {
  ll n;
  cin >> n;
  vector<Point> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i].x >> v[i].y;
  }

  int ans = 0;
  for (int s = 0; s < n; s++) {  // 全ての差を全探索する
    for (int t = 0; t < n; t++) {
      if (s == t) continue;
      Point d;
      d.x = v[t].x - v[s].x;
      d.y = v[t].y - v[s].y;
      int count = 0;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          if (i == j) continue;
          if (v[j].x - v[i].x == d.x && v[j].y - v[i].y == d.y) count++;
        }
      }
      ans = max(ans, count);
    }
  }

  cout << n - ans << endl;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for(int i=0; i<N; i++){
    cin >> H.at(i);
  }
  sort(H.begin(), H.end());
  int Ans=1000000000;
  for(int i=0; i<N-K+1; i++){
    Ans=min(Ans, H.at(i+K-1)-H.at(i));
  }
  cout << Ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <map>

using namespace std;
const int MAXN = 1e5 + 10;
const int MOD = 1e9+7;

int n, m;
int a[MAXN];
int dp[MAXN];
map<int, bool> map_;

void solve() {
  for (int i=0;i<m;i++) {
    map_[a[i]] = true;
  }
  dp[0] = 1;
  for (int i=0;i<n;i++) {
    if (!map_[i]) {
      dp[i+1] = dp[i+1] + dp[i] % MOD;
      dp[i+2] = dp[i+2] + dp[i] % MOD;
    }
  }
  cout << (dp[n] % MOD) << endl;
}

int main() {
  cin >> n >> m;
  for (int i=0;i<m;i++) {
    cin >> a[i];
  }
  solve();
}


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

int main(){
    int N,M;
    cin >> N >> M;
    int s[M],c[M];
    for ( int i = 0; i < M; ++i){
        cin >> s[i] >> c[i];
    }
    int num = -1;
    
    if ( N == 1 ){
        bool flag2 = false;
        for ( int num1 = 0; num1 < 10; ++num1){
            /* 条件に合うものを探す */
            int flag = 0;
            for ( int i = 0; i < M ; ++i ){
                if ( ( s[i] == 1 and num1 == c[i] )){
                    flag += 1;
                }
            }
            if ( flag == M ){
                num = num1;
                flag2 = true;
                break;
            }
        }
    } else if ( N == 2 ){
        bool flag2 = false;
        
        for ( int num10 = 1; num10 < 10; ++num10){
            for ( int num1 = 0; num1 < 10; ++num1){
                /* 条件に合うものを探す */
                int flag = 0;
                for ( int i = 0; i < M ; ++i ){
                    if (( s[i] == 1 and num10 == c[i] )
                        or ( s[i] == 2 and num1 == c[i] )){
                        flag += 1;
                    }
                }
                if ( flag == M ){
                    num = 10 * num10 + num1;
                    flag2 = true;
                    break;
                }
            }
            if ( flag2 ) break;
        }
                
            
    } else {
        bool flag2 = false;
        for ( int num100 = 1; num100 < 10; ++num100){
            for ( int num10 = 0; num10 < 10; ++num10){
                for ( int num1 = 0; num1 < 10; ++num1){
                    /* 条件に合うものを探す */
                    int flag = 0;
                    for ( int i = 0; i < M ; ++i ){
                        if ( ( s[i] == 1 and num100 == c[i] )
                            or ( s[i] == 2 and num10 == c[i] )
                            or ( s[i] == 3 and num1 == c[i] )){
                            flag += 1;
                        }
                    }
                    if ( flag == M ){
                        num = 100 * num100 + 10 * num10 + num1;
                        flag2 = true;
                        break;
                    }
                }
                if ( flag2 ) break;
            }
            if (flag2 )break;
        }
    }
    
    cout << num << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#define ll long long
#define N 200010
using namespace std;
int n,a[N],b[N],c[N],d[N],ans;
int read()
{
	int x=0,f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x*f;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	for(int i=1;i<=n;i++)
		b[i]=read();
	for(int k=0;k<=28;k++)
	{
		for(int i=1;i<=n;i++)
			c[i]=a[i]&((1<<(k+1))-1),d[i]=b[i]&((1<<(k+1))-1);
		sort(d+1,d+n+1);	
		for(int i=1;i<=n;i++)
		{
			int l1,r1,l2,r2;
			l1=lower_bound(d+1,d+n+1,(1<<k)-c[i])-d;
			r1=lower_bound(d+1,d+n+1,(1<<(k+1))-c[i])-d-1;
			l2=lower_bound(d+1,d+n+1,3*(1<<k)-c[i])-d;
			r2=lower_bound(d+1,d+n+1,(1<<(k+2))-c[i])-d-1;
			if((r1-l1+r2-l2+2)&1) ans^=(1<<k);
			//cout<<l1<<' '<<r1<<' '<<l2<<' '<<r2<<endl;
		}
		//puts("");
	}
	printf("%d",ans);	
	return 0;
}



Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n,c[10],i;
	string s;
	cin>>n;
	c[0]=c[1]=c[3]=c[2]=0;
	for(i=0;i<n;i++) {
		cin>>s;
		if(s=="AC") c[0]++;
		if(s=="WA") c[1]++;
		if(s=="TLE") c[2]++;
		if(s=="RE") c[3]++;
	}
	cout<<"AC x "<<c[0]<<"\n";
	cout<<"WA x "<<c[1]<<"\n";
	cout<<"TLE x "<<c[2]<<"\n";
		cout<<"RE x "<<c[3]<<"\n";
}

Measured memory_bytes: 3648
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; i < (n); i++)

int main(){
  int a, b, s[4] = {};
  rep(i, 3){
    cin >> a >> b;
    s[a - 1]++;
    s[b - 1]++;
  }
  rep(i, 4) if(s[i] == 3){
    puts("NO");
    return 0;
  }
  puts("YES");
  
}	

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
const ll mod = 998244353;
#define int ll
int n, W;
int w[102], v[102], dp[100002][2];

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n>>W;
    for(int i=1; i<=n; i++)cin>>w[i]>>v[i];
    for(int i=1; i<=n; i++){
        for(int xd=w[i]; xd<=W; xd++){
            dp[xd][1]=max(dp[xd][0], dp[xd-w[i]][0]+v[i]);
        }
        for(int xd=w[i]; xd<=W; xd++){
            dp[xd][0]=dp[xd][1];
        }
    }
    cout<<dp[W][1];
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>

int main()
{
  int n;
  std::cin >> n;
  
  std::vector<int> vec(n);
  for(int i=0; i < n; ++i)
  {
    std::cin >> vec[i];
  }

  int sum = 0;
  for(const int i : vec)
  {
  	sum += i;
  }

  for(const int i : vec)
  {
    if(i >= sum - i)
    {
    	std::cout << "No" << std::endl;
     	return 0;
    }
  }
  std::cout << "Yes" << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
//#include <unistd.h>
//#include <iostream>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
//#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
    fio();   
    string s;
    cin >> s;
    int q;
    cin >> q;
    bool front = true;
    string head, tail;
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            front = not front;
        }
        else {
            int f;
            cin >> f;
            char c;
            cin >> c;
            if (f == 1) {
                if (front) head += c;
                else tail += c;
            }
            else {
                if (front) tail += c;
                else head += c;
            }
        }
    }
    if (front) {
        reverse(all(head));
        cout << head << s << tail << endl;
    }
    else {
        reverse(all(tail));
        reverse(all(s));
        cout << tail << s << head << endl;
    }
}

Measured memory_bytes: 1040
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <limits>
#include <set>
#include <map>

int main()
{
    int k{}, n{};
    std::cin >> k >> n;
    std::vector<int> pt(n);
    for (int i = 0; i < n; i++) {
        std::cin >> pt[i];
    }
    int result = pt.back() - pt.front();
    for (int i = 0; i < n - 1; i++) {
        const auto tmp = pt[i] - (pt[i + 1] - k);
        result = std::min(result , tmp);
    }
    std::cout << result << std::endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int V,E,S;
LL d[100001];
typedef pair<LL,int> P;
vector<P> G[100001];
int main(){
	cin>>V>>E>>S;
	REP(i,E){
	    int a,b;
	    LL c;
	    cin>>a>>b>>c;
	    G[a].push_back(make_pair(c,b));
	    //G[b].push_back(make_pair(c,a));
	}
        REP(i,100001){
            d[i]=10e12;
        }
        priority_queue<P,vector<P>,greater<P> >q;
        q.push(make_pair(0,S));
        while(!q.empty()){
           P p=q.top();q.pop();
           LL cost=p.first;
           LL num=p.second;
           if(d[num]<cost)continue;
                      //cout<<num<<"aaa"<<cost<<endl;
           d[num]=cost;
           REP(i,G[num].size()){
               if(d[num]+G[num][i].first<d[G[num][i].second]){
                  q.push(make_pair(d[num]+G[num][i].first,G[num][i].second));
                  d[G[num][i].second]=d[num]+G[num][i].first;
               }
           }
        }
        REP(i,V){
            if(d[i]==10e12){
               cout<<"INF"<<endl;
            }else{
               cout<<d[i]<<endl;
            }
        }
	return(0);
}

Measured memory_bytes: 19500
# E - This Message Will Self-Distruct in 5s

n = int(input())
a = list(map(int, input().split()))
assert len(a) == n

# Ai + Aj == j - i
# Aj - j == -Ai - i

# Aj - j の各値の個数
diff = {}
for j in range(n):
    x = a[j] - (j+1)
    if x not in diff:
        diff[x] = 0
    diff[x] += 1

# 各Aiについて Aj - j == -Ai - i + 1 となるjの個数を数える
count = 0
for i in range(n):
    diff[a[i] - (i+1)] -= 1  # i自身を取り除く
    x = -a[i] - (i+1)
    if x in diff:
        count += diff[x]

print(count)


Measured memory_bytes: 40320
import collections

N, M = map(int, input().split())

ans = [0] * (N + 1)
parent = [0] * (N + 1)
parent[0] = N+M
child = [[] for i in range(N+1)]
deq = collections.deque()

for i in range(N+M-1):
    p, c = map(int, input().split())
    parent[c] += 1
    child[p].append(c)
root = parent.index(min(parent))
deq.append(root)
while len(deq) > 0:
    v = deq.pop()
    if len(child[v]) > 0:
        for u in child[v]:
            if parent[u] == 1:
                deq.appendleft(u)
                ans[u] = v
            else:
                parent[u] -= 1
for i in range(1,N+1):
    print(ans[i])

Measured memory_bytes: 20668
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

map<int64_t,int> prime_factor(int64_t n){
    map<int64_t,int>ret;
    for(int64_t i=2;i*i<=n;i++){
        while(n%i==0){
            ret[i]++;
            n/=i;
        }
    }
    if(n!=1)ret[n]=1;
    return ret;
}

struct Combination{
    const int MOD = 1000000007;
    vector<ll> fac,finv,inv;
    Combination(const int MAX):fac(MAX),finv(MAX),inv(MAX){
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    long long calc(int n, int k){
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
};
const int MOD = 1000000007;

int main(){
    int N,M;cin >> N >> M;
    struct Combination com(110000);
    map<int64_t,int> pf = prime_factor(M);
    ll res = 1;
    for(auto x:pf){
        res = (res*com.calc(x.second+N-1,x.second))%MOD;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    string s;
    cin >> s;
    int n = sz(s) + 1;
    vi a(n, -1);
    heap<pii> q;
    s = ">" + s + "<";
    rep(i, 0, n - 1 + 1) {
        if (s[i] == '>' && s[i + 1] == '<') {
            q.push({0, i});
            a[i] = 0;
            dump(i);
        }
    }
    while (sz(q)) {
        int h, idx;
        tie(h, idx) = q.top(); q.pop();
        dump(h, idx);
        if (idx > 0 && s[idx] == '>') {
            if (chmax(a[idx - 1], a[idx] + 1)) {
                q.push({a[idx - 1], idx - 1});
            }
        }
        if (idx < n - 1 && s[idx + 1] == '<') {
            if (chmax(a[idx + 1], a[idx] + 1)) {
                q.push({a[idx + 1], idx + 1});
            }
        }
    }
    dump(a);

    int ans = 0;
    rep(i, 0, n) {
        ans += a[i];
    }
    cout << ans << endl;
    return (0^_^0);
}



Measured memory_bytes: 11692
#include<iostream>
#include<set>
#include<vector>
#include<string>
using namespace std;
 
int main(){
  int N; cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) cin >> S[i];
  
  set<string> Set;
  for (int i = 0; i < N; i++) Set.insert(S[i]);
  
  cout << Set.size() << endl;
}

Measured memory_bytes: 24956
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<P> vp;
typedef vector<bool> vb;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

int n;
ll ans=0;
vi a,b;

int main(){
	cin>>n;
	a=vi(n);
	b=vi(n);
	set<int> st{-1,n};
	for(auto i=a.begin();i!=a.end();i++){
		cin>>*i;
		b[*i-1]=i-a.begin();
	}
	int l,r;
	for(auto i=b.begin();i!=b.end();i++){
		auto it=st.insert(*i).first;
		it--;
		l=*it;
		it++;
		it++;
		r=*it;
		ans+=(ll)(i-b.begin()+1)*(*i-l)*(r-*i);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
#define N 300000
using namespace std;

int main(){
  int p[N];
  int v[N];
  int vS=1;
  int pS=0;
  unsigned int j;

  v[0]=6;
  for( int i=7;i<N;i+=7 ){
    v[vS++]= i+1;
    v[vS++]=i+6;
  }

  for( int i=0;i<vS;i++ ){
    for( j=0;j<pS;j++ )
      if( !(v[i]%p[j]) ) break;
    if( j==pS )
      p[pS++] = v[i];
  }

  int n;
  while( cin>>n && (n-1) ){
    cout << n << ":";

    for( int i=0,len=n/6+1;p[i]<len;i++ ){
      if( n%p[i]==0 ){
	cout << " " << p[i];
      }
    }
    if( binary_search( p,p+pS,n ) )
      cout << " " << n;

    cout << endl;
  }
  

  return 0;
}

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

int n,m;

const int MAXN = 10010;
int par[MAXN],sz[MAXN];
vector<int> comps,orders,grf[MAXN],rev_grf[MAXN];
bool visited[MAXN];

int findcc(int x){
    return (x==par[x]) ? x : par[x]=findcc(par[x]);
}
bool unite(int a,int b){
    a = findcc(a);
    b = findcc(b);
    if(a==b){return false;}
    if( sz[a]<sz[b]){ swap(a,b);}
    par[b] = a;
    sz[a]+=sz[b];
    return true;
}

void dfs(int u){
    visited[u]=true;
    for(auto nbr: grf[u]){
        if(!visited[nbr]){
            dfs(nbr);
        }
    }
    orders.push_back(u);
}

void dfs2(int u){
    visited[u]=true;
    comps.push_back(u);
    for(auto nbr: rev_grf[u]){
        if(!visited[nbr]){
            dfs2(nbr);
        }
    }
}

void init()
{
    for(int i=0; i<n; i++){
        par[i]=i; sz[i]=1;
    }
    memset(visited,false,sizeof visited);
    for(int i=0; i<n; i++){
        if(!visited[i]){
            dfs(i);
        }
    }
    memset(visited,false,sizeof visited);
    
    while(!orders.empty()){
        int x = orders.back(); orders.pop_back();
        if(!visited[x]){
            comps.clear();
            dfs2(x);
            for(auto c: comps){
                unite(x,c);
            }
        }
    }
}

void top_sort()
{
    memset(visited,false,sizeof visited);
    for(int i=0; i<n; i++){
        if(!visited[i]){
            dfs(i);
        }
    }
    for(int i=n-1; i>=0; i--){
        cout<< orders[i] <<"\n";
    }   
}

int main() {
    // freopen("./input.txt","r",stdin);
    // freopen("./output.txt","w",stdout);

    cin>>n>>m;
    for(int i=0; i<m; i++){
        int x,y; cin>>x>>y;
        grf[x].push_back(y);
        rev_grf[y].push_back(x);
    }
    top_sort();
    
    
}


Measured memory_bytes: 4064
N = int(input())
h = list(map(int, input().split()))
dp = [10**10 for _ in range(N)]
dp[0] = 0

for i in range(N-1):
    if(i+2 > N-1):
        dp[i+1] = min(dp[i+1], dp[i]+abs(h[i+1]-h[i]))
    else:         
        dp[i+2] = min(dp[i+2], dp[i]+abs(h[i+2]-h[i]))
        dp[i+1] = min(dp[i+1], dp[i]+abs(h[i+1]-h[i]))

print(dp[-1])  

Measured memory_bytes: 20580
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<vector<char>> vec(2,vector<char>(N));
  for(int i=0; i<2; i++){
    for(int j=0; j<N; j++){
      cin >> vec.at(i).at(j);
    }
  }
  int64_t ans = 1;
  bool yoko = true;
  bool prev_yoko = true;
  int i = 0;
  if(vec.at(0).at(0) != vec.at(1).at(0)){
    ans = 2;
    i = 2;
  }
  else{
    prev_yoko = false;
    i = 1;
  }
  
  while(i < N){
    if(vec.at(0).at(i) != vec.at(1).at(i)){
      if(prev_yoko){
        ans *= 3;
        ans %= 1000000007;
      }
      else{
        ans *= 2;
        ans %= 1000000007;
        prev_yoko = true;
      }
      i += 2;
      continue;
    }
    else{
      if(prev_yoko){
        prev_yoko = false;
      }
      else{
        ans *= 2;
        ans %= 1000000007;
      }
      i++;
      continue;
    }
  }    
  cout << (ans * 3) % 1000000007 << endl; 
}

Measured memory_bytes: 256
#{1, 2, ..., n} の順列 p = {p1,p2, ..., pn } があります。
#以下の条件を満たすような pi (1<i<n) がいくつあるかを出力してください。
#pi−1, pi, pi+1 の 3 つの数の中で、pi が 2 番目に小さい。

n = int(input())
p = list(map(int, input().split()))
ans=0
for i in range(1,n-1):
    if p[i-1]<=p[i]<p[i+1] or p[i+1]<=p[i]<p[i-1] :
        ans+=1

    else:
        ans==ans
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    int d,x;
    cin >> d >> x;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        x+=(d+a[i]-1)/a[i];
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,x,y,a[222222]={0};
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>x>>y;
    if(x==1) a[y]++;
    if(y==n) a[x]++;
    if(a[x]==2||a[y]==2){
      cout<<"POSSIBLE"<<endl;
      return(0);
    }
  }
  cout<<"IMPOSSIBLE"<<endl;
  return(0);
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }

int main(){
  int m,f,r;
  REP(count,50){
    cin >> m >> f >> r;
    if(m==-1 && f==-1 && r==-1){break;}
    string g = "nan";
    if(m==-1 || f==-1){ g = "F";}
    else if( m+f>=80){ g = "A";}
    else if( m+f>=65){ g = "B";}
    else if( m+f>=50){ g = "C";}
    else if( m+f>=30){
      if(r>=50){ g = "C";}
      else{ g = "D";}
    }else{
      g = "F";
    }
    cout << g <<"\n";
  }
}


Measured memory_bytes: 3092
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset> 

using namespace std;

typedef vector<vector<int>> matrix;
struct edge {
	int p, q, w;
	const bool operator<(const edge& right) const {
		return w < right.w;
	}
};
const int INF = (1 << 30);

void pushToQueue(queue<int>&q, bitset<100> &b, int to);
bool isASpanningTree(const int l, const int h, const int n, const vector<edge> &e);

int solve();

int main(void) {

	while (solve()){}

	return 0;

}

void pushToQueue(queue<int>&q, bitset<100> &b, int to) {
	if (b.test(to) == false) {
		b.set(to);
		q.push(to);
	}
}

bool isASpanningTree(const int l, const int h, const int n, const vector<edge> &e) {

	if (l > h) { return false; }
	bitset<100> visited;
	visited.reset();
	queue<int> q;
	q.push(0);
	visited.set(0);

	while (q.empty() == false && visited.count() < n) {

		int p = q.front();
		q.pop();
		for (int i = l; i <= h; i++) {
			if (e[i].p == p) {
				pushToQueue(q, visited, e[i].q);
			} else if (e[i].q == p) {
				pushToQueue(q, visited, e[i].p);
			}
		}

	}
	return visited.count() >= n;
}

/*
	??\???
	->	???????????????????????????
	->	????°????????????????????????¢?´¢
	->  ?????§???????????????????????¢?´¢
	->	????????¢?´¢???????¨???§O(V)??§??¨?????¨?????????????????????
*/

int solve() {

	int n,m;
	cin >> n >> m;
	if (!(n|m)){ return 0; }
		
	vector<edge> e(m);

	for (int i = 0; i < m; i++){
		cin >> e[i].p >> e[i].q >> e[i].w;
		e[i].p--;
		e[i].q--;
	}
	sort(e.begin(), e.end());

	//????°????????????¢?´¢
	int ans = INF;
	for (int i = 0; i < m; i++) {
		int low = i, high = m, mid;
		do {
			mid = (low + high) / 2;
			if ( mid-i+1 >= n-1 && isASpanningTree(i, mid, n, e)) {
				high = mid;
				ans = min(ans, e[mid].w - e[i].w);
			} else {
				low = mid;
			}
		} while (abs(high - low) > 1);
	}

	if (ans < INF)
		cout << ans << endl;
	else
		cout << -1 << endl;

	return 1;
}

Measured memory_bytes: 3068