akhauriyash/Code-Regression huggingface dataset:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
ans = [[0]*w for _ in range(h)]
def dfs(x,y):
    if 0 <= x < h and 0 <= y < w:
        if s[x][y] == "#":
            ans[x][y] = 1 
            
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            dfs(i+1, j)
            dfs(i, j+1)
            dfs(i, j-1)
            dfs(i-1, j)
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            if ans[i][j]!=1:
                print("No")
                exit()
print("Yes")

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 100005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

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

  ll n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  ll res = 0;
  for (ll i = 1; i < s.length(); i++) {
    res += (s[i] == s[i - 1]);
  }

  char prev1 = s[0];
  ll cnt = 0;
  vector<ll> curr;
  for (ll i = 0; i < n; i++) {
    if (s[i] == prev1)
      cnt++;
    else {
      curr.push_back(1);
      prev1 = s[i];
      cnt = 1;
    }
  }

  if (cnt) {
    curr.push_back(1);
  }

  ll val = 0;
  for (ll i = 1; i < ((ll)curr.size() - 1); i += 2) {
    val++;
  }

  if (val >= k) {
    cout << res + 2 * k << en;
  } else {

    ll flag = 0;

    if (curr.size() && (curr.size() % 2 == 0)) {
      flag = 1;
    }
    cout << res + 2 * val + flag << en;
  }

  return 0;
}


Measured memory_bytes: 1480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[114514];
int main(){
	ll a;
	long double b;
	cin>>a>>b;
	b=b*100.0+0.5;
	a=a*ll(b)/100;
	cout<<a<<endl;
	return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

//const ll INF=(ll)1e18;
const int INF=(1<<21);

int dp[1001][4096];

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

  REP(i,M+1)REP(j,1<<N)dp[i][j]=INF;
  dp[0][0]=0;

  REP(i,M){
    int a,b;
    cin >> a >> b;
    int m=0;
    REP(j,b){
      int c;
      cin >> c;
      m += 1<<(c-1);
    }

    REP(j,1<<N){
      if(dp[i][j]==INF)continue;
      dp[i+1][j] = dp[i][j];
    }

    REP(j,1<<N){
      if(dp[i][j]==INF)continue;

//      printf("%d %d: %d %d\n", i,j|m, dp[i][j|m], dp[i][j] + a);
      int tmp = min(dp[i][j|m], dp[i][j] + a);
      dp[i+1][j|m] = min(tmp, dp[i+1][j|m]);
    }
  }


  // REP(i,M+1){
  //   REP(j,1<<N){
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  if(dp[M][(1<<N)-1] == INF){
    cout << -1 << endl;
  }else{
    cout << dp[M][(1<<N)-1] << endl;
  }

}




Measured memory_bytes: 16256
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main(void){
  string number;
  cin >> number;
  
  for(int i=0;i<3;i++){
    if(number[i] == '1')
      number[i] = '9';
    else if(number[i] == '9')
      number[i] = '1';
  }
  
  cout << number << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    string s;
    cin >> s;
    vector<ll> cnt(2, 0);
    rep(i, len(s)) cnt[s[i] - 'A']++;
    if ((cnt[0] > 0) && (cnt[1] > 0)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int i = Integer.parseInt(line);
			int count = 0;
			// a == b
			if (i % 2 == 0) {
				count++;
			}
			// a != b
			for (int j = 1; j < line.length(); j++) {
				if (line.charAt(j) != '0') {
					int l = Integer.parseInt(line.substring(0, j));
					int r = Integer.parseInt(line.substring(j));
					if (l <= r && (r - l) % 2 == 0) {
						count++;
					}
				}
			}
			System.out.println(count);
		}
	}
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

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

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  ll a, b; std::cin >> a >> b;
  auto exor_up2x = [](ll x) {
    ll ret = 0, remain = x % 4 + 1;
    x = (x / 4) * 4;
    rep(i, remain) {
      ret ^= x+i;
    }
    return ret;
  };
  ll up2a = exor_up2x(a-1), up2b = exor_up2x(b);
  std::cout << (up2a ^ up2b) << "\n";
}


Measured memory_bytes: 256
N=gets.chomp.to_i
a=gets.chomp.split.map(&:to_i)

a.sort!.reverse!

ans = 0
N.times do |i|
  next if i == 0
  if i == 1
    ans += a[0]
    next
  end

  n=i/2
  ans += a[n]
end
p ans


Measured memory_bytes: 31592
from collections import Counter
from itertools import combinations
N = int(input())
Slist = [input() for _ in range(N)]
Sc = Counter([S[0] for S in Slist])
ans = 0
for x, y, z in combinations(list("MARCH"), 3):
    ans += Sc[x] * Sc[y] * Sc[z]
print(ans)

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

int main(int argc, char const *argv[]){
	int N,a;
	string W[105];
	bool b = false;

  	cin >> N;
	cin >> W[0];
	a = W[0].length() - 1;

	for(int i = 1; i < N; i++){
		cin  >> W[i];
		
		if (W[i][0] != W[i-1][a]) {
			b = true;
		}

		a = W[i].length() - 1;

		for(int j = 0; j < i; j++){
			if(W[j] == W[i]){
				b = true;
			}
		}

	}

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

}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long sum = 0;
		int max = 0;
		for(int i = 0; i < N; i++) {
			int p = sc.nextInt();
			sum += p;
			max = Math.max(max,p);
		}
		sum -= max/2;
		System.out.println(sum);
	}
}


Measured memory_bytes: 23380
//Robs Code

/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <iomanip>

/***********MACROS***************/
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>

using namespace std;

const int N = 1e5 + 1;
int n,m,i,j,k,l,x,y,z,cnt[3],sum[3];

/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	long double x,y;
	cin >> x >> y;
	cout << (((int)((int)x*round(y*100)))/(int)100) << "\n";
}
//.........	

Measured memory_bytes: 3772
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var k = int.Parse(Console.ReadLine().Trim());
        getAns(k);
    }
    static void getAns(int k)
    {
        var q = new Queue<long>();
        for (int i = 1; i <= 9; i++) q.Enqueue(i);
        var count = 0;
        while (true)
        {
            var w = q.Dequeue();
            count++;
            if (count == k) { Console.WriteLine(w); return; }
            var a = w % 10;
            if (a == 0) { q.Enqueue(w * 10); q.Enqueue(w * 10 + 1); }
            else if (a == 9) { q.Enqueue(w * 10 + 8); q.Enqueue(w * 10 + 9); }
            else
            {
                q.Enqueue(w * 10 + a - 1);
                q.Enqueue(w * 10 + a);
                q.Enqueue(w * 10 + a + 1);
            }
        }
    }
}


Measured memory_bytes: 15072
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin >> s;
	bool ac = 0;
	for (int i = 0; i < (int) s.length() - 1; ++ i) if (s[i] == 'A' && s[i + 1] == 'C') ac = 1;
	puts(ac ? "Yes" : "No");
}


Measured memory_bytes: 256
mod = 998244353
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline
    N, K = map(int, input().split())
    L = []
    R = []
    for _ in range(K):
        l, r = map(int, input().split())
        L.append(l)
        R.append(r)

    dp = [0] * (N+1)
    dp[1] = 1
    for i in range(2, N+1):
        dp[i] = dp[i-1]
        for k in range(K):
            l, r = L[k], R[k]
            if i - l <= 0:
                continue
            mi = max(1, i - r)
            ma = i - l
            dp[i] = (dp[i] + dp[ma] - dp[mi - 1])%mod
    print((dp[-1] - dp[-2])%mod)


if __name__ == '__main__':
    main()


Measured memory_bytes: 70152
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#include <queue>
#include <map>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	string s;
	while(cin >> s){
	int cnt=0,cnt1=0;
	//string s; cin >> s;
	int n=s.size();
	for(int i=0;i<n-2;i++){
		if(s.substr(i,3)=="JOI")cnt++;
		if(s.substr(i,3)=="IOI")cnt1++;
	}
	cout << cnt << endl;
	cout << cnt1 << endl;
	}
}


Measured memory_bytes: 3228
#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
int n;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
main()
{
	while(cin>>n,n)
	{
		vector<pair<pair<int,int>,pair<int,int> > >a;
		vector<int>x,y;
		for(int i=0;i<=n;i++)
		{
			int u,v,U,V;
			if(i<n)cin>>u>>V>>U>>v;
			else u=v=-1,U=V=1e9;
			a.push_back({{u,v},{U,V}});
			x.push_back(u);
			x.push_back(U);
			y.push_back(v);
			y.push_back(V);
		}
		sort(x.begin(),x.end());x.erase(unique(x.begin(),x.end()),x.end());
		sort(y.begin(),y.end());y.erase(unique(y.begin(),y.end()),y.end());
		map<int,int>X,Y;
		int sz=0;
		for(int e:x)X[e]=sz++;
		sz=0;
		for(int e:y)Y[e]=sz++;
		vector<vector<long> >S(x.size(),vector<long>(y.size()));
		vector<vector<bool> >used(x.size(),vector<bool>(y.size()));
		function<void(int,int)>dfs=[&dfs,&used,&x,&y,&S](int nx,int ny){
			used[nx][ny]=1;
			for(int r=0;r<4;r++)
			{
				int tx=nx+dx[r],ty=ny+dy[r];
				if(tx<0||ty<0||tx>=x.size()||ty>=y.size()||used[tx][ty]||S[nx][ny]!=S[tx][ty])continue;
				dfs(tx,ty);
			}
		};
		sz=0;
		for(auto p:a)
		{
			long pu=1L<<sz++;
			int u,v,U,V;
			u=X[p.first.first];
			v=Y[p.first.second];
			U=X[p.second.first];
			V=Y[p.second.second];
			S[u][v]+=pu;
			S[u][V]-=pu;
			S[U][v]-=pu;
			S[U][V]+=pu;
		}
		for(int i=0;i<x.size();i++)for(int j=0;j+1<y.size();j++)S[i][j+1]+=S[i][j];
		for(int i=0;i+1<x.size();i++)for(int j=0;j<y.size();j++)S[i+1][j]+=S[i][j];
		int ans=0;
		for(int i=0;i+1<x.size();i++)for(int j=0;j+1<y.size();j++)
		{
			if(used[i][j])continue;
			ans++;
			dfs(i,j);
		}
		cout<<ans<<endl;
	}
}



Measured memory_bytes: 3960
N = int(input())
a = list(map(int,input().split()))
amod4 = [0,0,0,0]
for i in range(N):
    if a[i]%4 == 0:
        amod4[0]+=1
    elif a[i]%4 == 1:
        amod4[1]+=1
    elif a[i]%4 == 2:
        amod4[2]+=1
    else:
        amod4[3]+=1
if amod4[1]+amod4[3] <= amod4[0]:
    print("Yes")
elif amod4[1]+amod4[3] == amod4[0]+1 and amod4[2] == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14224
/*
                           \\\|///
                         \\  - -  //
                          (  @ @  )
O-----------------------oOOo-(_)-oOOo--------------------O
| CPP-file           *******                 IOI         |
|                by  *Jacob*	             IZhO        |
|                    *******                 BOI         |
|   <I_am_Champion>              Oooo        APIO        |
O------------------------oooO---(   )--------------------O
                        (   )    ) /
                        \  (    (_/
                         \_)
SITE: USACO
ID: allakov1
TASK:
LANG: C++
*/
#include<bits/stdc++.h>
//#include<conio.h>
#define pb(a) push_back(a)
#define pp() pop_back()
#define ff first
#define ss second
#define inf 1000000000
#define pii pair<int,int>
#define pll pair<long long,long long>
#define ll  long long
using namespace std;
const int N=INT_MAX;
ll a[109],b[109],c[109],d,n,j,i,k,l,m;
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		l+=a[i];
	}
	k=l;
	cin>>m;
	for(i=1;i<=m;i++)
	{
		l=k;
		cin>>b[i]>>c[i];
		l-=a[b[i]];
		l+=c[i];
		cout<<l<<endl;
	}
	
	
}

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

#define jaldi ios_base::sync_with_stdio(false)
#define fr(i,j,n) for(i=j;i<n;i++)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%ld",&x)
#define sll(x) scanf("%lld",&x)
#define sc(x) scanf("%c",&x)
#define ss(x) scanf("%s",x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%ld",x)
#define pll(x) printf("%lld",x)
#define pc(x) printf("%c",x)
#define ps(x) printf("%s",x)
#define vi vector<int> 
#define vl vector<long> 
#define vll vector<long long>
#define vc vector<char>  
#define vs vector<string>
#define vvi vector<vector<int>> 
#define vvll vector<vector<long long>> 
#define F first
#define S second
#define ll long long
#define pb push_back
#define ppii pair<int,int> 
#define ppll pair<long long,long long>
#define ppcc pair<char,char>
#define ppss pair<string,string> 
#define vpll vector<pair<long long,long long>>
#define PI 3.1415926535897932384626
#define precision(x) cout<<fixed<<setprecision(x) 
#define mod 998244353

int x_d[8] = {-1,1,0,0,-1,-1,1,1};
int y_d[8] = {0,0,-1,1,-1,1,-1,1};

ll power(ll b,ll e)
{
    if(b==0)
        return 0;
    
    ll r=1;
    while(e>0)
    {
        if(e%2)
            r=(r*b)%mod;
        b=(b*b)%mod;
        e/=2;
    }
    return r;
}

int main()
{
    jaldi;
    precision(20);
    
    ll n;
    cin>>n;
    ll i,ans=0;
    fr(i,1,n+1)
    {
        if(i%3!=0 && i%5!=0)
            ans+=i; 
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3636
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
As = list(mapint())
doubling = [[0]*N for _ in range(61)]
doubling[0] = list(map(lambda x:x-1, As))

for i in range(1, 61):
    for j in range(N):
        doubling[i][j] = doubling[i-1][doubling[i-1][j]]

now = 0
for i in range(61):
    if (K>>i)&1:
        now = doubling[i][now]
print(now+1)

Measured memory_bytes: 196296
import queue
n, q = map(int, input().split(" "))
plist = queue.Queue()
for i in range(n):
    plist.put((lambda l: [l[0], int(l[1])])(input().split(" ")))
time = 0
history = queue.Queue()
while not plist.empty():
    p = plist.get()
    if p[1] <= q:
        time += p[1]
        history.put([p[0], time])
    else:
        p[1] -= q
        plist.put(p)
        time += q
while not history.empty():
    p = history.get()
    print("%s %d" % (p[0], p[1]))

Measured memory_bytes: 18108
using System;
using System.Collections.Generic;
using System.Runtime;
using System.Numerics;
using System.Linq;

namespace ABC153
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] ha = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ans = (ha[0] + ha[1] - 1) / ha[1];
            Console.WriteLine(ans);
        }
    }
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define per(i,n,a) for(ll i=n-1;i>=a;i--)
#define nl "\n"
#define LLMAX 1e18
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define fastread cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);

ll dp[100001][101];

int main(){
  fastread;

  int n,w;
  cin >> n >> w;

  ll a,b;
  vector<pair<ll,ll>> values;
  rep(i,0,n){
    cin >> a >> b;
    values.pb(mp(a,b));
  }

  rep(i,0,100001){
    rep(j,0,n){
      if(!i)
        dp[i][j]=0;
      else if(!j && i==values[j].ss)
        dp[i][j]=values[j].ff; 
      else
        dp[i][j]=w+1;
    }
  }

  rep(i,1,100001){
    rep(j,1,n){
      if(i-values[j].ss>=0)
        dp[i][j]=min(dp[i][j-1], values[j].ff + dp[i-values[j].ss][j-1]);
      else
        dp[i][j]=dp[i][j-1];
    }
  }

  ll ma=0;
  rep(i,0,100001){
    rep(j,0,n){
      // cout << dp[i][j] << " ";
      if(dp[i][j]<=w){
        ma=max(ma,i);
      }
    }
    // cout << nl;
  }

  cout << ma << nl;
  return 0;
}


Measured memory_bytes: 79232
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
#include <math.h>
#include <vector>
//#include <unordered_map>
//#include <string>
//typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007

int main() {
    int n;
    int t;
    int a;
    vector<int> h;
    int tmp_h;
    double min_error=1000.0;
    double tmp_error;
    int ans;
    cin >> n;
    cin >> t >> a;
    for(int i=0; i<n; i++){
        cin >> tmp_h;
        h.push_back(tmp_h);
    }

    for(int i=0; i<n; i++){
        tmp_error=(double)a-((double)t-0.006*(double)h[i]);
        tmp_error=fabs(tmp_error);
        if(tmp_error<min_error){
            min_error=tmp_error;
            ans=i;
        }
    }
    ans++;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 768
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, *A = map(int, read().split())

    pos = [a for a in A if a >= 0]
    neg = [a for a in A if a < 0]

    pos.sort()
    neg.sort(reverse=True)

    if N == K:
        vec = A
    elif N == len(neg):
        if K & 1:
            vec = neg[:K]
        else:
            vec = neg[-K:]
    else:
        vec = []
        if K & 1:
            vec.append(pos.pop())

        tmp = []
        while len(neg) >= 2:
            tmp.append(neg.pop() * neg.pop())
        while len(pos) >= 2:
            tmp.append(pos.pop() * pos.pop())

        tmp.sort(reverse=True)
        vec.extend(tmp[: K // 2])

    ans = 1
    for a in vec:
        ans = ans * a % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 122964
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
int main(){
    int n;
    std::cin >> n;
    std::vector<long long int> a(n);
    for (auto& itr : a)
    {
      int tmp;
      std::cin >> tmp;
      itr = tmp;
    }
    std::vector<int> index(n);
    std::iota(index.begin(), index.end(), 0);
    std::sort(index.begin(), index.end(), [&](int x, int y){return a[x] > a[y];});

    std::vector<std::vector<long long int> > dp(n + 1, std::vector<long long int>(n + 1));
    long long int ans = 0;
    for (int l = 0; l < n; ++l)
    {
      for (int r = 0; r < n; ++r)
      {
        if (l + r == n)
        {
          ans = std::max(ans, dp[l][r]);
          break;
        }
        dp[l + 1][r] = std::max(dp[l + 1][r], dp[l][r] + std::abs(l - index[l + r]) * a[index[l + r]]);
        dp[l][r + 1] = std::max(dp[l][r + 1], dp[l][r] + std::abs(n - r - 1 - index[l + r]) * a[index[l + r]]);
      }
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 34632
#include <stdio.h>
 int main(void)
 {
     int H ,W;
     int i, j;
     while(1){
         scanf("%d %d" ,&H ,&W);
         if(H == 0 && W == 0) break;
         for ( i = 0; i < H; i++ ){
             for ( j = 0; j < W; j++ ){
                 if(j==0||j==W-1||i==0||i==H-1){
                     printf("#");
                     
                 }else{
                     printf(".");
                     }
                 }
             printf("\n");
        }
         puts("");
        }
     return 0;
     }



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

using namespace std;
#define ll long long int
int const mod=1000000007;

int main()
{
    string s,t;
    cin>>s>>t;
    ll n=s.size(),m=t.size();
    ll ans=1000;
    for(int i=0;i<n;i++)
    {
        if(i+m>n)
            break;
        ll c=0;
        for(int j=0;j<m;j++)
        {
            if(t[j]!=s[i+j])
                c++;
        }
        ans=min(ans,c);
    }
    cout<<ans;
}


Measured memory_bytes: 3624
//前置き
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>

using namespace std;

typedef  long long ll;

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)

//関数定義
//最大公約数
ll gcd(ll a, ll b);

//最小公倍数
ll lcm(ll a, ll b);

int main(){
    // ========================================================
    int a, b;
    cin >> a >> b;
    cout << max(0, a-2*b) << endl;
}

//最大公約数
ll gcd(ll a, ll b) {  
    if (!b)  
        return a;  
    return gcd(b, a%b);  
}

//最小公倍数
ll lcm(ll a, ll b) {  
    return a*b/gcd(a,b);  
} 

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

ll dp[100005][3];

int main() {
    int n;
    cin >> n;
    vector<ll> a(n), b(n), c(n);
    rep(i,n) cin >> a[i] >> b[i] >> c[i];
    for (int i = 1; i <= n; ++i) {
        dp[i][0] = max(dp[i-1][1]+a[i-1], dp[i-1][2]+a[i-1]);
        dp[i][1] = max(dp[i-1][0]+b[i-1], dp[i-1][2]+b[i-1]);
        dp[i][2] = max(dp[i-1][0]+c[i-1], dp[i-1][1]+c[i-1]);
    }
    ll ans = max(dp[n][0], dp[n][1]);
    ans = max(ans, dp[n][2]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
//https://atcoder.jp/contests/agc029/tasks/agc029_e
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

map<pair<int,int>,int> memo;
vector<int> G[212345];
int N;
int c[212345];
int Q(int v,int p,int x){
    if(memo.count({v,x}))return memo[{v,x}];
    int ret=0;
    for(int u:G[v]){
        if(p==u)continue;
        if(u>x)continue;
        ret+=1+Q(u,v,x);
    }
    return memo[{v,x}]=ret;
}
void solve(int v,int p,int mv,int mpv){
    if(v!=1){
        if(v>mpv){
            c[v]=c[p]+Q(v,p,mv)+1;
        }
        else{
            c[v]=c[p]-Q(v,p,mpv)+Q(v,p,mv);
        }
    }
    for(int u:G[v]){
        if(u==p)continue;
        solve(u,v,max(v,mv),max(mpv,p));
    }
}
int main(){
    cin>>N;
    for(int i:range(N-1)){
        int a,b;
        cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    solve(1,0,0,0);
    string sp(N,' ');sp.push_back('\n');
    for(int i:range(2,N+1)){
        cout<<c[i]<<sp[i];
    }
    return 0;
}

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

int main(){
  
  vector<int> cst(3);
  cin >> cst[0] >> cst[1] >> cst[2];
  sort(cst.begin(), cst.end());
  
  cout << cst[2] - cst[0] << endl; 
  return 0;
}

Measured memory_bytes: 3632
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 X = sc.nextInt();

        int pattern = 0;

        for(int i = 0; i <= A ; i++){
            for(int j = 0; j <= B ; j++){
                for(int k =0 ; k <= C ; k++){ 
                    if( i*500 + j*100 + k*50 == X){
                        pattern++;
                    }
                }
            }
        }
        System.out.println(pattern);
    }
}

Measured memory_bytes: 23636
#include<stdio.h>

int main(void) {

    int a,b,c,i,x=0;

    scanf("%d%d%d",&a,&b,&c);
    for (i=a;i<=b;i++) {

        if ((c%i)==0) x++;

    }

    printf("%d\n",x);
    return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   String S = sc.next();
   if(S.charAt(0)==S.charAt(1)&&S.charAt(1)==S.charAt(2)&&S.charAt(2)==S.charAt(3)){
     System.out.println("No");
   }else if(S.charAt(0)==S.charAt(1)){
     if(S.charAt(2)==S.charAt(3)){
     System.out.println("Yes");
     }else{
     System.out.println("No");
     }
   }else if(S.charAt(0)==S.charAt(2)){
     if(S.charAt(1)==S.charAt(3)){
     System.out.println("Yes");
     }else{
     System.out.println("No");
     }
   }else if(S.charAt(0)==S.charAt(3)){
     if(S.charAt(1)==S.charAt(2)){
     System.out.println("Yes");
     }else{
     System.out.println("No");
     }
   }else if(S.charAt(1)==S.charAt(2)){
     if(S.charAt(0)==S.charAt(3)){
     System.out.println("Yes");
     }else{
     System.out.println("No");
     }
   }else if(S.charAt(1)==S.charAt(3)){
     if(S.charAt(0)==S.charAt(2)){
     System.out.println("Yes");
     }else{
     System.out.println("No");
     }
   }else if(S.charAt(2)==S.charAt(3)){
     if(S.charAt(0)==S.charAt(1)){
     System.out.println("Yes");
     }else{
     System.out.println("No");
     }
   }else{
     System.out.println("No");
   }
  
 }
}

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

#define ll long long
#define MOD 1000000007




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

    ll t = s/1000 -n;

    ll x=-1,y=-1,z=-1;

    for(int i=0;4*i<=t;i++){
        if((t-4*i)%9==0){
            y=i;
            x=(t-4*i)/9;

            break;
        }
    }

    z = n -(x+y);
    
    int j=0;
    if(x<0||y<0||z<0){
        cout<<"-1 -1 -1"<<endl;
    }else{
        cout<<x<<" "<<y<<" "<<z<<endl;
    }
    
}



Measured memory_bytes: 256
#!/usr/bin/env python

def main(N, d):
    d.sort()
    upper = N // 2
    lower = N // 2 -1
    ans = d[upper] - d[lower]
    return ans

if __name__ == '__main__':
    N = int(input())
    d = list(map(int, input().split()))
    print(main(N, d))

Measured memory_bytes: 52780
# coding: utf-8
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
Ac=(((a-1)//10)+1)*10
Bc=(((b-1)//10)+1)*10
Cc=(((c-1)//10)+1)*10
Dc=(((d-1)//10)+1)*10
Ec=(((e-1)//10)+1)*10
Af=(a-1)%10
Bf=(b-1)%10
Cf=(c-1)%10
Df=(d-1)%10
Ef=(e-1)%10

if min(Af,Bf,Cf,Df,Ef)==Af:
  print(a+Bc+Cc+Dc+Ec)
  
elif min(Af,Bf,Cf,Df,Ef)==Bf:
  print(Ac+b+Cc+Dc+Ec)
  
elif min(Af,Bf,Cf,Df,Ef)==Cf:
  print(Ac+Bc+c+Dc+Ec)  
  
elif min(Af,Bf,Cf,Df,Ef)==Df:
  print(Ac+Bc+Cc+d+Ec)
  
elif min(Af,Bf,Cf,Df,Ef)==Ef:
  print(Ac+Bc+Cc+Dc+e)

Measured memory_bytes: 3064
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    println!("{}",if read::<usize>()==2||read::<usize>()==2{"No"}else{"Yes"})
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  cin>>n;
  int nt=0;
  int nx=0,ny=0;
  bool ans=true;
  rep(i,n){
    int t,x,y;
    cin>>t>>x>>y;
    int cost=abs(x-nx)+abs(y-ny);
    int p=t-nt-cost;
    if(p<0 || p%2==1)ans=false;
  }
  if(ans)  cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
A = []
B = []

for _ in range(N):
    A.append(input())

for _ in range(M):
    B.append(input())

for i in range(N - M + 1):
    for j in range(N - M + 1):
        f = True

        for p in range(M):
            if A[i + p][j:j + M] != B[p]:
                f = False
                break
        if f:
            print('Yes')
            exit()
print('No')


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<functional>
#include<cstdlib>
#include<stdexcept>
#include<numeric>
#include<cmath>
#include<fstream>
#include<memory>
#include<algorithm>
#include<cstring>
#include<ctime>
#include<deque>
#include<sstream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<map>
#include<set>
#include<list>
#include<cassert>
#include<deque>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<27
#define all(n) n.begin(),n.end()
#define F first
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define S second
#define ppins(a,b,c,d) PP(P(a,b),P(c,d))
#define pb push_back
#define My "NARIYOSHI_XX"
#define pf push_front
#define LIM 100000
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef long long ll;
typedef unsigned long long ull;

bool calc(set<int>& B,set<int>& A,string& ope,stack<set<int> >& ele,map<string,set<int> >& index)
{
  set<int> C;
  for(set<int>::iterator it_A = A.begin();it_A != A.end();it_A++)
    {
      for(set<int>::iterator it_B = B.begin();it_B != B.end();it_B++)
	{
	  if(ope == "+")
	    {
	      C.insert(((*it_A)+(*it_B))%256);
	    }
	  else if(ope == "-")
	    {
	      C.insert(((*it_A)-(*it_B)+256)%256);
	    }
	  else if(ope == "*")
	    {
	      C.insert(((*it_A)*(*it_B))%256);
	    }
	  else if(ope == "/")
	    {
	      if(!(*it_B))
		{
	
		  return false; 
		}
	      C.insert(((*it_A)/(*it_B))%256);
	    }
	  else 
	    assert(false);
	}
    }
  index[My] = C;
  ele.push(C);
  return true;
}

int main(){
  int m,n;
  map<string,set<int> > index;
  stack<set<int> > ele;
  deque<string> st;
  bool fin = false;

  cin >> m;
  for(int i=0;i<m;i++)
    {
      string name;
      int lb,ub;
      cin >> name >> lb >> ub;
      for(int j = lb;j <= ub;j++)
	index[name].insert(j);
    }

  cin >> n;
  for(int i=0;i<n;i++)
    {
      string e;
      cin >> e;
      //cout <<"e = " << e << endl;
      if(fin)
	continue;
      if(e != "/" && e != "*" && e != "-" && e != "+")
	{
	  if(index.find(e) != index.end())
	    {
	      ele.push(index[e]);
	    }
	  else
	    {
	      set<int> FAGS;
	      FAGS.insert((atoi)(e.c_str()));
	      ele.push(FAGS);
	    }
	}
      else 
	{
	  set<int> A,B;
	  if(ele.empty())
	    {
	      fin = true;
	      continue;
	    }
	  B = ele.top(),ele.pop();
	  if(ele.empty())
	    {
	      fin = true;
	      continue;
	    }
	  A = ele.top(),ele.pop();
	  if(!calc(B,A,e,ele,index))
	    fin = true;	    
	}

    }

  if(fin)
    {
      cout << "error" << endl;
      return 0;
    }
  
    cout << "correct" << endl;

return 0;
}

Measured memory_bytes: 1408
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }


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

	vll acc_l(N + 2, 0), acc_r(N + 2, 0);
	fori(i, 1, N + 1) {
		if (S[i - 1] == 'W') acc_l[i] = acc_l[i - 1] + 1;
		else acc_l[i] = acc_l[i - 1];
	}
	ford(i, 1, N + 1) {
		if (S[i - 1] == 'E') acc_r[i] = acc_r[i + 1] + 1;
		else acc_r[i] = acc_r[i + 1];
	}

	ll ans = INF;
	fori(i, 1, N + 1) ans = min(ans, acc_l[i - 1] + acc_r[i + 1]);
	cout << ans << endl;

}

Measured memory_bytes: 5380
#include<stdio.h>
#include<stdlib.h>
int func(const void *a,const void *b)
{
  if(*(int*)a < *(int*)b){
      return -1;
    }
    else
      if(*(int*)a == *(int*)b){
        return 0;
      }
    return 1;
}
int main()
{
  int S[200001],A[200001],i,N,K,t,res=0,k=0;
  scanf("%d %d",&N,&K);
  for(i=0;i<N;i++)
    scanf("%d",&A[i]);
  for(i=0;i<N+1;i++)
    S[i] = 0;
  for(i=0;i<N;i++)
    S[A[i]]++;
  qsort(S,N+1,sizeof(int),func);
  for(i=0;i<N+1;i++)
    if(S[i])
      k++;
  t = k - K;
  for(i=0;i<N+1;i++){
    if( t <= 0 )
      break;
    if( S[i] != 0){
      res += S[i];
      t--;
    }else
      continue;
   }
  printf("%d\n",res);
}



Measured memory_bytes: 2556
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i, c) for(long long i=0; i<(long long)c; i++)
const ll INF=1000000000000001;
int main() {
	ll n;
	int cnt =0;
	cin >>n;
	for (int a=1;a<=n-1;a++){
		for(int b=1;a*b<n;b++){
			if (a*b<n) cnt++;
		}
	}
	cout << cnt <<endl;
	return 0;
}


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

vector<vector<int>> to;
vector<int> a, ans, dp;

void dfs(int cur, int pre){
	int tmp = lower_bound(dp.begin(), dp.end(), a[cur]) - dp.begin();
	int par = dp[tmp];
	dp[tmp] = a[cur];
	ans[cur] = tmp;
	if(pre != -1) ans[cur] = max(ans[cur], ans[pre]);
	for(auto&& next : to[cur]){
		if(next == pre) continue;
		dfs(next, cur);
	}
	dp[tmp] = par;
}

int main()
{
	int n;
	cin >> n;
	to.resize(n);
	a = ans = vector<int>(n);
	dp = vector<int>(n, 1e9);
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n - 1; i++){
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		to[u].push_back(v);
		to[v].push_back(u);
	}
	dp[0] = -1e9;
	dfs(0, -1);
	for(int i = 0; i < n; i++) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 28008
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll H, W;
    cin >> H >> W;
    ll Ch, Cw;
    cin >> Ch >> Cw;
    Ch--;
    Cw--;
    ll Dh, Dw;
    cin >> Dh >> Dw;
    Dh--;
    Dw--;

    vector<vector<char>> maze(H, vector<char>(W));
    vector<vector<ll>> dist(H, vector<ll>(W, -1));
    dist.at(Ch).at(Cw) = 0;

    rep(0, i, H)
    {
        rep(0, j, W)
        {
            cin >> maze.at(i).at(j);
        }
    }

    queue<Pll> que, que_2;

    pair<ll, ll> s = make_pair(Ch, Cw);

    que.push(s);
    que_2.push(s);

    vector<ll> dx(4), dy(4);
    dx = {1, 0, -1, 0};
    dy = {0, 1, 0, -1};

    while (!que_2.empty())
    {
        while (!que.empty())
        {
            Pll v = que.front();
            que.pop();

            ll x = v.first;
            ll y = v.second;

            rep(0, i, 4)
            {
                ll nx = x + dx.at(i);
                ll ny = y + dy.at(i);
                if (nx < 0 || ny < 0 || nx >= H || ny >= W)
                {
                    continue;
                }
                if (maze.at(nx).at(ny) == '#')
                {
                    continue;
                }

                if ((dist.at(nx).at(ny) == -1) || (dist.at(nx).at(ny) > dist.at(x).at(y)))
                {
                    dist.at(nx).at(ny) = dist.at(x).at(y);
                }
                else
                {
                    continue;
                }
                Pll nv = make_pair(nx, ny);
                que.push(nv);
                que_2.push(nv);
            }
        }

        pair<ll, ll> v = que_2.front();
        que_2.pop();

        ll x = v.first;
        ll y = v.second;

        rep(-2, i, 3)
        {
            rep(-2, j, 3)
            {
                ll nx = x + i;
                ll ny = y + j;

                if (nx < 0 || ny < 0 || nx >= H || ny >= W)
                {
                    continue;
                }
                if (maze.at(nx).at(ny) == '#')
                {
                    continue;
                }

                if ((dist.at(nx).at(ny) == -1) || (dist.at(nx).at(ny) > dist.at(x).at(y) + 1))
                {
                    dist.at(nx).at(ny) = dist.at(x).at(y) + 1;
                }
                else
                {
                    continue;
                }
                Pll nv = make_pair(nx, ny);
                que.push(nv);
                que_2.push(nv);
            }
        }
    }

    cout << dist.at(Dh).at(Dw) << endl;
}

Measured memory_bytes: 12388
def dfs(prev,length,n,m,lists,A):

    if length == n+1:
        res = 0
        for lis in lists:
            if A[lis[1]-1] - A[lis[0]-1] == lis[2]:
                res += lis[3]
        return res
    else:
        res = 0  
        for i in range(prev,m+1):
            Atmp = A + [i]
            res = max(res,dfs(i,length+1,n,m,lists,Atmp))
        return res

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

lists = []
for i in range(Q):
    lis = list(map(int,input().split()))
    lists.append(lis)

print(dfs(1,1,N,M,lists,[]))



Measured memory_bytes: 74320
#include <algorithm>
#include <cstdio>

using namespace std;

int main(){
    int N[65535];
    int i = 0;
    while(true){
        scanf("%d", &N[i]);
        if(N[i] == 0) break;
        i++;
    }

    for (int j = 0; j < i; j++){
        printf("Case %d: %d\n", j + 1, N[j]);
    }
    return 0;
}

Measured memory_bytes: 1076
#include<iostream>
#include<algorithm>
using namespace std;
long long n;
int p_1[106],p_0[106];

int main(){
    cin>>n;
    n++;
    int k1=0,k2=0;
    int m=100;
    while(n>1){
        if((n&1)==1){
            p_1[k1]=m--;k1++;n--;
        }
        else{
            p_0[k2]=m--;k2++;n=n>>1;
        }
    }
    cout<<(k1+k2)*2<<endl;
    for(int i=0;i<k1;i++)
        cout<<p_1[i]<<" ";
    for(int i=k2-1;i>=0;i--)
        cout<<p_0[i]<<" ";
    int p=101-k1-k2;
    for(;p<100;p++)
        cout<<p<<" ";
    cout<<"100"<<endl;
    return 0;
}


Measured memory_bytes: 256
S = input()
K = 'keyence'

for i in range(8):
  #print(S[:i], S[len(S)-7+i:], K[:i], K[i:])
  if S[:i] == K[:i] and S[len(S)-7+i:] == K[i:]:
    print('YES')
    break
  else:
    continue
else:
  print('NO')

Measured memory_bytes: 3060
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
  n,t = readInts()
  T = readInts()
  X = 0
  
  for i in range(n-1):
    if T[i+1] - T[i] >= t:
      X += t
    else:
      X += T[i+1] - T[i]
  X += t
  print(X)
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 25200
n,m = map(int,input().split())
p = list(map(int, input().split()))
g = [[] for _ in range(0,n+1)]
visit = [None] * (n+1)
ans = 0
for _ in range(0,m):
    x,y = map(int, input().split())
    g[x].append(y)
    g[y].append(x)
for i in range(1,n+1):
    if visit[i] is not None:
        continue
    stack = [i]
    part = [i]
    visit[i] = 0
    while len(stack) > 0:
        q = stack.pop()
        for qq in g[q]:
            if visit[qq] is None:
                visit[qq] = 0
                part.append(qq)
                stack.append(qq)
    part2 = []
    for i in part:
        part2.append(p[i-1])
    ans += len(list(set(part) & set(part2)))
print(ans)


Measured memory_bytes: 42464
import io.StdIn._

object Main extends App {
  val line1 = readLine.split(" ").map(_.toInt)
  val N = line1(0)
  val P = line1(1)

  val S = readLine.toCharArray.map(_.toInt - 48)

  if (10 % P == 0) {
    var ans = 0L
    for (i <- 0 until N) {
      if (S(i) % P == 0) {
        ans = ans + i + 1
      }
    }
    println(ans)
  } else {

    val d = Array.fill[Int](N + 1)(0)
    var ten = 1
    for (i <- N - 1 to 0 by -1) {
      val a = S(i) * ten % P
      d(i) = (d(i + 1) + a) % P
      ten = ten * 10 % P
    }

    val cnt = Array.fill[Int](P)(0)
    var ans = 0L
    for (i <- N to 0 by -1) {
      ans = ans + cnt(d(i))
      cnt(d(i)) = cnt(d(i)) + 1
    }

    println(ans)
  }
}


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

int main(){
  int n,l;cin>>n>>l;
  vector<string> s(n);
  for (auto && a : s) {
    cin>>a;
  }

  sort(s.begin(),s.end());
  for (auto && a : s) {
    cout << a;
  }
  cout << endl;
}


Measured memory_bytes: 256
S = gets.chomp().split("")

acgt = ["A", "C", "G", "T"]

count = 0
max_count = 0

S.each do |s|
  if acgt.include?(s)
    count += 1
  elsif count > max_count
    max_count = count
    count = 0
  else
    count = 0
  end
end

puts [max_count, count].max

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

// 出力
void print() { std::cout << '\n'; }
template <class T>void print(const T &x) {std::cout << x <<'\n';}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}

void solve(long long A, long long B){
    if (A + B == 3) print(3);
    if (A + B == 4) print(2);
    if (A + B == 5) print(1);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        boolean ok = true;
        for(int i = 0; i < n; i++){
            int a = Integer.parseInt(sc.next());
            if(a % 2 == 0){
                if(a % 3 != 0 && a % 5 != 0){
                    ok = false;
                }
            }
        }
        
        if(ok){
            System.out.println("APPROVED");
        }else{
            System.out.println("DENIED");
        }
    }
}

Measured memory_bytes: 21844
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int ll
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define ll long long
#define pi pair<int,int> 
#define pii pair<pi,int>
#define vi vector<int>
#define pb push_back 
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
// #define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a >= mod)a %= mod;
}
int maxn = 3e5 + 10;
int n = maxn;
// vi a(100);
vi s(4*maxn);
// void build(int id = 1,int l = 0,int r = n){
// 	if(r - l < 2){	//	l + 1 == r
// 		s[id] = a[l];
// 		return ;
// 	}
// 	int mid = (l+r)/2;
// 	build(id * 2, l, mid);
// 	build(id * 2 + 1, mid, r);
// 	s[id] = s[id * 2] + s[id * 2 + 1];
// }
int sum(int x,int y,int id = 1,int l = 0,int r = n){
	if(x >= r or l >= y)	return 0;
	if(x <= l && r <= y)	return s[id];
	int mid = (l+r)/2;
	return max(sum(x, y, id * 2, l, mid),
			sum(x, y, id * 2 + 1, mid, r));
}
void modify(int p, int x,int id = 1, int l = 0, int r = n){
	// s[id]+=x-a[p];
	if(r-l<2){
		// a[p]=x;
		s[id] = x;
		return;
	}
	int mid = (l+r)/2;
	if(p < mid) modify(p, x, id*2, l, mid);
	else modify(p, x, 2*id + 1, mid, r);
	s[id] = max(s[2*id],s[2*id+1]);
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,k;
	cin>>n>>k;
	vi v(n);
	rep(i,n){
		cin>>v[i];
	}	
	int ans = 0;
	rep(i,n){
		int x = sum(max(0ll,v[i]-k),min(v[i]+k+1,maxn));
		x++;
		ans = max(ans,x);
		if(sum(v[i],v[i]+1) < x){
			modify(v[i],x);
		}
	}
	cout<<ans;
	return 0;
}

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

#define ll long long
#define ull unsigned long long
#define openfiles ifstream cin("input10.txt"); ofstream cout("output10.txt");

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector <ll> dp(n+2, 1000000000), a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    dp[0] = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = 1; j <= 2; j++)
        {
            if(i - j >= 0)
                dp[i] = min(dp[i-j] + abs(a[i] - a[i - j]), dp[i]);
        }
    }
    cout<<dp[n - 1];
}


Measured memory_bytes: 1792