akhauriyash/Code-Regression huggingface dataset:
char buf[1800000],f[5];
sz,osz;
#define rd(x)x=0;for(;;){k=buf[sz++];if(k<'0')break;x=x*10+k-'0';}
N,M,L,Q;
D[301][301];
i,j,k;
a,b,c;
main()
{
	read(0,buf,1800000);
	rd(N);rd(M);rd(L);
	for(i=0;i<N;i++)for(j=0;j<N;j++)D[i][j]=1000000001;
	for(i=0;i<M;i++)
	{
		rd(a);rd(b);rd(c);
		--a;
		--b;
		D[a][b]=D[b][a]=c;
	}
	for(k=0;k<N;++k)for(i=0;i<N;++i)for(j=0;j<N;++j)
		if(D[i][j]>D[i][k]+D[k][j])D[i][j]=D[i][k]+D[k][j];
	for(i=0;i<N;++i)for(j=0;j<N;++j)D[i][j]=D[i][j]>L?1000000000:1;
	for(k=0;k<N;++k)for(i=0;i<N;++i)for(j=0;j<N;++j)
		if(D[i][j]>D[i][k]+D[k][j])D[i][j]=D[i][k]+D[k][j];
	rd(Q);
	for(i=0;i<Q;++i)
	{
		rd(a);rd(b);
		--a;
		--b;
		if(D[a][b]<1000000000)
		{
			c=D[a][b]-1;
			k=0;
			do{
				f[k++]=c%10+'0';
				c/=10;
			}while(c);
			for(;k;)buf[osz++]=f[--k];
		}
		else buf[osz++]='-',buf[osz++]='1';
		buf[osz++]='\n';
	}
	write(1,buf,osz);
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define INF (1LL<<30)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long

signed main(){
	while(1){
		int n,l,r;
		cin>>n>>l>>r;
		if(n==0&&l==0&&r==0)break;
		int a[50];
		lp(i,n){
			cin>>a[i];
		}
		int ans=0;
		for(int i=l;i<=r;i++){
			int now=i;
			lp(j,n){
				if(now%a[j]==0){
					if(j%2==0)ans++;
					break;
				}
				if(j==n-1){
					if(n%2==0)ans++;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3100
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO.Pipes;
using System.Runtime;
 
namespace Csharponly
{
    class Program
    {
        static public void Main()
        {
        	int[] NM = Arrayint();
        	int[] N = new int[NM[0]];
        	int[] H = Arrayint();
        	for(int i = 0; i < NM[1]; i++)
        	{               
        	    int[] AB = Arrayint();
        	    if(H[AB[0]-1] >= H[AB[1]-1])
        	    {
        	        N[AB[1]-1]++;
        	    }
        	    if(H[AB[0]-1] <= H[AB[1]-1])
        	    {
        	        N[AB[0]-1]++;
        	    }
        	}
			
        	int ans = 0;
        	for(int i = 0; i < NM[0]; i++)
        	{
        	    if(N[i] == 0)
        	    {
        	        ans++;
        	    }
        	}
			Console.WriteLine(ans); 
        }
 
　　　　//一つの文字列を受け渡す
        static string Onestring()
        {
            return Console.ReadLine();
        }
 
        //複数の文字列を配列で受け渡す
        //文字列と文字列の間は" "で区切る
        static string[] Arraystring()
        {
            return Console.ReadLine().Split(' ');
        }
 
        //一つの数字を受け渡す
        static int Oneint()
        {
            return int.Parse(Console.ReadLine());
        }
 
        //複数の数字を配列で受け渡す
        //数字と数字の間は" "で区切る
        static int[] Arrayint()
        {
            String[] input_line = Console.ReadLine().Split(' ');
            int[] input_num = new int[input_line.Length];
            for (int i = 0; i < input_line.Length; i++)
            {
                input_num[i] = int.Parse(input_line[i]);
            }
            return input_num;
        }
    }
}

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

int main() {
  int N, A; // 1 <= N <= 10000, 0 <= A <= 1000
  
  cin >> N >> A ;

  if((N % 500) <= A){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main()
{
    int n, d, x, a, ans;
    cin >> n >> d >> x;
    ans = x;
    for(int i = 0; i < n; i++){
        cin >> a;
        for(int j = 1; j <= d; j += a){
            ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N, M; cin >> N >> M; 
	bool broken[100010] = {}; 
	for(int i = 0; i < M; i++){
		int a; cin >> a; 
		broken[a] = true; 
	}
	long long P = 1000000007; 
	long long dp[100010] = {}; 
	dp[0] = 1; 
	if(!broken[1]) dp[1] = 1; 
	for(int i = 2; i <= N; i++){
		if(!broken[i]) dp[i] = (dp[i-2] + dp[i-1]) % P; 
	} 
	cout << dp[N] << endl; 
}

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

#define INF 0x3f3f3f3f

int dp[100][100];

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

  while(true) {
  int n, k;
  cin >> n >> k;
  if(n==0&&k==0) break;
  memset(dp, 0x3f, sizeof(dp));
  for (int i = 0; i < n; i++) {
    dp[i][i] = 0;
  }
  for (int i = 0; i < k; i++) {
    int a, b, c, d;
    cin >> a >> b >> c; b--; c--;
    if (!a) {
      if (dp[b][c] == INF) cout << "-1" << endl;
      else cout << dp[b][c] << endl;
      continue;
    }
    cin >> d;
    if (dp[b][c] <= d) continue;
    dp[b][c] = dp[c][b] = d;
    for (int j = 0; j < n; j++) {
      for (int x = j+1; x < n; x++) {
        dp[j][x] = dp[x][j] = min(dp[j][x], min(dp[j][b] + dp[c][x], dp[j][c] + dp[b][x]) + d);
      }
    }
  }
  }

	return 0;
}



Measured memory_bytes: 3176
n = int(input())
list1 = [list(map(int,input().split())) for i in range(n)]

#高さは一意に求まるので、どれをとっても良い、
#わけではないh=0のとき一意に求まらない。
for i in list1:
  if i[2] != 0:
    a,b,c = i
    break

#highについてのループ
for y in range(101):
  for x in range(101):
    h = c + abs(a-x) + abs(b-y) #頂点の座標
    if all(h_ == max(h-abs(x-i)-abs(y-j),0) for i,j,h_ in list1):
      print(x,y,h)
      exit()


Measured memory_bytes: 47196
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,a,b) for (int i = (b-1); i >= (a); i--)
#define REP(i,n) FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int N; cin >> N;
  vector<double> A(N); REP(i,N) cin >> A[i];

  double ans = 0.0;
  REP(i,N) {
    ans += 1.0/A[i];
  }
  ans = 1.0/ans;
  
  cout << fixed << setprecision(10);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  int n;
  
  cin >> s;
  n = s.size()-1;
  if (s[n]=='s') cout << s << "es" << endl;
  else cout << s << "s" << endl;
  
 
}

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

using namespace std;
#define MAX 100000
#define MAX_PARENT 100

vector<int>G[MAX];
int depth[MAX];
int parent[MAX_PARENT][MAX];
int root = 0;

void dfs(int v,int p,int d){
    parent[0][v] = p;
    depth[v] = d;
    for(int i = 0;i < G[v].size();++i){
        if(G[v][i] != p)
            dfs(G[v][i],v,d + 1);
    }
}

void init(int v){
    dfs(root,-1,0);
    for(int i = 0;i + 1 < MAX_PARENT;++i){
        for(int j = 0;j < v;++j){
            if(parent[i][j] < 0){
                parent[i + 1][j]= -1;  
            } 
            else{
                parent[i + 1][j] = parent[i][parent[i][j]];  
            } 
        }
    }
}

int lca(int u,int v){
    if(depth[u] > depth[v]){
        swap(u,v);   
    }
    
    for(int i = 0;i < MAX_PARENT;++i){
        if((depth[v] - depth[u]) >> i & 1){
            v = parent[i][v];
        }
    }
    if(u == v){
        return u;
    }
    
    for(int i = MAX_PARENT -1;i >= 0;--i){
        if(parent[i][u] != parent[i][v]){
            u = parent[i][u];
            v = parent[i][v];
        }
    }
    return parent[0][u];
}

int main(){
    int n,p,t;
    cin>>n;
    for(int i = 0;i < n;++i){
        cin >> p;
        for(int j = 0;j < p;++j){
            cin >> t;
            G[i].push_back(t);
        }
    }
    init(n);
    cin >> n;
    for(int i = 0;i < n;++i){
        cin >> p >> t;
        cout << lca(p,t) << endl;
    }
}


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  for (int i = 0; i < S.size(); i++) {
    int tmp = S.at(i) - 'A';
    tmp += N;
    tmp %= 26;
    S.at(i) = char('A' + tmp);
  }
  cout << S << "\n";
}

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <iomanip>
#include <cstring>
#include <cmath>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> x;
    int a;
    for (int i=0;i<n;++i){
        cin>>a;
        x.push_back(a);
    }
    sort(x.begin(),x.end());
    
    auto minmax = minmax_element(x.begin(),x.end());
    int m = 1000000000;
    for (int i = *minmax.first;i<=*minmax.second;++i){
        int s=0;
        for (int j=0;j<n;++j){
            s+=(i-x[j])*(i-x[j]);
        }
        m=min(m,s);
    }
    cout<<m;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1010;
int n,m,a[N],b[N],k,q;
int f[1<<12],g[1<<12];
int main(){
    scanf("%d %d",&m,&n);
    for(int i=1;i<=n;++i){
        scanf("%d %d",&a[i],&k); b[i]=0;
        while(k--){
            scanf("%d",&q); q-=1;
            b[i]|=1<<q;
        }
    }
    for(int i=0;i<(1<<m);++i) f[i]=INF; f[0]=0;
    for(int i=1;i<=n;++i){
        for(int j=0;j<(1<<m);++j) g[j]=f[j];
        for(int j=0;j<(1<<m);++j)
            g[j|b[i]]=min(g[j|b[i]],g[j]+a[i]);
        for(int j=0;j<(1<<m);++j) f[j]=g[j];
    }
    printf("%d\n",f[(1<<m)-1]==INF?-1:f[(1<<m)-1]);
}

Measured memory_bytes: 256
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define MX 10000000000
#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}

void solve()
{
	int x;
	cin >> x;
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++)
	{
		int y = s[i] - 'A';
		 y = (y + x) % 26;
		cout << char('A' + y);
	}
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	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 X =sc.nextInt();
      
      int Z = X/500;
      int B = Z*1000;
      int A = (X-(500*Z))/5;
      int C = A*5;
      
      System.out.print(B+C);
    }
}


Measured memory_bytes: 22484
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <fstream> //ofstream
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int n;
string data1,data2;
void solve(){
        rep(i,n){
                cout<<data1.at(i)<<data2.at(i);
        }
        cout<<endl;
}

int main(){
        cin>>n;
        cin>>data1>>data2;

        solve();
        return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N,V;
int x[MAXN],d[30],tot,r[30][MAXN],l[30][MAXN];
int dp[2][(1 << 19) + 5];
void Solve() {
    read(N);read(V);
    for(int i = 1 ; i <= N ; ++i) read(x[i]);
    d[0] = V / 2;
    while(d[tot]) {
	++tot;
	d[tot] = d[tot - 1] / 2;
    }
    for(int j = 0 ; j <= tot ; ++j) {
	r[j][N] = N;r[j][N + 1] = N + 1;
	for(int i = N - 1 ; i >= 1 ; --i) {
	    r[j][i] = i;
	    if(x[i + 1] - x[i] <= d[j]) r[j][i] = r[j][i + 1];
	}
	l[j][1] = 1;
	for(int i = 2 ; i <= N ; ++i) {
	    l[j][i] = i;
	    if(x[i] - x[i - 1] <= d[j]) l[j][i] = l[j][i - 1];
	}
    }
    dp[0][0] = 0;dp[1][0] = N + 1;
    for(int S = 1 ; S < (1 << (tot + 1)) ; ++S) {
	dp[1][S] = N + 1;
	for(int j = 0 ; j <= tot ; ++j) {
	    if(S >> j & 1) {
		dp[0][S] = max(r[j][dp[0][S ^ (1 << j)] + 1],dp[0][S]);
		dp[1][S] = min(l[j][dp[1][S ^ (1 << j)] - 1],dp[1][S]);
	    }
	}
    }
    int cnt = 0;
    for(int i = 1 ; i <= N ; ++i) {
	int l = i,r = i;
	while(r < N && x[r + 1] - x[r] <= V) ++r;
	i = r;
	++cnt;
    }
    if(cnt - 1 > tot + 1) {
	for(int i = 1 ; i <= N ; ++i) {
	    puts("Impossible");
	}
	return;
    }
    for(int i = 1 ; i <= N ; ++i) {
	int l = i,r = i;
	while(r < N && x[r + 1] - x[r] <= V) ++r;
	int A = (1 << tot + 1) - 1;
	bool f = 0;
	for(int S = 0 ; S < (1 << tot + 1) ; ++S) {
	    if(dp[0][S] >= l - 1 && dp[1][A ^ S] <= r + 1) {f = 1;break;}
	}
	for(int i = l ; i <= r ; ++i) {
	    if(f) puts("Possible");
	    else puts("Impossible");
	}
	i = r;
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 38784
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n = I()
H = LI()
def dfs(A):
    if not A:
        return 0
    m = min(A)
    mi = A.index(m)
    B = [x-m for x in A[:mi]]
    C = [x-m for x in A[mi+1:]]
    return m + dfs(B) + dfs(C)
print(dfs(H))

Measured memory_bytes: 72724
<?php

fscanf(STDIN, "%d %d %d", $N, $A, $B);

if ($A > $B) {
    echo "0\n";
    exit;
}

if ($N == 1) {
    if ($A != $B) {
        echo "0\n";
        exit;
    }
}

$mmin = $A * ($N - 1) + $B;
$mmax = $A + $B * ($N -1);

echo ($mmax - $mmin + 1) . PHP_EOL;


Measured memory_bytes: 4604
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;

namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            if ((s[0] + s[1]) % 2 == 0)
            {
                WriteLine((s[0] + s[1]) / 2);
            }
            else
            {
                WriteLine("IMPOSSIBLE");
            }
        }
    }
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int cnt = 0, tmp;
	for (int i = 1; i <= n; ++i) {
		cin >> tmp;
		if (tmp != i)
			++cnt;
	}
	if (cnt > 2)
		cout << "NO\n";
	else
		cout << "YES\n";
	return 0;
}

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

int main()
{
	int i,j,tmp1,tmp2,height[3]={0,0,0};
	for (i=0;i<10;i++){
		cin >> tmp1;
		for(j=0;j<3;j++)
		if(tmp1>height[j]){
			tmp2=height[j];
			height[j]=tmp1;
			tmp1=tmp2;
		}
	}
	for(i=0;i<3;i++){
		cout << height[i] <<endl;
	}
}

Measured memory_bytes: 1160
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

h, w = MAP()
A = [list(input()) for i in range(h)]


def bfs():
    que = deque([])
    
    dx = [0, 1, 0, -1]
    dy = [1, 0, -1, 0]

    d = [[INF] * w for i in range(h)]
    
    for i in range(h):
        for j in range(w):
            if A[i][j] == "#":
                sy, sx = i, j
                d[sy][sx] = 0
                que.append((sy, sx))
    ans = 0
    while que:
        p = que.popleft()
        for i in range(4):
            ny, nx = p[0] + dy[i], p[1] + dx[i]
            
            if 0 <= ny < h and 0 <= nx < w and d[ny][nx] == INF and A[ny][nx] == ".":
                d[ny][nx] = d[p[0]][p[1]] + 1
                # A[ny][nx] = "#"
                que.append((ny, nx))
 
                ans = max(ans, d[ny][nx])     
#    print(*d, sep="\n")
    return ans


if __name__ == "__main__":
    print(bfs())

    


Measured memory_bytes: 150360
#include <iostream>
#include <queue>
#include <algorithm>
#define  INF  1000000
using namespace std;
struct edge{int to,cost;};
typedef pair <int ,int> P;
typedef vector<edge> graph;

graph g[910];

void ae(int from,int to,int cost){ 
	edge in1,in2;
	in1.to=to,in2.to=from;
	in1.cost=in2.cost=cost?10000:1;
	g[from].push_back(in1);
	g[to].push_back(in2);
}

int w,h;

int main(void){
	while(cin >> w >> h,w|h){
		/*for(int i=0;i<w*h;i++){
			cout << i << " "  ;
			for(int j=0;j<g[i].size();j++){
				cout << g[i][j].to << " ";
			}
			cout << endl;
		}*/
		for(int i=0;i<2*h-1;i++){
			if(i%2){//縦
				for(int j=0;j<w;j++){
					int tmp; cin >> tmp;
					ae(j+w*(i/2),j+w*(i/2)+w,tmp);
				}
			}else{//横
				for(int j=0;j<w-1;j++){
					int tmp; cin >> tmp;
					ae(j+i/2*w,j+i/2*w+1,tmp);
				}
			}
		}
		int d[910];
		priority_queue < P,vector<P>,greater<P> > q;
		fill(d,d+w*h,INF);
		d[0]=0;
		q.push(P(0,0));
		while(!q.empty()){
			P p=q.top();q.pop();
			int v=p.second;
			if(d[v]<p.first)
				continue;
			for(int i=0;i<g[v].size();i++){
				edge e=g[v][i];
				if(d[e.to]>d[v]+e.cost)
					d[e.to]=d[v]+e.cost,q.push(P(d[e.to],e.to));
			}	
		}
		if(d[w*h-1]>=10000)
			cout << 0 << endl;
		else 
			cout << d[w*h-1]+1 << endl;

		for(int i=0;i<910;i++)
			for(int j=0;j<g[i].size();)
				g[i].pop_back();
		/*for(int i=0;i<w*h;i++){
			cout << i << " "  ;
			for(int j=0;j<g[i].size();j++){
				cout << g[i][j].to << " ";
			}
			cout << endl;
		}*/
	}
	return 0;
}

Measured memory_bytes: 1296
import sys
while True:
    h, w = [int(i) for i in input().split()]
    if h == 0 and w == 0:
        sys.exit()
    else:
        for i in range(h):
            if i == 0 or i == h - 1:
                print('#' * w)
            else:
                print('#'+'.'*(w-2)+'#')
        print('')


Measured memory_bytes: 5628
#include<stdio.h>
int main(){
  int x,y,a,b;
  scanf("%d%d",&x,&y);
  if(x<y){
    a=x;
    x=y;
    y=a;
  }
  b=x%y;
  while(b!=0){
    x=y;
    y=b;
    b=x%y;
  }
  printf("%d\n",y);
  return 0;
}




Measured memory_bytes: 2100
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//constants
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = 1<<28;


int main(int argc, char **argv) {
    string S;
    cin >> S;

    bool flag = true;
    int state = 0;
    REP(i, S.size()){
        if((state == 0 || state == 5 || state == 15 || state == 101 || state == 200) && S[i] == 'd')
            state=1;
        else if(state == 1 && S[i] == 'r')
            state=2;
        else if(state == 2 && S[i] == 'e')
            state=3;
        else if(state == 3 && S[i] == 'a')
            state=4;
        else if(state == 4 && S[i] == 'm')
            state=5;
        else if(state == 5 && S[i] == 'e')
            state=100;
        else if(state == 100 && S[i] == 'r')
            state=101;
        else if((state == 0 || state == 5 || state == 15 || state == 101 || state == 200) && S[i] == 'e')
            state=11;
        else if(state == 11 && S[i] == 'r')
            state=12;
        else if((state == 12 or state == 101) && S[i] == 'a')
            state=13;
        else if(state == 13 && S[i] == 's')
            state=14;
        else if(state == 14 && S[i] == 'e')
            state=15;
        else if(state == 15 && S[i] == 'r')
            state=200;
        else{
            flag = false;
            break;
        }
        //cout << i << " " << state << endl;
    }

    if(flag)
        flag = (state == 0 or state == 5 or state == 15 or state == 101 or state == 200);

    cout << ((flag)? "YES" : "NO") << endl;
    return 0;

}



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

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

    vector<int>  D(n,0);
    for(int i= 1; i< n; i++){
        cin >> D.at(i);
    }
    vector<int> count(n,0);

    long long int answer = 0;

    for(int i = 1; i<n; i++){
        count.at(D.at(i))++;
    }
    if(count.at(0)>0){
        cout << 0 << endl;
        return 0;
    }else{
        answer = 1;
        for(int i = 1; i< n; i++){
            if(D.at(i) - 1 == 0){

            }else{
            answer = answer * count.at(D.at(i)-1);
            answer = answer% 998244353;
            }
        }
    }
    cout << answer<< endl;
}

Measured memory_bytes: 1024
H, W = map(int, input().split())
h, w = map(int, input().split())

List = []
for i in range(H):
    l = []
    for j in range(W):
        l.append(0)
    List.append(l)

for i in range(h):
    for j in range(W):
        List[i][j] = 1
for i in range(H):
    for j in range(w):
        List[i][j] = 1

count = 0
for i in range(H):
    count += List[i].count(0)

print(count)


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

using namespace std;

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

// chmax, chmin
template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

void solve(long long N, long long X, long long M) {
    vector<long long> S;
    map<long long, int> pos;
//    cout << "STOP" << endl;
    while (true) {
        if (S.size() == N) {
            cout << accumulate(S.begin(), S.end(), 0ll) << endl;
            return;
        }
        if (pos.count(X)) {
            int currentIndex = S.size();
            int lastIndex = pos[X];
            long long ans = 0;
            for (int i = 0; i < lastIndex; i++) {
//                cout << S[i] << " ";
                ans += S[i];
            }
            long long lsum = 0;
//            cout << "[";
            for (int i = lastIndex; i < currentIndex; i++) {
//                cout << S[i] << " ";
                lsum += S[i];
            }
            long long R = N - lastIndex;

            for (int i = 0; i < R % (currentIndex - lastIndex); i++) {
                ans += S[lastIndex + i];
            }
            ans += (R / (currentIndex - lastIndex)) * lsum;

//            cout << "]" << endl;
            cout << ans << endl;
            break;
        } else {
            pos[X] = S.size();
            S.push_back(X);
            X = (X * X) % M;
        };
    }

}

int main() {
    long long N;
    scanf("%lld", &N);
    long long X;
    scanf("%lld", &X);
    long long M;
    scanf("%lld", &M);
    solve(N, X, M);
    return 0;
}


Measured memory_bytes: 6796
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

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

using namespace std;

namespace Dump {
#define dump(...) Dump::print(#__VA_ARGS__, __VA_ARGS__)
static std::vector<string> dumpKey;
static string dumpKeyBuf;

void print() { cerr << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
  if (dumpKey.empty()) {
    dumpKeyBuf = head;
    dumpKeyBuf.erase(std::remove_if(dumpKeyBuf.begin(), dumpKeyBuf.end(),
                                    [](char c) { return c == ' '; }),
                     dumpKeyBuf.end());

    std::istringstream stream(dumpKeyBuf);
    string field;
    while (std::getline(stream, field, ','))
      dumpKey.push_back(field);

    reverse(dumpKey.begin(), dumpKey.end());
  } else {
    cerr << dumpKey.back() << ":" << head << "  ";
    dumpKey.pop_back();
  }
  Dump::print(std::move(tail)...);
}
}

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef vector<unsigned long long> vull;
typedef pair<int, int> pii; // p.first p.second

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(string S) {
  REP(i, S.size() - 8) { cout << S[i]; }
  cout << endl;
}

int main() {
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  solve(S);
  return 0;
}


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

using namespace std;

#define INP "solve"
#define OUT "solve"

const int QQ = 3e5 + 10;
const int maxN = 3e5 + 100;
const int maxM = 3e5 + 10;
const long long oo = 1e18;
const int module = 998244353;
const long double du = 1e-9;

void doc() {
    freopen(INP ".inp","r",stdin);
    freopen(OUT ".out","w",stdout);
}

void solve() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    if (a[0] != 0) {
        cout << 0;
        return;
    }
    sort(a + 1, a + n);
    int SL = 1;
    int Res = 1;
    for (int i = 1; i < n; ) {
        int j = i;
        while (j < n && a[i] == a[j]) j++;
        if (a[i] != a[i - 1] + 1) {
            cout << 0;
            return;
        }
        int L = j - i;
        int pw = 1;
        for (int k = 0; k < L; k++) pw = 1LL * pw * SL % module;
        Res = 1LL * Res * pw % module;
        SL = L;
        i = j;
    }
    cout << Res;
}
int main(int argc,char *argv[]) {
    //srand(time(nullptr));
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    ///doc();
    solve();
}


Measured memory_bytes: 640
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    sets = set()
    for i in range(1, 10):
        for j in range(1, 10):
            sets.add(i*j)

    if N in sets:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    solve()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
int main(){
    string l;
    cin>>l;
    ll dp[100005][2];
    rep(i,l.size()+1)rep(j,2) dp[i][j]=0;
    dp[0][0]=1;
    rep(i,l.size()){
        { // a+b=0
            if(l[i]=='0'){
                dp[i+1][0] += dp[i][0]%mod;
                dp[i+1][1] += dp[i][1]%mod;
                dp[i+1][0] %=mod;
                dp[i+1][1] %=mod;
            } else {
                dp[i+1][1] += (dp[i][0] + dp[i][1])%mod;
                dp[i+1][1] %=mod;
            }
        }
        { // a+b=1
            if(l[i]=='0'){
                dp[i+1][1] += 2*dp[i][1]%mod;
                dp[i+1][1] %=mod;
            } else {
                dp[i+1][0] += 2*dp[i][0]%mod;
                dp[i+1][1] += 2*dp[i][1]%mod;
                dp[i+1][0] %=mod;
                dp[i+1][1] %=mod;               
            }
        }
    }
    cout<<(dp[l.size()][0]+dp[l.size()][1])%mod<<endl;
    return 0;
}

Measured memory_bytes: 2048
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }

template<typename T, typename U>
T lis(vector<U> a) {
	T rtn = 0;
	vector<int> lis;
	lis.push_back(a[0]);
	FOR(i, 1, a.size()) {
		if (lis.back() <= a[i]) {
			lis.push_back(a[i]);
		}
		else {
			auto itr = upper_bound(all(lis), a[i]) - lis.begin();
			lis[itr] = a[i];
		}
	}
	rtn = lis.size();//LISの長さ
	return rtn;
}


int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	REP(i, n) {
		cin >> a[i];
	}
	reverse(all(a));
	int m = lis<int>(a);
	put(m);
	return 0;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii  = pair<int,int>;
const int INF=1001001001;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define MOD 1000000007
#define EPS 10e-8
int gcd(int a,int b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main(){
    int a,b;
    cin >> a>>b;
    if(a<b*2){
        cout << 0 << endl;
    }
    else
    {
        cout << a - 2 * b << endl;
    }

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    from collections import Counter

    n = int(input())
    s = [input() for _ in range(n)]
    c = Counter(s)
    max_value = max(c.values())
    ans = list()

    for key, value in c.items():
        if value == max_value:
            ans.append(key)

    for a in sorted(ans):
        print(a)


if __name__ == '__main__':
    main()


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

int main(){
	string s,c="yes";
    cin >> s;
    int a[26]={},sum=0;
    for(int i=0;i<s.size();i++)
      a[s.at(i)-97]++;
    for(int i=0;i<26;i++){
      if(a[i]>1)
        c = "no";
    }
    cout << c << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>
#include<cmath>
#include<cstring>
#include<map>
#include<sstream>
 
using namespace std;

long long int X;
long long int init_val = 100;
long long int year = 0;

int main(){
  
  cin>>X;
  
while(init_val < X){
  init_val *= 1.01;
  year++;
}
  
  cout<<year<<endl;
}


Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
using namespace std;
//#define int long long
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;
#define X first
#define Y second
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)

int gcd(int x,int y){ return (!y ? x : gcd(y, x%y)); }
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7, base = 773;
inline int mu(int x,int y){
	return 1LL * x * y % mod;
}
inline int ad(int x,int y){
	return (x + y) % mod;
}
int h[maxn], pw[maxn], h2[maxn];
int gh(int l,int r){
	return ad(h[r], mod - mu(h[l], pw[r - l]));
}
int32_t main(){
	//IOS;
	int n;
	string s;
	cin >> s;
	bool can = 1;
	for(int i=0; i<s.size(); i++){
		if(i % 2 == 0 && s[i] == 'L')
			can = 0;
		if(i % 2 == 1 && s[i] == 'R')
			can = 0;
	}
	if(can)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

int main() {
    ll n, Z, W;
    cin >> n >> Z >> W;

    vl a(n+1);
    exrep(i, 1, n) {
        cin >> a[i];
    }

    vvl dp(n, vl(2));  // dp[i][id] : 山札の上からi枚取られている状態でいまの手番がid(id=0:先手, id=1:後手)のときのスコアの最適値
    for(ll i = n-1; i >= 0; i--) {
        // 先手
        dp[i][0] = -INF;
        ll Y = a[i];
        if(i == 0) {
            Y = W;
        }
        chmax(dp[i][0], abs(a[n] - Y));
        exrep(j, i+1, n-1) {
            chmax(dp[i][0], dp[j][1]);
        }
        
        // 後手
        dp[i][1] = INF;
        ll X = a[i];
        if(i == 0) {
            X = Z;
        }
        chmin(dp[i][1], abs(X - a[n]));
        exrep(j, i+1, n-1) {
            chmin(dp[i][1], dp[j][0]);
        }
    }
    
    out(dp[0][0]);
    re0;
}

Measured memory_bytes: 3716
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define ALL(x) x.begin(), x.end()
#define INF (1001000000)
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i:c)
#define EXIST(cs,v) (find(ALL(cs),(v))!=cs.end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define UNIQ(c) (c).erase(unique((c).begin(),(c).end()), (c).end());
#define P(p) cout<<(p)<<endl;

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

    int x;
    cin >> x;
    if (x == 7 || x == 5 || x == 3) {
        P("YES");
    }
    else {
        P("NO");
    }

    return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/keyence2020
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

struct interval {
    int s, f;
    interval(int s, int f) : s(s), f(f) {}
};
bool compare_f(const interval &x, const interval &y) { return x.f < y.f; }
vector<interval> interval_scheduling(vector<interval> J) {
    vector<interval> A;
    sort(J.begin(), J.end(), compare_f);
    int f = 0;
    for (int i = 0; i < J.size(); ++i) {
        if (J[i].s >= f) {
            A.push_back(J[i]);
            f = J[i].f;
        }
    }
    return A;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<interval> J;
    REP(i, N) {
        int X, L;
        cin >> X >> L;
        J.push_back(interval(max(0LL, X - L), X + L));
    }
    vector<interval> ans = interval_scheduling(J);
    cout << ans.size() << endl;

    return 0;
}


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

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)

// policy-based
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;	


using namespace std;


typedef long long ll; // int or long long
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;

/*
typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
*/
 
const ll MAX = 1e7+10;
const ll inf = 1e9;

ll p[MAX],pot[MAX],nd[MAX];

int main(){
	fastio;
	nd[1] = p[1] = 1;
	f(i,1,MAX) nd[i] = 1;
	f(i,2,MAX){
		if(p[i] == 0){
			f(j,1,MAX/i + 1){
				if(i*j>MAX) break;
				p[i*j] = i;
				if(p[j] == i) {
					pot[i*j] = pot[j] +1;
					nd[i*j] =  (nd[j]*(pot[j]+2))/(pot[j]+1);
				}
				else {
					pot[i*j] = 1,nd[i*j] = nd[j]*2 ;
				}
			}
		}
	}
	ll n,ans = 0;
	cin>>n;
	f(i,1,n+1) ans += i*nd[i];
	cout<<ans<<endl;
}

Measured memory_bytes: 237940
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=105;

int n, totw, base=0, ans=0;
int w[N], v[N];
int cache[N][N][3*N];

int dp(int idx, int take, int curw)
{
	if(curw<0)
		return -1e15;
	if(take==0)
		return 0;
	if(idx==n+1)
		return -1e15;
	int &ans=cache[idx][take][curw];
	if(ans!=-1)
		return ans;
	ans=max(dp(idx+1, take, curw), v[idx] + dp(idx+1, take-1, curw-w[idx]));
	return ans;
}

int32_t main()
{
	IOS;
	memset(cache, -1, sizeof(cache));
	cin>>n>>totw;
	for(int i=1;i<=n;i++)
	{
		cin>>w[i]>>v[i];
		if(i==1)
			base=w[i];
		w[i]-=base;
	}
	for(int take=1;take<=n;take++)
	{
		int curw = totw - base*take;
		if(curw<0)
			break;
		curw=min(curw, 3*n);
		ans=max(ans, dp(1, take, curw));
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 27392
#include<stdio.h>
int main(){
  int x, a, b;
  scanf("%d%d%d", &x, &a, &b);
  if(b - a <= 0){ printf ("delicious\n"); }
  else if(b - a > 0 && b - a <=  x){ printf("safe\n"); }
  else if(b - a > x){ printf("dangerous\n"); }
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, to}}的に使う。
const int INF = 1001001001;
const double pi = acos(-1);

int main()
{
    string s;
    cin >> s;
    string c = s.substr(0, 3);
    cout << c << endl;

    return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int x,n;
    int mn = 1000000;
    cin >> x >> n;
    vector<int> p(n);
    
    vector<int> ans;
    
    map<int, int> m;
    map<int, int> a;
    rep(i,n){
        cin >> p[i];
        m[p[i]] = 1;
    }

    if(n == 0){
        cout << x << endl;
        return 0;
    }
    //sort_1(p);
    rep(i, 200){
        if(m[i] == 0){
            a[i] = abs(x-i);
        }
    }
    for(auto x1:a){
        if(mn > x1.second && x1.second != 0){
            mn = x1.second;
            continue;
        }
        if(x1.second == 0 && x == x1.first){
            bool flag = true;
            for(int i = 0; i < n; i++){
                if(x1.first == p[i]){
                    flag = false;
                    break;
                }
            }
            if(flag){
                mn = x1.second;
            }
        }
    }
    for(auto x1:a){
        if(mn == x1.second){
            ans.pb(x1.first);
        }
    }
    sort_1(ans);
    cout << ans[0] << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int MOD = 1000000007;
//const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    ld a, b; cin >> a >> b;
    int h, m; cin >> h >> m;
    ld pai = 3.141592653589793;
    ld sa = abs(6.0*m-30.0*h-m/2.0) * pai / 180.0;
    ld ans = sqrt(a*a+b*b-2*a*b*cos(sa));
    cout << setprecision(20) << ans << endl;
}

Measured memory_bytes: 4172
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter

N = int(stdin.readline().rstrip())
A = [int(s) for s in stdin.readline().rstrip().split()]

B = copy.copy(A)
B.sort()

d = {}
e = {}
count = 0
pos = 0
for el in B:
    if pos == 0:
        count += 1
    elif B[pos] == B[pos - 1]:
        count += 1
    elif B[pos] != B[pos - 1]:
        e[str(el-1)] = int(count*(count-1)/2)
        count = 1
    d[str(el)] = count
    pos += 1
    if len(B) == pos:
        e[str(el)] = int(count*(count-1)/2)
res = 0
for el in e.values():
    res += el
for el in A:
    print(res-int((d[str(el)]*(d[str(el)]-1)/2)) +
          int(((d[str(el)]-2)*(d[str(el)]-1)/2)))


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

int main () {
	char c;
	cin >> c;
	if (c == 'A') {
		cout << "T\n";
	} else if (c == 'G') {
		cout << "C\n";
	} else if (c == 'C') {
		cout << "G\n";
	} else {
		cout << "A\n";
	}
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
neg = 0
mini = 1000000000000000000000000000
s = 0
for i in range(n):
    if a[i] < 0: neg += 1
    mini = min(mini, abs(a[i]))
    s += abs(a[i])
print(s if neg % 2 == 0 else s - mini*2)

Measured memory_bytes: 14412
#include<bits/stdc++.h>
using namespace std;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
LL inf=2147483647;const long long ll =9223372036854775807,ninf=1000000000;const double eps = 1e-6; const long long nll =1000000000000000000;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ULL unsigned long long
#define de cout<<"test"<<endl;
#define st system("pause");
#define F first
#define S second
class MagicNumberThree
{

    public:
int countSubsequences(string s)
{

}

};


int main()
{
    string a;
    while(cin>>a){
        int cnt=0;
   
        int n=a.sz;
       int ans=n;
       for(int i=1;i<n;i++){
        if(a[i]!=a[i-1]){
            ans=min(ans,max(i,n-i) );
        }
       }


        cout<<ans<<endl;





    }
    return 0;
}


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

typedef long long int ll;

int main(){
  int N;
  string S;
  cin >> N >> S;
  vector<pair<int,int>> L(N+1);
  for(int i = 0;i < N;i++){
    if(S[i] == 'W'){
      L[i+1].first = L[i].first + 1;
      L[i+1].second = L[i].second;
    }else{
      L[i+1].first = L[i].first;
      L[i+1].second = L[i].second + 1;
    }
  }
  int ans = 10000000;
  for(int i = 0;i < N;i++){
    ans = min(ans,L[i].first + L[N].second - L[i+1].second);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3076