akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
struct edge{
    int to;
    int cap;
    int rev;
};
struct Dinic{
    int V, E;
    vector<int> level, used;
    vector<vector<edge>> G;
    Dinic(){
        cin >> V >> E;
        used.resize(V, 0);
        level.resize(V, -1);
        G.resize(V);
        for(int i = 0; i < E; i++){
            int u, v, c;
            cin >> u >> v >> c;
            edge e1 = {v, c, (int)G[v].size()};
            G[u].push_back(e1);
            edge e2 = {u, 0, (int)G[u].size() - 1};
            G[v].push_back(e2);
        }
    }
    void bfs(int s){
        level.assign(V, -1);
        queue<int> q;
        q.push(s);
        level[s] = 0;
        while(!q.empty()){
            int v = q.front();
            q.pop();
            for(edge &e: G[v]){
                if(e.cap > 0 && level[e.to] < 0){
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }
    int dfs(int s, int t, int f){
        if(s == t) return f;
        for(int &i = used[s]; i < G[s].size(); i++){
            edge &e = G[s][i];
            if(e.cap > 0 && level[e.to] > level[s]){
                int d = dfs(e.to, t, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    int solve(int s, int t){
        int flow = 0;
        int INF = 1e9;
        while(1){
            bfs(s);
            if(level[t] < 0) return flow;
            used.assign(V, 0);
            int f;
            while((f = dfs(s, t, INF)) > 0) flow += f;
        }
    }
};
int main(){
    Dinic Dinic;
    cout << Dinic.solve(0, Dinic.V - 1) << endl;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);    cout.tie(NULL);
#define forf(i,n) for(int i=0;i<n;i++)
#define foro(i,n) for(int i=1;i<=n;i++)
#define ll long long
using namespace std;


void check(char n[],int l){
	int s=0;
	forf(i,l){
		s+=n[i]-'0';
	}
	if (s%9==0)
	cout<<"Yes";
	else
	cout<<"No";
}

int main(){
	char n[200001];
	cin>>n;
	int l=strlen(n);
	check(n,l);
	return 0;
}

Measured memory_bytes: 3824
#include<bits/stdc++.h>
using namespace std;
int main(){long long n,i,j;
cin>>n;
float a[n],b[n],s=0,p,t,r=1;
for(i=0;i<n;i++){
cin>>a[i]>>b[i];
}for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
t=sqrt(((a[i]-a[j])*(a[i]-a[j]))+((b[i]-b[j])*(b[i]-b[j])));
s=s+t;
    }}r=n;s=s*2;
    s=s/r;
cout.precision(10);
cout<<fixed<<s;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[5];
string ans;

int dfs(int cnt,int sum,string s){
  string temp;
  if(cnt==4&&sum==7){
    ans=s;
    return 0;
  }
  else if(cnt==4)return 0;
  temp=s;
  temp+="+";
  dfs(cnt+1,sum+a[cnt],temp);
  temp=s;
  temp+="-";
  if(cnt!=0)dfs(cnt+1,sum-a[cnt],temp);
  return 0;
}

int main(){
  for(int i=0;i<4;i++){
    char w;
    cin>>w;
    a[i]=w-'0';
  }
  dfs(0,0,"");
  int cnt=0,c=1;
  for(int i=0;i<8;i++){
    if(i==7)cout<<"=7"<<endl;
    else if(i%2==0){
      cout<<a[cnt];
      cnt++;
    }
    else if(i%2==1){
      cout<<ans[c];
      c++;
    }
  }
  return(0);
}


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

int main(){
int h,w;
  cin >> h >> w;
string d[50];
  for(int i=0;i<h;i++) cin >> d[i];
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
for(int i=0;i<h;i++){
  for(int j=0;j<w;j++){
    
    if(d[i][j]=='#')continue;
    int num=0;
    for(int k=0;k<8;k++){
    const int y = i+ dy[k];
    const int x = j+ dx[k];
    if(x<0 | x>=w)continue;
    if(y<0 | y>=h)continue;
    if(d[y][x]=='#')num++;      
    }
    d[i][j]=char(num+'0');
  }
}  
for(int i=0;i<h;i++) cout << d[i] << endl;
  
  
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int n,m,k,d[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
char mp[888][888];
bool vis[888][888];
struct node
{
	int x,y,num;
	node(int a=0,int b=0,int c=0) {x=a;y=b;num=c;}
};
queue<node>q;

void bfs(int x,int y)
{
	memset(vis,0,sizeof(vis));
	while(!q.empty()) q.pop();
	q.push(node(x,y,k));
	vis[x][y]=1;
	while(!q.empty())
	{
		node tp=q.front();q.pop();
		if(tp.num==0) continue;
		for(int i=0;i<4;++i)
		{
			int dx=tp.x+d[i][0],dy=tp.y+d[i][1];
			if(dx<0||dx>=n||dy<0||dy>=m) continue;
			if(mp[dx][dy]=='#') continue;
			if(vis[dx][dy]) continue;
			vis[dx][dy]=1;
			q.push(node(dx,dy,tp.num-1));
		}
	}
}
int cal(int L)
{
	if(L%k) return L/k+1;
	else return L/k;
}
int main()
{
    //freopen("3.txt","r",stdin);
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<n;++i) scanf("%s",mp[i]);
	for(int i=0;i<n;++i)
		for(int j=0;j<m;++j) if(mp[i][j]=='S') bfs(i,j);
	int ans=2*n*m;
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<m;++j)
		{
			if(!vis[i][j]) continue;
			if(i==0||i==n-1||j==0||j==m-1) ans=min(ans,1);
			ans=min(ans,1+cal(i));
			ans=min(ans,1+cal(n-i-1));
			ans=min(ans,1+cal(j));
			ans=min(ans,1+cal(m-j-1));
		}
	}
	printf("%d\n",ans);
    return 0;
}

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

int main() {
	int n,i;
	string s;
	cin >> s;
	if(s=="Sunny"){
		cout << "Cloudy";
	}else if(s=="Cloudy"){
		cout << "Rainy";
	}else{
		cout << "Sunny";
	}
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var nextString func() string

func init() {
	nextString = newReadString(os.Stdin)
}

func main() {
	var (
		a = nextInt()
		b = nextInt()
		c = nextInt()
	)
	for i := 0; (a*i)%b != 0 || i == 0; i++ {
		if (a*i)%b == c {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}

func nextInt() (result int) {
	result, _ = strconv.Atoi(nextString())
	return
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
		}
		return r.Text()
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int n, c, v[500500], mem[500500];
void solve(int l, int r) {
	if(r - l == 1) return;
	solve(l, (l + r) / 2);
	solve((l + r) / 2, r);
	merge(v + l, v + (l + r) / 2, v + (l + r) / 2, v + r, mem);
	for(int i = l; i < r; i++) v[i] = mem[i - l];
	c += r - l;
}
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", &v[i]);
	solve(0, n);
	for(int i = 0; i < n; i++) {
		if(i) printf(" ");
		printf("%d", v[i]);
	}
	printf("\n%d\n", c);
}

Measured memory_bytes: 7048
#include <bits/stdc++.h>
using namespace std;
const int mod =1e9+7;
int main(void){
    int n,m;cin>>n>>m;
    vector<int> d(m);
    for(int i=0;i<m;i++)cin>>d[i];
    vector<int> dp(n+1,0);
    dp[0]=dp[1]=1;
    int tmp=0;
    if(d.size()>0&&d[0]==1){
        tmp++;
        dp[1]=0;
    }
    for(int i=2;i<=n;i++){
        if(tmp<m&&d[tmp]==i){
            tmp++;
            continue;
        }
        dp[i]=dp[i-1]+dp[i-2];
        dp[i]%=mod;
    }
    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
unsigned long long int x;
unsigned long long int result = 0;
int remain = 0;
int main(){
  cin >> x;
  result = (x/11)*2;
  remain = x%11;
  if(remain > 0){
    if(remain <= 6) result += 1;
    else result += 2;
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var p, q, r int
	fmt.Scanf("%d %d %d\n", &p, &q, &r)

	result := exec(p,q,r)

	fmt.Println(result)
}

func exec(a,b,c int) int {
	return sum(a,b,c) - max(a,b,c)	
}

func max(a,b,c int) int {
	max := a
	if max < b {
		max = b
	}

	if max < c {
		max = c
	}

	return max
}

func sum(a,b,c int) int {
	return a+b+c
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
    long long int n,a[200001],suma = 0,sum = 0,i,mod = 1000000000 + 7;
    scanf("%lld",&n);
    for(i = 0; i < n ; i++)
    {
        scanf("%lld",&a[i]);
        suma += a[i] ;
        suma %= mod;
    }
    for(i = 0 ; i < n ; i++)
    {
        suma = suma - a[i];
        while(suma < 0)
    {
        suma += mod;
    }
        
        sum += a[i] * suma;
        
        sum %= mod;
        
    }
    while(sum < 0)
    {
        sum += mod;
    }
    printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 3268
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

a,b,k = map(int, input().split())

cnt = 0
for i in range(101, 0, -1):
    if a % i == 0 and b % i == 0:
        cnt += 1
    if cnt == k:
        print(i)
        exit()


Measured memory_bytes: 9164
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;

int main(){
    int dif, all, first;

    while( cin >> all >> dif >> first, all || dif || first ){
        vector<int> num(all);
        for( int i = 0; i < all; i++ ){
            num[i] = i + 1;
        }
        vector<int>::iterator it = num.begin();
        int next = first - 1;
        num.erase( it + next );
        for( int i = 0; i < all - 1; i++ ){
            next = (next + dif - 1) % num.size();
            //cout << num[next] << endl;
            num.erase( it + next );
        }
        cout << num[0] << endl;
    }
}

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

#define REP(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main(void)
{
    const int N_MAX = 9;
    int N;
    int case_num = 0;
    int a[N_MAX][N_MAX];
    while (true) {
        cin >> N;
        if (N == 0) { break; }
        printf("Case %d:\n", ++case_num);
        int i = 0;
        int j = 0;
        int di = -1;
        int dj = 1;
        int t = 0;
        while(true) {
            a[i][j] = ++t;
            if (i == N - 1 && j == N - 1) { break; }
            if (j == N - 1 && dj == 1) {
                di = 1;
                dj = -1;
                ++i;
            } else if (i == N - 1 && di == 1) {
                di = -1;
                dj = 1;
                ++j;
            } else if (j == 0 && dj == -1) {
                di = -1;
                dj = 1;
                ++i;
            } else if (i == 0 && di == -1) {
                di = 1;
                dj = -1;
                ++j;
            } else {
                i += di;
                j += dj;
            }
        }
        REP(i, N) {
            REP(j, N) printf("%3d", a[i][j]);
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

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

  vector<int> mode_a(1e6);
  vector<int> mode_b(1e6);

  rep (i, n) {
    int x;
    cin >> x;

    if (i % 2 == 0) {
      mode_a[x]++;
    } else {
      mode_b[x]++;
    }
  }

  int max_a = max_element(mode_a.begin(), mode_a.end()) - mode_a.begin();
  int max_b = max_element(mode_b.begin(), mode_b.end()) - mode_b.begin();

  ll ans = n;
  if (max_a == max_b) {
    sort(mode_a.rbegin(), mode_a.rend());
    sort(mode_b.rbegin(), mode_b.rend());
    ans -= max(mode_a[0] + mode_b[1], mode_b[0] + mode_a[1]);
  } else {
    ans -= (mode_a[max_a] + mode_b[max_b]);
  }

  cout << ans << endl;

  //rep (i, 10) cout << mode_a[i];
  //cout << endl;
  //rep (i, 10) cout << mode_b[i];

  return 0;
}


Measured memory_bytes: 11160
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef tuple<int, int, int> ti3;

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

int main(int argc, char const* argv[])
{
    const long long INF = 1LL << 60;
    const int SIZE = 1e5 + 200;

    int N, K;
    ll h[SIZE];
    ll dp[SIZE];

    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        int x;
        cin >> h[i];
    }
    for (int i = 0; i < N; i++) {
        dp[i] = INF;
    }
    dp[0] = 0;

    for (int i = 0; i < N; i++) {
        for (int j = 1; j <= K; j++) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }
    cout << dp[N - 1] << "\n";
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;class Main{public static void main(String[]z){int x,y,n=10,i,j,m,r=0,u=0;int[][]a=new int[n][n];for(Scanner s=new Scanner(System.in);s.hasNext();){String[]p=s.nextLine().split(",");x=new Integer(p[0]);y=new Integer(p[1]);m=new Integer(p[2]);for(i=u=0;i<n;i++)for(j=0;j<n;u+=a[i][j]<1?1:0,j++)r=Math.max(r,a[i][j]+=(m<2&&Math.abs(i-x)+Math.abs(j-y)<2)||(m>2&&Math.abs(i-x)+Math.abs(j-y)<3)||(m==2&&x-2<i&&i<x+2&&y-2<j&&j<y+2)?1:0);}System.out.println(u+"\n"+r);}}

Measured memory_bytes: 12000
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	m := make(map[rune]int)
	for _, v := range s {
		m[v]++
	}

	if len(m) != 2 {
		fmt.Println("No")
		return
	}

	for _, v := range m {
		if v != 2 {
			fmt.Println("No")
			return
		}
	}

	fmt.Println("Yes")
}


Measured memory_bytes: 512
from collections import*
from bisect import*

s=input()
t=input()
slen=len(s)
d=defaultdict(list)

for i,c in enumerate(s):
    d[c].append(i)

nowplace=-1
roop=0
for c in t:
    if not d[c]:
        print(-1)
        exit()
    i=bisect(d[c],nowplace)
    if len(d[c])==i:
        roop+=1
        nowplace=d[c][0]
    else:
        nowplace=d[c][i]

print(roop*slen+nowplace+1)


Measured memory_bytes: 7924
#include<iostream>
#include<string>

using namespace std;

int main(void) {
	int a, b;
	cin >> a >> b;
	switch (a) {
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12:
		a = 100;
		break;
	case 4:
	case 6:
	case 9:
	case 11:
		a = 200;
		break;
	case 2:
		a = 300;
		break;
	}
	switch (b) {
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12:
		b = 100;
		break;
	case 4:
	case 6:
	case 9:
	case 11:
		b = 200;
		break;
	case 2:
		b = 300;
		break;
	}
	if (a == b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
	int i, a, b, c, s[4];
 
	scanf("%d %d %d", &a, &b, &c);
 
	s[0] = a + b;
	s[1] = b + c;
	s[2] = c + a;

	s[3] = s[0];
	for(i = 0; i < 3; i++) {
		if(s[i] <= s[3]) {
			s[3] = s[i];
		}
	}
	printf("%d", s[3]);
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <unordered_map>
#include <numeric>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)

constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;


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

	int n; cin >> n;
	vector<int> h(n);
	rep(i, 0, n) cin >> h[i];

	int mx = 0;
	int ans = 0;
	rep(i, 0, n) {
		if (mx <= h[i]) ++ans;
		mx = max(mx, h[i]);
	}
	cout << ans;

	return 0;
}


Measured memory_bytes: 3456
#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;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	rep(i, n) {
		if (a[i] % 2 == 0) {
			if (a[i] % 3 != 0 && a[i] % 5 != 0) {
				puts("DENIED");
				return 0;
			}
		}
	}
	puts("APPROVED");
	return 0;
}


Measured memory_bytes: 256
//Zory-2018
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
using namespace std;

namespace mine
{
	typedef long long ll;
	const int INF=0x3f3f3f3f;

	ll MOD;
	ll qpower(ll x,ll e)
	{
		ll ans=1;
		while(e>0)
		{
			if(e&1) ans=ans*x%MOD;
			x=x*x%MOD;e>>=1;
		}
		return ans;
	}

	int a[110000];
	int f[110000][2];//0up 1down

	int num1[110000];
	int num2[110000];
	void main()
	{
		int n;scanf("%d",&n);
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);

		for(int i=1;i<=n;i+=2) num1[a[i]]++;
		int mxnum1=0,mx2num1=0;
		for(int i=1;i<110000;i++)
		{
			if(num1[i]>num1[mxnum1]) mx2num1=mxnum1,mxnum1=i;
			else if(num1[i]>num1[mx2num1]) mx2num1=i;
		}

		for(int i=2;i<=n;i+=2) num2[a[i]]++;
		int mxnum2=0,mx2num2=0;
		for(int i=1;i<110000;i++)
		{
			if(num2[i]>num2[mxnum2]) mx2num2=mxnum2,mxnum2=i;
			else if(num2[i]>num2[mx2num2]) mx2num2=i;
		}

		int ans=n-num1[mxnum1]-num2[mxnum2];
		if(mxnum1==mxnum2) ans=min(n-num1[mxnum1]-num2[mx2num2],n-num1[mx2num1]-num2[mxnum2]);
		printf("%d",ans);
	}
}
int main()
{
	mine::main();
}


Measured memory_bytes: 1280
#include <algorithm>  //sort,二分探索,など
#include <array>
#include <bitset>         //固定長bit集合
#include <cmath>          //pow,logなど
#include <complex>        //複素数
#include <deque>          //両端アクセスのキュー
#include <functional>     //sortのgreater
#include <iomanip>        //setprecision(浮動小数点の出力の誤差)
#include <iostream>       //入出力
#include <map>            //map(辞書)s
#include <numeric>        //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>          //キュー
#include <set>            //集合
#include <stack>          //スタック
#include <string>         //文字列
#include <unordered_map>  //イテレータあるけど順序保持しないmap
#include <unordered_set>  //イテレータあるけど順序保持しないset
#include <utility>        //pair
#include <vector>         //可変長配列

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())  // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

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

Measured memory_bytes: 256
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::HashMap;

fn main() {
    input!(n: usize, m: usize);
    if n == 1 && m == 1 {
        println!("{}", 1);
    } else if n == 1 || m == 1 {
        let ans = max(n, m) - 2;
        println!("{}", ans);
    } else {
        let ans = (n - 2) * (m - 2);
        println!("{}", ans);
    }
}


Measured memory_bytes: 4352
#include<stdio.h>
int main()
{
  int n,a,b;
  scanf("%d\n %d %d",&n,&a,&b);
  int l=0;
  for(int i=a;i<=b;i++)
  {
    if(i%n==0)
    {
      printf("OK\n");
      l++;
      break;
    }
  }
  if(l==0)
  {
  printf("NG\n");}
  
}

Measured memory_bytes: 1656
module module_sort
    use iso_fortran_env
    implicit none

    interface quicksort
        module procedure :: int32_qsort
        module procedure :: int64_qsort
    end interface quicksort
contains

    recursive function int32_qsort(m) result(res)
        integer(int32), intent(in) :: m(:)
        integer(int32) :: res(size(m)) 

        if (size(m) <= 1) then; res = m
        else; res = [int32_qsort( pack(m(2:), m(2:) >= m(1)) ), m(1), int32_qsort( pack(m(2:), m(2:) < m(1)) )]
        end if

    end function int32_qsort

    recursive function int64_qsort(m) result(res)
        integer(int64), intent(in) :: m(:)
        integer(int64) :: res(size(m)) 

        if (size(m) <= 1) then; res = m
        else; res = [int64_qsort( pack(m(2:), m(2:) >= m(1)) ), m(1), int64_qsort( pack(m(2:), m(2:) < m(1)) )]
        end if

    end function int64_qsort

end module module_sort

program main
    use module_sort
    use iso_fortran_env
    implicit none
    integer(8) :: n
    integer(8), allocatable :: ai(:)
    integer(8) :: i, ie
    integer(8) :: ans

    read *, n
    allocate( ai(n) )
    read *, ai( 1:n )
!    ai = quicksort( ai )
!    print *, int32, int64, int128
!    call qsort( ai )
!    ai(n:1:-1) = ai(1:n)
    ai = intQsort( ai )
    ai(n:1:-1) = ai(1:n)

    if ( mod((n-1), 2) == 0 ) then
        ie = (n-1) / 2
        ans = ai(1) + ai(ie + 1)
    else
        ie = n / 2
        ans = ai(1)
    endif

    do i = 2, ie
        ans = ans + ai(i) * 2
    enddo

    print *, ans

contains

recursive subroutine qsort(a)
  implicit none
  integer(8),intent(inout) :: a(:)
  integer(8)::i,j,toobig,toosmall,pv,n

  n = size(a)
i = 1
j = n
pv = a((i+j)/2)
do
   do
     if (a(i) < pv) then
       i = i+1
     else
       exit
     end if
   end do
   do
     if(a(j) > pv) then
       j = j-1
     else
       exit
     end if
   end do
   if (i>=j) then
     exit
   else
     toobig = a(j)
     toosmall = a(i)
     a(i) = toobig
     a(j) = toosmall
     i = i+1
     j = j-1
   end if
 end do
 if (i > 2) then
   call qsort(a(1:i-1))
 end if
 if (j < n-1) then
   call qsort(a(j+1:n))
 end if
end subroutine qsort

pure recursive function intQsort( a ) result( r )
implicit none
integer(8), intent(in) :: a(:)
integer(8) :: r( size(a) )
integer(8) :: sample(3), len, i,j

len = size( a(:) )
if( len<=1 )then
  r = a
else
  !select pivot
  sample(1:3) = [a(1), a(len/2), a(len)]
  do i = 1,2
    do j = 2,3
      if( sample(i)>sample(j) )then
        len = sample(i) !len is buffer
        sample(i) = sample(j)
        sample(j) = len
      end if
    end do
  end do
  
  r = [ intQsort( pack(a(:), a(:)< sample(2)) ), &
                  pack(a(:), a(:)==sample(2))  , &
        intQsort( pack(a(:), a(:)> sample(2)) ) ]
end if
end function intQsort

end program main

Measured memory_bytes: 11952
import sys
A,B,M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for l in sys.stdin:
  xi,yi,ci = map(int,l.split())
  ans = min(ans,a[xi-1]+b[yi-1]-ci)
print(ans)

Measured memory_bytes: 18736
N, M = map(int, input().split())
s = []
c = []
for _ in range(M):
    a, b = map(int, input().split())
    s.append(a)
    c.append(b)
ans = [-1] * N
flag = True
for i in range(M):
    if N > 1 and s[i] == 1 and c[i] == 0: flag = False
    if ans[s[i] - 1] < 0:
        ans[s[i] - 1] = c[i]
    elif ans[s[i] - 1] != c[i]:
        flag = False


for i in range(N):
    if ans[i] < 0:
        ans[i] = 0

if ans[-N] == 0 and N > 1:
    ans[-N] = 1

if flag:
    print(''.join(map(str, ans)))
else:
    print(-1)

Measured memory_bytes: 38256
// AOJ 0659 Exhibition
// 2019.3.29 bal4u

#include <stdio.h>
#include <stdlib.h>

//// 入力の高速化
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()    // 整数の入力（負数非対応）
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

typedef struct { int s, v; } T;
T t[100005]; int N;
int c[100005]; int M;

// C言語内蔵クイックソート関数用比較関数
int cmpInt(const void *a, const void *b) { return *(int *)b - *(int *)a; }
int cmpT(const void *a, const void *b) {
	int t = ((T *)b)->v - ((T *)a)->v; if (t) return t;
	return ((T *)b)->s - ((T *)a)->s;
}

int main()
{
	int i, j, ans;

	// 入力受付
	N = in(), M = in();
	for (i = 0; i < N; i++) t[i].s = in(), t[i].v = in();
	for (i = 0; i < M; i++) c[i] = in();

	// 降順にソートしておく
	qsort(t, N, sizeof(T), cmpT);
	qsort(c, M, sizeof(int), cmpInt);
	t[N].s = 0;  // 番兵

	ans = 0, i = 0;
	for (j = 0; i < N && j < M; j++) {
		while (t[i].s > c[j]) i++;
		if (i == N) break;
		ans++, i++;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3416
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define pb push_back
 
#define limit (int) (1e5 + 5)
#define mod (int) (1e9 + 7)

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
using ld = long double;

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

    int p;
    cin >> p;

    int ans = 8 - (p-400)/200;

    // if (p%400 == 0)
    // {
    //     ans++;
    // }

    cout << ans;
    
    

    return 0;
}







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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  string s, t;
  cin >> s >> t;
  rep(i, sz(s)) {
    if (s[i] != t[i]) {
      no();
    }
  }
  yes();
}


Measured memory_bytes: 3640
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(int N, long[] A) {
    auto l = new long[](N);
    auto r = new long[](N);

    l[0] = A[0];
    r[$ - 1] = A[$ - 1];
    for (auto i = 0; i < N - 1; i++) {
        l[1 + i] = gcd(A[1 + i], l[i]);
        r[$ - 2 - i] = gcd(A[$ - 2 - i], r[$ - 1 - i]);
    }

    long ans;
    for (auto i = 0; i < N; i++) {
        if (i == 0) {
            ans = ans.max(r[1]);
        } else if (i == N - 1) {
            ans = ans.max(l[$ - 2]);
        } else {
            ans = ans.max(gcd(l[i - 1], r[i + 1]));
        }
    }

    return ans;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    int N;
    N = input.front.to!int;
    input.popFront;

    long[] A = new long[](N);
    foreach (i; 0 .. N) {
        A[i] = input.front.to!long;
        input.popFront;
    }

    static if (is(ReturnType!solve == void))
        solve(N, A);
    else
        solve(N, A).writeln;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

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

int main() {
  int ans = 0;
  int x, y;
  cin >> x >> y;

  if (x == 1 && y == 1) {
    cout << 1000000 << endl;
    return 0;
  } else {
    if (x == 1)
      ans += 300000;
    else if (x == 2)
      ans += 200000;
    else if (x == 3)
      ans += 100000;

    if (y == 1)
      ans += 300000;
    else if (y == 2)
      ans += 200000;
    else if (y == 3)
      ans += 100000;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
cards_p = []
$count = 0
n.times do |i|
  cards_p << gets.chomp.to_i
end
#cards_p.flatten!

#p cards_p

tmp = 0

0.upto(n-1) do |idx|
#  p cards_p
  arr = cards_p[idx] + tmp
#  puts %(arr:#{arr})
#  puts ""
  if arr % 2 == 0
    $count += arr/2
  else
    $count += arr/2
    if idx < n-1
      unless cards_p[idx+1] == 0
        tmp = 1
        next
      end
    end
#    unless cards_p[idx+1].empty?
#      cards_p[idx+1].unshift arr.last
#    end

  end
  tmp = 0
end

puts $count

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

bool checkY(char a, char b){
	if (a >= '0' && a <= '9' && b >= '0' && b <= '9')
	{
		return true;
	}
	return false;
}

bool checkM(char a, char b){
	if (a == '0'){
		if (b >= '1' && b <= '9'){
			return true;
		}
	}else if(a == '1'){
		if (b >= '0' && b <= '2'){
			return true;
		}
	}
	return false;
}

int main()
{
	char s[4];
	cin >> s;

	bool Y1 = checkY(s[0], s[1]);
	bool Y2 = checkY(s[2], s[3]);
	bool M1 = checkM(s[0], s[1]);
	bool M2 = checkM(s[2], s[3]);

	if (Y1 && Y2 && M1 && M2){
		cout << "AMBIGUOUS" << endl;
	}else if(Y1 && M2){
		cout << "YYMM" << endl;
	}else if(Y2 && M1){
		cout << "MMYY" << endl;
	}else{
		cout << "NA" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
//hinagata.cpp
//作成日
//更新日
//目的
//手段
/*includes*/
#include <bits/stdc++.h>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REPi(i,a,b) for(ll i=(a);i<(b);i++)
#define REPRi(i,a,b) for(ll i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

const int debug =0;
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// テーブルを作る前処理
int mult_mf(ll a,ll b){
    return (a%MOD)*(b%MOD)%MOD;
}

int pow_mf(ll a,ll b){
    if(b==0){
        return 1;
    }else if(b==1){
        return a%MOD;
    }else if(b%2==0){
        ll k=pow_mf(a,b/2);
        return mult_mf(k,k);
    }else{
        ll k=pow_mf(a,b/2);
        return mult_mf(mult_mf(k,k),a);
    }
}

int main(){
    COMinit();
    int N,A,B;
    cin>>N>>A>>B;
    ll allpat=pow_mf(2,N)-1;
    //全通りの場合の値を得た．
    //NCa,NCbの計算
    ll NCA=1,NCB=1;
    REP(i,A){
        NCA=(((NCA*(N-i))%MOD)*inv[i+1])%MOD;
    }
    REP(i,B){
        NCB=(((NCB*(N-i))%MOD)*inv[i+1])%MOD;
    }
    
    //end;
    
    ll ans=(2*MOD+allpat-NCA-NCB)%MOD;
    cout<<(2*MOD+allpat-NCA-NCB)%MOD<<endl;
}

Measured memory_bytes: 12160
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
      Scanner sc = new Scanner(System.in);
      
      int W = sc.nextInt();
      int H = sc.nextInt();
      int x = sc.nextInt();
      int y = sc.nextInt();
      int r = sc.nextInt();
      
      if(y>=r&&H-r>=y&&x>=r&&W-r>=x){
          System.out.println("Yes");
      }else if(!(y>=r&&H-r>=y&&x>=r&&W-r>=x)){
          System.out.println("No");
      }
    }
}



Measured memory_bytes: 26300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 1e5 + 10;
int a[maxn], n, k;
ll norm(ll x)
{
	while(x < 0) x += mod;
	while(x >= mod) x -= mod;
	return x;
}
ll powMod(ll a, ll k)
{
	ll ret = 1;
	while(k)
	{
		if(k & 1) ret = ret * a % mod;
		a = a * a % mod; k >>= 1;
	}
	return ret;
}
ll getInv(ll x) { return powMod(x, mod - 2);}
ll solve()
{
	ll cur = 1, ret = 0;
	for(int i = k; i <= n; ++i)
	{
		ret += a[i] * cur % mod;
		ret = norm(ret);
		cur = cur *  i % mod * getInv(i - k + 1) % mod;
	}
	return ret;
}
int main()
{
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	ll ret1 = solve();
	reverse(a + 1, a + n + 1);
	ll ret2 = solve();
	cout << norm(ret1 - ret2) << endl;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(){
  int a,b,i,c[5],cnt=0;
  scanf("%d %d",&a,&b);
  for(i=a;i<=b;i++){
    if(i%10==i/10000&&(i%100/10)==(i/1000%10)) cnt++;
  }
  printf("%d\n",cnt);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<vector<int>>;

const int INF = 1 << 30;
const ll INFL = 1LL << 60;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const int MAX_S = 3005;

int dp[MAX_S][MAX_S] = {0}; //---- dp[i+1][j+1]: s[i], t[j]までのLCSの長さ
string s, t;

int main(){
    cin >> s;
    cin >> t;
    int s_sz = s.length();
    int t_sz = t.length();

    for(int i=0; i<s_sz; ++i){
        for (int j=0; j<t_sz; ++j){
            if( s[i] == t[j] ) chmax( dp[i+1][j+1], dp[i][j] + 1 );
            chmax( dp[i+1][j+1], dp[i+1][j] );
            chmax( dp[i+1][j+1], dp[i][j+1] );
        }
    }

    string res = "";
    int i = s.length(), j = t.length();
    while( i > 0 && j > 0 ){
        if( dp[i][j] == dp[i-1][j] ){
            --i;
        }
        else if (dp[i][j] == dp[i][j-1]) {
            --j;
        }
        else {
            res = s[i-1] + res; // このとき s[i-1] == t[j-1] なので、t[j-1] + res でも OK
            --i, --j; // DP の遷移を遡る
        }
    }

    cout << res;
	return 0;
}

Measured memory_bytes: 35456
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define eps 1e-9
#define oo 1e7+5

using namespace std;

typedef unsigned long long ull;
typedef vector<pair<int,pair<int,int>>> dirgraph;
typedef vector<vector<int>> graph;

const int maxN=1e12+5;

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

	int n,k;
	cin>>n>>k;
	int h[n];
	
	for (int i = 0; i < n; i++)
	{
		cin>>h[i];
	}
	
	vector<int> dp(n,maxN);
	dp[0]=0;
	for (int i = 0; i < n; i++)
	{
		for (int j = i+1; j < min(n,(i+k+1)); j++)
		{
			dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
		}
		
	}
	
	cout<<dp[n-1]<<endl;
	
	return 0;
}



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

using namespace std;

int main(){
    int N,M;
    int t;
    float s;
    vector<int> A;

    cin >> N >> M;
    for (int i=0;i<N;i++){
        cin >> t;
        A.push_back(t);
        s+=float(t);
    }
    int cnt=0;
    for(int i=0;i<N;i++){
        if (float(A[i])>=s/(4.0*M)){
            cnt+=1;
        }
    }
    if (cnt>=M){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}


Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    A, B, C = in_nn()
    ans = min(B // A, C)
    print(ans)


if __name__ == '__main__':
    main()


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

int N;
int x[127];
int y[127];
ll h[127];

ll check(int i, int j, int N){
    ll height = 0;
    ll last =0;  
    for(int k=0;k<N;k++){
        if(h[k]>0){
            last = abs(x[k]-i) + abs(y[k]-j) + h[k];
            break;
        }
    }
    for(int k=0; k<N; k++){
        if(max(last-abs(x[k]-i)-abs(y[k]-j), (ll)0) == h[k]) continue;
        else return 0;
    }
    return last;
}
int main(){
    scanf("%d", &N);
    for(int i=0; i<N; i++){
        scanf("%d%d%lld", &x[i], &y[i], &h[i]);
    }
    for(int i=0; i<=100; i++){
        for(int j=0; j<=100; j++){
            ll H = check(i, j, N);
            if(H>0) {
            printf("%d %d %lld\n", i, j, H);
            return 0;
        }
        }
    }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	int a = x2 - x1;
	int b = y2 - y1;
	
	int p1x = x2 - b;
	int p1y = y2 + a;

	cout << p1x << " " << p1y << " " << p1x - a << " " << p1y - b << endl;

	return 0;
}

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

int main(){
  int A , B , C , D , E;
  cin >> A;
  
  B = A / 1000;
  C = (A / 100) % 10;
  D = (A / 10) % 10;
  E = A % 10;
  
  if(B == C && C == D || C == D && D == E)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
}

Measured memory_bytes: 256
a, b, k = gets.strip.split.map(&:to_i)

list = []

(1..k).each do |i|
  list << a + i - 1
  list << b - i + 1
end

sorted = list.select { |i| a <= i && i <= b }.uniq.sort

sorted.each do |i|
  puts i
end


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

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

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

    int N;
    cin >> N;

    vector<string> grid(N);
    for (int i = 0; i < N; i++) {
        cin >> grid[i];
    }

    int works = 0;
    for (int i = 0; i < N; i++) {
        bool good = true;
        for (int a = 0; a < N; a++) {
            for (int b = 0; b < a; b++) {
                good &= grid[a][b] == grid[b][a];
            }
        }
        works += good;

        string last = grid.back();
        grid.pop_back();
        grid.insert(grid.begin(), last);
    }
    cout << works * N << endl;

    return 0;
}



Measured memory_bytes: 384
N,maxW = map(int,input().split())
w,v = [],[]
for i in range(N):
    weight,value = map(int,input().split())
    w.append(weight)
    v.append(value)
maxV=sum(v)
inf = float('inf')
dp = [[inf for _ in range(maxV+1)] for _ in range(N+1)]
dp[0][0] =0
for i in range(N):
    for sum_v in range(maxV+1):
        if (sum_v -v[i]>=0):
            dp[i+1][sum_v] = min(dp[i+1][sum_v],dp[i][sum_v-v[i]]+w[i])
        dp[i+1][sum_v] = min(dp[i+1][sum_v],dp[i][sum_v])
res = 0
for i in range(maxV+1):
    if dp[N][i] <= maxW:
        res = i
print(res)

Measured memory_bytes: 326836
#include <iostream>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

int main(){
    int n,x[100000],y[100000];
    int i=0;
    char a,b;
    int sum=0;
    cin >>n;
    while(i!=n){
        cin >>x[i];
        i++;
    }
    sort(x,x+n);
    reverse(x,x+n);
    i=0;
    while(i!=n){
        if(i%2==0){
            sum+=x[i];
        }
        else{
            sum-=x[i];
        }
        i++;
    }
    cout << sum << endl;

return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = l[0], W = l[1];

            var weight = new int[N];
            var cost = new int[N];

            for (var i = 0; i < N; i++)
            {
                var tmp = Console.ReadLine().Split().Select(int.Parse).ToArray();
                weight[i] = tmp[0];
                cost[i] = tmp[1];
            }

            var sol = new Solve(N, W, weight, cost);
            Console.WriteLine(sol.Execute());
        }
    }

    class Solve
    {
        public int N { get; set; }
        public int W { get; set; }
        public int[] weight { get; set; }
        public int[] cost { get; set; }
        public long[,] dp { get; set; }

        public Solve(int N, int W, int[] weight, int[] cost)
        {
            this.N = N;
            this.W = W;
            this.weight = weight;
            this.cost = cost;
            dp = new long[N + 10, W + 10];
        }

        public long Execute()
        {
            for (var i = 0; i < N; i++)
            {
                for (var j = 0; j <= W; j++)
                {
                    if (j >= weight[i])
                        dp[i + 1, j] = Math.Max(dp[i, j - weight[i]] + cost[i], dp[i, j]);
                    else
                        dp[i + 1, j] = dp[i, j];
                }
            }
            return dp[N, W];
        }
    }
}

Measured memory_bytes: 93792
N,K,Q = gets.split.map(&:to_i)
A = Array.new(Q){gets.to_i}

SCORE = Array.new(N){0}

A.each do |a|
    SCORE[a-1] += 1
end

SCORE.each do |point|
    puts K - Q + point > 0 ? "Yes" : "No"
end

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

int main(void) 
{
   string s;
   cin >> s;
   int ans = 0;
   int tmp =0;
   rep(i,3)
   {
       if(s[i] == 'R') tmp++;
       else
       {
           ans = max(tmp, ans);
           tmp = 0;
       }
   }

   ans = max(tmp, ans);
   cout << ans << endl;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;
  cin >> n >> m;
  vector<ll> f(2*n);
  rep(i,2 * n){
    f[i] = i+1;
  }
  ll k;
  rep(i,m){
    cin >> k;
    if(k){
      vector<ll> tmp = vector<ll>(f.begin(),f.begin()+k);
      vector<ll> tmp2 = vector<ll>(f.begin()+k,f.end());
      f.clear();
      for(auto N:tmp2){
        f.pb(N);
      }
      rep(j,tmp.size()){
        f.pb(tmp[j]);
      }
    }
    else{
      vector<ll> tmp(0);
      rep(i,n){
        tmp.pb(f[i]);
        tmp.pb(f[n+i]);
      }
      f = tmp;
    }
  }
  for(auto u:f){
    cout << u << endl;
  }
  return 0;
}

Measured memory_bytes: 3152
n, x = gets.split(" ").map(&:to_i)
children = gets.split(" ").map(&:to_i)
children.sort!

count = 0

while x >= children.first && children.length > 1
  x -= children.first
  children.delete_at(0)
  count += 1
end

if children.first == x
  count += 1
end

puts count

Measured memory_bytes: 1788
#include <stdio.h>
#include <stdlib.h>
 
typedef struct{
  int k;
  int l;
  int r;
} Tree;
 
void insert(int, int);
void chu(int);
void sen(int);
void find(int,int);
Tree t[500001];
int get;
int main()
{
  char s[8];
  int m;
  int num,t;
  int i;
   
  scanf("%d", &m);
   
  int count=0;
  for(i=0; i<m; i++){
    scanf("%s", &s);
    if(s[0]=='i'){ 
      scanf("%d", &num); 
      insert(count, num); 
      count++; 
    }
    if(s[0]=='f'){
      scanf("%d",&t);
      find(t,0);
       
    }
    if(s[0]=='p'){
      if(count>0) chu(0);
      printf("\n");
      if(count>0) sen(0);
      printf("\n");
    }
  }
   
  return 0;
   
}
 
void chu(int p){
  if(t[p].l>=0) chu( t[p].l);
  printf(" %d", t[p].k);
  if(t[p].r>=0) chu( t[p].r);
}
 
void sen(int p){
  printf(" %d", t[p].k);
  if(t[p].l>=0) sen(t[p].l);
  if(t[p].r>=0) sen(t[p].r);
}
 
void insert(int count, int z){
  int x=0, y;
  if(count<1) x=-1;
   
  t[count].k = z;
  t[count].l = -1;
  t[count].r = -1;
   
  while(x>=0){
    y = x; 
    if(z < t[x].k)x = t[x].l; 
    else x = t[x].r; 
  }
  if(count<1){}
  else if(z < t[y].k)t[y].l = count; 
  else t[y].r = count; 
   
}
 
void find(int num,int c){
  if (c==-1){
    printf("no\n");
  }
  else if (t[c].k==num){
    printf("yes\n");
  }
  else if (t[c].k > num && t[c].l != -1){
    find(num,t[c].l);
  }
  else {
    find(num,t[c].r);
  }
}

Measured memory_bytes: 5304
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vl vector<ll>
typedef long long int ll;
typedef long double ld;
using namespace std;

struct edge{ll to, cost, num;};
std::vector<std::vector<edge> > G(200000);
std::vector<ll> ue(200000, -1), num(200000, 1);

void dfs(ll from, ll now){
  for(int i=0;i<G[now].size();i++){
    if(from == G[now][i].to) continue;
    if(ue[now]==num[now]) num[now]++;
    G[now][i].cost = num[now];
    ll t =  G[now][i].to;
    ue[t] = num[now];
    num[now]++;
    dfs(now, t);
  }
}
int main(int argc, char const *argv[]) {
  ll n, a, b;
  std::cin >> n;
  for(int i=0;i<n-1;i++){
    std::cin >> a >> b;
    G[a].push_back(edge{b, -1, i});
    G[b].push_back(edge{a, -1, i});
  }
  ll c = 0;
  dfs(-1, 1);
  std::vector<ll> ans(n-1);
  for(int i=0;i<200000;i++){
    for(int j=0;j<G[i].size();j++){
      c = max(c, G[i][j].cost);
      ans[G[i][j].num] = max(ans[G[i][j].num], G[i][j].cost);
    }
  }
  std::cout << c << '\n';
  for(int i=0;i<n-1;i++){
    std::cout << ans[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 16128