akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
    string S;
    cin >> S;
    int n0=0, n1=0;
    for(int i=0;i<S.length();i++){
        if(S[i] == '0') n0++;
        else if(S[i] == '1') n1++;
    }
    cout << min(n0,n1) * 2 << endl;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}


ll imos[2020][2020];

int main(){

    ll N;
    cin >> N;
    vector<ll>v(N + 1, 0);
    rep1(i, N){
        cin >> v[i];
        imos[i][v[i]]++;
    }

    for(ll i = 1; i <= 2005; i++){
        for(ll j = 1; j <= 2005; j++){
            imos[i][j] += imos[i][j - 1];
        }
    }
    for(ll j = 1; j <= 2005; j++){
        for(ll i = 1; i <= 2005; i++){
            imos[i][j] += imos[i - 1][j];
        }
    }

    ll ans = 0;
    for(ll i = 1; i <= N; i++){
        for(ll j = i + 1; j <= N; j++){
            if(j == N)continue;
            ll a = v[i], b = v[j];
            ll mn = max(b - a, a - b);
            ll mx = a + b - 1;
            if(mn > mx)continue;
            ans += imos[N][mx] + imos[j][mn] - imos[j][mx] - imos[N][mn];
            // ll tmp1 = imos[N][mx] + imos[j][mn] - imos[j][mx] - imos[N][mn];
            // ll tmp2 = 0;
            // for(ll k = j + 1; k <= N; k++){
            //     ll c = v[k];
            //     if(mn < c && c <= mx)tmp2++;
            // }
            // if(i == 2 && j == 3){
            //     cout << "#" << mn << " " << mx << endl;
            // }
            // cout << a << " " << b << " " << tmp1 << " " << tmp2 << endl;
        }
    }
    cout << ans << endl;

    return 0;
}

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

int t;
vector<vector<int>> humans;
vector<vector<int>> seats;

void bfs(int _x, int _y) {
    queue<pair<int,int>> q;
    q.push({_x,_y});
    while(!q.empty()) {
        auto&& xy = q.front(); q.pop();
        int x = xy.first, y = xy.second;
        if(y > 0 && seats[y - 1][x] > seats[y][x] + humans[y - 1][x]) {
            seats[y - 1][x] = seats[y][x] + humans[y - 1][x];
            q.push({x, y - 1});
        }
        if(y < t - 1 && seats[y + 1][x] > seats[y][x] + humans[y + 1][x]) {
            seats[y + 1][x] = seats[y][x] + humans[y + 1][x];
            q.push({x, y + 1});
        }
        if(x > 0 && seats[y][x - 1] > seats[y][x] + humans[y][x - 1]) {
            seats[y][x - 1] = seats[y][x] + humans[y][x - 1];
            q.push({x - 1, y});
        }
        if(x < t - 1 && seats[y][x + 1] > seats[y][x] + humans[y][x + 1]) {
            seats[y][x + 1] = seats[y][x] + humans[y][x + 1];
            q.push({x + 1, y});
        }
    }
}

int main() {
    cin >> t;
    for(int y = 0; y < t; y++) {
        vector<int> row;
        for(int x = 0; x < t; x++) {
            row.push_back(min({x, t - x - 1, y, t - y - 1}));
        }
        seats.push_back(row);
        vector<int> humanRow(t, 1);
        humans.push_back(humanRow);
    }
    int result = 0;
    for(int i = 0; i < t * t; i++) {
        int number;
        cin >> number;
        number--;
        int x = number % t;
        int y = number / t;
        result += seats[y][x];
        seats[y][x]--;
        humans[y][x]--;
        bfs(x, y);
    }
    cout << fixed << result;
}


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

void insertionsort(vector<int> &A,int N){
  int v,j;
  for(int l=0;l<N;l++){
      if(l==N-1)
        cout<<A.at(l);
      else
        cout<<A.at(l)<<" ";
    }
    cout<<endl;
  for(int i=1;i<N;i++){
    v=A.at(i);
    j=i-1;
    while(j>=0&&A.at(j)>v){
      A.at(j+1)=A.at(j);
      j--;
    }
    A.at(j+1)=v;
    for(int l=0;l<N;l++){
      if(l==N-1)
        cout<<A.at(l);
      else
        cout<<A.at(l)<<" ";
    }
    cout<<endl;
  }
  
}

int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  insertionsort(A,N);
  
}



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

using namespace std;

char c[1200][1200];
int i,j,m,n,x,y;

inline void dfs(int x,int y,int rx,int ry)
{
	if ((! rx) && (! ry))
	{
		puts("YES");
		for (i=1;i<=n;i++)
		{
			for (j=1;j<=m;j++)
				putchar(c[i][j]);
			puts("");
		}
		exit(0);
	}
	if (x==n+1)
		return;
	if (y==m+1)
	{
		dfs(x+1,1,rx,ry);
		return;
	}
	if (2*rx+2*ry>m*(n-x)+(m-y))
		return;
	dfs(x,y+1,rx,ry);
	if ((c[x][y]=='.') && (c[x][y+1]=='.'))
	{
		c[x][y]='<',c[x][y+1]='>';
		dfs(x,y+1,rx-1,ry);
		c[x][y]='.',c[x][y+1]='.';
	}
	if ((c[x][y]=='.') && (c[x+1][y]=='.'))
	{
		c[x][y]='^',c[x+1][y]='v';
		dfs(x,y+1,rx,ry-1);
		c[x][y]='.',c[x+1][y]='.';
	}
	return;
}

int main()
{
//	freopen("21C.out","w",stdout);
	scanf("%d%d%d%d",&n,&m,&x,&y);
//	for (int ii=1;ii<=100;ii++)
//	for (int jj=1;jj<=100;jj++)
//	for (int xx=ii*jj/2-5;xx<=ii*jj/2+5;xx++) if (xx>=0)
//	for (int yy=ii*jj/2-5;yy<=ii*jj/2+5;yy++) if (yy>=0)
//	{
//	n=ii,m=jj,x=xx,y=yy; printf("%d %d %d %d ",n,m,x,y);
	for (i=1;i<=n;i++)
		for (j=1;j<=m;j++)
			c[i][j]='.';
	if (n&1)
		for (j=1+(m&1);(j+1<=m) && (x);j=j+2)
			c[n][j]='<',c[n][j+1]='>',x--;
	if (m&1)
		for (i=1;(i+1<=n-(n&1)) && (y);i=i+2)
			c[i][m]='^',c[i+1][m]='v',y--;
//	printf("%d %d\n",x,y);
	for (j=m-(m&1);j>0;j=j-2)
		for (i=1;i<=n-(n&1);i=i+2)
			if (x>=2)
			{
				x=x-2;
				c[i][j-1]='<',c[i][j]='>';
				c[i+1][j-1]='<',c[i+1][j]='>';
			}
			else
			if (y>=2)
			{
				y=y-2;
				c[i][j-1]='^',c[i][j]='^';
				c[i+1][j-1]='v',c[i+1][j]='v';
			}
	for (i=n;i>0;i--)
		for (j=1;j<=m;j++)
			if ((c[i][j]=='.') && (c[i-1][j]=='.') && (y))
				y--,c[i-1][j]='^',c[i][j]='v';
	for (i=1;i<=n;i++)
		for (j=1;j<=m;j++)
			if ((c[i][j]=='.') && (c[i][j+1]=='.') && (x))
				x--,c[i][j]='<',c[i][j+1]='>';
	if ((x) || (y))
		puts("NO");
	else
	{
		puts("YES");
		for (i=1;i<=n;i++)
		{
			for (j=1;j<=m;j++)
				putchar(c[i][j]);
			puts("");
		}
	}
//	}
	return 0;
}

Measured memory_bytes: 2304
#include <stdio.h>
#include <string.h>

int main(void) {
	char s[64];
	int t[64] = {0},n,i,j,b,m;
	while(scanf("%s",s) , strcmp("#",s) != 0){
		b = 0;
		for(i = 0;i <= 32;i++){
			switch(s[i]){
				case 'y':
				case 'u':
				case 'i':
				case 'o':
				case 'p':
				case 'h':
				case 'j':
				case 'k':
				case 'l':
				case 'n':
				case 'm':
					t[i] = 1;
					m = 1;
				break;
				case '\0':
					t[i] = m;
					b = 1;
				break;
				default:
					t[i] = 0;
					m = 0;
				break;
			}
			if(b) break;
		}
		n = 0;
		for(j = 0;j <= i;j++){
			if(j != 0){
				if(m != t[j]) n++;
			}
			m = t[j];
		}
		printf("%d\n",n);
	}
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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 ll MRINF = 5000000000000000;

int main() {


    ll N, X;
    cin >> N >> X;
    vector<ll> m(N);
    ll ans=0;
    ll count = 0;
    REP(i, N){
        cin >> m[i];
        ans += m[i];
        count++;
    }
    sort(m.begin(), m.end());
    X -= ans;
    while(X-m[0]>=0){
        ans += m[0];
        X -= m[0];
        count++;
    }
    cout << count << endl;

    

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

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

vector<int> prime;
bool isPrime[1000001];
void primeCalc()
{
	for(int i = 0; i < 1000001; ++i)
	{
		isPrime[i] = true;
	}
	isPrime[0] = isPrime[1] = false;
	for(int i = 2; i < 1000001; ++i)
	{
		if(isPrime[i])
		{
			prime.push_back(i);
			for(int j = 2 * i; j < 1000001; j += i)
			{
				isPrime[j] = false;
			}
		}
	}
}

void solve()
{
	primeCalc();
	int n;
	while(cin >> n, n)
	{
		int count = 0;
		int pos = 0;
		while(prime[pos] <= n / 2)
		{
			if(isPrime[n - prime[pos]])
			{
				++count;
			}
			++pos;
		}
		cout << count << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 2564
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
const int N = 200'000;
const ll INF = 200'000'000'000'001ll;
int n;
ll a[N + 1];
ll mem[N + 2][2][3][3];
bool in_mem[N + 2][2][3][3];
ll opt(int i, bool gap_front, int gap2, int gap3) {
    ll& ans = mem[i][gap_front][gap2][gap3];
    bool& in = in_mem[i][gap_front][gap2][gap3];
    if(not in) {
        if(i >= n) {
            ans = (n / 2) * 2 + gap_front + gap2 + 2 * gap3 == i ? 0 : -INF;
        } else if(i == 0) {
            ans = max({
                a[0] + opt(2, false, 0, 0),
                3 <= n + 1 ? a[0] + opt(3, false, 1, 0) : -INF,
                4 <= n + 1 ? a[0] + opt(4, false, 0, 1) : -INF,
                1 < n ? a[1] + opt(3, true, 0, 0) : -INF,
                2 < n ? a[2] + opt(4, true, 1, 0) : -INF,
                3 < n ? a[3] + opt(5, true, 0, 1) : -INF
            });
        } else {
            ans = max({
                a[i] + opt(i + 2, gap_front, gap2, gap3),
                i + 3 <= n + 1 and gap2 < 2 ? a[i] + opt(i + 3, gap_front, gap2 + 1, gap3) : -INF,
                i + 4 <= n + 1 and gap3 < 2 ? a[i] + opt(i + 4, gap_front, gap2, gap3 + 1) : -INF,
                i + 1 < n and gap2 < 2 ? a[i + 1] + opt(i + 3, gap_front, gap2 + 1, gap3) : -INF,
                i + 2 < n and gap3 < 2 ? a[i + 2] + opt(i + 4, gap_front, gap2, gap3 + 1) : -INF
            });
        }
        in = true;
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    cout << opt(0, 0, 0, 0) << endl;
    return 0;
}


Measured memory_bytes: 57108
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>

using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
template<typename T>void max_self(T &a,T b){a=max(a,b);}
template<typename T>void min_self(T &a,T b){a=min(a,b);}
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=4e5+10,oo=0x3f3f3f3f,MOD=1e9+7;
const long double PI = acos(-1),eps=1.0e-14;

void solve(){
    int a,b,t;
    cin>>a>>b>>t;
    cout<<t/a*b<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


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

int main() {
	string s,t;
	cin >> s;
	t=s;
	
	int i,jud,n;
	jud=0; n=s.size();
	for(i=0; i<n; i++){
		if(s[i]!=s[n-1-i]){
			jud++;
		}
	}

	for(i=0; i<(n-1)/2; i++){
		if(s[i]!=s[(n-1)/2-1-i]){
			jud++;
		}
	}
	for(i=(n+3)/2-1; i<n; i++){
		if(s[i]!=s[n-1-i]){
			jud++;
		}
	}
	if(jud>0){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>

int main(){
	int d, area;
	while (std::cin >> d) {
		area = 0;
		for (int i = 1; i < 600/d; ++i) 
			area += i*i*d*d*d;
		std::cout << area << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        
        while (true) {
            if ((int)Math.sqrt(n) * (int)Math.sqrt(n) == n) {
                System.out.println(n);
                return;
            }
            n--;
        }
    }
}


Measured memory_bytes: 23252
#include<iostream>
using namespace std;
int main()
{
    int n,reminder,count=0;
    cin>>n;
    while (n>0)
    {
        reminder=n%10;
        if(reminder==7)
        {
          count++;
          break;
        }
        n/=10;
    }
    if(count>0)
    cout<<"Yes";
    else
    cout<<"No";
}

Measured memory_bytes: 3596
#include <stdio.h>

int main(){
    
    int cnt=0,num;
    
    while(1){
        cnt++;
        if(scanf("%d",&num)==EOF)break;
	if(num == 0)break;
        printf("Case %d: %-d\n",cnt,num);
    }
    
    
    return 0;
}



Measured memory_bytes: 2036
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int K;
  cin>>K;
  string ans;
  for(int i=0;i<K;++i) {
    ans += "ACL";
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3536
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int  cat = sc.nextInt();
    int catOrDog = sc.nextInt();
    int ans = sc.nextInt();
    if (ans >= cat && ans <= cat + catOrDog) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=(a);i<=(int)(n);++i)
#define lpd(i,a,n) for(int i=(a);i>=(int)(n);--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-8
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 200002;
int n,m;
vvi g(N);

int main(){
    read2i(n,m);
    lp(i,1,m){
        int x,y;
        read2i(x,y);
        g[x].pb(y);
        g[y].pb(x);
    }

    for(int i : g[1]) for(int j : g[i]) if(j == n) return cout <<"POSSIBLE", 0;
    cout <<"IMPOSSIBLE";
}

/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
ios::sync_with_stdio(0);cin.tie(0);
*/


Measured memory_bytes: 12016
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

i64 dp[100100];

int main(){
    i64 H, N;
    cin >> H >> N;
    vector<i64> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];

    rep(i, 100100) dp[i] = 1e9;
    dp[H] = 0;

    for(int h = H; h > 0; h--){
        for(int n = 0; n < N; n++){
            dp[max(0l, h - A[n])] = min(dp[max(0l, h - A[n])], dp[h] + B[n]);
        }
    }

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

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	static int cnt;
	
	static long gcd(long a, long b){
		if(b==0){
			return a;
		}
		else{
			cnt++;
			return gcd(b,a%b);
		}
	}
	
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true){
			long a = stdIn.nextInt();
			long b = stdIn.nextInt();
			if((a|b)==0){
				return;
			}
			cnt = 0;
			if(a<b){
				long tmp = a;
				a = b;
				b = tmp;
			}
			System.out.println(gcd(a,b)+" "+cnt);
		}
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <stdlib.h>

int main(void){
  int i, n, *R, min, max;

  scanf("%d", &n);
  R = (int *)malloc(sizeof(int) * n);
  if(R == NULL){
    printf("?????¢????¢??????¨??????\n");
    return -1;
  }
  for(i = 0; i < n; i++){
    scanf("%d", &R[i]);
  }
  min = R[0];
  max = R[1] - R[0];
  for(i = 1; i < n; i++){
    if(max < R[i] - min){
      max = R[i] - min;
    }
    if(min > R[i]){
      min = R[i];
    }
  }
  printf("%d\n", max);
  free(R);
  return 0;
}

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

#define int long long
#define double long double

using namespace std;

template<class T> string tostr(T x) { stringstream o; o << x; return o.str(); }
template<class T> T sqr(T x) { return x*x; }
template<class T> T mypow(T x, int n) { T r = 1; while (n > 0) { if (n & 1)r = r*x; x = x*x; n >>= 1; }return r; }

int toint(string s) { int v; stringstream i(s); i >> v; return v; }
bool check(int x, int y, int w, int h) { return x >= 0 && y >= 0 && w > x && h > y; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

#define REP(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	REP(i,0,n)
#define PER(i,a,b)	for(int (i) = (a-1);i >= (b);(i)--)
#define per(i,n)	PER(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define dump(val) 	cerr << #val " = " << val << endl;
#define dum(val)	cerr << #val " = " << val;
#define FILL(a,v)	fill(a,a+sizeof(a)/sizeof(*a),v)

const int dx[8] = { +1,+0,-1,+0,+1,+1,-1,-1 };
const int dy[8] = { +0,-1,+0,+1,-1,+1,-1,+1 };
const int mod = 1e9 + 7;
const int INF = 1e9;

typedef tuple<int,int,int,int> F;
int vis[801][801];

signed main() {

	int h, w, k;
	cin >> h >> w >> k;

	int sy, sx;

	vector<string> s(h);
	rep(y, h){
		cin >> s[y];
		rep(x, w){
			if(s[y][x] == 'S'){
				sy = y;sx = x;
			}
		}
	}

		
	auto ok = [&](int m){
		vector<string> t = s;
		clr(vis);

		priority_queue<F, vector<F>, greater<F>> q;
		q.push(F(0, 0, sy, sx));
		rep(i, w)rep(j, h){
			vis[j][i] = INF;
		}
		vis[sy][sx] = 0;

		while(q.size()){
			auto now = q.top();
			q.pop();

			int mv = get<0>(now);
			int us = get<1>(now);
			int y = get<2>(now);
			int x = get<3>(now);

			if(mv > m * k)continue;
			if(mv && mv % k == 0) us += k;
			if(x == 0 || y == 0 || x == w - 1 || y == h - 1){
				return true;
			}

			rep(i, 4){
				int tx = x + dx[i], ty = y + dy[i];
				if(check(tx, ty, w, h) && vis[ty][tx] > mv + 1){
					if(s[ty][tx] == '#'){
						if(us){
							q.push(F(mv + 1, us - 1, ty, tx));
						}else continue;
					}else{
						q.push(F(mv + 1, us, ty, tx));
					}
					vis[ty][tx] = mv + 1;
				}
			}

			bool ok = false;
			rep(i, 4){
				int tx = x + dx[i], ty = y + dy[i];
				if(check(tx, ty, w, h) && vis[ty][tx] > (mv / k + 1) * k + 1){
					ok = true;
				}
			}
			if(ok){
				q.push(F((mv / k + 1) * k, us, y, x));
			}

		}

		return false;
	};

	int l = 0, r = 800 * 800 / k + 10;
	while(r - l > 1) {
		int m = (r + l) / 2.0;
		if (ok(m)) {
			r = m;
		}
		else {
			l = m;
		}
	}

	cout << r << endl;

	return 0;
}


Measured memory_bytes: 8800
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s = input()
    f = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
    for i in range(7):
        if f[i] == s:
            break
    print(7-i)
    return

#Solve
if __name__ == "__main__":
    solve()


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

using namespace std;

const int MOD = 1000000007;

int dp[3010][3010][2];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n, m, i, j, k;
	
	cin>>n>>m;
	
	dp[0][0][1] = 1;
	for (i = 1; i <= n; ++i)
		dp[0][i][0] = 1;
	
	for (i = 0; i < m; ++i) for (j = 0; j <= n; ++j) for (k = 0; k <= 1; ++k)
	{
		if (j > 0)
		{
			dp[i + 1][j][k | (j == 1)] += dp[i][j][k];
			dp[i + 1][j - 1][k | (j == 1)] += dp[i][j][k];
			dp[i + 1][j][k | (j == 1)] %= MOD;
			dp[i + 1][j - 1][k | (j == 1)] %= MOD;
		}
		if (j < n)
		{
			dp[i + 1][j][k] += dp[i][j][k];
			dp[i + 1][j + 1][k] += dp[i][j][k];
			dp[i + 1][j][k] %= MOD;
			dp[i + 1][j + 1][k] %= MOD;
		}
	}
	
	int sol = 0;
	for (i = 0; i <= n; ++i)
		sol = (sol + dp[m][i][1]) % MOD;
	
	cout<<sol<<'\n';
}



Measured memory_bytes: 70784
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

vll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> N;
    string ans = "APPROVED";

    rep(ni,N){
        cin >> ltmp;
        if(ltmp%2==0){
            if(ltmp%3>0 && ltmp%5>0){
                ans = "DENIED";
            }
        }

    }    
    cout << ans << endl;

}

Measured memory_bytes: 256
/*
ID: simpgoo1
TASK: 
LANG: C++14            
*/
// timus 219263UI
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <ctime>
#include <queue>
#include <vector>
#include <iomanip>
#include <cstdlib>
#include <stdio.h>
#include <string.h>
#include <algorithm>
// #include <unordered_map>
 
using namespace std;
 
typedef long long ll;
 
#define y1 needtrainharder
#define F first
#define S second
#define gg exit(0)
#define sz() size()
#define pb push_back
#define mp make_pair
#define skip continue
#define all(x) x.begin(), x.end()
#define boost ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
#define file(s) if(fopen(task".in", "r"))freopen(s".in","r",stdin),freopen(s".out","w",stdout);
#define task "sorting"
 
const int INF = 1e9 + 100;  
const ll INFLL = 1e18 + 100;  
const double EPS = 1e-10;
const int MAXN = 5e5 + 100; 
const int P = 51;
const int mod = 1e9 + 7;

int n;

int a[3][111];

int dp[3][111];

int main(){ 
 
  //boost; srand(time(NULL));
 
  file(task);

  cin >> n;

  for(int i = 1; i <= 2; ++i){
    for(int j = 1; j <= n; ++j){
      cin >> a[i][j];
    }
  }

  dp[1][1] = a[1][1];
  dp[2][1] = a[1][1] + a[2][1];

  for(int i = 1; i <= 2; ++i){
    for(int j = 2; j <= n; ++j){
      dp[i][j] = max({dp[i - 1][j], dp[i][j - 1]}) + a[i][j];
    }
  }

  cout << dp[2][n];
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

int fib[46];

int main()
{
	memset (fib, 0, sizeof (fib ) );
	fib[0] = 1;
	fib[1] = 1;
	for (int i = 2; i < 46; i++ ){
		fib[i] = fib[i-1] + fib[i-2];
	} // end for

	ios_base::sync_with_stdio(0);
	int n; cin >> n;
	printf ("%d\n", fib[n] );
		
	return 0;
}

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

using namespace std;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using D = double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;

#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())
#define rep(i, x)  for(int i = 0; i < (x); i++)
#define rrep(i, x) for(int i = (x - 1); i >= 0; i--)
#define sqrt(x) sqrt(abs(x))
#define y1 y1_1234413
#define j1 j1_235
#define y0 y0_235
#define j0 j0_256
#define fi first
#define se second
#define re return
#define prev PREV
#define next NEXT
#define sz(x) ((int)x.size())

template<typename T> T sqr(T a) { re a * a; }
template<typename T> T gcd(T a, T b) { re b ? gcd(b, a % b) : a; }
template<typename T> T sgn(T a) { re a > 0 ? 1 : (a < 0 ? -1 : 0); }
template<typename T> T abs(T a) { re a > 0 ? a : -a; }

const ll inf = 2e14 + 105;
const ld st = 0.000001;
const ld pi = acos((ld)-1);

const int N = 2e2 + 105;
const int M = 2e5 + 105;

#define FILENAME ""

int n;
int m;
int k;

ll dp[N][M];

int c[N], w[N];

void fdp() {
	for (int i = 0; i <= n; i++) dp[i][0] = inf;
	for (int i = 0; i <= m; i++) dp[0][i] = inf;
	for (int j = 1; j <= m; j++) {
		for (int i = 1; i <= n; i++) {
			dp[i][j] = min (dp[i - 1][j], (j > c[i] ? w[i] + dp[i - 1][j - c[i]] : w[i]));
		}
	}
}

int main()
{
	ios::sync_with_stdio(0);
    cin.tie(NULL);
//	freopen(FILENAME ".in", "r", stdin);
//	freopen(FILENAME ".out", "w", stdout);
	cin >> n >> k;
	m = 0;
	for (int i = 1; i <= n; i++) {
		cin >> w[i] >> c[i];
		m += c[i];
	}
	fdp();
	for (int i = m; i >= 0; i--) {
		if (dp[n][i] <= k) re cout << i, 0;
	}
	cout << 0;
	re 0;
}     







Measured memory_bytes: 157184
H, W = map(int, input().split())
H_lis = [str(input()) for _ in range(H)]

def check_bomb(i,j):
    if i<0 or j<0:
        return 0
    try:
        if H_lis[i][j]==".":
            return 0
        elif H_lis[i][j]=="#":
            return 1
        else:
            return 0
    except:
        return 0

for i in range(H):
    ans = ""
    for j in range(W):
        if check_bomb(i,j)==1:
            ans += "#"
        else:
            ans+=str(check_bomb(i-1,j-1)+check_bomb(i-1,j)+check_bomb(i-1,j+1)+check_bomb(i,j-1)+check_bomb(i,j+1)+check_bomb(i+1,j-1)+check_bomb(i+1,j)+check_bomb(i+1,j+1))
    print(ans)


Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
constexpr int MAX = 1000001;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  vector<int> nums;
  for (int i = 1; i * (i + 1) * (i + 2) / 6 < MAX; i++) {
    nums.push_back(i * (i + 1) * (i + 2) / 6);
  }
  vector<int> dp_all(MAX, 1 << 30), dp_odd(MAX, 1 << 30);
  dp_all[0] = 0;
  dp_odd[0] = 0;
  for (int x : nums) {
    for (int i = 1; i < MAX; i++) {
      if (i - x >= 0) {
        dp_all[i] = min(dp_all[i], dp_all[i - x] + 1);
        if (x % 2) dp_odd[i] = min(dp_odd[i], dp_odd[i - x] + 1);
      }
    }
  }
  int n;
  while (cin >> n) {
    if (n == 0) return 0;
    cout << dp_all[n] << " " << dp_odd[n] << '\n';
  }
  return 0;
}



Measured memory_bytes: 10672
#include<stdio.h>

int main(){
	int i,j,n,a[5000];
	long long max,t;
	while(1){
		scanf("%d",&n);
		if(!n)break;
		for(i=0;i<n;i++)scanf("%ld",&a[i]);
		max=-858993460;
		for(i=0;i<n;i++){
			t=0;
			for(j=i;j<n;j++){
				t+=a[j];
				if(t>max)max=t;
			}
		}
		printf("%ld\n",max);
	}

	return 0;
}

Measured memory_bytes: 616
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int gcd(int a,int b);
int compare(const void* a, const void* b);

int main(void){
    int N,K;
    int i,j,d,A,ret,flag;
    int arrN[100];
    //初期化    
    for(i=0;i<100;i++){
        arrN[i] = 0;
    }
    
    scanf("%d %d",&N,&K);

    for(i = 0 ; i < K ; i++){
        // i番目のお菓子を持っているのはd人でN[J]君が持っている
        scanf("%d",&d);
        for(j = 0; j < d; j++){
            scanf("%d",&A);
            A--;
            arrN[A]++;
        }
    }
    ret = 0;
    for(i=0;i<N;i++){
        if (arrN[i] == 0 ){
            ret++;
        }
    }
    printf("%d\n",ret);
}
int compare(const void* a, const void* b){
    return strcmp(a, b);
}
// 最大公約数
int gcd(int a,int b){
    int c;
    int tmp;
    if(b > a){  //bがaより大きい場合bとaを入れ替える
        c = a;
        a = b;
        b = c;
    }
    tmp = a % b;
    while(tmp!=0){
        a = b;
        b = tmp;
        tmp = a % b;
    }
    return b;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/11/22  Problem: 011_arc_b / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	VL a(N, 0);
	VL sum(N + 1, 0);
	FOR(i, 0, N) {
		cin >> a[i];
	}
	SORT(a);
	FOR(i, 0, N) {
		sum[i + 1] = sum[i] + a[i];
	}
	ans = 1;
	int f = 1;
	FORR(i, N - 2, -1) {
		if (a[i + 1] <= 2 * sum[i + 1] && f)ans++;
		else f = 0;
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1792
import sys
S=input()
T=input()

mydict={}
for i in range(len(S)):
    if( S[i] in mydict):
        if(mydict[S[i]] != T[i]):
            print("No")
            sys.exit(0)
    else:
        mydict[S[i]]=T[i]

mydict={}
for i in range(len(T)):
    if( T[i] in mydict):
        if(mydict[T[i]] != S[i]):
            print("No")
            sys.exit(0)
    else:
        mydict[T[i]]=S[i]
print("Yes")

Measured memory_bytes: 3632
import sys
import numpy as np
import math  # gcdもあるよ
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化

def main():
    n = int(input())
    a = list(map(int,input().split()))
    #ans = 0
    ans_list = [a[i] for i in range(n) if i % 2 == 0]
    ans = [ans_list[i] for i in range(len(ans_list)) if ans_list[i] % 2 == 1]
    #print(ans_list)
    #print(ans)
    print(len(ans))
    return 0

if __name__ == "__main__":
    main()


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

#define int         long long int
#define all(a)      (a).begin(),(a).end()
#define f           first
#define s           second
#define endl        '\n'
#define MOD         1000000007

void solve()
{
    int a, b, c ;
    cin >> a >> b >> c ;
    int sum = (a + b + c)/3;
    if(a == b and b != c)
    {
        cout << "Yes" << endl ;
    }
    else  if(a == c and b != c)
    {
        cout << "Yes" << endl ;
    }
    else if(a != b and b == c)
    {
        cout << "Yes" << endl ;
    }
    else
        cout << "No" << endl ;
}

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

    int t = 1 ;
    //cin >> t ;
    while(t--)
    {
        solve() ;
    }
    return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N,M;
    cin >> N;
    map<string, int> S;
    rep(i,N) {
      string s;
      cin >> s;
      S[s]++;
    }
    cin >> M;
    rep(i,M) {
      string s;
      cin >> s;
      S[s]--;
    }
    int res = 0;
    for (auto x : S) {
//      cout << x.first << " " << x.second << endl;
      res = max(res, x.second);
    }
    cout << res << endl;
}


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

string S, T;

bool val(string sub){
	for(int i = 0; i < sub.length(); i++)
		if(!(sub[i] == '?' || sub[i] == T[i])) return false;
	return true;
}

int main(){
	bool fin = false;
	cin >> S >> T;
	for(int i = S.length() - T.length(); i >= 0; i--){
		string sub = S.substr(i, T.length());
		if(val(sub)){
			fin = true;
			for(int j = 0; j < sub.length(); j++) S[j + i] = T[j];
			for(int j = 0; j < S.length(); j++)
				if(S[j] == '?') S[j] = 'a'; 
		}
	}
	if(fin) cout << S << endl;
	else cout << "UNRESTORABLE\n";
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int m[100000];
int s[100000];
int w[100000];
pair<int,int>lz[100001];
int main(){
	int a,b,c,d;
	while(scanf("%d%d%d%d",&a,&b,&c,&d),a){
		int g=b;
	//	printf("%d %d %d %d\n",a,b,c,d);
		for(int i=0;i<a;i++){
			m[i]=(g/7)%10;
			if(g%2==0){g=(g/2);}
			else {g=(g/2)^c;}
		}
	//	printf("%d ",d);
	//	if(d==5){
	//		for(int i=0;i<a;i++){
	//			printf("%d ",m[i]);
	//		}
	//	}
		if(d==2){
			int ret=0;
			int now=0;
			for(int i=a-1;i>=0;i--){
				//if(m[i]==0)ret-=now;
				if(m[i]%2==0)now++;
				if(m[i])ret+=now;
			}
			printf("%d\n",ret);
			//continue;
		}
		else if(d==5){
			int ret=0;
			int now=0;
			for(int i=a-1;i>=0;i--){
				if(m[i]%5==0)now++;
				if(m[i])ret+=now;
			}
			printf("%d\n",ret);
			//continue;
		}else{
			int p=1;
			int v=0;
			for(int i=a-1;i>=0;i--){
				v=(v+p*m[i])%d;
				s[i]=v;
				p=p*10%d;
				lz[i]=make_pair(s[i],i);
				//if(d==3)printf("%d,%d\n",m[i],s[i]);
			}
			lz[a]=make_pair(11,1);
			std::sort(lz,lz+a+1);
			for(int i=0;i<a;i++)w[i]=s[i];
			std::sort(s,s+a);
			long long ret=0;
			long long now=1;
			int ss=0;
			int t=a;
			for(int i=0;i<a;i++){
				if(!m[i]){
					//t=min(t,i);
					if(w[i]==0)ret--;
					ret-=upper_bound(lz,lz+a+1,make_pair(w[i],199999999))-lower_bound(lz,lz+a+1,make_pair(w[i],i+1));
				}
			}
			//printf("%d\n",t);
			for(int i=0;i<a;i++){
				if(ss==s[i])now++;
				else{
					ret+=now*(now-1)/2;
					now=1;
					ss=s[i];
				}
			}
			ret+=now*(now-1)/2;
			printf("%lld\n",ret);
		}
	}
}

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

#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
#define int long long

signed main(){
	
	int l , r;
	cin>>l>>r;
	const int mod = 2019;
	
	if(r-l >= mod){

		cout<<0<<endl;
		return 0;
	}
	int ans = INT_MAX;
	for(int i = l ; i <= r ; ++i){

		for(int j = i+1 ; j <= r ; ++j)
			ans = min(ans , (i*j)%mod);
	}

	cout<<ans<<endl;
  
}

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

#if 0
所用時間: 1h

感想: 変数が多く飲み込むのにかなり時間がかかった。紙で手を動かしてみてようやく仕組みを理解できた。

#endif

int N, W, v[101], w[101], Val[101][100001], ans = 0;//Val[y=i][x=c]

int solve(){

  for(int i = 0; i <= N; ++i){
    for(int c = 0; c <= W; ++c){
      if((i == 0) || (c == 0)) Val[i][c] = 0;
      else if(c - w[i] < 0) Val[i][c] = Val[i-1][c];
      else Val[i][c] = max(Val[i-1][c], Val[i-1][c-w[i]]+v[i]);
    }
  }

  return ans = Val[N][W];

}

int main(){
  cin >> N >> W;
  for(int i = 1; i <= N; ++i){
    cin >> v[i] >> w[i];
    //printf("v[%d]: %d, w[%d]: %d\n",i, v[i], i, w[i]);
  }
  cout << solve() << endl;
}



Measured memory_bytes: 7412
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <iomanip>
using namespace std;
#define Would
#define you
const int INF = 999999999;
const int MOD = 1e9 + 7;

int main() {
	while (1) {
		int n, k[1005], ans = INF;
		cin >> n;
		if (n == 0) { break; }
		for (int i = 0; i < n; ++i) {
			cin >> k[i];
		}
		sort(k, k + n);
		for (int i = 1; i < n; ++i) {
			ans = min(ans, abs(k[i] - k[i - 1]));
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3092
if __name__ == '__main__':

    n = int(input())
    x = [int(i) for i in input().split()]

    result = 900000
    for p in range(min(x), max(x) + 1):        
        s = sum([(i - p)** 2 for i in x])
        if result > s:
            result = s
    print(result)
    

Measured memory_bytes: 3060
import itertools
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
cnt = 0
for v in itertools.permutations(list(range(1,n+1))):
    cnt += 1
    if p == v: a = cnt
    if q == v: b = cnt
print(abs(a-b))

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;

const int INF=10000000;

int field[101][101];
int costs;
int s,g1,g2;
int n,m;
int f,t,c;

void root(){
	int a,b;
	field[f][t]=min(field[f][t],c);
	for(b=1;b<=n;b++){
		for(a=1;a<=n;a++){
			field[a][b]=min(field[a][b],field[a][f]+field[f][t]+field[t][b]);
		}
	}
	for(a=1;a<=n;a++){
		costs=min(costs,field[s][a]+field[a][g1]+field[a][g2]);
	}
}

int main(void){
	int a,b;
	while(1){
		for(b=0;b<=100;b++){
			for(a=0;a<=100;a++){
				field[a][b]=INF;
				if(a==b)field[a][b]=0;
			}
		}
		costs=INF;
		cin >> n >> m >> s >> g1 >> g2;
		if(n==0 && m==0 && s==0 && g1==0 && g2==0)break;
		for(a=0;a<m;a++){
			cin >> f >> t >> c;
			root();
		}
		cout << costs << endl;
	}
	return 0;
}

Measured memory_bytes: 908
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>


typedef unsigned long long ULONG;
typedef long long LONG;
using namespace std;

#define PI 3.1415926535897932384626433
#define _DBG_



int main(void) {
	char alpha;
	cin >> alpha;

	if ('a' <= alpha && alpha<= 'z') {
		cout << 'a' << endl;

	}
	else {
		cout << 'A' << endl;
	}




	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lli long long int
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v)  v.begin(),v.end()
#define mod 1000000007
#define vi vector<int>
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
#define pll pair<lli,lli>
#define vvi vector<vector<int>>
#define vvl vector<vector<lli>>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define tk(args...) take(args);
#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
#define umreserve(X) X.reserve(32768); X.max_load_factor(0.25);
void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << "\n"; err(++it, args...);}
void take() {} template<typename T, typename... Args> void take( T & a, Args & ... args ) { cin>>a; take(args...); }
template<class T>
void printvec(vector<T> &a){
	for(T &x:a){
		cout<<x<<" ";
	}
	cout<<endl;
}
template<class T>
void printarr(T a[],lli n){
	for(lli i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};

#define endl "\n"

lli add(lli a, lli b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

lli mul(lli a, lli b) {
	return a * 1ll * b % mod;
}

inline bool setmin(lli &x, lli y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(lli &x, lli y) { return (y > x) ? x = y, 1 : 0; }

lli power_mod(lli a,lli x){if(x==0) return 1;lli y=power_mod(a,x/2);lli ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
lli inv(lli a){return power_mod(a,mod-2);}
lli power(lli a, lli x){ if(x==0) return 1; lli y= power(a,x/2); lli ans=(y*y); if(x%2) ans*=a; return ans;}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s,t;
	cin>>s>>t;
	int n=s.size();
	int m=t.size();
	vector<vector<int>> lcs(n+1,vector<int>(m+1));
	vector<vector<pair<int,int>>> par(n+1,vector<pair<int,int>>(m+1,mp(0,0)));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i-1]==t[j-1]){
				lcs[i][j]=lcs[i-1][j-1]+1;
				par[i][j]=mp(i-1,j-1);
			}
			else{
				lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
				if(lcs[i-1][j]>=lcs[i][j-1]){
					par[i][j]=mp(i-1,j);
				}
				else{
					par[i][j]=mp(i,j-1);
				}
			}
		}
	}
	int x=n,y=m;
	vector<char> ans;
	while(x!=0||y!=0){
		if(s[x-1]==t[y-1]){
			ans.pb(s[x-1]);
		}
		pair<int,int> xx=par[x][y];
		x=xx.first,y=xx.second;
	}
	for(int i=SZ(ans)-1;i>=0;i--)cout<<ans[i];
	cout<<endl;
}

Measured memory_bytes: 106112
n,x = map(int,input().split())
lst = sorted([x] + list(map(int,input().split())))

def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

for i in range(n):
    if i==0:
        ans = lst[i+1] - lst[i]
    else:
        ans = gcd(ans,(lst[i+1]-lst[i]))
print(ans)

Measured memory_bytes: 14252
import sys
input=sys.stdin.readline
from _collections import deque
n,m=map(int,input().split())
edg=[[] for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    edg[a].append(b)
    edg[b].append(a)
dep=[-1]*(n+1)
dep[1]=0
data=deque([1])
while len(data)>0:
    p=data.popleft()
    for i in edg[p]:
        if dep[i]==-1:
            dep[i]=dep[p]+1
            data.append(i)
print("POSSIBLE" if dep[n]==2 else "IMPOSSIBLE")


Measured memory_bytes: 107280
#include <bits/stdc++.h>
using namespace std;
#define ll long long int

void printprecise(double l,ll precision)
{
    std::cout << std::fixed;
    std::cout << std::setprecision(precision);
    std::cout << l;
}

int main() {
  ll n;
  cin >> n;
  double ar[n+1];
  for(ll x = 1; x <= n; x++) {
  	cin >> ar[x];
  }
  double dp[n+1][n+1];
  for(ll x = 0; x <= n; x++) {
  	dp[x][0] = 0.0;
    dp[0][x] = 1.0;
  }
  for(ll x = 1; x <= n; x++) {
    for(ll y = 1; y <= n; y++) {
      dp[x][y] = (1-ar[y])*dp[x][y-1] + ar[y] * dp[x-1][y-1];
    }
  }
  printprecise(dp[(n+1)/2][n], 10);
}

Measured memory_bytes: 74032
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int n ,d;
    cin >> n >> d;
    cout << ceil(n*1.0/(d*2+1));

    return 0;
}

Measured memory_bytes: 256