akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-


def main():

    # 整数の入力
    a = int(input())
    # # スペース区切りの整数の入力
    nums = list(map(int, input().split()))

    vilist = []
    for i in range(a):
        vilist.append((nums[i], i))
    vilist = sorted(vilist, key=lambda vi: vi[0])

    # dp[x][y]をx人を左から活性度順に並べて、y人を右から活性度順に並べた状態のスコア最大値とする
    dp = []
    for i in range(a):
        dp.append([0]*(a-i))

    # dp = [[0] * a for i in range(a)]

    # cnt = 0
    # dp[i][j]を考える
    for k in range(a-1):
        vi = vilist.pop()
        v = vi[0]
        p = vi[1]
        vi_z = vilist[0]
        vz = vi_z[0]
        pz = vi_z[1]

        for i in range(k + 2):
            # cnt += 1
            j = k - i + 1
            # if i == 0 and j == 0:
            #     continue

            # 最後の値は場所が特定できるのでそのまま計算させる
            if k == a - 2:
                if j == 0:
                    dp[i][0] = dp[i-1][0] + v * abs(p - i + 1) + vz * abs(pz - i)
                elif i == 0:
                    dp[0][j] = dp[0][j-1] + v * abs(a - j - p) + vz * abs(a - j - 1 - pz)
                else:
                    dp[i][j] = max(dp[i-1][j] + v * abs(p - i + 1) + vz * abs(pz - i),
                                   dp[i][j-1] + v * abs(a - j - p) + vz * abs(pz - i))
            else:
                if j == 0:
                    dp[i][0] = dp[i-1][0] + v * abs(p - i + 1)
                elif i == 0:
                    dp[0][j] = dp[0][j-1] + v * abs(a - j - p)
                else:
                    dp[i][j] = max(dp[i-1][j] + v * abs(p - i + 1),
                                   dp[i][j-1] + v * abs(a - j - p))

    # print(cnt)
    print(max([max(x) for x in dp]))


main()


Measured memory_bytes: 120260
a1 = [1,3,5,7,8,10,12]
a2 = [4,6,9,11]
a3 = [2]

x,y = list(map(int,input().strip().split()))

if x in a1:
  _x = 0
elif x in a2:
  _x = 1
else:
  _x = 2
  
if y in a1:
  _y = 0
elif y in a2:
  _y = 1
else:
  _y = 2
  
if _x == _y:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;

#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)

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

const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;

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

using MIte = multimap<ll, ll, greater<ll> >::iterator;

//2112
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	// long long?
	ll N;
	cin >> N;

	ll a1 = N / 100;
	ll a2 = (N - 100 * a1) / 10;
	ll a3 = N - 100 * a1 - 10 * a2;
	if (a1 == a3) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
from collections import deque


#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets

#公約数の列挙
def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	#x:縦，y:横
	return fact(x+y)/fact(x)/fact(y)

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
	
def count_str(m):
	tmp={}
	for i in range(10):
		if i in tmp:
			tmp[i]=1
		else:
			tmp[i]+=1
	return tmp

def is_prime(n):
	if n==1: return True

	for i in range(2,int(math.sqrt(n))+1):
		if n%i==0:
			return False
	return True


n=input1()
print(n//2 + n%2)




Measured memory_bytes: 12504
#include<iostream>
#include<cstring>
 
using namespace std;
 
int main() {
	char a, b, c;
	cin >> a >> b >> c;
	if (a == '7' || b == '7' || c == '7') {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
	return 0;
}

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

using namespace std;

int main()
{
    string n,m;
    cin>>n;
    cin>>m;
    int counter = 0;
    for(int i=0; i<3; i++)
    {
        if(n[i]==m[i])
            counter++;

    }
    cout<<counter<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int P,Q,R;
    int m=200;
    scanf("%d  %d  %d", &P,&Q,&R);
    if(m>P+Q)
        m=P+Q;
    if(m>Q+R)
        m=Q+R;
    if(m>R+P)
        m=R+P;

    printf("%d", m);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define rfor(i, n) for (int i = n-1; i>=0; --i)
#define rmod(x, y) (((x%y)+y)%y)
using namespace std;
typedef vector<int>::iterator vit;
typedef unsigned int uint;
typedef unsigned short ushort;
typedef long long ll;
const int MAXN = 1024;
const ll modu = 1e9+7;
//OPERATORS


//GLOBALS


//FUNCTIONS

char matr[1001][1001];
int depe[1001][1001];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	memset(depe,0,sizeof(depe));
	int h,w; cin >> h >> w;	
	for(int i = 0; i < h; i++){
		string f; cin >> f;
		for(int j = 0; j < w; j++){
			matr[i+1][j+1] = f[j];
		}
	}
	
	depe[1][1] = 1;
	
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(i == 0 and j == 0) continue;
			if(matr[i+1][j+1] != '#')
				depe[i+1][j+1] = (depe[i+1][j]%modu + depe[i][j+1]%modu)%modu;
		}
	}

 	cout << depe[h][w] << endl;
	
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
using ll = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;

int main() {
  int n; cin>>n;
  int ans = 0;
  rep(i, n) {
    int a; cin>>a;
    int num = i + 1;

    if (num % 2 == 1 && a % 2 == 1) ans++; 
  }
  cout << ans;
}


Measured memory_bytes: 3592
#include<iostream>
#include<stdio.h>
#include<map>
#include<algorithm>
typedef long long ll;
using namespace std;

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

    ll t,i;
    cin >> t;
    string s;

    map <string,ll> poll;
    map <string,ll>::iterator itr;

    while(t--)
    {
        cin >> s;

        if(!poll[s])
            poll[s]=1;

        else
            poll[s]++;
    }
    int ocMax = 0;

    for (itr = poll.begin(); itr != poll.end(); ++itr)
    {
        //cout << itr-> first << " " << itr->second <<endl;
        if ( itr -> second >= ocMax)
        {
            ocMax = itr -> second;
        }
    }

    for (itr = poll.begin(); itr != poll.end(); ++itr)
    {
        if ( itr -> second == ocMax)
        {
            cout << itr -> first << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 19260
import java.util.Scanner;
class Main{
	public void Germany() {
		Scanner sc = new Scanner(System.in);
		int x;
		int i;
		x = sc.nextInt();
		for(i=1; x!=0; i++){
		System.out.println("Case" + " " + i + ":" + " " + x);
		x = sc.nextInt();
		}
	}
	public static void main(String[] args) {
			new Main().Germany();
		}
	}

Measured memory_bytes: 33004
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 5005
#define INF 1000000005LL
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int n,m;
vector<int> G[SIZE];
int indeg[SIZE];
bool used[SIZE];
vector<int> tsort;

bool T;

void bfs(int s){
	queue<int> q; //入次数0の頂点
	q.push(s);
	used[s] = true;
	while(!q.empty()){
		if(q.size()>=2)T = true;
		int u = q.front();q.pop();
		tsort.push_back(u);
		for(int i=0;i<G[u].size();i++){
			int v = G[u][i];
			indeg[v]--;
			if(indeg[v]==0 && !used[v]){
				q.push(v);
				used[v] = true;
			}
		}
	}
}



int main()
{
	scanf("%d%d",&n,&m);
	int a,b;
	T = false;
	for(int i=0;i<m;i++){
		scanf("%d%d",&a,&b);
		G[a].push_back(b);
		indeg[b]++;
	}
	vector<int> S; //start
	for(int i=1;i<=n;i++){
		if(indeg[i]==0)S.push_back(i);
	}

	//tsort
	for(int i=0;i<S.size();i++)bfs(S[i]);
	for(int i=0;i<tsort.size();i++)printf("%d\n",tsort[i]);
	if(S.size()>1 || T)puts("1");
	else puts("0");

	return 0;
}



Measured memory_bytes: 3424
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
using namespace std;
using ll=long long;
const ll LINF=0x1fffffffffffffff;
const vector<ll> four={0,1,0,-1,0};
using tuplis=pair<ll,pair<ll,ll>>;
template<class T>using pq=priority_queue<T,vector<T>,greater<T>>;
template<class T>inline constexpr bool update_min(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}



const vector<ll> dx={1,1,-1,-1};
const vector<ll> dy={-1,1,1,-1};

signed main(){
    ll h,w,a,b;
    cin>>h>>w>>a>>b;
    vector<string>s(h);
    for(auto&&i:s)cin>>i;
    ll x,y;
    rep(i,0,h)rep(j,0,w)if(s[i][j]=='s'){
        x=i;
        y=j;
    }
    vv(ll,cost,h,w,LINF);
    cost[x][y]=0;
    pq<tuplis>q;
    q.push({0,{x,y}});
    vv(bool,used,h,w);
    while(q.size()){
        ll x=q.top().second.first,y=q.top().second.second;
        q.pop();
        if(used[x][y])continue;
        used[x][y]=1;
        if(s[x][y]=='g'){
            cout<<cost[x][y]<<endl;
            return 0;
        }
        bool bomb=0;
        rep(i,-1,2)rep(j,-1,2)try{
            if(s.at(x+i).at(y+j)=='*')bomb=1;
        }catch(...){}
        rep(i,0,4)try{
            if(s.at(x+four[i]).at(y+four[i+1])!='#')if(update_min(cost[x+four[i]][y+four[i+1]],cost[x][y]+a))q.push({cost[x+four[i]][y+four[i+1]],{x+four[i],y+four[i+1]}});
        }catch(...){}
        if(!bomb){
            rep(i,0,4)try{
                if(update_min(cost.at(x+four[i]).at(y+four[i+1]),cost[x][y]+a+b))q.push({cost[x+four[i]][y+four[i+1]],{x+four[i],y+four[i+1]}});
            }catch(...){}
            rep(i,0,4)try{
                if(update_min(cost.at(x+dx[i]).at(y+dy[i]),cost[x][y]+a*2+b))q.push({cost[x+dx[i]][y+dy[i]],{x+dx[i],y+dy[i]}});
            }catch(...){}
        }
    }
    cout<<"INF\n";
}






Measured memory_bytes: 12128
import java.util.Scanner;
class Main{
    int n,m,x,y;
    public void solve(){
        Scanner sc = new Scanner(System.in);
        sc.useDelimiter("\\s");
        n = sc.nextInt();
        m = sc.nextInt();
        int [] []A = new int[n][m];
        int [] b = new int[m];
        int [] c = new int[n];
        for(x = 0; x < n; x++){
            c[x] = 0;
            for(y = 0; y < m; y++){
                A[x] [y]= sc.nextInt();
            }
        }
        for(y = 0; y < m; y++){
            b[y]= sc.nextInt();
        }
        for(x = 0; x < n; x++){
            for(y = 0; y < m; y++){
                c[x] = c[x] + A[x][y] * b[y];
            }
        }
        for(x = 0; x < n; x++){
            System.out.println(c[x]);
        }
    }
    public static void main(String[] args){
        new Main().solve();
    }
}

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

void print(vector<int> &v) {
  for (int i: v) {
    cout<<i<<" ";
  }
  cout<<endl;
}
int main() {
  long long n, K;
  cin>>n>>K;
  int a[n];
  for (int i=0; i<n; i++) cin>>a[i];
  vector<int> idx_a[200001];
  for (int i=0; i<n; i++) {
    idx_a[a[i]].push_back(i);
  }
  int cnt = 1;
  int idx = 0;
  map<int, int> most_left;
  while (true) {
    vector<int> v = idx_a[a[idx]];
    auto it = upper_bound(v.begin(), v.end(), idx);
    if (it == v.end()) {
      ++cnt;
      idx = v[0] + 1;
      most_left[cnt] = idx;
    } else {
      idx = *it + 1;
      most_left[cnt] = idx;
    }
    if (idx == n) {
      break;
    }
  }
  int mod = K % cnt;
  if (mod > 0) {
    vector<int> ans;
    idx = most_left[mod];
    while (idx < n) {
      vector<int> v = idx_a[a[idx]];
      auto it = upper_bound(v.begin(), v.end(), idx);
      if (it == v.end()) {
        ans.push_back(a[idx]);
        ++idx;
      } else {
        idx = *it + 1;
      }
    }
    for (int i=0; i<ans.size(); i++) {
      cout<<ans[i];
      if (i != ans.size() - 1) {
        cout<<" ";
      }
    }
  }
  cout<<endl;

  // vector<int> v;
  // for (int j=1; j<=K; j++) {
  //   cout<<"--"<<j<<"--"<<endl;
  //   for (int i=0; i<n; i++) {
  //     if (find(v.begin(), v.end(), a[i]) == v.end()) {
  //       v.push_back(a[i]);
  //     } else {
  //       while (v.size() > 0 && find(v.begin(), v.end(), a[i]) != v.end()) {
  //         v.pop_back();
  //       }
  //     }
  //     printf("idx: %d, a[i]: %d, s: ",i, a[i]);
  //     print(v);
  //   }
  // }
}

Measured memory_bytes: 23544
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define M1 1000000007
#define M2 998244353
#define fl(i,a,b) for(ll i=a;i<b;i++)
#define ifl(i,a,b) for(ll i=b-1;i>=a;i--)
#define V(a) vector<a>
#define bn "\n"

ll modI(ll a,ll m);
ll gcd(ll a,ll b);
ll powM(ll x,ll y,ll m);
ll swap(ll a,ll b);

void swap(ll& a,ll& b)
{
    ll tp=a;
    a=b;
    b=tp;
}

ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}

ll powM(ll x,ll y,ll m)
{
    ll ans=1,r=1;
    x%=m;
    while(r>0&&r<=y)
    {
        if(r&y)
        {
            ans*=x;
            ans%=m;
        }
        r<<=1;
        x*=x;
        x%=m;
    }
    return ans;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	int t=1;
    //cin>>t;
	while(t--)
	{
	   int n;
	   cin>>n;
	   for(int i=0;i<3;i++)
	   {
	       int num=n%10;
	       if(num==7)
	      { cout<<"Yes"<<endl;return 0;}
	      else n=n/10;
	      
	   }
	  cout<<"No";
	  
	}
	
	return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;   //author: madmin2619/mintu_agarwal
     
#define nfs() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define endl "\n"
#define pb push_back
#define pf push_front
#define forin(i, n) for(int i=0;i<n;i++)
#define tr(c, it) for(auto it=c.begin();it!=c.end();it++)
#define sz(c) c.size()
#define all(c) c.begin(),c.end()
#define ff first
#define ss second
#define m_p(x, y) make_pair(x, y)

const int inf = 1e15L;     
const int M = 1e9 + 7;
     
int32_t main(){
    nfs()
    int t, n, i, j, k, W, sum=0;
    cin >> n >> W;
    vector<int> w(n), v(n);
    forin(i, n)	cin >> w[i] >> v[i];
    forin(i, n)
        sum+=(v[i]);
    int dp[sum+1];
    fill(dp, dp+sum+1, inf);
    dp[0]=0;
    for(i=0;i<n;i++){
        for(j=sum-v[i];j>=0;j--){
                dp[j+v[i]]=min(dp[j+v[i]], dp[j]+w[i]);
        }
    }
    int res=0;
    for(i=sum;i>=0;i--){
        if(dp[i]<=W){
            res=i;
            break;
        }
    }
    cout << res << "\n";
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int d[100010];
int par[100010];

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

    vector<vector<int>> G(n);
    int a, b;
    for (int i = 0; i < m; ++i) {
        cin >> a >> b;
        a--; b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    priority_queue<pii, vector<pii>, greater<pii>> que;
    fill(d, d+n, INF);
    d[0] = 0;
    par[0] = 0;
    que.push(pii(0, 0));

    while(!que.empty()){
        pii p = que.top();
        que.pop();
        int nv = p.second;
        if(d[nv] < p.first) continue;

        for (int i = 0; i < G[nv].size(); ++i) {
            int to = G[nv][i];
            if(d[to] > d[nv] + 1){
                d[to] = d[nv] + 1;
                par[to] = nv;
                que.push(pii(d[to], to));
            }
        }
    }

    cout << "Yes" << endl;
    for (int i = 1; i < n; ++i) {
        cout << par[i] + 1 << endl;
    }
}

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

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

    int n;
    cin >> n;
    vector<vector<pair<int, int>>> adj(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b, w;
        cin >> a >> b >> w;
        a--, b--;
        adj[a].emplace_back(b, w);
        adj[b].emplace_back(a, w);
    }

    vector<int> color(n, -1);

    function<void(int, int, long long)> dfs = [&](int v, int p, long long acc) {
        color[v] = acc & 1;
        for (auto &s : adj[v]) {
            if (s.first != p) {
                dfs(s.first, v, acc + s.second);
            }
        }
    };
    dfs(0, -1, 0);

    for (int i = 0; i < n; i++) {
        cout << color[i] << '\n';
    }
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll Mod = (ll)(1e9) + 7;
const int MaxN = int(1e5) + 1;
ll fac[MaxN], inv_fac[MaxN];
int n, k;

ll inv(ll x){
    ll res = 1;
    ll y = Mod - 2;
    while (y > 0){
        if (y & 1) res = (res * x) % Mod;
        x = (x * x) % Mod;
        y >>= 1;
    }
    return res; 
}


void Init(){
    fac[0] = 1;
    for (int i = 1; i < MaxN; i++) fac[i] = (fac[i - 1] * (ll)i) % Mod;
    inv_fac[MaxN - 1] = inv(fac[MaxN - 1]);
    for (int i = MaxN - 2; i >= 0; i--) inv_fac[i] = (inv_fac[i + 1] * (ll)(i + 1)) % Mod;
}

ll nCk(int k,int n){
    ll ans = (fac[n] * inv_fac[k]) % Mod;
    ans = (ans * inv_fac[n - k]) % Mod;
    return ans;
}
int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout.tie(0);
    cin >> n >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(),a.end());
    ll ans = 0;
    Init();
    for (int i = n - 1; i >= k - 1; i --){
        ll val = (a[i] - a[n - 1 - i] + Mod*Mod) % Mod;
        val = (val * nCk(k-1,i)) % Mod;
        ans = (ans + val) % Mod;
    }
    cout << ans;
    return 0;
}









Measured memory_bytes: 2560
#include <iostream>
#include <vector>
using namespace std;
const int INF=1<<29;
int main() {
	int n,m,s,g1,g2;
	while(true){
		cin >> n >> m >> s >> g1 >> g2;
		if(n==0)	break;
		--s; --g1; --g2;
		vector<vector<int> > a(n, vector<int>(n,INF) );
		for(int i=0; i<n; ++i)	a[i][i]=0;
		for(int i=0; i<m; ++i){
			int f,t,c;
			cin >> f >> t >> c;
			--f; --t;
			a[f][t]=c;
		}
		for(int j=0; j<n; ++j)for(int i=0; i<n; ++i)for(int k=0; k<n; ++k)	a[i][k]=min(a[i][k], a[i][j]+a[j][k]);
		int ans=INF;
		for(int i=0; i<n; ++i)	ans=min(ans, a[s][i]+a[i][g1]+a[i][g2]);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1260
#include <cstdio>
#include <iostream>
using namespace std;
int a[101], b[101];
int main() {
    int n;
    while (scanf("%d",&n)) {
        if (!n) break;
        string str; cin>>str;
        for (int i=0; i<n; i++) {
            scanf("%d%d",&a[i],&b[i]);
            a[i]--; b[i]--;
        }
        for (int i=n-1; i>=0; i--) {
            int diff=(b[i]-a[i])%26;
            char c1, c2;
            if (str[a[i]]+diff>'z') c1=str[a[i]]+diff-26;
            else c1=str[a[i]]+diff;
            if (str[b[i]]+diff>'z') c2=str[b[i]]+diff-26;
            else c2=str[b[i]]+diff;
            str[a[i]]=c2; str[b[i]]=c1;
        }
        cout<<str<<endl;
    }
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
#pragma GCC optimize "-O3"
#pragma GCC target "tune=native"
using namespace std;
const int maxn = 333;
const int N = maxn * maxn;
vector<tuple<int,int,int> > p[N];
vector<int> sum[N];
int main(){
    int w, h, d;
    cin >> w >> h >> d;
    for(int e = 0; e < w; e++)
        for(int f = 0; f < h; f++){
            int v; cin >> v;
            p[v%d].push_back(make_tuple(v, e, f));
        }
    for(int e = 0; e < d; e++){
        sort(p[e].begin(), p[e].end());
        sum[e].assign(p[e].size(), 0);
        for(int f = 1; f < p[e].size(); f++)
            sum[e][f] = sum[e][f-1] + abs(get<1>(p[e][f-1]) - get<1>(p[e][f]))
                                    + abs(get<2>(p[e][f-1]) - get<2>(p[e][f]));

    }
    int q;
    cin >> q;
    while(q--){
        int l, r;
        cin >> l >> r;
        int pp = l % d;
        int pl = lower_bound(p[pp].begin(), p[pp].end(), make_tuple(l, -1, -1)) - p[pp].begin();
        int pr = lower_bound(p[pp].begin(), p[pp].end(), make_tuple(r, -1, -1)) - p[pp].begin();
        cout << sum[pp][pr] - sum[pp][pl] << endl;
    }
	return 0;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
//typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef pair<ll, pair<int, int>> P;
typedef pair<ll,pair<ll,ll>> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
int INFM =100000000;
ll MOD  = 1000000007;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
ll dp[100010][4];

int main(){
    string S,T;
    cin >> S >> T;
    int l = S.size();
    bool t = 0;
    for(int i = 0; i < l; i++){
        bool a = 1;
        for(int j = 0; j < l; j++){
            if(S.at(j) != T.at((j+i)%l)){
                a = 0;
            }
        }
        if(a == 1) t = 1;
    }
    if(t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

class Main {
  boolean[] primeTable;
  public static void main(String[] args) {
    Scanner cin = new Scanner(System.in);
    PrimeNum prime = new PrimeNum(100000010);
    prime.createTable();
    int n = cin.nextInt(), ct = 0;
    for (int i = 0; i < n; i++){
      int num = cin.nextInt();
      if (prime.judge(num)) ct++;
    }
    System.out.println(ct);
  }
}

class PrimeNum {
  private boolean[] primeTable;
  private int maxNum;
  
  PrimeNum(int n) {
    primeTable = new boolean[n];
    Arrays.fill(primeTable, true);
    this.maxNum = n;
  }

  protected void createTable() {
    final double sqrt_max = Math.sqrt(maxNum);
    for (int i = 2; i < sqrt_max; i++){
      if (primeTable[i]){
        for (int j = i * 2; j < maxNum; j += i)
          primeTable[j] = false;
      }
    }
  }

  protected boolean judge(int n) {
    return (primeTable[n]);
  }

  protected int serch(int n) {
    for (int i = 2; i < maxNum; i++){
      if (primeTable[i]) n--;
      if (n == 0) return(i);
    }
    return (-1);
  }
}

Measured memory_bytes: 141872
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  string str;
  cin >> str;
  if((str.substr(0,1)!=str.substr(1,1))&&(str.substr(1,1)!=str.substr(2,1))!=(str.substr(2,1)==str.substr(0,1))){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
# insertion_sort
N = gets.to_i
a = gets.split.map(&:to_i)
# 
# N = 6
# a = [5,2,4,6,1,3]
#
# p N
# p a

def insertion_sort(n,a)
  for i in 1..(n-1)
    v = a[i]
    j = i - 1
    while j >= 0 and a[j] > v
      a[j+1] = a[j]
      j -= 1
    end
    a[j+1] = v
    puts a.join(' ')
  end
end
puts a.join(' ')
insertion_sort(N,a)



Measured memory_bytes: 6888
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;cin>>n>>k;
    vector<ll> a(n);rep(i,n){cin>>a.at(i);}
    vector<vector<ll> > dp(n+1,vector<ll>(k+1,0));
    dp.at(0).at(k)=1;
    rep(i,n){
        dp.at(i+1).at(k) = dp.at(i).at(k);
        for(ll j=k-1;j>=0;j--){
            dp.at(i+1).at(j) += dp.at(i+1).at(j+1);
            dp.at(i+1).at(j) += dp.at(i).at(j);
            dp.at(i+1).at(j) %= MOD;
            if(j<k-a.at(i)){
                dp.at(i+1).at(j) += (MOD-dp.at(i).at(j+a.at(i)+1));
                dp.at(i+1).at(j) %= MOD;
            }
        }
    }
    DEBUG{
        rep(i,n){
            rep(j,k+1){
                cout << dp[i+1][j] <<" ";
            }
            cout << endl;
        }
    }
    cout << dp.at(n).at(0) << endl;
    return 0;
}


Measured memory_bytes: 80256
/*input
2 10
20 20
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long 
#define double long double

typedef pair<int,int> pi;

typedef vector<int> vi;
typedef vector<pi> vpi;

#define f first
#define s second
#define mp make_pair
#define pb push_back

#define gcd __gcd

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int n,x;
int a[101];
int i,j,ans = 0;

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  cin >> n >> x;
  for(i = 0;i < n;i++)cin >> a[i];
  sort(a,a+n);
  for(i = 0;i < n;i++){
      if(a[i] <= x){
      	x-=a[i];
      	ans++;
      	if(i == n-1 && x != 0)ans--;
      }
      if(a[i] > x)break;
  } 
  cout << ans;
  return 0;
}

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> A(N);
  for_each(begin(A), end(A), [](auto &e) { cin >> e; });
  sort(begin(A), end(A));
  vector<pair<long long, long long>> CB(M);
  for_each(begin(CB), end(CB), [](auto &e) { cin >> e.second >> e.first; });

  sort(rbegin(CB), rend(CB));
  int idx = 0;
  for (auto e : CB) {
    long long b, c;
    tie(c, b) = e;
    for (int i = 0; i < b && idx < N; i++, idx++) {
      if (A[idx] < c) {
        A[idx] = c;
      } else {
        idx = N;
      }
    }
  }

  cout << accumulate(begin(A), end(A), 0LL) << endl;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

struct aa {
	bitset<16>bs;
	int cost;
	int now;
};
class Compare {
public:
	bool operator()(const aa&l, const aa&r) {
		return l.cost>r.cost;
	}
};

int main() {
	while (true) {
		int N;cin>>N;
		if(!N)break;
		string a,b;cin>>a>>b;
		bitset<16>start,goal;
		for (int i = 0; i < N; ++i) {
			if(a[i]=='B')start[i]=true;
			if(b[i]=='B')goal[i]=true;
		}
		vector<vector<int>>memo((1<<N),vector<int>(N,1e9));
		for (int i = 0; i < N; ++i) {
			memo[start.to_ulong()][i]=0;
		}

		priority_queue<aa,vector<aa>,Compare>que;
		for (int i = 0; i < N; ++i) {
			que.push(aa{ start,0,i });
		}

		int ans=1e9;
		while (!que.empty()) {
			auto atop(que.top());
			que.pop();

			bitset<16>bs(atop.bs);
			const int cost(atop.cost);
			const int now(atop.now);
			if (bs == goal) {
				ans=min(ans,cost);
			}
			for (int i = 0; i < N; ++i) {
				int u=bs[now];
				bs[now]=bs[i];
				bs[i]=u;
				const int next_cost=cost+(abs(now-i));
				if (memo[bs.to_ulong()][i] > next_cost) {
					memo[bs.to_ulong()][i]=next_cost;
					que.push(aa{ bs,next_cost,i });
				}
				u = bs[now];
				bs[now] = bs[i];
				bs[i] = u;
			}
			for (int i = 0; i < N; ++i) {
				const int next_cost = cost + (abs(now - i));
				if (memo[bs.to_ulong()][i] > next_cost) {
					memo[bs.to_ulong()][i] = next_cost;
					que.push(aa{ bs,next_cost,i });
				}
			}
		}
		cout<<ans<<endl;
	}


	return 0;
}


Measured memory_bytes: 15780
package main

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

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func main() {
	list := getStdinIntArr64()
	N := list[0]
	K := list[1]
	A := getStdinIntArr64()
	var i int64
	var j int64

	for idx, val := range A {
		A[idx] = val - 1
	}
	Mati := make([]int64, N) // 町１からの距離
	for i = 0; i < N; i++ {
		Mati[i] = -1
	}

	// 町探索
	var prev int64 = 0
	var now int64 = 0
	for i = 0; i < K; i++ {
		prev = now
		now = A[now]
		if Mati[now] == -1 {
			Mati[now] = i
		} else {
			// ループした
			loop := Mati[prev] - Mati[now] + 1
			if loop <= 1 {
				break
			}
			var rem int64 = (K - (i + 1)) % loop
			if (K - (i + 1)) < 0 {
				rem = (K - (i + 1)) + loop%loop
			}
			for j = 0; j < rem; j++ {
				now = A[now]
			}
			break
		}
	}

	fmt.Printf("%d\n", now+1)
}

func getStdinIntArr64() []int64 {
	str := readLine()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 1024*1024*10)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 13176
n, l = map(int, input().split())

orig = int((n*(n+1))/2) + (l-1)*n
min = 1000000
flag = 0
for i in range(1, n+1):
    temp = l + i - 1
    # if temp == 0:
    #     min = 0
    #     break
    if abs(temp) < min:
        min = abs(temp)
        if temp < 0:
            flag = 1

if flag == 1:
    print(orig + min)
else:
    print(orig - min)

# orig = 0
# a = []
# low = 10000000
# for i in range(1, n+1):
#     orig += l + i - 1
#     if abs(l + i - 1) < low:
#         low = abs(l + i - 1)
#     # a.append(l + i - 1)
# # b = a
# # a = list(map(abs, a))
# # a = sorted(a)
# print(orig)
# print(orig - low)


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

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

/* [💭] [💡] [🎈] */

using namespace std;

vector<string> b;
vector<vector<int>> dist;

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

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

    int h, w, k;
    cin >> h >> w >> k;
    b.resize(h);
    dist.resize(h);
    for (auto &v : dist) v.resize(w);

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    for (int i = 0; i < h; i++) cin >> b[i];
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) b[i] += '.';
    x1--, y1--, x2--, y2--;

    queue<pii> q;
    q.emplace(x1, y1);
    while (q.size()) {
        int x = q.front().first, y = q.front().second;
        if (x == x2 && y == y2) break;
        q.pop();
        for (int d = 0; d < 4; d++) {
            int nx = x, ny = y;
            for (int l = 1; l <= k; l++) {
                nx += dx[d], ny += dy[d];
                if (0 > nx || nx >= h) break;
                if (0 > ny || ny >= w) break;
                if (b[nx][ny] == '@') break;
                if (dist[nx][ny]) {
                    if (dist[nx][ny] <= dist[x][y]) break;
                    continue;
                }
                if (nx == x1 && ny == y1) continue;
                dist[nx][ny] = dist[x][y] + 1;
                q.emplace(nx, ny);
            }
        }
    }

    if (!dist[x2][y2]) {
        cout << -1;
    } else {
        cout << dist[x2][y2];
    }

    return 0;
}

Measured memory_bytes: 10544
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    let n:i64 = read();
    let a:i64 = read();

    println!("{}", if n%500<=a {"Yes"} else {"No"});
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
	int k, a, b;
	ll bi = 1;
	cin >> k >> a >> b;
	if (a >= b - 2) {
		cout << k + 1 << endl;
		return 0;
	}
	for (int i = 0; i < k; i++) {
		if (bi >= a && i < k - 1) {
			bi += b - a;
			i++;
			continue;
		}
		bi++;
	}
	cout << bi << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int accept = Integer.valueOf(br.readLine());
        System.out.println(accept*accept*accept);
    }
}

Measured memory_bytes: 24152
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;
int N ;
ll h[100010] ;
ll dp[100010] ;
 int main(){
  int N ;cin>> N;
  rep(i,N) cin>>h[i] ; //初期化
  rep(i,100010) dp[i] =INF ;
  dp[0] =0 ;
  rep(i,N){
      chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1])) ;
      if(i>1) chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2])) ;
  }

    cout <<dp[N-1] <<endl ; 
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using II = pair<int, int>; using VII = vector<II>; using VVII = vector<VII>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, const pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, const map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
constexpr int MOD = 1e9 + 7;

signed main() {
  int a, b, c; cin >> a >> b >> c;
  int ans = b + min(a + b + 1, c);
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		// String s = "abcde";
		// print(s, 0, 3);
		// System.out.println(reverse(s, 1, 3));
		// System.out.println(reverse(s, 1, 1));
		// System.out.println(replace(s, 0, 4, "ab"));

		Scanner sc = new Scanner(System.in);
		String input1 = "";
		String input2 = "";
		String input3 = "";
		String[] output;
		String[] data;
		String[] Command = { "print", "reverse", "replace" };
		String str = "";
		boolean judge_str = true;
		boolean judge_q = true;
		boolean judge_command = true;

		int q = 0;
		int a = 0;
		int b = 0;
		int printcount = 0;

		input1 = sc.nextLine();
		str = input1;

		if (str.length() < 1 || str.length() > 1000) {
			judge_str = false;
		}

		if (str.equals(str.toLowerCase()) == false) {
			judge_str = false;
		}

		if (judge_str == true) {
			input2 = sc.nextLine();
			q = Integer.parseInt(input2);
			output = new String[q];

			if (q < 1 || q > 100) {
				judge_q = false;
			}

			if (judge_q == true) {

				for (int i = 0; i < q; i++) {
					input3 = sc.nextLine();
					data = input3.split(" ");
					a = Integer.parseInt(data[1]);
					b = Integer.parseInt(data[2]);
					if (data[0].equals(Command[0])) {
						output[printcount] = print(str, a, b);
						printcount++;
					} else if (data[0].equals(Command[1])) {
						str = reverse(str, a, b);
					} else if (data[0].equals(Command[2])) {
						str = replace(str, a, b, data[3]);
					} else {
						judge_command = false;
					}
				}

				if (judge_command == true) {

					for (int j = 0; j < printcount; j++) {
						System.out.println(output[j]);

					}
				}

			}

		}

	}

	public static String print(String s, int start, int end) {
		return s.substring(start, end + 1);

	}

	public static String reverse(String s, int start, int end) {
		String restring = "";
		for (int i = end; i >= start; i--) {
			restring += "" + s.charAt(i);
		}
		return s.substring(0, start) + restring
				+ s.substring(end + 1, s.length());
	}

	public static String replace(String s, int start, int end, String t) {

		return s.substring(0, start) + t + s.substring(end + 1, s.length());
	}
}



Measured memory_bytes: 45644
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)                                                         

using namespace std;
#define ll long long

int main(){
  string s;
  cin >> s;
  int K;
  cin >> K;
  vector<string> sss;
  for(int i=0; i<(int)s.size(); i++){
    for(int j=i; j<i+K; j++){
      sss.push_back(s.substr(i, j-i+1));
    }
  }
  sort(sss.begin(), sss.end());
  int begin = 0;
  while(begin < (int)sss.size()){
    string stmp = sss[begin];
    int end = begin;
    while(end < (int)sss.size() && sss[end] == stmp)
      end++;
    sss.erase(sss.begin()+begin+1, sss.begin()+end);
    begin++;
  }
  // for(int i=0; i<(int)sss.size(); i++)                                                                       
  //   cout << sss[i] << ' ';                                                                                   
  // cout << endl;                                                                                              
  cout << sss[K-1] << endl;
  return 0;
}

Measured memory_bytes: 1660
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

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

using namespace std;

int main() {
    int n, x;
    cin >> n >> x;
    int sumx = 0;
    int cnt = 0;
    rep(i, n){
        int l;
        cin >> l;
        sumx += l;
        if(sumx <= x)
            cnt++;
    }
    cout << cnt + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 998244353;
// const ll INF = 1000000000000000000LL;

int main(){
   int k;
   cin >> k;
   int x = 7 % k;
   set<int> s;
   int i = 1;
   while(s.count(x) == 0){
      if(x==0){
         cout << i << endl;
         return 0;
      }
      s.insert(x);
      x = (x*10+7)%k;
      i++;
   }
   cout << -1 << endl;
}

Measured memory_bytes: 50460
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

int main(void){
	int D;
	cin>>D;
	
	if(D==25)cout<<"Christmas"<<endl;
	else if(D==24)cout<<"Christmas Eve"<<endl;
	else if(D==23)cout<<"Christmas Eve Eve"<<endl;
	else if(D==22)cout<<"Christmas Eve Eve Eve"<<endl;
	
	return 0;
}


Measured memory_bytes: 256
N,S=map(int,input().split())
dp=[0]*3001
res=0
for i,a in enumerate(map(int,input().split())):
    for w in range(S-a,0,-1):
        dp[w+a]+=dp[w]
    dp[a]+=i+1
    res+=dp[S]
print(res%998244353)

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

int partition(int A[],int p,int r){
	int x = A[r];
	int i = p-1;
	
	for(int j=p; j<=r-1; j++){
		if(A[j] <= x){
			i = i+1;
			swap(A[i],A[j]); 
		}
	}	
	swap(A[i+1],A[r]);
		      
  return i+1;
 } 
  
 int main(){
 	int n;
	cin >> n;
 
  int A[100000];
  for(int i=0; i<n; i++){
      cin >> A[i];
  }
 
  int x = partition(A, 0, n-1);
 
  for(int i=0; i<n; i++){
      if(i==x){
          cout << '[' << A[i] << ']';
      }
      else{
          cout << A[i];
      }
      if(i<n-1){
          cout << ' ';
       }
      else{
          cout << endl;
       }
   }
 
  return 0;
}

Measured memory_bytes: 3388
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <bitset>
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
using namespace std;    
const int N = int(3e5), mod = int(1e9)  + 7;
ll n,x;

int main () {
	cin >> n >> x;
	cout << 3 * (n - __gcd(n,x));

return 0;
}

Measured memory_bytes: 256
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

string a, b, c;
int n;

int main() {
	cin >> n;
	cin >> a >> b >> c;
	int ret = 0;
	for (int i = 0; i < n; i++) {
		set<char> s;
		s.insert(a[i]);
		s.insert(b[i]);
		s.insert(c[i]);
		//cerr << s.size() << endl;
		ret += s.size() - 1;
	}
	cout << ret << endl;
	return 0;
}


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

int main(void)
{
	char s[1<<13];

	while (EOF!= scanf(" %s", s)){
		if (strlen(s) > 5 && s[2]== s[3] && s[4]== s[5]){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, n) for(ll i = x; i < n; i++) 
#define pb push_back
#define ll long long
#define hii cout << "hii" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
#define int ll
#define mpp make_pair
#define endl '\n'
#define ff first 
#define ss second
#define all(s) s.begin(), s.end()
#define fuck_you_scanf ios_base:: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define si size()
 
const int N = 1e6 + 5;
set<int> v[26];

int32_t main()
{
    string input1;
    string input2;
    cin >> input1 >> input2;
    for(int i = 0; i < input1.size(); i++)
    {
        v[input1[i] - 'a'].insert(i);
    }
    
    int rot = 0;
    int prev = -1;
    for(int j = 0; j < input2.size(); j++)
    {
        auto it = v[input2[j] - 'a'].lower_bound(prev + 1);
        if(it == v[input2[j] - 'a'].end() and v[input2[j] - 'a'].size() == 0) {cout << -1; return 0;}
        else if(it == v[input2[j] - 'a'].end())
        {
            prev = *v[input2[j] - 'a'].begin();
            rot++;
        }
        else
        {
            prev = *it;
        }
    }
    cout << rot * input1.si + prev + 1;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n, m;
    cin >> n >> m;
    vvi adj(n + m);
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int a;
            cin >> a;
            a--;
            adj[i].push_back(n + a);
            adj[n + a].push_back(i);
        }
    }

    vi visited(n + m);
    function<void(int, int)> dfs = [&](int v, int p) {
        visited[v] = 1;
        for (int s : adj[v]) {
            if (s != p && !visited[s]) {
                dfs(s, v);
            }
        }
    };

    dfs(0, -1);

    int ok = 1;
    for (int i = 0; i < n; i++) {
        if (!visited[i]) {
            ok = 0;
            break;
        }
    }
    cout << (ok ? "YES" : "NO") << endl;
}

Measured memory_bytes: 10356
#ABC-137-C
N = int(input())
S = []
for _ in range(N):
    si = sorted(input())
    S.append("".join(si))

ans = 0
already_exist = {}

for i in range(N):
    if S[i] not in already_exist:
        already_exist[S[i]] = 0
    else:
        already_exist[S[i]] += 1
        ans += already_exist[S[i]]

# TLEになるので却下
# for i in range(N-1):
#     for j in range(i+1, N):
#         if S[i] == S[j]:
#             ans += 1

print(ans)

Measured memory_bytes: 19404
#!/usr/bin/python

def shred(num, bit):
    num = list(str(num))
    i = 0
    while bit:
        if bit & 1:
            num[i] += num[i+1]
            num.pop(i+1)
        else:
            i += 1

        bit >>= 1

    return num

def testcase_ends():
    t, num = map(int, raw_input().split())
    if t == 0 and num == 0:
        return 1

    cut = []
    best = -1
    for i in range(1<<(len(str(num))-1)):
        curcut = shred(num, i)
        cursum = sum(map(int, curcut))
        if cursum > t: continue
        if cursum == best:
            cut.append(curcut)
        elif cursum > best:
            cut = [curcut]
            best = cursum

    if not cut:
        print 'error'
    elif len(cut) > 1:
        print 'rejected'
    else:
        print best, ' '.join(cut[0])

def main():
    while True:
        if testcase_ends():
            return 0

if __name__ == '__main__':
    main()

Measured memory_bytes: 6412
def inp():
  return map(int, input().split())

h1, h2 = inp()
k1, k2 = inp()
a, b, c, d = inp()

def point(x1, x2):
  return x1 * a + x2 * b + (x1 // 10) * c + (x2 // 20) * d

ph = point(h1, h2)
pk = point(k1, k2)
if ph > pk:
  print("hiroshi")
elif ph < pk:
  print("kenjiro")
else:
  print("even" )


Measured memory_bytes: 5600
K,n = map(int,input().split(' '))
A = list(map(int, input().split(' ')))
A.sort()
maxD = K-(A[-1]-A[0])
i = 0
while i < n-1:
    if A[i+1]-A[i] > maxD:
        maxD = A[i+1]-A[i]
    i += 1
print(K-maxD)

Measured memory_bytes: 26444
loop do
  n = gets.chomp.to_i
  row_count = gets.chomp.to_i

  break if n == 0 && row_count == 0

  pairs = row_count.times.map { gets.chomp.split(' ') }

  friends, others = [], []

  pairs.each do |pair|
    if pair[0] == '1'
      friends << pair[1] 
    else
      others << pair
    end
  end

  foaf = others.inject([]) do |pairs, pair|
      pairs << pair[1] if friends.include?(pair[0])
      pairs << pair[0] if friends.include?(pair[1])
      pairs
    end

  puts (friends | foaf).uniq.size
end

Measured memory_bytes: 10028