akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<typename T>
void print(T &arr){
    ll sz = sizeof(arr)/sizeof(arr[0]);
    for(int i = 0;i < sz-1;i++){cout << arr[i] << ' ';}
    cout << arr[sz-1] << endl;
}


int main(){
    ll n; cin >> n;
    vector<ll> l(n);
    rep(i,n) cin >> l[i];
    sort(l.begin(), l.end());
    ll res = 0;
    rep(i,n)rep(j,n){
        if(i >= j)continue;
        ll a = l[i], b = l[j];
        // ll it = lower_bound(l.begin(), l.end(),a+b) - upper_bound(l.begin(), l.end(), b-a);
        ll low = upper_bound(l.begin(), l.end(),b-a) - l.begin();
        ll high = lower_bound(l.begin(), l.end(), a+b) - l.begin();
        ll it = high - low;
        if(b-a < a)it--;
        if(b-a < b)it--;
        // print(a,b,it, low, high);
        res += it;
    }
    cout << res / 3 << endl;
    return 0;
}

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

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;

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

  vector<string> s(N);

  for (int i = 0; i < N; i++) {
    string temp;
    cin >> temp;

    sort(temp.begin(),temp.end());
    s[i] = temp;
  }

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

  ll ans = 0;
  ll temp = 1;
  for (int i = 0; i < N - 1; i++) {
    if (s[i] == s[i+1]) {
      ans += temp;
      temp++;
    } else {
      temp = 1;
    }
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 5760
#include<iostream>
#include<list>
#include<cstring>

using namespace std;

int main()
{
    int n;
    cin >> n;
    list<int> L;
    char command[12];
    int key;

    for( int i = 0; i < n; i++)
    {
        cin >> command;
        if( strcmp( command, "insert" ) == 0 )
        {
            cin >> key;
            L.push_front( key );
        }
	else if( strcmp( command, "delete" ) == 0 )
        {
            cin >> key;
            for( list<int>::iterator j = L.begin() ; j != L.end(); j++)
	    {
                if( key == *j )
                {
                    L.erase(j);
                    break;
                }
	    }
        }
        if( strcmp( command, "deleteFirst" ) == 0 )
        {
            L.pop_front();
        }
        if( strcmp( command, "deleteLast" ) == 0 )
        {
            L.pop_back();
        }
    }

    for( list<int>::iterator i = L.begin(); i != L.end(); )
    {
        cout << *i;
	if( ++i != L.end() )
            cout << ' ';
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 34304
#include <stdio.h>
#include <string.h>
int main(void){
    char s[100];
    scanf("%s",s);
    int l = strlen(s);
    for (int i=0;i<l;i++){
        if (i%2==0){
            if (s[i]=='L'){
                printf("No");
                return 0;
            }
        }
        else {
            if (s[i]=='R'){
                printf("No");
                return 0;
            }
        }
    }
    printf("Yes");
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        sc.close();

        if (t.startsWith(s)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

        return;
    }
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;

  ll ans = 0;
  REP(i, n){
    ll now = i+1;
    ll nowCount = 0;
    while(now != 0){
      now /= 10;
      nowCount++;
    }

    if(nowCount % 2 == 1)
      ans++;
  }

  cout << ans << endl;
      
  
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<long long>> vvl;
#define out(x) cout<<x<<"\n";
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}
 
ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}

using namespace std;

void solve()
{
	int n;
	cin >> n;
	map<string, int> mp;
	rep(i,n){
		string s;
		cin >> s;
		mp[s]++;
	}
	cout << mp.size();
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 19272
#include<iostream>
using namespace std;
int main(){
	
	int n,a[12],ans=1,ot=1;
	
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		ans*=3;
		if(a[i]%2==0)ot*=2;
	}
	ans-=ot;
	cout<<ans<<endl;
		
	return 0;	
}

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

typedef long long LL;
typedef pair<LL, LL> PII;
typedef vector<LL> VI;
typedef vector<double> VD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(LL i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(LL i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (LL)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int a[100005];
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	int ans = 0;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	for(int i = 1; i <= n + 1; i++)
		ans += abs(a[i] - a[i - 1]);
	for(int i = 1; i <= n; i++)
	{
		ans -= abs(a[i] - a[i - 1]);
		ans -= abs(a[i + 1] - a[i]);
		ans += abs(a[i + 1] - a[i - 1]);
		cout << ans << endl;
		ans += abs(a[i] - a[i - 1]);
		ans += abs(a[i + 1] - a[i]);
		ans -= abs(a[i + 1] - a[i - 1]);
	}
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}


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

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

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define zeroend __builtin_ctz
#define ones __builtin_popcount
#define ends "\n"
#define space ' '
typedef long long ll;
typedef pair<int, int> pii;

/*
void solve(int i, int j, string s){
	if(i==0)
		ans.insert(s2.substr(0, j)+s);
	else if(j==0)
		ans.insert(s1.substr(0, i)+s);
	else if(s1[i-1]==s2[j-1])
		solve(i-1, j-1, s1[i-1]+s);
	else{
		if(dp[i-1][j]<=dp[i][j-1])
			solve(i-1, j, s1[i-1]+s);
		if(dp[i-1][j]>=dp[i][j-1])
			solve(i, j-1, s2[j-1]+s);
	}
}*/


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

	for(int i=1; i<n; ++i){
		for(int j=0; j<i; ++j){
			if(a[j]>a[i]&&low[i]<high[j]+1)
				low[i]=high[j]+1;
			else if(a[j]<a[i]&&high[i]<low[j]+1)
				high[i]=low[j]+1;
		}
		ans=max({ans, low[i], high[i]});
	}

	cout << ans << ends;


*/

const int N = 3000, M = 1e9+7;

ll dp[N+1][N+1];
//array<ll, 3> dp;
//set<string> ans;
//vector<int> low(N, 1), high(N, 1);
ll a[N];

int n, m;

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

	for(int i=n-1; i>=0; --i)
		for(int j=i; j<=n-1; ++j)
			if(i==j) dp[i][j]=a[i];
			else dp[i][j]=max(a[i]-dp[i+1][j], a[j]-dp[i][j-1]);
		
	cout << dp[0][n-1] << ends;

}

Measured memory_bytes: 49756
#S = input()
#S, W2 = input().split()
#I = int(input())
S, W = map(int, input().split())
#L = list(map(int, input().split()))

#D1 = []
#D2 = [[]] * 4
#D1 = [0] * 5
#D2 = [[0] * 5 for i in range(4)]
#D3 = [[[0] * 5 for i in range(4)] for i in range(3)]

print( "unsafe" if W >= S else "safe")


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

struct Node {
    int index = -1;
    int depth = -1;
    int parent = -1;
    int *child;
    int ccnt = 0;
    int type = 0;
};

void depth(Node *node, int x, int d) {
    node[x].depth = d;
    for (int i = 0; i < node[x].ccnt; ++i) {
        depth(node, node[x].child[i], d+1);
    }
}

int main() {
    int n, x, root;
    string type[] = {"leaf", "internal node", "root"};
    cin >> n;
    Node a[n];
    for (int i = 0; i < n; ++i) {
        cin >> x;
        cin >> a[x].ccnt;
        a[x].index = x;
        a[x].child = new int[a[x].ccnt];
        for (int j = 0; j < a[x].ccnt; ++j) {
            a[x].type = 1;
            cin >> a[x].child[j];
            a[a[x].child[j]].parent = x;
        }
    }
    
    for (auto& i : a) {
        if (i.parent < 0) {
            i.type = 2;
            root = i.index;
        }
    }
    depth(a, root, 0);
    
    for (auto& i : a) {
        cout << "node " << i.index << ": ";
        cout << "parent = " << i.parent << ", ";
        cout << "depth = " << i.depth << ", ";
        cout << type[i.type] << ", ";
        cout << "[";
        for (int j = 0; j < i.ccnt-1; ++j) {
            cout << i.child[j] << ", ";
        }
        if (i.ccnt) { 
            cout << i.child[i.ccnt-1] << "]" << endl;
        } else {
            cout << "]" << endl;
        }
    }
    
    return 0;
}

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

int xa[10];
int ya[10];
int xxn = 0, yyn = 0;

inline int xPower(int n)
{
	int ret = 0;

	for( int i = 0; i < xxn; i++ ) {
		if( xa[i] > n ) {
			if( i > 0 ) {
				ret = xa[i-1];
			}
			break;
		}
	}
	return ret;
}

inline int yPower(int n)
{
	int ret = 0;

	for( int i = 0; i < yyn; i++ ) {
		if( ya[i] > n ) {
			if( i > 0 ) {
				ret = ya[i-1];
			}
			break;
		}
	}
	return ret;
}

int count( int n, int i )
{
	if( n < 6 ) {
		return i + n;
	}
	int cnt = 10000, cnt2 = 10000;
	int x = xPower( n );
	if( x != 0 ) {
		cnt = count(n - x, i + 1);
	}
	int y = yPower( n );
	if( y != 0 ) {
		cnt2 = count(n - y, i + 1);
	}
	if( cnt < cnt2 ) {
		return cnt;
	}
	else {
		return cnt2;
	}
}

int main() {
	int n;

	cin >> n;

	int x = 9;
	for( int i = 0; i < 10; i++) {
		xa[i] = x;
		x *= 9;
		xxn++;
		if(xa[i] > n) {
			break;
		}
	}
	int y = 6;
	for( int i = 0; i < 10; i++) {
		ya[i] = y;
		y *= 6;
		yyn++;
		if(ya[i] > n) {
			break;
		}
	}

	int cnt = count( n, 0 );

	cout << cnt << "\n";

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int a = scn.nextInt();
		for(int i=1;i<10;i++) {
			if(a%i==0 && (a/i<=9 && a/i>=1)) {
				System.out.println("Yes");
				return;
			}
		}System.out.println("No");
	}
}

Measured memory_bytes: 27036
#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 INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
	int A[5];
	int min[5];
	int max[5];
  	vector<int> v{10, 10};
	int minimam, tmp;
  
  	REP(i, 5){
    	cin >> A[i];
      	min[i] = A[i] % 10;
    }
  	
  	REP(i, 5){
    	tmp = (A[i] + 10 - 1) / 10;
      	max[i] = tmp * 10;
    }
  
  	REP(i, 5){
      if(max[i] != A[i]) v.push_back(min[i]);
    }
  
	minimam = *min_element(ALL(v));
  
	cout << max[0] + max[1] + max[2] + max[3] + max[4] - 10 + minimam <<endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n+1), b(n);
  rep(i, n+1) cin >> a[i];
  rep(i, n) cin >> b[i];
  long ans = 0;
  for (int i = n-1; i >=0 ; i--) {
    int c = std::min(b[i], a[i+1]);
    ans += c;
    b[i] -= c;
    a[i+1] -= c;
    c = std::min(b[i], a[i]);
    ans += c;
    b[i] -= c;
    a[i] -= c;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
package main

import (
	"bufio"
	"os"
	"strconv"
	"sort"
	"fmt"
)

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	if !sc.Scan() {
		panic("failed scan string")
	}
	return sc.Text()
}

func nextInt() int {
	if !sc.Scan() {
		panic("failed scan int")
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

type pair struct {
	start int
	end   int
}

func main() {
	sc.Split(bufio.ScanWords)

	// start -> id map
	startMap := make(map[int]map[int]struct{})
	// end -> id map
	endMap := make(map[int]map[int]struct{})
	idMap := make(map[int]pair)

	_ = nextInt()
	m := nextInt()

	for i := 0; i < m; i ++ {
		start := nextInt()
		end := nextInt() - 1
		if _, ok := startMap[start]; ok {
			startMap[start][i] = struct{}{}
		} else {
			startMap[start] = map[int]struct{}{i: {}}
		}

		if _, ok := endMap[end]; ok {
			endMap[end][i] = struct{}{}
		} else {
			endMap[end] = map[int]struct{}{i: {}}
		}

		idMap[i] = pair{start: start, end: end}
	}

	startList := make([]int, len(startMap))
	var i int
	for start, _ := range startMap {
		startList[i] = start
		i++
	}
	sort.Ints(startList)

	endList := make([]int, len(endMap))
	i = 0
	for end, _ := range endMap {
		endList[i] = end
		i++
	}
	sort.Ints(endList)

	var count int
	var currentEnd int
	for _, start := range startList {
		if start <= currentEnd {
			ids := startMap[start]
			for id, _ := range ids {
				delete(idMap, id)
			}
			continue
		}

		var found bool
	endloop:
		for ; len(endList) > 0; {
			end := endList[0]
			endList = endList[1:]
			ids := endMap[end]
			for id, _ := range ids {
				if _, ok := idMap[id]; ok {
					found = true
					currentEnd = end
					break endloop
				}
			}
		}
		if !found {
			break
		}

		ids := startMap[start]
		for id, _ := range ids {
			delete(idMap, id)
		}
		count++
	}

	fmt.Println(count)
}


Measured memory_bytes: 51072
N,_=gets.split(" ").map{|i| i.to_i}
A,B=gets.split(" ").map{|i| i.to_i}
P=gets.split(" ").map{|i| i.to_i}

puts [P.count{|n| n <= A},
P.count{|n| A < n && n <= B},
P.count{|n| B < n}].min



Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int r,menseki=1;
int main()
{
  cin>>r;
  int squarer1=1;
  for(int i=1;i<=2;i++)
  {
    squarer1*=r;
  }
  menseki=3*squarer1;
  cout<<menseki;
  return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
ans = 0
cnt = 0

for i in range(1,m+1):
    for j in range(n):
        for k in range(1,a[j][0]+1):
            if a[j][k] == i:
                cnt += 1
                break
    if cnt == n:
        ans += 1
    cnt = 0

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  ll M,N;
  cin>>M>>N;
  ll A=max(M,N);
  ll B=min(M,N);
  ll X;
  if(A==1&&B==1) X=1;
  else if(B==1) X=A-2;
  else X=(A-2)*(B-2);
  cout<<X;
return 0;}

Measured memory_bytes: 3632
n,k=gets.split.map(&:to_i)
dp=[1]*n
dp[0]=1
k.times{dp[gets.to_i-1]=0}

1.upto(n-1) do |i|
    next if dp[i]==0
    b = dp[i-1]
    bb= dp[i-2]

    dp[i]=(b+bb)%(10**9+7)
end

p dp[n-1]%(10**9+7)

Measured memory_bytes: 2812
import java.util.*;

public class Main {


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

        HashMap<Character, Integer> ans = new HashMap<>();

        String s = sc.nextLine();

        for(int i = 0; i < s.length(); i++){
            if(ans.containsKey(s.charAt(i))){
                ans.put(s.charAt(i), ans.get(s.charAt(i)) + 1);
            } else {
                ans.put(s.charAt(i), 1);
            }
        }

        boolean flg = true;
        for(Map.Entry<Character, Integer> e : ans.entrySet()){
            if(e.getValue() != 2){
                flg = false;
                break;
            }
        }

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


        return;
    }
}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void OUT(T t){cout<<t<<"\n";}
template<class T,class... Ts>inline void OUT(T t,Ts... ts){cout<<t<<" ";OUT(ts...);}
template<typename T=int>vector<T>mv(size_t a){return vector<T>(a);}
template<typename T=int,typename... Ts>auto mv(size_t a,Ts... ts){return vector<decltype(mv<T>(ts...))>(a,mv<T>(ts...));}
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type FILL(T&t,const V&v){t=v;}
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type FILL(T&t,const V&v){for(auto &e:t)FILL(e,v);}
constexpr long long INF = 1e18;


signed main(){
	int A,B;
	cin>>A>>B;
	OUT(6-A-B);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[101][100005]={0};

ll knapsack(ll a[][2], ll i ,ll w, ll n){
    if(w<=0) return 0;
    if(i==n) return 0;
    if(dp[i][w]!=0)  return dp[i][w];
    ll op1=INT_MIN;
    if(w-a[i][0]>=0) op1 = a[i][1] + knapsack(a,i+1, w-a[i][0],n);
    ll op2 = knapsack(a,i+1, w, n);
    return dp[i][w] = max(op1,op2);  
}

int main() {
    ll n,w;
    cin>>n>>w;
    //{weight, value}
    ll a[n][2];
    // memset(dp,-1,sizeof dp);
    for(ll i=0; i<n; i++) cin>>a[i][0]>>a[i][1];
    cout<< knapsack(a,0,w,n);
}


Measured memory_bytes: 75464
#include<iostream>

using namespace std;

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

	int A = N / 1000;
	int B = N % 1000 / 100;
	int C = N % 1000 % 100 / 10;
	int D = N % 1000 % 100 % 10;

	if (A == B && B == C || B == C && C == D) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    double J=0,B=0;
    ll n;cin >>n;
    for (int i = 0; i < n; ++i) {
        double x;cin >>x;
        string u;cin >>u;
        if(u=="JPY")J+=x;
        else B+=x;
    }
    B*=380000;
    double ans=J+B;
    cout <<ans <<endl;
    return 0;
}

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

int main(int argc, char const *argv[])
{
	int N;
	int A[51];
	int B[51];
	int C[51];
	int ans = 0;
	cin>>N;
	for(int i=1; i<=N; i++) cin>>A[i];
	for(int i=1; i<=N; i++) cin>>B[i];
	for(int i=1; i<N; i++) cin>>C[i];
	for(int i=1; i<=N; i++){
		if(i<N and A[i] + 1 == A[i+1]){
			ans+= C[A[i]];
		}
		ans += B[i];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp6
{
    class Program
    {
        static void Main()
        {
            var i = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine(Enumerable.Range(1, i[0]).Select(x => new { x, n = x.ToString().Select(c => c - 48).Sum() }).Where(x => i[1] <= x.n && x.n <= i[2]).Sum(x => x.x));
        }
    }
}


Measured memory_bytes: 13524
i,c[50101],n;main(j){for(i=2;i*i<5e4;i++)for(j=i;!c[i]&&j<5e4;c[j+=i]=1);for(;scanf("%d",&j),i=j;n=!printf("%d\n",n))for(i=2;i<=j/2;n+=!(c[j-i]+c[i++]));exit(0);}

Measured memory_bytes: 600
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

n, m = input_a
# グラフ構造を格納する二次元配列を宣言(pathのindexが部屋番号を表し、その中の配列が到達可能な部屋を表す)
# 下記の書き方でないと、同じ配列オブジェクトを参照することになるので注意
# 宣言する配列は部屋番号が1から始まるので+1する
path = Array.new(n + 1).map{Array.new}
m.times do |i|
  # グラフは双方向で行来可能な無向グラフなので部屋番号に対するpushは双方向で行う
  index, to = input_a
  path[index].push(to)
  path[to].push(index)
end

# 到達したことのある頂点を記録する配列。到達していない場合は-1
district = Array.new(n + 1, -1)
# 発見済みで、今後探索する頂点を格納するqueue
queue = []

# 出発地点となる最初の部屋を指定。今回は1番の部屋
queue.push(1)

# queueが空になるまで繰り返す
while !queue.empty?
  # 部屋番号をFIFOで取り出す
  from = queue.shift

  path[from].each do |to|
    # 到達済みの部屋は探索しない
    next if district[to] != -1
    district[to] = from
    queue.push(to)
  end
end

# 配列の無意味な0番目をshiftして削除
district.shift
# 問題は1つ目の部屋への移動回数なので、1つ目の部屋を除外する
district.shift

puts "Yes"
puts district.join("\n")

Measured memory_bytes: 34044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp(a, b) make_pair(a, b)
#define ls (rt << 1)
#define rs (rt << 1 | 1) 
typedef pair<int, int> pii; 
const int mod = 998244353;
template <class T> T lowbit(T x){return ((x)&(-(x)));}
const int maxn = 3000 + 10;
int t, n, a[maxn], f[maxn][maxn], s, ans;
int main()
{
	scanf("%d%d", &n, &s);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= s; ++j)
		{
			f[i][j] = f[i - 1][j];
			if(j == a[i]) f[i][j] = (f[i][j] + i) % mod;
			if(j > a[i]) f[i][j] = (f[i][j] + f[i - 1][j - a[i]]) % mod;
			if(j == s) ans = (ans + f[i][j]) % mod;
		}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
char m[7]={'I','V','X','L','C','D','M'};
int n[7]={1,5,10,50,100,500,1000};
int d[110];
int main(){
	string s;
	while(cin>>s){
		for(int i=0;i<s.size();i++){
			for(int j=0;j<7;j++){
				if(m[j]==s[i])d[i]=n[j];
			}
		}
		int ans=0;
		for(int i=0;i<s.size();i++){
			bool t=false;
			for(int j=i+1;j<s.size();j++){
				if(d[j]>d[i])t=true;
			}
			if(t)ans-=d[i];
			else ans+=d[i];
		}
		cout<<ans<<endl;
	}
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 1176
import java.util.*;

public class Main {
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int x = b - a;
        
        int ans = 0;
        for(int i = 1; i <= x; i++){
            ans = ans + i;
        }
        
        System.out.println(ans - b);
        
        sc.close();
        
    }
}


Measured memory_bytes: 22612
#include<iostream>

using namespace std;

int a[100], n;

void insertionSort(int a[], int n)
{
	for (int i = 1; i < n; i++)
	{
		int v = a[i];
		int j = i - 1;
		while (j >= 0 && a[j] > v)
		{
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;
		for (int j = 0; j < n; j++)
		{
			if (j == n - 1) { cout << a[j] << endl; }
			else { cout << a[j] << " "; }
		}
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < n - 1; i++)
	{
		cout << a[i] << " ";
	}
	cout << a[n - 1] << endl;
	insertionSort(a, n);
    return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    string S;
    cin >> S;
    int N = S.size();
    if(S[0] != 'A') {
        cout << "WA" << endl;
        return 0;
    } else S[0] = 'a';
    int cnt = 0;
    for(int i = 2; i < N-1; i++) {
        if(S[i] == 'C') {
            cnt++;
            S[i] = 'c';
        }
    }
    if(cnt != 1) {
        cout << "WA" << endl;
        return 0;
    }
    REP(i,N) {
        if((int)S[i] < 97) {
            cout << "WA" << endl;
            return 0;
        }
    }
    cout <<"AC" << endl;
}

Measured memory_bytes: 256
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
using namespace std;

const long long INF = 4000000000000000001;
const int inf = 1001001001;
const int MOD = 1000000007;
typedef pair<long long,long long> P;

void chmax(long long &a,long long b){if(a < b) a = b;}
void chmin(long long &a,long long b){if(a > b) a = b;}

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //When end-of-a bit is 1, times simple N.
    if (M & 1) res = (res * N) % MOD;
    return res %= MOD;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

int dist[105][105];
vector<int> A,B;
vector<int> C;

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N,M;cin >> N >> M;
    for(int i = 0;i<N;i++) for(int j = 0;j<N;j++) dist[i][j] = inf;
    for(int i = 0;i<N;i++) dist[i][i] = 0;
    for(int i = 0;i<M;i++){
        int from,to,cost;cin >> from >> to >> cost;from--;to--;
        A.push_back(from),B.push_back(to),C.push_back(cost);
        dist[from][to] = cost;
        dist[to][from] = cost;
    }

    for(int i = 0;i<N;i++){
        for(int j = 0;j<N;j++){
            for(int k = 0;k<N;k++){
                dist[j][k] = min(dist[j][k],dist[j][i]+dist[i][k]);
            }
        }
    }

    int ans = 0;
    for(int i = 0;i<M;i++){
        if(dist[A.at(i)][B.at(i)] < C.at(i)) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
  char ch;
  short int sum;
 
  do {
    sum = 0;
 
    fscanf(stdin, "%c", &ch);
    while (ch != '\n') {
      sum += (short int)atoi(&ch);
      fscanf(stdin, "%c", &ch);
    }
 
    if (sum != 0) {
      fprintf(stdout, "%hd", sum);
      putchar('\n');
    }
  } while (sum != 0);
 
    return 0;
}

Measured memory_bytes: 556
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto &a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

int T;
vector<int> a(3333), b(3333);
vector<pii> k;
pii maxind = pii(-1, -1);

void input() {
  ;
  ;
  cin >> N >> T;
  k.resize(N);
  rep(i, 0, N - 1) {
    cin >> a[i];
    cin >> b[i];
    k[i] = pii(a[i], b[i]);
    if (b[i] > maxind.second) {
      maxind = pii(i, b[i]);
    }
  }
}
// vector<int> A, B;
// int dp[3334][7777];
void solve() {
  // rep(i, 0, N - 1) {
  //   if (i != maxind.first) {
  //     A.push_back(a[i]);
  //     B.push_back(b[i]);
  //   }
  // }

  // sort(all(k),
  //      [](const pii &a, const pii &b) { return (a.second > b.second); });

  // A.push_back(3333);
  // B.push_back(3333);
  // a.erase(a.begin() + maxind.first);
  // b.erase(b.begin() + maxind.first);
  // int ans = maxind.second;
  // int ans = k[0].second;

  // T--;
  // rep(i, 1, N - 1) {
  //   rep(j, 0, T + 3033) {
  //     if (j < k[i].first) {
  //       dp[i][j] = dp[i - 1][j];
  //     } else {
  //       dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - k[i].first] +
  //       k[i].second);
  //     };
  //     ;
  //   };
  // }

  sort(all(k));
  vi DP(T + 1);
  for (auto &p : k) {
    for (int k = T - 1; k >= 0; --k) {
      chmax(DP[min(T, k + p.first)], DP[k] + p.second);
    }
  }
  cout << DP.back() << endl;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 512
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int[] nums=new int[n+1];
        for(int i=0;i<n;i++){
            nums[i]=sc.nextInt();
        }
        Arrays.sort(nums);
        int tmp=1;
        int output=0;
        for(int i=n;i>0;i--){
            if(nums[i]!=nums[i-1]){
                output+=tmp%2;
                tmp=1;
            }else{
                tmp++;
            }
        }
        System.out.println(output);
    }
 
    
}

Measured memory_bytes: 51640
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

constexpr int dx[] = {-1, 0, 1, 0};
constexpr int dy[] = {0, -1, 0, 1};

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	string s;
	cin >> s;
	string yy = s.substr(0, 2);
	string mm = s.substr(2, 4);
	int iy = stoi(yy);
	int im = stoi(mm);
	bool iy_is_mm = (12 >= iy && iy > 0);
	bool im_is_mm = (12 >= im && im > 0);
	if(iy_is_mm && im_is_mm) {
		cout << "AMBIGUOUS" << endl;
	} else if(iy_is_mm) {
		cout << "MMYY" << endl;
	} else if(im_is_mm) {
		cout << "YYMM" << endl;
	} else {
		cout << "NA" << endl;
	}
	return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;
#define N  100005


int main()
{
	ll a,b;
	cin>>a>>b;
	cout<<max(a+b,(max(a-b,a*b)));			
}

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

using namespace std;

signed main(){
    string f, s, t;
    cin >> f >> s >> t;
    cout << (char)toupper(f[0]) << (char)toupper(s[0]) << (char)toupper(t[0]) << endl;
}

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


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7,MAX = 1e5;

int main()
{
	ll N;
	cin >> N;
	//4 = N(1/h+1/n+1/w)
	//4hnw = Nnw+Nhw+Nhn
	//4hnw -Nnw - Nhn = Nhw
	//n(4hw-Nw-Nh)=Nhw
	//n=Nhw/(4hw-Nw-Nh)

	for(ll h = 1;h<=3500;h++)
	{
		for(ll w = h;w<=3500;w++)
		{
			if((4*h*w-N*w-N*h)==0)continue;
			if(h==3498&&w==3498)cout<<(N*h*w)%(4*h*w-N*w-N*h)<<endl;
			if((N*h*w)%(4*h*w-N*w-N*h)==0&&(N*h*w)/(4*h*w-N*w-N*h)>0)
			{
				cout<<h<<' '<<w<<' '<<N*h*w/(4*h*w-N*w-N*h)<<endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
use io::*;

fn main() {
    let con =read_string();
    let mut sc =Scanner::new(&con);

    let a:i32 = sc.next();
    let b:i32 = sc.next();
    let x:i32 = sc.next();
    if a<=x&&a+b>=x{
    println!("YES");
    }else{
    println!("NO");
    }
}

pub mod io {
    use std;
    use std::str::FromStr;
 
    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }
 
    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }
 
        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }
 
        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }
 
        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }
 
    pub fn read_string() -> String {
        use std::io::Read;
 
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }
 
    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 4352
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

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

    vector<int> lf(n);
    vector<int> rg(n);

    stack<int> st;
    for (int i = 0; i < n; ++i) {
        while (!st.empty() && a[st.top()] > a[i]) {
            int id = st.top();
            st.pop();
            rg[id] = i - 1;
        }
        st.push(i);
    }
    while (!st.empty()) {
        int id = st.top();
        st.pop();

        rg[id] = n - 1;
    }

    for (int i = n - 1; i >= 0; --i) {
        while (!st.empty() && a[st.top()] > a[i]) {
            int id = st.top();
            st.pop();
            lf[id] = i + 1;
        }
        st.push(i);
    }
    while (!st.empty()) {
        int id = st.top();
        st.pop();

        lf[id] = 0;
    }

    long long result = 0;
    for (int i = 0; i < n; ++i) {
        result += 1LL * a[i] * (i - lf[i] + 1) * (rg[i] - i + 1);
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 3456
N, T = map(int, input().split())
c = [None] * N
t = [None] * N

for i in range(N):
  c[i], t[i] = map(int, input().split())

a = [x for x, y in zip(c, t) if y <= T]
if len(a) > 0:
  print(min(a))
else:
  print('TLE')

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <fstream>
using namespace std;
typedef long long ll;

#define _ { \
	ios_base::sync_with_stdio(false); \
    cin.tie(NULL); \
}


int main(){
   _;
  string s;cin>>s;
  if(s[2]==s[3]&&s[4]==s[5])cout<<"Yes";
  else cout<<"No";
    
}

Measured memory_bytes: 256
using System;
using System.Linq;

class B
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var r9 = Enumerable.Range(1, 9);
		Console.WriteLine(r9.SelectMany(i => r9.Select(j => i * j)).Any(x => x == n) ? "Yes" : "No");
	}
}


Measured memory_bytes: 13396
import java.util.*;

public class Main {
 	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		long total = 0;
		int min = Integer.MAX_VALUE;
		int count = 0;
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		    total += Math.abs(arr[i]);
		    min = Math.min(min, Math.abs(arr[i]));
		    if (arr[i] < 0) {
		        count++;
		    }
		}
		if (count % 2 == 1) {
		    total -= min * 2;
		}
	    System.out.println(total);
   }
}




Measured memory_bytes: 52288
//12, 01, 2019, 10:16:19 Rafaelcs cpp
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

const int H = 410, W = 410, N = H * W, D = 4;
bool marked[N];
string tab[H];
int h, w;
char colors[2] = {'.', '#'};
vector< int > adj[N];
int bel[N];
int comp_num;
ll qtd[N][2];
int vi[D] = {-1, 1, 0, 0};
int vj[D] = {0, 0, -1, 1};

bool ok(int x, int y){
    return 0 <= x && x < h && 0 <= y && y < w;
}

void dfs(int u, int color){
    marked[u] = true;

    int ii = u / w;
    int jj = u % w;
    qtd[comp_num][color]++;

    for(int i = 0 ; i < D ; i++){
        int xi = vi[i] + ii;
        int xj = vj[i] + jj;

        if(ok(xi, xj)){
            int v = xi * w + xj;
            
            if(tab[xi][xj] == colors[!color] && !marked[v]){
                dfs(v, !color);
            }
        } 
    }
}

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

    cin >> h >> w;

    for(int i = 0 ; i < h ; i++){
        cin >> tab[i];
    }    

    for(int i = 0 ; i < h ; i++){
        for(int j = 0 ; j < w ; j++){
            int v = i * w + j;

            if(tab[i][j] == '#' && !marked[v]){
                comp_num++;
                dfs(v, 1);
            }
        }
    }

    ll tot = 0LL;

    for(int i = 1 ; i <= comp_num ; i++){
        tot += qtd[i][0] * qtd[i][1];
    }

    cout << tot << endl;

    return 0;
}

Measured memory_bytes: 18304
#include<iostream>
using namespace std;
char X[8][9];
int H,W;

int main(){
	cin >> H >> W;
	for(int i=0; i<H; i++){
		cin >> X[i];
	}

	int x=0, y=0;
	while(x<H-1 || y<W-1){
		//cout << x << " " << y << endl;
		//cout << X[x+1][y] << " " << X[x][y+1] << endl;
		if(x>0 && y>0 && X[x-1][y] == X[x][y-1]){
			cout << "Impossible" << endl;
			return 0;
		}
		if(x == H-1){
			if(X[x][y+1] == '.'){
				cout << "Impossible" << endl;
				return 0;
			}
			else{
				y++;
				continue;
			}
		}
		if(y == W-1){
			if(X[x+1][y] == '.'){
				cout << "Impossible" << endl;
				return 0;
			}
			else{
				x++;
				continue;
			}
		}
		if(X[x+1][y] == X[x][y+1]){
			cout << "Impossible" << endl;
			return 0;
		}
		if(X[x+1][y] == '#') x++;
		else y++;
	}
	if(X[x-1][y] == X[x][y-1]){
		cout << "Impossible" << endl;
		return 0;
	}

	cout << "Possible" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
//#include <math.h>
long Gcd(long m, long n)
{
	long temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}
long Lcm(long m, long n)
{
	return m * n / Gcd(m,n); 
}

int main(){
	long a,b;
	while(scanf("%ld %ld",&a,&b)!=EOF){
		long ans1,ans2;
		ans1=Gcd(a,b);
		ans2=Lcm(a,b);
		printf("%ld %ld\n",ans1,ans2);
	}
	return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <cstdio>
const int MAXN = 105;
int	F[MAXN]{ };
int	P[MAXN][11]{ };
int L=1<<10, N, tem;

int bit_count(int n) { return (n) ? __builtin_popcount(n) : 0; }

int main()
{
	scanf("%d", &N);
	for(int i = 0; i < N; ++i)
	for(int j = 0; j < 10; ++j)
	{
		scanf("%d", &tem);
		F[i] |= tem<<j;
	}
	for(int i = 0; i < N; ++i)
	for(int j = 0; j < 11; ++j)
		scanf("%d", &P[i][j]);
	int ret = -1E9;
	for(int mask = 1; mask < L; ++mask)
	{
		int res = 0;
		for(int i = 0; i < N; ++i)
			res += P[i][bit_count(mask & F[i])];
		ret = std::max(res, ret);
	}
	printf("%d\n", ret);
	return 0;
}

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

using namespace std;
using int64 = long long int;

struct City
{
    int index;
    int year;
    int prefecture;
    int id;
};

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

    vector<vector<City>> C(n + 1);

    for (int i = 0; i < m; i++)
    {
        City c = { i };
        cin >> c.prefecture >> c.year;
        C[c.prefecture].push_back(c);
    }

    vector<City> allCities;

    for (auto &vec : C)
    {
        sort(vec.begin(), vec.end(), [](auto &a, auto &b) { return a.year < b.year; });

        int lastID = 0;
        for (auto c : vec)
        {
            c.id = ++lastID;
            allCities.push_back(c);
        }
    }

    sort(allCities.begin(), allCities.end(), [](auto &a, auto &b) { return a.index < b.index; });
    for (auto &c : allCities)
    {
        char buffer[64];
        snprintf(buffer, sizeof(buffer), "%06d%06d", c.prefecture, c.id);
        cout << buffer << endl;
    }
}

Measured memory_bytes: 8688
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
using ll = long long;

const string YES = "Yes";
const string NO = "No";

#define ALL(x) begin(x),end(x)

void solve(string S) {
  sort(ALL(S));
  bool pred = S[0] == S[1] && S[2] == S[3] && S[1] != S[2];
  cout << (pred ? YES : NO) << endl;
}

int main() {
  string S;
  cin >> S;
  solve(S);
  return 0;
}


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

int main() {
  long long S;
  cin >> S;//s=ad-bc(0,0,a,b,c,d)
  int a=1000000000;
  int b=1;
  int d=(S+999999999)/1000000000;
  int c=(-S+a*d)/b;
  char e=' ';
  cout << "0 0 "<< a << e << b << e << c << e << d << endl;
}


Measured memory_bytes: 256
main :: IO ()
main = do
  [_, k] <- map read . words <$> getLine :: IO [Integer]
  a      <- map read . words <$> getLine :: IO [Integer]
  let countOps 0 = 2000000000
      countOps t =
        sum $ map (\l -> l `div` t + if l `mod` t == 0 then -1 else 0) a
  let binarySearch lo hi | lo + 1 == hi     = hi
                         | countOps mid > k = binarySearch mid hi
                         | otherwise        = binarySearch lo mid
        where mid = (lo + hi) `div` 2
  print $ binarySearch 0 1000000000


Measured memory_bytes: 64228
#include<iostream>
using namespace std;
 
int main(){
 
 
for(int i=0;i<9;i++){
for(int j=0;j<9;j++){
cout << i+1 << 'x' << j+1 << '=' << (i+1)*(j+1)  << endl;
}
}
 
return 0;
}

Measured memory_bytes: 1116
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int n, m;
  scanf("%d %d",&n, &m);
  vector<int> p(m), y(m);
  vector<int> city[n+1];
  for(int i = 0; i < m; i++){
    scanf("%d %d", &p[i], &y[i]);
    city[p[i]].emplace_back(y[i]);
  }
  for(int i = 1; i <= n; i++)
    sort(city[i].begin(), city[i].end());

  int Y;
  for(int i = 0; i < m; i++){
    auto itr = lower_bound(city[p[i]].begin(),
                           city[p[i]].end(), y[i]);
    Y = itr-city[p[i]].begin() + 1;
    printf("%06d%06d\n", p[i], Y);
  }
  return 0;
}


Measured memory_bytes: 7680
n, q = map(int, input().split())

if n == 1:
    def solve(v, w):
        return min(v, w)
else:
    def solve(v, w):
        while v != w:
            if v > w:
                v, w = w, v
            w = (w + n - 2) // n
        return v

print('\n'.join(map(str, (solve(*map(int, input().split())) for _ in range(q)))))


Measured memory_bytes: 11332