akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a, b ,c;
  cin >> a >> b >> c;
  
  if ( a[a.size()-1] == b[0] && b[b.size()-1] == c[0]){
    cout << "YES" << endl;
  }
  
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define LEN 1000
#define NIL -1
using namespace std;

char s1[LEN+1],s2[LEN+1];
int L1,L2;
int memo[LEN+2][LEN+2];//[s1][s2]

int rec(int n1,int n2){
	if(memo[n1][n2] != NIL)return memo[n1][n2];

	if(n1 == 0){memo[n1][n2] = n2;return memo[n1][n2];}
	if(n2 == 0){memo[n1][n2] = n1;return memo[n1][n2];}
	if(s1[n1] == s2[n2]){memo[n1][n2] = rec(n1-1,n2-1);return memo[n1][n2];}
	memo[n1][n2] = min(min(rec(n1,n2-1),rec(n1-1,n2)),rec(n1-1,n2-1)) + 1;return memo[n1][n2];
	//if(n1 > n2){memo[n1][n2] = rec(n1-1,n2) + 1;return memo[n1][n2];}
	//if(n1 < n2){memo[n1][n2] = rec(n1,n2-1) + 1;return memo[n1][n2];}
}

void solve(){
	for(int i = 0;i <= L1;i++)
		for(int j = 0;j <= L2;j++)memo[i][j] = NIL;
	int ans;
	ans = rec(L1,L2);
	printf("%d\n",ans);
	return;
}

int main() {
	scanf("%s",&s1);
	scanf("%s",&s2);
	for(int i = 0;s1[i] != NULL;i++)
		if(s1[i+1] == NULL)L1 = i+1;
	for(int i = 0;i < L1;i++)
		s1[L1-i] = s1[L1-1-i];
	for(int i = 0;s2[i] != NULL;i++)
		if(s2[i+1] == NULL)L2 = i+1;
	for(int i = 0;i < L2;i++)
		s2[L2-i] = s2[L2-1-i];
	//cout <<L1 <<" " <<L2 <<endl;

	solve();

    return 0;
}

Measured memory_bytes: 5116
#include <bits/stdc++.h>
#define MAXN 105
#define MAXpeso 100005
#define ll long long

using namespace std;
 
ll peso[MAXN];
ll value[MAXN];
ll dp[MAXN][MAXpeso];
int n, w;

ll knapsack(ll obj, ll aguenta)
{
	if(obj == n || !aguenta) return dp[obj][aguenta] = 0;

	if(dp[obj][aguenta] >= 0) return dp[obj][aguenta];

	ll nao_coloca = knapsack(obj + 1, aguenta);

	if(peso[obj] <= aguenta)
	{
		ll coloca = value[obj] + knapsack(obj + 1, aguenta - peso[obj]);		
		return dp[obj][aguenta] = max(coloca, nao_coloca);
	}

	return dp[obj][aguenta] = nao_coloca;


}





int main()
{

	cin >> n >> w;  
	for (int i = 0; i < n; ++i)
	{
		cin >> peso[i] >> value[i];
	}
	
	memset(dp, -1, sizeof(dp));


	cout << knapsack(0, w) << endl;

 
 
 
    return 0;
}

Measured memory_bytes: 85680
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int H,W;
  cin>>H>>W;
  int ans=0;
  int v[H+2][W+2];
  REP(i,H+2)REP(j,W+2)v[i][j]=0;
  FOR(i,1,H+1)FOR(j,1,W+1){
    char c;
    cin>>c;
    if(c=='.'){
      ans++;
      v[i][j]=-1;
    }
  }
  queue<pair<int,int> > q;
  q.push(make_pair(1,1));
  v[1][1]=0;
  while(!q.empty()){
    int x=q.front().first;
    int y=q.front().second;
    q.pop();
    FOR(i,-1,2)FOR(j,-1,2){
      if(i*j!=0)continue;
      if(v[x+i][y+j]<0){
        q.push(make_pair(x+i,y+j));
        v[x+i][y+j]=v[x][y]+1;
      }
    }
  }
  if(v[H][W]<=0)cout<<-1<<endl;
  else cout<<ans-v[H][W]-1<<endl;
  // FOR(i,1,H+1){
  //   FOR(j,1,W+1)cerr<<v[i][j]<<" ";
  //   cerr<<endl;
  // }
  return 0;
}


Measured memory_bytes: 256
import sys

input=sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()


def II(): return int(input())


def MI(): return map(int,input().split())


def MF(): return map(float,input().split())


def LI(): return list(map(int,input().split()))


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))


# rstrip().decode('utf-8')



def main():
	a,b,c,k=MI()
	ans=min(a,k)
	ans-=max(k-a-b,0)
	print(ans)







if __name__=="__main__":
	main()


Measured memory_bytes: 61852
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}
vector<int>v(maxn),adj[maxn];

void solve(){
    // int n;
    // cin >> n;
    // FOR(i,1,n+1)cin >> v[i];
    // FOR(i,1,n){
    //     int u,v;
    //     cin >> u >> v;
    //     adj[u].pb(v);
    //     adj[v].pb(u);
    // }
    string s;
    cin >> s;
    if(s == "ABC")cout << "ARC";
    else cout << "ABC";


}

signed main()   
{
    showoff;
    int T = 1;
    //cin >> T;
    FOR(t,1,T+1){
        solve();
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...


Measured memory_bytes: 9456
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int MAXN = 120000;

int n, m;

vector<int> eds[MAXN];
int was[MAXN];
set<int> v1, v2;
int p[MAXN];

void dfs1(int v) {
	v1.insert(v);
	v2.insert(p[v]);
	was[v] = 1;
	for (int u: eds[v])
		if (!was[u])
			dfs1(u);
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> p[i], --p[i];
	}
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		eds[a].push_back(b);
		eds[b].push_back(a);
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		if (was[i])
			continue;
		v1.clear();
		v2.clear();
		dfs1(i);
		for (int j: v1)
			if (v2.count(j))
				ans += 1;
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 17792
N = int(input())
X = list(map(int,input().split()))
Y = [[X[k],k] for k in range(N)]

Y.sort()

A = [0] * N
for k in range(N):
	if k >= N // 2:
		A[Y[k][1]] = Y[N//2-1][0]
	else:
		A[Y[k][1]] = Y[N//2][0]

for x in A:
	print(x)

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

using namespace std;

class EdgeTable : public map<uint64_t, set<uint64_t>> {};

inline uint64_t match_node(uint64_t x, uint64_t y)
{
  return (min(x, y) << 10) + max(x, y);
}

static array<bool, 2000000> visited;
static array<bool, 2000000> finished;
static array<uint64_t, 2000000> cache;

const uint64_t NotFound = -1;

uint64_t search_dfs(uint64_t src, const EdgeTable &edges)
{
  cache[src] = 1;
  
  if (edges.find(src) == edges.end()) {
    goto END_OF_SEARCH_DFS;
  }
  
  for (auto &dst : edges.at(src)) {
    uint64_t ret = cache[dst];
    
    if (!visited[dst]) { 
      visited[dst] = true;
      
      ret = search_dfs(dst, edges);
    } else {
      if (!finished[dst]) {
        return NotFound;
      }
    }
    
    if (ret == NotFound) {
      return NotFound;
    }
    
    if (ret + 1 > cache[src]) {
      cache[src] = ret + 1;
    }
  }
  
END_OF_SEARCH_DFS:
  finished[src] = true;
  
  return cache[src];
}

int main()
{
  uint64_t N;
  cin >> N;
  
  vector< vector<uint64_t> > A(N);
  for (uint64_t n = 0; n < N; ++n) {
    A[n] = vector<uint64_t>(N - 1);
    for (uint64_t m = 0; m < N - 1; ++m) {
      cin >> A[n][m];
      --A[n][m];
    }
  }
  
  EdgeTable edges;
  for (uint64_t n = 0; n < N; ++n) {
    for (uint64_t m = 0; m < N - 2; ++m) {
      edges[match_node(n, A[n][m])].insert(match_node(n, A[n][m + 1]));
    }
  }
  
  set<uint64_t> match_set;
  for (uint64_t n = 0; n < N; ++n) {
    for (uint64_t m = 0; m < n; ++m) {
      match_set.insert(match_node(n, m));
      
      cache[match_node(n, m)] = NotFound;
      visited[match_node(n, m)] = false;
      finished[match_node(n, m)] = false;
    }
  }
  
  uint64_t max_depth = 0;
  for (uint64_t start : match_set) {
    if (visited[start]) { continue; }
    
    visited[start] = true;
    
    uint64_t depth = search_dfs(start, edges);
    
    if (depth == NotFound) {
      cout << -1 << endl;
      return 0;
    }
    
    if (max_depth < depth) { max_depth = depth; }
  }
  
  cout << max_depth << endl;
  
  return 0;
}

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


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

    multiset<long long> se;
    for (auto ai : a) {
        se.insert(ai);
        if (se.size() >= 2 and ai > *begin(se)){
            se.erase(--se.lower_bound(ai));
            }
//    cout << se.size() << endl;
        
    }
    cout << se.size() << endl;
}


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

int main(){
    int s,c=1;
    cin>>s;
    set<int> st;
    while(st.count(s)==0){
        st.insert(s);
        if(s%2==0) s/=2;
        else s=3*s+1;
        c++;
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
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 c = sc.nextInt();
      int max = Math.max(a,Math.max(b,c));
      if(a%2==b%2&&b%2==c%2)System.out.println((max*3-a-b-c)/2);
      else if(b%2==c%2){
      	b++;
        c++;
        max = Math.max(a,Math.max(b,c));
        System.out.println((max*3-a-b-c)/2+1);
      }else if(a%2==c%2){
      	a++;
        c++;
        max = Math.max(a,Math.max(b,c));
        System.out.println((max*3-a-b-c)/2+1);
      }else{
      	a++;
        b++;
        max = Math.max(a,Math.max(b,c));
        System.out.println((max*3-a-b-c)/2+1);
      }
    }
    public static int lcm(int x, int y){
      return x*y/gcd(x,y);
    }
    public static int gcd(int x, int y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}

Measured memory_bytes: 22612
Scanf.scanf "%d %d" (fun n m ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    Array.sort (fun a b -> compare b a) a;
    let sum = Array.fold_left (+) 0 a in
    print_endline @@ if a.(m - 1) * 4 * m < sum then "No" else "Yes"
)

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

const int N = 1e5+34;
int h[N];
bool notit[N];

void solve() {
    int n, m; scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++i) {
        scanf("%d", h+i);
    }
    int ans = 0;
    for (int i = 0; i < m; ++i) {
        int a, b; scanf("%d%d", &a, &b); --a; --b;
        if (h[a] >= h[b]) {
            notit[b] = true;
        }
        if (h[a] <= h[b]) {
            notit[a] = true;
        }
    }
    for (int i = 0; i < n; ++i) {
        ans += !notit[i];
    }
    printf("%d", ans);
}

int main() {
    init();
    int t = 1; //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

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

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

using namespace std;

const int INF = 10000;

int main()
{
	
	rep(i, 1000) {
		int H, W;
		cin >> H >> W;

		if (H == 0 || W == 0)continue;

		rep(i, H) {
			rep(j, W) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}



Measured memory_bytes: 3080
#include<iostream>
#include<sstream>
#include<bitset>
#include<string>
#include<math.h>
using namespace std;

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

    int A[N];
    int x,y;
    int X[N][N-1];
    int Y[N][N-1];

    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            X[i][j]=0;
            Y[i][j]=0;
        }
    }

    for(int i=0; i<N; i++){
        cin >> A[i];
        for( int j=0; j<A[i]; j++ ){
            cin >> x >> y;
            X[i][j]=x;
            Y[i][j]=y;
        }
    }

    stringstream ss;
    string s;
    int tmp,ans;
    bool flag;

    ans=0;
    for(long long ii=1; ii< (int) pow(2,N) ; ii++){
        ss << bitset<15>(ii);
        s = ss.str();
        ss.str("");

        flag=true;
        for( int j=0; j<N; j++ ){
            int jj=s.size()-1-j;
            int man_j= (int) s[jj] - '0'; // 0: Unkind, 1: Honest
            for (int k=0; k<A[j]; k++){
                int kk=s.size()-X[j][k]; // X from 1!
                int man_k = (int) s[kk] - '0';
                if( man_j==1 && Y[j][k]==0 && man_k==1 ){
                    flag=false;
                    break;
                }else if( man_j==1 && Y[j][k]==1 && man_k==0 ){
                    flag=false;
                    break;
                }
            }
        }
        tmp=0;
        if( flag ){
            for(int i=0; i<N; i++){
                int man_i= (int) s[s.size()-1-i] - '0';
                if( man_i==1 ){
                    tmp++;
                }
            }
        }
        ans=max(ans,tmp);

    }

    cout << ans << endl;

    return 0;
}

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

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

int solve(int x, int y, vector<vector<int> >& ice, const int m, const int n)
{
  int ret = 0;
  ice[y][x] = 0;
  for (int d = 0; d < 4; ++d) {
    int xx = x + dx[d];
    int yy = y + dy[d];
    if (xx < 0 || m <= xx || yy < 0 || n <= yy || ice[yy][xx] == 0)
      continue;
    ret = max(ret, solve(xx, yy, ice, m, n));
  }
  ice[y][x] = 1;
  return ret+1;
}

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

    vector<vector<int> > ice(n, vector<int>(m));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j)
        cin >> ice[i][j];
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (ice[i][j] == 1)
          ans = max(ans, solve(j, i, ice, m, n));
      }
    }

    cout << ans << endl;
  }
  return 0;
}

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

#define ll long long
#define int ll
#define endl "\n"

signed main () {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int a, b, c;
	cin >> a >> b >> c;
	cout << ((a + b - 1) / b)*c << endl;
	return 0;

}


Measured memory_bytes: 3636
n,y=map(int,input().split())

for i in range(n+1):
    for j in range(n+1):
        if n-(i+j)>=0 and 10000*i+5000*j+1000*(n-(i+j))==y:
            print(i,j,(n-(i+j)))
            exit()
print(-1,-1,-1)

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

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    bool turn = true;
    while (a > 0 && c > 0)
    {
        if (turn)
        {
            c -= b;
            turn = false;
        }
        else
        {
            a -= d;
            turn = true;
        }
    }

    if (a > 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
int n;
cin>>n;
long long int arr[n],sum(0);
map<int,int>freq;
for(int i=0; i<n; ++i)
{
cin>>arr[i];
sum+=arr[i];
++freq[arr[i]];
}
int q;
cin>>q;
for(int i=0; i<q; ++i)
{
int a,b;
cin>>a>>b;
sum-=(long long)(freq[a]*a);
sum+=(long long)(freq[a]*b);
freq[b]+=freq[a];
freq[a]=0;
cout<<sum<<"\n";
}
}

Measured memory_bytes: 8336
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
 
#define REP(i, n) for(LL i = 0; i < (LL)(n); i++)
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const LL IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 2019;
 
LL power(LL x, LL y) {
    LL res = 1;
    for(;0 < y;) {
        if(y%2 == 0) {
            x *= x;
            x %= MOD;
            y /= 2;
        }else{
            res *= x;
            res %= MOD;
            y--;
        }
    }
    return res;
}
 
int main() {
    string s;
    cin >> s;
    reverse(ALL(s));
    LL N;
    N = s.size();
    vector<LL> v(N, 0);
    vector<LL> c(MOD, 0);
    v[0] = s[0] - '0';
    c[v[0]] = 1;
    FOR(i, 1, N) {
        LL p = s[i] - '0';
        v[i] = power(10, i)*p + v[i - 1];
        v[i] %= MOD;
        c[v[i]]++;
    }
    LL res = 0;
    res += c[0];
    REP(i, MOD) {
        res += c[i]*(c[i] - 1)/2;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5244
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static void main(String args[]) throws Exception {
        String[] tokens = br.readLine().split(" ");
        int a= Integer.parseInt(tokens[0]);
        int v=Integer.parseInt(tokens[1]);
        tokens = br.readLine().split(" ");
        int b = Integer.parseInt(tokens[0]);
        int w = Integer.parseInt(tokens[1]);
        int t = Integer.parseInt(br.readLine());
        if(v<=w){
            System.out.println("NO");
        }else{
            int rel = v-w;
            int dist = Math.abs(b-a);
            if(dist%rel==0){
                if(dist/rel<=t)
                    System.out.println("YES");
                else System.out.println("NO");
            }else {
                if(dist/rel<t)
                    System.out.println("YES");
                else
                    System.out.println("NO");
            }
        }
    }




}

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

int main(){
	while(1){
		int n, r;
		int card[51]; //1~nを使う
		
		scanf(" %d %d", &n, &r);
		if(n==0 && r==0) break; 
		for(int i=1; i<=n; ++i) card[i]=n+1-i;
	
		for(int i=0; i<r; ++i){
			int p, c;
			scanf(" %d %d", &p, &c);
			
			int tmp[50];
			for(int j=0; j<c; ++j) tmp[j]=card[p+j];
			for(int j=p-1; j>0; --j) card[j+c]=card[j];	
			for(int j=1; j<=c; ++j) card[j]=tmp[j-1];
			
			//for(int i=1; i<=n; ++i) printf(" %d",card[i]);
			//printf("\n");
		}
		printf("%d\n", card[1]);
	}
	return 0;
}

Measured memory_bytes: 1188
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;

public class Main {

	static FastScanner sc = new FastScanner();

	public static void main(String[] args) throws Exception {
		int[] I = new int[256];
		double[] en = new double[257];
		StringBuilder sb = new StringBuilder();
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			for (int i = 0; i < N; ++i) {
				double v = 1.0 * (i + 1) / N;
				en[i + 1] = -v * Math.log(v);
				I[i] = sc.nextInt();
			}
			double best = Double.MAX_VALUE;
			int bs = 0;
			int ba = 0;
			int bc = 0;
			for (int s = 0; s < 16; ++s) {
				for (int a = 0; a < 16; ++a) {
					OUT: for (int c = 0; c < 16; ++c) {
						int[] hist = new int[256];
						int r = s;
						for (int i = 0; i < N; ++i) {
							r = (a * r + c) & 0xFF;
							hist[(I[i] + r) & 0xFF]++;
						}
						double e = 0;
						for (int i = 0; i < 256; ++i) {
							if (hist[i] != 0) {
								e += en[hist[i]];
								if (e >= best) continue OUT;
							}
						}
						if (e < best - 1e-10) {
							best = e;
							bs = s;
							ba = a;
							bc = c;
						}
					}
				}
			}
			sb.append(bs + " " + ba + " " + bc + "\n");
		}
		System.out.print(sb);
	}

	static class FastScanner {
		Reader input;

		FastScanner() {
			this.input = new BufferedReader(new InputStreamReader(System.in));
		}

		int nextInt() throws IOException {
			int sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			int ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) return ret * sign;
				ret *= 10;
				ret += b - '0';
			}
		}
	}

}

Measured memory_bytes: 87580
#include<bits/stdc++.h>
using namespace std;
const int C=100000;
vector<int> prime,num(C);
void sieve(){
    for(int i=0;i<C;i++){
        num[i]=i;
    }while(num.size()>2){
        prime.push_back(num[2]);
        num.erase(num.begin()+2);
        for(int k=2;k<num.size();k++){
            if(num[k]%prime.back()==0){
                num.erase(num.begin()+k);
                k--;
            }
        }
    }return;
}
int main(){
    sieve();
    int judge[C]={0};
    for(int i=0;i<prime.size();i++){
        judge[prime[i]]++;
        if(2*prime[i]-1<C){
            judge[2*prime[i]-1]++;
        }
    }int count=0;int integral[C];
    for(int j=0;j<C;j++){
        if(judge[j]==2){
            count++;
        }integral[j]=count;
    }

    int Q;cin>>Q;
    int L[Q],R[Q];
    for(int i=0;i<Q;i++){
        cin>>L[i]>>R[i];
    }for(int j=0;j<Q;j++){
        cout<<integral[R[j]]-integral[L[j]-1]<<endl;
    }
}

Measured memory_bytes: 2688
while 1:
    try:
        A = map(int, raw_input().split())
        B = map(int, raw_input().split())
        hit = sum(1 for i in range(4) if A[i] == B[i])
        blow = len(set(A) & set(B)) - hit
        print hit, blow
    except:
        break

Measured memory_bytes: 4208
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] a = new int[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		sc.close();

		int n2 = 1 << n;
		long[][] dp = new long[n + 1][n2];
		dp[0][0] = 1;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (a[i][j] == 0) {
					continue;
				}
				int j1 = 1 << j;
				for (int j2 = 0; j2 < n2; j2++) {
					dp[i + 1][j2 | j1] += dp[i][j2];
				}
			}
			for (int j2 = 0; j2 < n2; j2++) {
				dp[i + 1][j2] %= 1000000007;
			}
		}
		System.out.println(dp[n][n2 - 1]);
	}
}


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

int main(){
  int N, K;
  int A;
  cin >> N >> K;
  for (int i = 0; i < N ; i ++){
    int s;
    cin >> s;
    if ( s > K - s ){//s、K-s移動距離
      A += K-s;
    }
    else if ( s <= K - s){
      A += s;
    }
  }
  cout << A * 2 << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import numpy as np

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str, T: str):
    if S==T[:len(S)]:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)

if __name__ == '__main__':
    main()


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

int main() {
	int a; cin >> a;
	string s; cin >> s;

	if (a >= 3200) cout << s << endl;
	else cout << "red" << endl;

	return 0;
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, c;
int p[111];
int sum;

int main(){
    INIT;
    cin >> n >> c;
    REP(i, c){
        cin >> p[i];
        sum += p[i];
    }
    cout << sum/(n + 1) + (sum%(n + 1) == 0 ? 0 : 1) << endl;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int samecount(string S){
    int A = 0;
    for(int i = 0;i < S.size();i++){
        int QA = 1;
        for(int j = i ;j < S.size() - 1;j++){
           if(S.at(j) == S.at(j + 1)){
               QA++ ;
           }
           if(S.at(j) != S.at(j + 1)){
               break;
           }
           
        }
        A = max(QA,A);
    }
    return A;
}

int64_t minn(int64_t a,int64_t b){
    if(a >= b) return b;
    else return a;
}
int main(){
    string s;
    cin >>s;
    cout << s[0] << s.size() - 2 << s[s.size()- 1] << endl;
}



Measured memory_bytes: 256
N, M = map(int, input().split())
# l = list()
# for _ in range(M):
#     A, B = input().split()
#     l.append((int(A), B))
# print(l)
#
# d = dict()
# keys =
# v1 = False
# v2 = 0
#
# for k, v in l:
#     d[keys] = (v1, v2)
#     if v2 == "WA":
#         v2 += 1
#         if v == "AC":
#             k = True
#             continue
# print(d)

from collections import defaultdict
d = defaultdict(list)
for _ in range(M):
    p, S = input().split()
    d[int(p)].append(S)
# print(d)

for p, results in d.items():
    is_ac = 'AC' in results
    if not is_ac:
        d[p] = (False, 0)
    else:
        d[p] = (True, results.index('AC'))
# print(d)
cnt = 0
penas = 0
for ac, pena in d.values():
    if ac == True:
        cnt += 1
    penas += pena
print(cnt, penas)


Measured memory_bytes: 29816
#include <iostream>
#include <cmath>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main(){
	int n;
	int dp[32] = {};
	dp[0] = dp[1] = 1;
	dp[2] = 2;
	rep2(i,3,32) {
		dp[i] = dp[i-3] + dp[i-2] + dp[i-1];
	}
	while(cin >> n, n) {
		cout << ceil(dp[n] / 3650.0) << endl;
	}
    return 0;
}

Measured memory_bytes: 1232
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for(int i=(a);i<(int)(n);i++)
#define repc(i, a, n) for(int i=(a);i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
#define DBG(str) cerr<<(str)<<endl;
int main() {
	int a,b;
	cin>>a>>b;
	cout<<a*b-(a+b-1)<<endl;
	
	return 0;
}





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

int main() {
	int n; cin >> n;
  if (n == 0) { cout << 0 << endl; return 0; }

	string ans = "";
	while (n != 0) {
		int rem = n % -2;
		if (rem < 0) n -= 1;
		
		ans.push_back((rem ? '1' : '0'));
		n /= -2;
		
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3584
#include <stdio.h>

int main(void){
	int a;
	int b;

	scanf("%d %d", &a, &b);

	if (a<b){
	printf("%s < %s\n", "a","b");
}else if(a>b){
	printf("%s > %s\n", "a","b");
}else if(a==b){
	printf("%s == %s\n", "a","b");
}

	return 0;
}


Measured memory_bytes: 2684
#include <iostream>
using namespace std;
int main(){
    int h,w;
    cin>>h>>w;
    while(h!=0&&w!=0){
        for(int g=1;g<=h;g++){
            for(int i=1;i<=w;i++){
                cout<<"#";
            }
            cout<<"\n";
        }
        cout<<"\n";
        cin>>h>>w;
    }
}

Measured memory_bytes: 3100
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=100005;
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int main(){
    char c;
    scanf(" %c",&c);
    c++;
    printf("%c\n",c);
    return 0;
}

Measured memory_bytes: 256
from queue import PriorityQueue


N, M = map(int, input().split())
que = PriorityQueue()
for _ in range(N):
    A, B = map(int, input().split())
    que.put([A, B])

ans = 0
while not que.empty():
    a, b = que.get()
    if M > b:
        M -= b
        ans += a * b
    else:
        ans += a * M
        break

print(ans)


Measured memory_bytes: 71764
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int F[5010];
int main(){
	int n=gi(),mod=gi(),t=0;
	if(n==2)return puts("3"),0;
	int pL,pR;
	if(n&1)pL=n+1>>1,pR=pL+1;
	else pL=n>>1,pR=pL+2;
	F[0]=1;
	for(int i=2;i<=n;++i){
		int c=(n-std::max(pR,i)+1)-std::max(0,pL-i+1)+1;
		for(int k=c;k<=n;++k)F[k]=(F[k]+F[k-c])%mod;
	}
	int ans=0;
	for(int i=0;i<=n;++i)ans=(ans+1ll*F[i]*(n-i))%mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
const double PI = 3.14159265358979323846;
int vector_finder(vector<int> vec, int number) {
  auto itr = find(vec.begin(), vec.end(), number);
  size_t index = distance(vec.begin(), itr);
  if (index != vec.size()) {  // 発見できたとき
    return 1;
  } else {  // 発見できなかったとき
    return 0;
  }
}
int main() {
  int n;
  int A = 0, W = 0, T = 0, R = 0;
  cin >> n;
  string d[n];
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    if (d[i] == "AC") A++;
    if (d[i] == "WA") W++;
    if (d[i] == "TLE") T++;
    if (d[i] == "RE") R++;
  }
  cout << "AC x " << A << endl;
  cout << "WA x " << W << endl;
  cout << "TLE x " << T << endl;
  cout << "RE x " << R << endl;
}

Measured memory_bytes: 6756
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int N,ans=0;
  cin>>N;
  int A[N];
  REP(i,N){
    cin>>A[i];
    ans+=A[i]-1;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,a,b) for (int i = (a); i < (b); i++ )
typedef pair<int,int> P;
typedef long long ll;
const int INF = 100000000;

int main() {
    int N, K;
    cin >> N >> K;
    ll ans = K*pow(K-1,N-1);
    cout << ans << endl;
}



Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
 
using namespace std;
 
typedef long long ll;
 
ll const INF = 1LL<<60;
 
ll N;
ll sum[200001];
ll arr[100001];
 
ll midx;

bool C(ll d, ll S[], ll base) {
  ll p1 = lower_bound(S, S+N, d+base) - S;
  ll p2 = lower_bound(S, S+N, d+S[p1]) - S;
  if(N <= p2) return false;
  if(S[N-1] - S[p2] >= d) {
    return true;
  }
  return false;
}
 
int main() {
   
  cin >> N;
  for(int i=0; i<N; i++) {
    cin >> arr[i];
  }
   
  for(int i=0; i<N; i++) {
    sum[i] = arr[i];
    if(i) sum[i] += sum[i-1];
  }
  for(int i=N; i<2*N; i++) {
    sum[i] = arr[i-N]+sum[i-1];
  }
   
  ll ans = 0;
  for(midx=0; midx<N; midx++) {
    ll lb = 0, ub = INF;
    while(ub-lb>1) {
      ll mid = (lb+ub)/2;
      ll c;
      if(midx>0) c = sum[midx-1];
      else c = 0;
 
      if(C(mid, sum+midx, c)) {
        lb = mid;
      } else {
        ub = mid;
      }
    }
    ans = max(ans, lb);
  }
   
  cout << ans << endl;
   
  return 0;
}

Measured memory_bytes: 3500
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 30;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int x; cin >> x;
    if(x < 1200){
        cout << "ABC" << endl;
    }
    else {
        cout << "ARC" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll N,P;
  cin>>N>>P;
  string S;
  cin>>S;
  //桁数のMOD用意
  vector<int> X(N,0);
  X[0]=1%P;
  for(int i=1; i<N; i++){
    X[i]=X[i-1]*10;
    X[i]=X[i]%P;
  }
  //1桁目からN桁目までのあまりを用意
  vector<int> Y(N,0);
  Y[0]=(S[N-1]-'0')*X[0];
  Y[0]=Y[0]%P;
  for(int i=1; i<N; i++){
    Y[i]=(S[N-1-i]-'0')*X[i]+Y[i-1];
    Y[i]=Y[i]%P;
  }
  //1桁目からN桁目まで、都度和をとる
  ll ans=0;
  if(P==2 || P==5){
    for(int i=0; i<N; i++){
      if((S[N-1-i]-'0')%P==0)
        ans+=N-i;
    }
  }
  else{
    unordered_map<int,int> mp;
    mp[0]=1;
    for(int i=0; i<N; i++){
      ll tmp=mp[Y[i]];
      mp[Y[i]]=tmp+1;
      ans+=tmp;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 2436
use std::collections::HashMap;

fn main() {
    let inputs: Vec<i32> = read_vec();
    let x = inputs[0];

    let nums: Vec<i32> = read_vec();
    let num_dict = conv_dict(&nums);

    // xからマイナス方向に探索
    let mut min_num = 0;
    // x自身も含めることに注意
    for i in (0..x + 1).rev() {
        if let Some(_) = num_dict.get(&i) {
            continue;
        }
        min_num = i;
        break;
    }

    // xからプラス方向に探索
    let mut max_num = 0;
    let mut i = x + 1;
    loop {
        if let Some(_) = num_dict.get(&i) {
            i += 1;
            continue;
        }
        max_num = i;
        break;
    }

    // 最短を計算
    let result = if (x - min_num).abs() <= (max_num - x).abs() {
        min_num
    } else {
        max_num
    };

    println!("{}", result);
}

fn conv_dict(nums: &Vec<i32>) -> HashMap<i32, i32> {
    let mut map = HashMap::new();
    for num in nums {
        map.insert(*num, 0);
    }
    return map;
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
#include <iostream>
#include <climits>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define INF 1LL << 60;
#include <string>
#include <typeinfo>
#include <bitset>

int main(){
  int s,ans;
  cin >> s;
  
  vector<int> vec;
  vec.push_back(s);
  bool flag = true;
  
  for(int i=1; i<1e9; i++){
    int a = vec.at(i-1);
    if(a%2 == 0){
      int b = a/2;
      vec.push_back(b);
    }
    else{
      int c = 3*a+1;
      vec.push_back(c);
    }
    for(int j=0; j<vec.size() -1 ; j++){
      int z = vec.size()-1;
      if(vec.at(z) == vec.at(j)){
        ans = z+1;
        flag = false;
        break;
      }
    }
    if(!flag){
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
	int n;
	cin>>n;
	long long int ans = 0;
	vector<string> s(n);
	map<string,long long int> a;
	rep(i, n) {
		cin >> s[i];
		sort(s[i].begin(), s[i].end());
		ans+=a[s[i]];
		a[s[i]]++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

typedef struct Edge{
    int from;
    int to;
    LL cost;
}Edge;

vector<Edge> G; // グラフ
vector<LL> D;   // 各ノードへの最短距離
int N,M;  // Nは頂点数
#define MINF -1000000000000000000

void Bellman_Ford(int a){   // a はスタート地点
    rep(i,N)D[i] = INF;
    D[a] = 0;   // 初期地点
    rep(i,N){   // N回繰り返すだけなので、indexは気にしない(頂点数)
        for(auto j : G){
            if(D[j.from] != INF && D[j.to] > D[j.from] + j.cost)D[j.to] = D[j.from] + j.cost;
        }
    }
}


// Bellman_Ford後に使用
void Nega_Search(){     // 負閉路を検知すると、その閉路に関わるノードのDを-INFに書き換える
    rep(i,N){
        for(auto j : G){
            if(D[j.to] != INF && D[j.to] > D[j.from] + j.cost)D[j.to] = MINF;
        }
    }
}

int main(){
    cin >> N >> M;
    G.resize(N);
    D.resize(N);
    rep(i,M){
        int a,b;
        LL c;
        cin >> a >> b >> c;
        a--;b--;
        G.push_back((Edge){a,b,-1*c});
    }
    Bellman_Ford(0);
    Nega_Search();
    LL ans = -1*D[N-1];
    if(D[N-1] == MINF)cout << "inf" << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>

int mas[3][3];
int cpy[3][3];


int main() {
  input();
  printf("%d\n", solve());
  return 0;
}
void input() {
  int i, j;
  for(i = 0; i < 3; i++)
    for(j = 0; j < 3; j++)
      scanf("%d", &mas[i][j]);
}

void output() {
  int i, j;
  for(i = 0; i < 3; i++) {
    for(j = 0; j < 3; j++) printf("%3d", mas[i][j]);
    puts("");
  }
}

void copy(int m[3][3], int t[3][3]) {
  int i, j;

  for(i = 0; i < 3; i++)
    for(j = 0; j < 3; j++) m[i][j] = t[i][j];
}

int calc() {
  int i, sum = 0;
  for(i = 0; i < 9; i++) {
    int v = mas[i/3][i%3];
    if(v) {
      v--;
      sum += abs(i/3-v/3)+abs(i%3-v%3);
    }
  }
  return sum;
}

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

void swap(int *a, int *b) {
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

int is_in(int x, int y) {
  return 0<=x&&x<3&&0<=y&&y<3;
}

int dfs(int x, int y, int p, int dep, const int lim) {
  int i, h = calc();
  //output();
  if(h == 0) return dep;
  //printf("%d %d %d\n", h, lim, p);
  if(dep+h > lim) return -1;

  for(i = 0; i < 4; i++) {
    int nx = x+dx[i], ny = y+dy[i], res;
    if(~p && i == (p+2)%4) continue;
    if(!is_in(nx, ny)) continue;
    swap(&mas[y][x], &mas[ny][nx]);
    res = dfs(nx, ny, i, dep+1, lim);
    if(~res) return res;
    swap(&mas[y][x], &mas[ny][nx]);
  }

  return -1;
}

void get_empty(int *x, int *y) {
  int i, j;
  for(i = 0; i < 3; i++) {
    for(j = 0; j < 3; j++) {
      if(!mas[i][j]) {
	*x = j;
	*y = i;
	return;
      }
    }
  }
}

int solve() {
  int x, y, lim, ans;
  get_empty(&x, &y);
  for(lim = 0; lim < 50; lim++) {
    copy(cpy, mas);
    if((ans = dfs(x, y, -1, 0, lim)) != -1) return ans;
    copy(mas, cpy);
  }
  return -1;
}




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

using namespace std;
using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int IINF = INT_MAX;
const static llong LINF = LLONG_MAX;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

/* --------------- template start --------------- */
template <typename T> 
struct BinaryIndexTree { // [1, n]
    vector<T> array;
    int n;

    BinaryIndexTree(int _n) {
        array.resize(_n + 1, 0);
        n = _n;
    }

    T cumsum(int i) {
        T s = 0;
        while(i > 0) {
            s += array[i];
            i -= i & -i;
        }

        return s;
    }

    T sum(int i, int j) {
        T ret_i = cumsum(i - 1);
        T ret_j = cumsum(j);

        return ret_j - ret_i;
    }

    void add(int i, T x) {
        while (i <= n) {
            array[i] += x;
            i += i & -i;
        }
    }
};

template<typename T>
struct UnionFind {
    vector<int> par;
    vector<T> sz;

    UnionFind(int n) {
        par.resize(n);
        sz.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            sz[i] = 1;
        }
    }

    int find_root(int x) {
        return par[x] == x ? x : par[x] = find_root(par[x]);
    }

    bool same(int x, int y) {
        return find_root(x) == find_root(y);
    }

    void unite(int x, int y) {
        x = find_root(x);
        y = find_root(y);
        if (x == y) return;
        
        if (sz[x] < sz[y]) swap(x, y);
        sz[x] += sz[y];
        par[y] = x;
    }

    T size_of_tree(int x) {
        return sz[find_root(x)];
    }
};
/* --------------- template end --------------- */

/* --------------- function start --------------- */
llong my_gcd(llong a, llong b) {
    return (a ? my_gcd(b % a, a) : b);
}
llong my_lcm(llong a, llong b) {
    return a * b / my_gcd(a, b);    
}

llong facmod(llong n) {
    if (n == 0) return 1;

    llong res = n;
    for (int i = n - 1; i > 0; --i) {
        res = (res * i) % MOD;
    }

    return res;
}
llong powmod(llong a, llong n) {
    llong res = 1;
    while (n > 0) {
        if (n & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        n >>= 1;
    }

    return res;
}
llong modinv(llong n) {
    return powmod(n, MOD - 2);
}
llong combmod(llong n, llong k) {
    llong res = 1;
    for (int i = 0; i < k; ++i) {
        res = (res * (n - i)) % MOD;
    }
    res = (res * modinv(facmod(k))) % MOD;

    return res;
}
/* --------------- function end --------------- */

int cnt = 0;
llong recur(llong x) {
    if (x == 0) return 0;
    ++cnt;
    return recur(x / 2);
}
int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    llong h;
    cin >> h;

    llong k = floor(log2(h));

    llong ans = 0;
    rep(i, k + 1) ans += pow(2, i);

    cout << ans << endl;

    return 0;
}

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

int main(){
    int n;
    cin >> n; 
    map<int, int> mp;
    rep(i, n) {
        int a;
        cin >> a;
        mp[a-1]++;
        mp[a]++;
        mp[a+1]++;
    }
    int mx = 0;
    for (auto p: mp) {
        mx = max(mx, p.second);
    }
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 4736
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = (1..n).map { sc.nextInt() - 1 }
    val b = (1..n).map { sc.nextInt() }
    val c = (1 until n).map { sc.nextInt() }
    var ans = 0
    repeat(n) {
        ans += b[a[it]]
        if (0 < it && a[it] == a[it - 1] + 1) {
            ans += c[a[it - 1]]
        }
    }
    println(ans)
}

Measured memory_bytes: 29480