akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//void p(vector<int> A){rep(i,A.size()){cout << A[i] << " ";}cout << "\n";}

int main(){
    int n;
    cin >> n;
    vector<int> x(n),y(n);
    rep(i,n) cin >> x[i] >> y[i];
    auto dist = [&](int i,int j){
        double dx = x[i]-x[j];
        double dy = y[i]-y[j];
        return sqrt(dx*dx+dy*dy);
    };
    vector<int> p(n);
    rep(i,n) p[i] = i;
    double len = 0;
    int cnt = 0;
    do{
        rep(i,n-1){
            len += dist(p[i],p[i+1]);
        }
        cnt++;
    }while(next_permutation(p.begin(),p.end()));
    double ans = len/cnt;
    printf("%.10f\n",ans);
}

Measured memory_bytes: 256
// In The Name Of The Queen
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, q, C[N], R[N];
int main()
{
    scanf("%d%d", &n, &q);
    for (int i = 1; i <= n; i ++)
        C[i] = 1;
    R[1] = 1;
    for (; q; q --)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        C[a] --; C[b] ++;
        if (R[a]) R[b] = 1;
        if (!C[a]) R[a] = 0;
    }
    int tot = 0;
    for (int i = 1; i <= n; i ++)
        tot += R[i];
    return !printf("%d\n", tot);
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
	if (n == 2 || n == 3 || n == 5)
		return true;
	else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
		return false;
	else {
		for (int i = 5; i <= sqrt(n); i += 2){
			if (n%i == 0)
				return false;
		}
		return true;
	}
}

//char arr[107][107];
int main(){
	Lancer();
	string str,num;
	ll n, res = 10000000;
	cin >> str;
	for (int i = 0; i < str.size(); i++){
		num = str.substr(i, 3);
		n = stoi(num);
		n = abs(n - 753);
		res = min(res, n);
	}
	cout << res;
	cout << endl;
	return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
 
 
    int n,sum=0;
    cin>>n;
    int arr[n];
   for(int i=0;i<n-1;i++)
   cin>>arr[i];
   sum+=arr[0];
   for(int i=0;i<n-2;i++)
   sum+=min(arr[i],arr[i+1]);
   sum+=arr[n-2];
   cout<<sum;
 
}

Measured memory_bytes: 256
let () =
  let a = [1; 3; 5; 7; 8; 10; 12] and b = [4; 6; 9; 11] in
  Scanf.scanf "%d %d" (fun x y ->
      if List.exists (( = ) x) a && List.exists (( = ) y) a
      || List.exists (( = ) x) b && List.exists (( = ) y) b
      || x = 2 && y = 2
      then "Yes"
      else "No" )
  |> print_endline

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define pb push_back
#define ppb pop_back
#define vi vector<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define ren(i,n) for(int i=n-1;i>=0;i--)
#define iter(it,v) for(auto it:v)
#define iterp(it,v) for(auto it=v.begin(),it!=v.end();it++)
#define itern(it,v) for(auto it=v.rbegin();it!=v.rend();it++)
#define w(n) while(n--)
#define forp(i,a,b) for(int i=a;i<=b;i++)
#define forn(i,a,b) for(int i=a;i>=b;i--)
#define sc(a) scanf("%d",&a)
#define pf(a) printf("%d",a)
#define init(a,r) for(auto&i:a) i=r;
#define initi(a,r) memset(a,r,sizeof(a))
#define inpt(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define inp(a) for(int&i:a) cin>>i;
#define diss(a) for(int i:a) cout<<i<<' ';
#define disn(a) for(int i:a) cout<<i<<'\n';
#define debug(a) cout<<#a<<": ";for(auto i:a)cout<<i<<" ";cout<<'\n';
#define mpii map<int,int>
#define sii set<int>
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define all(v) v.begin(),v.end()
#define bitc __builtin_popcount
#define fst ios::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define pq priority_queue
#define pii pair<int,int>
#define cs(a) cout<<a<<' '
#define cn(a) cout<<a<<'\n'
#define deb(a,b) cout<<a<<' '<<b<<endl;
#define yy "YES"
#define nn "NO"
#define ff first
#define ss second
typedef long long ll;
const int mod=1e9+7,mod1=998244353;
const int N=2e5+7;
int ar[N];
void a_b_l(){
    int n,m;
    cin>>n>>m;
    int dp[n+1][m+1];
    initi(dp,0);
    forp(i,1,n){
        forp(j,1,m){
            char ch;
            cin>>ch;
            if(ch!='#'){
                dp[i][j]=1;
            }
        }
    }
    forp(i,1,n){
        forp(j,1,m){
            if(i==1&&j==1)  
                continue;
            if(dp[i][j]){
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
            }
        }
    }
    cn(dp[n][m]);
}
signed main(){
    fst;
    int t=1;
    //cin>>t;
    w(t)
    	a_b_l();
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int main() {
    string s;
    cin >> s;

    cout << count(s.begin(), s.end(), '1') << endl;

    return 0;
}


Measured memory_bytes: 256
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of };
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }
// sort(配列変数.begin(), 配列変数.end());
// do {
//   // 順列に対する処理
// } while (next_permutation(配列変数.begin(), 配列変数.end()));
//const double PI = acos(-1); M_PI
// cout << fixed << setprecision(10);
#include <bits/stdc++.h>
#include <regex>
using namespace std;
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() //sort(all(vec)); ,reverse(all(vec));etc
int main(){
    int n,m;
    cin>>n>>m;
    vector<string>vec(n);
    int s;
   string c;
  rep(i,m){
       cin>>s>>c;
       if(n!=1&&s==1&&c=="0"){
           cout<<-1<<endl;
           return 0;
       }
       if(vec.at(s-1)==""){
         vec.at(s-1)=c;
       }
       else if(vec.at(s-1)!=c){
           cout<<-1<<endl;
           return 0;
       }
      
   }
   string ans="";

   if(n!=1&&vec.at(0)==""){
       vec.at(0)="1";
   }
   rep(i,n){
       if(vec.at(i)==""){
           ans+="0";
       }else{
           ans+=vec.at(i);
       }
   }
   //cout<<vec.at(0)<<vec.at(1)<<vec.at(2)<<endl;
   cout<<ans<<endl;

    
}


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

// Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

// Type / Class / Struct Definitions:
using namespace std;

using ll = long long;
using ull = unsigned long long;

// Constants:
const int INF = (1ll << 30) - 1;  // approx 1.07e9
const ll INFLL = 1ll << 60;       // approx 1.15e18
const int MOD = 1e9 + 7;          // 998244353
const long double EPS = 1.0e-14;

// Global Variables:

// Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);

// ================ Main Loop ================
int main() {
    string s, t;
    cin >> s >> t;

    int ans = 0;
    rep(i, s.size()) {
        ans += (s[i] != t[i]);
    }

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

// Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

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


Measured memory_bytes: 3916
#include<bits/stdc++.h>
using namespace std;
bitset<4000000+5> q;
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		q|=(q<<x);
		q.set(x);
	}
	int S=0;
	for(int i=0;i<=4000000;i++){
		S+=q[i];
	}
	S=ceil(1.*S/2);
	int s=0;
	for(int i=0;i<=4000000;i++){
		s+=q[i];
		if(s>=S){
			printf("%d\n",i);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
using vld=vector<long double>;
using ld=long double;
int main(){
  int n,k;
  ld ans=0,ansmax=0;
  cin>>n>>k;
  vld a;
  for(int i=0;i<n;i++){
    ld c;
    cin>>c;
    a.push_back((c+1)/2);
  }for(int i=0;i<k;i++){
    ans+=a[i];
  }if(n!=k){
    for(ld i=k;i<n;i++){
      ans=ans-a[i-k]+a[i];
      ansmax=max(ans,ansmax);
    }
  }else{
    ansmax=ans;
  }
  cout<<fixed<<setprecision(12)<<ansmax<<endl;
}

Measured memory_bytes: 6512
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

// add and min
struct LazySegmentTree{
    int n, width;
    VL dat, lazy;
    const ll INF = 1e18;

    LazySegmentTree(VL v){
        int n = v.size();
        width = 1;
        while (width < n) width *= 2;
        dat.assign(2 * width - 1, INF);
        lazy.assign(2 * width - 1, 0);
        REP(i,n) dat[i + width - 1] = v[i];
        FORR(i,width-2,0) dat[i] = min(dat[2 * i + 1], dat[2 * i + 2]);
    }

    void eval(int k, int l, int r){
        dat[k] += lazy[k];
        if (r - l > 1){
            lazy[2 * k + 1] += lazy[k];
            lazy[2 * k + 2] += lazy[k];
        }
        lazy[k] = 0;
    }

    void add(int a, int b, ll x, int k, int l, int r){
        eval(k, l, r);
        if (r <= a || b <= l) return;
        if (a <= l && r <= b){
            lazy[k] += x;
            eval(k, l, r);
        }else{
            add(a, b, x, 2 * k + 1, l, (l + r) / 2);
            add(a, b, x, 2 * k + 2, (l + r) / 2, r);
            dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }

    // [l, r) += x
    void add(int l, int r, ll x){
        add(l, r, x, 0, 0, width);
    }

    ll query(int a, int b, int k, int l, int r){
        eval(k, l, r);
        if (r <= a || b <= l) return INF;
        if (a <= l && r <= b) return dat[k];
        ll vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        ll vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return min(vl, vr);
    }

    ll query(int l, int r){
        return query(l, r, 0, 0, width);
    }
};

void out(int i, int j, int k, int l, int v){
    printf("%d %d %d %d %d\n", i + 1, j + 1, k + 1, l + 1, v);
}

int main() {
    int n, q;
    cin >> n >> q;
    VL a(n);
    LazySegmentTree seg(a);
    while (q--){
        int type = in();
        if (type == 0){
            int l = in(), r = in() + 1, x = in();
            seg.add(l, r, x);
        }else{
            int l = in(), r = in() + 1;
            printf("%lld\n", seg.query(l, r));
        }
    }

    return 0;
}



Measured memory_bytes: 8468
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	//ios::sync_with_stdio(false);
	ll H,W,N;
	while(cin>>H>>W>>N) {
		VI w(N);
		REP(i, N) cin>>w[i];
		RANGE(i, 1, N) w[i]+=w[i-1];
//		DD(w);
		ll idx=0;
		VVI ans(H, VI(W));
		REP(y, H) REP(x, W) {
			ll X = y%2 ? W-1-x : x;
			ans[y][X] = idx+1;
			if(y*W+x+1 >= w[idx]) idx++;
		}
		REP(y, H) {
			REP(x, W) {
				cout<<ans[y][x];
				if(x<W-1) cout<<" ";
			}
			cout<<endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 512
using System;

class Program
{
    static void Main(){
        int count=int.Parse(Console.ReadLine());
        string[] rin = Console.ReadLine().Replace("  ", " ").Split(' ');
        int[] A=new int[count];
        for(int i=0;i<count;i++){
            A[i]=int.Parse(rin[i]);
        }
        Write(A);
        for(int j=1;j<count;j++){
            int key=A[j];
            int i = j - 1;
            while (i>=0&&A[i] > key)
            {
                A[i + 1] = A[i];
                A[i] = key;
                i--;
            }
            Write(A);
        }
        Console.ReadKey();
    }
    static void Write(int[] ary)
    {
        string output = ary[0].ToString();
        for (int k = 1; k < ary.Length; k++) output += " " + ary[k].ToString();
        Console.WriteLine(output);
    }
}

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

int main(){
  int s;
  cin >> s;
  int count = 1;
  if (s == 2 || s == 1){
    count = 4;
  }
  else{
    while (s != 4){
      count ++;
      if (s % 2 == 0) s /= 2;
      else s = 3 * s + 1;
    }
    count += 3;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
A,B,K=map(int,input().split())

for i in range(int(K/2)):
    if A%2==1:
        A-=1
    A=A/2
    B=B+A
    if B%2==1:
        B-=1
    B=B/2
    A=A+B
if K%2==1:
    if A%2==1:
        A-=1
    A=A/2
    B=B+A
print(int(A),int(B))

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

int main()
{
    ll n;
    string tmp;
    cin >> n;

    unordered_map<string, ll> map;

    for(ll i = 0; i < n; ++i)
    {
        cin >> tmp;
        map[tmp]++;
    }

    cout << map.size() << "\n";
    return 0;
}

Measured memory_bytes: 17784
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int N;
    cin >> N;
    VD a(N);
    REP(i, N) cin >> a[i];
    double avg = 0;
    REP(i, N) {
        avg += a[i];
    }
    avg /= N;
    double dif = LLINF;
    int ans = -1;
    REP(i, N) {
        if (chmin(dif, abs(avg - a[i]))) {
            ans = i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a,b,c;
string s[100005];
char ans[100005];

bool ok;
void dfs(int ind,int a,int b,int c){
  if(a<0 || b<0 || c<0) return;
  if(ind==n){
    puts("Yes");
    for(int i=0; i<n; i++){
      cout<<ans[i]<<endl;
    }
    exit(0);
  }
  else{
    if(s[ind]=="AB"){
      ans[ind]='A';
      dfs(ind+1,a+1,b-1,c);
      ans[ind]='B';
      dfs(ind+1,a-1,b+1,c);
    }
    else if(s[ind]=="AC"){
      ans[ind]='A';
      dfs(ind+1,a+1,b,c-1);
      ans[ind]='C';
      dfs(ind+1,a-1,b,c+1);
    }
    else{
      ans[ind]='B';
      dfs(ind+1,a,b+1,c-1);
      ans[ind]='C';
      dfs(ind+1,a,b-1,c+1);
    }
  }
}

int main(){
  cin>>n>>a>>b>>c;
  for(int i = 0;i<n;i++) cin>>s[i];
  dfs(0,a,b,c);
  puts("No");
  return 0;
}

Measured memory_bytes: 14632
/**
 * @author yuzining
 * @date 2020/08/02 20:10
 */

#ifdef local
#include "D:\vscode\acm\local.hpp"
#else
#include<bits/stdc++.h>
using namespace std;
#define debug(...) do { } while(false)
void Main();
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
  return 0;
}
#endif

void Main() {
  int n; cin >> n;
  string s; cin >> s;
  int w = 0, r = 0;
  for(int i = 0; i < n; i++) {
    if(s[i] == 'W') {
      w++;
    } else {
      r++;
    }
  }
  int ans = 0;
  for(int i = 0; i < r; i++) {
    if(s[i] == 'W') {
      ans++;
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 3772
import java.awt.Point;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        String[][] s = new String[h][w];
        for (int i = 0; i < h; i++) {
            s[i] = sc.next().split("");
        }

        Deque<Point> queue = new ArrayDeque<>();
        queue.add(new Point(0, 0));
        int depth = 1;
        boolean[][] visited = new boolean[h][w];
        visited[0][0] = true;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (".".equals(s[i][j])) {
                    visited[i][j] = true;
                }
            }
        }
        while (!queue.isEmpty()) {
            int size = queue.size();
            if (size >= 2) {
                System.out.println("Impossible");
                return;
            }
            for (int i = 0; i < size; i++) {
                final int[][] DXDY = { { 1, 0 }, { 0, 1 } };
                Point p = queue.poll();
                int posx = p.x;
                int posy = p.y;
                for (int j = 0; j < DXDY.length; j++) {
                    int x = posx + DXDY[j][0];
                    int y = posy + DXDY[j][1];
                    if (x < 0 || x >= s.length || y < 0 || y >= s[0].length || ".".equals(s[x][y])
                        || visited[x][y]) {
                        continue;
                    }
                    visited[x][y] = true;
                    queue.add(new Point(x, y));
                }
            }
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (!visited[i][j]) {
                    System.out.println("Impossible");
                    return;
                }
            }
        }
        System.out.println("Possible");
    }
}


Measured memory_bytes: 22736
n = int(input())
k =  input()
stone = list(k)
w = 0
r = 0
for i in range(n):
    if stone[i] == 'R':
        r += 1
    else:
        w += 1

ans = 0
w_s = 0
r_s = 0
for i in range(n):
    if i <= r-1 and stone[i] ==  'W':
        w_s += 1
    elif i > r-1 and stone[i] == 'R':
        r_s += 1
ans = max(w_s, r_s)
print(ans)


Measured memory_bytes: 10740
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 

vll dp(100100);

ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n;
  	ci(n);
  st s;
  	ci(s);
  if(n>=3200){
    co(s)
  }
  else{
    co("red")
  }
}

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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  long sum = 0;
  for (int bit = 0; bit < 1 << (N - 1); bit++) {
    string tmp = S;
    for (int i = 1, j = 0; i < N; i++) {
      if (bit >> (i - 1) & 1) tmp.insert(i + j, "+"), j++;
    }
    tmp += '+';
    string num;
    for (int i = 0; i < tmp.size(); i++) {
      if (isdigit(tmp.at(i))) num += tmp.at(i);
      else sum += stol(num), num = "";
    }
  }
  cout << sum << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n, k;
  cin >> n >> k;
  vl a(3);
  rep(i, 3) {
    cin >> a[i];
  }
  string t;
  cin >> t;

  auto f = [](char c){
    if (c == 'r') return 0;
    if (c == 's') return 1;
    return 2;
  };

  auto mod = [](ll c){
    if (c < 0) {
      c += 3;
    }
    return c%3;
  };

  ll ans = 0;

  rep(i, k) {
    for (ll j = i; j < n; j += k) {
      ll cnt = 1;
      while (j+k < n && t[j] == t[j+k]) {
        j += k;
        cnt++;
      }

      ans += (cnt+1)/2 * a[mod(f(t[j])-1)];
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

string S;

int main(){
	cin >> S;
	if (S == "Sunny"){
		cout << "Cloudy" << endl;
	}
	else if (S == "Cloudy"){
		cout << "Rainy" << endl;
	}
	else if (S == "Rainy"){
		cout << "Sunny" << endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <math.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const ll mod = 1000000007;
ll n, a, b, c, d, ans;
string s;

map<P, int> mp;

ll pow(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return pow(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = pow(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll div(ll x)
{
	return pow(x, mod - 2);
}

ll gcd(ll x, ll y)
{
	if (y == 0)
	{
		return x;
	}
	else
	{
		return gcd(y, x % y);
	}
}

int main(void)
{
	cin >> s;
	ll cnt = 0;
	bool flag = false;
	for (ll i = 0; i < s.length(); i++)
	{
		if (s[i] == 'A')
		{
			if (flag)
			{
				flag = false;
				cnt = 1;
			}
			else
			{
				cnt++;
			}
		}
		else if (s[i] == 'B')
		{
			if (flag)
			{
				cnt = 0;
			}
			else
			{
				flag = true;
			}
		}
		else
		{
			if (flag)
			{
				ans += cnt;
				flag = false;
			}
			else
			{
				cnt = 0;
			}
		}
	}
	cout << ans << endl;
	int www;
	cin >> www;
}


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

int gcds(int a, int b){
    int c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int main() {
    int a, b; cin >> a >> b;
    if ((a+b) % 2 == 0) cout << (a+b) / 2 << endl;
    else cout << (a+b+1) / 2 << endl;
}

Measured memory_bytes: 3588
import sys
input = sys.stdin.readline


# 解説ACのつもり。場合分けがバヤで完全に無理
def main():
    N = int(input())
    A = []
    for _ in range(N):
        A.append(int(input()))
    A.sort()
    ans = 0
    m = N//2
    if N % 2 == 0:
        for i in range(m - 1):
            ans -= 2 * A[i]
        for i in range(m + 1, N):
            ans += 2 * A[i]
        ans -= A[m-1]
        ans += A[m]
    else:
        for i in range(m - 1):
            ans -= 2 * A[i]
        for i in range(m + 2, N):
            ans += 2 * A[i]
        a1 = ans - 2*A[m-1] + A[m] + A[m+1]
        a2 = ans - A[m-1] - A[m] + 2*A[m+1]
        ans = max(a1, a2)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 7512
def ok(c)
  a=[0]*3
  b=[0]*3
  0.upto(100) do |i|
    a[0] = i
    b[0] = c[0][0] - a[0]
    b[1] = c[0][1] - a[0]
    b[2] = c[0][2] - a[0]
    a[1] = c[1][0] - b[0]
    a[2] = c[2][0] - b[0]
    f=true
    3.times do |i|
      3.times do |j|
        f = false if c[i][j]!=a[i]+b[j]
      end
    end
    return true if f
  end
  false
end
puts ok(3.times.map{gets.split.map &:to_i}) ? :Yes : :No


Measured memory_bytes: 1916
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=1,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  double a1,b1;
  IN2(a1,b1);
  double num = a1*pow(10,(int)(log10(b1)+1))+b1;
  Yes(sqrt(num) == (int)sqrt(num));
}


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

using namespace std;

#define bug(x) cerr << #x << " = " << x << '\n'
#define ll     long long
#define maxn

int main() {
        //freopen(".inp","r",stdin);

        int n;
        cin >> n;
        string s;
        cin >> s;

        int r = 0;
        for(int i = 0; s[i]; ++ i)
            if(s[i] == 'R') r ++;
        int cnt = 0;
        for(int i = 0; i < r; ++ i)
            if(s[i] == 'W') cnt ++;
        cout << cnt;
}



Measured memory_bytes: 3676
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

void A_500_Yen_Coins(void) {

	int K, X;
	cin >> K >> X;
	cout << ((500 * K >= X) ? "Yes" : "No") << flush;
	return;
}

void B_Count_ABC(void) {

	int N;
	string S;
	cin >> N >> S;

	int counter = 0;
	for (int loop = 0; loop < N - 2; loop++) {
		if (S[loop] == 'A' && S[loop + 1] == 'B' && S[loop + 2] == 'C') counter++;
	}
		
	cout << counter << flush;
	return;
}

void C_Count_Order(void) {

	int N;
	cin >> N;
	vector<int> P(N);
	for (int& it : P) cin >> it;
	vector<int> Q(N);
	for (int& it : Q) cin >> it;

	vector<int> sample(N);
	int index = 0;
	int a = 0;
	int b = 0;
	for (int loop = 0; loop < N; loop++) sample[loop] = loop + 1;
	do {
		if (P == sample) a = index;
		if (Q == sample) b = index;
		index++;
	} while (next_permutation(sample.begin(), sample.end()));

	cout << abs(a - b) << flush;
	return;
}

int main(void) {

	//A_500_Yen_Coins();
	//B_Count_ABC();
	C_Count_Order();
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        while(true){
            int n=sc.nextInt();
            if(n==0){
                break;
            }
            for(int i=0;i<n;i++){
                double pm=sc.nextInt();
                double pe=sc.nextInt();
                double pj=sc.nextInt();
                if(pm==100||pe==100||pj==100){
                    System.out.println("A");
                }else if((pm+pe)/2.0>=90){
                    System.out.println("A");
                }else if((pm+pe+pj)/3.0>=80){
                    System.out.println("A");
                }else if((pm+pe+pj)/3.0>=70){
                    System.out.println("B");
                }else if((pm+pe+pj)/3.0>=50&&pm>=80){
                    System.out.println("B");
                }else{
                    System.out.println("C");
                }
            }
        }
    }
}


Measured memory_bytes: 37048
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

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


using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;

//#define int ll


const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n,m,k,col,us[N],p[N],sz[N];
vi g[N],bl[N];
int pr(int a) {
  return (p[a]==a?a:p[a]=pr(p[a]));
}
void unite(int a, int b) {
  a=pr(a);
  b=pr(b);
  if (a!=b) {
    if (sz[a]<sz[b]) swap(a,b);
    sz[a]+=sz[b];
    p[b]=a;
  }
}
main() {
  file("threesum");
  ios;
  cin>>n>>m>>k;
  fo(i,1,n,1) p[i]=i,sz[i]=1;
  fo(i,1,m,1) {
    int u,v;
    cin>>u>>v;
    g[u].eb(v);
    g[v].eb(u);
    unite(u,v);
  }
  fo(i,1,k,1) {
    int u,v;
    cin>>u>>v;
    bl[u].eb(v);
    bl[v].eb(u);
  }
  fo(i,1,n,1) {
    int x=pr(i);
    int ans=sz[x]-1-(int)g[i].size();
    for (int it : bl[i]) if (pr(it)==x) --ans;
    cout<<ans<<' ';
  }
  cerr << "\nTime elapsed: " << (clock() + 0.0) / CLOCKS_PER_SEC;
  return 0;
}
/**

*/


Measured memory_bytes: 17656
#include <cstdio>
#include <functional>
#include <vector>
#include <tuple>
#include <algorithm>
#include <deque>

using namespace std;

using ll = long long;
int n, m;
int digits[9];
int sticks_for_digits[10] = {-1,2,5,5,4,5,6,3,7,6};
bool called[10000];
bool reachable[10000];

struct Node {
  int value;
  Node *next;
};
struct LinkedList {
  Node *root;
  int length;
};
LinkedList new_LinkedList()
{
  LinkedList ret;
  ret.root = 0;
  ret.length = 0;
  return ret;
}
LinkedList cons(int value, LinkedList list)
{
  LinkedList ret;
  ret.root = (Node *)malloc(sizeof (Node));
  ret.root->value = value;
  ret.root->next = list.root;
  ret.length = list.length+1;
  return ret;
}
LinkedList dp[10000] = {0};

bool is_left_ge(LinkedList& left, LinkedList& right)
{
  if (left.length > right.length) return true;
  if (left.length < right.length) return false;
  Node *l = left.root;
  Node *r = right.root;
  while (!((l == 0) && (r == 0))) {
    if (l->value > r->value) return true;
    if (l->value < r->value) return false;
    l = l->next;
    r = r->next;
  }
  return true;
}

void solve(int sticks)
{
  if (called[sticks]) return;
  called[sticks] = true;
  LinkedList cur = new_LinkedList();
  //printf("entering solve(%d)\n", sticks);
  //cur.push_back(0);
  for (int i = 0; i < m; i++) {
    int to_consume = sticks_for_digits[digits[i]];
    if (sticks < to_consume) continue;
    solve(sticks-to_consume);
    /*printf("solve(%d) =", sticks-to_consume);
    Node *ptr = dp[sticks-to_consume];
    while (ptr) {
      printf("%d", ptr->value);
      ptr = ptr->next;
    }
    printf("\n");*/
    if (!reachable[sticks-to_consume]) continue;
    LinkedList newlist = cons(digits[i], dp[sticks-to_consume]);
    if (is_left_ge(newlist, cur)) {
      cur = newlist;
    }
  }
  if (cur.length == 0) {
    int c = 0;
    for (int i = 0; i < m; i++) {
      if (sticks_for_digits[digits[i]] == sticks) {
        c = max(c, digits[i]);
      }
    }
    if (c != 0) {
      cur = cons(c, cur);
    }
  }
  else if (cur.length == 1) {
    for (int i = 0; i < m; i++) {
      if (sticks_for_digits[digits[i]] == sticks) {
        cur.root->value = max(cur.root->value, digits[i]);
      }
    }
  }
  if (cur.length != 0) {
    dp[sticks] = cur;
    reachable[sticks] = true;
  }
}

int main()
{
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &(digits[i]));
    //int sticks = sticks_for_digits[digits[i]];
    //digits_for_sticks[sticks] = max(digits_for_sticks[sticks], digits[i]);
  }
  reachable[0] = true;
  called[0] = true;
  dp[0] = new_LinkedList();
  solve(n);
  Node *ptr = dp[n].root;
  vector<int> ds;
  while (ptr) {
    ds.push_back(ptr->value);
    ptr = ptr->next;
  }
  for (auto d : ds) {
    printf("%d", d);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 3840
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,W; cin >> n >> W;
    ll w[n], v[n];
    rep(i,n) cin >> w[i] >> v[i];

    ll dp[n+1][W+10];
    rep(i,W+10) dp[0][i] = 0;

    REP(i,1,n+1) rep(j, W+1)
    {
        if (j-w[i-1]>=0)
        {
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]]+v[i-1]);
        }
        else
        {
            dp[i][j] = dp[i-1][j];
        }
    }
    ll ans = 0;
    rep(i,W+1)
    {
        ans = max(ans, dp[n][i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 79232
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 998244353;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
string s[1000100];

bool solve() {
    int lo = 0, ro = 0;
    int l = 0, r = 0;
    vector<P> vec_l, vec_r;
    for (int i = 0; i < n; i++) {
        int t = 0, tl = 0;
        for (int j = 0; j < s[i].size(); j++) {
            if (s[i][j] == '(') {
                t++;
            } else if (t > 0) {
                t--;
            } else {
                tl++;
            }
        }
        if (t >= tl) {
            vec_l.push_back(make_pair(tl, t));
        } else {
            vec_r.push_back(make_pair(tl, t));
        }
    }

    sort(ALL(vec_l));
    sort(ALL(vec_r), [](const P& p, const P& q){ return P(p.second, p.first) < P(q.second, q.first); });
    reverse(ALL(vec_r));
    int num = 0;
    for (P p : vec_l) {
        num -= p.first;
        if (num < 0) return false;
        num += p.second;
    }
    for (P p : vec_r) {
        num -= p.first;
        if (num < 0) return false;
        num += p.second;
    }
    return num == 0;
}

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> s[i];
}

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

    input();
    cout << (solve()?"Yes":"No") << endl;
}


Measured memory_bytes: 34296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007

ll a[100001],n,dp[100001],k;

ll frog(ll ind){
   if(ind==n-1)
    return 0;
    if(dp[ind]!=-1)
        return dp[ind];
 ll mi=1e10;
 for(ll i=ind+1;i<min(ind+k+1,n);i++)
    mi=min(mi,abs(a[i]-a[ind])+frog(i));
  return dp[ind]=mi;
}

int main(){
memset(dp,-1,sizeof(dp));
cin>>n>>k;
ll i;
for(i=0;i<n;i++)
    cin>>a[i];
cout<<frog(0)<<endl;
  	return 0;
}


Measured memory_bytes: 9856
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <queue>

using namespace std;

#define ll long long
constexpr ll inf = 1e9+7;

bool dpx[2][20000] = {0};
bool dpy[2][20000] = {0};

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

    bool dir = false;
    bool rowx = false, rowy = false;
    string s;
    cin>>s;
    vector<ll> fs;
    ll f_count = 0;
    for (auto c : s) {
        if (c == 'F') f_count++;
        else {
            fs.push_back(f_count);
            f_count = 0;
        }
    }
    fs.push_back(f_count);
    dpx[0][fs[0]+10000] = dpy[0][10000] = true;
    for (int i = 2; i < fs.size(); i += 2) {
        for (int j = 0; j < 20000; j++) {
            if (j - fs[i] >= 0) dpx[!rowx][j] |= dpx[rowx][j-fs[i]];
            if (j + fs[i] < 20000) dpx[!rowx][j] |= dpx[rowx][j+fs[i]];
        }
        for (int j = 0; j < 20000; j++) dpx[rowx][j] = false;
        rowx = !rowx;
    }
    for (int i = 1; i < fs.size(); i += 2) {
        for (int j = 0; j < 20000; j++) {
            if (j - fs[i] >= 0) dpy[!rowy][j] |= dpy[rowy][j-fs[i]];
            if (j + fs[i] < 20000) dpy[!rowy][j] |= dpy[rowy][j+fs[i]];
        }
        for (int j = 0; j < 20000; j++) dpy[rowy][j] = false;
        rowy = !rowy;
    }


    ll x, y;
    cin>>x>>y;
    if (dpx[rowx][x + 10000] && dpy[rowy][y + 10000]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}

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

int main() {
	int a, b;
	scanf("%d%d", &a, &b);
	
	printf("%s", (a + b) % 3 == 0 || a % 3 == 0 || b % 3 == 0? "Possible" : "Impossible");
	return 0;
}

Measured memory_bytes: 256
import queue
K = int(input())
q = queue.Queue()
for i in range(1,10):
    q.put(i)
for j in range(K-1):
    x = q.get()
    if x%10 != 0:
        q.put(10*x+x%10-1)
    q.put(10*x+x%10)
    if x%10 != 9:
        q.put(10*x+x%10+1)
x = q.get()
print(x)

Measured memory_bytes: 12452
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <map>
#include <numeric>
#include <set>
using namespace std;

#define ll long long
#define ld long double
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// vector 要素の総和算出
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// vector 最大値( return ite )
#define _max_element(v) max_element(v.begin(),v.end())
// vector 最大値が格納されている要素値
#define _max_element_number(v) distance(v.begin(),max_element(v.begin(),v.end()))

//set<uint32_t> member;	// 重複するデータを保持する事はできない member.insert(2) member.insert(2) ⇒ member.count(2)は1
//multiset<uint32_t> v;	// 重複するデータも保持する事はできる   member.insert(2) member.insert(2) ⇒ member.count(2)は2

// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値 ex) 3.30303 ⇒ 4
#define _ceil(x) ceil(x)
// 指定された要素以上の値が現れる最初の位置のイテレータを取得する
#define _lower_bound(v,min) lower_bound(v.begin(), v.end(), min)
// 指定された要素より大きい値が現れる最初の位置のイテレータを取得する
#define _upper_bound(v,min) upper_bound(v.begin(), v.end(), min)

// 順列 n個の数が与えられる
// 0,1,2,...,n-1
// 全ての並べ方を1行ごとに出力する
// ex 0 1 2 / 0 2 1 / 1 0 2 / 1 2 0 / 2 0 1 / 2 1 0
#define _next_permutation(v) do {   \
	for (auto num : v) {            \
		printf("%d ", num);         \
	}                               \
	printf("\n");                   \
} while (next_permutation(v.begin(), v.end()))

// 絶対値
static int32_t _abs(const int32_t x) { return  (x > 0 ? x : -x); }
// 最大公約数
static int gcd(int a, int b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}
	return b ? gcd(b, a % b) : a;
}
// 最小公倍数
static int lcm(int a, int b) { return a * b / gcd(a, b); }
// 多次元 std::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...)); }
// ex) auto dp = make_vec<uint64_t>(SIZE + 1, 2, 2);


// ABC 164 B
// https://atcoder.jp/contests/abc164/tasks/abc164_b
int main()
{
	int32_t a,b,c,d;

	cin >> a >> b >> c >> d;

	uint32_t e = c / b + ((c % b) ? 1 : 0);
	uint32_t f = a / d + ((a % d) ? 1 : 0);

	if (e <= f) {
		printf("Yes\n");
		return 0;
	}

	printf("No\n");
	return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int n;
long long m[222222];
long long sum,ans=1e15;
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>m[i];
        sum+=m[i];
    }
    for(int i=0;i<n-1;i++){
        sum-=m[i]; 
        sum-=m[i]; 
        if(sum < 0)ans=min(ans,-sum);
        else ans=min(ans,sum);
    }
    cout<<ans;
}


Measured memory_bytes: 1792