akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import deque
def input(): return sys.stdin.readline().rstrip()

def main():
    K = int(input())
    if K <= 10:
        print(K)
        exit()

    q = deque(range(1, 10))
    K -= 9
    while q:
        v = q.popleft()
        sv = v % 10
        for i in (-1, 0, 1):
            if 0 <= sv + i < 10:
                if K == 1:
                    print(v * 10 + sv + i)
                    exit()
                K -= 1
                q.append(v * 10 + sv + i)

if __name__ == '__main__':
    main()


Measured memory_bytes: 40432
#include<bits/stdc++.h>
using namespace std;
     
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007  
#define mod2 998244353 
#define pi 3.14159265358979323846

int solve(){
    int n;
    char c;
    cin>>c;
    c++;
    cout<<c;
//    cin>>n;

    return 0;
}   
     
signed main(){      
    IOS;
    int t=1;
    //cin>>t;   
    while(t--){
        solve();
        //if(solve()) cout<<"YES";
        //else cout<<"NO";
        cout<<"\n";
    }
    return 0;
} 


Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
	int len,a[100000],b[2],i,cnt,m,j;
	char s[100001];
	scanf("%s",s);
	len=strlen(s);
	for(i=0;i<len;i++)	a[i]=0;
	b[0]=0; b[1]=1; cnt=1;
	for(i=1;i<len;i++)	{
		if(s[i]=='R')	{
			cnt++;
			m=cnt%2;
			b[m]++;
		}
		else {
			m=cnt%2;

			if(m==0)	{
				a[i-1]+=b[0];
				a[i]+=b[1];
			}
			else	{
				a[i]+=b[0];
				a[i-1]+=b[1];
			}
			b[0]=0;	b[1]=0;
			cnt=0;
		}
	}
	b[0]=0; b[1]=1; cnt=1;
	for(i=len-2;i>=0;i--)	{
		if(s[i]=='L')	{
			cnt++;
			m=cnt%2;
			b[m]++;
		}
		else {
			m=cnt%2;
//			printf("i=%d m=%d b0=%d b1=%d\n",i,m,b[0],b[1]);	
			if(m==0)	{
				a[i+1]+=b[0];
				a[i]+=b[1];
			}
			else {	
				a[i]+=b[0];
				a[i+1]+=b[1];
			}
			b[0]=0;	b[1]=0;
			cnt=0;
		}
//		for(j=0;j<len;j++)	printf("a=%d\n",a[j]);
	}
	printf("%d",a[0]);
	for(i=1;i<len;i++)	printf(" %d",a[i]);
	printf("\n");
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>
#include <iomanip>
using namespace std;

int main(){
  double n;
  while (true){
    cin >> n;
    if (n == 0){
      break;
    }
    vector<double> nums;
    for (int i = 0; i < n; i++){
      double s;
      cin >> s;
      nums.push_back(s);
    }
    double mean = accumulate(nums.begin(), nums.end(), 0.0) / nums.size();
    double a = 0.0;
    for (int i = 0; i < n; i++){
      a += pow((nums[i] - mean), 2);
    }
    double aa = a/n;
    
    cout << fixed << setprecision(9) << pow(aa, 0.5) << endl;
  }
  // double n;
  // cin >> n;
  // cout << typeof(n) << endl;
}


Measured memory_bytes: 3440
def count(i,j):
  count=0
  if list[i-1][j-1]=='#':
    count += 1
  if list[i-1][j]=='#':
    count += 1
  if list[i-1][j+1]=='#':
    count += 1
  if list[i][j-1]=='#':
    count += 1
  if list[i][j+1]=='#':
    count += 1
  if list[i+1][j-1]=='#':
    count += 1
  if list[i+1][j]=='#':
    count += 1
  if list[i+1][j+1]=='#':
    count += 1
  return count

h,w=map(int, input().split())
s_init='0'*(w+2)
list=[]
list.append(s_init)
for i in range(h):
  s=str(input())
  list.append('0'+s+'0')
list.append(s_init)
for i in range(1,h+1):
  for j in range(1,w+1):
    if list[i][j]=='.':
      list[i]=list[i][:j]+str(count(i,j))+list[i][j+1:]
for i in range(h):
  print(list[i+1][1:-1])

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

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

 vector<int>dp(N + 1,N);
 dp[0] = 0;
//  print(dp[N]);

 for(int i = 1; i <= N; i++){ 
    for(int six = 1; six <= i; six *= 6){ 
       dp[i] = min(dp[i], dp[i - six] + 1);
    }
    for(int nine = 1; nine <= i; nine *= 9){ 
       dp[i] = min(dp[i], dp[i - nine] + 1);
    }
 
 }

print(dp[N]);
 }

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

  cin>>s>>k;

  char ch = '1';

  for (int i=0;i<k;i++)
  {
    if (s[i] != '1')
    {
      ch=s[i];
      break;
    }
  }


  cout<<ch<<endl;

    return 0;
}


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

using namespace std;

int m, n;
string s, t, res = "";

void printpath(vector<vector<pair<int, int>>>& p, pair<int, int> x) {
	if (x.first == 0 || x.second == 0) return;
	auto xx = p[x.first][x.second];
	auto d = x.first + x.second - (xx.first + xx.second);
	if (d == 2) {
		res += s[x.first - 1];
	}
	printpath(p, xx);
	return;
}

int main() {
	cin >> s >> t;
	m = s.length(), n = t.length();
	vector<vector<int>> dp(s.length() + 1, vector<int>(t.length() + 1));
	vector<vector<pair<int, int>>> p(m + 1, vector<pair<int, int>>(n + 1));
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			if (s[i - 1] == t[j - 1]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
				p[i][j] = {i - 1, j - 1};
			} else {
				dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
				p[i][j] = dp[i][j] == dp[i][j - 1] ? make_pair(i, j - 1) : make_pair(i - 1, j);
			}
		}
	}
	printpath(p, {m, n});
	reverse(res.begin(), res.end());
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 109104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int tmp;
        while(true){
            int x = sc.nextInt();
            int y = sc.nextInt();
            if ( x == 0 && y == 0 ) break;
            if (x > y){
            	tmp = x;
            	x = y;
            	y = tmp;
            }
            System.out.println(x + " " + y);
        }
	}

}


Measured memory_bytes: 36328
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll INF = 1000000009;
ll MOD = 1000000007;


ll ans;


ll dist(ll a, ll b){
    if(a<b) return dist(b,a);
    if(a%b==0){
        return (2*b)*(a/b)-b;
    }
    else{
        return (2*b)*(a/b) + dist(b,a%b);
    }
}


void solve(){

    ll n,x;
    cin >> n >> x;
    if(n==2*x){
        cout << 3*x << endl;
        return;
    }

    ans = 0;

    if(n>2*x){
        ans += (n+2*x);
        ans += dist(x,n-2*x);
    }
    else{
        ans += n;
        ans += dist(x,n-x);
    }

    cout << ans << endl;

}

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


Measured memory_bytes: 256
//ALDS1_11_B:Depth First Search
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <cstdlib>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <random>
#include <time.h>
#include <cassert>
using namespace std;

vector<int> friends[100000];
int group[100000];

void dfs(int now, int g){
    group[now] = g;
    for(int i=0; i<friends[now].size(); i++){
        if(group[friends[now][i]] == -1) dfs(friends[now][i], g);
    }
}

int main(){
    int n,m;
    cin >> n >> m;
    for(int i=0; i<m; i++){
        int s,t;
        cin >> s >> t;
        friends[s].push_back(t);
        friends[t].push_back(s);
    }
    for(int i=0; i<n; i++) group[i] = -1;

    for(int i=0; i<n; i++){
        if(group[i] == -1){
            dfs(i, i);
        }
    }

    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        int s,t;
        cin >> s >> t;
        if(group[s] == group[t]) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


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

ll findMaxPoints(vector < int > &nums, int i, int j, vector < vector < ll > > &dp) {
  if (i > j) {
    return 0;
  }
  if (dp[i][j] != -1) {
    return dp[i][j];
  }

  dp[i][j] = max(nums[i] + min(findMaxPoints(nums,i + 2, j, dp), findMaxPoints(nums, i + 1, j - 1, dp)), nums[j] + min(findMaxPoints(nums, i, j - 2, dp), findMaxPoints(nums, i + 1, j - 1, dp)));
  return dp[i][j];
}

ll findTarosPoint(vector < int > &nums) {
  int n = nums.size();
  vector < vector < ll > >dp(n, vector < ll >(n, -1));
  return findMaxPoints(nums, 0, nums.size() - 1, dp);
}

int main() {
  int n;
  cin>>n;
  vector < int > nums(n, 0);
  ll totalPoints = 0;
  for (int i = 0; i < n; i++) {
    cin>>nums[i];
    totalPoints += nums[i];
  }

  ll tarosPoints = 0;
  tarosPoints = findTarosPoint(nums);
  // cout<<"taros points = "<<tarosPoints<<endl;
  ll jirosPoints = totalPoints - tarosPoints;
  cout<<tarosPoints - jirosPoints<<endl;

  return 0;
}


Measured memory_bytes: 74000
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int min = a[0];
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] <= min) {
				count++;
				min = a[i];
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 60428
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int a, b;
  cin >> a >> b;
  if ((a * b) % 2 == 1) {
    cout << "Odd" << endl;
  }else{
    cout << "Even" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    string a, b;
    cin >> a >> b ;
    //*/

    /*
    vector<int> vec(3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;

    sort(vec.begin(), vec.end());
    //*/
    
    /*
    if( a * 500 >= b ){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    //*/
    
    cout << b << a << endl;

    return 0; 
}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
typedef int64_t ll;

int main(){
  ll n,q;
  cin>>n>>q;
  atcoder::fenwick_tree<ll> fw(n);
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    fw.add(i,a);
  }
  for(int i=0;i<q;i++){
    ll t,x,y;
    cin>>t>>x>>y;
    if(t==0){
      fw.add(x,y);
    }
    else{
      cout<<fw.sum(x,y)<<endl;
    }
  }
}


Measured memory_bytes: 8208
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdio>
#include <list>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define vec vector<int>
#define vecll vector<ll>
#define vecstr vector<string>
#define vecch vector<char>
#define vecpii vector<pii>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}

int main(){
    int a=in();
    char c;cin>>c;
    int b=in();
    if(c=='+')cout<<a+b<<endl;   
    else cout<<a-b<<endl;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		ArrayList<Integer> list = new ArrayList<>();
		boolean[] check = new boolean[N - 1];

		//初項を投入
		list.add(Integer.parseInt(sc.next()));
		for(int i = 1; i < N; i++) {
			list.add(Integer.parseInt(sc.next()));
			if(list.get(i - 1) >= list.get(i)) {
				check[i - 1] = true;
			}else {
				check[i - 1] = false;
			}
		}
		sc.close();

		//checkの配列を見ていく
		int count = 0;
		int checkCount = 0;
		for(int i = 0; i < check.length; i++) {
			if(check[i] == true) {
				checkCount++;
				count = Math.max(checkCount, count);
			}else {
				checkCount = 0;
			}
		}
		System.out.println(count);
	}

}

Measured memory_bytes: 61296
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int[] x = new int[n];
		for (int i=0; i<n; i++) { x[i] = sc.nextInt(); }
		int[] y = new int[n];
		for (int i=0; i<n; i++) { y[i] = sc.nextInt(); }

		double D1 = 0;
		double D2 = 0;
		double D3 = 0;
		double Di = Double.MIN_VALUE;

		for (int i = 0; i < x.length; i++) {

			double abs = Math.abs(x[i] - y[i]);
			D1 += abs;
			D2 += Math.pow(abs, 2);
			D3 += Math.pow(abs, 3);
			if (Di < abs) { Di = abs; }
		}
		D2 = Math.sqrt(D2);
		D3 = Math.pow(D3,1/3.0);

		System.out.printf("%.5f\n", D1);
		System.out.printf("%.5f\n", D2);
		System.out.printf("%.5f\n", D3);
		System.out.printf("%.5f\n", Di);

	}
}


Measured memory_bytes: 26580
import java.util.Scanner;
import java.util.ArrayList;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int max = sc.nextInt();
   ArrayList<Integer> Carr = new ArrayList<>(max);
   ArrayList<Integer> Varr = new ArrayList<>(max);
   for(int i=0;i<max;i++){
   int C = sc.nextInt();
   Carr.add(C);
   }
   for(int j=0;j<max;j++){
   int V = sc.nextInt();
   Varr.add(V);
   }
   int mem = 0;
   
 for(int k=0;k<max;k++){
   int m = Carr.get(k)-Varr.get(k);
   if(m>=0){ mem += m;}
 }
    System.out.print(mem);
 }
}

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

using namespace std;

int
main(int argc, char* argv[]) {
  int R;
  cin >> R;
  if (R < 1200) {
    cout << "ABC" << endl;
  } else if (R < 2800) {
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }
  return 0;
}


Measured memory_bytes: 888
#include <stdio.h>

int main(void) {

	int w,h;
	int i ,j;

	while(1){
		scanf("%d %d",&h,&w);
		if((w ==0) || (h == 0)){
			break;
		}
		for(i=0;i < h;i++){
			for(j = 0;j<w;j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}



Measured memory_bytes: 2044
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;



int main() {

    int x,y;
    cin>>x>>y;
    for(int t=0;t<=x;t++){
        int k=x-t;
        if(t*2+4*k==y){
            fin("Yes");
            return 0;
        }
    }
    fin("No");
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int r; cin>>r;
    if(r<1200) cout<<"ABC"<<endl;
    else if(r<2800) cout<<"ARC"<<endl;
    else cout<<"AGC"<<endl;
}

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

int main(){
	int N;
	cin >> N;
	bool d[110] = {};
	for (int i = 0; i < N; i++) {
		int val;
		cin >> val;
		d[val] = true;
	}
	int ans = 0;
	for (int i = 1; i <= 100; i++) {
		if (d[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE OverloadedStrings #-}

import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = do
    n <- fst . fromJust . B.readInt <$> B.getLine
    as <- V.fromList . B.words <$> B.getLine
    let printn i = do
        B.putStr $ as V.! i
        B.putStr " "
    mapM_ printn [(n - 1), (n - 3) .. 0]
    mapM_ printn $ if odd $ V.length as then [1, 3 .. (n - 1)] else [0, 2 .. (n - 1)]


Measured memory_bytes: 24956
package main

import (
	"fmt"
)

func judge(a, b, c int) string {

	var ab, bc, ca bool

	if a == b {
		ab = true
	}
	if b == c {
		bc = true
	}
	if c == a {
		ca = true
	}

	if ab && !bc && !ca {
		return "Yes"
	}

	if !ab && bc && !ca {
		return "Yes"
	}

	if !ab && !bc && ca {
		return "Yes"
	}

	return "No"
}

func main() {
	var a, b, c int

	fmt.Scan(&a, &b, &c)

	fmt.Println(judge(a, b, c))

}


Measured memory_bytes: 512
// Crt. 2019-12-12  20:27:16
#include <algorithm>
#include <iostream>
#include <cstdio>
#define N 200005
using namespace std;
typedef long long ll;

int n, m, now[N], ans[N], tmp[N];
ll x[N], y[N], z[N], K;

int main() {
#ifdef LOCAL_JUDGE
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n;
    for (int i = 1; i <= n; ++i)
        scanf("%lld", x + i), y[i] = x[i] - x[i - 1], now[i] = ans[i] = i;
    cin >> m >> K;

    for (int i = 1, t; i <= m; ++i)
        scanf("%d", &t), swap(now[t], now[t + 1]);

    while (K) {
        if (K & 1) {
            for (int i = 1; i <= n; ++i) tmp[i] = ans[now[i]];
            for (int i = 1; i <= n; ++i) ans[i] = tmp[i];
        }
        for (int i = 1; i <= n; ++i) tmp[i] = now[now[i]];
        for (int i = 1; i <= n; ++i) now[i] = tmp[i];
        K >>= 1;
    }

    for (int i = 1; i <= n; ++i)
        z[i] = y[ans[i]];

    for (int i = 1; i <= n; ++i)
        z[i] += z[i - 1], printf("%lld.0\n", z[i]);

    return 0;
}


Measured memory_bytes: 7168
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<pii, int> ppi;
#define mp make_pair
#define pb push_back
#define f first
#define s second


//var 
const int BLCK = 700;
int n, q, a[500005], ans[500005], fq[500005], cans = 1, lb, rb, l, r;
vector<ppi> qu;

struct MO{
	bool operator()(ppi t1, ppi t2){
		return (mp(t1.f.f/BLCK, t1.f.s) < mp(t2.f.f/BLCK, t2.f.s));
	}
};

void ad(int g){
	if(!fq[g])cans++;
	fq[g]++;
}

void rem(int g){
	fq[g]--;
	if(fq[g] == 0)cans--;
}

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

	scanf("%d %d\n", &n, &q);
	for(int i = 1; i<=n; i++)
		scanf("%d ", a+i);
	scanf("\n");
	
	for(int i = 1; i<=q; i++){
		scanf("%d %d\n", &l, &r);
		qu.pb(mp(mp(l,r), i));
	} sort(qu.begin(), qu.end(), MO());

	lb = 1, rb = 1; fq[a[1]] = 1; cans = 1;
	for(auto u : qu){
		while(rb < u.f.s){
			rb++;
			ad(a[rb]);
		}

		while(rb > u.f.s){
			rem(a[rb]);
			rb--;
		}

		while(lb < u.f.f){
			rem(a[lb]);
			lb++;
		}

		while(lb > u.f.f){
			lb--;
			ad(a[lb]);
		}

		ans[u.s] = cans;
	}

	for(int i = 1; i<=q; i++)
		printf("%d\n", ans[i]);

	cout.flush();
	return 0;
}

Measured memory_bytes: 15552
#include<bits/stdc++.h>
using namespace std;
     
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long int
#define pb push_back
#define endl "\n"
#define ff first
#define ss second
#define N 200009
#define M 15000007
#define mod 1000000007
#define debug cout<<"There There\n";
#define debug1(x) cout<<"\nValue is "<<x<<endl
#define debug2(x,y) cout<<"\nValue is "<<x<<" "<<y<<endl
#define debug3(x,y,z) cout<<"\nValue is "<<x<<" "<<y<<" "<<z<<endl  
#define pq priority_queue<int>
#define mpq priority_queue<int,vector<int>,greater<int>>
#define pr pair<int,int>
#define mx INT_MAX
#define lmx LLONG_MAX
#define err return 0
#define all(a) a.begin(),a.end()

int n;
int m;
vector<int> a;
int dp[N];

int32_t main()
{
     IOS;
     cin>>n>>m;
     map<int,int> mp;
     a.resize(n);
     for(int i=0;i<n;i++)
     {
          cin>>a[i];
          mp[a[i]] =  1;
     }
     dp[0] = 1;
     for(int i=1;i<=n;i++)
     {
          if(mp[i]==1)
          {
               dp[i]=0;
          }     
          else
          {
               if(i>=2)
                    dp[i] = (dp[i-1]+dp[i-2])%mod;
               else
               {
                    dp[i] = dp[i-1];
               }
               
          }
     }
     cout<<(dp[n]+mod)%mod<<endl;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

int left(int x, int n) {
  x--;
  if (x == -1) x = n - 1;
  return x;
}

int right(int x, int n) {
  x++;
  if (x == n) x = 0;
  return x;
}

// sheep is one
// wolf is zero

int modify(int &a, int &b, int i, int c) {
  if (i == 0) c = 1 - c;
  if (a == -1) {
    if (c) a = b;
    else a = 1 - b;
  }
  else if (b == -1) {
    if (c) b = a;
    else b = 1 - a;
  }
  else {
    if ((a == b) != c) return 1;
  }
  return 0;
}

void sol(string s, int n, int sto, int stt) {
  vector<int> a(n, -1);
  a[0] = sto;
  a[1] = stt;
  for (int i = 0; i < n; i++) {
    if (modify(a[left(i, n)], a[right(i, n)], a[i], (s[i] == 'o'))) {
      return;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << (a[i] ? "S" : "W");
  }
  cout << '\n';
  exit(0);
}

void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i <= 1; i++)
  for (int j = 0; j <= 1; j++) {
    sol(s, n, i, j);
  }
  cout << -1 << '\n';
}

signed main() {
#ifdef _DEBUG
  freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  // ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


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

using namespace std;
typedef long long ll;

int n, a, b, c, d;

int main() {
	scanf( "%d%d%d%d%d", &n, &a, &b, &c, &d );
	--n;
	for( int x = 0; x <= n; ++x ) {
		ll minv = a + (ll)c*x - (ll)d*(n-x);
		ll maxv = a + (ll)d*x - (ll)c*(n-x);
		if( minv <= b && maxv >= b ) {
			puts("YES");
			return 0;
		}
	}
	puts("NO");
	return 0;
}


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

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; }
using Graph = vector<vector<int>>;
/* 4方向への隣接頂点への移動を表すベクトル */
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const long long INF = 1LL << 60;

int main(){
    long long N, K, Q;
    cin >> N >> K >> Q;
    vector<long long> A(Q);
    long long num[N+1] = {0};
    for(int i = 0; i < Q; ++i){
        cin >> A[i];
    }
    for(int i = 0; i < Q; ++i){
        num[A[i]]++;
    }
    for(int i = 1; i <= N; ++i){
        if(K - (Q - num[i]) <= 0){
            cout << "No" << endl;

        } else {
            cout << "Yes" << endl;

        }
    }


    

}

Measured memory_bytes: 2176
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<string.h>
#include<map>
#include<set>
//#include <boost/multiprecision/cpp_int.hpp>

//namespace mp = boost::multiprecision;

using namespace std;
int main() {
	int k, a, b;
	cin >> k >> a >> b;
	long long int ans = 1;
	int i = 0;
	while (i != k) {
		if (i < k - 1) {
			if (ans - a + b > ans + 2&&ans>=a) {
				ans += -a+b;
				i += 2;
			}
			else  {
				ans++;
				i++;
			}
		
		
			
		}
		else {
			ans++;
			i++;
		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 256
//usr/bin/env scala $0 $@;exit

object Main{
	def main(args: Array[String]){
		val cin=new java.util.Scanner(System.in)
		var y=cin.nextInt();var m=0;var d=0;
		while(cin.hasNext()){
			y=cin.nextInt()-1;m=cin.nextInt()-1;d=cin.nextInt();
			var r=0;
			if(y%3!=2)r=m/2;
			printf("%d\n",196471-y*195-y/3*5-m*20+r-d);
		}
	}
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
				
	int n, k;
	cin >> n >> k;
	int p[n];
	for(int i=0; i < n; i++) cin >> p[i];
	sort(p,p+n);

	int totalPrice = 0;
	for(int i=0; i < k; i++)  totalPrice += p[i];

	cout << totalPrice << endl;

	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007LL
#define EPS ((ld)(1e-9))
 
#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, e) for (int i = 0, _##i = (e); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))
 
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}
 
template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    for (auto p : v) cout << p << ",";
    cout << "]";
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os, const set<T> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
#ifndef __SOULTCH
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif
 
template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

int N;
int A[100000];

void print(bool res) {
    if (res) cout << "Yes" << endl;
    else cout << "No" << endl;
    exit(0);
}

int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> N;
    rep(i, N) cin >> A[i];

    if (N%3 == 0) {
        sort(A, A+N);
        vector<pii> r;
        rep(i, N) if (i == 0 or A[i-1] != A[i]) {
            r.pb({A[i], 1});
        } else {
            r.back().se++;
        }

        if (sz(r) == 3) {
            if ((r[0].fi^r[1].fi^r[2].fi) == 0 and r[0].se == N/3 and r[1].se == N/3 and r[2].se == N/3) print(true);
            print(false);
        } else if (sz(r) == 2) {
            if (r[0].fi == 0 and r[0].se == N/3) print(true);
            print(false);
        } else if (sz(r) == 1) {
            print(r[0].fi == 0);
        } else {
            print(false);
        }

    } else {
        print(count(A, A+N, 0) == N);
    }
}

Measured memory_bytes: 1784
import sys
input = sys.stdin.readline

N = int(input())
P = list(map(int,input().split()))

class SegmentTree:
  def __init__(self, n, e):
    self.n = n
    self.e = e
    self.size = 2 ** ((n - 1).bit_length())
    self.node = [self.e] * (2 * self.size)
 
  def build(self, array):
    for i in range(self.n):
      self.node[self.size + i] = array[i]
 
  def get(self, i):
    i += self.size
    ret = self.node[i]
    while i > 1:
      i >>= 1
      ret += self.node[i]
    return ret
 
  def add(self, l, r, val):
    l, r = l + self.size, r + self.size
    while l < r:
      if l & 1:
        self.node[l] += val
        l += 1
      if r & 1:
        r -= 1
        self.node[r] += val
      l, r = l >> 1, r >> 1
      
STA = SegmentTree(N,0)
STB = SegmentTree(N,0)

STA.build(list(range(N)))
STB.build(list(range(N)[::-1]))

prev = P[0]-1
for p in P[1:]:
  p -= 1
  toadd = (STA.get(prev)+STB.get(prev)) - (STA.get(p)+STB.get(p)) + 1
  toadd = max(0,toadd)
  if p>prev:
    STA.add(p,N,toadd)
    if p+1 <= N-1:
      STB.add(p+1,N,-toadd)
  else:
    STB.add(0,p+1,toadd)
    if p >= 1:
      STA.add(0,p,-toadd)
  prev = p
  
ansa = [STA.get(i) for i in range(N)]
ansb = [STB.get(i) for i in range(N)]

mina = min(ansa)
minb = min(ansb)

ansa = [i-mina+1 for i in ansa]
ansb = [i-minb+1 for i in ansb]

print(*ansa)
print(*ansb)

Measured memory_bytes: 74512
import bisect
if __name__ == "__main__":
    n = int(input())
    s = list(map(int, input().split()))
    q = int(input())
    t = list(map(int, input().split()))

    ans = 0
    for i in range(q):
        index = bisect.bisect_left(s, t[i])
        if index == len(s) or s[index] != t[i]:
            continue
        ans += 1
    print(ans)


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

int main()
{
    int N;
    cin >> N;
    int odd = 0;
    for (int i = 0; i < N; ++i)
    {
        int a;
        cin >> a;
        if (a % 2 == 1)
        {
            ++odd;
        }
    }
    if (odd % 2 == 0)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

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

using namespace std;

int main()
{
    int k,a,b;
    cin>>k>>a>>b;
    int flag = 0;

    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            flag = 1;
            break;
        }
    }

    if(flag==1)
        cout<<"OK"<<endl;
    else
        cout<<"NG"<<endl;

    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <sstream>

#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>

#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

#include <chrono>
#include <random>

using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<i64>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<i64, i64>;

//////////////////////////////////////////////////

int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    s[k-1] = s[k-1] -'A' + 'a';
    cout << s << endl;
    return 0;
}


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

int main() {
	int n; cin >> n;
	int L = n / 100;
	int R = n % 100;

	if (1 <= L && L <= 12) {
		if (1 <= R && R <= 12) {
			cout << "AMBIGUOUS" << endl;
		}
		else {
			cout << "MMYY" << endl;
		}
	}
	else {
		if (1 <= R && R <= 12) {
			cout << "YYMM" << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

main() {
    int N;
    cin >> N;
    map<int, int> e, o;
    for(int i = 0; i < N; i++){
        int x;
        cin >> x;
        if(i % 2 == 0){
            e[x]++;
        }else{
            o[x]++;
        }
    }

    vector< pair<int, int> > E(2), O(2);
    for(auto p:e){
       E.push_back(make_pair(p.second,p.first));   
    }
    for(auto p:o){
       O.push_back(make_pair(p.second,p.first));
    }
    sort(E.begin(), E.end(), greater<pair<int, int>>());
    sort(O.begin(), O.end(), greater<pair<int, int>>());

    int ans;
    if(E[0].second != O[0].second){
        ans = N - (E[0].first + O[0].first);
    }else{
        ans = N - max(E[0].first+O[1].first, E[1].first+O[0].first);
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 6136
#include <iostream>
#include <string>
using namespace std;
int main(void) {
	//B
	string s;
	cin >> s;
	string tmp;
	int diff = 2000;
	for (int i = 0; i < s.size()-2; i++) {
		tmp = s.substr(i, 3);
		if (abs((stoi(tmp)) - 753) < diff) {
			diff = abs(stoi(tmp) - 753);
		}
	}
	cout << diff;

}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>

int main() {
  int A1, A2, A3;
  std::cin >> A1 >> A2 >> A3;

  int a[3] = { A1, A2, A3 };
  std::sort(a, a + 3);
  int cost = 0;
  for (int i = 1; i < 3; ++i) {
    cost += abs(a[i] - a[i - 1]);
  }
  std::cout << cost << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include <utility>

using namespace std;

int main() {

	int M, N;
	cin >> N >> M;

	vector<pair<int,int>> price_list;
	//vector<long long> howmuch;
	price_list.resize(N);
	
	for (auto i = 0; i < N; i++) {
		pair<int, int> temp;
		scanf("%d %d", &temp.first, &temp.second);
		price_list[i] = temp;
		
	}

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


	int num = 0;
	long long ans = 0;
	for (auto store = 0; store < N; store++) {
		num += price_list[store].second;
		if (num > M) {
			num -= price_list[store].second;
			ans += (long long)price_list[store].first * (long long)(M - num);
			break;
		}
		else {
			ans += (long long)price_list[store].first * (long long)price_list[store].second;
		}

	}
	cout << ans << endl;

	return 0;
}

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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
#define guard(x) if( not ( x ) ) continue;
typedef int64_t Int;
typedef std::vector<Int> LI;
const double pi = 3.14159265358979323846264338;
const Int mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(Int& x) { if( scanf("%" PRId64, &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
template<> void scan1(LI& xs) { for(Int &x : xs) scan1(x); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      Int n, a, b; scan(n, a, b);
      Int res = 0;
      for(Int i = 1; i <= n; ++i) {
         Int t = 0;
         Int s = i;
         while( s != 0 ) t += s % 10, s /= 10;
         if( a <= t and t <= b ) res += i;
      }
      printf("%ld\n", res);
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <cmath>
using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
	
void change_min(ll* p_dpi,ll dpj_absh){
	if(*p_dpi > dpj_absh) *p_dpi = dpj_absh;
	return;
}

int main(){
	//入力;
	int N,K;
	cin >> N >> K;
	
	vector<int> h;
	int tmp;
	REP(i,N){
		cin >> tmp;
		h.push_back(tmp);
	}
	
	//DPの初期化;
	vector<ll> dp;
	REP(i,N) dp.push_back(LLONG_MAX);
	dp[0] = 0;
	
	//DPの更新;
	FOR(i,1,N){
		FOR(j,max(0,i-K),i){
			change_min(&dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}
	
	cout << dp[N-1] << endl;
	return 0;
}

Measured memory_bytes: 1784
#include <iostream>
#include <algorithm>

using namespace std;

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

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

    int ans = a[n-1] - a[0];
    for (int i = 0; i < n - 1; i++) {
        ans = min(ans, k - (a[i+1] - a[i]));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
a, b, c, d = gets.split.map(&:to_i)
lcm = c.lcm(d)
calc_b1a = (a - 1) / c
calc_b2a = (a - 1) / d
calc_b3a = (a - 1) / lcm

calc_b1b = b / c
calc_b2b = b / d
calc_b3b = b / lcm

puts (b - (a - 1)) - ((calc_b1b + calc_b2b - calc_b3b) - (calc_b1a + calc_b2a - calc_b3a))

Measured memory_bytes: 1788
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

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

		BigDecimal a = sc.nextBigDecimal();
		BigDecimal b = sc.nextBigDecimal();

		sc.close();

		BigDecimal ans = a.multiply(b);

		System.out.println(ans.setScale(0, BigDecimal.ROUND_DOWN));

	}

}

Measured memory_bytes: 28980
N = int(input())
S = [input() for _ in range(N)]

dic = {}
ans = 0
for s in S:
    sortstr = str(sorted(s))
    if sortstr in dic:
        ans += dic[sortstr]
        dic[sortstr] += 1
    else:
        dic[sortstr] = 1
print(ans)

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

#ifdef MYDEBUG
#define dbp(x) cout<<#x<<": "<<x<<endl
#define dbp2(x,y) cout<<#x<<","<<#y<<": "<<x<<","<<y<<endl
#define dbp3(x,y,z) cout<<#x<<","<<#y<<","<<#z<<": "<<x<<","<<y<<","<<z<<endl
#else
#define dbp(x)
#define dbp2(x,y)
#define dbp3(x,y,z)
#endif
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define all(x) x.begin(), x.end()
#define rep(i, from, to) for(int i=from; i<to; ++i)

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  size_t last = v.size() - 1;
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != last)
      out << ",";
  }
  out << "]";
  return out;
}

void solve() {
  int n;
  ll k;
  vector<pair<int, int> > v;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(all(v));
  ll pos = 0;
  for (size_t i = 0; i < v.size(); ++i) {
    int diff = v[i].second;
    pos += diff;
    if (pos >= k) {
      cout << v[i].first << endl;
      return;
    }
  }
  //v[i]はi+1回目の操作で入った数
  //num[i]はv[i]が何個並ぶかの数
  cout << v[n - 1].first << endl;
}

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


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int big = max(a, max(b, c));
  int ans = a+b+c - big;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

ll d = 1e9 + 7;

ll gyaku(ll nu){
   ll e = d - 2;
   ll ret = 1;
   ll bai = nu;
   while (e > 0){
       if (e % 2 == 1){
           ret *= bai;
           ret %= d;
       }
       bai *= bai;
       bai %= d;
       e /= 2;
   }
   return ret;
}

vector <ll> kaijos = {1};

vector <ll> gyakukaijos = {1};


ll cmb(ll n, ll k){
    if (n < k){
        return 0;
    }
    ll ret = 1;
    ret *= kaijos[n]; ret %= d;
    ret *= gyakukaijos[k]; ret %= d;
    ret *= gyakukaijos[n-k]; ret %= d;
    return ret;
}


int main(void){
    for(int i=1; i<1e5 + 10; i++){
        kaijos.push_back(kaijos[i-1] * i % d);
    }
    for(int i=1; i<1e5 + 10; i++){
        gyakukaijos.push_back(gyakukaijos[i-1] * gyaku(i) % d);
    }
    ll n; cin >> n;
    ll k; cin >> k;
    vector <ll> as;
    REP(i, n){
        ll a; cin >> a;
        as.push_back(a);
    }
    sort(as.begin(), as.end());
    ll total_min = 0;
    set <ll> used;
    REP(i, n){
        ll a = as[i];
        if (i > 0 && as[i] == as[i-1]){
            continue;
        }
        ll yoridai = as.end() - upper_bound(as.begin(), as.end(), a);
        ll ijou = as.end() -  lower_bound(as.begin(), as.end(), a);
        ll kake = 0;
        kake += cmb(ijou, k);
        kake %= d;
        kake += d - cmb(yoridai, k);
        kake %= d;
        kake *= a;
        kake %= d;
        total_min += kake; total_min %= d;
    }
    ll total_max = 0;
    REP(i, n){
        if (i > 0 && as[i] == as[i-1]){
            continue;
        }
        ll a = as[i];
        ll yorishou = lower_bound(as.begin(), as.end(), a) - as.begin();
        ll ika = upper_bound(as.begin(), as.end(), a) - as.begin();
        ll kake = 0;
        kake += cmb(ika, k);
        kake %= d;
        kake += d - cmb(yorishou, k);
        kake %= d;
        kake *= a;
        kake %= d;
        total_max += kake; total_max %= d;
    }
    dump(total_max)
    dump(total_min)
    ll ans = d + total_max - total_min % d;
    ans %= d;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

using ll = long long;

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

    vector<char> ch;

    while (n > 26) {
        if (n%26 == 0) {
            ch.push_back('z');
            n--;
        }
        else ch.push_back((char)('a' - 1 + n % 26));
        n /= 26;
    }
    ch.push_back((char)('a' - 1 + n));
    reverse(ch.begin(), ch.end());

    for (int i = 0; i < ch.size(); i++) {
        cout << ch[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m; 
    cin >>n >>m;
    int x=0,y=1e5+1;
    for(int i=0; i<m; i++)
    {
        int l,r; cin >>l >>r;
        if(l>x) x=l;
        if(r<y) y=r;
    }
    cout <<(x<=y?y-x+1:0);
    return 0;
}


Measured memory_bytes: 3644
import java.util.*;

public class Main{

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

        int N = sc.nextInt();
        int[][] A = new int[2][N];
        Map<Integer, Integer> map = new TreeMap<>();
        for(int i = 0; i < N; i++){
            A[0][i] = sc.nextInt();
            A[1][i] = sc.nextInt();
            if(map.containsKey(A[1][i]))
                map.put(A[1][i], map.get(A[1][i])+A[0][i]);
            else
                map.put(A[1][i], A[0][i]);
        }
        sc.close();

        int time = 0;
        for(Integer key: map.keySet()){
           if(time + map.get(key) <= key){
               time += map.get(key);
           } else {
               System.out.println("No");
               return;
           }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 123424
while True:
    n,x= map(int, input().split())
    if n==0:
        break
    s= 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            for k in range(j+1, n+1):
                if i + j + k == x:
                    s += 1
    print(s)


Measured memory_bytes: 5596
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int mod = 1000000007;


int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int x,y,z;
  cin>>x>>y>>z;
  if(x+y+z>=22)cout<<"bust"<<endl;
  else cout<<"win"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int A, B, C, D, E, F;

int reachable_water[4096], reachable_sugar[4096];

void reachable(int mofu[], int c1, int c2, int current, int limit) {
	if (current > limit || mofu[current]) return;
	mofu[current] = current;
	reachable(mofu, c1, c2, current + c1, limit);
	reachable(mofu, c1, c2, current + c2, limit);
}

int main(void) {
	int i, w;
	int answer_water = 0, answer_sugar = 0;
	if (scanf("%d%d%d%d%d%d", &A, &B, &C, &D, &E, &F) != 6) return 1;
	answer_water = 100 * A;
	reachable(reachable_water, 100 * A, 100 * B, 0, F);
	reachable(reachable_sugar, C, D, 0, F);
	for (i = 1; i <= F; i++) {
		if (reachable_sugar[i] == 0) reachable_sugar[i] = reachable_sugar[i - 1];
	}
	for (w = 100; w <= F; w += 100) {
		if (reachable_water[w]) {
			int situryo_limit = F - w;
			int tokeru_limit = w * E / 100;
			int limit = situryo_limit < tokeru_limit ? situryo_limit : tokeru_limit;
			int genkai = reachable_sugar[limit];
			if (genkai * (answer_water + answer_sugar) > answer_sugar * (w + genkai)) {
				answer_water = w;
				answer_sugar = genkai;
			}
		}
	}
	printf("%d %d\n", answer_water + answer_sugar, answer_sugar);
	return 0;
}


Measured memory_bytes: 256