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

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define FILE "parade"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const ull ULLINF = numeric_limits<ull>::max();
const double PI = acos(-1.0);

int a[110];

int main()
{
//    freopen(FILE".in", "r", stdin);
//    freopen(FILE".out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    int bst = INF;
    for(int t = -1000; t <= 1000; t++)
    {
        int cur = 0;
        for(int i = 0; i < n; i++)
            cur += (t - a[i]) * (t - a[i]);
        bst = min(bst, cur);
    }
    cout << bst;
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var c1, c2 string
	fmt.Scan(&c1, &c2)

	if c1[0] == c2[2] && c1[1] == c2[1] && c1[2] == c2[0] {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
# unihernandez22
# https://atcoder.jp/contests/abc151/tasks/abc151_c
# implementation

class Counter(dict):
    def __missing__(self, i):
        return 0

class BoolDict(dict):
    def __missing__(self, i):
        return False

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

passed = 0
penalties = Counter()

ac = BoolDict()

for i in range(m):
    p, s = input().split()
    if not ac[p]:
        if s == "WA": penalties[p] += 1
        elif s == "AC":
            passed += 1
            ac[p] = True

x = 0
for i in penalties:
    if ac[i]:
        x += penalties[i]

print(passed, x)


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	long double ans=0;
	for(int i=0;i<n;i++)
	{
		long double x;
		cin >> x;
		string u;
		cin >> u;
		if(u=="JPY")
			ans+=x;
		else
			ans+=(x*380000.0);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 998244353
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;//thisポインター　thisで自分自身のアドレス
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
	int n,s;
	cin >> n>>s;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	vector<mint> q(s+1);
	/*
	rep(i,2*s+1){
		q[i]=0;
	}
	*/
	mint ans=0;
	rep(i,n){
		q[0]+=1;
		vector<mint> q2(s+1);
		rep(j,s+1){
			q2[j]+=q[j];
			if(j+a[i]<=s)q2[j+a[i]]+=q[j];
		}
		q=q2;
		ans+=q[s];
	}
	
	cout<<ans.x<<endl;
    return 0;
}



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

using namespace std;

int main(){
	int n;
	cin >> n;
	int a[n];
	int ans = -1;

	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(i != j){
				ans = max(ans,abs(a[i]-a[j]));
			}
		}
	}
	cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i=0; i<N; i++) {
    cin >> H.at(i);
  }
  
  
  int count = 1;
  
  for (int i=1; i<N; i++) {
    bool flag = true;
    for (int j=0; j<i; j++) {
      if (H[j] > H[i]) flag = false;
    }
    if (flag) count++;
  }
  
  cout << count << endl;

}

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

int main(){
    
    int H,W;
    while(1){
        cin >> H >> W;
        if((H == 0 )&&(W == 0)){
          break;
        }

        for(int i=0 ; i < H ; i++){
            for(int j=0 ; j < W ; j++){
              if((i == 0)||
                 (i == H-1)||
                 (j == 0)||
                 (j == W-1)){                 
                   cout << '#';
                 }else{
                   cout << '.';                     
                 }
            }
            cout << endl;
        }
        cout << endl;
    }
    return(0);
}


Measured memory_bytes: 3116
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[0]*n
    for i in range(n):
        a[i]=int(input())
    s=[0]*(n+1)
    for i in range(n):
        s[i+1]=s[i]+a[i]
    ans=int()
    for i in range(n-k+1):
        ans=max(ans,s[k+i]-s[i])
    print(ans)


Measured memory_bytes: 13320
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    if ((n + m) % 2) puts("IMPOSSIBLE");
    else cout<<(n+m)/2<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int number,a,b,c,d;
    while(scanf("%d",&number)!=EOF)
    {
        a=number/1000;
        b=number/100%10;
        c=number/10%10;
        d=number%10;
        if(a+b+c+d==7) {cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;continue;}
        if(a+b-c+d==7) {cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;continue;}
        if(a-b+c+d==7) {cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;continue;}
        if(a+b+c-d==7) {cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;continue;}
        if(a-b-c+d==7) {cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;continue;}
        if(a+b-c-d==7) {cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;continue;}
        if(a-b+c-d==7) {cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;continue;}
        if(a-b-c-d==7) {cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;continue;}
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;

int n ,c ;
string s;
int main()
{
    cin >> s;
    n = s.size();
    for (int i = 0 ; i < n / 2 ; i++)
    {
        if (s[i] != s[n -i -1])c++;
    }
    cout <<c;


    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
from collections import deque

def main():
    N,M = map(int,input().split())
    dist = [[] for _ in range(N)]
    
    for i in range(M):
        l,r,d = map(int,input().split())
        dist[l-1].append((r-1,d))
        dist[r-1].append((l-1,-d))
        
    go = [None for _ in range(N)]
    for i in range(N):
        if go[i] is None:
            go[i] = 0
        q = deque([i])
        while q:
            l = q.pop()
            for r,d in dist[l]:
                if go[r] is None:
                    go[r] = go[l] + d
                    q.append(r)
                else:
                    if go[r] - go[l] != d:
                        print("No")
                        exit()
        
    print("Yes")
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 66320
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n;
	cin>>n;
	vector<int> t(n+1),x(n+1),y(n+1);
	for(int i=1;i<=n;++i){
		cin>>t[i]>>x[i]>>y[i];
		int dist=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
		int T=t[i]-t[i-1];
		if(dist>T||(dist<=T&&((dist^T)&1))) 
			return cout<<"No\n",0;
	}
	cout<<"Yes\n";
}



Measured memory_bytes: 4484
#include<stdio.h>

int main(void) {
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if (a + b + c == a * 2 || a + b + c == b * 2 || a + b + c == c * 2) printf("Yes\n"); else printf ("No\n");
  return 0;
}

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


using namespace std;
typedef long long ll;

const ll MAXN=1e5+10;
ll cost[MAXN]={0};//每个点到达k的最短路径
bool vis[MAXN]={0};
int q,k;

struct EDGE{
	int to;
	ll w;
};

vector<EDGE> tree[MAXN];


void search(int kn,ll co){
	int len=tree[kn].size();
	vis[kn]=true;
	for(int i=0;i<len;i++){
		int gov=tree[kn][i].to;
		if(vis[gov]==false){
			cost[gov]=tree[kn][i].w+co;
			search(gov,cost[gov]);
		}
	}
}


int main() {
	int n;
	scanf("%d",&n);
	int to,end;
	ll weight;
	EDGE edge;
	for(ll i=1;i<=n-1;i++){
		scanf("%d %d %lld",&to,&end,&weight);
		edge.to=end;
		edge.w=weight;
		tree[to].push_back(edge);
		edge.to=to;
		tree[end].push_back(edge);
	}
	
	scanf("%d %d",&q,&k);
	search(k,0);
	for(int i=1;i<=q;i++){
		scanf("%d %d",&to,&end);
		printf("%lld\n",cost[to]+cost[end]);
	}
	return 0;
}


Measured memory_bytes: 14336
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int[] alp = new int[26];
    String s = sc.next();
    int cnt = 0;

    for (int i = 0; i < 4; i++) {
      alp[s.charAt(i) - 'A']++;
    }

    for (int i = 0; i < 26; i++) {
      if (alp[i] == 0) {
        continue;
      } else if (alp[i] == 2) {
        cnt++;
      } else {
        System.out.println("No");
        return;
      }
    }

    if (cnt == 2) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }
}

Measured memory_bytes: 35744
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define takearr(a,n) int a[n];for(int i=0;i<n;i++)cin>>a[i]
#define rep(i,n) for(int i=0;i<n;i++)
#define f(i,a,b) for(int i=a;i<=b;i++)
#define mods (1000*1000*1000)+7

int main()
{

  int n,k;cin>>n>>k;
  takearr(a,n);
  int ans[n];
  rep(i,n)ans[i]=INT_MAX;
  ans[0]=0;
  ans[1]=abs(a[1]-a[0]);
  f(i,1,n)
    {
      for(int j=i-1;(j>=0)&&(i-j<=k);j--)
        {
          ans[i] = min (ans[j] + abs (a[i] - a[j]), ans[i]);
        }
    }
    cout<<ans[n-1]<<endl;

}

Measured memory_bytes: 1024
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      int N = nextInt();
      if(N / 10 == 9 || N % 10 == 9){
        myout("Yes");
      }else{
        myout("No");
      }
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 33056
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
using namespace std;

int main()
{
    fast_io
    ll i,j,n,ans=0;
    cin>>n;
   if(n==0) return cout<<0<<endl,0;
    string s="";


    while(n!=0)
    {
        if(n%(-2)==0)
        {
            s='0'+s;
            n/=(-2);
        }
        else{
            n=(n-1)/(-2);
            s='1'+s;
        }
    }

    cout<<s<<endl;




    return 0;
}





Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define rall(x) x.rbegin(),x.rend()
#define mu(x) x.resize(unique(all(x))-x.begin());
#define srt(x) sort(all(x));
#define sum(x) accumulate(all(x),0ll);
#define rev(x) reverse(all(x));
#define each(x,a) for(auto& x:a)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define PER(i,a,b) for(int i=a;i>=b;i--)
#define debug(x) cerr<<#x<<" "<<x<<"\n";
#define debug_v(x) { cout<<#x<<"\n";  each(y,x) cout<<y<<" "; cout<<'\n';}
#define debug_vp(x) { cout<<#x<<"\n";  each(y,x) cout<<y.ff<<" "<<y.ss<<'\n'; cout<<'\n';}
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<bool> vb;

int main(){
	fastio;
	int n,m;
	cin>>n>>m;
	vi a(n);
	rep(i,n)cin>>a[i];
	int tot=sum(a);
	int x=tot/(4*m)+(tot%(4*m)!=0);
	srt(a);
	rev(a);
	if(a[m-1]>=x){
		cout<<"Yes";
	} else {
    cout<<"No";
	}
	return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const double pi = acos(-1);
const int maxn = 2e6 + 10;
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ull base = 131;
const ull mod1 = 1e9 + 9;
const ull mod2 = 1610612741;

char s[maxn];

int main()
{
	scanf("%s", s+1);
	int n = strlen(s+1);
	if (n == 2 && s[1] == s[2])
	{
		printf("%d %d\n", 1, 2);
		return 0;
	}
	for (int i = 2; i <= n-1; ++i)
	{
		if (s[i] == s[i+1])
		{
			printf("%d %d\n", i, i+1);
			return 0;
		}
		else if (s[i] == s[i-1])
		{
			printf("%d %d\n", i-1, i);
			return 0;
		}
		else if (s[i+1] == s[i-1])
		{
			printf("%d %d\n", i-1, i+1);
			return 0;
		}
	}
	printf("-1 -1\n");
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k, a, b;
	scanf("%d %d %d", &k, &a, &b);
	for(int i=a; i<=b; i++){
		if(i%k==0){
			printf("OK");
			return 0;
		}
	}
	printf("NG");
}

Measured memory_bytes: 3824
import java.util.*;
 
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        //next()で受け取って/を閾値で分けて配列に入れる
        String date[] = sc.next().split("/", -1);
        sc.close();
        String kekka = jud(date);
        System.out.println(kekka);
    }
    
    private static String jud(String data[]){
        int a = 0;
        String kekka = null;
        if((a = Integer.parseInt(data[0])) <= 2019){
            if(Integer.parseInt(data[1]) < 5){
                kekka = "Heisei";
            }else{
                kekka = "TBD"; 
            }
        }
        return kekka;
    }
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int n;
    scanf(" %d", &n);

    vector<int> t(n),a(n);
    rep(i,n) scanf(" %d %d", &t[i], &a[i]);

    vector<double> p(n+1,1);
    rep(i,n) p[i] = (100-10*a[i])*0.01;
    for(int i=1; i<n; ++i) p[i] *= p[i-1];

    int q;
    scanf(" %d", &q);
    rep(qqq,q){
        int l,r;
        scanf(" %d %d", &l, &r);

        int lidx = lower_bound(all(t), l) - t.begin();
        int ridx = lower_bound(all(t), r) - t.begin();
        --ridx;

        double x = p[ridx];
        if(lidx > 0) x /= p[lidx-1];
        printf("%.10f\n", 1e9*x);
    }
    return 0;
}



Measured memory_bytes: 4424
void main(){
	int a, b, c, d;
	readf("%d %d %d %d", &a, &b, &c, &d);
	if(a+b > c+d)writeln("Left");
	else if(a+b < c+d)writeln("Right");
	else writeln("Balanced");
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2740
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string a,b,c; cin>>a>>b>>c;
	cout<<(a.back()==b.front()&&b.back()==c.front() ? "YES" : "NO")<<endl;
	return 0;
}


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

int main(){
	int H, W;
	cin >> H >> W;
	int rnow = 0;
	rep(i,H) {
		int l = -1, r = -1;
		bool flag = false;
		string s;
		cin >> s;
		rep(j,W){
			if (s[j] == '#') { l = j; break;}
		}
		rep(j,W){
			if (s[W-1-j] == '#') { r = W-1-j; break;}
		}
		if (l < rnow) flag = true;
		for (int j = l; j<=r; j++) {
			if (s[j] == '.') flag = true;
		}
		rnow = r;

		if (flag) {
			cout << "Impossible" << endl;
			return 0;
		}
	}

	cout << "Possible" << endl;

	return 0;
}


Measured memory_bytes: 3568
#include<iostream>
#include<vector>
#include<cmath>
#include<utility>
#include<algorithm>
#include<map>
using namespace std;
typedef long long int ll;
int main(void) {
	int n; cin >> n;
	int y; cin >> y;
	vector<string> v;
	string x;
	for (int i = 0; i < n; i++) {
		cin >> x;
		v.push_back(x);
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < n; i++) {
		cout << v[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <unordered_map>
#include <algorithm>
 
typedef long long ll;
 
constexpr int MAX_N = 400200;
constexpr int MOD = 1000000007;
 
using namespace std;
 
int n, x, y;
int col[MAX_N], weight[MAX_N];
 
vector<pair<int, int>> each[MAX_N];
vector<pair<int, int>> all;
 
vector<int> adj[MAX_N];
bool vis[MAX_N];
 
int dfs(int u, unordered_map<int, int> &col_cnt) {
    if (vis[u]) return 0;
    vis[u] = true;
    int ans = 1;
    col_cnt[col[u]]++;
    for (int v : adj[u]) {
        ans += dfs(v, col_cnt);
    }
    return ans;
}
 
int fact(int x) {
    ll ans = 1;
    for (int i = 1; i <= x; i++) {
        ans = (ans * i) % MOD;
    }
    return ans;
}
 
int pow(int b, int e) {
    if (e == 0) return 1;
    ll res = pow(b, e >> 1);
    res = (res * res) % MOD;
    if (e & 1) res = (res * b) % MOD;
    return res;
}
 
int inv(int x) {
    return pow(x, MOD - 2);
}
 
int permute(int cnt, unordered_map<int, int> &col_cnt) {
    ll ans = fact(cnt);
    for (pair<int, int> c : col_cnt) {
        if (c.second > 0) {
            ans = (ans * inv(fact(c.second))) % MOD;
        }
    }
    return ans;
}
 
int main() {
    scanf(" %d %d %d", &n, &x, &y);
    for (int i = 0; i < n; i++) {
        scanf(" %d %d", &col[i], &weight[i]);
        each[col[i]].push_back(make_pair(weight[i], i));
        all.push_back(make_pair(weight[i], i));
    }
 
    sort(all.begin(), all.end());
    for (int i = 1; i <= n; i++) {
        sort(each[i].begin(), each[i].end());
    }
 
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j < each[i].size(); j++) {
            if (each[i][j].first + each[i][0].first <= x) {
                adj[each[i][j - 1].second].push_back(each[i][j].second);
                adj[each[i][j].second].push_back(each[i][j - 1].second);
            }
        }
    }

    int diff = n;
    for (int i = 1; i < all.size(); i++) {
        if (col[all[i].second] != col[all[i - 1].second]) {
            diff = i;
            break;
        }
    }

    int bases[] = { 0, diff };
 
    for (int i = 1; i < all.size(); i++) {
        for (int j = 0; j < 2; j++) {
            if (col[all[i].second] == col[all[bases[j]].second]) continue;
            if (all[i].first + all[bases[j]].first > y) continue;
            adj[all[i].second].push_back(all[bases[j]].second);
            adj[all[bases[j]].second].push_back(all[i].second);
        }
    }
 
    ll tot = 1;
    for (int i = 0; i < n; i++) {
        if (!vis[i]) {
            unordered_map<int, int> col_cnt;
            int cnt = dfs(i, col_cnt);
            tot = (tot * (ll) permute(cnt, col_cnt)) % MOD;
        }
    }
 
    printf("%lld\n", tot);
 
    return 0;
}


Measured memory_bytes: 39920
#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 <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
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 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;
typedef map<int, int> mii;
typedef set<int> si;
#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 STLL(s) strtoll(s.c_str(), NULL, 10)
#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 Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
#define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const 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;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;





int main() {
    
    ll ans=0;
    int n;cin>>n;
    vector<pair<int,pair<int,int>>> v;
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        v.pb(mp(b+a,mp(a,b)));
    }
    Rort(v);
    rep(i,n){
        if(!(i%2))ans+=v[i].se.fi;
        else ans-=v[i].se.se;
    }
    fin(ans);


}



Measured memory_bytes: 1912
from collections import deque
def check(x,y):
    if 0<=x and x<h:
        if 0<=y and y<w:
            return True
    return False

count=0
def bfs():
    while (q):
        x,y,count=q.popleft()
        
        if check(x,y)==False or (x,y) in finished or c[x][y]=='#':
            continue

        else:
            q.append([x,y-1,count+1])
            q.append([x,y+1,count+1])
            q.append([x+1,y,count+1])
            q.append([x-1,y,count+1])
            finished.add((x,y))
            bfscount.append(count)

    return max(bfscount)

q = deque()
h,w=map(int,input().split())
global finished 
finished = set()
c=[]
for i in range(h):
    c.append(list(map(str,input())))
ans=[]
bfscount=[]
for i in range(h):
    for j in range(w):
        if c[i][j]==".":
            q.append([i,j,0])
            ans.append(bfs())
            finished = set()
            bfscount=[]
print(max(ans))


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=2e5+100;
const int M=4e5+100;
int head1[N],ver1[M],Next1[M];
int tot1,tot2;
int add1(int x,int y)
{
	ver1[++tot1]=y;
	Next1[tot1]=head1[x];
	head1[x]=tot1;
}

int head2[N],ver2[M],Next2[M];
int add2(int x,int y)
{
	ver2[++tot2]=y;
	Next2[tot2]=head2[x];
	head2[x]=tot2;
}
int cnt=0;
int c1[N],c2[N];
void dfs1(int x)
{
	c1[x]=cnt;
	for(int i=head1[x];i;i=Next1[i])
	{
		int y=ver1[i];
		if(c1[y])continue;
		dfs1(y);
	}
}
void dfs2(int x)
{
	
	c2[x]=cnt;
	for(int i=head2[x];i;i=Next2[i])
	{
		int y=ver2[i];
		
		if(c2[y])continue;
		dfs2(y);
	}
}

map<pair<int,int>,int>MM;
int main()
{
	int n,k,l;
	while(cin>>n>>k>>l)
	{
		MM.clear();
		memset(head1,0,sizeof(head1));
		memset(ver1,0,sizeof(ver1));
		memset(Next1,0,sizeof(Next1));
		memset(head2,0,sizeof(head2));
		memset(ver2,0,sizeof(ver2));
		memset(Next2,0,sizeof(Next2));
		memset(c1,0,sizeof(c1));
		memset(c2,0,sizeof(c2));
		tot1=0;
		tot2=0;
		for(int i=1;i<=k;i++)
		{
			int x,y;
			cin>>x>>y;
			add1(x,y);
			add1(y,x);
		}
		
		for(int i=1;i<=l;i++)
		{
			int x,y;
			cin>>x>>y;
			add2(x,y);
			add2(y,x);
		}
		for(int i=1;i<=n;i++)
		{
			if(c1[i]==0)
			{
				cnt++;
				dfs1(i);
			}
		}
		cnt=0;
		for(int i=1;i<=n;i++)
		{
			if(c2[i]==0)
			{
				cnt++;
				dfs2(i);
			}
		}
		
		for(int i=1;i<=n;i++)
			MM[make_pair(c1[i],c2[i])]++;
		for(int i=1;i<=n;i++)
		{
			cout<<MM[make_pair(c1[i],c2[i])]<<" ";
			if(i==n)cout<<endl;
		}
		
	}
	return 0;
} 

Measured memory_bytes: 21504
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
typedef long long ll;
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    ll a[n+1];
    fill(a, a+n+1, 0);
    a[0] = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] += a[i-1];
    }

    int s = n * (n+1) / 2;
    ll sum_a[s];
    int count = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j <= n; j++) {
            sum_a[count] = a[j] - a[i];
            count++;
        }
    }

    sort(sum_a, sum_a+s, greater<ll>());

    vector <ll> sa;
    for (int i = 0; i < s; i++) {
        sa.push_back(sum_a[i]);
    }

    ll ans = 0;

    for (int i = 39; i >= 0; i--) {
        vector <ll> tmp;
        for (int j = 0; j < sa.size(); j++) {
            if (sa.at(j) & (1LL<<i)) {
                tmp.push_back(sa.at(j));
            }
            sa.at(j) %= (1LL<<i);
        }

        if (tmp.size() >= k) {
            sa = tmp;
            ans += (1LL<<i);
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10352
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

using ll = long long;

ll f(string& s) {
    string a = "";
    ll sum = 0;

    int n = s.size();
    for (int i = 0; i < n; ++i) {
        if (s[i] == '+') {
            sum += stoll(a);
            a = "";
        } else {
            a += s[i];
        }
    }

    sum += stoll(a);
    return sum;
}

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

    int n = s.size();
    ll sum = 0;
    for (int mask = 0; mask < (1 << (n - 1)); ++mask) {
        string t;
        t += s[0];
        for (int i = 0; i < n - 1; ++i) {
            if (mask & (1<<i)) {
                t += '+';
            }
            t += s[i + 1];
        }
        sum += f(t);
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)

/*
*/

ll n,ans=0;
string s[100010];
map<string,ll> m;

void init(){
	cin>>n;
	rep(i,n)cin>>s[i];
}

int main(void){
	init();
	rep(i,n){
		string t="";
		ll a[30]={};
		rep(j,10)a[s[i][j]-'a']++;
		rep(j,26){
			rep(k,a[j])t+=(char)(j+'a');
		}
		m[t]++;
		// cerr<<t<<endl;
	}
	for(auto itr=m.begin(); itr!=m.end();itr++){
		// cerr<<itr->first<<": "<<itr->second<<endl;
		ans += itr->second*(itr->second-1)/2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 19712
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;

int main(){
	int N;
	cin>>N;
	if(N%2==0)cout<<N;
	else cout<<2*N;
}

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

int main(){
	int n;
	cin>>n;
	int i=10;
	int a=1;
	int ans=0;
	for(;i<=n;i*=10){
		if(a%2==1){
			ans+=i/10*9;
		}
		a++;
	}
	if(a%2==1){
		ans+=n-(i/10)+1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
/*************************************
 * @contest:      AtCoder ABC156.
 * @user_id:      63720.
 * @user_name:    Jomoo.
 * @time:         2020-02-22.
 * @language:     C++.
 * @upload_place: Luogu.
*************************************/ 

#include <bits/stdc++.h>
using namespace std;

typedef signed char          int8;
typedef unsigned char       uint8;
typedef short                int16;
typedef unsigned short      uint16;
typedef int                  int32;
typedef unsigned            uint32;
typedef long long            int64;
typedef unsigned long long  uint64;

template <typename Int>
inline Int read()       
{
    Int flag = 1;
    char c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
    return init * flag;
}

template <typename Int>
inline Int read(char &c)       
{
    Int flag = 1;
    c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
    return init * flag;
}

template <typename Int>
inline void write(Int x)
{
    if (x < 0) putchar('-'), x = ~x + 1;
    if (x > 9) write(x / 10);
    putchar((x % 10) | 48);
}  

template <typename Int>
inline void write(Int x, char nextch)
{
    write(x);
    putchar(nextch);
}
#define int long long
#define P 1000000007
int n, k;
// a sort of {a_i} that sum{a_i} = n and the number of {a_i = 0} isn't more than k
// output the count of the sorts module (1e9 + 7) 

/*
15 6
22583772
2^2 * 3^4 * 43 * 1621
*/

inline int64 fexp(int64 a, int np)
{
    int64 res = 1;
    while (np) {
        if (np & 1) res = res * a % P;
        a = a * a % P;
        np >>= 1;
    }
    return res;
}
#define inv(x) fexp(x, P - 2)
int64 fac[200007];
inline int64 C(int n, int m)
{
    return fac[m] * inv(fac[n] * fac[m - n] % P) % P;
}

signed main()
{
    register int64 ans = 1, now = 0;
    n = read<int>();
    k = read<int>();
    fac[1] = fac[0] = 1;
    for (int i = 2; i <= n; i++) fac[i] = fac[i - 1] * i % P;
    for (register int i = 1; i <= min(n - 1, k); i++) {
        now = C(i, n) * C(n - i - 1, n - 1) % P;
        ans = (ans + now) % P;
    }
    write(ans, 10);
    return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

const ll MOD = 1e9 + 7;

vvl operator*(vvl a, vvl b) {
	ll n = sz(a);
	vvl c(n,vl(n));
	FOR(i,0,n) FOR(k,0,n) FOR(j,0,n) {
		c[i][j] = (c[i][j] + a[i][k]*b[k][j]) % MOD;
	}
	return c;
}

vvl power(vvl a, ll k) {
	ll n = sz(a);
	vvl res(n,vl(n));
	FOR(i,0,n) res[i][i] = 1;
	while (k) {
		if (k&1) res = res*a;
		a = a*a;
		k /= 2;
	}
	return res;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, k;
	cin >> n >> k;

	vvl adj(n,vl(n));
	FOR(i,0,n) FOR(j,0,n) cin >> adj[i][j];
	adj = power(adj,k);

	ll res = 0;
	FOR(i,0,n) FOR(j,0,n) res += adj[i][j];
	cout << res%MOD << endl;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  string S;
  cin >> S;
  string tmp[7] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  int ans = 1;
  for (int i = 6; i >= 0; i--) {
    if (tmp[i] == S) {
      cout << ans << endl;
    }
    ans++;
  }
  return 0;
}

Measured memory_bytes: 3544
N = int(input())
S1=input()
S2=input()

m1=""
m=10**9+7
S1+="."
for i in range(len(S1)-1):
    if S1[i]==S1[i+1]:
        m1+='y'
    else:
        m1+='t'
m1 = m1.replace('yt','y')
score = [1]*len(m1)
for i in range(1,len(m1)):
    if m1[i-1]=='t' and m1[i]=='t':
        score[i]=2
    elif m1[i-1]=='y' and m1[i]=='t':
        score[i]=1
    elif m1[i-1]=='t' and m1[i]=='y':
        score[i]=2
    elif m1[i-1]=='y' and m1[i]=='y':
        score[i] = 3
if m1[0]=='y':
    score[0]=6
else:
    score[0]=3

ans = 1
for i in range(len(m1)):
    ans =(ans*score[i])%m
print(ans)

Measured memory_bytes: 9168
#include<cstdio>
#include<algorithm>

using namespace std;

const long long MA=1000000000000000000ll+1;

long long gcd(long long a,long long b){
	if(a<b) return gcd(b,a);
	if(b==0) return a;
	return gcd(b,a%b);
}

long long lcm(long long a,long long b){
	if(a==MA||b==MA) return MA;
	long long d=gcd(a,b);
	b/=d;
	if(a>=MA/b+1) return MA;
	return min(MA,a*b);
}

long long num[1<<20];
double pr[1<<20];

long long a[20];
double p[20];

int main(){
	int N;
	long long M;
	scanf("%d%lld",&N,&M);
	for(int i=0;i<N;i++) scanf("%lld",a+i);
	for(int i=0;i<N;i++){
		int in;
		scanf("%d",&in);
		p[i]=(double)in/100;
	}
	for(int stat=0;stat<(1<<N);stat++){
		int cnt=0;
		if(stat==0) num[stat]=0;
		else{
			long long d=1;
			for(int i=0;i<N;i++) if(((stat>>i)&1)==1){
				cnt++;
				d=lcm(d,a[i]);
			}
			num[stat]=M/d;
			if(cnt%2==0) num[stat]*=-1;
		}
		pr[stat]=1;
		for(int i=0;i<N;i++){
			if(((stat>>i)&1)==1) pr[stat]*=p[i];
			else pr[stat]*=(1-p[i]);
		}
	}
	for(int i=0;i<N;i++) for(int j=0;j<(1<<N);j++){
		if(((j>>i)&1)==1){
			num[j]+=num[j&(~(1<<i))];
		}
	}
	double ans=0;
	for(int stat=0;stat<(1<<N);stat++){
		double tmp=pr[stat]*num[stat];
		ans+=tmp;
	}
	printf("%.9f\n",ans);
	return 0;
}

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

using namespace std;

int main() {
  int H,W;
  char S[53][53];
  cin >> H >> W;
  for (int j=0;j<W+2;++j) {
    S[0][j] = ' ';
    S[H+1][j] = ' ';
  }
  for (int i=1;i<H+1;++i) {
    S[i][0] = ' ';
    cin >> (S[i]+1);
    S[i][W+1] = ' ';
  }
  for (int i=1;i<=H;++i) {
    for (int j=1;j<=W;++j) {
      int count = 0;
      if (S[i][j] == '#') {
        continue;
      }
      for (int k=0;k<3;++k) {
        for (int l=0;l<3;++l) {
          if (S[i-1+k][j-1+l] == '#') {
            ++count;
          }
        }
      }
      S[i][j] = to_string(count).c_str()[0];
    }
    S[i][W+1]='\0';
    cout << (S[i]+1) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main ()
{
   int a, b;

   scanf("%d", &a);
   scanf("%d", &b);

   if (a > b) 
      printf("a > b\n");
   else if (a < b)
      printf("a < b\n");
   else if (a == b)
      printf("a == b\n");

   return 0;

}

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

typedef long long ll;

const ll N = 1000 + 10;
const ll inf = 1e9 + 7;

void maximize(ll &a, ll b) { a = max(a, b); }
void minimize(ll &a, ll b) { a = min(a, b); }

ll n, m;
ll a[N][N];

ll dp[N][N];
ll vis[N][N];
ll col[N][N];

ll tx[3] = {0, 1};
ll ty[3] = {1, 0};

ll getCol(ll cid, ll l, ll r){
	if (r < l) return 0;
	return col[cid][r] - col[cid][l - 1];
}

ll dfs(ll i, ll j){
	if (vis[i][j]) return dp[i][j];
	vis[i][j] = 1;
	if (i == n && j == m) 
		return dp[i][j] = 0;
	ll turn = (i + j) % 2;
	dp[i][j] = (turn == 0 ? -inf : inf);
	for (ll t = 0; t < 2; t++){
		ll ni = tx[t] + i, nj = ty[t] + j;
		if (0 <= ni && ni <= n && 0 <= nj && nj <= m); else continue;
		ll del = (t == 1 ? 0 : getCol(nj, 1, ni) - getCol(nj, ni + 1, n) );
		if (!turn) maximize( dp[i][j], dfs(ni, nj) + del);
		else	   minimize( dp[i][j], dfs(ni, nj) + del);
	}
	return dp[i][j];
}

main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("8.inp", "r", stdin);
	cin >> m >> n;
	for (ll i = 1; i <= n; i++)
		for (ll j = 1; j <= m; j++)
			cin >> a[i][j];
	
	for (ll j = 1; j <= m; j++){
		for (ll i = 1; i <= n; i++)
			col[j][i] = col[j][i - 1] + a[i][j];
	}
	cout << abs( dfs(0, 0) ) << '\n';
}


Measured memory_bytes: 34852
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, sum, P;
  cin >> N;
  
  for(int i = 0; i < N; i++){
    int l, r;
    cin >> l >> r;
    P = r - l + 1;
    sum += P;
  }
  cout << sum <<endl;
}
    

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<sstream>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; ++i)
#define per(i, a, n)  for(int i=n-1; i>=a; --i)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 1000000007
using namespace std;
typedef long long ll;

struct UnionFind{
private:
  vector<int> tree;
public:
  UnionFind(int _size){
    tree = vector<int>(_size, -1);
  }
  int root(int _n){
    if(tree[_n] < 0)  return _n;
    return tree[_n] = root(tree[_n]);
  }
  int size(int _n){
    return -tree[root(_n)];
  }
  bool unite(int _x, int _y){
    int rx = root(_x);
    int ry = root(_y);
    if(rx == ry)  return  false;

    if(size(rx) < size(ry)) swap(rx, ry);
    tree[rx] += tree[ry];
    tree[ry] = rx;

    return true;
  }
  bool same(int _x, int _y){
    int rx = root(_x);
    int ry = root(_y);
    return rx==ry;
  }
};

int main(){
  int N, M; cin >> N >> M;
  UnionFind uf(N);
  vector<pair<int,int>> bridge;
  rep(i, 0, M){
    int a, b;
    cin >> a >> b;
    a--; b--;
    bridge.push_back(make_pair(a, b));
  }

  vector<ll> ans(M);
  ans[M-1] = (ll)N * (N-1) / 2;
  for(int i = M-1; i>=1; i--){
    int A = bridge[i].first;
    int B = bridge[i].second;

    ans[i-1] = ans[i];
    if(!uf.same(A, B)){
      ans[i-1] -= (ll)uf.size(A) * uf.size(B);
      uf.unite(A, B);
    }
  }
  rep(i, 0, M){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3444
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int[] l = new int[n];
            for (int i = 0; i < n; i++) {
                l[i] = Integer.parseInt(in.next());
            }
            int ans = 0;
            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j < n; j++) {
                    for (int k = j + 1; k < n; k++) {
                        if (kumi(l[i], l[j], l[k]) && len(l[i], l[j], l[k])) ans++;
                    }

                }
            }

            // 出力
            out.println(ans);

        }

        boolean kumi(int a, int b, int c) {
            if (a != b && b != c && c != a) return true;
            else return false;

        }

        boolean len(int a, int b, int c) {
            if (a < b + c && b < c + a && c < a + b) return true;
            else return false;

        }

    }
}



Measured memory_bytes: 36472
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = (int)1e9 + 7;
int INF = (int)2e18;
// Comment out below and program paste

// #include "UnionFind.hpp"
// #include "power.hpp"

signed main() {
      int N, M;
      cin >> N >> M;
      vector<vector<int>> light;
      for (int i = 0; i < M; i++) {
            int k;
            cin >> k;
            vector<int> temp;
            for (int j = 0; j < k; j++) {
                  int s;
                  cin >> s;
                  temp.push_back(s);
            }
            light.push_back(temp);
      }
      vector<int> check(M);
      for (int i = 0; i < M; i++) cin >> check[i];
      int ans = 0;
      for (int i = 0; i < (1 << N); i++) {
            bool flag = true;
            for (int j = 0; j < M; j++) {
                  int number = 0;
                  for (int k = 0; k < light[j].size(); k++) {
                        if (i & (1 << (light[j][k] - 1))) ++number;
                  }
                  if (number % 2 != check[j]) {
                        flag = false;
                        break;
                  }
            }
            if (flag) ++ans;
      }
      cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll k;
int n;
bool check(ll mid,vector<ll> a, vector<ll> b){
	ll sum=0;
	for(int i=0;i<n;i++){
		sum += max(a[i] - mid/b[i],0ll);
	}
	if(sum > k ) return 0;
	else return 1;
}
int main(){
	cout << fixed << setprecision(10);
	cin >> n >> k;
	vector<ll> a(n),f(n);
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> f[i];
	sort(a.begin(),a.end());
	sort(f.begin(),f.end());
	reverse(f.begin(),f.end());
	ll left = -1, right = (ll)1e13;
	ll mid;
	ll cnt = 0;
	while(left+1<right){
		mid = (left+right)/2;
		if(check(mid,a,f)){
			right = mid;
		}
		else{
			left = mid;
		}
		cnt++;
	}
	cout << right << endl;
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
const double EPS = 1e-9;


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

    int n; cin >> n;
    map<string, int> mp1;
    rep(i, n) {
        string s; cin >> s;
        mp1[s]++;
    }
    int m; cin >> m;
    map<string, int> mp2;
    rep(i, m) {
        string s; cin >> s;
        mp2[s]++;
    }
    
    int ans = 0;
    for(auto e : mp1) {
        ans = max(ans, e.second - mp2[e.first]);
    }
    cout << ans << '\n';
    return 0;
}

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

int main(){
    stack<int> S1;
    stack<pair<int,int> > S2;
    char ch;
    int sum=0;
    for(int i=0;cin >> ch;i++){
        if(ch=='\\')S1.push(i);
        else if(ch=='/'&&S1.size()>0){
            int j = S1.top();S1.pop();
            sum +=i-j;
            int a =i-j;
            while(S2.size()>0&&S2.top().first>j){
                a+=S2.top().second;S2.pop();
            }
            S2.push(make_pair(j,a));
        }
    }

    vector<int> ans;
    while(S2.size()>0){
        ans.push_back(S2.top().second);S2.pop();
    }
    reverse(ans.begin(),ans.end());
    cout << sum << endl;
    cout << ans.size();
    for(int i=0;i<ans.size();i++){
        cout << ' ';
        cout << ans[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3240
x = input()
n = int(x.split()[0])
b = int(x.split()[1])
r = int(x.split()[2])

shou = n // (b + r)
amari = n % (b + r)

if amari - b == 0:
    sum = shou * b
elif amari - b < 0:
    sum = (shou * b) + amari
elif amari - b > 0:
    sum = (shou * b) + b
   
print(sum)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=0;cin>>n;
  lvector p(n,0);rep(i,n) cin>>p[i];
  ll pos=0,ord=0;
  while(pos<n) {
    if(p[pos]==pos+1) {
      ord++;
      while(pos+1<n&&p[pos+1]==pos+1+1) {pos++;ord++;}
      if(ord==1) ans++;
      else ans+=(ord+1)/2;
      ord=0;
    }
    pos++;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[3],b[3];
  int c[5];fill(c,c+5,0);
  for(int i=0;i<3;i++){
    cin>>a[i]>>b[i];
    c[a[i]]++;
    c[b[i]]++;
  }
  for(int i=1;i<=4;i++){
    if(c[i]>=3){
      cout<<"NO"<<endl;
    return 0;
    }
  }
  cout<<"YES"<<endl;
}

Measured memory_bytes: 256