akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int r, c, k;
    cin >> r >> c >> k;
    vector<vector<int>> m(r + 1, vector<int>(c + 1, 0));
    for (int i = 0; i < k; i++) {
        int x, y, val;
        cin >> x >> y >> val;
        m[x][y] = val;
    }

    vector<vector<long long int>> dp1(c + 2, vector<long long int>(4, 0));
    vector<vector<long long int>> dp2(c + 2, vector<long long int>(4, 0));
    for (int i = 1; i <= r; i++) {
        dp2 = vector<vector<long long int>> (c + 2, vector<long long int>(4, 0));
        for (int j = 1; j <= c; j++) {
            for (int s = 0; s < 4; s++) {
                // state
                int val = dp1[j][s];
                if (s < 3 && i <= r) {
                    dp2[j][0] = max(dp2[j][0], dp1[j][s] + m[i][j]);
                }
                if (i <= r) {
                    dp2[j][s] = max(dp2[j][s], dp1[j][s]);
                }
                if (s < 3 && j <= c) {
                    dp1[j + 1][s + 1] = max(dp1[j + 1][s + 1], dp1[j][s] + m[i][j]);
                }
                if (j <= c) {
                    dp1[j + 1][s] = max(dp1[j + 1][s], dp1[j][s]);
                }
            } 
        }
        if (i != r)
        dp1 = dp2;
    }
    cout << max(*max_element(dp2[c].begin(), dp2[c].end()), *max_element(dp1[c + 1].begin(), dp1[c + 1].end())) << endl;
}


Measured memory_bytes: 39432
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    if(s=="ABC") cout<<"ARC";
    else cout << "ABC";



    return 0;
}

Measured memory_bytes: 3636
#include <iostream>

int main() {
  int A, B, C;
  std::cin >> A >> B >> C;

  for (int i = A; i <= A * B; i += A) {
    if ( i % B == C ) {
      std::cout << "YES" << std::endl;
      return 0;
    }
  }
  std::cout << "NO" << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9+7
typedef long long int ll;
const int maxn = 100;
ll mod = INF;
bool pass[maxn][maxn]={0};
int dp[maxn][maxn];
int h,w;

int main(){
    cin >> h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            char c;cin >> c;
            if(c=='.'){
                pass[i][j]=true;
            }
            dp[i][j]=INF;
        }
    }
    if(pass[0][0])dp[0][0]=0;
    else dp[0][0]=1;

    for(int i=1;i<w;i++){
        if(pass[0][i-1]&&!pass[0][i])dp[0][i]=dp[0][i-1]+1;
        else dp[0][i]=dp[0][i-1];
    }
    for(int i=1;i<h;i++){
        if(pass[i-1][0]&&!pass[i][0])dp[i][0]=dp[i-1][0]+1;
        else dp[i][0]=dp[i-1][0];
    }

    for(int i=1;i<h;i++){
        for(int j=1;j<w;j++){
            if(pass[i-1][j]&&!pass[i][j]){
                dp[i][j]=min(dp[i][j],dp[i-1][j]+1);
            }else{
                dp[i][j]=min(dp[i][j],dp[i-1][j]);
            }
            if(pass[i][j-1]&&!pass[i][j]){
                dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
            }else{
                dp[i][j]=min(dp[i][j],dp[i][j-1]);
            }
        }
    }
    // for(int i=0;i<h;i++){
    //     for(int j=0;j<w;j++){
    //         cout << dp[i][j]<<" ";
    //     }
    //     cout << endl;
    // }
    cout << dp[h-1][w-1]<<endl;
    return 0;
}

Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

struct UF{
    vector<ll> d;
    UF(ll size):d(size,-1){}
    void init(){
        fill(d.begin(),d.end(),-1);
    }
    bool u(ll x,ll y){
        x = r(x); y = r(y);
        if(x != y){
            if(d[y] < d[x]) swap(x,y);
            d[x] += d[y]; d[y] = x;
        }
        return x!=y;
    }
    bool f(ll x,ll y){
        return r(x) == r(y);
    }
    ll r(ll x){
        return d[x] < 0 ? x:d[x] = r(d[x]);
    }
    ll s(ll x){
        return -d[r(x)];
    }
};

ll n,m;
struct edge{
    ll u,v,cost;
    edge(){}
    edge(ll u,ll v,ll cost):u(u),v(v),cost(cost){}
    bool operator < (const edge& e) const{
        return cost < e.cost;
    }    bool operator > (const edge& e) const{
        return cost > e.cost;
    }
};
ll solve(){
    ll res = LINF;
    vector<ll> s(m),t(m),c(m);
    vector<edge> edges(m);
    for(int i = 0; i < m;i++){
        ll s,t,c; cin >> s >> t >> c; s--; t--;
        edges[i] = edge(s,t,c);
    }
    sort(edges.begin(),edges.end());
    UF uf(n);
    vector<int> f(m);
    vector<ll> C;
    for(int i = 0; i < m;i++){
        if(uf.f(edges[i].u,edges[i].v)) continue;
        f[i] = true;
        uf.u(edges[i].u,edges[i].v);
        C.push_back(edges[i].cost);
    }
    sort(C.begin(),C.end());
    res = C[(n-1)/2];
    for(int i = 0; i < m;i++){
        if(edges[i].cost > res) break;
        if(f[i]) continue;
        C.clear();
        uf.init();
        C.push_back(edges[i].cost);
        uf.u(edges[i].u,edges[i].v);
        for(int j = 0; j < m;j++){
            if(i == j) continue;
            if(uf.f(edges[j].u,edges[j].v)) continue;
            uf.u(edges[j].u,edges[j].v);
            C.push_back(edges[j].cost);
        }
        if(uf.s(0) != n) continue;
        sort(C.begin(),C.end());
        res = min(res,C[(n-1)/2]);
    }
    
//    for(auto e:edges){ cout << e.cost << " " ;
//    }cout << endl;
    return res;
}
int main(void){
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> n >> m,n|m){
        cout << solve() << endl;
    }
    return 0;
}



Measured memory_bytes: 3384
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(a) for(int i=0;i<a;i++)
#define nrep(a,b) for(int i=a;i<b;i++)
#define mrep(a) for(int i=a;i>=0;i--)
#define ll long long
using namespace std;

vector<ll> ans_tree;
vector<vector<bool> > dp;
ll n, m;

struct TREE{
	vector<ll> next;
};

vector<TREE> tree;

void solv(ll d,ll v,ll c){
	if (dp[v][d]) return;
	dp[v][d] = true;
	if (!ans_tree[v]) ans_tree[v] = c;
	if (!d) return;
	solv(d - 1, v, c);
	rep(tree[v].next.size()) solv(d-1,tree[v].next[i], c);
}

int main(){
	ll a, b;
	cin >> n >> m;
	ans_tree.resize(n);
	tree.resize(n);
	dp.resize(n, vector<bool>(10));
	rep(m){
		cin >> a >> b;
		tree[a - 1].next.push_back(b - 1);
		tree[b - 1].next.push_back(a - 1);
	}

	ll q; cin >> q;
	vector<ll> v(q), d(q), c(q);
	rep(q) cin >> v[i] >> d[i] >> c[i];
	rep(q) solv(d[q - (i + 1)], v[q - (i + 1)]-1, c[q - (i + 1)]);
	rep(n) cout << ans_tree[i] << endl;
	return 0;
}

Measured memory_bytes: 17012
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
using ll = long long;
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
int main(){
  ll n;
  cin >> n;
  ll a[n];
  rep(i,n){
    cin >> a[i];
  }
  sort(a,a+n);
  bool can;
  if(n%3 != 0){
    if(a[n-1] == 0){
      can = true;
    }else{
      can = false;
    }
  }else{
    can = true;
    ll tmp;
    rep(i,n){
      if(i % (n/3) == 0){
        tmp = a[i];
      }else{
        if(tmp != a[i]){
          can = false;
          break;
        }
      }
    }
    if((a[0] ^ a[n/3] ^ a[n/3*2]) != 0){
      can = false;
    }
  }
  if(can){
    cout << "Yes";
  }else{
    cout << "No";
  }
}


Measured memory_bytes: 1024
#pragma GCC optimize("O3")
        #pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize("unroll-loops")
         
        #include <algorithm>
        #include <bitset>
        #include <cassert>
        #include <chrono>
        #include <cmath>
        #include <complex>
        #include <cstdio>
        #include <cstdlib>
        #include <cstring>
        #include <ctime>
        #include <deque>
        #include <functional>
        #include <iomanip>
        #include <iostream>
        #include <iterator>
        #include <limits>
        #include <climits>
        #include <list>
        #include <map>
        #include <numeric>
        #include <queue>
        #include <random>
        #include <ratio>
        #include <set>
        #include <sstream>
        #include <stack>
        #include <string>
        #include <unordered_map>
        #include <unordered_set>
        #include <utility>
        #include <vector>
        using namespace std;
         
        typedef long long ll;
        typedef long double LD;
        #define int ll
        #define double LD
        #define pb push_back
        #define mp make_pair
        #define REP(i,n) for (int i = 0; i < n; i++)
        #define loop(i,n) for (int i = 0; i < n; i++)
        #define FOR(i,a,b) for (int i = a; i < b; i++)
        #define REPD(i,n) for (int i = n-1; i >= 0; i--)
        #define FORD(i,a,b) for (int i = a; i >= b; i--)
        #define remax(a,b) a = max(a,b)
        #define remin(a,b) a = min(a,b)
        #define mem(a, b) memset(a, b, sizeof a)
        #define append push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define print(x) cout << (x) << endl
        #define PRECISION(x) cout << fixed << setprecision(x)
        #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
         
        const double PI=acos(-1);
        const int MOD = 1000000007;
        const int FMOD = 998244353;
        const double eps = 1e-9;
         
        mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
        const int N=300006;
        int unread[N],d[N];
        signed main()
        {
        	int n;
        	cin>>n;
        	int a[n];
        	loop(i,n)
        	cin>>a[i];
        	map<int,int> mp1,mp2;
        //	sort(a,a+n);
        	loop(i,n)
        	{
        		mp1[a[i]]++;
			}
		
			int ans=0;
			for(auto x:mp1)
			{
				ans+=x.second*(x.second-1)/2;
			}
			loop(i,n)
			{
				cout<<ans-(mp1[a[i]]-1)<<endl;
			}
		}

Measured memory_bytes: 11008
import copy
 
H, W, K = map(int, input().split())
tiles = [list(input()) for _ in range(H)]
count  = 0
 
for num in range(2**(H+W)):
  copied_tiles = copy.deepcopy(tiles)
  for i in range(H+W):
    if num>>i&1:
      if i < H:
        for j in range(W):
          copied_tiles[i][j] = 'R'
      else:
        for j in range(H):
          copied_tiles[j][i-H] = 'R'
  black_c = 0
  for i in range(H):
    for j in range(W):
      if copied_tiles[i][j] == '#':
        black_c += 1
  if black_c == K:
    count += 1
print(count)

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

const double EPS = 1e-8;
const double INF = 1e12;
const double PI = acos(-1);

using Point = complex<double>;
using Polygon = vector<Point>;

inline int sgn(const double &a) { return (a < -EPS ? -1 : (a > EPS ? 1 : 0)); }

inline bool eq(const Point &a, const Point &b) { return abs(a - b) < EPS; }

inline bool operator<(const Point &a, const Point &b) {
    if (sgn(a.real() - b.real()))
        sgn(a.real() - b.real()) < 0;
    return sgn(a.imag() - b.imag());
}

double dot(const Point &a, const Point &b) { return real(conj(a) * b); }

double det(const Point &a, const Point &b) { return imag(conj(a) * b); }

struct Line {
    Point p1, p2;

    Line(Point p1 = Point(), Point p2 = Point()) : p1(p1), p2(p2) {}

    bool operator<(const Line &rhs) const {
        if (eq(p2, rhs.p2))
            return p1 < rhs.p1;
        return p2 < rhs.p2;
    }
    bool operator==(const Line &rhs) const {
        return (eq(p1, rhs.p1) && eq(p2, rhs.p2)) ||
               (eq(p1, rhs.p2) && eq(p2, rhs.p1));
    }
};

enum CCW {
    ONLINE_FRONT = -2,
    CLOCKWISE,
    ON_SEGMENT,
    COUNTER_CLOCKWISE,
    ONLINE_BACK
};

int ccw(Point p0, Point p1, Point p2){
    Point a = p1 - p0;
    Point b = p2 - p0;
    if(sgn(det(a, b)) == 1) return COUNTER_CLOCKWISE;
    if(sgn(det(a, b)) == -1)return CLOCKWISE;
    if(sgn(dot(a, b)) == -1)return ONLINE_BACK;
    if(sgn(norm(b)-norm(a)) == 1)return ONLINE_FRONT;
    return ON_SEGMENT;
}

int main(){
    double x0, y0, x1, y1;
    cin >> x0 >> y0 >> x1 >> y1;
    Point p0 = Point(x0, y0), p1 = Point(x1, y1);
    int q;
    cin >> q;
    for(int i=0;i<q;++i){
        double x2, y2;
        cin >> x2 >> y2;
        switch(ccw(p0, p1, Point(x2,y2))){
            case ONLINE_FRONT:
                cout << "ONLINE_FRONT";
                break;
            case CLOCKWISE:
                cout << "CLOCKWISE";
                break;
            case ON_SEGMENT:
                cout << "ON_SEGMENT";
                break;
            case COUNTER_CLOCKWISE:
                cout << "COUNTER_CLOCKWISE";
                break;
            case ONLINE_BACK:
                cout << "ONLINE_BACK";
                break;
        }
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3300
#include <iostream>
using namespace std;
int main()
{
	int a[20],n,i,j,m;
	int t = 1;
	cin >> n;
	for (i = 0; i < n; ++i) {
		m = 0;
		cin >> a[i];
		if (i > 0) {
			for (j = i; j > 0; --j) {
				if (a[i] < a[j-1]) {
					m = 1;
					break;
				}
			}
			if (m == 1)continue;
			else ++t;
		}
	}
	cout << t << "\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {

		Scanner sc = new Scanner(System.in);
		int sec = sc.nextInt();
		int min, hour;

		min = sec / 60;
		sec = sec % 60;

		hour = min / 60;
		min = min % 60;

		System.out.println(hour + ":" + min + ":" + sec);

	}

}



Measured memory_bytes: 26252
n,q = map(int,input().split( ))
s = 1
while s < n:
    s*=2

A = [(1<<31)-1]*(2*s-1)

def query(a,b,k,l,r):#区間[a,b)についてｋが答える
    if r<=a or b<=l:#はみ出る
        return 2**31-1
    if a<=l and r<=b:#含まれる
        return A[k]
    else:#ノード追うのが大変,##+1,+2
        c1 = query(a,b,2*k+1,l,(l+r)//2)    
        c2 = query(a,b,2*k+2,(l+r)//2,r)
        return min(c1,c2)

for _ in range(q):
    c,x,y = map(int, input().split( ))
    if not c:
        x += (s-1)###-1
        A[x] = y
        while x>0:
            x =(x-1)//2
            A[x] = min(A[x*2+1],A[x*2+2])##+1,+2
        #print(A)
            
    else:
        print(query(x,y+1,0,0,s))
        


Measured memory_bytes: 8692
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;

int main(){
    long long A,B,C;
    cin>>A>>B>>C;
    vector<long long> N;
    N.push_back(A);
    N.push_back(B);
    N.push_back(C);
    sort(N.begin(),N.end());
    long long ans= N[0]*N[1];
    ans=min(ans,N[1]*N[2]);
    ans=min(ans,N[0]*N[2]);
    if(N[0]%2==0 or N[1]%2==0 or N[2]%2==0) cout<<"0"<<endl;
    else cout<<ans<<endl;
    return 0;
};


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>
#include <cmath>
#include <cstdio>

using namespace std;

const double pi=4.0*atan(1.0);

int main(){
  int n;
  while(cin>>n&&n){
    double res=0;
    if(n%3!=0){
      double S=(sqrt(3)+1.0/tan((pi/3)/n))*6;
      S=1.0/S;
      res=6*n*S;
    }
    else{
      double S=(sqrt(3)+1.0/tan(pi/n))*6;
      S=1.0/S;
      res=2*n*S;
    }
    printf("%.10f\n",res);
  }

  return 0;
}

  

Measured memory_bytes: 0
#include<stdio.h>
int main()
{
    int given,hour,minute,second;
    scanf("%d",&given);
    hour=given/3600;
    minute=(given%3600)/60;
    second=given-(hour*3600)-(minute*60);
    printf("%d:%d:%d\n",hour,minute,second);
    return 0;
}



Measured memory_bytes: 2028
import java.util.*;

public class Main {

    private void solve() {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int Z = sc.nextInt();
        int K = sc.nextInt();

        long[] A = new long[X];
        long[] B = new long[Y];
        long[] C = new long[Z];
        for (int i = 0; i < X; i++) {
            A[i] = sc.nextLong();
        }
        for (int i = 0; i < Y; i++) {
            B[i] = sc.nextLong();
        }
        for (int i = 0; i < Z; i++) {
            C[i] = sc.nextLong();
        }

        long[] AB = new long[X*Y];
        int k = 0;
        for (int i = 0; i < X; i++) {
            for (int j = 0; j < Y; j++) {
                AB[k] = A[i] + B[j];
                k++;
            }
        }
        Arrays.sort(AB);
        long[] sortedAB = reverseArray(AB);

        int l = 0;
        long[] ABC = new long[(Math.min(K, sortedAB.length)) * C.length];
        for (int i = 0; i < Math.min(K, sortedAB.length); i++) {
            for (int j = 0; j < Z; j++) {
                ABC[l] = sortedAB[i] + C[j];
                l++;
            }
        }

        Arrays.sort(ABC);
        long[] sortedABC = reverseArray(ABC);
        for (int i = 0; i < K; i++) {
            System.out.println(sortedABC[i]);
        }

    }
    private long [] reverseArray (long[] array) {
        long[] ret = new long[array.length];
        int index = array.length -1;
        for (long elem : array) {
            ret[index] = elem;
            index--;
        }
        return ret;
    }

    // Main
    public static void main(String[] args) {
        //long start = System.currentTimeMillis();
        new Main().solve();
        //long end = System.currentTimeMillis();
        //System.out.println((end - start)  + "ms");
    }

}


Measured memory_bytes: 93240
N = int(input())
A = list(map(int, input().split(" ")))

def print_list(A):
    for a in A[:-1]:
        print ("%d "%a, end="")
    print(A[-1])

def BubbleSort(A, N):
    count = 0
    flag = True
    while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
                count += 1
                flag = True
                
    return A, count

A_sorted, c = BubbleSort(A, N)

print_list(A_sorted)
print(c)

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

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define EACH(begin, end) for(auto itr = (begin); itr != (end); itr++)

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;



ll N = 0;
ll ret = 0;
string s;
ll table[100005][13];

void input() {
  IN(s);
  REP(i, s.size()) {
    REP(j, 13) {
      table[i][j] = 0;
    }
  }
}

void solve() {
  REP(i, s.size()) {
    REP(j, 13) {
      char c = s[i];
      if (i == 0) {
        //一列目
        if (c == '?' && j < 10) {
          table[i][j] += 1;
        } else if (c - '0' == j) {
          table[i][j] += 1;
        }
      } else {
        //二列目以降
        if (c == '?') {
          REP(l, 10) {
            REP(k, 13) {
              if ((k*10+l) % 13 == j) {
                table[i][j] += table[i-1][k];
                table[i][j] %= MOD;
              }
            }
          }
        } else {
          REP(k, 13) {
            if ((k*10+(c-'0')) % 13 == j) {
              table[i][j] += table[i-1][k];
              table[i][j] %= MOD;
            }
          }
        }
      }
    }
  }

  PRINT(table[s.size()-1][5]);
}

int main(void){
  input();
  solve();
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

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

ll dp[20][2];

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

    string N;
    cin >> N;
    int n = N.size();

    fill_n(&dp[0][0], sizeof(dp) / sizeof(ll), -L_INF);
    dp[0][0] = 0;

    for (int i = 0; i < n; i++) {
        int Ni = N[i] - '0';
        for (int smaller = 0; smaller < 2; smaller++) {
            for (int d = 0; d <= (smaller ? 9 : Ni); d++) {
                if (dp[i][smaller] != -L_INF)
                    dp[i + 1][smaller || d < Ni] = max(dp[i + 1][smaller || d < Ni], dp[i][smaller] + d);
            }
        }
    }

    cout << max(dp[n][0], dp[n][1]) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

struct ST {
  int i;
  int y;
  int p;
  int x;
};
bool operator<(const ST& a, const ST& b){
  return a.y < b.y;
}

int main(){
  int N, M;
  cin >> N >> M;

  map<int,vector<ST>> m;
 
  rep(i,M){
    int P, Y;
    cin >> P >> Y;
    m[P].push_back({i,Y,P,0});
  }

  vector<pair<int,int>> ret(M);
  FOR(it,m){
    vector<ST> w = it->second;
    sort(ALLOF(w));
    rep(i,w.size()){
      ret[w[i].i] = make_pair(w[i].p, i+1);
    }
  }
  
  rep(i,ret.size()){
    printf("%06d%06d\n", ret[i].first, ret[i].second);
  }

  return 0;
}


Measured memory_bytes: 13184
import sys

input_data = []
input_pointer = 0

output_data = []

def input_scan():
    global input_data
    input_data = sys.stdin.readlines()
    input_data = [x[:-1] for x in input_data]

def next_line():
    global input_pointer
    global input_data
    if input_pointer < len(input_data):
        input_pointer += 1
        return input_data[input_pointer - 1]
    else:
        return ""

def append_output(string):
    global output_data
    output_data.append(string)

def print_output():
    global output_data
    output_data.append("")
    sys.stdout.write("\n".join(output_data))

# Problem A
# alpha = input()
# if alpha.isupper():
#     print("A")
# else:
#     print("a")

# Problem B
input_scan()
[n, k] = [int(x) for x in next_line().split(" ")]
fruits = sorted([int(x) for x in next_line().split(" ")])
print(sum(fruits[:k]))


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

int main() {
  
  int D, N, ans; cin >> D >> N;
  
  if (N == 100) ans = pow(100, D) * (N + 1);
  
  else ans = pow(100, D) * N;
  
  cout << ans << endl;
  
}

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

int main(){
  string a,b;
  cin>>a;
  cin>>b;
  if(a.size() > b.size()){
    cout<<"GREATER";
    return 0;
  }
  if(a.size() < b.size()){
    cout<<"LESS";
    return 0;
  }
  for(int i=0;i<a.size();i++){
    if(a[i]>b[i]){
      cout<<"GREATER";
      return 0;
    }
    if(a[i]<b[i]){
      cout<<"LESS";
      return 0;
    }
  }
  cout<<"EQUAL";
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N = Scanner.int()
    ans = 0
    for i in range(1, N+1):
        if i % 3 == 0 or i % 5 == 0:
            continue
        ans += i
    print(ans)


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 10728
import sys
input = sys.stdin.readline
s = input().rstrip('\n')
q = int(input())
s1 = []
s2 = []
k = 0
for i in range(q):
    r = input().rstrip("\n")
    if r == "1":
        k = (k + 1) % 2
    else:
        _, f, c = r.split()
        f = int(f) - 1
        if (k + f) % 2:
            s2.append(c)
        else:
            s1.append(c)

s1.reverse()
ans = s1 + list(s) + s2

if k:
    ans.reverse()
print("".join(ans))


Measured memory_bytes: 9272
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
	int n, k, c;
	cin >> n >> k >> c;
	string s;
	cin >> s;
	// L[x]: x回目に働くのはL[x]日以降
	// R[x]: x回目に働くのはR[x]日以前
	int L[200001], R[200001];
	int now = 0;
	for (int i = 1; i <= k; i++) {
		while (s[now] == 'x') now++;
		L[i] = now;
		now += c + 1;
	}
	now = n - 1;
	for (int i = k; i >= 1; i--) {
		while (s[now] == 'x') now--;
		R[i] = now;
		now -= c + 1;
	}
	for (int i = 1; i <= k; i++) {
		if (L[i] == R[i]) cout << L[i] + 1 << endl;
	}
}

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

int main() {
    int N, K; cin >> N >> K;
    vector<int> A(N);
    rep(i, N){
        cin >> A[i];
    }

    int l = 0, r = 1e9;
    while(r-l > 1){
        int m = (l+r) / 2;
        ll now = 0;
        for (int i = 0; i < N; i++){
            now += (A[i]-1) / m;
        }
        if(now <= K){
            r = m;
        } else {
            l = m;
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 4032
# coding: utf-8
import math


def solve(*args: str) -> str:
    s = args[0]
    k = int(args[1])

    if all([s[0] == c for c in s]):
        return str(int(len(s) * k / 2))

    H = s[0]

    ret = 0
    h = 0
    t = 0
    if H == s[-1] and 1 < k:
        h = t = 1
        while H == s[h] and h < len(s):
            h += 1

        while H == s[-t-1] and t < len(s):
            t += 1
        ret += int((h + t) / 2) * (k - 1) + int(h/2) + int(t/2)

    ret += count_adjacent_dup(s[h:len(s)-t]) * k

    return str(ret)


def count_adjacent_dup(s: str) -> int:
    ret = 0
    cnt = 0

    for i in range(len(s) - 1):
        if s[i] == s[i+1]:
            cnt += 1
        else:
            ret += math.ceil(cnt/2)
            cnt = 0

    if 0 < cnt:
        ret += math.ceil(cnt/2)

    return ret


if __name__ == "__main__":
    print(solve(*[input() for _ in range(2)]))


Measured memory_bytes: 39800
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll; 
typedef pair<int, int> P;
  
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<P> p(m);
    rep(i,m) cin >> p[i].first >> p[i].second;
    rep(x,1000) {
        int keta = 1;
        int nx = x/10;
        vector<int> d(1,x%10);
        while (nx) {
            keta++;
            d.push_back(nx%10);
            nx /= 10;
        }
        if (keta != n) continue;
        bool ok = true;
        reverse(d.begin(), d.end());
        rep(i,m) {
            if (d[p[i].first-1] != p[i].second) ok = false;
        }
        if (ok) {
            cout << x << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n;
	while(cin>>n,n){
		string s;
		map<string,int>m;
		getline(cin,s);
		rep(i,n){
			getline(cin,s);
			stringstream ss(s);
			while(ss>>s)m[s]--;
		}
		char c;cin>>c;
		vector<pair<int,string> >in;
		for(map<string,int>::iterator it=m.begin();it!=m.end();it++){
			if(it->first[0]==c)in.pb(pair<int,string>(it->second,it->first));
		}
		sort(all(in));
		if(in.size()==0){
			cout<<"NA"<<endl;
			continue;
		}
		rep(i,in.size()){
			if(i)cout<<" ";
			cout<<in[i].second;
			if(i==4)break;
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1248
def solve(h, w):
    if h == 1 or w == 1:
        return 1
    return (h * w + 1) // 2


def main():
    h, w = map(int, input().split())
    res = solve(h, w)
    print(res)


def test():
    assert solve(4, 5) == 10
    assert solve(7, 3) == 11
    assert solve(1000000000, 1000000000) == 500000000000000000


if __name__ == "__main__":
    test()
    main()


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

int main() {
  string S;
  long K;
  cin >> S >> K;
  int N = S.length();
  long ans = 0;
  int count = 1;
  if(S[0] != S[N-1]){
    for(int i = 0; i < N-1; i++){
      if(S[i] == S[i+1]) count++;
      else{
        if(count != 0){
          ans += count / 2;
          count = 1;
        }//if
      }//if
    }//fori
    if(count != 1) ans+= count / 2;
    ans *= K;
  }else{
    int countFirst = 1, countEnd = 1;
    for(int i = 0; i < N-1; i++){
      if(S[i] == S[i+1]) countFirst++;
      else break;
    }
    if(countFirst == N) ans = N*K / 2;
    else{
      for(int i = N-1; i > 0; i--){
        if(S[i] == S[i-1]) countEnd++;
        else break;
      }
      //cout << "first" << countFirst << "end" << countEnd << endl;
      ans += (countFirst+countEnd) / 2;
      //cout << ans << endl;
      ans *= K-1;
      ans += countFirst / 2;
      ans += countEnd / 2;
      //cout << ans << endl;
      int temp = 0;
      for(int i = countFirst; i < N-countEnd; i++){
        if(S[i] == S[i+1]) count++;
        else{
          if(count != 0){
            temp += count / 2;
            count = 1;
          }//if
        }//if
      }//fori
      ans += temp * K;
    }
  }
  cout << fixed;
  cout << setprecision(20) << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=100005;
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int n,t[max_n];
string s[max_n],x;
char str[max_n];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%s%d",str,t+i);
        s[i]=str;
    }
    scanf("%s",str);x=str;
    int ans=0;
    bool f=false;
    for(int i=1;i<=n;i++){
        if(f)ans+=t[i];
        if(s[i]==x)f=true;
    }
    printf("%d\n",ans);
    return 0;
}

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

int main(){
	string S;
	cin >> S;
	
	int l=S.size();
	int ans=l;
	for(int i=0;i<l-1;i++){
		if(S[i]!=S[i+1])ans=min(ans,max(i+1,l-i-1));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
using System;
class attend{
  public static void Main(){
    int n = int.Parse(Console.ReadLine());
    String[] str = Console.ReadLine().Split(' ');
    int[] rank = new int[n];
    int count=1;
    for(int i=0; i<n; i++){
      rank[int.Parse(str[i])-1] = count;
      count++;
    }
    for(int i=0; i<n-1; i++){
      Console.Write("{0} ",rank[i]);
    }
    Console.WriteLine(rank[n-1]);
  }
}


Measured memory_bytes: 28508
void main() {
  problem();
}

void problem() {
  const A = scan!real;
  const B = scan!real;
  const H = scan!real;
  const M = scan!real;

  void solve() {
    real thetaHour = ((H / 12L) + (M / 720L)) * 2 * PI;
    real thetaMinute = (M / 60L) * 2 * PI;

    real hx = sin(thetaHour) * A;
    real hy = cos(thetaHour) * A;

    real mx = sin(thetaMinute) * B;
    real my = cos(thetaMinute) * B;

    deb([hx, hy, (hx.pow(2) + hy.pow(2)).sqrt]);
    deb([mx, my, (mx.pow(2) + my.pow(2)).sqrt]);

    writefln("%.16f", ((hx - mx).pow(2) + (hy - my).pow(2)).sqrt);
  }

  solve();
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

// -----------------------------------------------


Measured memory_bytes: 2996
n, l = map(int, input().split())
ll = []

for i in range(1, n+1):
    ll.append(i + l - 1)

if ll[0]>= 0:
    ans = sum(ll) - ll[0]
elif ll[n-1]<=0:
    ans = sum(ll) - ll[n-1]
else:
    if n != 3:
        for i in range(1, n-1):
            if abs(ll[i-1]) >  abs(ll[i]) and abs(ll[i]) < abs(ll[i+1]):
                ans = sum(ll) - ll[i]
    else:
        ans = sum(ll) - ll[1]

print(ans)

Measured memory_bytes: 38384
#include <cstdio>
#include <iostream>
#include <complex>
using namespace std;
const int N = 500005;
int n,m,deg[N];
int main(){
	cin >> n >> m;
	for (int i = 1;i <= m;i++)	{
		int a,b;
		cin >> a >>b;
		deg[a]++;	deg[b]++;
	}
	for (int i = 1;i <= n;i++)	cout << deg[i] << endl;
	return 0;
}

Measured memory_bytes: 256
//by (111110101)2
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n;
string a,b;
int main()
{
	cin>>n>>a>>b;
	for(int i=0;i<n;i++)
	{
		cout<<a[i]<<b[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(a, b) printf(a, b);
#define c(s) cout << (s) << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define cyn(c) cout << (c ? "Yes" : "No") << endl;
#define cYN(c) cout << (c ? "YES" : "NO") << endl;
#define pyn(c) printf("%s\n", c ? "Yes" : "No");
#define pYN(c) printf("%s\n", c ? "YES" : "NO");
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> P;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}
ULL mod = 1e9 + 7;

int main() {
    int cnt=0,cnt_max=0;
    string ans="",s,s1=""; cin>>s;
    rep(i,s.size()){
        if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
            cnt++;
        }else{  
            cnt_max=max(cnt_max,cnt);
            cnt=0;
        }
    }
    cnt_max=max(cnt_max,cnt);
    c(cnt_max);
}

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

int main() {
  int N;
  cin >> N;
  int t;
  int min;
  int count = 0;
  for (int i = 0; i < N; i++) {
    cin >> t;
    if (i == 0) {
      min = t;
      count++;
    } else if (min > t) {
      min = t;
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List

main = do
  li <- BS.getLine
  let [n,d] = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  co <- BS.getContents
  let xys = map (unfoldr (BS.readInt . BS.dropWhile isSpace)) $ BS.lines co
  let ans = compute n d xys
  print ans

compute :: Int -> Int -> [[Int]] -> Int
compute n d xys = length [() | [x,y] <- xys, x*x+y*y <= d*d]


Measured memory_bytes: 10336
#include<bits/stdc++.h>
#define ll long long int
#define Y printf("YES\n")
#define N printf("NO\n")
#define pb push_back
#define tp make_tuple
#define srt(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define pr(a) printf("%lld\n",a)
#define r0 return 0
#define pi acos(-1)
using namespace std;

int main()
{
    ll n,m,i,j,k,x,y,z,t;

     //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    string s;

    cin>>s;

    k=0;

    x=s.size();

    for(i=0;i<x;i++)k+=s[i]-'0';

    if(k%9==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=998244353;

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

template<class T>
class RMQ{
	int n,seg;
	P init;
	vector<T> dat;
public:
	RMQ(int siz,P def) : n(siz),init(def),seg(1){
		while(seg < n) seg *= 2;
		dat.resize(seg * 2 - 1);
		for(int i = 0;i < seg;i++) dat[i + seg - 1] = T(init,i);
		for(int i = seg - 2;i >= 0;i--) dat[i] = min(dat[i * 2 + 1],dat[i * 2 + 2]);
	}
	void update(int i,P x){
		dat[i + seg - 1] = T(x,i);
		i += seg - 1;
		while(i){
			i = (i - 1) / 2;
			dat[i] = min(dat[i * 2 + 1],dat[i * 2 + 2]); //do
		}
	}
	T get(int a = 0,int b = -1,int k = 0,int l = 0,int r = -1){
		if(b == -1) b = seg;
		if(r == -1) r = seg;
		if(b <= l || r <= a) return T(init,seg);
		if(a <= l && r <= b) return dat[k];
		return min(get(a,b,k * 2 + 1,l,(l + r) / 2),get(a,b,k * 2 + 2,(l + r) / 2,r)); //do
	}
};

using PP = pair<P,int>;

signed main(){
	vector<P> vec;
	int n,a[100010],b[100010];
	cin >> n;
	for(int i = 0;i < n;i++) cin >> a[i];
	for(int i = 0;i < n;i++) cin >> b[i];
	for(int i = 0;i < n;i++){
		vec.emplace_back(a[i],b[i]);
	}
	sort(all(vec),[](const P p1,const P p2){
		return p1.second < p2.second;
	});
	for(int i = 0;i < n;i++){
		a[i] = vec[i].first;
		b[i] = vec[i].second;
	}
	RMQ<PP> rmq(n + 5,P(INF,-1));
	for(int i = 0;i < n;i++) rmq.update(i,P(a[i],i));
	vector<P> veca;
	for(int i = 0;i < n;i++){
		veca.emplace_back(a[i],i);
	}
	sort(all(veca));
	for(int i = 0;i < n;i++){
		if(veca[i].first > b[i]){
			No();
			return 0;
		}
	}
	int nowIndex[100010];
	for(int i = 0;i < n;i++){
		nowIndex[i] = i;
	}
	int ans = 0;
	for(int i = n - 1;i >= 0;i--){
		int ind = lower_bound(b,b + n,veca[i].first) - b;
		if(ind <= nowIndex[veca[i].second]) continue;
		PP mi = rmq.get(ind,n);
		rmq.update(nowIndex[veca[i].second],mi.first);
		rmq.update(mi.second,veca[i]);
		swap(nowIndex[veca[i].second],nowIndex[mi.first.second]);
		ans++;
	}
	if(ans <= n - 2) Yes();
	else No();
}

Measured memory_bytes: 13296
battle_num = gets.chop.to_i
t_score = 0
h_score = 0
battle_num.times do
  t_card, h_card = gets.chop.split(' ')
  if t_card > h_card
    t_score += 3
  elsif t_card < h_card
    h_score += 3
  else
    t_score += 1
    h_score += 1
  end
end
printf("%d %d\n",t_score, h_score)



Measured memory_bytes: 6880
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,mod=1000000007;
const long long llinf=9223372036854775807ll;
int n,h[N],minh,minid;
void kill(int he,int id)
{
	for(int i=1;i<=n;i++)
	{
		if(h[i]>=he&&i!=id)
		{
			h[i]%=he;
			if(h[i]&&h[i]<he)
			{
				minh=h[i];
				kill(h[i],i);
				return ;
			}
		}
	}
}
int main(){
	minh=inf;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>h[i];
		if(h[i]<minh)
			minh=h[i],minid=i;
	}
	kill(minh,minid);
	cout<<minh;
	return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        while(true) {
            int H = scn.nextInt(), W = scn.nextInt();
            if(H == 0 && W == 0) {
                break;
            }
            for(int i = 0; i < H; i++) {
                for(int j = 0; j < W; j++) {
                    System.out.print((i == 0 || i == ~-H || j == 0 || j == ~-W) ? '#' : '.');
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 25016
from fractions import gcd
n,k=map(int,input().split())
A=list(map(int,input().split()))
if k>max(A):
    print('IMPOSSIBLE')
else:
    a=A[0]
    for i in range(n):
        a=gcd(a,A[i])
    if a==1 or k%a==0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')

Measured memory_bytes: 16048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h,w;
  cin >> h >> w;
  vector<vector<char> > a(h,vector<char>(w));
  for(int i = 0;i<h;i++){
    for(int j = 0;j<w;j++)
      cin >> a.at(i).at(j);
  }
  vector<int> I(h);
  vector<int> J(w);
  for(int i = 0;i<h;i++){
    for(int j = 0;j<w;j++){
      if(a.at(i).at(j) != '.'){
        break;
      }
      if( j == w-1){
        I.at(i) = 1;
      }
    }
  }
  for(int i = 0;i<w;i++){
    for(int j = 0;j<h;j++){
      if(a.at(j).at(i) != '.'){
        break;
      }
      if(j == h-1){
        J.at(i) = 1;
      }
    }   
  }
  for(int i = 0;i<h;i++){
    if( I.at(i) !=1){
      for(int j = 0;j<w;j++){
        if( J.at(j) != 1){
          cout << a.at(i).at(j) ;
        }
        if( j == w-1){
          cout << endl;
        }
      }
    }
  }
}

Measured memory_bytes: 256
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    _ = int(input())
    A = list(map(int, input().split()))

    MOD = 1000000007

    res = 1
    cnt = {'R': 0, 'G': 0, 'B': 0}
    for a in A:
        cv = 0
        cc = 'R'
        for c, v in cnt.items():
            if v == a:
                cv += 1
                cc = c
        res *= cv
        res %= MOD
        cnt[cc] += 1

    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 55672
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Solution sol = new Solution();
		sol.solve(in, out);
		out.close();
	}

	private static class Solution {
		private void solve(InputReader in, PrintWriter out) {
			int k = in.ni(), max = 1000000;
			int n = 0;
			if (k % 2 == 0) {
				out.println(-1);
				return;
			}
			for (int i = 0; i < max; ++i) {
				n = (n * 10 + 7) % k;
				if (n == 0) {
					out.println(i + 1);
					return;
				}
			}
			if (n != 0) {
				out.println(-1);
			}
		}
	}

	private static class InputReader {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

		private InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		private String n() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		private int ni() {
			return Integer.parseInt(n());
		}
	}
}

Measured memory_bytes: 32936
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
multiset<int>Set;
int n,res;
int main() {
	read(n);rep(i,1,n){int x;read(x);Set.insert(x);}
	while(!Set.empty()){
		int x=*Set.rbegin();Set.erase(Set.find(x));
		if(Set.empty())break;
		rep(i,1,30)if(Set.count((1<<i)-x)){
			res++;
			Set.erase(Set.find((1<<i)-x));
			break;
		}
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 9600