akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <string.h>

#define rep(i,n)    for(ll i=0;i<n;i++)
#define repu(i,k,n) for(ll i=k;i<=n;i++)
#define repd(i,k,n) for(ll i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define endl "\n"
#define INF (ll)ll_MAX

typedef long long ll;
typedef long double ld;
typedef std::pair<ll, ll> pii;
typedef std::vector<ll> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, ll > > vpp;

const ll N = 3*1e5 +5 ;
const long long MOD = 1000000007;
const long long MOD2 = 998244353;
const long long inf = 1e18;

using namespace std;

void solve()
{    
    int r , c , k ;
    cin>>r>>c>>k ;
    vector<vector<ll>>mat(r , vector<ll>(c , 0)) ;
    rep(i , k){
        int ind1 , ind2  ;
        ll val ;
        cin>>ind1>>ind2>>val ;
        mat[ind1-1][ind2-1] = val ;
    }
   
    vector<vector<vector<ll>>>dp(r , vector<vector<ll>>(c , vector<ll>(4 , 0)));
    int used = 0 ;
    rep(i , c){
        if(i==0){
            dp[0][i][0] = 0 ;dp[0][i][1] = mat[0][i] ; dp[0][i][2] = 0 ; dp[0][i][3] = 0 ;
            continue ;
        }
        dp[0][i][0] = dp[0][i-1][0] ;
        dp[0][i][1] = max(mat[0][i]+dp[0][i-1][0] , dp[0][i-1][1]);
        dp[0][i][2] = max(mat[0][i] + dp[0][i-1][1] , dp[0][i-1][2]) ;
        dp[0][i][3] = max(mat[0][i]+ dp[0][i-1][2] , dp[0][i-1][3]) ;
    }
    repu(i , 1 , r-1){
        rep(j , c){
            ll tans = max(max(dp[i-1][j][0] , dp[i-1][j][1]) , max(dp[i-1][j][2] , dp[i-1][j][3]));
            if(j==0){
                dp[i][j][0] = dp[i][j][1] = dp[i][j][2] = dp[i][j][3] = tans ;
                dp[i][j][1] += mat[i][j] ;
                continue ;
            }
            dp[i][j][0] = max(tans , dp[i][j-1][0]) ;
            dp[i][j][1] = max(mat[i][j]+max(tans , dp[i][j-1][0]) , max(dp[i][j-1][1] , tans));
            dp[i][j][2] = max(tans+mat[i][j] , max(dp[i][j-1][1]+mat[i][j] , dp[i][j-1][2]));
            dp[i][j][3] = max(tans+mat[i][j] , max(dp[i][j-1][2]+mat[i][j] , dp[i][j-1][3]));
        }
    }
    // cout<<dp[1][3][2]<<endl;
    cout<<max(max(dp[r-1][c-1][0] , dp[r-1][c-1][1]) , max(dp[r-1][c-1][2] , dp[r-1][c-1][3]));
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    //cout<<"helo";
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    ll t = 1;
    //  cin>>t;

    while(t--)
    {
        solve();    
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

}

Measured memory_bytes: 706024
#include<bits/stdc++.h>
using namespace std; 
using lint  =                           long long int;
using pint  =                           pair<int, int>;
using plint =                           pair<lint, lint>;
#define vli                             vector<lint>
#define pb                              push_back
#define ALL(x)                          begin(x),end(x)
#define inf                             (1LL<63)-1
#define MOD                             1000000007
#define SZ(x)                           ((lint)(x).size())
#define                                 FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define                                 IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define                                 REP(i, n) FOR(i,0,n)
#define                                 IREP(i, n) IFOR(i,0,n)
#define                                 f_ip   ios_base::sync_with_stdio(false); cin.tie(NULL);
#define                                 debug(x) cerr << #x << " " << (x) << endl
struct fast_ios                         { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T>                    istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T>                    bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T>                    bool mmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }


/* -------
         |
    **   |
   -------      
   |
   ---------------------------------------------------------------------------------------------------------------------------------*/

void solve(){  
    int N;
    cin >> N;
    vector<int> d(N);
    cin >> d;
    int ret = 0;
    for(int i = 0;i < N-1;++i){
        for(int j = i + 1;j < N; ++j){
            ret += d[i]*d[j];
        }
    }
    cout << ret << endl;
}

int main(){   
  
 solve();

 return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int *p = new int[5];
  
  for(int i=0;i<5;i++){
    cin>>p[i];
  }
  for(int i =0;i<5;i++){
    if(p[i]==0){
      cout<<i+1;
      break;
    }
  }
  return 0;
}

  


Measured memory_bytes: 3588
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
      m: usize,
      ab: [(usize, usize); m]
   }
   let mut to = vec![vec![false; n]; n];
   for &(a, b) in ab.iter() {
      to[a - 1][b - 1] = true;
      to[b - 1][a - 1] = true;
   }
   let mut ans = 0;
   let mut x: Vec<_> = (1..n).collect();
   loop {
      let mut f = true;
      if !to[0][x[0]] {
         f = false;
      } else {
         for i in 1..n-1 {
            if !to[x[i-1]][x[i]] {
               f = false;
               break;
            }
         }
      }
      if f {
         ans += 1;
      }
      if !x.next_permutation() {
         break;
      }
   }
   println!("{}", ans);
}

pub trait LexicalPermutation {
   fn next_permutation(&mut self) -> bool;
   fn prev_permutation(&mut self) -> bool;
}
impl<T> LexicalPermutation for [T]
where
   T: Ord,
{
   fn next_permutation(&mut self) -> bool {
      if self.len() < 2 {
         return false;
      }
      let mut i = self.len() - 1;
      while i > 0 && self[i - 1] >= self[i] {
         i -= 1;
      }
      if i == 0 {
         return false;
      }
      let mut j = self.len() - 1;
      while j >= i && self[j] <= self[i - 1] {
         j -= 1;
      }
      self.swap(j, i - 1);
      self[i..].reverse();
      true
   }
   fn prev_permutation(&mut self) -> bool {
      if self.len() < 2 {
         return false;
      }
      let mut i = self.len() - 1;
      while i > 0 && self[i - 1] <= self[i] {
         i -= 1;
      }
      if i == 0 {
         return false;
      }
      self[i..].reverse();
      let mut j = self.len() - 1;
      while j >= i && self[j - 1] < self[i - 1] {
         j -= 1;
      }
      self.swap(i - 1, j);
      true
   }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;


int main() {
  int N,x=0,ans=0;
  string s;
  cin>>N>>s;
  for(int i=0;i<N;i++){
    if(s[i]=='I')x++;
    else x--;
    ans=max(ans,x);
  }
  cout<<ans<<"\n";

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c;cin>>a>>b>>c;
  if(c>=a&&b>=c)cout<<"Yes";
  else cout<<"No";
  cout<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <utility>
#include <memory>
#include <valarray>
#include <climits>

using namespace std;

using ll = long long int;

#define loop(i, N) for (int i = 0; i < N; ++i)
#define scanInt(x) int x; scanf("%d", &x); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &x); getchar();
#define scanVecInt(A, N) vector<int> A(N); loop(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); loop(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    vector<char> S;
    loop(i, N){
        S.emplace_back(getchar());
    }
    int front_l = 0;
    int last_r = 0;
    {
        int l = 0;
        int r = 0;
        for (auto& c : S){
            if (c == '('){
                ++l;
            }else{
                ++r;
            }
            if (l < r){
                ++l;
                ++front_l;
            }
        }
        if (r < l){
            last_r = l - r;
        }
    }
    loop(i, front_l)  putchar('(');
    for (auto& c : S) putchar(c);
    loop(i, last_r)   putchar(')');
    puts("");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ii pair <int, int>
#define dl pair <ll, ll>
#define vi vector <int>
#define vl vector <ll>
#define vii vector <ii>
#define REP(a, b) for (int i = a; i < b; i++)
#define REP2(a, b) for (int j = a; j < b; j++)
#define REPS(a, b, c) for (int i = a; i < b; i += c)

using namespace std;

vi p;
vi s;

int findset(int u) {return u == p[u] ? u : p[u] = findset(p[u]);}

void merge(int u, int v) {
    int x = findset(u), y = findset(v);
    if (x == y) return;
    if (s[x] > s[y]) {
        p[y] = x;
        s[x] += s[y];
    } else {
        p[x] = y;
        s[y] += s[x];
    }
}

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

    int n, m;
    cin >> n >> m;
    p.resize(n + 5);
    s.assign(n + 5, 1);
    REP(0, n + 5) p[i] = i;
    int in1, in2;
    REP(0, m) {
        cin >> in1 >> in2;
        merge(in1, in2);
    }
    int mayor = 0;
    REP(0, n + 5) {
        mayor = max(s[findset(i)], mayor);
    }
    cout << mayor << "\n";
	return 0;
}

Measured memory_bytes: 4752
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

const int dx[4] = { 1, 0, -1, 0};
const int dy[4] = { 0, 1, 0, -1};

int h, w, r, c;
bool row[501][501], col[501][501];
bool esc[501][501];

void solve() {
    r--; c--;
    memset(esc, 0, sizeof(esc));
    memset(row, 0, sizeof(row));
    memset(col, 0, sizeof(col));
    rep(i,h*2+1) {
        if (i%2 == 0) rep(j,w) cin >> col[i/2][j];
        else rep(j,w+1) cin >> row[i/2][j];
    }
    queue<pi> que;
    rep(i,h) { que.push(pi(i,0)); que.push(pi(i,w-1)); }
    rep(i,w) { que.push(pi(0,i)); que.push(pi(h-1,i)); }

    while (!que.empty()) {
        pi p = que.front(); que.pop();
        if (esc[p.first][p.second]) continue;
        bool ok1 = false, ok2 = false;
        if (col[p.first][p.second] && (p.first == 0 || esc[p.first-1][p.second])) ok1 = true;
        if (col[p.first+1][p.second] && (p.first == h-1 || esc[p.first+1][p.second])) ok1 = true;
        if (row[p.first][p.second] && (p.second == 0 || esc[p.first][p.second-1])) ok1 = true;
        if (row[p.first][p.second+1] && (p.second == w-1 || esc[p.first][p.second+1])) ok1 = true;
        if (!col[p.first][p.second] && (p.first == 0 || esc[p.first-1][p.second])) ok2 = true;
        if (!col[p.first+1][p.second] && (p.first == h-1 || esc[p.first+1][p.second])) ok2 = true;
        if (!row[p.first][p.second] && (p.second == 0 || esc[p.first][p.second-1])) ok2 = true;
        if (!row[p.first][p.second+1] && (p.second == w-1 || esc[p.first][p.second+1])) ok2 = true;
        if (!ok1 || !ok2) continue;
        esc[p.first][p.second] = true;
        rep(i,4) {
            int tx = p.first+dx[i], ty=p.second+dy[i];
            if (tx < 0 || tx >= h || ty < 0 || ty >= w) continue;
            if (esc[tx][ty]) continue;
            que.push(pi(tx,ty));
        }
    }
    bool ok = false;
    if (!col[r][c] && (r == 0 || esc[r-1][c])) ok = true;
    if (!col[r+1][c] && (r == h-1 || esc[r+1][c])) ok = true;
    if (!row[r][c] && (c == 0 || esc[r][c-1])) ok = true;
    if (!row[r][c+1] && (c == w-1 || esc[r][c+1])) ok = true;

    if (ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

int main() {
#ifndef LOCAL
    ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
    cout.precision(20);
    cerr << fixed;
    cerr.precision(6);
#ifdef LOCAL
    //freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif  
    while (cin >> h >> w >> r >> c) {
        if (h == 0 && w == 0 && r == 0 && c == 0) break;
        solve();
    }
    //cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}



Measured memory_bytes: 3888
N = int(input())
s = input()
def calcnext(a, b, c):
  if b == "W":
    c = "x" if c == "o" else "o"
  n = a if c == "o" else "S" if a == "W" else "W"
  return n
for ab in ["SS", "SW", "WS", "WW"]:
  l = list(ab)
  for i in range(2, N+2):
    n = calcnext(l[i-2], l[i-1], s[(i-1)%N])
    l.append(n)
  #print(l)
  if l[N:N+2] == l[0:2]:
    print("".join(l[:N]))
    exit()
print(-1)


Measured memory_bytes: 4836
/*
 * author :Sadik Hassan
 *
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define PI            (acos(-1.0))
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,a,n)    for(int i=a;i<n;i++)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
#define TSFL(s)       transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSFH(s)       transform(s.begin(),s.end(),s.begin(),::tolower);
typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/

const int N = 2e5+10;
const int INF = (int)1e9+5;

int main()
{
    _SAD()
    int n,m;
    cin>>n>>m;
    vii a(m);
    rep(i,0,m)cin>>a[i];
    ll ans=accumulate(a.begin(),a.end(),0);
    if(ans>n)cout<<-1<<nl;
    else cout<<n-ans<<nl;
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define scan(a,n) for(long int index=0;index<n;index++) cin>>a[index];
#define print(a,n) for(long int index=0;index<n;index++) cout<<a[index]<<" ";cout<<endl;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define vli vector<long long int>
#define vlli vector<pair<long long int,long long int>>
#define vsi vector<string>
#define vci vector<char>
#define all(n) (n.begin(),n.end())


 
int main() {
   #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    fast;
    ll t;
    t=1;
    while(t--){
      ll n;
      cin>>n;
      ll a[n],i;
      scan(a,n);
      ll sum=0;
      for(i=0;i<n;i++){
        sum+=a[i];
        sum%=mod;
      }
      ll ans=0;
      for(i=0;i<n;i++){
        sum-=a[i];
        if(sum<0) sum+=mod;
        ans+=(sum*a[i])%mod;
        ans%=mod;
      }
      cout<<ans%mod<<endl;
      }
return 0;    
 }  

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

int main()
{
	int a,b;

    cin >> a >> b;
    if(b%a==0)
    {
        cout << a+b<<endl;
    }
    else
    {
        cout<<b-a<<endl;
    }
    
	
	
	
	return 0;
}
	

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)

mod = 10 ** 9 + 7

N, *AB = map(int, open(0).read().split())

E = [[] for _ in range(N + 1)]
for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):
    E[a - 1].append((b - 1, i))
    E[b - 1].append((a - 1, i))

X = [0] * N

def dfs(u, p):
    res = 1
    for v, c in E[u]:
        if p != c:
            res += dfs(v, c)
    X[p] = res
    return res

dfs(0, -1)

I = [1] * (N + 1)
inv = pow(2, mod - 2, mod)
for i in range(N):
    I[i + 1] = I[i] * inv % mod

ans = - inv * N - I[N] + 1
for e in range(N - 1):
    ans += (1 - I[X[e]]) * (1 - I[N - X[e]])
    ans %= mod

print(ans)

Measured memory_bytes: 215172
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const int MAX = 1000000000;

int ans, N, K, S;

int main(void) {
    scanf("%d %d %d", &N, &K, &S);
    rep(i, 0, N) {
        if (i > 0) printf(" ");
        
        if (i < K) printf("%d", S);
        else if (S == MAX) printf("%d", S-1);
        else printf("%d", S+1);
        
    }
    printf("\n");

	return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
//#include<chrono>
//#include<time.h>
//#include<windows.h>
using namespace std;
 
//#define int ll
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
//static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
struct edge {int /*from,*/to,cost;};

signed main(){
    int n,a[114];
    cin >> n;
    REP(i,n) scanf("%d",&a[i]);

    sort(a,a+n);
    int al = 0,b = 0;
    int c = 0;
    RREP(i,n){
        if(!(c%2)) al += a[i];
        else b += a[i];
        c++;
    }
    printf("%d\n",al-b);
    return 0;
}



Measured memory_bytes: 256
ABK = list(map(int,input().strip().split()))
A = ABK[0]
B = ABK[1]
K = ABK[2]

tmp = min(A,B)
nums = []
for i in range(tmp,0,-1):
    if A % i == 0 and B % i == 0:
        nums.append(i)
    if len(nums) >= K:
        break

print(nums[K - 1])



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

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

    vector<int> dp(n+1,n);
    dp[0] = 0;
    rep(i,n){
        dp[i+1] = min(dp[i+1], dp[i]+1);

        for(int p:{6,9}){
            for(int j=p; i+j<=n; j*=p) dp[i+j] = min(dp[i+j], dp[i]+1);
        }
    }
    cout << dp[n] << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#ifndef ONLINE_JUDGE
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#else
#define dbg(x)
#endif

#define X first
#define Y second
const int MOD = (int)1e9 + 7;
const int MAXN = 5050;
int memo[MAXN][MAXN];
void add(int &a, int b){
    a += b;
    if (a >= MOD) a -= MOD;
}
int exp(int a, int b){
    if (b == 0) return 1;
    if (b & 1){
        return (ll)a * exp(a, b-1) % MOD;
    }
    int tmp = exp(a, b/2);
    return (ll)tmp * tmp % MOD;
}
int fact[2 * MAXN], invfact[2 * MAXN];
void pre(){
    fact[0] = invfact[0] = 1;
    for (int i = 1; i < 2 * MAXN; i++){
        fact[i] = (ll)fact[i-1] * i % MOD;
        invfact[i] = exp(fact[i], MOD - 2);
    }
}

int cat(int n){
    int res = (ll)fact[2 * n] * invfact[n] % MOD * invfact[n] % MOD;
    res = (ll)res * exp(n + 1, MOD - 2) % MOD;
    return res;
}

int N, M;
int dp(int id, int c){
    int &res = memo[id][c];
    if (res != -1) return res;
    if (id == 0){
        if (c == M) return res = 1;
        return res = 0;
    }
    res = 0;
    add(res, 2 * dp(id - 1, c + 1) % MOD);
    add(res, dp(id - 1, max(0, c - 1)));
    return res;
}
int main(){
    pre();
    std::ios_base::sync_with_stdio(false);
    string str;
    cin >> N >> str;
    M = (int)str.size();
    memset(memo, -1, sizeof memo);

    int res = (ll)dp(N, 0) * exp(exp(2, M), MOD-2) % MOD;
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 100224
n = int(input())
a = [int(input()) for i in range(n)]
sum_a = sum(a)
MOD = 998244353

dp = [[0] * (sum_a + 1) for i in range(n + 1)]
dp[0][0] = 1
for i in range(n):
    for j in range(sum_a + 1):
        # 選ぶとき
        if j - a[i] >= 0:
            dp[i + 1][j] += dp[i][j - a[i]]
        # 選ばないとき
        dp[i + 1][j] += dp[i][j] * 2
        dp[i + 1][j] %= MOD
        
dq = [[0] * (sum_a + 1) for i in range(n + 1)]
dq[0][0] = 1
for i in range(n):
    for j in range(sum_a + 1):
        # 選ぶとき
        if j - a[i] >= 0:
            dq[i + 1][j] += dq[i][j - a[i]]
        # 選ばないとき
        dq[i + 1][j] += dq[i][j]
        dq[i + 1][j] %= MOD

ans = 0
for j in range(sum_a + 1):
    if sum_a <= j * 2:
        ans += dp[-1][j] * 3
        ans %= MOD

if sum_a % 2 == 0:
    ans -= dq[-1][sum_a // 2] * 3

print((3 ** n - ans) % MOD)

Measured memory_bytes: 457096
use std::io::*;

fn main() {
    let mut buf = String::new();
    stdin().read_to_string(&mut buf).unwrap();

    let (k, a, b) = match &buf
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<i64>>()[..]
    {
        &[k, a, b] => (k, a, b),
        _ => panic!(),
    };

    println!("{}", if b / k * k >= a { "OK" } else { "NG" });
}


Measured memory_bytes: 2160
#include<bits/stdc++.h>
#define w while
#define loop(i,l,r) for(int i=l;i<r;i++)
#define ci cin>>
#define co cout<<
#define mm 1000000007
#define ll long long
using namespace std;
ll int helper( vector<vector<ll int>> &dp,vector<ll int> &vec ,int start,int last ){
  if(start>last){
    return 0;}
    if(start==last)
    return vec[start];
    if(last-start==1)
      return max(vec[last],vec[start]);

    if(dp[start][last]!=-1)
    return dp[start][last];

  ll  int a  = vec[start] + min( helper(dp,vec,start+2,last ) , helper(dp,vec,start+1,last-1 ) );
   ll int b= vec[last]+min(helper(dp,vec,start+1,last-1),helper(dp,vec,start,last-2) );
        dp[start][last]=max(a,b);
   return max(a,b);
}
int main()
 {  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll int n;
     cin>>n;
     ll int sum=0;
   vector<ll int>vec(n);
    for(int i=0;i<n;i++){
      cin>>vec[i];
    sum+=vec[i];
  }
  vector<vector<ll int>>dp(n,vector<ll int>(n,-1));
   ll int taro = helper(dp,vec,0,n-1);
   cout<<( taro - sum + taro );
}


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

#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;

ll combi(ll n, ll k) {
    if (n == k || k == 0)
        return 1;
    else {
        return combi(n - 1, k - 1) + combi(n - 1, k);
    }
}

int main(int argc, char *argv[]) {
    ll n;
    cin >> n;

    set<ll> s;
    for (int i = 0; i < n; ++i) {
        ll tmp;
        cin >> tmp;
        s.insert(tmp);
    }

    cout << s.size() << endl;

    return 0;
}


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

int main(){
  int n;
  cin >> n;
  int a[n];
  int count = 0;
  for(int i = 0;i<n;i++){
    cin >> a[i];
    if(a[i]%2 == 1){
      continue;
    }else if(a[i]%3 == 0 || a[i]%5 == 0){
      continue;
    }else{
      count++;
    }
  }
  if(count)
    cout << "DENIED" << endl;
  else
    cout << "APPROVED" << endl;
  
  
}

Measured memory_bytes: 256
S = input()
wait_day = 0

if S == "SUN":
  wait_day = 7
elif S == "MON":
  wait_day = 6
elif S == "TUE":
  wait_day = 5
elif S == "WED":
  wait_day = 4
elif S == "THU":
  wait_day = 3
elif S == "FRI":
  wait_day = 2
elif S == "SAT":
  wait_day = 1

print(wait_day)

Measured memory_bytes: 9016
import java.util.*;

class Main {
	public static void main(String args[]) {
		
		Scanner sc = new Scanner(System.in);
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		
		int x = A + B;
		int y = A - B;
		int z = A * B;
		
		int max = Math.max(x, y);
		max = Math.max(max,z);
		
		System.out.println(max);
	}
}

Measured memory_bytes: 21716
#include<stdio.h>

int fibonacci(int);

int main(){
  int k;
  scanf("%d", &k);
  printf("%d\n", fibonacci(k));
  return 0;
}

int fibonacci(int n){
  int i;
  int F[n];
  F[0] = 1;
  F[1] = 1;
  for(i = 2; i <= n; i++) F[i] = F[i - 2] + F[i - 1];
  return F[n];
}



Measured memory_bytes: 2148
import java.util.Scanner;
public class Main{
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int count = 3;
		if(a == b) {
			count -= 1;
		}
		if(a == c) {
			count -= 1;
		}
		if(b == c) {
			count -= 1;
		}
		if(a == b && b == c) {
			count += 1;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 35856
from collections import deque
from copy import deepcopy
h,w=map(int,input().split())
s=[list(input()) for _ in range(h)]
ans=0
for i in range(h):
    for j in range(w):
        
        count=[[0]*w for _ in range(h)]
        if s[i][j]==".":
            s_copy=deepcopy(s)
            que=deque()
            que.append([i,j])
            s_copy[i][j]="#"
            
            while que:
                
                x,y=tuple(que.popleft())
                dx_dy=[[1,0],[0,1],[-1,0],[0,-1]]
                for k in range(4):
                    nx=x+dx_dy[k][0]
                    ny=y+dx_dy[k][1]
                    if 0<=nx<=h-1 and 0<=ny<=w-1:
                        if s_copy[nx][ny]==".":
                            s_copy[nx][ny]="#"
                            count[nx][ny]=count[x][y]+1
                            que.append([nx,ny])
        
            temp=0
            for l in range(h):
              temp=max(temp,max(count[l]))
            ans=max(temp,ans)
print(ans)
            

Measured memory_bytes: 9592
#include <iostream>
#include <string>
#include <cmath>
#define int long long

using namespace std;

int R, G, B;
int K;

signed main()
{
    cin >> R >> G >> B >> K;

    int need;

    if (G > R)
    {
        need = 0;
    }
    else
    {
        need = ceil(log2((double)R / G) + 0.1);
        // cout << need << endl;
        // cout << log2((double)R / G) << endl;

        G = G * pow(2, need);
        // cout << G << endl;
    }

    if (B > G)
    {
        cout << (need <= K ? "Yes" : "No") << endl;
    }
    else
    {
        int plus = ceil(log2((double)G / B) + 0.1);
        // cout << plus << endl;
        need += plus;
        // cout << need << endl;
        // cout << R << G << B << endl;
        cout << (need <= K ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 3796
#include <iostream>
#define min(a,b) ((a<b)?a:b)
#define max(a,b) ((a>b)?a:b)
#define ll long long int
#define BIG 1e9
using namespace std;

int main() {
	ll dp[200000][3],a[200000][3],N;
	cin>>N;
	for(int i=0; i<N; i++){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	dp[0][0] = a[0][0];
	dp[0][1] = a[0][1];
	dp[0][2] = a[0][2];
	for(int i=1; i<N; i++){
		for(int j=0; j<3; j++){
			int x[2]={(j+1)%3,(j+2)%3};
			dp[i][j] = a[i][j]+max(dp[i-1][x[0]],dp[i-1][x[1]]);
		}
	}
	int ans = max(max(dp[N-1][0],dp[N-1][1]),dp[N-1][2]);
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    set<int> s;

    int ans = 0;
    rep(i, n) {
        int d;
        cin >> d;
        s.insert(d);
    }

    cout << s.size() << endl;
    return 0;
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int t;
  cin >> t;
  while(t--) {
    int n, d;
    cin >> n >> d;
    if(n%2) cout << 127*(n-1)+d << endl;
    else cout << 127*n-d << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin >> n >> m;

  vector<string> a(n);
  rep(i,n) cin >> a[i];
  vector<string> b(m);
  rep(i,m) cin >> b[i];

  rep(j,n-m+1){
    rep(i,n-m+1){
      bool ok = true;
      rep(k,m)rep(l,m){
        if(a[j+k][i+l] != b[k][l]) {
          ok = false;
        }


      }
      if(ok){
        cout << "Yes"<< endl;
        return 0;
      }

    }
  }
  cout << "No" << endl;

  return 0;
    

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;   //author: madmin2619/mintu_agarwal
     
#define nfs() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define endl "\n"
#define pb push_back
#define pf push_front
#define forin(i, n) for(int i=0;i<n;i++)
#define tr(c, it) for(auto it=c.begin();it!=c.end();it++)
#define sz(c) c.size()
#define all(c) c.begin(),c.end()
#define ff first
#define ss second
#define m_p(x, y) make_pair(x, y)
     
const int M = 1e9 + 7;
     
int32_t main(){
    nfs()
    int t, n, i, j, k;
    cin >> n;
    double p;
    double dp[n+1];
    for(i=0;i<=n;i++)
    	dp[i]=0.0;
    dp[0] = 1.0;
    for(int i=1;i<=n;i++){
    	cin >> p;
    	for(j=i;j>=0;j--)
    		dp[j] = ((!j) ? 0.0 : dp[j-1]*p) + (1.0-p)*dp[j];
    }
    double res = 0.0;
    for(i=n;i>(n/2);i--)
    	res += dp[i];
    cout << setprecision(12) << res << '\n';
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-3;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int n, x; ll w[100], v[100];
ll dp[1<<17];
int main() {
	cin >> n>>x;
	rep(i, n)cin >> w[i] >> v[i];
	rep(i, x + 1)dp[i] = -1;
	dp[0] = 0;
	rep(i, n) {
		per(j, x+1) {
			if (dp[j] < 0)continue;
			if (j + w[i] > x)continue;
			dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
		}
	}
	ll ans = 0;
	rep(i, x + 1)ans = max(ans, dp[i]);
	cout << ans << endl;
	//stop
	return 0;
}

Measured memory_bytes: 1152
using System;

namespace AtCoder
{
    internal static class Program
    {
        private static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            int[] AN = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int res = 0 - N;

            for(int i = 0; i < N; i++)
                res += AN[i];

            Console.WriteLine(res);
        }
    }
}

Measured memory_bytes: 11200
#include <iostream>
#include <vector>
using namespace std;
int a[110];
vector<int> b[110],c[110];
int main(){
	int i,j,k,n;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
		for(j=0;j<a[i];j++){
			int x,y;
			cin >> x >> y;
			x--;
			b[i].push_back(x);
			c[i].push_back(y);
		}
	}
	int ans = 0;
	for(i=0;i<(1<<n);i++){
		bool flag = true;
		for(j=0;j<n;j++){
			if(!(i & (1<<j))) continue;
			for(k=0;k<a[j];k++){
				if(c[j][k]==0){
					if(i & (1<<b[j][k])) flag = false;
				}else{
					if(!(i & (1<<b[j][k]))) flag = false;
				}
			}
		}
		if(!flag) continue;
		int cnt = 0;
		j = i;
		while(j){
			cnt += (j&1);
			j /= 2;
		}
		ans = max(ans,cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<ll,ll>
#define endl "\n"
#define MAXN 100005
using namespace std;

ll n,k,x;
vector<ll> v;

void solve()
{
	cin>>n>>k;
	for(ll i=0;i<n;i++)
	{
		cin>>x;
		v.pb(x);
	}
	sort(v.begin(),v.end());
	ll sum=0;
	for(ll i=0;i<k;i++) sum+=v[i];
	cout<<sum<<endl;
}

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

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

vector<int> getpows() {
    int maxa = 2000000000;
    vector<int> ret;
    for(int i = 0; 1LL<<i <= maxa; ++i) ret.push_back(1LL<<i);
    return ret;
}

int32_t main() {

    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    unordered_map<int, int> freq;
    for(int i = 0; i < n; ++i) {
        freq[a[i]]++;
    }
    vector<int> twopows = getpows();
    int ans = 0;
    for(int i = n-1; i >= 0; --i) {
        int ai = a[i];
        if(!freq[ai]) continue;
        for(int p : twopows) {
            if(p < ai) continue;
            int need = p-ai;
            if(need == ai) {
                if(freq[need] > 1) {
                    ++ans;
                    freq[need] -= 2;
                }
            } else {
                if(freq[need]) {
                    ++ans;
                    freq[need]--;
                    freq[ai]--;
                }
            }
        }
    }

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


Measured memory_bytes: 30324
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
#define INF 2000000000
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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
数値型から文字列に変換　to_string(number);これは簡単
文字列から数値型に変換　stoi(number)
文字列からllに変換　stoll(number)*/

//ここから書き始める
int main(){
	ll n; cin >> n;
	vector<ll> b(n-1);
	rep(i,n-1){
		cin >> b[i];
	}

	ll ans = 0;
	ll mb = 0;
	rep(i,n){
		if(i==0||i==n-1){
			if(i==n-1){
				ans+= b[n-2];
			}
			else{
			ans += b[i];
			}
		}
		else{
		mb = min(b[i-1],b[i]);
		ans += mb;
		}
	}
	cout << ans << endl;
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

char maze[50][50];
int  dist[50][50];

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  string s;
  ll k;
  cin>>s>>k;
  
  rep(i,k){
    if(s[i]!='1'){
      cout<<s[i]<<endl;
      return 0;
    }
  }
  cout<<1<<endl;
  
}
  



Measured memory_bytes: 256
#include <iostream>

using namespace std;

bool tst (int n, const string &s, const string &t, int pos) {
  for (int i = 0; i + pos < n; i++) {
    if (s[i + pos] != t[i]) return false;
  }
  return true;
}

int main () {
  int n;
  string s, t;
  cin >> n >> s >> t;

  for (int i = 0; i < n; i++) {
    if (tst(n, s, t, i)) {
      cout << n + i << '\n';
      return 0;
    }
  }
  cout << 2 * n << '\n';
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
const int N = 1e3 + 5;
using namespace std;
char S[N][N];
int f[N][N], dr[4][2] = { {1,0},{-1,0},{0,1},{0,-1} }, que[N * N], s, t;
int main() {
	int h, w, sx, sy, tx, ty; scanf("%d%d%d%d%d%d", &h, &w, &sx, &sy, &tx, &ty);
	for (int i = 0; i < h; i++) {
		scanf("%s", S[i]);
		for (int j = 0; j < w; j++)f[i][j] = S[i][j] == '#';
	}
	f[--sx][--sy] = 1; tx--, ty--;
	que[t++] = sx * N + sy;
	while (s < t) {
		int s1 = s;
		while (s < t) {
			int x = que[s++], y = x % N; x /= N;
			for (int i = 0; i < 4; i++) {
				int x1 = x + dr[i][0], y1 = y + dr[i][1];
				if ((unsigned)x1 >= h || (unsigned)y1 >= w || f[x1][y1])continue;
				f[x1][y1] = f[x][y]; que[t++] = x1 * N + y1;
			}
		}
		while (s1 < s) {
			int x = que[s1++], y = x % N; x /= N;
			for (int i = -2; i < 3; i++) {
				for (int j = -2; j < 3; j++) {
					int x1 = x + i, y1 = y + j;
					if ((unsigned)x1 >= h || (unsigned)y1 >= w || f[x1][y1])continue;
					f[x1][y1] = f[x][y] + 1; que[t++] = x1 * N + y1;
				}
			}
		}
	}
	printf("%d", f[tx][ty] ? f[tx][ty] - 1 : -1);
	return 0;
}

Measured memory_bytes: 10620
#coding:utf-8
#1_10_B 2015.4.14
import math

a,b,C = list(map(int,input().split()))
rad = math.pi * C / 180
S = a * b * math.sin(rad) / 2
c = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(rad))
L = a + b + c
h = S * 2 / a
print('{:.10f}\n{:.10f}\n{:.10f}'.format(S,L,h))

Measured memory_bytes: 6868
A = input().split(" ")
sum=0
for i in range(len(A)):
    A[i]=int(A[i])
for i in range(len(A)-1):
    if A[len(A)-1] >= A[i]:
        sum+=(len(A)-3-i)*A[i]
        A[len(A)-1]= A[len(A)-1]-A[i]
    elif A[len(A)-1] < A[i]:
        sum+=(len(A)-3-i)*A[len(A)-1]
        A[len(A)-1]=0
print(sum)

Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<string> a;
  string s;
  for(int i=0;i<n;i++){
    cin>>s;
    a.push_back(s);
  }
  map<string,int>m;
  int max=1;
  for(int i=0;i<a.size();i++){
    if(m.find(a[i])==m.end()){
      m.insert(pair<string,int>(a[i],1));
    }
    else{
      m[a[i]]+=1;
      if(m[a[i]]>max){
        max=m[a[i]];
      }
    }
  }
  for(auto it=m.begin();it!=m.end();it++){
    if(it->second==max){
      cout<<it->first<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 26736
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int main() {

	int tree[100000];
	int n, k;
	int dif = INF;
	cin >> n >> k;

	rep(i, 0, n) {
		cin >> tree[i];
	}

	sort(tree, tree + n);

	rep(i, 0, n - k+1) {
		dif = min(dif, tree[i + k-1] - tree[i]);
	}

	cout << dif << endl;

	return 0;
}

Measured memory_bytes: 640
import sys
input=sys.stdin.readline
n=int(input())
a_list=list(map(int,input().split()))
b_list=list(map(int,input().split()))
c_list=list(map(int,input().split()))
pre=100
ans=0
for x in a_list:
    if x==pre+1:
        ans+=c_list[x-2]
    ans+=b_list[x-1]
    pre=x
print(ans)



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

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

  int N; cin >> N;
  int C; cin >> C;
  int K; cin >> K;
  vector<int> T(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> T[i];
  }
  sort(T.begin(), T.end());
  reverse(T.begin(), T.end());

  int ans = 1;
  int tempT = T[0], tempC = 1;
  for (int i = 1; i < N; i++) {
    if (tempT <= T[i] + K && tempC < C) {
      tempC++;
    } else {
      ans++;
      tempT = T[i];
      tempC = 1;
    }
  }

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

Measured memory_bytes: 640
// 参考
// https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r"8
" => r"5",

r"7
" => r"18",

r"54
" => r"114"
}

use std::cmp;
use std::collections::HashSet;

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        s: i32,
    }

    let mut vec: Vec<i32> = Vec::new();
    let mut ans = HashSet::new();
    ans.insert(s);

    let mut prev = s;
    let mut i = 2;

    loop {
        prev = match prev % 2 {
            0 => prev / 2,
            _ => 3 * prev + 1,
        };
        if !ans.contains(&prev) {
            ans.insert(prev);
        } else {
            break;
        }
        i += 1
    }

    i.to_string()
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  string s, t;
  cin >> s >> t;
  cout << t + s;
}

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

using namespace std;

#define ll long long

void solve(){
    ll x;
    cin>>x;
    cout<<(x/500) * 1000 + 5 * ((x-(500*(x/500))) / 5);
}

int main(){
    int t = 1;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>

#define mk(x, y) make_pair(x, y)
#define X first
#define Y second
#define SEC(h, m, s) (h * 3600 + m * 60 + s)

using namespace std;

typedef pair<int, int> pii;

int main( void )
{
	int T[10000];
	pii S[10000];
	int n;
	while(cin >> n, n) {
		fill(T, T+n, 0);
		memset(S, 0, sizeof(S));
		int ans = 0;
		for(int i=0; i < n; ++i) {
			int h1, m1, s1, h2, m2, s2;
			scanf("%d:%d:%d", &h1, &m1, &s1);
			scanf("%d:%d:%d", &h2, &m2, &s2);
			S[i].X = SEC(h1, m1, s1);
			S[i].Y = SEC(h2, m2, s2);
		}
		sort(S, S+n);
		for(int i=0; i < n; ++i) {
			for(int j=0; j < n; ++j) {
				if(T[j] <= S[i].X) {
					T[j] = S[i].Y;
					ans = max(ans, j+1);
					break;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1036