akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using static System.Console;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        solve();
    }
    static Scanner cin;

    static int[,] Map = new int[3, 3];
    static int[] a = new int[3];
    static int[] b = new int[3];
    static void input()
    {
        cin = new Scanner();
        for (int y = 0; y < 3; y++)
        {
            for(int x = 0; x < 3; x++)
            {
                Map[y, x] = cin.nextInt();
            }
        }
    }
    static void solve()
    {
        input();
        for(int i = 0; i <= Map[0,0]; i++)
        {
            a[0] = i;
            b[0] = Map[0, 0] - a[0];
            a[1] = Map[1, 0] - b[0];
            b[1] = Map[1, 1] - a[1];
            a[2] = Map[2, 1] - b[1];
            b[2] = Map[2, 2] - a[2];
            if (b.Min() < 0 || a.Min() < 0)
                continue;

            if (Map[2, 0] != a[2] + b[0] ||
               Map[0, 1] != a[0] + b[1] ||
               Map[0, 2] != a[0] + b[2] ||
               Map[1, 2] != a[1] + b[2])
            {
                continue;
            }
            WriteLine("Yes");
            return;
        }
        WriteLine("No");
    }
    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }
        
        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }

        public double[] ArrayDounble(int N, int add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define N 100100
using namespace std;
typedef unsigned long long LL;
int k;
int a[N];
int main(){
	scanf("%d",&k);
	LL l=2,r=2;
	for(int i=0;i<k;i++) scanf("%d",&a[i]);
	for(int i=k-1;i>=0;i--){
		if((l-1)/a[i]==r/a[i]){
			puts("-1");
			exit(0);
		}
		l=((l-1)/a[i])*a[i]+a[i];
		r=(r/a[i])*a[i]+a[i]-1;
	}
	cout<<l<<" "<<r<<"\n";
	return 0;
}

Measured memory_bytes: 640
n = int(input())
b = list(map(int, input().split()))
sum_a = 0
for i in range(n):
    if i == 0:
        sum_a += b[i]
    elif i == n - 1:
        sum_a += b[i - 1]
    else:
        sum_a += min(b[i], b[i - 1])
print(sum_a)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

void f(vector<pair<char,int>> &a){
	while(1){
		char c;
		int x;
		cin>>c;
		if(c=='$') break;
		cin>>x;
		a.push_back(make_pair(c,x));
	}
}

vector<pair<char,int>> a,b,c,d,res,ans;

int main(){
	f(a),f(b),f(c),f(ans);
	d=a;
	int n=a.size(),m=b.size();
	for(int i=0;i+m-1<n;i++) if(a[i].first==b[0].first&&a[i].second>=b[0].second){
		bool B=1;
		for(int j=1;j<m;j++){
			if(a[i+j].first!=b[j].first) B=0;
			if(j<m-1&&a[i+j].second!=b[j].second) B=0;
			if(j==m-1&&a[i+j].second<b[j].second) B=0;
		}
		if(B){
			d.clear();
			for(int j=0;j<i;j++) d.push_back(a[j]);
			if(m>1) d.push_back(make_pair(a[i].first,a[i].second-b[0].second));
			for(auto p:c) d.push_back(p);
			d.push_back(make_pair(a[i+m-1].first,a[i+m-1].second-b[m-1].second));
			for(int j=i+m;j<n;j++) d.push_back(a[j]);
			break;
		}
	}
	n=d.size();
	for(int i=0;i<n;i++) if(d[i].second) res.push_back(d[i]);
	d=res;
	res.clear();
	n=d.size();
	for(int i=0;i<n;){
		char c=d[i].first;
		int x=0;
		while(i<n&&c==d[i].first){
			x+=d[i].second;
			i++;
		}
		res.push_back(make_pair(c,x));
	}
	for(int i=0;i<res.size();i++) cout<<res[i].first<<' '<<res[i].second<<' ';
	cout<<'$'<<endl;
}


Measured memory_bytes: 3184
#include <cstdio>

const char COLORS[] = "RYGB";

int main()
{
    int n, m, d;
    scanf("%d%d%d", &n, &m, &d);
    // if (d & 1) {
    //     for (int i = 0; i < n; ++ i) {
    //         for (int j = 0; j < m; ++ j) {
    //             putchar("RY"[i + j & 1]);
    //         }
    //         puts("");
    //     }
    // } else {
    // }
    for (int i = 0; i < n; ++ i) {
        for (int j = 0; j < m; ++ j) {
            int x = (i + m - j) / d % 2;
            int y = (i + j) / d % 2;
            putchar(COLORS[x * 2 + y]);
        }
        puts("");
    }
}

Measured memory_bytes: 512
#input
N = int(input())
A = list(map(int,input().split()))
#b = int(input())

#s = [0,0,0]
#s[0] = int(input/100)
#s[1] = int(input/10 - s[0]*10)
#[2] = int(input%10)

count = 0
flag = 0

#loop
while(1):
  for i in range(N):
    
    if A[i] %2 == 1:
      flag = 1
    else:
      temp = A[i]/2
      A[i] = temp;
  
  #judge
  if flag == 1:
    break
  else:
    count +=1
    #print(A)

#print('result')
#print(A)
print(count)


Measured memory_bytes: 3060
p=input
n,m=map(int,p().split())
l=[[int(i)for i in p().split()]for _ in[0]*n]
r=[1,-1]
print(max([sum(sorted([sum([x[i]*r[k>>i&1]for i in range(3)])for x in l],reverse=True)[:m])for k in range(8)]))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define ull unsigned long long int
#define forn(i,n)for(ll i=0;i<(n);i++)
#define forn_rev(i,n)for(ll i=(n)-1;i>=0;i--)
#define for1n(i,n) for(ll i=1;i<=(n);i++)
#define ARRAY_SIZE(a) sizeof(a)/sizeof(*a)
#define MOD 1000000007
#define MAXN 100005
#define PI 3.1415926535897932384626433
#define gcd(a,b) __gcd(a,b)

using namespace std;

ll power(ll x,ll y,ll p)
{
    ll res=1;
    x=x%p;
    if(x==0)
        return 0;
    while(y>0)
    {
        if(y&1)
            res=(res*x)%p;
        y=y>>1;
        x=(x*x)%p;
    }
    return res;
}



int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);cout.tie(NULL);

    ll T=1;
    //cin>>T;
    while(T--)
    {
        ld a,b;
        cin>>a>>b;
        cout<<(long long int)(a*b);



    }


    return 0;
}

Measured memory_bytes: 3804
def check_bracket(str)
  stack = []
  str.chars do |st|
    if st =~ /(\[|\()/
      stack.push(st)
    elsif st == "]" and stack.pop != "["
      return "no"
    elsif st == ")" and stack.pop != "("
      return "no"
    end
  end
  return stack.empty? ? "yes" : "no"
end

while gets do
  str = $_.chomp
  break if str == "."
  puts check_bracket(str)
end

Measured memory_bytes: 6176
import std.stdio;
import std.string;
import std.conv;
import std.range;
import std.array;
import std.algorithm;

void main(){
    auto abc = readln().chomp().split().map!(to!int).array();
    auto k = readln().chomp().to!int();
    solve(abc, k).writeln();
}

int solve(int[] input, int k){
    int result;
    
    auto sortedInput = input.sort!("a > b")().array();
    foreach(int i, num; sortedInput){
        if(i == 0){
            result += num * (2 ^^ k);
        }else{
            result += num;
        }
    }
    
    return result;
}

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

#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node *Node;

Node root;
int exist;

Node treeMinmum(Node x){
  while(x->left != NIL) x = x->left;
  return x;
}

Node treeMaxmum(Node x){
  while(x->right != NIL) x = x->right;
  return x;
}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u;
  if(k<u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
}

Node treeSuccessor(Node x){
  Node y=NIL;
  
  if(x->right != NIL) return treeMinmum(x->right);

  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y;
  Node x;

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x!=NIL) x->parent = y->parent;
  
  if(y->parent == NIL) root = x;
  else if(y==y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y!=z) z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y==NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;

  
}

void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}

void preorder(Node u){
  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}

void find(Node u,int k){
  if(u->key==k){
    printf("yes\n");
    exist = 1;
    return;
  }else{
    if(u!=NIL){
      find(u->left,k);
      find(u->right,k);
    }
    return;
  }
}

int main(){
  root = malloc(sizeof(Node));
  root = NIL;
  
  int n,i,x;
  char com[20];
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='f'){
      scanf("%d",&x);
      Node t = treeSearch(root,x);
      if(t!=NIL) printf("yes\n");
      else printf("no\n");
    }else if(com[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }else if(com[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(com[0]=='d'){
      scanf("%d",&x);
      treeDelete(treeSearch(root,x));
    }else if(com[0]=='f'){
      exist = 0;
      scanf("%d",&x);
      find(root,x);
      if(exist==0) printf("no\n");
    }
  }

  return 0;
		  
}



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

int main()
{

    int n;
    string str[105];
    while(cin>>n)
    {
        bool fla=0;
        for(int i=0;i<n;i++)
        {
            cin>>str[i];
        }
        for(int i=1;i<n;i++)
        {
            for(int j=0;j<i;j++)
            {
                if(str[i]==str[j])
                {
                    fla=1;
                    break;
                }
            }
            if(fla||str[i][0]!=str[i-1][str[i-1].size()-1])
            {
                fla=1;
                break;
            }
        }
        if(fla)
            printf("No\n");
        else
            printf("Yes\n");
    }
    return 0;
}


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c;
    map<int,int>helper;
    cin >> a >> b >> c;
    helper[a]++;
    helper[b]++;
    helper[c]++;
    helper[5]==2&&helper[7]==1?cout << "YES" <<endl:cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 3632
def main():
    while True:
        n = int(input())
        if n == 0:
            break
        m = int(input())
        s = input()
        pn = "IOI" + ("OI" * (n-1))
        limit = len(pn)
        searchflag = False
        nextI = False
        tmp = []
        start = 0
        i = 0
        ans = 0
        while i < m:
            if searchflag:
                if not nextI and s[i] == "O":
                    nextI = not nextI
                elif nextI and s[i] == "I":
                    nextI = not nextI
                else:
                    if s[i-1] == "I":
                        searching = s[start:i]
                    else:
                        searching = s[start: i - 1]
                    i -= 1
                    if len(searching) >= limit:
                        tmp.append(searching)
                    searchflag = not searchflag
            else:
                if s[i] == "I":
                    start = i
                    nextI = False
                    searchflag = True
            i += 1
        for i in range(len(tmp)):
            ans += len(tmp[i]) // 2 - n + 1
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 7320
//B-Ruined_Square
#include <iostream>
using namespace std;

int main()
{
  int x1,y1,x2,y2,x3,y3;
  cin>>x1>>y1>>x2>>y2;
  
  x3=x2+y1-y2;
  y3=y2+x2-x1;
  cout<<x3<<" "<<y3<<" "<<x3-(x2-x1)<<" "<<y3-(y2-y1)<<endl;
  return 0;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(obj) (obj).begin(),(obj).end()
typedef long long ll;
ll mod=2e12;
ll cnt=0;
#define max 100005
#define nil -1


int main(){
  int n,q,w,e;
  int m[105][105];
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>q>>w;
    for(int j=1;j<=n;j++)m[i][j]=0;
    for(int j=1;j<=w;j++){
      cin>>e;
      m[i][e]=1;
    }
  }
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      if(j!=1)cout<<' ';
      cout<<m[i][j];
    }
    cout<<endl;
  }
   return 0;
}



Measured memory_bytes: 3124
def examC():
    N = I()
    A = LI()
    cost1 = [0]*(N+1); cost2 = [0]*(N+1)
    A.append(0)
    for i in range(N+1):
        cost1[i] = abs(A[i]-A[i-1])
        cost2[i] = abs(A[i]-A[i-2])
    ans = []
    cost = sum(cost1)
    for i in range(N):
        cur = cost - cost1[i] - cost1[i+1] + cost2[i+1]
        ans.append(cur)
    for v in ans:
        print(v)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()


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

public class Main {
    public static void main(String[] args) {
        // Your code here!
        Scanner sc = new Scanner(System.in);        
        String Ns = sc.next();

	    int N = Integer.parseInt(Ns);

        
        int A[] = new int[N];
        for(int i=0; i<N; i++){
            A[i] = sc.nextInt();
        }
        
        for(int i=0; i<N; i++){
    	    if((A[i]%2)==0){
    	       if((A[i]%3)==0 || (A[i]%5)==0){
    	           
    	       }else{
                   System.out.println("DENIED");
    	           return ;
    	       }
    	    }
	    }
        System.out.println("APPROVED");
    }
}

Measured memory_bytes: 24020
#include<bits/stdc++.h>
#define ll long long
#define MAXN 100005

#define INF 0x3f3f3f3f
#define ld long double
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    #define int ll
    int n,m;
    cin>>n>>m;
    int s=0;
    for(int i=0;i<m;i++){
        int tp;
        cin>>tp;s+=tp;
    }
    if(s>n){
        cout<<-1<<endl;
    }
    else{
        cout<<n-s<<endl;
    }
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>

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

using namespace std;

typedef long long ll;

int H, W;
int a[505][505];

vector<pair<int, int>> src, dst;


int main() {
  
  scanf("%d %d", &H, &W);
  
  rep(i, 1, H+1) {
    rep(j, 1, W+1) {
      scanf("%d", &a[i][j]);
    }
  }
  
  rep(i, 1, H+1) {
    if (i%2==1) {
      rep(j, 1, W+1) {
        if (a[i][j]%2==1){
          if ( j != W) {
            src.pb(make_pair(i, j));
            dst.pb(make_pair(i, j+1));
            a[i][j+1]++;          
          } else if ( j == W && i != H) {
            src.pb(make_pair(i, j));
            dst.pb(make_pair(i+1, j));
            a[i+1][j]++; 
          }   
        }     
      }
    } else {
      per(j, 1, W+1) {
        if (a[i][j]%2==1){
          if ( j != 1) {
            src.pb(make_pair(i, j));
            dst.pb(make_pair(i, j-1));
            a[i][j-1]++;          
          } else if ( j == 1 && i != H) {
            src.pb(make_pair(i, j));
            dst.pb(make_pair(i+1, j));
            a[i+1][j]++; 
          }   
        }     
      }
    
    }
  
  }
  printf("%d\n", (int)src.size());
  for (int i = 0; i < src.size(); i++) {
    printf("%d %d %d %d\n", src[i].first, src[i].second, dst[i].first, dst[i].second);
  }
  
  return 0;
}
 


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

const int MOD = ( int ) 1e9 + 7;

const int MAXN = ( int ) 1e5;
const int MAXM = ( int ) 1e5;

int N, M;
int X[ MAXN ], Y[ MAXM ];

signed main(){
  ios::sync_with_stdio( 0 );
  cin >> N >> M;
  for( int i = 0; i < N; ++i ){
    cin >> X[ i ];
  }
  for( int i = 0; i < M; ++i ){
    cin >> Y[ i ];
  }
  sort( X, X + N );
  sort( Y, Y + M );
  int a = 0, b = 0;
  for( int i = 1, prev = 0; i < N; ++i ){
    ( a += prev ) %= MOD;
    ( prev += ( 1LL * X[ i ] - X[ i - 1 ] ) * i % MOD ) %= MOD;
    ( a += ( 1LL * X[ i ] - X[ i - 1 ] ) * i % MOD ) %= MOD;
  }
  for( int i = 1, prev = 0; i < M; ++i ){
    ( b += prev ) %= MOD;
    ( prev += ( 1LL * Y[ i ] - Y[ i - 1 ] ) * i % MOD ) %= MOD;
    ( b += ( 1LL * Y[ i ] - Y[ i - 1 ] ) * i % MOD ) %= MOD;
  }
  cout << 1LL * a * b % MOD << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n,a[10010][10010],t=0;
bool flag[10010],fl=0;
bool judge()
{
	for(int i=1;i<=n;++i)
		if(a[i][0]!=n)
			return 0;
	return 1;
}

int main()
{	cin>>n;
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<n;++j)
			scanf("%d",&a[i][j]);
		a[i][0]=1;
	}
	while(1)
	{
		if(judge())
		{
			printf("%d\n",t);
			return 0;
		}
		fl=0;
		memset(flag,0,sizeof(flag));
		++t;
		for(int i=1;i<=n;++i)
		{
			if(flag[i] || a[i][0]==n) 
				continue;
			int x=a[i][a[i][0]],y=a[x][a[x][0]];
			if(!flag[x] && !flag[i] && i==y)
			{
				fl=1;
				flag[x]=1;flag[i]=1;
				++a[i][0];++a[x][0];
			}
		}
		if(!fl)
		{
			printf("-1\n");
			return 0;
		}
	}
	return 0;
} 
// test

Measured memory_bytes: 39552
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    rep(i, n) sort(all(s[i]));
    sort(all(s));
    s.push_back("HOGE");
    int ans = 0, cnt = 1;
    rep(i, n)
    {
        if (s[i] == s[i + 1])
            cnt++;
        else
        {
            ans += (cnt * (cnt - 1)) / 2;
            cnt = 1;
        }
    }
    cout << ans << endl;
}

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

int main(){
	long N,M;
	cin>>N>>M;
	long deka=max(N,M);
	long mini=min(N,M);
	if(mini>=3){
		cout<<(deka-2)*(mini-2)<<endl;
	}
	else if(deka>=3 && mini==2){
		cout<<0<<endl;
	}
	else if(deka>=3 && mini==1){
		cout<<deka-2<<endl;
	}
	else if(deka==2 && mini==2){
		cout<<0<<endl;
	}
	else if(deka==2 && mini==1){
		cout<<0<<endl;
	}
	else if(deka==1 && mini==1){
		cout<<1<<endl;
	}
}


Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d", $n);
$w_arr = [];
for ($i = 0; $i < $n; ++$i) {
    $w_arr[] = trim(fgets(STDIN));
}

$tmp = [];
foreach($w_arr as $w) {
    if (!isset($tmp[$w])) {
        $tmp[$w] = 1;
        continue;
    }
    ++$tmp[$w];
}
if (max($tmp) !== 1) {
    echo 'No';
    return;
}

$flg = true;
$last_char = substr($w_arr[0], -1);
for ($i = 1; $i < $n; ++$i) {
    $tmp_char = substr($w_arr[$i], 0, 1);

    if ($last_char !== $tmp_char) {
        $flg = false;
        break;
    }
    
    $last_char = substr($w_arr[$i], -1);
}

echo $flg ? 'Yes' : 'No';


Measured memory_bytes: 4604
_, w, *ms = STDIN.read.lines.map(&:split).flatten
w = w.to_i
ms = ['a'*(w+2), ms.map{ |l| "a#{l.chomp}a"}, 'a'*(w+2)].flatten.map { |l| l.chars }
ans = ms.map.with_index do |line, i|
  line.map.with_index do |c, j|
    if c == "."
      cnt = 0
      [1,0,-1].each do |x|
        [1,0,-1].each do |y|
          cnt += 1 if ms[i+x][j+y] == '#'
        end
      end
      cnt
    else
      c
    end
  end
end
puts ans[1..(ans.length-2)].map(&:join).map{ |e| e[1..(e.length-2)]}


Measured memory_bytes: 2172
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vvc c(N,vc(N));
    rep(i,N){
        rep(j,N){
            cin >> c[i][j];
        }
    }
    int ans=0;
    rep(i,N){
        bool b=true;
        rep(j,N){
            rep(k,N){
                if(c[(i+j)%N][k]!=c[(i+k)%N][j])b=false;
            }
        }
        if(b)ans+=N;
    }
    cout << ans << endl;
}

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

ll MAX_N = 2222222ll;
vector<ll> FAC(MAX_N, 0);
vector<ll> IFAC(MAX_N, 0);
vector<ll> FACM(MAX_N, 0);
ll MOD = 998244353ll;

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

void fa(){
    FAC[0] = 1ll;
    IFAC[0] = 1ll;
    for(ll i=1ll;i<MAX_N;i++){
        FAC[i] = (FAC[i-1] * i) % MOD;
        IFAC[i] = (IFAC[i-1] * mpow(i, MOD-2)) % MOD;
    }
}

ll ncr(ll n, ll r){
    if (r==0) return 1ll;
    ll ans = FAC[n];
    ans = (ans * IFAC[r]) % MOD;
    ans = (ans * IFAC[n-r]) % MOD;
    return ans;
}

void fam(ll m){
    FACM[0] = 1ll;
    for(int i=1;i<MAX_N;i++){
        FACM[i] = (FACM[i-1] * (m-1ll)) % MOD;
    }
}

ll nm(ll n, ll m){
    ll ans = (m * FACM[n-1]) % MOD;
    return ans;
}

int main(void)
{
    fa();
    ll N, M, K;
    cin >> N >> M >> K;
    fam(M);
    
    ll ans = 0ll;
    for(int k=0;k<=K;k++){
        ll pair = ncr(N-1, k);
        ll pa = nm(N-k, M);
        ans += (pair*pa ) % MOD;
        ans = ans % MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 55100
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string.h>

using namespace std;

#define _ABS(X) (((X) < 0) ? -(X) : (X))

int get_cnt(int num)
{
	int ret = 0;

	while (num)
	{
		ret++;
		num /= 10;
	}

	return ret;
}

int main()
{
	int N, ans = 0;

	scanf("%d", &N);

	for (int i = 1; i <= N; ++i)
	{
		if (get_cnt(i) & 1) ans++;
	}

	printf("%d\n", ans);

	return 0;
}

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

#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define clr(arr, key) memset(arr, key, sizeof arr)
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define infinity (1 << 28)
#define LL long long
#define PI acos(-1)
#define gcd(a, b) __gcd(a, b)
#define CF ios_base::sync_with_stdio(0);cin.tie(0);
#define lcm(a, b) ((a)*((b)/gcd(a,b)))
#define all(v) v.begin(), v.end()
#define no_of_ones __builtin_popcount // __builtin_popcountll for LL
#define SZ(v) (int)(v.size())
#define eps 1e-7

//int col[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//int row[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//int col[4] = {1, 0, -1, 0};
//int row[4] = {0, 1, 0, -1};
//int months[13] = {0, ,31,28,31,30,31,30,31,31,30,31,30,31};

using namespace std;

struct point{int x, y; point () {} point(int a, int b) {x = a, y = b;}};
template <class T> T sqr(T a){return a * a;}
template <class T> T power(T n, T p) { T res = 1; for(int i = 0; i < p; i++) res *= n; return res;}
template <class T> double getdist(T a, T b){return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));}    // distance between a and b
template <class T> T extract(string s, T ret) {stringstream ss(s); ss >> ret; return ret;}
template <class T> string tostring(T n) {stringstream ss; ss << n; return ss.str();}
//LL bigmod(LL B,LL P,LL M){LL R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;}
struct fast{fast(){ios_base::sync_with_stdio(0);cin.tie(0);}}cincout;

#define MAX 100010
/***********************************THE GRASS IS ALWAYS GREENER ON THE OTHER SIDE***********************************/

int main()
{
    // in;
    int d, n, k, x, s[MAX];
    cin >> n >> k;
    clr(s, 0);
    int res = 0;
    for(int i = 1; i <= n; i++){
        cin >> d;
        for(int j = 0; j < d; j++)
        {
            cin >> x;
            s[x]++;
        }
    }
    for(int i = 1; i <= n; i++)
        res += s[i] == 0;
    cout << res << "\n";
    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n, k;
    cin >> n >> k;

    while (true) {
        if (k == 0 || n == 0) break;
        n = n % k;
        if (n == n % k) {
            n = min(n, abs(n - k));
            break;
        }
    }
    cout << n << endl;

    return 0;
}


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

int main() {
  int n,c=1;
  cin >> n;
  for (int i; i<n; i++){
    int x;
    cin >> x;
    if (x%2==0 && x%3!=0 && x%5!=0){
      c=0;
    }
  }
  if (c==1){
    cout << "APPROVED" << endl;
  }
  else{
    cout << "DENIED" << endl;
  }
}

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

using namespace std;
string s, t, ans;
int lcs[3000][3000];
char p[3000][3000];

int solve(int a, int b) {
	if(a < 0 || b < 0)
		return 0;

	if(lcs[a][b] != -1)
		return lcs[a][b];
	if(s[a] == t[b]) {
		lcs[a][b] = 1 + solve(a - 1, b - 1);
		p[a][b] = 'D';
		return lcs[a][b];
	}
	int tmp_1 = solve(a - 1, b);
	int tmp_2 = solve(a, b - 1);
	if(tmp_1 >= tmp_2) { 
		lcs[a][b] = tmp_1;
		p[a][b] = 'U';
	}
	else {
		lcs[a][b] = tmp_2;
		p[a][b] = 'L';
	}
	lcs[a][b] = max(solve(a - 1, b), solve(a, b - 1));
	return lcs[a][b];
}

void print_lcs(int a, int b) {
	if(a < 0 || b < 0)
		return;
	if(p[a][b] == 'D') {
		print_lcs(a - 1, b - 1);
		cout << s[a];
	}
	else {
		if(p[a][b] == 'U')
			print_lcs(a - 1, b);
		else
			print_lcs(a, b - 1);
	}
}

int main() {
	cin >> s >> t;
	for(int i = 0 ; i < s.size() ; i++) {
		for(int j = 0 ; j < t.size() ; j++)
			lcs[i][j] = -1;
	}
	solve(s.size() - 1, t.size() - 1);
	print_lcs(s.size() - 1, t.size() - 1);
	cout << endl;
	// for(int i = ans.size() - 1 ; i >= 0 ; i--)
		// cout << ans[i];
	// cout << endl;
	return 0;
}

Measured memory_bytes: 44672
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;
//階乗できるよ
ll kaizyo(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    sum = sum % ATCODER_AMARI;
  }
  return sum;
}

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

  std::vector<int> alphabet(26,0);
  std::vector<int> tmp(26,0);
  rep(i,n){
    string s; cin >> s;
    int sizes = s.size();
    rep(j,sizes) {
      int k = s.at(j);
      k = k - 97;
      tmp.at(k)++;
    }
    if(i == 0) {
      rep(j,26) {
        alphabet.at(j) = tmp.at(j);
      }
    }
    else{
      rep(j,26) {
        alphabet.at(j) = min(alphabet.at(j), tmp.at(j));
      }
    }

    rep(j,26){
      tmp.at(j) = 0;
    }
    
  }

  rep(i,26) {
    if(alphabet.at(i) != 0) {
      int tmp_alp_num = i + 97;
      char tmp_alp = tmp_alp_num;
      int count = alphabet.at(i);
      rep(j,count) {
        cout << tmp_alp;
      }
      
    }
  }

  cout << endl;
}



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

using namespace std;

int main() {
  int x, n;
  cin >> x >> n;
  vector<int> d(102);

  for(int i = 0; i < n; ++i){
    int p;
    cin >> p;
    d[p] = 1;
  }

  pair<int, int> ans(99999, -1);
  for(int i = 0; i <= 101; ++i){
    if(d[i] == 1) continue;

    int dif = abs(x - i);
    ans = min(ans, pair(dif, i));
  }
  cout << ans.second << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=10000009;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };
int main() {
	string s;
	int ans=0;
	while(true){
		cin>>s;
		if (cin.eof())break;
		int m=s.size();
		int n=m/2;
		for(int i=0;i<n;i++){
			if(s[i]!=s[m-1-i]) break;
			if(i==n-1) ans++;
		}
		if(m==1) ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3204
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
	fast_io
	string s[]={"Sunny", "Cloudy", "Rainy"};
	int k=0;
	string d; cin>>d;
	rep(i,3){
		if(s[i]==d){
			k=i;
			break;
		}
	}
	cout<<s[(k+1)%3];
	
	return 0;
}

Measured memory_bytes: 504
N,D=map(int,input().split())
X=[]
for _ in range(N):
    X.append(list(map(int,input().split())))
cnt=0
for i in range(N):
    for j in range(i+1,N):
        d=sum((t[0]-t[1])**2 for t in zip(X[i],X[j]))
        for k in range(int(d**0.5)+1):
            if k**2==d:
                cnt+=1
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    ll ans = 0;
    for(int i = 1; i < n; i++) ans ^= a[i];
    for(int i = 0; i < n; i++)
    {
        cout << ans;
        if(i < n-1) cout << " ";
        ans ^= a[i];
        ans ^= a[(i+1)%n];
    }
    cout << endl;
}


Measured memory_bytes: 4840
#include <stdio.h>

int main(){
  char ds[100];
  int a,i,d[100];
  while(scanf("%s",ds)!=EOF){
    for(i=0;ds[i]!=0;i++){
      switch(ds[i]){
        case 'I': d[i]=1; break;
        case 'V': d[i]=5; break;
        case 'X': d[i]=10; break;
        case 'L': d[i]=50; break;
        case 'C': d[i]=100; break;
        case 'D': d[i]=500; break;
        case 'M': d[i]=1000; break;
        default: d[i]=0;
      }
    }
    a=d[--i];
    for(--i;i>=0;i--)
      if(d[i]>=d[i+1]) a+=d[i]; else a-=d[i];
    printf("%d\n",a);
  }
  return 0;
}

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

# define F first    
# define S second
# define mp make_pair
// everything go according to my plan      
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right  

using namespace std;

typedef pair <int, int> pii; 
typedef long long ll;
typedef long double ld;

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {   
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") { 
  if (fopen (in, "r"))
    freopen (in, "r", stdin);
  else
    cerr << "Warning: Input file not found" << endl;
}
int n, k;
   
int main()
{
  # ifdef Local
    //localInput();
  # endif
  Read_rap();
  cin >> n >> k;
  

  ll ans = 0;
  for (int b = k + 1; b <= n; b++) {  
    int add = (n / b) * (b - k);
    if (n % b)
      add += max (0, n % b - k + (k != 0));
    ans += add;
  }    
  cout << ans;
  

  return 0;
}






// Coded by Z..


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int *t,n;
int main(){
  int i;
  scanf("%d",&n);
  t=(int*)malloc(n*sizeof(int));
  for(i=1;i<=n;i++)scanf("%d",&t[i]);
  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,t[i]);
    if(i/2>0)printf("parent key = %d, ",t[i/2]);
    if(2*i<=n)printf("left key = %d, ",t[2*i]);
    if(2*i+1<=n)printf("right key = %d, ",t[2*i+1]);
    printf("\n");
  }
  return 0;
}



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

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

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll T,X;
	while(cin>>T>>X) {
		cout<<(double)T/X<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
-- modules to import --
import Data.ByteString.Char8
import Data.Maybe
import Prelude

-- functions for this task --

read_Integer = Prelude.fst . Data.Maybe.fromJust . Data.ByteString.Char8.readInteger
get_Integer  = read_Integer <$> Data.ByteString.Char8.getLine

task_A :: Integer -> Integer
task_A target
        | target < 10 = target
        | otherwise   = val_mod + (task_A $ val_div)
        where
                (val_div, val_mod) = divMod target 10


-- main process is below --

main :: IO ()
main = do

        -- STEP.01
        -- read out the given string
        given_data <- get_Integer

        -- STEP.02
        -- output the answer of this task
        Prelude.print $ task_A $ given_data

-- End of this source code --

Measured memory_bytes: 380
n, m = gets.split.map(&:to_i)
cources = {}
ans = 'IMPOSSIBLE'
m.times do
  a, b = gets.split.map(&:to_i)
  if cources[a]
    cources[a] << b
  else
    cources[a] = [b]
  end
end

cources.each do |from, to|
  if from == 1
    to.each do |t|
      if cources[t]&.include?(n)
        ans = 'POSSIBLE'
        break
      end
    end
  end
end

puts ans


Measured memory_bytes: 17404
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

void solve(){
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> p(N);
    REP(i,N){
        cin >> p[i].first;
        p[i].second = i;
    }
    UnionFind uf(N);
    REP(i,M){
        int x, y;
        cin >> x >> y;
        uf.unite(x, y);
    }
    if(2 * (N - M - 1) > N){
        cout << "Impossible" << endl;
        return;
    }
    else if(N - 1 == M){
        cout << 0 << endl;
        return;
    }
    sort(p.begin(), p.end());
    set<int> st;
    ll ans = 0;
    int cnt = 0;
    REP(i,N){
        if(st.count(uf.root(p[i].second))){
            if(cnt < N - M - 2) ans += p[i].first, cnt++;
        }
        else{
            st.insert(uf.root(p[i].second));
            ans += p[i].first;
        }
    }
    cout << ans << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}

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


map<char, int> freq;

vector<char> oks = {'M', 'A', 'R', 'C', 'H'};
vector<int> sel;

bool first_letter_ok(const string& s){
	for (char ok : oks){
		if (s[0] == ok){
			return true;
		}
	}
	return false;
}

int main(){
	int n; cin >> n;
	cin.ignore();
	while(n--){
		string s;
		getline(cin, s);
		if (first_letter_ok(s)){
			freq[s[0]] += 1;
		}
	}
	LL ans = 0;
	for (int i = 0; i < 5; ++i){
		for (int j = i + 1; j < 5; ++j){
			for (int k = j + 1; k < 5; ++k){
				ans = ans + (LL)freq[oks[i]] * freq[oks[j]] * freq[oks[k]];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int N;
    int a[110];
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> a[i];
    int alice = 0;
    int bob = 0;
    sort(a, a + N, greater<int>());
    for (int i = 0; i < N; ++i){
        if (i % 2 == 0) alice += a[i];
        else bob += a[i];
    }
    cout << alice - bob << endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int d, r;
  d = a / b;
  r = a % b;
  double f;
  f = 1.0 * a / b;
  cout << fixed << setprecision(10);
  cout << d << " " << r << " " << f << endl;
}



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

long long sum(long long a,long long b){
  long long c=b*(a/b)*((a/b)+1)/2;
  return c;
}

int main(){
  long long n;
  cin>>n;
  long long ans=0;
  for(long long i=1;i<=n;i++){
    ans+=sum(n,i);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define fastio std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define F first
#define S second
#define pb push_back
#define M 1000000007
#define inf 1e18
#define jam(x) cout<<"Case #"<<x<<": "

int32_t main() {
	fastio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll n, k;
	cin >> n >> k;
	std::vector<int> h(n);
	std::vector<int> dp(n, INT_MAX);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}

	for (int i = 0; i <= k; ++i) {
		dp[i] = abs(h[0] - h[i]);
	}

	for (int i = k + 1; i < n; i++) {
		for (int j = 1; j <= k; j++) {

			dp[i] = min( dp[i] , dp[i - j] + abs( h[i] - h[i - j] ) );
		}
	}
	cout << dp[n - 1];

	return 0;
}

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

int main() {
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int res = 0;
  for(int a = 0; a <= A; a++){
    for(int b = 0; b <= B; b++){
      for(int c = 0; c <= C; c++){
        int total = 500*a + 100*b + 50*c;
        if(total == X){
          res++;
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
int main()
{
	long long int a,b;
	cin>>a>>b;
	if (a-b>=0)
	{
		cout<<a-b<<endl;
	}
	else
	{
		cout<<"0"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
def resolve():
    S = str(input())
    Q = int(input())

    rev_flag = 1
    head_str = ""
    tail_str = ""
    for _ in range(Q):
        query = input() # contains spaces
        if query[0] == "1":
            rev_flag *= -1
        else:
            h_or_t_flag = 1 if query[2] == "1" else -1
            h_or_t_flag *= rev_flag

            if h_or_t_flag == 1:
                head_str += query[4]
            else:
                tail_str += query[4]

    ans = head_str[::-1] + S + tail_str
    print(ans if rev_flag == 1 else ans[::-1])
resolve()


Measured memory_bytes: 4540
import sys

readline = sys.stdin.readline

ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))

def modinv(x, mod):
    a, b = x, mod
    u, v = 1, 0
    while b:
        t = a // b
        a -= t * b; a, b = b, a
        u -= t * v; u, v = v, u
    return u % mod

def solve():
  n = ni()
  a = nl()
  m = max(a)
  mod = 998244353
  l = [0]*(m+1)
  for x in a:
    l[x] += x
  sieve = [1]*(m+1)
  sieve[0] = sieve[1] = 0
  for i in range(2, m+1):
    if sieve[i]:
      for j in range(m//i, 0, -1):
        sieve[j*i] = 0
        l[j] += l[j*i]
      sieve[i] = 1
  for i in range(m+1):
    l[i] = l[i] * l[i] % mod
  for i in range(2, m+1):
    if sieve[i]:
      for j in range(1, m//i + 1):
        l[j] -= l[j*i]
  s = -sum(a)
  for i in range(1, m+1):
    if l[i]:
      s = (s + l[i] * modinv(i, mod)) % mod
  print(s * modinv(2, mod) % mod)
  return

solve()


Measured memory_bytes: 140528
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		String okikae = s.replace("ABC" , "0");
		int count = 0;
        for(int c : okikae.toCharArray()) {
			if(c == '0') {
				count++;
			}
		}
		System.out.print(count);
	}
}


Measured memory_bytes: 23764