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

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

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

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

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

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

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

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

#[allow(dead_code)]
fn practice_1() {
    input! {
    n: i32,
    m: [i32; 2],
    s: chars,
    }
    let s: Vec<char> = s;
    let s: String = s.into_iter().collect();

    println!("{} {}", n + m[0] + m[1], s);
}

#[allow(dead_code)]
fn abc086_a() {
    input! {
    n: [i32; 2],
    }
    let prod: i32 = n[0] * n[1];
    let res = if prod % 2 == 0 {
        "Even"
    } else {
        "Odd"
    };
    println!("{}", res)
}

#[allow(dead_code)]
fn abc081_a() {
    input! {
    s: chars,
    }
    let s: Vec<char> = s;
    let res: u32 = s.iter().map(|n| n.to_digit(10).unwrap()).sum();

    println!("{}", res)
}

#[allow(dead_code)]
fn abc081_b() {
    input! {
    n: i32,
    arr: [i32; n],
    }
    let mut arr: Vec<i32> = arr;
    let mut cnt = 0;

    loop {
        if arr.iter().any(|v| (v % 2) == 1) {
            break;
        }
        arr = arr.iter().map(|v| v / 2).collect();
        cnt += 1;
    }

    println!("{}", cnt)
}

#[allow(dead_code)]
fn abc087_b() {
    input! {
    n_500: i32,
    n_100: i32,
    n_50: i32,
    total: i32,
    }

    let n_500: i32 = n_500;
    let n_100: i32 = n_100;
    let n_50: i32 = n_50;
    let total: i32 = total;
    let mut cnt = 0;

    for i in 0..n_500 + 1 {
        for j in 0..n_100 + 1 {
            for k in 0..n_50 + 1 {
                let total_tried = i * 500 + j * 100 + k * 50;
                if total_tried == total {
//                    println!("{}, {}, {}", i, j, k);
                    cnt += 1;
                }
            }
        }
    }

    println!("{}", cnt)
}


fn main() {
    abc081_a()
}



Measured memory_bytes: 4352
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printfin(a) printf(a ? "possible\n" : "inposible\n")
#define all(x) (x).begin(), (x).end()
using ll = long long;

const int INF = 2147483647;
//const ll LINF = ll();今度書く

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int main() {
	
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	printYN((100 * a + 10 * b + c) % 4 == 0);

	return 0;
}


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

int main() {
  ll n,x;
  cin>>n>>x;
  vector<ll> a(n);
  rep(i,n){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  ll ans=0;
  rep(i,n){
    x-=a[i];
    if(x==0){
      ans++;
      break;
    }
    if(x<0){
      break;
    }
    ans++;
  }
  if(x>0){
    ans--;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
	int a, b, c;
	std::cin >> a >> b >> c;
	std::vector<int> sort{ a,b,c };
	std::sort(sort.begin(),sort.end());

	std::cout << sort[0] << " " << sort[1] << " " << sort[2] << std::endl;
	return 0;
}


Measured memory_bytes: 3140
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  int N, P;
  cin >> N >> P;
  ll odd = 0;
  vll A(N);
  rep(i, N) {
    int Aa;
    cin >> Aa;
    A[i] = Aa;
  }
  
  vvll dp(N + 1, vll(2));
  dp[0][0] = 1;
  rep(i, N) {
    if(A[i] % 2 == 0) {
      //余り0
      dp[i+1][0] = dp[i][0] + dp[i][0];
      dp[i+1][1] = dp[i][1] + dp[i][1];
    } else {
      dp[i+1][0] = dp[i][0] + dp[i][1];
      dp[i+1][1] = dp[i][1] + dp[i][0];
    }
  }
  
  fin(dp[N][P]);
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(all(ret));
  return (ret);
}

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

  vector<ll> div = divisor(n);

  ll s = div.size();
  
  if(s%2 == 0){
    cout << div[s/2]+div[s/2-1]-2 << endl;
  }
  else{
    cout << div[s/2]*2-2 << endl;
  }
}


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

using namespace std;

double solve(int x, double p)
{
    if(x%2==1)
        return p*solve(x-1, p)+(1.0-p)*solve(x+1, p)+1.0;
    x/=2;
    return x/p;
}

int main()
{
    int x, p;
    scanf("%d%d", &x, &p);
    printf("%.9f\n", solve(x, p/100.0));
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 28 22:05:17 2020
"""

import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

#N = int(input())
K, N = map(int,input().split())
A = list(map(int,input().split()))
#A.append()
B = []
for i in range(N-1):
    B.append(A[i+1] - A[i])
B.append(A[0] + (K - A[-1]))

ans = K - max(B)

print(ans)


Measured memory_bytes: 26444
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

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

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int s,w;
	cin >> s >> w;
	if(s <= w) cout << "unsafe" << endl;
	else cout << "safe" << endl;
}


Measured memory_bytes: 3636
import math
from collections import Counter

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
counter = Counter([''.join(sorted(input())) for i in range(N)])
ans = 0
for k, v in counter.items():
    if v == 1:
        continue
    ans += combinations_count(v, 2)
print(ans)

Measured memory_bytes: 68696
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main_old(): 
    N, _, W = LI()
    a = LI()

    # 初手でラストまで取るとき
    res = abs(a[-1] - W)
    if N == 1:
        print(res)
        return
    res2 = abs(a[-1] - a[-2])

    # 最後から n 枚目を取るときの max, min
    max_li = [0, res, res2] + [0 for _ in range(N)]
    min_li = [INF, res, res2] + [INF for _ in range(N)]
    for i in range(3, N+1):
        take_all = abs(a[-i] - a[-1])
        max_li[i] = min([min_li[j] for j in range(2, i)]+[take_all])
        min_li[i] = max([max_li[j] for j in range(2, i)]+[take_all])

    print(max(max_li))

def main():
    N, _, W = LI()
    a = LI()

    # 初手でラストまで取るとき
    res = abs(a[-1] - W)
    if N == 1:
        print(res)
        return

    # 初手でラスト1つ手前まで取るとき
    res2 = abs(a[-1] - a[-2])

    # res2 以上の結果を、カードをより少なく取ることで得ることはできない。
    # なぜなら、たとえそのような選び方を見つけたような気がしても、Y にラスト1つ手前まで取られてしまったら結局結果は res2 になってしまうため。
    # これ以上の結果を得ることはできないのでこれで満足するしかない。

    print(max(res, res2))

main()

Measured memory_bytes: 3188
def partition(a, p, r):
    x = a[r]
    i = p - 1
    for j in range(p, r):
        if a[j] <= x:
            i += 1
            tmp = a[i]
            a[i] = a[j]
            a[j] = tmp
    tmp = a[i+1]
    a[i+1] = a[r]
    a[r] = tmp
    return i + 1, x


def print_list_split_whitespace(a, x):
    ind = 0
    for i, y in enumerate(a):
        if x == y:
            ind = i
    for i in range(len(a) - 1):
        if i == ind:
            print("[" + str(a[i]) + "]", end=" ")
        else:
            print(a[i], end=" ")
    if ind == len(a) - 1:
        print("[" + str(a[-1]) + "]")
    else:
        print(a[-1])


n = int(input())
a = [int(x) for x in input().split()]

q, x = partition(a, 0, n - 1)

print_list_split_whitespace(a, x)


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

int main() {
  int n;
  scanf("%d",&n);
  long long sum=0;
  bool eq = true;
  int lmn=2e9;
  for(int i=0;i<n;i++) {
    int a,b;
    scanf("%d%d",&a,&b);
    sum += a;
    if(a == b) continue;
    eq = false;
    if(a>b) lmn = min(lmn, b);
  }
  if(eq) puts("0");
  else printf("%lld\n",sum - lmn);
}


Measured memory_bytes: 256
while true
	h, w = gets.split.map{|x| x.to_i}
	if h == 0 and w == 0
		break
	end
	
	h.times do |i|
		w.times do |j|
			if i == 0 or i == h-1
				print '#'
			elsif j == 0 or j == w-1
				print '#'
			else
				print '.'
			end
		end
		puts ''
	end
	puts ''
end

Measured memory_bytes: 8672
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
y = []
for i in range(m - 1):
    y.append(x[i + 1] - x[i])
y.sort()
count = 0
for i in range(m - n):
    count += y[i]
print(count)

Measured memory_bytes: 13960
import sys

INF = 1000000007

stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def nal(): return list(map(int, stdin.readline().split()))
def ns(): return stdin.readline().strip()
def ni(): return int(stdin.readline())

N = ni()
x = nal()
x.insert(0, 0)

n = 1
c = 0
a = 1

for i in range(N):
    t = x[i+1] - x[i] - 1
    c = c+1
    if(t > 1):
        n = n+t-1
    elif(t == 0):
        n = n-1
        if(n == -1):
            n = 1
            a = a*c%INF
            c = c-1

for i in range(1, c+1):
    a = a*i%INF

print(a % INF)

Measured memory_bytes: 14528
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
 
int main(){
    string s;
    cin>>s;
     
    int p[26]={};
    rep(i,s.size()){
        p[s[i]-'a']++;
    }
     
    if(s.size()%2==0){
        int odd = 0;
        rep(i,26)if(p[i]%2)odd++;
        cout<<odd/2+odd%2<<endl;
    }
    else{
        int ans = INF;
        rep(i,s.size()){
            p[s[i]-'a']--;
             
            int odd = 0;
            rep(i,26)if(p[i]%2)odd++;
            ans = min(ans,odd/2+odd%2);
             
            p[s[i]-'a']++;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3192
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int[] a=new int[n];
    for(int i=0;i<n;i++){
      a[i]=sc.nextInt()-1;
    }
    int sum=0;
    for(int i=0;i<n;i++){
      if(a[a[i]]==i){
        sum++;
      }
    }
    System.out.println(sum/2);
  }
}

Measured memory_bytes: 50408
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>
using namespace std;

int h, w, d;
int col[500][500];
int seed[4][4] = { {1, 0, 2, 0},
                   {0, 4, 0, 3},
                   {2, 0, 1, 0},
                   {0, 3, 0, 4} };
void RYGB(int n){
  char c;
  switch (n){
  case 0: c = 'O'; break;
  case 1: c = 'R'; break;
  case 2: c = 'Y'; break;
  case 3: c = 'G'; break;
  case 4: c = 'B'; break;
  }
  printf("%c",c);
}

int main(void) {
  scanf("%d %d %d",&h, &w, &d);

  if(d%2 == 1) for(int i=0;i<h;i++) for(int j=0;j<w;j++) col[i][j] = (i+j)%2 ? 2 : 3;
  else{
    int ifin = (ceil(1.0*h/d))*2 + 1, jfin = ceil(2.0*w/d);
    int halfd = d/2, hc, wc, hcs, wcs;
    int seedi, seedj;
    for(int i=0;i<ifin;i++) for(int j=-i%2;j<jfin;j+=2){
        seedi = i%4;
        seedj = (j+4)%4;
        hc = i * halfd;
        wc = j * halfd;
        for(int m=0;m<2;m++){
          wc += m;
          for(int k=0;k<halfd;k++) for(int l=0;l<halfd;l++){
              hcs = hc +k -l;
              wcs = wc +k +l;
              if(hcs>=0 && hcs<h && wcs>=0 && wcs<w) col[hcs][wcs] = seed[seedi][seedj];
            }
        }
      }   
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      RYGB(col[i][j]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define MAXN 200002

int n, cnt[MAXN] = {0}, a[MAXN];
LL sum = 0;

int main () {
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
		sum += 1LL * cnt[a[i]];
		cnt[a[i]] ++;
	}
	for (int i = 1; i <= n; i ++) {
		cout << sum - 1LL * (cnt[a[i]] - 1) << endl;
	}
	return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9L+7;
int n;
vector<vector<ll>> inp;
vector<vector<vector<ll>>> dp;

int main()
{

    /*ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    #ifndef ONLINE_JUDGE
   freopen("inp.txt", "r", stdin);      freopen("outp.txt", "w", stdout);
   #endif
    
    int t=1;
    //cin>>t;
    while(t--)
    {
        /*inp.assign(r+2,vector<ll> (c+2,0));
        dp.assign(r+2,vector<vector<ll>> (c+2,vector<ll> (4,-1)));
        */
        ll x,k,d;
        cin>>x>>k>>d;

        x = abs(x);

        if(k< x/d) cout<< x - k*d<<endl;
        else
        {
            ll ans1 = x%d;
            ll ans2 = abs(ans1 - d);
            k -= x/d;

            if(k%2 == 0)
            {
                cout<<ans1<<endl;
            }
            else
            {
                cout<<ans2<<endl;
            }
            
        }
        

    }
    
}


Measured memory_bytes: 3636
#include <stdio.h>

int main()
{
	int i, res = 0;
	char N[200001];
	scanf("%s", N);
	for (i = 0; N[i] != 0; i++) res = (res + N[i] - '0') % 9;
	if (res == 0) printf("Yes\n");
	else printf("No\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1800
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define INF 1e9
using namespace std;

int n;
int16_t x[8],y[8];
double ans;
bool zumi[8];

int facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

void dfs(int j,int num,double len){
    if (num==n){
        ans+=len/facctorialMethod(n);
        return;
    }
    rep(i,n){
        double newLen;
        if(zumi[i]==false){
            newLen=len+sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
            zumi[i]=true;
            dfs(i,num+1,newLen);
            zumi[i]=false;
        }
    }
}

int main()
{
    cin>>n;
    ans=0;
    rep(i,n){
        cin>>x[i]>>y[i];
        zumi[i]=false;
    }
    for (int i = 0; i < n; i++)
    {
        zumi[i]=true;
        dfs(i,1,0);
        zumi[i]=false;
    }
    
    printf("%.10f",ans);

    return 0;
}

Measured memory_bytes: 256
# coding:utf-8


def inpl(): return list(map(int, input().split()))


N, M = inpl()
A = inpl()

S = [0]
for i in range(N):
    S.append((S[-1] + A[i]) % M)
del S[0]

D = dict()
D[0] = 0
for i in range(N):
    if S[i] in D:
        D[S[i]] += 1
    else:
        D[S[i]] = 1

ans = 0
for num in D:
    tmp = D[num]
    # cmb(x, 2)を計算
    ans += tmp * (tmp - 1) // 2

# l, rが等しく（1箱で）分配できるパターンを最後に足す
ans += D[0]
print(ans)


Measured memory_bytes: 16300
#include<bits/stdc++.h>
using ll = long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()

#define INF (ll)1e9 //10^9:∞
#define LLINF (ll)1e12
#define MOD (ll)(1e9+7) //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)
#define endl "\n"

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/


/*.....................DEFINE FUNCTIONS ......................*/



/*.........................kemkemG0...........................*/
signed main() {
	__MAGIC__



	int n, k; cin >> n >> k;

	vector<long long> num(k, 0);

	for (int i = 1; i <= n; ++i) num[i % k]++; // num[x] = kで割ってxあまる数が1以上N以下に何個あるか

	long long res = 0;

	for (int a = 0; a < k; ++a) {

		int b = (k - a) % k;
		int c = (k - a) % k;

		if ((b + c) % k != 0) continue;

		res += num[a] * num[b] * num[c];
	}
	
	cout << res << endl;













	return 0;
}


Measured memory_bytes: 4712
import sys,os,io
# input = sys.stdin.readline
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(N-1):
  a,b = list(map(int, input().split()))
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

def dfs(start):
  stack = [start]
  parent = [N]*N
  parent[start] = -1
  while stack:
    v = stack[-1]
    marker = 0
    for u in edge[v]:
      if u==parent[v]:
        continue
      if parent[u]==N: #子へ降ろす
        marker = 1
        parent[u]=v
        stack.append(u)
      else: #子から吸い上げる
        ans[v] *= ans[u]+1
        ans[v] %=M
    if marker==0:
      stack.pop()
  return

def dfs2(start):
  stack = [start]
  parent = [N]*N
  parent[start] = -1
  p_value = [0]*N
  while stack:
    v = stack.pop()
    cum1 = [1]*(len(edge[v])+1)
    cum2 = [1]*(len(edge[v])+1)
    for i,u in enumerate(edge[v]):
      if u==parent[v]:
        cum1[i+1] = cum1[i]*(p_value[v]+1)%M
      else:
        cum1[i+1] = cum1[i]*(ans[u]+1)%M
    for i,u in enumerate(edge[v][::-1]):
      if u==parent[v]:
        cum2[-i-2] = cum2[-i-1]*(p_value[v]+1)%M
      else:
        cum2[-i-2] = cum2[-i-1]*(ans[u]+1)%M
    for i,u in enumerate(edge[v]):
      if u==parent[v]:
        continue
      parent[u]=v
      p_value[u] = cum1[i]*cum2[i+1]%M
      ans[u] *= (p_value[u]+1)
      ans[u] %= M
      stack.append(u)
    ans[v] %= M
  return

ans = [1]*N
dfs(0)
dfs2(0)
print(*ans, sep='\n')

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

int get_int() {
    int n = 0;
    int sign = 1;
    int c = getchar_unlocked();
    if(c == 45) sign = -1, c = getchar_unlocked();
    else if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) {
        n = 10 * n + (c & 0xf);
        c = getchar_unlocked();
    }
    return n * sign;
}
int get_str(char *str) {
    int c;
    while((c = getchar_unlocked()) > 32) *str++ = (char)c;
    *str = 0;
    return c;
}
typedef struct Node {
    int key;
    struct Node *left, *right;
} Node;
typedef struct BST {
    Node *root;
    size_t size;
} BST;
void bst_init(BST *BST) {
    BST->root = NULL;
    BST->size = 0;
}
void bst_insert(BST *BST, int key) {
    Node *new_node = malloc(sizeof(Node));
    new_node->key = key;
    new_node->left = NULL;
    new_node->right = NULL;
    Node *tmp;
    Node *root = BST->root;
    while(root != NULL) {
        tmp = root;
        if(key < root->key) root = root->left;
        else root = root->right;
    }
    if(BST->size == 0) BST->root = new_node;
    else if(key < tmp->key) tmp->left = new_node;
    else tmp->right = new_node;
    BST->size++;
}
void bst_inorder(Node *root) {
    if(root == NULL) return;
    bst_inorder(root->left);
    printf(" %d", root->key);
    bst_inorder(root->right);
}
void bst_preorder(Node *root) {
    if(root == NULL) return;
    printf(" %d", root->key);
    bst_preorder(root->left);
    bst_preorder(root->right);
}
int main(int argc, char **argv) {
    BST BST;
    bst_init(&BST);
    int m = get_int();
    char c[8];
    for(int i=0;i<m;++i) {
        get_str(c);
        if(*c == 'i') {
            int key = get_int();
            bst_insert(&BST, key);
        } else {
            bst_inorder(BST.root);
            puts("");
            bst_preorder(BST.root);
            puts("");
        }
    }
    return 0;
}



Measured memory_bytes: 17296
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
typedef long long ll;
using namespace std;
const ll inf=1e+18+1;
int main(void){
    // Your code here!
    ll n, k;cin>>n>>k;
    vector<ll> a(n),f(n);
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>f[i];
    sort(f.rbegin(),f.rend());
    sort(a.begin(),a.end());
    ll right=inf,left=-1;
    //各メンバーのコストをmid以下に抑えられるか
    while(right-left>1){
        ll mid=(right+left)/2;
        ll tot=0;
        rep(i,n){
            ll buf=a[i]-mid/f[i];
            if(buf>=0)tot+=buf;
        }
        if(tot<=k) right=mid; else left=mid;
    }
    cout<<right<<endl;
}


Measured memory_bytes: 3328
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector <char> > grid(H, vector<char>(W, 0));
  rep(y, H) {
    rep(x, W) {
      cin >> grid[y][x];
    }
  }
  vector<bool> blank_rows(W);
  vector<bool> blank_lines(H);
  rep(x, W) {
    bool blank = true;
    rep(y, H) {
      if (grid[y][x] == '#') { blank = false; break; }
    }
    if (blank) blank_rows[x] = true;
  }
  rep(y, H) {
    bool blank = true;
    rep(x, W) {
      if (grid[y][x] == '#') { blank = false; break; }
    }
    if (blank) blank_lines[y] = true;
  }
  rep(y, H) {
    if (blank_lines[y]) continue;
    rep(x, W) {
      if (blank_rows[x]) continue;
      cout << grid[y][x];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

//int main() {
//	long long a, b, x;
//	cin >> a >> b >> x;
//	long long ans = 0;
//	long long d = 10;
//
//	for (int i = 0;i < 10;i++) {
//		if (x < a * (long long)pow(10, i) + b * ((long long)i + (long long)1)) {
//			d = i;
//			break;
//		}
//	}
//
//	if (d == 0) {
//		cout << 0 << endl;
//		return 0;
//	}
//
//	x -= b * d;
//	ans = x - b*d / a;
//	if (ans > 1000000000) {
//		ans = 1000000000;
//	}
//
//	cout << ans << endl;
//
//	return 0;
//}

int main() {
	int a, b;
	cin >> a >> b;

	if (a > 9 || b > 9) {
		cout << -1 << endl;
	}
	else {
		cout << a * b << endl;
	}

	return 0;
}


Measured memory_bytes: 3616
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	int[][] map;
	boolean[][] visited;
	int n=12;

	void rec(int x, int y){
		if(x<0||x>=n||y<0||y>=n)
			return;
		if(visited[y][x])
			return;
		if(map[y][x]==0)
			return;
		visited[y][x]=true;
		rec(x, y-1);
		rec(x, y+1);
		rec(x-1, y);
		rec(x+1, y);
	}

	void run(){
		map=new int[n][n];
		sc=new Scanner(System.in);
		for(; sc.hasNext();){
			for(int j=0; j<n; j++){
				String s=sc.next();
				for(int i=0; i<n; i++)
					map[j][i]=s.charAt(i)=='0'?0:1;
			}
			visited=new boolean[n][n];
			int ans=0;
			for(int j=0; j<n; j++){
				for(int i=0; i<n; i++){
					if(map[j][i]==1&&!visited[j][i]){
						ans++;
						rec(i, j);
					}
				}
			}
			println(ans+"");
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
const double PI=3.14159265358979323846;
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<pair<int,int> > pi(n);
  int a,b;
  rep(i,n){
    cin>>a>>b;
    pi[i].first=b; pi[i].second=a;
  }
  int now=0;
  sort(all(pi));
  rep(i,n){
    now+=pi[i].second;
    if(now>pi[i].first){
      cout<<"No"<<'\n';
      return(0);
    }
  }
  cout<<"Yes"<<'\n';
  return(0);
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

class UnionFind {
    vector<int> _nodes;

public:
    UnionFind(int size) : _nodes(vector<int>(size+1, -1)) {}

    int findRoot(int a) {
        if (_nodes[a] == -1) return a;
        const int root = findRoot(_nodes[a]);
        _nodes[a] = root;
        return root;
    }
    void unite(int a, int b) {
        const int rootA = findRoot(a);
        const int rootB = findRoot(b);
        if (rootA == rootB) return;

        _nodes[rootB] = rootA;
    }
};


void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B){
    UnionFind uf(N+1);
    rep(i,0,M) {
        uf.unite(A[i], B[i]);
    }
    unordered_map<int, int> groups;
    rep(i,1,N+1) {
        groups[uf.findRoot(i)]++;
    }
    int answer = 0;
    for (auto [key, cnt] : groups) {
        answer = max(cnt, answer);
    }
    cout << answer << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, M, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 12016
import Control.Monad
import Data.List

check ss ts =
  case  group $ sort $ ss \\ ts of
    [] -> 0
    xs -> maximum $ map length  xs
  
main = do
  n <- read <$> getLine ::IO Int
  s <- replicateM n $ getLine
  m <- read <$> getLine ::IO Int
  t <- replicateM m $ getLine
  print $ check s t

Measured memory_bytes: 636
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int N = scanner.nextInt();
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < N; i++) {
            int a = scanner.nextInt();
            if (map.get(a) == null) {
                map.put(a, 0);
            }
            Integer b = map.get(a);
            map.put(a, b + 1);
        }

        int ans = 0;
        for (int a:map.keySet()) {
            int count = map.get(a);
            if (a > count) {
                ans += count;
            } else if (a < count) {
                ans += count - a;
            }
        }
        System.out.println(ans);
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {
                    line = br.readLine();
                }
                s = line.split(reg, 0);
                i = 0;
                return s[i++];
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}


Measured memory_bytes: 47944
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
#include<set>
#include<queue>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000
#define INFL (long long)(4e18)

using vi = vector<int>;

template<class T>
struct Edge {
    int to;
    T cost;
    Edge() {};
    Edge(int to, T cost) : to(to), cost(cost) {};
};

template<class T>
class Graph {
    int n;
    bool directed;
    vector<vector<Edge<T>>> edges;
public:

    Graph(int n, bool directed) :n(n), directed(directed), edges(vector<vector<Edge<T>>>(n)){};
    Graph() {};

    void add(int from,int to, T cost) {
        edges[from].emplace_back(to, cost);
        if(!directed){
            edges[to].emplace_back(from,cost);
        }
    }

    int size() {
        return n;
    }
};


int main() {

    int N,M;

    cin >> N >> M;

    vector<vi> acwa(N,vi(2));

    REP(i,N){
        acwa[i][0] = 0;
        acwa[i][1] = 0;
    }


    REP(i,M){
        int a;
        string s;
        cin >> a >> s;
        
        if(acwa[a-1][1] == 0){
            if(s == "AC"){
                acwa[a-1][1] = 1;
            }else{
                acwa[a-1][0]++;
            }
        }
    }

    int AC = 0;
    int WA = 0;
 
    REP(i,N){
        AC += acwa[i][1];
        if(acwa[i][1] == 1)WA += acwa[i][0];
    }

    cout << AC << ' '  << WA << endl;

    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
using namespace std;
int main(){
    int W=0;
    int H=0;
    int N=0;
    
    int X[100001];
    int Y[100001];
    int YMAX=0;
    int danMAX[100001];
    int ALLMAX[100001];
    int ans=0;
    
    int i=0;
    int c=0;
    int d=0;
    int j=0;
    
    cin>>W>>H>>N;
    
    for(i=0;i<N;i++){
        cin>>X[i]>>Y[i];
        if(danMAX[Y[i]]==0 || danMAX[Y[i]]<X[i]){
            danMAX[Y[i]]=X[i];
        }
        if(YMAX<Y[i]){
            YMAX=Y[i];
        }
    }
    
    ALLMAX[YMAX]=danMAX[YMAX];
    ans=YMAX;
    //cout<<ans<<endl;
    
    for(i=1;i<YMAX+1;i++){//一番下はすでに入力済み
        if(danMAX[YMAX-i]>=ALLMAX[YMAX-i+1]){
            ALLMAX[YMAX-i]=danMAX[YMAX-i];
        }else{
            ALLMAX[YMAX-i]=ALLMAX[YMAX-i+1];
        }
        //cout<<ALLMAX[YMAX-i]<<endl;
    }
    //cout<<ALLMAX[0]<<endl;
    
    for(i=0;i<YMAX+1;i++){
        if(i+ALLMAX[i+1]<ans){
            ans=ALLMAX[i+1]+i;
        }
    }
    
    //YMAX-i
    cout<<ans<<endl;
    
    
    
    
    
    
    
}



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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

void solve(){
	int n, a, ans, d;
	cin >> n;
	ans = 1;
	d = 1;
	REP(i, 0, n){
		ans *= 3;
		cin >> a;
		if (a % 2 == 0){
			d *= 2;
		}
	}
	ans-= d;
	cout << ans << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

time = 0
for i in range(n):
    if a[i] < 0:
        time += 1
        a[i] = -a[i]

sum = 0
for i in range(n):
    sum += a[i]

a.sort()

if time % 2 == 0:
    print(sum)
else:
    print(sum - a[0] * 2)

Measured memory_bytes: 15020
def main():
    import sys
    input = sys.stdin.readline
    s = str(input().rstrip())
    q =int(input())
    ten = 0
    r = []
    l = []
    la = l.append
    ra =r.append
    for _ in range(q):
        ls = tuple(map(str, sys.stdin.readline().split()))
        if len(ls)==1:
            ten +=1
        else:
            if ls[1] =='1':
                if ten%2 ==0:
                    la(ls[2])
                else:
                    ra(ls[2])
            else:
                if ten%2 ==1:
                    la(ls[2])
                else:
                    ra(ls[2])
    s = ''.join(reversed(l))+s+''.join(r)
    if ten%2 ==1:
        s = s[::-1]
    print(s)
if __name__ == '__main__':
    main()

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

int main(){
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  string divide[4] = {"dream", "dreamer", "erase", "eraser"};
  for(int i = 0; i < 4; i++){
    reverse((divide[i]).begin(), (divide[i]).end());
  }
  bool can = true;
  for(int i = 0; i < s.size();){
    bool can2 = false;
    for(int j = 0; j < 4; j++){
      if(s.substr(i, divide[j].size()) == divide[j]){
        can2 = true;
        i+=(divide[j]).size();
      }
    }
    if(!can2){
      can = false;
      break;
    }
  }
  if(can) cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

int main(){
  int A,B;
  cin >> A >> B;
  
  if(A%3==0 || B%3==0 || (A+B)%3==0)
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<random>
#include<math.h>
#include<limits.h>
#include<iterator>
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
#define ll long long
#define vl vector<ll> 
#define vvl vector<vector<ll> > 
#define vb vector<bool> 
#define vvb vector<vector<bool> > 
#define INF 1123456789012345
using namespace std;

int main(){
	ll r, g, b; cin >> r >> g >> b;
	r *= 100;
	g *= 10;
	ll ans = r + g + b;
	if (!(ans % 4)) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

int main()
{
    int n,reminder=0,count=0;
    cin>>n;
    while(n!=0)
    {
       reminder=n%10;
       n/=10;
       if(reminder==7)
        count++;
    }
 if(count>=1)
    cout<<"Yes"<<endl;
 else
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3524
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t k, x;
    cin >> k >> x;

    if (500 * k >= x) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int h = sc.nextInt();
		int w = sc.nextInt();
		int endPoint = 1;
		
		for (int i = 1; i <= h; i++) {
			String str = sc.next();
			char charArray[] = str.toCharArray();
			
			for (int j = 1; j <= w; j++) {
				if (charArray[j - 1] == '.') {
					continue;
				}
				if (j < endPoint) {
					System.out.println("Impossible");
					sc.close();
					return;
				}
				endPoint = j;
			}
		}
		
		System.out.println("Possible");
		sc.close();
	}
}

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

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    string s;cin>>s;
    int n = s.size();
    int ans=2;
  
    for(int i=2;i<=n/2;i+=2){
        int m = n - i;
        int cc = 0;
        rep(j,m/2){
            if(s[j]!=s[m/2 + j])cc=1;
        }
        if(cc == 0){
            ans = m;
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
/*

“Death created time to grow the things that it would kill.”

*/

#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll long long
//#define int long long
#define mod 1000000007
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define f(i,n) for(ll i=0;i<n;i++)
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define cout1(a) cout<<a<<endl
#define cout2(a,b) cout<<a<<" "<<b<<endl
#define cout3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define cout4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl
#define vcout(v,i) cout<<v[i].fi<<" "<<v[i].se<<endl
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define ms(v,n) memset((v),n,sizeof(v));
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define sll set<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define maxi(a,b,c) max(a,max(b,c))
#define maxii(a,b,c,d) max(max(a,b),max(c,d))
#define mini(a,b,c) min(a,min(b,c))
#define md(a,b)  ((a%mod)*(b%mod)+mod)%mod 
#define ad(a,b)  (a%mod+b%mod+mod)%mod
#define nl endl
#define inf 1e18
#define cases ll t;cin>>t;while(t--)
#define BLOCK 500
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
 
using namespace std;

string k;
ll d,len;
char cad[100];

ll dp[10005][2][101];
bool vis[10005][2][101];


ll go(ll pos,ll flag,ll sum)
{
    if(pos==len)
    {
        return (sum%d==0);
    }

    ll &ret=dp[pos][flag][sum];
    bool &v=vis[pos][flag][sum];

    if(v)
    return ret;

    v=true;

    ll ko=flag? k[pos]-'0':9;

    ll ans=0;


    for(ll i=0;i<=ko;i++)
    {
        ans=ad(ans,go(pos+1,flag && i==ko,(sum+i)%d));

    }

    return ret=ans;

}

ll solve(string x)
{
    // sprintf(cad,"%s",x);
    len=x.size();
   // ms(vis,false);
    return go(0,1,0);

}

int main()
{
    
    // fast
    cin>>k>>d;
    
    ll ans=solve(k)-1;
    if(ans==-1)
    ans=mod-1;

    cout<<ans;
       
    return 0;
    
}



Measured memory_bytes: 18944
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
#define N 300010
#define ll long long
int n;
struct data
{
	int x,y;
	bool operator <(const data&a) const
	{
		return x+y<a.x+a.y;
	}
}a[N];
ll ans;
int main()
{
	/*freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);*/
	n=read();
	for (int i=1;i<=n;i++) a[i].x=read(),a[i].y=read();
	sort(a+1,a+n+1);reverse(a+1,a+n+1);
	for (int i=1;i<=n;i++)
	if (i&1) ans+=a[i].x;
	else ans-=a[i].y;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
use std::io;
use std::str;

fn dfs(u: usize, graph: &[Vec<usize>], visited: &mut [bool], toposort: &mut Vec<usize>) {
    visited[u] = true;
    for &v in &graph[u] {
        if !visited[v] {
            dfs(v, graph, visited, toposort);
        }
    }
    toposort.push(u);
}

fn solve<R: io::BufRead, W: io::Write>(scan: &mut Scanner<R>, out: &mut W) {
    let n: usize = scan.token();
    let m: usize = scan.token();
    let mut graph = vec![Vec::new(); n];
    for _ in 0..m {
        let u = scan.token::<usize>() - 1;
        let v = scan.token::<usize>() - 1;
        graph[u].push(v);
    }
    let mut visited = vec![false; n];
    let mut toposort = Vec::new();
    for u in 0..n {
        if !visited[u] {
            dfs(u, &mut graph, &mut visited, &mut toposort);
        }
    }

    let mut dp = vec![0; n];
    for &u in toposort.iter().rev() {
        for &v in &graph[u] {
            dp[v] = dp[v].max(1 + dp[u]);
        }
    }

    let mut ans = 0;
    for u in 0..n {
        ans = ans.max(dp[u]);
    }
    writeln!(out, "{}", ans).ok();
}

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());
    solve(&mut scan, &mut out);
}

pub struct Scanner<R> {
    reader: R,
    buffer: Vec<String>,
}

impl<R: io::BufRead> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buffer: vec![],
        }
    }

    pub fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            self.reader.read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }

    pub fn tokens<T: str::FromStr>(&mut self) -> Vec<T> {
        assert!(self.buffer.is_empty());
        let mut input = String::new();
        self.reader.read_line(&mut input).expect("Failed read");
        input
            .split_whitespace()
            .map(|x| x.parse().ok().expect("Failed parse"))
            .collect()
    }
}


Measured memory_bytes: 12188
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
#define rep(i, n) for(int i = 0; i < n; i++)
#define ll long long
using namespace std;


int n, m;
int p[100000], y[100000];
vector<int> indx[100001];  // indxは市．要素番号に県，要素は誕生年．

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

    // input
    scanf("%d %d", &n, &m);
    rep(i, m) {
        scanf("%d%d", &p[i], &y[i]);
        // 市[県]<-誕生年
        indx[p[i]].push_back(y[i]);
    }
    rep(i, n) {
        // 1~nまでの県でそれぞれ誕生年を比較してソートを行う
        sort(indx[i+1].begin(), indx[i+1].end());
    }
    rep(i, m) {
        // 最初の6桁は市ごとの県
        // 次の6桁は市の誕生年より小さいときの都市を小さいものからの順にしたもの
        // lower_bound(vectorの要素, vectorの要素, 基準とする値)で初めから見て何番目のイテレータか返す
        printf("%012lld\n", (ll)(p[i]) * 1000000 + (lower_bound(indx[p[i]].begin(), indx[p[i]].end(), y[i]) - indx[p[i]].begin()) + 1);
    }

	return 0;
}

Measured memory_bytes: 7808
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using std::cout;
using std::cin;
using std::endl;
using std::pow;
using std::vector;
using std::string;

int fun(int x,int y,int z){
    return x*x+y*y+z*z+x*y+y*z+z*x;
}

int main(){
    int N,count=0;
    cin >> N;
    vector<int> a(N+1);
    for(int i=1;i<=N;i++) cin >> a.at(i);
    for(int i=1;i<=N;i++){
        if(i % 2 == 1){
            if(a.at(i) % 2 == 1) count++;
        }
    }
    cout << count;
}

Measured memory_bytes: 3620