akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

public class Program
{
    public static void Main(string[] args)
    {
        new Program().Solve(new ConsoleInput(Console.In, ' '));
    }

    public void Solve(ConsoleInput cin)
    {
        var s = cin.ReadLine;
        var ans = "";

        for (var i = 0; i < s.Length; i++)
        {
            ans += "x";
        }

        WriteLine(ans);
        ReadKey();
    }
}

public class ConsoleInput
{
    private readonly System.IO.TextReader _stream;
    private char _separator = ' ';
    private Queue<string> inputStream;
    public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
    {
        this._separator = separator;
        this._stream = stream;
        inputStream = new Queue<string>();
    }
    public string Read
    {
        get
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = _stream.ReadLine().Split(_separator);
            for (int i = 0; i < tmp.Length; ++i)
                inputStream.Enqueue(tmp[i]);
            return inputStream.Dequeue();
        }
    }
    public string ReadLine { get { return _stream.ReadLine(); } }
    public int ReadInt { get { return int.Parse(Read); } }
    public long ReadLong { get { return long.Parse(Read); } }
    public double ReadDouble { get { return double.Parse(Read); } }
    public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
    public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
    public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
}

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

int main(){
    string s; cin>>s;
    int cnt=0;
    int w[200001]={0};
    long long ans=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='B') cnt++;
        else w[i]=cnt;
    }
    for(int i=0;i<s.length();i++){
        ans+=w[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1412
class KMP:
    def __init__(self, P):
        self.P = P
        self.N = len(P)
        self.T = [0] * (self.N + 1)
        self._compile()

    def _compile(self):
        j = 0
        self.T[0] = -1
        for i in range(1, self.N):
            self.T[i] = j
            j += 1 if self.P[i] == self.P[j] else -j
        self.T[self.N] = j

    def search(self, S):
        NS = len(S)
        i = m = 0
        A = []
        while m + i < NS:
            if self.P[i] == S[m + i]:
                i += 1
                if i != self.N:
                    continue
                A.append(m)
            m += i - self.T[i]
            i = max(0, self.T[i])
        return A

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = [A[i]^A[(i+1)%N] for i in range(N)]
D = [B[i]^B[(i+1)%N] for i in range(N)]
C = C + C[:-1]
K = KMP(D).search(C)
#D string C pattern
for k in K:
    print(k, A[k]^B[0])


Measured memory_bytes: 128080
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }

const int N = 200005,V = N * 120,E = N * 120;
int n,a[N],b[N],p[N];

int To[E],Ne[E],He[V],_;
inline void add(int x,int y){ if (!x || !y) return; ++_; To[_] = y,Ne[_] = He[x],He[x] = _; }
int cntv;
int node[N<<2];
inline void Build(int o,int l,int r){
	node[o] = ++cntv; if (l == r) return;
	int mid = l+r>>1; Build(o<<1,l,mid); Build(o<<1|1,mid+1,r);
	add(node[o],node[o<<1]),add(node[o],node[o<<1|1]);
}
int pp,vv;
inline void Ins(int o,int l,int r){
	if (l == r){ ++cntv; add(cntv,node[o]),add(cntv,vv); node[o] = cntv;  return; }
	int mid = l+r>>1; if (pp <= mid) Ins(o<<1,l,mid); else Ins(o<<1|1,mid+1,r); 
	node[o] = ++cntv; add(node[o],node[o<<1]),add(node[o],node[o<<1|1]);
}
int ll,rr;
inline void Add(int o,int l,int r){
	if (ll <= l && rr >= r){ add(vv,node[o]); return; }
	int mid = l+r>>1; if (ll <= mid) Add(o<<1,l,mid); if (rr > mid) Add(o<<1|1,mid+1,r);
}

int dfn[V],low[V],stk[V],top,vis[V],scc_cnt,scc[V],ssiz[V],Time;
inline void dfs(int x){
	dfn[x] = low[x] = ++Time,vis[x] = 1,stk[++top] = x;
	for (int p = He[x],y; p ; p = Ne[p]){
		y = To[p];
		if (!dfn[y]) dfs(y),low[x] = min(low[x],low[y]);
		else if (vis[y]) low[x] = min(low[x],dfn[y]);
	}
	if (dfn[x] == low[x]){
		scc[x] = ++scc_cnt; vis[x] = 0;
		while (stk[top] ^ x) vis[stk[top]] = 0,scc[stk[top]] = scc[x],--top; --top;
	}
}

int main(){
//	cerr << sizeof(ssiz) * 9.0 / 1024 / 1024 << '\n';
	int i,x;
	read(n);
	for (i = 1; i <= n; ++i) read(a[i]),read(b[i]),p[b[i]] = i; 
	cntv = n;
	Build(1,1,n); 
	for (i = 1; i <= n; ++i){
		vv = p[i],pp = a[p[i]],Ins(1,1,n);
		vv = p[i],ll = 1,rr = a[p[i]],Add(1,1,n);
	//	cerr << "insert " << i << ' ' << p[i] << ' ' << a[p[i]] << '\n';
	}
	Build(1,1,n);
	for (i = n; i ; --i){
		vv = p[i],pp = a[p[i]],Ins(1,1,n);
		vv = p[i],ll = a[p[i]],rr = n,Add(1,1,n);
	//	cerr << "insert " << i << ' ' << p[i] << ' ' << a[p[i]] << '\n';
	}
	for (i = 1; i <= cntv; ++i) if (!dfn[i]) dfs(i);
	for (i = 1; i <= n; ++i) ++ssiz[scc[i]];
	for (i = 1; i <= n; ++i) write(ssiz[scc[i]]),putchar('\n');
	return 0;
}

Measured memory_bytes: 423068
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		System.out.println(solve());
	}
	
	public static int solve() {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int T = sc.nextInt();
		return (int)((T + 0.5) / A) * B;
	}
}


Measured memory_bytes: 22996
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>

using namespace std;

struct Point{
	double x,y;
};

int main(){

	int sum = 0,tmp;

	for(int i = 0; i < 10; i++){
		scanf("%d",&tmp);
		sum += tmp;
	}

	printf("%d\n",sum);

	return 0;
}

Measured memory_bytes: 2704
/**
    And in the end, the love you take is equal to the love you make.

        I LOVE YOU LAURA.
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_DISABLE_PERFCRIT_LOCKS

#define findOrder find_by_order
#define orderKey order_of_key

#define isOn(mask, i) (mask & (1 << i))
#define turn(mask, i) (mask |= (1 << i))
#define switch(mask, i) (mask &= ~(1 << i))
#define change(mask, i) (mask ^= (1 << i))
#define lowbit(mask) (mask & (-mask))
#define turnAll(mask, n) (mask = (1 << n) - 1)
#define switchLastBit(mask) (mask & (mask - 1))
#define turnLastZero(mask) (mask | (mask + 1))
#define modulo(x, mod) ((x) & (mod - 1))
#define log2(x) (31 - __builtin_clz(x))

#define mkp make_pair
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define ins insert
#define rsz resize
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) ((int)x.size())
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define debug(x) (cerr << x << " ")

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

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

typedef pair<int, int> ii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdb;
typedef pair<int, ii> tri;
typedef complex<ld> cd;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vdb;
typedef vector<cd> vcd;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vll> matrix;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_tree;

const ll mod = 1e9+7;
const int maxn = 1e5+2;
const int pi = 2 * acos(0.0);
const db eps = 1e-9;

ii arr[105];
ll dp[105][maxn];

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

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

    int mv = 0;
    for (int i = 1; i <= n; i++){
        cin >> arr[i].f >> arr[i].s;
        mv += arr[i].s;
    }

    memset(dp, 63, sizeof dp);

    dp[1][0] = 0;
    for (int i = 1; i <= n; i++){
        for (int j = 0; j <= mv; j++){
            if (j >= arr[i].s){
                dp[i + 1][j] = min(dp[i][j], dp[i][j -  arr[i].s] + arr[i].f);
            }
            else{
                dp[i + 1][j] = dp[i][j];
            }
        }
    }

    ll ans = 0;

    for (ll i = 0; i <= mv; i++){
        if (dp[n + 1][i] <= w) ans = max(ans, i);
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 82304
#include<cstdio>
#include<algorithm>
using namespace std;
int n,k,ans,a;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		if(a==1)
		{
			ans=66666666;
			for(int j=i;j>=1&&i-j<k;j--)
			{
				int r=min(n,j+k-1);
				int l=(j-1)/(k-1);
				if(l*(k-1)!=j-1) l++;
				int rr=(n-r)/(k-1);
				if(rr*(k-1)!=n-r) rr++;
				ans=min(ans,1+l+rr);
			}
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();

		long answer = 0;
		long quot = 0;
		long mod = 0;

		quot = n / (a + b);
		mod = n % (a + b);

		if (a <= mod) {
			answer = quot * a + a;
		} else {
			answer = quot * a +  mod;
		}

		System.out.println(answer);
	}
}

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

ll a, b; 


int main() {
  int n; cin >> n;
  vector<int>a(n);
  rep(i,n) cin >> a[i];
  
  int count = 0;
  int len = a.size();
  int tmp=1;
  rep(i,len) {
    if(a[i]==tmp) {
      tmp++;
    }
  }
 
  tmp--;
  if(tmp==0) cout << -1 << endl;
  else cout << len-tmp << endl;
 
  return 0;
}

Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        static final int mod = 1000000007;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int m = Integer.parseInt(in.next());
            int ans = 0;

            ans = nCk(n, 2, mod) + nCk(m, 2, mod);
            if (n == 0) ans--;
            if (m == 0) ans--;
            if (n == 1) ans--;
            if (m == 1) ans--;

            // 出力
            out.println(ans);

        }

        public static int nCk(int n, int k, int M) {
            long ret = 1;
            int min = Math.min(k, n - k);
            for (int i = 1; i <= min; i++) {
                ret = (ret * pow(i, M - 2, M)) % M;
            }
            for (int i = n - min + 1; i <= n; i++) {
                ret = (ret * i) % M;
            }
            return (int) ret;
        }

        public static long pow(long a, long b, int M) {
            long ret = 1;
            long tmp = a;
            while (b > 0) {
                if ((b & 1) == 1) ret = (ret * tmp) % M;
                tmp = (tmp * tmp) % M;
                b = b >> 1;
            }
            return ret;
        }

    }
}



Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ull unsigned long long
# define ll long long
# define mod 1000000007LL 
using namespace std;
int main()
{
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll num=0;
    ll temp=7;

    for(int i=1;i<=10000000;i++)
    {
        num=(num%n+temp%n)%n;
        if(num==0)
        {
            cout<<i;
            return 0;
        }
        temp=(temp*10)%n;
    }
    cout<<-1;


    
    return 0;
}

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

using namespace std;

int main()
{
  int A,B,C,D,P;
  cin>>A;
  cin>>B;
  cin>>C;
  cin>>D;
  cin>>P;

  // X社
  int X_sum = A * P;

  //Y社
  int Y_sum = B;
  if(P > C){
    Y_sum += D * (P - C);
  }

  int ans = min(X_sum,Y_sum);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3100
count = 0
a = 0
b = 0
while (count <= 3000) and (a  <= 10000) and (b <= 10000):
    a,b = map(int, input().split())
    if a == b == 0:
        break

    if a > b:
        tmp = a
        a = b
        b = tmp

    count += 1
    print(a, b, sep = ' ')


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

using namespace std;

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

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

    int best = 1e9;
    bool ok = false;
    for(int mask = 0; mask < (1 << n); mask++)
    {
        int cur = 0;
        vector<int> v(m);
        for(int i = 0; i < n; i++)
        {
            if(((mask >> i) & 1))
            {
                cur += c[i];
                for(int j = 0; j < m; j++)
                    v[j] += a[i][j];
            }
            bool ok1 = true;
            for(int j = 0; j < m; j++)
            {
                if(v[j] < x)
                {
                    ok1 = false;
                    break;
                }
            }
            if(ok1)
            {
                best = min(best, cur);
                ok = true;
            }
        }
    }

    if(!ok)
        cout << "-1";
    else
        cout << best;

    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long
#define maxn 200001
#define pb push_back
#define fi first
#define se second
#define mod 1000000007
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
vi AdjList[maxn];
vi eve;
vi od;
bool check[maxn];
int ans[maxn];
void dfs(int start, int cnt)
{
	check[start] = true;
	if (cnt % 2 == 0)	eve.pb(start);
	else od.pb(start);
	for (int i = 0; i < AdjList[start].size(); i++)
	{
		int u = AdjList[start][i];
		if (!check[u])
		{
			dfs(u, cnt+1);
		}
	}
}
bool lost[maxn];
int main()
{
	int n;	cin >> n;
	for (int i = 0; i < n-1; i++)
	{
		int u, v;	cin >> u >> v;
		AdjList[u].pb(v);
		AdjList[v].pb(u);
	}
	dfs(1, 0);
	int temp = n/3;
	if (temp >= min(od.size(), eve.size()))
	{
		if (od.size() <= eve.size())
		{
			for (int i = 0; i < od.size(); i++)
			{
				ans[od[i]] = (i+1)*3;
				lost[(i+1)*3] = true;
			}
		}
		else
		{
			for (int i = 0; i < eve.size(); i++)
			{
				ans[eve[i]] = (i+1)*3;
				lost[(i+1)*3] = true;
			}
		}
		int cnt = 1;
		for (int i = 1; i <= n; i++)
		{
			if (ans[i] == 0)
			{
				if (lost[cnt])	cnt++;
				ans[i] = cnt;
				cnt++;
			}	
		}
		for (int i = 1; i <= n; i++)
		{
			cout << ans[i] << " ";	
		}
	}
	else
	{
		for (int i = 0; i < eve.size(); i++)
		{
			if (i*3+1 > n)	break;
			ans[eve[i]] = i*3+1;
			lost[i*3+1] = true;
		}
		for (int i = 0; i < od.size(); i++)
		{
			if (i*3+2 > n)	break;
			ans[od[i]] = i*3+2;
			lost[i*3+2] = true;
		}
		int cnt = 1;
		for (int i = 1; i <= n; i++)
		{
			if (ans[i] == 0)
			{
				ans[i] = cnt*3;
				cnt++;
			}
		}
		for (int i = 1; i <= n; i++)
		{
			cout << ans[i] << " ";	
		}
	}
}

Measured memory_bytes: 19572
#include <stdio.h>

typedef struct {
	char name[ 21 ];
	int score;
} Rec;

Rec record[ 10 ];

void insertionSort( Rec *, int );

int main( void ) {
	int i, n, win, draw, cnt = 0;

	while ( scanf( "%d", &n ), n ) {
		if ( cnt++ )
			putchar( '\n' );

		for ( i = n; i--;  ) {
			scanf( "%s %d %*d %d", record[ i ].name, &win, &draw );

			record[ i ].score = win * 3 + draw;
		}

		insertionSort( record, n );

		while ( n-- )
			printf( "%s,%d\n", record[ n ].name, record[ n ].score );
	}

	return 0;
}

void insertionSort( Rec *data, int n ) {
	int i, j;
	Rec tmp;

	for ( i = 1; i < n; i++ ) {
		tmp = data[ i ];

		for ( j = i; j && data[ j - 1 ].score > tmp.score; j-- )
			data[ j ] = data[ j - 1 ];

		data[ j ] = tmp;
	}
}

Measured memory_bytes: 604
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    int N,K;
    cin>>N>>K;
    vector<vector<ll>> neta(N+1);
    priority_queue<tuple<ll,int,int>> que;
    priority_queue<ll,vector<ll>,greater<ll>> que2;
    ll d;
    int t;
    vector<int> vec_t(N);
    vector<ll> vec_d(N);
    REP(i,N){
        cin>>t>>d;
        vec_t[i]=t;
        vec_d[i]=d;
        que.push(make_tuple(d,t,i));
    }

    tuple<ll,int,int> p;
    int cnt=0;
    ll ans=0;
    int num;
    REP(i,K){
        p=que.top();
        que.pop();
        d=get<0>(p);
        t=get<1>(p);
        num=get<2>(p);
        if(neta[t].size()==0) cnt++;
        neta[t].push_back(d);
        ans+=d;
    }
    ans+=pow(cnt,2);

    ll tmp=ans;
    REP(i,N){
        REP2(j,1,neta[i].size()){
            que2.push(neta[i][j]);
        }
    }

    ll q;
    while(!que2.empty()&&!que.empty()){
        q=que2.top();
        que2.pop();
        tmp-=q;
        bool flag=false;
        while(!que.empty()){
            p=que.top();
            que.pop();
            d=get<0>(p);
            t=get<1>(p);
            num=get<2>(p);
            if(neta[t].size()==0){
                neta[t].push_back(num);
                tmp+=d;
                flag=true;
                break;
            }
            
        }
        if(flag){
            tmp+=(2*cnt+1);
            cnt++;
            ans=max(tmp,ans);
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 8176
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			scanner.nextLine();

			String str = scanner.nextLine();
			int length = str.length();

			List<Character> charList = new ArrayList<>(length);
			for (int i = 0; i < length; i++) {
				charList.add(str.charAt(i));
			}

			int min = 0;
			for (int i = 1; i < length; i++) {
				if (charList.get(i) == 'E') {
					min++;
				}
			}

			int nowVal = min;
			for (int i = 0; i < length - 1; i++) {
				if (charList.get(i) == 'W') {
					nowVal++;
				}
				if (charList.get(i + 1) == 'E') {
					nowVal--;
				}
				if (nowVal < min) {
					min = nowVal;
				}
			}

			System.out.println(min);
		}
	}
}


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

typedef long long ll;

int main(){
   int N;
   ll x;
   std::cin >> N >> x;
   std::vector<ll> a(N);
   for(int i=0; i<N; ++i)
      std::cin >> a[i];

   std::sort(a.begin(),a.end());
   int happy = 0;
   ll sum = 0;
   for(int i=0; i<N; ++i){
      sum += a[i];
      if(sum<=x) ++happy;
      else break;
   }
   if(sum<x) --happy;
   
   std::cout << happy << std::endl;

   return 0;

}


Measured memory_bytes: 256
N, W = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(N)]
x.insert(0, [0, 0])
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
for i in range(1, N+1):
    for sum_m in range(1, W+1):
        #品物(w[i], v[i])を選ぶとき
        if sum_m >= x[i][0]:
            dp[i][sum_m] = max(dp[i][sum_m], dp[i-1][sum_m-x[i][0]] + x[i][1])
        #品物(w[i], v[i])を選ばないとき
        dp[i][sum_m] = max(dp[i][sum_m], dp[i-1][sum_m])
print(dp[N][W])

Measured memory_bytes: 218108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;


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

int main()
{
    int n;
    ll res = 0;
    cin >> n;

    for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= n; ++j)
        {
            int ij = gcd(i, j);
            for(int k = 1; k <= n; ++k) 
                res += gcd(ij, k);
        }
    }

    cout << res << "\n";
    return 0;
}

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

int main() {
  int64_t N,X,Z=0;
  cin>>N>>X;
  vector<vector<int64_t>> p(N+1,vector<int64_t>(3));
  p.at(0).at(0)=1,p.at(0).at(1)=1;
  for(int64_t i=1;i<=N;i++){
    p.at(i).at(1)=p.at(i-1).at(1)*2+1;
    p.at(i).at(2)=p.at(i-1).at(2)*2+2;
    p.at(i).at(0)=p.at(i-1).at(0)*2+3;
  }
  while(X>0){
    X--;
    N--;
    if(X==p.at(N).at(0)){
      Z+=p.at(N).at(1);
      X=0;
    }
    else if(X>p.at(N).at(0)&&X<p.at(N).at(0)*2+1){
      Z+=1+p.at(N).at(1);
      X-=p.at(N).at(0)+1;
    }
    
    else if(X==p.at(N).at(0)*2+2||X==p.at(N).at(0)*2+1){
      Z+=p.at(N).at(1)*2+1;
      X=0;
    }
  }
  cout<<Z<<endl;
    
}

Measured memory_bytes: 256
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def comb(n, r):
    if n - r < r:
        r = n - r
    res = 1
    for i in range(r):
        res *= (n - i) % mod
        res %= mod
        res *= pow(r - i, mod - 2, mod)
        res %= mod
    return res


n = inp()
x = inpl()
left = min(x)
right = max(x)
ans = INF
for i in range(left, right + 1):
    tmp = sum([(j - i) * (j - i) for j in x])
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 38640
#coding:utf-8

def call(n):
    for i in range(1,n+1):
        x=i
        if x%3==0:
            print(" "+str(i),end="")
        else:
            while x!=0:
                if x%10==3:
                    print(" "+str(i),end="")
                    break
                else:
                    x//=10
                    
    print("")

n=int(input())
call(n)

Measured memory_bytes: 7932
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1000000000;
int main(){
  int h,n;
  cin >> h >> n;

  vector<pair<int,int>> ab(n);
  for(int i = 0;i < n;i++){
    int a,b;
    cin >> a >> b;
    ab[i] = make_pair(a,b);
  }
  vector<int> dp(h+1,INF);
  dp[0] = 0;
  for(int i = 0;i < h;i++){
    for(int j = 0;j < n;j++){
      int a = ab[j].first;
      int b = ab[j].second;

      dp[min(i+a,h)] = min(dp[min(i+a,h)],dp[i]+b);
    }
  }

  cout << dp[h] << endl;
}

Measured memory_bytes: 256
#include <math.h>

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

int main() {
  int x;
  cin >> x;
  x /= 200;

  cout << 8 - (x - 2);

  return 0;
}


Measured memory_bytes: 3668
eval"H,W,*A="+`dd`.split*?,
A.pop(H*W).zip(A){|a,b|a=(a-b).abs
$.%W<1&&N=0
N|=$*[-W]||0**$.<<T=1e4
$*<<N=N<<a|N>>a
$.+=1}
p (0..T).find{|i|N[T+i]>0}

Measured memory_bytes: 37252
#include<bits/stdc++.h>
using namespace std;
 
#define ll          long long  int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000000000
#define MAXN        300005
#define mod         998244353  
 
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    if(n<=m){
        cout<<"unsafe";
    }
    else{
        cout<<"safe";
    }
}

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

using namespace std;

int main()
{
    double n,k,p=0;
    cin >> n >> k;
    for(int i=0;i<n;i++){
        double a=i+1;
        double c=0;
        while(a<k){
            a*=2;
            c++;
        }
        p+=1/(pow(2,c)*n);
    }
    cout << setprecision(13) << p << endl;
    return 0;
}


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

long long gcd(long long x, long long y){
	if(y > x) swap(x, y);
	return !y ? x : gcd(y, x % y);
}

long long lcm(long long x, long long y){
	return x / gcd(x, y) * y;
}

int main() {
	int n;
	cin >> n;
	long long t[101] = {0};
	for(int i = 0; i < n; i++) cin >> t[i];
	
	long long ans = t[0];
	for(int i = 1; i < n; i++){
		ans = lcm(ans, t[i]);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void)
{
   int n,k,l[50],i,j,a,x,s;
 
   scanf("%d%d",&n,&k);
  
   for(i=0;i<n;i++){
      scanf("%d",&l[i]);
   }
  
   for(i=0;i<n-1;i++){
       for(j=i;j<n;j++){
         if(l[i]<l[j]){
            a=l[i];
            l[i]=l[j];
            l[j]=a;
         }
       }
   }
  
   for(i=0,a=0;i<k;i++){
      a+=l[i];
   }
  
   printf("%d\n",a); 
  
   return 0;
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=300005;
const ll INF=0x3f3f3f3f;
const ll MOD=998244353;
ll n,chk[MAX],pt,ans,ans_t;
struct range{
    ll x,y,idx;
};
range seg1[MAX],seg2[MAX];
bool cmp1(const range &a,const range &b){return a.x>b.x;}
bool cmp2(const range &a,const range &b){return a.y<b.y;}
int main(){
    scanf("%lld",&n);
    for(ll i=0;i<n;i++) scanf("%lld%lld",&seg1[i].x,&seg1[i].y),seg1[i].idx=i,seg2[i]=seg1[i];
    sort(seg1,seg1+n,cmp1),sort(seg2,seg2+n,cmp2);
    pt=0,ans_t=0;
    for(ll i=0;i<n;i++){
        if(chk[seg1[i].idx]==0){
            ll t=max(min(pt,seg1[i].y),seg1[i].x);
            chk[seg1[i].idx]=1;
            ans_t+=abs(pt-t), pt=t;
        }
        if(chk[seg2[i].idx]==0){
            ll t=max(min(pt,seg2[i].y),seg2[i].x);
            chk[seg2[i].idx]=1;
            ans_t+=abs(pt-t), pt=t;
        }
    }
    ans_t+=abs(pt);
    ans=max(ans_t,ans);
    for(ll i=0;i<n;i++) chk[i]=0;
    pt=0,ans_t=0;
    for(ll i=0;i<n;i++){
        if(chk[seg2[i].idx]==0){
            ll t=max(min(pt,seg2[i].y),seg2[i].x);
            chk[seg2[i].idx]=1;
            ans_t+=abs(pt-t), pt=t;
        }
        if(chk[seg1[i].idx]==0){
            ll t=max(min(pt,seg1[i].y),seg1[i].x);
            chk[seg1[i].idx]=1;
            ans_t+=abs(pt-t), pt=t;
        }
    }
    ans_t+=abs(pt);
    ans=max(ans_t,ans);
    printf("%lld\n",ans);
}


Measured memory_bytes: 12544
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

ll n, m, q;
ll a[55];
ll b[55];
ll c[55];
ll d[55];
ll ans;

void dfs(vll v) {
  if(v.size()==n) {
    ll tmp = 0LL;
    rep(i,q) {
      if(v[b[i]]-v[a[i]]==c[i]) tmp += d[i];
    }
    ans = max(ans,tmp);
    return;
  }
  ll k = v[v.size()-1];
  for(ll i = k; i<=m; i++) {
    vll vec = v;
    vec.push_back(i);
    dfs(vec);
  }
}

int main() {
  cin >> n >> m >> q;
  rep(i,q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--;
    b[i]--;
  }
  ans = 0LL;
  for(ll j = 1; j<=m; j++) dfs({j});
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> P;
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fir first
#define sec second
#define pb push_back
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; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

int main(){
    ll n, ans = 0;
    cin >> n;
    vector<int> A(n+1), B(n);
    rep(i,n+1)cin >> A[i];
    rep(i,n) cin >> B[i];
    rep(i,n){
        int a = min(A[i], B[i]);
        A[i] -= a, B[i] -= a;
        ans += a;
        int b = min(A[i+1], B[i]);
        A[i+1] -= b, B[i] -= b;
        ans += b;
    }
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
    int n, a;
    cin >> n >> a;
    vector<ll> f(6001);
    const int base = 3000;
    f[base]++;
    for(int i=0; i<n; i++) {
        int x;
        cin >> x;
        x -= a;
        if(x>0) {
            for(int i=6000; i>=x; i--) f[i] += f[i-x];
        } else if(x<0) {
            for(int i=0; i+x<=6000; i++) f[i] += f[i-x];
        } else {
            for(int i=0; i<=6000; i++) f[i] *= 2;
        }
    }
    cout << f[base] - 1 << endl;


    return 0;
}

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

typedef long long int ll;

int main(){
	int n;cin >> n;
	vector<int> v(n);
	for(int i = 0;i < n;i++)cin >> v[i];
	int ans = INT_MAX;
	for(int i = 1;i <= 100;i++){
		int sum = 0;
		for(int j = 0;j < n;j++){
			sum += pow(i - v[j], 2);
		}
		ans = min(ans, sum);
	}
	cout << ans;
}


Measured memory_bytes: 256
// itne me hi thakk gaye?
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("-O3")
#define ll long long 
#define ull unsigned long long
using ld = long double;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const ll rk = 256;
const ll mod2 = 998244353;
const ld PI = 3.141592653589793;
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define print(a) for(auto j:a) {cout<<j<<",";} cout << "\n";
#define endl '\n'
#define whatis(x) cout << "> "<<#x << " ==> " << x << endl;
#define lwi(x) cout << " your " << #x << " is ---> " << x << " ";
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
// // Printing pair
ostream & operator << (ostream & os, pair <ll, ll> const& x) {
    os << x.first << "," << x.second;
    return os;
}
 
// printing vector
template <class T>
ostream & operator << (ostream & os, vector <T> const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
// printing set
template <class T>
ostream & operator << (ostream & os, set <T> const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
    return os << "[ " << p.first << ", " << p.second << "]" ;
}
const int mxn = 1e5+5;
ll func(ll x, ll y, ll z) {
    return ((x*x) + (y*y) + (z*z) + (z*y )+ (x*y )+ (x*z));
}
int32_t main(){
    FastIO;
    ll n;
    cin >> n;
    vc <ll> ans(n+1, 0);
    // map<vector<ll>, int> seen;
    for(ll top=1; top*top <= n; top++) {
        for(ll i=1; i*i<=n; i++) {
            for(ll j=1; j*j<=n; j++) {
                ll tmp = func(i, j, top);
                if (tmp <= n) ans[tmp]++;
                // cout << i << " " << j << " " << top << ": " << func(i, j, top) << endl;
            }
        }
    }
    for(int i=1; i<=n; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3608
/*
 * atcoder/abc130/a.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int N, V[20], C[20];

void input() {
  cin >> N;
  loop(n,0,N) cin >> V[n];
  loop(n,0,N) cin >> C[n];
}

void solve() {
  int total =0;
  loop(n,0,N) {
    if (V[n] > C[n]) total += V[n] - C[n];
  }
  cout << total << endl;
}

int main() {
  // cout.precision(15);
  input();
  solve();
  return 0;
}


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

int main(){
	int n;
	while(scanf("%d", &n), n){
		int a, b, s = 0, t = 0;
		for(int i = 0; i < n; ++i){
			scanf("%d%d", &a, &b);
			if(a > b){
				s += a + b;
			}
			else if(a < b){
				t += a + b;
			}
			else{
				s += a;
				t += b;
			}
		}
		printf("%d %d\n", s, t);
	}
}

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

using namespace std;

int ans=1000000;

int main() {
	int a[3];
	for(int i=0; i<3; i++) cin>>a[i];
	for(int i=0; i<3; i++) {
		for(int j=0; j<3; j++) {
			if(i==j) continue;
			ans=min(ans, a[i]+a[j]);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

ll f(ll n)
{
	ll res{1};
	for (ll i = 2; i <= n; ++i)
		res *= i;
	return res;
}

int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<pair<ll, ll>> XY(N);
	for (ll i = 0; i < N; ++i)
	{
		ll x, y; cin >> x >> y;
		XY[i] = pair<ll, ll>(x, y);
	}

	sort(XY.begin(), XY.end());
	double res{0};
	do
	{
		for (ll i = 1; i < N; ++i)
		{
			res += sqrt(pow(XY[i].first-XY[i-1].first, 2) + pow(XY[i].second - XY[i-1].second, 2));
		}
	} while (next_permutation(XY.begin(), XY.end()));

	std::cout << fixed << setprecision(10) << res / f(N) << std::endl;
}


Measured memory_bytes: 256
#define _USE_MA_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    string s;
    cin>>s;
    int n=s.length();
    int ans=inf;
    rep(i,2){
        int t=0;
        rep(j,n){
            if(i%2){
                if(j%2&&s[j]=='0')t++;
                else if(!(j%2)&&s[j]=='1')t++;
            }
            else{
                if(j%2&&s[j]=='1')t++;
                else if(!(j%2)&&s[j]=='0')t++;
            }
        }
        ans=min(ans,t);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;

int main()
{
	int y, x;
	while (1) {
		cin >> y >> x;
		if (y == 0 && x == 0)break;
		for (size_t i = 0; i < y; i++)
		{
			if (i % 2 == 0) {
				for (size_t i = 0; i < x; i++)
				{
					if (i % 2 == 0)cout << '#';
					else cout << '.';
				}
			}
			else{
				for (size_t i = 0; i < x; i++)
				{
					if (i % 2 == 0)cout << '.';
					else cout << '#';
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3072
import heapq

n = int(input())
v = sorted(list(map(int, input().split())))


for i in range(n-1):
  p1 = heapq.heappop(v)
  p2 = heapq.heappop(v)
  heapq.heappush(v, (p1+p2)/2)

print(v[0])

Measured memory_bytes: 3064
def solve(string):
    n, *a = map(int, string.split())
    a = [0] + a + [0]
    base = sum([abs(j - i) for i, j in zip(a, a[1:])])
    ans = []
    for a0, a1, a2 in zip(a, a[1:], a[2:]):
        if min(a0, a1, a2) == a1:
            ans.append(str(base - 2 * abs(a1 - min(a0, a2))))
        elif max(a0, a1, a2) == a1:
            ans.append(str(base - 2 * abs(a1 - max(a0, a2))))
        else:
            ans.append(str(base))
    return "\n".join(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


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

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

int f(int x) {
    int res = 0;
    while (x % 2 == 0) {
        x /= 2;
        res++;
    }
    return res;
}

int main()
{
    int n,m; cin >> n >> m;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    rep(i,n) {
        if (a[i] % 2 == 1) {
            cout << 0 << endl;
            return 0;
        }
        a[i] /= 2;
    }

    int t = f(a[0]);
    rep(i,n) {
        if (f(a[i]) != t) {
            cout << 0 << endl;
            return 0;
        }
        a[i] >>= t;
    }
    m >>= t;

    ll l = 1;
    rep(i,n) {
        l = lcm(l, a[i]);
        if (l > m) {
            cout << 0 << endl;
            return 0;
        }
    }

    m /= l;
    int ans = (m + 1) / 2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
m, n = gets.split.map &:to_i
$t = 1000000007

def pow(m, n)
  m = m % $t
  if n == 0
    1
  elsif n.even?
    pow(m * m, n / 2)
  else
    pow(m * m, n / 2) * m
  end
end

puts pow(m, n) % $t

Measured memory_bytes: 8688
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;
const ll mod = 1000000007;

int main() {
double a,b;
  in(a>>b);
  cout << fixed <<setprecision(10) << a/b <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int dp[81][81][12801]={0};
int main(){
    int h,w,A[80][80],B[80][80];
    cin>>h>>w;
    rep(i,h)rep(j,w) cin>>A[i][j];
    rep(i,h)rep(j,w) cin>>B[i][j];
    rep(i,h)rep(j,w){
        if(!i&&!j){
            dp[i][j][6400+A[i][j]-B[i][j]]=1;
            dp[i][j][6400-A[i][j]+B[i][j]]=1;
        }
        if(i){
            rep(k,12801)if(dp[i-1][j][k]){
                if(abs(k+A[i][j]-B[i][j]-6400)<=6400) dp[i][j][k+A[i][j]-B[i][j]]=1;
                if(abs(k-A[i][j]+B[i][j]-6400)<=6400) dp[i][j][k-A[i][j]+B[i][j]]=1;
            }
        }
        if(j){
            rep(k,12801)if(dp[i][j-1][k]){
                if(abs(k+A[i][j]-B[i][j]-6400)<=6400) dp[i][j][k+A[i][j]-B[i][j]]=1;
                if(abs(k-A[i][j]+B[i][j]-6400)<=6400) dp[i][j][k-A[i][j]+B[i][j]]=1;
            }
        }
    }
    int ans=6400;
    rep(i,12801) if(dp[h-1][w-1][i]) ans=min(ans,abs(i-6400));
    cout<<ans<<"\n";
}


Measured memory_bytes: 324608
<?php
$i=0;
$r=array_fill(1,4,0);
while($i<3){
  list($a,$b) = explode(" ",trim(fgets(STDIN)));
  ++$r[$a];
  ++$r[$b];
  ++$i;
}
$r=array_count_values($r);
$r=array_count_values($r);
echo ($r[2]==2)?'YES':'NO';

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

struct edge {
  ll from;
  ll to;
  ll cost;
};

int main() {
  ll n, m, p;  // n:頂点の数、m:辺の数
  cin >> n >> m >> p;
  vector<edge> edges;
  vector<vl> g(n), rg(n);
  rep(i, m) {
    edge e;
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    e.from = a;
    e.to = b;
    e.cost = p - c;
    edges.push_back(e);
    g[a].push_back(b);
    rg[b].push_back(a);
  }
  vb ok1(n, false);
  queue<int> q;
  ok1[0] = true;
  q.push(0);
  while(!q.empty()) {
    int i = q.front();
    q.pop();
    for(auto v : g[i]) {
      if(ok1[v]) continue;
      ok1[v] = true;
      q.push(v);
    }
  }
  vb ok2(n, false);
  ok2[n - 1] = true;
  q.push(n - 1);
  while(!q.empty()) {
    int i = q.front();
    q.pop();
    for(auto v : rg[i]) {
      if(ok2[v]) continue;
      ok2[v] = true;
      q.push(v);
    }
  }
  vl d(n, 1e18);
  d[0] = 0;
  rep(i, n) rep(j, m) {
    edge e = edges[j];
    if(!ok1[e.to] || !ok2[e.to] || !ok1[e.from] || !ok2[e.from]) continue;
    if(d[e.to] > d[e.from] + e.cost) {
      d[e.to] = d[e.from] + e.cost;
      if(i == n - 1) {
        cout << -1 << endl;  //負のループがある
        return 0;
      }
    }
  }
  cout << max(0LL, -d[n - 1]) << endl;
}

Measured memory_bytes: 3956
using namespace std;

#include <stdio.h>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>

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

int n, m;

int gcd(int a, int b) {
  return (b == 0) ? a : gcd(b, a % b);
}

signed main() {
  scanf("%d%d", &n, &m);
  int mx = (m / n) + 1;
  int ans = 1, mod;
  int s = sqrt(m) + 1.;
  if (n == 1) printf("%d\n", m);
  else if (m % n == 0) printf("%d\n", m / n);
  else if (mx <= 50000000) {
    for (int i = 2; i < mx; i++) {
      mod = m - (i * (n - 1));
      ans = max(ans, gcd(mod, i));
    }
    printf("%d\n", ans);
  }
  else {
    for (int i = 2; i < s; i++) {
      if (m % i == 0) {
	if (i < mx) ans = max(i, ans);
	if (m / i < mx) ans = max(m / i, ans);
      }
    }
    printf("%d\n", ans);
  }

}



Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const S = arg[0].split("");
    
    const MOD = 1000000007;
    
    let dp = [];
    
    // dp[i][j]は後ろからi桁を13で割った余りがjであるものの個数
    for(let i=0;i<S.length+1;i++){
        dp.push(Array(13).fill(0));
    }
    
    dp[0][0] = 1;
    
    for(let i=0; i<S.length; i++) {
        const c = S[i] === "?" ? -1: parseInt(S[i]);
        
        for(let j=0; j<10; j++) {
            if(c !== -1 && c !== j) continue;
            
            for(let k=0; k<13; k++) {
                dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
            }
        }
        
        for(let j=0; j<13; j++) {
            dp[i+1][j] %= MOD;
        }
    }
    
    console.log(dp[S.length][5]);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 62212
import Foundation

func readDoble() -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func main() {
    let abhm = readDoble()
    let (a, b, h, m) = (abhm[0], abhm[1], abhm[2],abhm[3])
    
    let alpha = (h * 60 + m) / 720 * (Double.pi * 2)
    let beta  = m / 60 * (Double.pi * 2)
    let theta = alpha - beta
    
    let sqAns = pow(a, 2.0) + pow(b, 2.0) - 2.0 * a * b * cos(theta)
    print(sqAns.squareRoot())
    
}
main()


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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int H, W;
string a[110];
bool tate[110], yoko[110];

signed main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            tate[j] |= a[i][j] == '#';
            yoko[i] |= a[i][j] == '#';
        }
    }
    for (int i = 0; i < H; i++) {
        if (!yoko[i])continue;
        for (int j = 0; j < W; j++) {
            if (tate[j])cout << a[i][j];
        }
        cout << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define mod 1000000007
#define ff first
#define ss second
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define vll vector<ll>
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define f(i, n) for(int i=0; i<n; ++i)
#define rep(i, a, b) for(int i=a; i<=b; i++)
#define repd(i, a, b) for(int i=a; i>=b; i--)
#define MAXN 200001
#define umapi unordered_map<int, int>
#define umapll unordered_map<ll, ll> 
 
 
int add(int a, int b)
{
    int temp=a+b;
    if(temp<0)
        temp=mod+temp;
    else if(temp>mod)
        temp=temp%mod;
    return temp;
}
 
int mul(int a, int b)
{
    ll temp=(1ll*a*b);
    if(temp<0)
        temp=mod+temp;
    else if(temp>=mod)
        temp=temp%mod;
    return temp;
}

bool perfect(int x)
{
    if(x<0)
        return false;
    if(x==0)
        return true;
    int temp=sqrt(x);
    return (temp*temp)==x;
}

int A[MAXN], B[MAXN], C[MAXN];
ll dp[MAXN][4];

/*
ll cost(int n, int curr, int flagA, int flagB, int flagC)
{
    if(dp[curr]!=0)
        return dp[curr];
    if(curr==n+1)
        return 0;
    if(curr>n+1)
        return -100000000;
    int costA=0, costC=0, costB=0;
    if(flagA)
        costA=A[curr]+cost(n, curr+1, 0, 1, 1);
    if(flagB)
        costB=B[curr]+cost(n, curr+1, 1, 0, 1);
    if(flagC)
        costC=C[curr]+cost(n, curr+1, 1, 1, 0);
    return dp[curr]=max(costA, max(costB, costC));
}
*/

 
void solve()
{   
    int n; cin>>n;
    f(i, n)
        cin>>A[i+1]>>B[i+1]>>C[i+1];
    memset(dp, 0, sizeof(dp));


    dp[1][1]=max(B[1], C[1]);
    dp[1][2]=max(A[1], C[1]);
    dp[1][3]=max(B[1], A[1]);
    //printf("%lld %lld %lld\n", dp[1][1], dp[1][2], dp[1][3]);
    rep(i, 2, n)
    {
        dp[i][1]=A[i]+max(dp[i-1][2], dp[i-1][3]);
        dp[i][2]=B[i]+max(dp[i-1][1], dp[i-1][3]);
        dp[i][3]=C[i]+max(dp[i-1][2], dp[i-1][1]); //printf("%lld %lld %lld\n", dp[i][1], dp[i][2], dp[i][3]);
    }

    //ll ans=cost(n, 1, 1, 1, 1);
    ll ans=max(dp[n][1], max(dp[n][2], dp[n][3]));
    printf("%lld\n", ans);
}
 

void io()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
 
 
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    //io();
    
    //int t; cin>>t; 
    int tc=0;
    //while(t--)
    {
        tc++;
        //printf("Case #%d: ", tc); 
        solve();
    }  
    return 0;
}

Measured memory_bytes: 8576