akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
# define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;


long long f(long long x) {
    long long ret = 0;
    long long d = 1 + log10(x);
    for (long long i=1; i<=d; i++) {
        long long factor = pow(10, i);
        long long denominator = pow(10, i-1);
        ret += (x % factor) / denominator;
    }
    return ret;
}


int main() {
    long long n; cin >> n;
    if (n % f(n) == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
#define INF (1<<29)
#define LINF (1ll<<60)
#define PI 3.14159265359
#define _fi(n) for(int i = 0;i < n;i++)
#define _fj(n) for(int j = 0;j < n;j++)
#define _fk(n) for(int k = 0;k < n;k++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'

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

    int n;cin>>n;

    for(int i = 1;i <= 9;i++){
        int a = n/i;
        if (n%i == 0 && a < 10) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	N := nextInt()

	h := make(map[int]map[int]bool)

	ans := 0
	for i := 1; i <= N; i++ {
		a := nextInt()
		b := i
		if a > b {
			a, b = b, a
		}
		if _, ok := h[a]; !ok {
			h[a] = make(map[int]bool)
		}
		if h[a][b] {
			ans++
		}
		h[a][b] = true
	}
	fmt.Println(ans)
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}


Measured memory_bytes: 14976
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
using namespace std;
int sml=1e9,sum,ans1;
int main(){
	int n;
	string s;
	cin>>n>>s;
	for (int i=0;i<n;i++){
		if (s[i]=='(') sum++;
		else sum--;
		sml=min(sum,sml);
	}
	if (sml<0) ans1=-sml;
	int ans2=ans1+sum;
	for (int i=0;i<ans1;i++) printf("(");
	cout<<s;
	for (int i=0;i<ans2;i++) printf(")");
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  int n;
  cin >> n;
  bool plus;
  int ans = 0;
  int before_a;
  cin >> before_a;
  bool reset = true;
  rep(i,n-1){
    int a;
    cin >> a;
    // cout << "reset" << endl;
    // cout << "before_a = " << before_a << ", a = " << a << endl;
    // cout << reset << endl;
    if (reset) {
      if (before_a - a == 0) continue;
      plus = (before_a - a) > 0; reset=false;
    }
    // cout << reset << endl;
    if(before_a - a > 0){
      if(!plus) {
        ans++;
        reset = true;
      }
    }
    if((before_a - a) < 0){
      if(plus){
        ans++;
        reset=true;
      }
    }
    // cout << reset << endl;
    before_a = a;
  }
  cout << ans+1 << endl;
  return 0;
}


Measured memory_bytes: 888
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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 A,B,H=100,W=100;
  cin>>A>>B;
  cout<<H<<" "<<W<<endl;
  
  char C[105][105];
  for(int i=1; i<=100; ++i){
    for(int j=1; j<=100; ++j){
      if(i<=50) C[i][j]='#';
      else C[i][j]='.';
    }
  }
  
  A--,B--;
  for(int i=1; i<=49; i+=2){
    for(int j=1; j<=50; ++j){
      if(A==0) break;
      C[i][2*j]='.';
      A--;
    }
  }
  
  for(int i=52; i<=100; i+=2){
    for(int j=1; j<=50; ++j){
      if(B==0) break;
      C[i][2*j]='#';
      B--;
    }
  }
  
  for(int i=1; i<=100; ++i){
    for(int j=1; j<=100; ++j){
      cout<<C[i][j];
    }
    cout<<endl;
  }
  return 0;
}

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

int main(){
  int n;
  int m;
  int ans = 0;
  cin >> n >> m;
  int l[m],r[m];
  for(int i=0;i<m;i++) cin >> l[i] >> r[i];
  int max = l[0];
  int min = r[0];
  for(int i=1;i<m;i++){
    if(l[i]>max) max = l[i];
    if(r[i]<min) min = r[i];
  }
  
  for(int i=max;i<=min;i++) ans++;
  cout << ans <<endl;
  return 0;
}

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

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> h(N+1,0);
    REP(i,N){
        cin >> h[i];}
    vector<ll> dp(N+1,0);
    for (int i = 1; i < N; i++) {
        vector<ll> temp;
        REP(l,K){
            if(i-l-1>=0){
                temp.push_back(dp[i-l-1]+abs(h[i]-h[i-l-1]));
            }
        }
        dp[i] = *min_element(temp.begin(), temp.end());

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


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


int main(){
  ll N,M,Q;
  cin >> N >> M >> Q;
  vector<vector<ll>> A(N,vector<ll>(N,0));
  rep(i,M){
    ll l,r;
    cin >> l >> r;
    A.at(l-1).at(r-1)++;
    
  }
  rep(i,N){
    rep(j,N){
      if(j!=0){
        A.at(i).at(j)+=A.at(i).at(j-1);
      }
    }
  }
  rep(i,N){
    rep(j,N){
      if(i!=0){
        A.at(N-1-i).at(j)+=A.at(N-i).at(j);
      }
    }
  }
  rep(i,Q){
    ll p,q;
    cin >> p >> q;
    p--;
    q--;
    cout << A.at(p).at(q) << endl;
  }
}

Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, l, ans;
  cin >> n;
  vector<int> vec(n+1);
  bool a = true;
  l = 0;
  ans = 0;
  vec.at(0) =1;
  for (int i = 0; i<n; i++) {
    cin >> vec.at(i+1);
  }
  for(int i = 0;i < n+1; i++){
    l = vec.at(l);
    ans++;
    if(l == 2){
      a = false;
      
      break;
    }
  }
  if (a)
    cout << "-1"<<endl;
  else
    cout << ans - 1 << endl;
}

Measured memory_bytes: 640
#include<cstdio>

int main(){
	int total,a,result;
	total = 0;
	a = 0;
	result = 0;
	int N,K,X,Y;
	scanf("%d%d%d%d", &N,&K,&X,&Y);
	if(K >= N) printf("%d", N*X);
	else{
	for(int i = 1; i <= K;i++)
		result = result + X;
	for(int j = 1; j <= N-K;j++)
		a = a + Y;
	total = a + result;
	printf("%d\n", total);
	return 0;}
}


Measured memory_bytes: 128
using System;

class Program
{
    static void Main(string[] args)
    {
        var abc = Console.ReadLine().Split(' ');
        var a = int.Parse(abc[0]);
        var b = int.Parse(abc[1]);
        var c = int.Parse(abc[2]);

        var ans = Math.Min(Math.Min(a + b, a + c), b + c);
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int maxDiff = 100000;
const int origin = maxDiff / 2;
bool dp[80][80][maxDiff];

int main() {
    // dp、最大で80^3まで見れば良い
    int H, W;
    cin >> H >> W;
    vector<vector<int>> A(H, vector<int> (W));
    rep(i, H) rep(j, W) cin >> A[i][j];
    vector<vector<int>> B(H, vector<int> (W));
    rep(i, H) rep(j, W) cin >> B[i][j];
    rep(i, H) rep(j, W) A[i][j] = abs(A[i][j] - B[i][j]);
    dp[0][0][origin+A[0][0]] = 1;
    dp[0][0][origin-A[0][0]] = 1;
    rep(i, H) rep(j, W) {
        int cur = A[i][j];
        if (i >= 1) {
            // 上から
            for (int k = 0; k < maxDiff; k++) {
                if (dp[i-1][j][k] && k + cur < maxDiff) {
                    dp[i][j][k+cur] = 1;
                }
                if (dp[i-1][j][k] && k - cur >= 0) {
                    dp[i][j][k-cur] = 1;
                }                
            }
        }
        if (j >= 1) {
            for (int k = 0; k < maxDiff; k++) {
                if (dp[i][j-1][k] && k + cur < maxDiff) {
                    dp[i][j][k+cur] = 1;
                }
                if (dp[i][j-1][k] && k - cur >= 0) {
                    dp[i][j][k-cur] = 1;
                }                
            }
        }
    }
    int ans = maxDiff;
    for (int i = 0; i < maxDiff; i++) {
        if (dp[H-1][W-1][i]) {
            ans = min(ans, abs(origin-i));
        }
    }
    cout << ans << '\n';
    return 0;
}

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

#define ll long long
const int MOD = 1e9 + 7;
#define INF 2e9

#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

#define MATCH(_str, _ptn) regex_match(_str, regex(_ptn))
#define REPLACE(_str, _ptn, _replacement) regex_replace(_str, regex(_ptn), _replacement)

# define pb push_back

# define INIT() cin.tie(0); ios::sync_with_stdio(false)

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


#define MAX_V 100000

struct edge {
    ll to;
    ll cost;
};
vector<edge> Graph[MAX_V];
vector<ll> MinTree,MinTreeDepth;

using _DijkstraCsot = pair<ll, ll>;
ll _dijkstraResults[MAX_V];

ll* dijkstra(ll V, ll s) {
    priority_queue<_DijkstraCsot, vector<_DijkstraCsot>, greater<_DijkstraCsot> > que;
    fill(_dijkstraResults, _dijkstraResults + V, INF);
    _dijkstraResults[s] = 0;
    que.push(_DijkstraCsot(0, s));

    while (!que.empty()) {
        _DijkstraCsot p = que.top();
        que.pop();
        ll v = p.second;
        if (_dijkstraResults[v] < p.first) continue;

        REP(i, Graph[v].size()) {
            edge e = Graph[v][i];
            if (_dijkstraResults[e.to] > _dijkstraResults[v] + e.cost) {
                _dijkstraResults[e.to] = _dijkstraResults[v] + e.cost;
                MinTree[e.to] = v;
                que.push(_DijkstraCsot(_dijkstraResults[e.to], e.to));
            }
        }
    }
    return _dijkstraResults;
}
void pushOneWay(ll from,ll to, ll cost) {
    edge e = {to, cost};
    Graph[from].push_back(e);
}
void pushTwoWay(ll from,ll to, ll cost) {
    pushOneWay(from, to, cost);
    pushOneWay(to, from, cost);
}

ll n,m,x,y,tmp;
string s;
ll resolveS(ll i) {
    if(MinTreeDepth[MinTree[i]] < INF) {
        return MinTreeDepth[MinTree[i]] + 1;
    }
    return resolveS(MinTree[i]) + 1;
}
void resolve(ll n) {
    MinTreeDepth[0] = 0;
    REPS(i,1,n) {
        MinTreeDepth[i] = resolveS(i);
    }
}
int main() {
    INIT();

    cin >> n >> m;
    MinTree.assign(n, INF);
    MinTreeDepth.assign(n, INF);
    REP(i,m) {
      cin >> x >> y;
        x--; y--;   
        pushTwoWay(x, y, 1);
    }
    
    ll* d = dijkstra(n, 0);
    resolve(n);
    REPS(i,1,n) {
        if(MinTreeDepth[MinTree[i]] >= MinTreeDepth[i]) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes" << endl;
    REPS(i,1,n) {
        cout << MinTree[i] + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 20324
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


int main(){
    LL n;
    cin >> n;
    vector<LL> a(n);
    for(LL i = 0; i < n; ++i){
        LL v;
        cin >> v;
        a[--v] = i+1;
    }
    for(LL i = 0; i < n; ++i){
        if(i+1 < n){
            cout << a[i] << " ";
        }else{
            cout << a[i] << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 1664
use proconio::input;

fn main() {
    input! {
        mut a: i32,
        b: i32,
        mut c: i32,
        d: i32
    }

    loop {
        c -= b;
        if c <= 0 {
            println!("Yes");
            return;
        }

        a -= d;
        if a <= 0 {
            println!("No");
            return;
        }
    }
}


Measured memory_bytes: 2108
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def No(): print('No')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N = iin()

dp = [INF for _ in range(N+1)]

dp[0] = 0
for i in range(1, N+1):

    pow6 = 1
    while pow6 <= i:
        dp[i] = min(dp[i], dp[i-pow6]+1)
        pow6 *= 6
    pow9 = 1
    while pow9 <= i:
        dp[i] = min(dp[i], dp[i-pow9]+1)
        pow9 *= 9

print(dp[N])


Measured memory_bytes: 6060
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        new Main().main();
    }
    void main() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] mat = new int[n+1][n+1];
        for(int i=1;i<=n;i++) {
            for(int j=1;j<=n;j++) {
                mat[i][j] = sc.nextInt();
            }
        }
        
        int[][] dp1 = new int[n+1][n+1];
        for(int i=1;i<=n;i++) {
            for(int j=1;j<=n;j++) {
                dp1[i][j] = dp1[i-1][j] + dp1[i][j-1] - dp1[i-1][j-1] + mat[i][j];
            }
        }
        
        int[][] dp2 = new int[n+1][n+1];
        for(int i=1;i<=n;i++) {
            for(int j=1;j<=n;j++) {
                int max = dp1[i][j];
                for(int k=1;k<=i;k++) {
                    for(int l=1;l<=j;l++) {
                        max = Math.max(dp1[i][j] - dp1[k-1][j] - dp1[i][l-1] + dp1[k-1][l-1] , max);
                    }
                }
                dp2[i][j] = max;
            }
        }
//        for(int i=1;i<=n;i++) {
//            for(int j=1;j<=n;j++) {
//                System.out.print(dp2[i][j] + " ");
//            }
//            System.out.println();
//        }
        
        int max = dp2[1][1];
        for(int i=1;i<=n;i++) {
            for(int j=1;j<=n;j++) {
                max = Math.max(dp2[i][j], max);
            }
        }
        System.out.println(max);
    }
}


Measured memory_bytes: 40976
#include <iostream>

using namespace std;
string reverse(string src)
{
  int size = src.size();
  string dest = string(size, '_');
  for (int i = 0; i < size; i++) {
    dest[size-i-1] = src[i];
  }
  return dest;
}

int main(int argc, char const* argv[])
{
  string input;
  cin >> input;
  cout << reverse(input) << endl;
  return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;
const ll INF=1LL<<60;void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d!=0&&d>0?i<n:i>n;i+=d)
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}
template<class T> void contout(const T &v){for(auto it=v.begin();it!=v.end();++it,cerr<<(it!=v.end()?" ":"\n"))cout<<*it;}

void solve(){
  ll n,m; cin>>n>>m;
  vector<pll> key;
  rep(i,m){
    ll a,b; cin>>a>>b;
    ll t=0;
    rep(_,b){
      ll c; cin>>c;
      t+=1<<(--c);
    }
    key.emplace_back(t,a);
  }
  const ll N=1<<n;
  vector<ll> dp(N,INF);
  dp[0]=0;
  rep(i,m){
    auto newdp=dp;
    ll t,a; tie(t,a)=key[i];
    rep(j,N){
      chmin(newdp[j|t],dp[j]+a);
    }
    dp=newdp;
  }
  ll ans=dp[N-1];
  cout<<(ans!=INF?ans:-1)<<"\n";
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
input = sys.stdin.readline
 
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
def main():
	#R, G, B, N = map(int, input().split(" "))
	N = int(input())

	S = []
	xA = 0
	Bx = 0
	BA = 0
	for _ in range(N):
		tmp = input()
		tmp = tmp[:-1]
		S.append(tmp)
		if tmp[0] == "B" and tmp[-1] == "A":
			BA += 1
			continue
		if tmp[-1] == "A":
			xA += 1
		if tmp[0] == "B":
			Bx += 1

	ans = 0
	for i, val in enumerate(S):
		tmp = val.split("AB")
		ans = ans + len(tmp) -1

	#print("{} {} {}".format(xA, Bx, BA))
	#print(ans)
	pls = 0
	if xA > 0 and Bx > 0:
		xA -= 1
		Bx -= 1

		pls = pls + 1 + BA
		BA = 0
	
	#print(pls)
	pls2 = 0
	if xA > 0 and Bx == 0 and BA > 0:
		xA -= 1
		pls2 = BA
		BA = 0
	
	#print(pls2)
	pls3 = 0
	if Bx > 0 and xA == 0 and BA > 0:
		Bx -= 1
		pls3 = BA
		BA = 0
	
	#print(pls3)
	pls4 = 0
	if Bx == 0 and xA == 0 and BA > 0:
		pls4 = BA - 1
		BA = 0
	
	#print(pls4)
	plspls = pls + pls2 + pls3 + pls4 + min(xA, Bx)
	#print(plspls)
	print(ans + min(plspls, N - 1))

	
if __name__ == "__main__":
	main()

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

string s, t;

int main() {
	ios::sync_with_stdio(0); cin.tie(0); 
	cin >> s >> t;

	int ans = 0;
	for (int i=0; i<s.size(); i++) ans += s[i] != t[i];

	cout << ans << '\n';
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
 
using std::pair;
using std::vector;
using std::string;

typedef long long ll;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int oo = 0x3f3f3f3f;
 
template<typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48; 
    return x *= f;
}

const int N = 4000000;

int n, a;
std::bitset<N + 5> Set;

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif 

    int sum = 0;

    read(n);
    Set.set(0);
    for(int i = 1; i <= n; ++i) {
        read(a);
        sum = (sum + a);
        Set = Set | (Set << a);
    }

    sum = (sum + 1) / 2;

    for(int i = sum; ; i++) {
        if(Set.test(i)) {
            printf("%d\n", i);
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    ll a, b, x;
    cin >> a >> b >> x;
    ll u = b / x + 1;
    ll l = a == 0 ? 0 : (a - 1) / x + 1;
    cout << u - l << endl;
    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
int n,a,b;
int main(){
    cin >> n >> a >> b;
    cout << min(a*n,b) << endl;
    return 0;
}

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

using namespace std;

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

    long long n, m;
    cin >> n >> m;

    if(n == 1 || m == 1)
        n == m? cout << 1 << '\n' : cout << max(n, m) - 2 << '\n';
    else
        cout << max(0ll, n - 2) * max(0ll, m - 2) << '\n';
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000

using namespace std;

void func(){

	int N,K,first,last,tmp,pre,ans;
	scanf("%d %d",&N,&K);

	if(N == 1){
		scanf("%d",&tmp);
		ans = 0;
	}else if(N == 2){
		scanf("%d",&first);
		scanf("%d",&last);

		if(K == 1){
			ans = last-first;
		}else{
			ans = 0;
		}
	}else{ //N >= 3

		priority_queue<int> Q;

		scanf("%d",&first);
		scanf("%d",&tmp);

		Q.push(tmp-first);
		pre = tmp;

		for(int i = 2; i < N-1; i++){
			scanf("%d",&tmp);

			Q.push(tmp-pre);
			pre = tmp;
		}
		scanf("%d",&last);
		Q.push(last-pre);

		ans = last-first;

		for(int i = 0; Q.empty() == false && i < K-1; i++){
			ans -= Q.top();
			Q.pop();
		}
	}

	printf("%d\n",ans);
}

int main(){

	int K;
	scanf("%d",&K);

	for(int i = 0; i < K; i++){
		func();
	}

    return 0;
}

Measured memory_bytes: 3160
from collections import deque
plusQ = deque([]) 
minsQ = deque([])
 
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
 
for itr, val in enumerate(A):
  if itr == 0:
    plusQ.append(val)
  elif itr != len(A) - 1 and val > 0:
    plusQ.append(val)
  else:
    minsQ.append(val)
    
p1 = plusQ.popleft()
 
ans = deque([])
while len(minsQ) > 0:
  if len(plusQ) > 0:
    p, m = plusQ.popleft(), minsQ.popleft()
    ans.append([m, p])
    minsQ.append(m - p)    
  else:
    m = minsQ.popleft()
    ans.append([p1, m])
    p1 = p1 - m

print(p1)
while len(ans) > 0:
  hoge = ans.popleft()
  print(hoge[0],hoge[1])

Measured memory_bytes: 21644
#include <iostream>
#include <math.h>

using namespace std;
void sayYes() { cout << "Yes" << endl; };
void sayNo() { cout << "No" << endl; };

int main(void)
{
    int num;
    cin >> num;

    int happy_500 = num / 500;
    int happy_5 = (num - happy_500 * 500) / 5;

    cout << happy_500 * 1000 + happy_5 * 5;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<functional>
#include<algorithm>
using namespace std;
int main() {
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;
	if (w >= x + r&&x - r >= 0 && y + r <= h&&y - r >= 0) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
}

Measured memory_bytes: 3088
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

using namespace std;

int main(){

    int ans=0;
    int n;
    cin>>n;

    vector<int> a,b,c;

    for(int i=0;i<n;i++){
        int d;
        cin>>d;
        a.push_back(d);
    }
    for(int i=0;i<n;i++){
        int d;
        cin>>d;
        b.push_back(d);
    }
    for(int i=0;i<n-1;i++){
        int d;
        cin>>d;
        c.push_back(d);
    }

    ans+=b[a[0]-1];
   
    for(int i=1;i<n;i++){
        ans+=b[a[i]-1];
        if(a[i-1]==a[i]-1){
            ans+=c[a[i-1]-1];
        }
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<P>p,q;
  rep(i,0,n){
    string s;cin>>s;
    ll m=0,d=0;
    rep(j,0,s.size()){
      if(s[j]=='(')m++;
      else m--;
      if(m<0)chmax(d,-m);
    }
    //cout<<d spa m<<endl;    
    if(m>=0)p.EB(d,m);
    else q.EB(d,m);
  }
  sort(ALL(p));
  sort(ALLR(q));
  vector<ll>order(q.size());
  iota(ALL(order),0);
  sort(ALL(order),[&](ll x,ll y){
    return q[x].fi+q[x].se>q[y].fi+q[y].se;
  });
  ll m=0;
  for(auto z:p){
    //cout<<z<<endl;
    if(z.fi>m)judge=false;
    m+=z.se;
  }
  for(auto i:order){
    auto z=q[i];
    //cout<<z<<endl;
    if(z.fi>m)judge=false;
    m+=z.se;
  }
  if(m!=0)judge=false;
  ans1(judge);
  return 0;
}


Measured memory_bytes: 22736
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>

//エイリアス
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};



int main(){
    Stream io;

    int A, B, C, K;
    io.read(A, B, C, K);

    for(; A >= B && K > 0; B *= 2, K--);

    for(; B >= C && K > 0; C *= 2, K--);

    if(A < B && B < C) cout << "Yes";
    else cout << "No";
    
    return 0;
}


Measured memory_bytes: 3628
import scipy.sparse as sp
import scipy.sparse.csgraph as gp


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

adj = sp.dok_matrix((N,N), dtype=bool)
def it():
    for m in range(M):
        x,y,z = map(int,input().split())
        x,y = x-1,y-1
        adj[x,y] = True
        adj[y,x] = True
it()

res,_ = gp.connected_components(adj, directed=False)
print(res)

Measured memory_bytes: 51316
n = int(input())
p_array = list(map(int, input().split()))
# print(p_array)
ans = 0

for i in range(n - 2):
    if (p_array[i] - p_array[i + 1])*(p_array[i + 1] - p_array[i + 2]) > 0:
        ans += 1
print(ans)

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

string rev(string s){
  string ans="";
  for(int i=s.size()-1; i>=0; i--)
    ans += s.substr(i,1);
  return ans;
}

int main(){

  int n;
  cin >> n;
  for(int k=0; k<n; k++){
    string s;
    cin >> s;
    vector<string> ans;
    for(int i=1; i<s.size(); i++){
      for(int j=0; j<8; j++){
	string pre  = s.substr(0,i);
	string late = s.substr(i,s.size()-i);
	if(j%4 > 1)
	  pre = rev(pre);
	if(j%8 > 3)
	  late = rev(late);
	if(j%2==1)
	  swap(pre,late);
	ans.push_back(pre+late);
      }
    }
    sort(ans.begin(),ans.end());
    ans.erase(unique(ans.begin(),ans.end()), ans.end());
    cout << ans.size() <<endl;
  }
}

Measured memory_bytes: 3248
n = int(input())
k = int(input())

def d_sum(digit, k):
    if k==1:
        return 9*digit
    elif k==2:
        return 9**2*digit*(digit-1)//2
    else:
        return 9**3*digit*(digit-1)*(digit-2)//6

s = str(n)
ans = 0

for ind, i in enumerate(s):
    if int(i)==0:
        continue
    digit = len(s)-ind-1
    ans += d_sum(digit, k)
    k -= 1
    if k==0:
        ans += int(i)
        break
    ans += (int(i)-1)*d_sum(digit, k)

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
  
int main() {
	int N;
  	cin >> N;
  	for (int i = 0; i < N; i++) {
    string S;
      cin >> S;
      if(S == "Y") {
      cout << "Four" << endl;
        break;
      }
      else if(S != "Y" && i == N-1) {
      cout << "Three" << endl;
      }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int dp[100010];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int h[100010];
    rep(i, N) cin >> h[i];
    dp[1] = abs(h[1] - h[0]);
    rep(i, N - 1) {
        int a = dp[i] + abs(h[i + 2] - h[i]);
        int b = dp[i + 1] + abs(h[i + 2] - h[i + 1]);
        dp[i + 2] = min(a, b);
    }
    cout << dp[N - 1] << endl;

    return 0;
}


Measured memory_bytes: 4392
/* Parth Manubhai Patel */
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define ll long long
#define int long long
#define ull unsigned long long
#define ld long double
#define sb __builtin_popcount
#define vi vector<int>
#define vc vector<char>
#define ii pair<int, int>
#define pq priority_queue<ii, vector<ii>, greater<ii>>
#define vii vector<ii>
#define sz(a) int((a).size())
#define f(a, b) for (int i = a; i < b; i++)
#define fr(a, b) for (int i = a - 1; i >= b; i--)
#define tr(x, m) for (auto x : m)
#define in(a, b) (b.find(a) != string::npos)
#define minin(a) *min_element(all(a))
#define maxin(a) *max_element(all(a))
#define X first
#define Y second
#define fill(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define pf push_front
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) reverse(v.begin(), v.end())
#define unq(v) v.erase(unique(all(v)), v.end())
#define el "\n"
#define mx3(a, b, c) max(max(a, b), c)
#define mn3(a, b, c) min(min(a, b), c)
#define S(v) accumulate(all(v), (ll)0)
#define SP(n) cout.precision(n)
#define PI = atan(1.0) * 4.0;
#define MOD = 1e9 + 7;
#define EPS = 0.0000001;
void start() {
    fio;
    SP(10);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
    start();
    int k;
    cin>>k;
    string s;
    cin>>s;
    int n=s.size();
    if(n>k)cout<<s.substr(0,k)<<"...";
    else cout<<s;
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long int ll;

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }


int main(){
	int n,d; cin >> n >> d;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	ll ans=abs(a[0]-d);
	for(int i=1;i<n;i++){
		ans=GCD(abs(a[i]-d),ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
/*
ID: rchalam1
LANG: C++14
TASK:
*/
// For train.usaco.org, fill the template above.

// Competitive Coding Template

// GCC OPTIMIAZTION FLAGS
#ifdef ONLINE_JUDGE
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#endif

#include <bits/stdc++.h>

/*
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
*/
// All Includes for Competitive Coding Template

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

using vi = std::vector<int>;
using vll = std::vector<long long>;
using vull = std::vector<unsigned long long>;

#define FOR(i, a, b) for (auto i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (auto i = (a); i >= (b); --i)
#define R0F(i, a) ROF(i, a, 0)
#define ITR(a, x) for (auto& a: x)

#define FSRT(set) sort((set).begin(),(set).end())
#define RSRT(set) sort((set).rbegin(),(set).rend())
#define CSRT(set, function) sort((set).begin(),(set).end(), (function))
#define TRS(set) sort((set).begin(),(set).end(), greater<>())
#define REV(set) reverse((set).begin(),(set).end());

#define ALL(set) (set).begin(), (set).end()

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// For stdio, call setIO() or setIO("").
void setIO(std::ifstream &readFile, std::ofstream &writeFile, const std::string &name = "", bool stdIO = false)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	if(!name.empty() && !stdIO)
	{
		readFile.open(name + ".in");
		if(readFile.fail()) return;
		writeFile.open(name + ".out");
		std::cin.rdbuf(readFile.rdbuf());
		std::cout.rdbuf(writeFile.rdbuf());
	}
}

// To time program, create object Timer  to start timing, and call Timer.elapsed().
#include <chrono>

class Timer
{
	std::chrono::time_point<std::chrono::high_resolution_clock> m_beg;
public:
	Timer() : m_beg(std::chrono::high_resolution_clock::now())
	{}

	void reset()
	{ m_beg = std::chrono::high_resolution_clock::now(); }

	[[nodiscard]] long double elapsed() const
	{
		return std::chrono::duration_cast<std::chrono::duration<long double, std::ratio<1> >>(
				std::chrono::high_resolution_clock::now() - m_beg).count();
	}
};

// Defines datatype
using dt = int;
// Defines MAXN value
constexpr dt MAXN = 1e5 + 1;
// Defines Modulus
constexpr dt MOD = 1e9 + 7;
// Defines Floating Point Correction
constexpr long double EPS = 1e-9;

//*****
//START CODE BELOW
//*****

int main(int argc, char *argv[])
{
	static std::ifstream readFile;
	static std::ofstream writeFile;
	setIO(readFile, writeFile);
	map<string, int> net;
	ll n;
	cin >> n;
	ll power = 1;
	for(ll i = 1; i <= n; ++i) (power *= i) %= MOD;
	cout << power << '\n';
}

Measured memory_bytes: 3588
n = int(input())
a = list(map(int, input().split()))
assert len(a) == n

# 添字のリスト
p = list(range(n))
p.sort(key=lambda i: a[i])

# dp[j] = 位置jから幅iの区間に小さい方からi個を配置したときの最大うれしさ
dp = [0] * (n + 1)

for i in range(n):
    for j in range(n - i):
        dp[j] = max(dp[j]     + a[p[i]] * abs(p[i] - (j + i)),
                    dp[j + 1] + a[p[i]] * abs(p[i] - j))

print(dp[0])

Measured memory_bytes: 9368
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

class Program
{
	static void Main(string[] args)
	{
		int[] intArray = Console.ReadLine().Split(' ').Select(z => int.Parse(z)).ToArray();
		int N = intArray[0];
		int M = intArray[1];
		int[,] ab = new int[N, 2];
		int[,] cd = new int[M, 2];
		int[] ans = new int[N];



		for(int i = 0; i < N; i++)
        {
			int[] tmp = Console.ReadLine().Split(' ').Select(z => int.Parse(z)).ToArray();

			ab[i, 0] = tmp[0];
			ab[i, 1] = tmp[1];
		}
		for (int i = 0; i < M; i++)
		{
			int[] tmp = Console.ReadLine().Split(' ').Select(z => int.Parse(z)).ToArray();

			cd[i, 0] = tmp[0];
			cd[i, 1] = tmp[1];
		}

		for (int i = 0; i < N; i++)
		{
			ans[i] = int.MaxValue;
			int kyori = int.MaxValue;
			for (int j = 0; j < M; j++)
			{
				int tmp = Math.Abs(ab[i, 0] - cd[j, 0]) + Math.Abs(ab[i, 1] - cd[j, 1]);
				if(tmp < kyori)
                {
					kyori = tmp;
					ans[i] = j + 1;
                }
			}
		}
		for (int i = 0; i < N; i++)
		{
			Console.WriteLine(ans[i]);
		}
	}

	/// <summary>
	/// アナグラム
	/// </summary>
	/// <param name="word1"></param>
	/// <param name="word2"></param>
	/// <returns></returns>
	static bool IsAnagramOf(string word1, string word2)
	{
		return word1.OrderBy(x => x).SequenceEqual(word2.OrderBy(x => x));
	}
	/// <summary>
	/// 最小公倍数
	/// </summary>
	/// <param name="a"></param>
	/// <param name="b"></param>
	/// <returns></returns>
	public static long Lcm(long a, long b)
	{
		return a * b / Gcd(a, b);
	}

	/// <summary>
	/// 最大公約数
	/// </summary>
	/// <param name="a"></param>
	/// <param name="b"></param>
	/// <returns></returns>
	public static long Gcd(long a, long b)
	{
		if (a < b)
			// 引数を入替えて自分を呼び出す
			return Gcd(b, a);
		while (b != 0)
		{
			var remainder = a % b;
			a = b;
			b = remainder;
		}
		return a;
	}
}




//string s = Console.ReadLine();
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];
//int N = int.Parse(Console.ReadLine());
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());
//Boolean ok = false;

//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.ReadKey();
//Console.WriteLine(cnt);

//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];


Measured memory_bytes: 28200
from sys import stdin

X,N = map(int,input().split())
p = list(map(int,stdin.readline().split()))

def solve():
    i = 1
    if N == 0:
        print(X)
        return
    if not X in p:
        print(X)
        return
    while True:
        if not X-i in p:
            print(X-i)
            return
        if not X+i in p:
            print(X+i)
            return
        i += 1

solve()



Measured memory_bytes: 9136
//AtCoder ABC077 C - Snuke Festival
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
#if LOCAL&01
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll N;
    cin>>N;
    vector<vector<ll>> abc(3,vector<ll>(N));
    for(ll i=0;i<3;++i){
        for(auto && v:abc[i]){
            cin>>v;
        }
        sort(abc[i].begin(),abc[i].end());
    }
 
    vector<ll> d0(N+1,0);
    constexpr int a=0, b=1, c=2;
    for(ll i=0;i<abc[b].size();++i){
        auto itr = lower_bound(abc[a].begin(),abc[a].end(),abc[b][i]); //FIXME:せばめる 
        auto d = distance(abc[a].begin(),itr);
        d0[i+1]=d0[i]+d;
    }

    vector<ll> d1(N+1,0);
    for(ll i=0;i<abc[c].size();++i){
        auto itr = lower_bound(abc[b].begin(),abc[b].end(),abc[c][i]);
        auto d = distance(abc[b].begin(), itr);
        ll num=d0[d];
        d1[i+1]=d1[i]+num;
    }

    cout<<d1[N]<<endl;

    return 0;
}

Measured memory_bytes: 4208
#include <bits/stdc++.h>
using namespace std;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;
int main(){
    Bint A;
    cin>>A;
    Bint N = 1;
    Bint B;
    int c = 0;
    for(int i = 0; i < A; i++){
        cin>>B;
        if(c != 0 && B != 0){
            if(i == A-1){
                N=-1;
                break;
            }
            else{
                continue;
            }
        }
        else if (B == 0){
            N=0;break;
        }
        N=N*B;
        if(N>1000000000000000000){
            c++;
            if(i==A-1){N=-1;}
        }
    }
    cout<<N<<endl;
}


Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
int main ()
{
int n,cnt,cnt1=0,save,m;
cin >> n;
if(n==1){
cout <<"1"<<endl;
return 0;
}
for(int i=2;i<=n;i++){
cnt=0;
m=i;
while(m>=2){


if(m%2==0)
cnt++;

m=m/2;
}
int p=i;
if(cnt>cnt1)
save=i;
else
continue;
cnt1=cnt;




}
cout << save << endl;

return 0;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  string s;
  cin >> s;
  if ((s[2] == s[3]) && (s[4] == s[5])) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
N = int(input())

max_count = 0
ans = 1

def div2(x, count):
    x, mod = divmod(x, 2)
    if mod != 0:
        return count
    else:
        if x == 1:
            return count+1
        return div2(x, count+1)
for x in range(1, N+1):
    count = div2(x, 0)
    
    if count > max_count:
        max_count = count
        ans = x
    
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int d, g;
    cin >> d >> g;
    vector<int> p(d) , c(d);
    rep(i, d) cin >> p[i] >> c[i];

    int ans = INF;
    rep(s, 1 << d) {
        int score = 0;
        int tot = 0;
        vector<bool> check(d, true);
        rep(i, d) {
            if(s >> i & 1) {
                score += c[i] + p[i] * 100 * (i + 1);
                tot += p[i];
                check[i] = false;
            }
        }
        if(score < g) {
            for(int i = d - 1; i >= 0; i--) {
                if(check[i]) {
                    if(score + (p[i] - 1) * (i + 1) * 100 < g) break;
                    while(score < g) {
                        score += 100 * (i + 1);
                        tot++;
                    }
                    break;
                }
            }
        }
        if(score >= g) ans = min(ans, tot);
    }

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

Measured memory_bytes: 256