akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

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

int dp[3005][3005][2];

void Main()
{
    arrayFill(dp, 0);
    int n, t;
    cin >> n >> t;
    vector<pint> ab(n);
    rep(i, n)
    {
        int a, b;
        cin >> a >> b;
        ab[i] = make_pair(a, b);
    }

    rep(i, n)
    {
        rep(j, t)
        {
            rep(k, 2)
            {
                // 入れない
                chmax(dp[i + 1][j][k], dp[i][j][k]);

                // 外側
                if (k == 0)
                {
                    chmax(dp[i + 1][j][1], dp[i][j][0] + ab[i].second);
                }

                // 内側
                if (j + ab[i].first <= t)
                {
                    chmax(dp[i + 1][j + ab[i].first][k], dp[i][j][k] + ab[i].second);
                }
            }
        }
    }

    int ans = 0;
    rep(k, 2)
    {
        chmax(ans, dp[n][t - 1][k]);
    }
    cout << ans << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 70912
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>

using namespace std;

int func(vector<int>& stones, int index, vector<int>& dp){
	if(index == (int)stones.size() - 1) return 0;
	if(index >= (int)stones.size()) return INT_MAX;
	
	if(dp[index] == -1){
		int take1 = abs(stones[index] - stones[index + 1]) + func(stones, index + 1, dp);
		
		int take2 = INT_MAX;
		
		if(index + 2 < (int)stones.size())
			take2 = abs(stones[index] - stones[index + 2]) + func(stones, index + 2, dp);
		
		dp[index] = min(take1, take2);
	}
	return dp[index];
}


int main() {
	int n;cin>>n;
	vector<int> stones(n), dp(n, -1);
	for(auto &x : stones) cin>>x;
	cout<<func(stones, 0, dp)<<endl;
}




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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

bool flag[100001];

void solve(long long N, std::vector<long long> a){
    
    int next = a[0] - 1;
    int cnt = 1;
    while(true) {
        if(next == 1) {
            cout << cnt << endl;
            return;
        }

        if(flag[next]) {
            break;
        }

        flag[next] = true;
        next = a[next]-1;
        cnt++;
    } 

    cout << -1 << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


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

using namespace std;

int main()
{
    std:string s;
    cin >> s;
    
    if(s == "Sunny"){
        cout << "Cloudy" << endl;
    }else if(s == "Cloudy"){
        cout << "Rainy" << endl;
    }else if(s == "Rainy"){
        cout << "Sunny" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>
#include <functional>
#include <queue>
#include <utility>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long LL;

using namespace std;

int main(void)
{
	int y, m, d;
	char c1, c2;

	cin >> y >> c1 >> m >> c2 >> d;

	if ((y >= 2019) && (m >= 5) && (d >= 1)) {
		cout << "TBD" << endl;
	}
	else {
		cout << "Heisei" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
// const ll MOD = 1e9 + 7;
const ll MOD = 998244353;

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








ll POW(ll n, ll m, ll p){
    ll res = 1, x = n;
    for(ll i = m; i > 0; i >>= 1){
        if(i & 1){
            res *= x;
            res %= p;
        }
        x *= x;
        x %= p;
    }
    return res;
}

int main(){
    int n;
    scanf("%d", &n);
    int a[300];
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    
    sort(a, a + n);

    ll dp[90001] = {};
    dp[0] = 1;
    int sum = 0;
    for(int i = 0; i < n; i++){
        vector<ll> tmp(sum + a[i] + 1);
        for(int j = 0; j <= sum; j++){
            tmp[j] += dp[j] * 2;
            tmp[j] %= MOD;
            tmp[j + a[i]] += dp[j];
            tmp[j + a[i]] %= MOD;
        }
        sum += a[i];
        for(int j = 0; j <= sum; j++){
            dp[j] = tmp[j];
        }
    }
    
    ll dp2[90001] = {};
    dp2[0] = 1;
    sum = 0;
    for(int i = 0; i < n; i++){
        vector<ll> tmp(sum + a[i] + 1);
        for(int j = 0; j <= sum; j++){
            tmp[j] += dp2[j];
            tmp[j] %= MOD;
            tmp[j + a[i]] += dp2[j];
            tmp[j + a[i]] %= MOD;
        }
        sum += a[i];
        for(int j = 0; j <= sum; j++){
            dp2[j] = tmp[j];
        }
    }
    
    ll res = 0;
    for(int i = (sum + 1) / 2; i <= sum; i++){
        res += dp[i];
        res %= MOD;
    }
    res *= 3;
    res %= MOD;
    
    printf("%lld\n", (POW(3, n, MOD) - res + ((sum % 2 == 0)? dp2[sum / 2] * 3 : 0) + MOD) % MOD);
}

Measured memory_bytes: 2380
(defvar *b*)
(defvar *cache*)
(defvar *x*)

(defun binomial (n)
	(setf *b* (make-array (list n n)))
	(dotimes (i n)
		(setf (aref *b* 0 i) 0)
		(setf (aref *b* i i) 1))
	(loop :for i :from 1 :below n :do
		 (loop :for j :from 1 :below i :do
				(setf (aref *b* i j) (+ (aref *b* (1- i) (1- j)) (aref *b* (1- i) j))))))

(defun s (a k i)
	(cond ((< a 0) 0)
				((< k 0) 0)
				((zerop k) (if (zerop a) 1 0))
				((> i a) 0)
				((= i 51) 0)
				(t (let ((key (+ (* a 51 51) (* k 51) i)))
						 (if (aref *cache* key)
								 (aref *cache* key)
								 (let ((c (s a k (1+ i))))
									 (loop :for j :from 1 :to (aref *x* i) :do
											(incf c (* (aref *b* (1+ (aref *x* i)) (1+ j))
																 (s (- a (* i j)) (- k j) (1+ i)))))
									 (setf (aref *cache* key) c)
									 c))))))

(let ((n (read))
			(a (read)))
	(binomial (+ n 2))
	(setf *cache* (make-array (expt 51 4) :initial-element nil))
	(setf *x* (make-array 51 :initial-element 0))
	(loop :repeat n :do (incf (aref *x* (read))))
	(format t "~a~%" (loop :for i :from 1 :to n :sum (s (* a i) i 0))))


Measured memory_bytes: 80096
class UnionFind1:

    def __init__(self, n):
        self.n = n
        self.par = [-1] * (n+1)

    def root(self, x):
        if self.par[x] < 0:
            return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]

    def unite(self, x, y):
        if self.same(x, y):
            return
        x = self.root(x)
        y = self.root(y)
        if self.par[x] > self.par[y]:
            x, y = y, x
        self.par[x] += self.par[y]
        self.par[y] = x

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def size(self, x):
        return -self.par[self.root(x)]


n, m = map(int, input().split())
uf = UnionFind1(n)

for _ in range(m):
    x, y, z = map(int, input().split())
    uf.unite(x, y)

cost = 0
for i in range(1, n+1):
    if uf.root(i) == i:
        cost += 1

print(cost)


Measured memory_bytes: 81652
from collections import deque
def readinput():
    n=int(input())
    nList=[]
    for _ in range(n+1):
        nList.append([])
    edges=[]
    for _ in range(n-1):
        a,b=map(int,input().split())
        edges.append((a,b))
        nList[a].append(b)
        nList[b].append(a)
    return n,nList,edges

def bfs(s,nList):
    #print(nList)
    WHITE=0
    GRAY=1
    BLACK=2
    status=[WHITE]*(n+1)
    parent=[0]*(n+1)
    color=[0]*(n+1)
    maxcolor=0
    Q=deque([])
    Q.append(s)
    while(len(Q)>0):
        u=Q.popleft()
        usedcolor=color[u]
        col=1
        for t in nList[u]:
            if status[t]==WHITE:
                status[t]=GRAY
                parent[t]=u
                if col==usedcolor:
                    col+=1
                color[t]=col
                Q.append(t)
                col+=1
                maxcolor=max(maxcolor,col-1)
        status[u]=BLACK
        #print(u,usedcolor)
    return color, maxcolor


def main(n,nList,edges):
    color, maxcolor=bfs(1,nList)
    print(maxcolor)
    for a,b in edges:
        print(color[b])

if __name__=='__main__':
    n,nList,edges=readinput()
    main(n,nList,edges)


Measured memory_bytes: 35468
#include<iostream>
#include<stack>
using namespace std;
#define MAX 100
#define NIL -1

int n, T[MAX+1][MAX+1];
int laps = 0, d[MAX+1], f[MAX+1];

void solve(int i){
    d[i] = ++laps;
    for ( int j = 1; j <= n; j++){
      if ( T[i][j] && d[j] == NIL ){
        solve(j);
      }
    }

    f[i] = ++laps;
}

int main(){
  cin >> n;
  for ( int i = 1; i <= n; i++){
    d[i] = f[i] = NIL;
    for ( int j = 1; j <= n; j++){
      T[i][j] = 0;
    }
  }

  int u, k, v;
  for ( int i = 1; i <= n; i++){
    cin >> u >> k;
    for ( int j = 0; j < k; j++){
      cin >> v;
      T[u][v] = 1;
    }
  }

  for ( int i = 1; i <= n; i++){
    if ( d[i] == NIL){
      solve(i);
    }
  }

  for ( int i = 1; i <= n; i++){
    cout << i << " " << d[i] << " " << f[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 3148
#include<iostream>
#include<cstdio>
#define MN 100000
#define mod 1000000007
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int head[MN+5],cnt=0,n,vis[MN+5],Fa[MN+5],dep[MN+5],c[MN+5],top,in[MN+5],ans=1;
int A,B,C,num[MN+5],vnum,cirnum[MN+5],p[MN+5],inv[MN+5],pw[MN+5],Out[MN+5];
struct edge{int to,next;}e[MN*2+5];
inline void ins(int f,int t)
{
	e[++cnt]=(edge){t,head[f]};head[f]=cnt;
	e[++cnt]=(edge){f,head[t]};head[t]=cnt; 
}
void dfs(int x,int fa)
{
	Fa[x]=fa;vis[x]=1;++vnum;
	for(int i=head[x];i;i=e[i].next)
		if(e[i].to!=fa) 
		{
			if(vis[e[i].to]) A=x,B=e[i].to;
			else dep[e[i].to]=dep[x]+1,dfs(e[i].to,x);
		}
}
inline int lca(int x,int y)
{
	for(;x!=y;x=Fa[x])
		if(dep[x]<dep[y]) swap(x,y);
	return x;	
}
int GetChain(int x,int fa)
{
	int son=0,val=1;
	for(int i=head[x];i;i=e[i].next)
		if(e[i].to!=fa)
		{
			++son;
			int res=GetChain(e[i].to,x);
			if(res==0) return 0;	
			else val+=res;
		}
	return son>1?0:val;
}
inline int CC(int n,int m){return 1LL*p[n]*inv[m]%mod*inv[n-m]%mod;}
int main()
{
	n=read();pw[0]=p[0]=inv[0]=inv[1]=p[1]=1;pw[1]=2;
	for(int i=2;i<=n;++i) p[i]=1LL*p[i-1]*i%mod,inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod,pw[i]=2*pw[i-1]%mod;
	for(int i=2;i<=n;++i) inv[i]=1LL*inv[i-1]*inv[i]%mod;
	for(int i=1,j;i<=n;++i) ++num[j=read()],ins(i,j);
	for(int i=1;i<=n;++i) if(num[i]>2) return 0*puts("0");
	for(int i=1;i<=n;++i) if(!vis[i]) 
	{
		vnum=top=0;dfs(i,0);C=lca(A,B);
		int len=dep[A]+dep[B]-2*dep[C]+1;
		if(len==vnum) {++cirnum[vnum];continue;}
		for(;A!=C;A=Fa[A]) c[++top]=A;c[++top]=C;top=len;
		for(;B!=C;B=Fa[B]) c[len--]=B;
		for(int j=1;j<=top;++j) in[c[j]]=1;
		for(int j=head[c[1]];j;j=e[j].next)
			if(e[j].to==c[2]) 
			{
				if(~j&1) 
					for(int l=1,r=top;l<r;++l,--r)
						swap(c[l],c[r]);
				break;	
			}
		for(int j=1;j<=top;++j)
		{
			Out[j]=0;
			for(int k=head[c[j]];k;k=e[k].next)
				if(!in[e[k].to])
				{
					Out[j]=GetChain(e[k].to,c[j]);
					if(!Out[j]) return 0*puts("0"); 
				}
		}
		int last,way=1;
		for(int j=top;j;--j) if(Out[j]) {last=top-j;break;}
		for(int j=1;j<=top;++j)
		{
			++last;
			if(!Out[j]) continue;
			if(Out[j]>last) return 0*puts("0");
			else if(Out[j]<last) way=way*2%mod;
			last=0;
		}
		ans=1LL*ans*way%mod;
	}
	for(int i=1;i<=n;++i) if(cirnum[i])
	{
		int way=(i==1||i%2==0)?1:pw[cirnum[i]];
		for(int j=1,k=i,i2=mod+1>>1;j<<1<=cirnum[i];++j,k=1LL*k*i%mod,i2=1LL*i2*(mod+1)/2%mod)
		{
			int thway=1LL*CC(cirnum[i],j*2)*CC(j*2,j)%mod*p[j]%mod*i2%mod*k%mod;
			if(i==1||i%2==0);else thway=1LL*thway*pw[cirnum[i]-2*j]%mod;
			way=(way+thway)%mod;
		}
		ans=1LL*ans*way%mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 11136
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
#define minn(x,y) x=min(x,y)
#define maxx(x,y) x=max(x,y)
using namespace std;
int a[1010][1010],in[1010][1010];
bool vis[1010][1010];
vector<pii> ve[1010][1010];
int main()
{
	int i,j,k,n,m,x,y,z;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		for(j=0;j<n-1;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	for(i=1;i<=n;i++)
	{
		for(j=0;j<n-2;j++)
		{
			in[min(i,a[i][j+1])][max(i,a[i][j+1])]++;
			ve[min(i,a[i][j])][max(i,a[i][j])].push_back(mp(min(i,a[i][j+1]),max(i,a[i][j+1])));
		}
	}
	vector<pii> vv,vv1;
	for(i=1;i<=n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			if(in[i][j]==0)
			{
				vv.push_back(mp(i,j));
				vis[i][j]=1;
			}
		}
	}
	int ans=0;
	while(!vv.empty())
	{
		ans++;
		for(i=0;i<vv.size();i++)
		{
			x=vv[i].fi;
			y=vv[i].se;
			for(j=0;j<ve[x][y].size();j++)
			{
				if(!vis[ve[x][y][j].fi][ve[x][y][j].se])
				{
					in[ve[x][y][j].fi][ve[x][y][j].se]--;
					if(in[ve[x][y][j].fi][ve[x][y][j].se]==0)
					{
						vis[ve[x][y][j].fi][ve[x][y][j].se]=1;
						vv1.push_back(ve[x][y][j]);
					}
				}
			}
		}
		vv=vv1;
		vv1.clear();
	}
	for(i=1;i<=n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			if(!vis[i][j])
			{
				printf("-1");
				return 0;
			}
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 48640
n, k = map(int, input().split())

preans = 0
j = 1

for i in range(1, n + 1):
    if i >= k:
        preans += 1
    else:
        while i * (2 ** j) < k:
            j += 1
        preans += 1 / (2 ** j)
        j = 1

ans = preans / n

print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF= 1LL << 60;
#define REP(i,n) for(ll i=0; i<n; i++)
#define FOR(i,a,n) for(ll i=a; i<n; i++)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string strs[] = {"dreamer", "dream", "eraser", "erase"};

    string s;
    cin >> s;
    string t= "";
    for(int i=s.size()-1; i>=0; i--){
        t= s[i]+t;
        REP(j,4){
            if(t==strs[j]) t= "";
        }
    }
    // cout << t << endl;
    cout <<((t=="")?"YES":"NO") << endl;

}

Measured memory_bytes: 592
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    ArrayList<Obj> listA = new ArrayList<>();
    ArrayList<Obj> listB = new ArrayList<>();
    for(int i = 0; i < n; i++){
      String s = sc.next();
      int left = 0;
      int right = 0;
      for(int j = 0; j < s.length(); j++){
        if(s.charAt(j) == '('){
          left++;
        } else if(s.charAt(j) == ')'){
          if(left > 0){
            left--;
          } else {
            right++;
          }
        }
      }
      Obj obj = new Obj(left,right);
      if(obj.left > obj.right){
        listA.add(obj);
      } else {
        listB.add(obj);
      }
    }
    if(solve(listA, listB)){
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }
  static boolean solve(ArrayList<Obj> listA, ArrayList<Obj> listB){
    listA.sort((o1, o2) -> o1.right - o2.right);
    listB.sort((o1, o2) -> o2.left - o1.left);
    int temp = 0;
    for(Obj a : listA){
      temp -= a.right;
      if(temp < 0) return false;
      temp += a.left;
    }
    for(Obj a : listB){
      temp -= a.right;
      if(temp < 0) return false;
      temp += a.left;
    }
    if(temp != 0) return false;
    return true;
  }

  static class Obj {
    int left;
    int right;
    public Obj(int left, int right){
      this.left = left;
      this.right = right;
    }
  }
}

Measured memory_bytes: 95432
N, M = map(int, input().split())
A=list(map(int,input().split()))
count=0
count2=0
flag=False
for i in range(N):
    count+=A[i]
for i in range(N):
    if A[i]>=count*1/(4*M) and flag==False:
        count2+=1
    if count2>=M:
        flag=True
        break
if flag:
    print("Yes")
else:
    print("No")

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

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

    s += s;

    vector<vector<int>> position(26, vector<int>());
    for (int i = 0; i < s.size(); i++)
    {
        position[s[i] - 'a'].push_back(i);
    }

    long long ans = 0;
    int current = -1;
    int next;
    for (char c : t)
    {
        if (position[c - 'a'].empty())
        {
            cout << -1 << endl;
            return 0;
        }

        auto itr = upper_bound(position[c - 'a'].begin(), position[c - 'a'].end(), current);
        if (itr == position[c - 'a'].end())
        {
            itr = position[c - 'a'].begin();
        }
        next = *itr;

        ans += next - current;
        current = next;
        current %= s.size() / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1784
#include <iostream>
using namespace std;
int main(){
  int n,k,a,c=0;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>a;
    if(a>k/2){
      c+=k-a;
    }else{
      c+=a;
    }
  }
  cout<<c*2;
}

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

bool can[3][200000];
int n, m;
int v[200000];
int to[200000];

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> v[i] >> to[i];
		v[i]--;
		to[i]--;
	}
	
	for (int i = 0; i < n; i++) {
		can[0][i] = can[1][i] = can[2][i] = 0;
	}
	can[0][0] = 1;
	
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < m; j++) {
			if (can[i][v[j]]) {
				can[i + 1][to[j]] = 1;
			}
			if (can[i][to[j]]) {
				can[i + 1][v[j]] = 1;
			}
		}
	}
	if (can[2][n - 1]) {
		cout << "POSSIBLE";
	} else {
		cout << "IMPOSSIBLE";
	}
	
    return 0;
}


Measured memory_bytes: 2432
#include <cstdio>
#include <cstring>
#define R register
#define Min(_A, _B) (_A < _B ? _A : _B)
#define Max(_A, _B) (_A > _B ? _A : _B)
#define Abs(_A) (_A > 0 ? _A : -(_A))
int t, u, v, tot, p1, p2, a[55];
int main()
{
	int n;
	scanf("%d", &n);
	for(R int i = 1; i <= n; i++) scanf("%d", &a[i]);
	u = v = a[1]; p1 = p2 = 1;
	for(R int i = 1; i <= n; i++)
	{
		if(u < a[i]) p1 = i, u = a[i];
		if(v > a[i]) p2 = i, v = a[i];
	}
	if(Abs(u) > Abs(v)) t = p1; else t = p2;
	printf("%d\n", n + n - 1);
	for(R int i = 1; i <= n; i++) printf("%d %d\n", t, i);
	if(a[t] > 0) for(R int i = 2; i <= n; i++) printf("%d %d\n", i - 1, i);
	else for(R int i = n; i > 1; i--) printf("%d %d\n", i, i - 1);
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using static System.Console;
using static System.Math;
class Simple {
    void Solve() {
        var A = io.Int;
        var B = io.Int;
        var C = io.Int;
        var ABC = new int[] {A, B, C};
        var ans = 0;
        while(ABC.Max() - ABC.Min() >= 2) {
            if(ABC[0] == ABC.Min()) {
                ABC[0] += 2;
            } else if(ABC[1] == ABC.Min()) {
                ABC[1] += 2;
            } else {
                ABC[2] += 2;
            }
            ans++;
        }
        var sameMax = ABC.Where(x => x == ABC.Max()).Count();
        if(sameMax == 3) {
            //
        } else if(sameMax == 2) {
            ans += 2;
        } else { //sameMax = 1
            ans++;
        }        
        WriteLine(ans);
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) => new Simple().Stream();
    private void Stream() {
        //var exStdIn = new System.IO.StreamReader("stdin.txt");
        //SetIn(exStdIn);
        Solve();
        io.Flush();
    }
}
class SimpleIO {
    string[] _nextBuffer;
    int _bufferCnt;
    char[] cs = new char[] {' ', '"', ','};
    StreamWriter sw = new StreamWriter(OpenStandardOutput()) {
#if DEBUG
        AutoFlush = true
#else
        AutoFlush = false
#endif
    };
    public SimpleIO() {
        _nextBuffer = new string[0];
        _bufferCnt = 0;
        SetOut(sw);
    }
    string Next() {
        if(_bufferCnt < _nextBuffer.Length)
            return _nextBuffer[_bufferCnt++];
        var st = ReadLine();
        while(st == "")
            st = ReadLine();
        _nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        _bufferCnt = 0;
        return _nextBuffer[_bufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void Flush() => Out.Flush();
}


Measured memory_bytes: 13396
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
map<char,int> tot;
int main(){
	string s;
	cin>>s;
	LL len=s.length();
	rep(i,len){
		tot[s[i]]++;
	} 
	LL res=len*(len-1);
	res>>=1;
	for(map<char,int>:: IT ite=tot.begin();ite!=tot.end();ite++){
		if(ite->SEC) res-=((LL)(ite->SEC)*((ite->SEC)-1))/2;
	}
	cout<<res+1<<endl;
	return 0;
}

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

int main() {
  int N; cin >>N;
  vector<int> H(N);
  for (int i=0; i<N;++i)cin >> H[i];
  
  int ans =0;
  int current_max =0;
  for (int i =0;i<N;++i){
    if (H[i]>=current_max)++ans;
    if (current_max<H[i])current_max=H[i];
  }
  cout <<ans <<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int A, B; cin >> A >> B;
  if (A <= 8 && B <= 8) cout << "Yay!" << endl;
  else                  cout << ":(" << endl;
}


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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

//#define _USE_MATH_DEFINES
//#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>
#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef int long long i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 1000000007; // 10000000000000007ll;

const double eps = 1e-8;

const i64 MAXN = 400005;
const i64 MAXM = 20;


i64 A, B, M;

i64 a[MAXN];
i64 b[MAXN];
map<pair<i64, i64>, i64> c;

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);


    cin >> A >> B >> M;

    for (i64 i = 1; i <= A; i++) {
        cin >> a[i];
    }

    for (i64 i = 1; i <= B; i++) {
        cin >> b[i];
    }

    for (i64 i = 1; i <= M; i++) {
        i64 u, v, w;
        cin >> u >> v >> w;


        c[{u, v}] = max(c[{u, v}], w);

    }

    i64 R = inf;
    for (auto t : c) {
        R = min(R, a[t.first.first] + b[t.first.second] - t.second);
    }

    sort(a + 1, a + A + 1);
    sort(b + 1, b + B + 1);

    R = min(R, a[1] + b[1]);

    cout << R << endl;


    return 0;
}

Measured memory_bytes: 9344
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <cmath>
using namespace std;

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18
// cout << fixed << setprecision(10);

int main()
{
    int S, W;
    cin >> S >> W;
    if (W >= S) {
        cout << "unsafe" << endl;
    }
    else {
        cout << "safe" << endl;
    }
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
vector<pair<ll,ll>> vec(N);
  for(ll i=0;i<N;i++) {
ll X,L;
    cin>>X>>L;
    vec[i]=make_pair(X+L,X-L);
  }
  
  sort(all(vec));
  ll ans=1;
  ll s=vec[0].first;
  for(ll i=1;i<N;i++) {
if(vec[i].second>=s) {
ans++;
  s=vec[i].first;
}
  }
  
  cout<<ans<<endl;
}
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  

Measured memory_bytes: 4744
import math
A = list(map(int,input().split()))
C2 = A[0]**2+A[1]**2-2*A[0]*A[1]*math.cos(math.pi*2*abs(A[2]/12+A[3]/60/12-A[3]/60))
print('{:.20f}'.format(math.sqrt(C2)))

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

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i,n) cin >> l[i];
  int ans = 0;
  rep(i,n)rep(j,n)rep(k,n) {
    if (i < j && j < k) {
      if (l[i] == l[j]) continue;
      if (l[i] == l[k]) continue;
      if (l[k] == l[j]) continue;
      if ((ll)l[i]+l[j]+l[k] <= max({l[i],l[j],l[k]})*2) continue;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3600
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

void dfs(const vector<vector<int>>&edges, int now, int pre,int rest,vector<int>&ans,bool flag) {

	ans[now]=true;
	if(rest==0)return;
	for (auto e : edges[now]) {
		if(e==pre)continue;
		else {
			if (flag&&edges[now].size() == 3) {
				flag=false;
				continue;
			}
			dfs(edges,e,now,rest-1,ans,flag);
			return ;
		}
	}
	return;
}

int main() {
	int N,S,T;cin>>N>>S>>T;
	S--;T--;

	vector<vector<int>>edges(N);
	for (int i = 0; i < N-1; ++i) {
		int a,b;cin>>a>>b;
		a--;b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	bool ok=false;

	if (N == 2) {
		ok=true;
	}
	else if (N%2==1||edges[S].size() > 2 || edges[T].size() > 2) {
		ok=false;
	}
	else {
		if (count_if(edges.begin(), edges.end(), [](const vector<int>&v) {return v.size() >= 4; }) >= 1) {
			ok=false;
		}
		else if (count_if(edges.begin(), edges.end(), [](const vector<int>&v) {return v.size() >= 3; }) >= 3) {
			ok=false;
		}
		else {
			for (int i = 0; i < edges[S].size() * 2; ++i) {
				for (int j = 0; j < edges[T].size() * 2; ++j) {
					vector<int>vs, vt;
					vs.resize(N); vt.resize(N);
					vs[S] = true;
					vt[T] = true;
					dfs(edges, edges[S][i / 2], S, N / 2 - 2, vs, i % 2 == 0);
					dfs(edges, edges[T][j / 2], T, N / 2 - 2, vt, j % 2 == 0);

					bool aok = true;
					for (int k = 0; k < N; ++k) {
						if (!vs[k] && !vt[k])aok = false;
					}
					if (aok)ok = true;
				}
			}
		}
		
	}

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


Measured memory_bytes: 9172
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
string s;
int ans = 0;
/**********************************************/

int main(){
    cin >> s;
    REP(i, s.size()){
        if(s[i] == '1') ans++; 
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
from itertools import zip_longest
N, M = map(int, input().split())

A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]

def isSame(h, w):
    for lineA, lineB in zip_longest(A[h: h + M], B, fillvalue=[]):
        for a, b in zip_longest(lineA[w: w + M], lineB, fillvalue='?'):
            if a != b:
                return False
    return True

for h in range(N):
    for w in range(N):
        if isSame(h, w):
            print('Yes')
            exit()

print('No')

Measured memory_bytes: 3064
N, C = map(int, input().split())
D = [list(map(int,input().split())) for i in range(C)]
c = [list(map(int,input().split())) for i in range(N)]

g0, g1, g2 = [0]*C, [0]*C, [0]*C
for i in range(N):
    for j in range(N):
        if (i+j)%3 == 0:
            g0[c[i][j]-1] += 1
        elif (i+j)%3 == 1:
            g1[c[i][j]-1] += 1
        elif (i+j)%3 == 2:
            g2[c[i][j]-1] += 1

ans = 10**20
for i in range(C):
    for j in range(C):
        for k in range(C):
            if i != j and j != k and k != i:
                # iはg0, jはg1, kはg2用の色
                tmp = 0
                for l in range(C):
                    tmp += D[l][i]*g0[l]
                    tmp += D[l][j]*g1[l]
                    tmp += D[l][k]*g2[l]
                ans = min(ans, tmp)

print(ans)
        

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

namespace mxfl{
  const int N=1e6, M=5e6;
  typedef int str;
  const str inf=1e9;
  
  struct E{
    int to; str fl; int nex;
  }e[M];
  int n, hea[N], cne, cur[N], st, en, d[N];
  void init(int n_=N-1){
    n=n_; cne=1;
    memset(hea,0,sizeof (int)*(n+1));
  }
  int adde(int u,int v,str w,str bw=0){
    e[++cne]=(E){v,w,hea[u]}; hea[u]=cne;
    e[++cne]=(E){u,bw,hea[v]}; hea[v]=cne;
    return cne;
  }
  bool bfs(){
    memset(d,33,sizeof d); d[st]=0;
    queue<int>q; q.push(st);
    for (int x,y,z;!q.empty();){
      x=q.front(); q.pop(); if (x==en) return 1;
      for (int i=hea[x];i;i=e[i].nex){
        if (!e[i].fl) continue;
        y=e[i].to; z=d[x]+1;
        if (z<d[y]) d[y]=z, q.push(y);
      }
    }
    return 0;
  }
  str dfs(int x,str F){
    if (x==en||!F) return F;
    str las=F;
    for (int &i=cur[x];i;i=e[i].nex){
      int y=e[i].to;
      if (!e[i].fl||d[y]!=d[x]+1) continue;
      str t=dfs(y,min(las,e[i].fl));
      las-=t; e[i].fl-=t; e[i^1].fl+=t;
      if (!las) break;
    }
    return F-las;
  }
  str realmain(int st_,int en_){
    st=st_; en=en_;
    str ans=0;
    for (;bfs();){
      memcpy(cur,hea,sizeof (int)*(n+1));
      ans+=dfs(st,inf);
    }
    return ans;
  }
}

int n, s, t, pre[101000], vis[101000];
vector<tuple<int,int,int> >vec;
vector<int>in[101000];

void dfs(int x){
    for (auto y:in[x])
        if (!vis[y]){
            vis[y]=x;
            dfs(pre[y]);
        }
}

int main(){
    cin>>n; s=n*2+1; t=n*2+2;
    mxfl::init(t);
    for (int i=1;i<=n-1;++i){
        int k, x; scanf("%d",&k);
        for (;k--;){
            scanf("%d",&x);
            in[x].push_back(i);
            vec.push_back(make_tuple(x,i,mxfl::adde(x,i+n,1)));
        }
    }
    for (int i=1;i<=n-1;++i){
        mxfl::adde(s,i,1);
        mxfl::adde(i+n,t,1);
    }
    if (mxfl::realmain(s,t)!=n-1){
        puts("-1"); exit(0);
    }
    for (auto o:vec){
        int u, v, id; tie(u,v,id)=o;
        if (mxfl::e[id].fl){
            pre[v]=u;
        }
    }
    dfs(n);
    if (*min_element(vis+1,vis+n)==0){
        puts("-1"); exit(0);
    }
    for (int i=1;i<=n-1;++i)
        printf("%d %d\n",pre[i],vis[i]);
}

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

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()

using namespace std;

typedef long long ll;

int main(){
    int n; ll ans = 0;
    cin >> n;
    vector<int> l(n+1, 0), r(n+1, 0);
    for(int i=0;i<n;i++)
        cin >> l[i] >> r[i];
    sort(rall(l));
    sort(all(r));
    for(int i=0;i<n;i++)
    {
        if(l[i] - r[i] <= 0)
            break;
        ans += l[i] - r[i];
    }
    cout << 2*ans << endl;
}


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

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    ll summin = b + (ll)(n-1) * a;
    ll summax = a + (ll)(n-1) * b;
    ll ans = summax - summin + 1;
    if (0 <= ans) cout << ans << endl;
    else cout << 0 << endl;
    return 0;
}

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

int main(){
  string S;
  cin >> S;
  
  int ans = 0;
  
  for (int i = 0; i < S.size(); i++){
    
    int count = 0;
    
    for(int j = 0; i + j< S.size();j++){
      char T = S[i+j];
      if (T != 'A' && T != 'C' && T != 'G' && T != 'T'){
        break;
      }
      count++;
    }
    ans = max(ans, count);
  }
  cout << ans;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-06-25 17:30:38 +0900
# LastModified: 2020-06-25 21:19:30 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    n = int(input())
    v = list(map(int, input().split()))
    v.sort(reverse=True)
    while len(v) != 1:
        s = v.pop()
        t = v.pop()
        v.append((s+t)/2)
    print(v[0])


if __name__ == "__main__":
    main()


Measured memory_bytes: 8884
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a[200005] = {};
    vector<int> z;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = n; i; i--) {
        if (a[i]) {
            z.push_back(i);
            for (int j = 1; j * j <= i; j++) if (i % j == 0) {
                a[j] = !a[j];
                if (j * j != i) a[i / j] = !a[i / j];
            }
        }
    }
    cout << z.size() << '\n';
    for (int i : z) cout << i << ' ';
}


Measured memory_bytes: 2552
#include<bits/stdc++.h>
using namespace std;
#define in(s) ll s; cin>>s
#define pr(r) cout<<r<<endl
#define prr(m,n) cout<<m<<" "<<n<<endl
#define prarr(a,i,n) fab(j,i,n) cout<<a[j]<<" "
#define wh(t) ll t; cin>>t; while(t--)
#define sz(u) u.size()
#define all(v) v.begin(),v.end()
#define arr(a,n) ll a[n]; fab(i,0,n) cin>>a[i]
#define showdp(d,n,m) fab(i,0,n){ fab(j,0,m) if(d[i][j]==-1 || d[i][j]>9) cout<<d[i][j]<<" "; else cout<<" "<<d[i][j]<<" "; cout<<endl; }
#define prs(u) cout<<u<<" "
#define fab(i,a,b) for(ll i=a;i<b;i++)
#define fba(i,b,a) for(ll i=b;i>=a;i--)
#define sup ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MX 1000000007
#define MAX 10000007
#define endl "\n"
#define ll long long int
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define pl pair<ll,ll>
#define pll pair<ll,pl>
#define vvl vector<vl>
#define mxe(x,n) *max_element(x,x+n)
#define mne(x,n) *min_element(x,x+n)
#define mp make_pair
#define pb push_back
#define fs first
#define sd second
#define fr front()
#define bk back()
#define rr return
#define N 300005
#define inf 1e18+7
 
bool rsort1(const pair<ll,ll> &a,const pair<ll,ll> &b) { return (a.first > b.first);}
bool rsort2(const pair<ll,ll> &a,const pair<ll,ll> &b) { return (a.second>b.second);}
bool sort2(const pair<ll,ll> &a,const pair<ll,ll> &b){ return (a.second < b.second);}
 
bool isPrime(ll p)
{
    for(ll i=2;i*i<=p;i++)
        if(p%i==0)
            rr false;
    rr true;
}
 
void sieve(ll n,vl &v)
{
    v.pb(2);
    bool prime[n+1];
    memset(prime,true,sizeof(prime));
    for(ll i=3;i*i<=n;i+=2)
        if(prime[i])
            for(ll j=i;j*i<=n;j+=2)
                prime[j*i]=false;
        
    for(ll i=3;i<=n;i+=2)
        if(prime[i])
            v.pb(i);
}

ll phi(ll n)
{
    ll result=n;
    for(ll p=2;p*p<=n;p++)
    {
        if(n%p==0)
        {
            while(n%p==0)
                n/=p;
            result-=result/p;
        }
    }

    if(n>1)
        result-=result/n;
    return result;
}


int main()
{
	sup;
    
    ll a,b;
    cin>>a>>b;
    if(a>b)
    {
        fab(i,0,a)
        cout<<b;
    }
	else 
    {
        fab(i,0,b)
        cout<<a;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, s, n) for(int i = s; i < n; i++)
using namespace std;

int a[500][500];
vector<int> ys;
vector<int> xs;
vector<int> yys;
vector<int> xxs;
void move(int y, int x, int yy, int xx) {
    a[yy][xx]++;
    ys.push_back(++y);
    xs.push_back(++x);
    yys.push_back(++yy);
    xxs.push_back(++xx);

}


int main(void) {
    int h, w;
    cin >> h >> w;
    rep(i, h) rep(j, w) cin >> a[i][j];

    int n = 0;
    rep(i, h) {
        rep(j, w-1) {
            if (a[i][j] % 2 == 1) {
                move(i, j , i, j+1);
            }
        }
    }
    rep(i, h-1) {
        if (a[i][w-1] % 2 == 1) {
            move(i, w-1, i+1, w-1);
        }
    }

    cout << ys.size() << endl;
    rep(i, ys.size()) {
        cout << ys[i] << " ";
        cout << xs[i] << " ";
        cout << yys[i] << " ";
        cout << xxs[i] << endl;
    }
}


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

const int MAX_N = 500;

int n, m;
int isfriend[MAX_N][MAX_N];

int main() {
	while (cin >> n >> m, n || m) {
		memset(isfriend, 0, sizeof(isfriend));
		for (int i = 0; i < m; i++) {
			int a, b;
			cin >> a >> b;
			isfriend[a][b] = isfriend[b][a] = 1;
		}
		int cnt = 0;
		for (int i = 2; i <= n; i++) {
			if (isfriend[1][i]) {
				cnt++;
			}
			else {
				for (int j = 2; j <= n; j++) {
					if (isfriend[1][j] && isfriend[j][i]) {
						cnt++;
						break;
					}
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 2144
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    ll sum = 0;
    vector<ll> A(N);
    ll pre = 0;
    rep(i, N) {
        cin >> A[i];
        sum += abs(pre - A[i]);
        pre = A[i];
    }
    sum += abs(A.back());
    print(sum - (abs(A[0]) + abs(A[0] - A[1])) + abs(A[1]));
    for(ll i = 1; i < N-1; i++) {
        print(sum - (abs(A[i-1] - A[i]) + abs(A[i] - A[i+1])) + abs(A[i-1] - A[i+1]));
    }
    print(sum - (abs(A[N-2]-A.back())+abs(A.back())) + abs(A[N-2]));
    return 0;
}

Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
using namespace std;
int table[20][20];
int d,w;
const int N=-1;

int check(int y,int x,int dy,int dx){
	int cntmax=N;
	for(int i=y;i<=y+dy;i++){
		for(int j=x;j<=x+dx;j++)cntmax=max(cntmax,table[i][j]);
	}
	int cntmin=1000000;
	for(int i=y-1;i<=y+dy+1;i++){cntmin=min(cntmin,table[i][x-1]);cntmin=min(cntmin,table[i][x+dx+1]);}
	for(int i=x-1;i<=x+dx+1;i++){cntmin=min(cntmin,table[y-1][i]);cntmin=min(cntmin,table[y+dy+1][i]);}
	if(cntmax>=cntmin)return N;
	
	int sum=0;
	for(int i=y;i<=y+dy;i++){
		for(int j=x;j<=x+dx;j++)sum+=cntmin-table[i][j];
	}
	return sum;
}

int main(){
	while(cin>>d>>w,d||w){
	for(int i=0;i<=d+1;i++)for(int j=0;j<=w+1;j++)table[i][j]=N;
	for(int i=1;i<=d;i++){
		for(int j=1;j<=w;j++)cin>>table[i][j];
	}
	int ans=0;
	for(int i=2;i<d;i++){
		for(int j=2;j<w;j++){
			for(int y=0;y+i<d;y++){
				for(int x=0;x+j<w;x++){
						
						ans=max(ans,check(i,j,y,x));//i,j??????i+y,x+j?????????????±???¨??????????????????????????¢?????????????????????????????°-1?????????
					}
			}
		}
	}
	cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3112
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <math.h>
#include <string.h>
#include <map>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#define INF 1000000
#define MAX 500000
#define pb push_back
#define mp make_pair
#define UNVISITED 0
using namespace std;
typedef long long int ll;
typedef vector <ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
int main()
{
 // freopen("input.txt","r",stdin);
 // freopen("output.txt","w",stdout);
  ll n;
  long int arr[300005];
  ll sum=0;
  cin>>n;
  for(int i=0;i<3*n;i++)
    cin>>arr[i];
  sort(arr,arr+3*n);
  reverse(arr,arr+3*n);
  ll cnt=0;
  for(ll i=1;i<3*n;i+=2)
  {
    if(cnt==n)
      break;
sum+=arr[i];
cnt++;
  }
cout<<sum<<endl;
return 0;
}



Measured memory_bytes: 2560
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int):
    print(max(0, C-(A-B)))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int N, K;
int main(int argc, char const *argv[])
{
    cin >> N >> K;
    int ans=1;
    for(int i=0;i<N;i++){
        ans=min(ans*2,ans+K);
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	int N, M, k, a;
	int count = 0;
	int data[30] = {};
	cin >> N >> M;
	for(int i = 0; i < N; i++){
		cin >> k;
		for(int j = 0; j < k; j++){
			cin >> a;
			data[a-1]++;
		}
	}
	for(int i = 0; i < M; i++){
		if(data[i] == N){
			count++;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	static final int mod = (int) 1e9 + 7;
	static final int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int[] DX8 = { -1, -1, -1, 0, 0, 1, 1, 1 }, DY8 = { -1, 0, 1, -1, 1, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;
	static final String nextLine = "\n";

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		long x = fs.nextLong(), y = fs.nextLong();
		int cnt = 0;
		while(x<=y) {
			x *= 2;
			cnt++;
		}
		System.out.println(cnt);
	}

	//MOD culculations
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

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

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 21204
#include <iostream>

template<typename T>
inline T input(){T t; std::cin >> t; return t;}

int main(){
    std::ios::sync_with_stdio(false);
    auto N = input<int>();
    while(N--){
        const auto K = input<int>();
        const auto P = input<int>();
        std::cout << (K%P == 0 ? P : K%P) << std::endl;
    }
}

Measured memory_bytes: 1192